| | |
| | | package org.sxkj.system.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import org.springblade.core.log.annotation.ApiLog; |
| | | import org.springblade.core.log.logger.BladeLogger; |
| | |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springblade.core.tool.utils.DigestUtil; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | import org.sxkj.system.entity.User; |
| | | import org.sxkj.system.entity.UserInfo; |
| | | import org.sxkj.system.enums.DictEnum; |
| | | import org.sxkj.system.mapper.UserMapper; |
| | | import org.sxkj.system.param.DeptAddParam; |
| | | import org.sxkj.system.service.IDeptService; |
| | | import org.sxkj.system.service.IRoleService; |
| | |
| | | import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE; |
| | | |
| | | @NonDS |
| | | @Slf4j |
| | | @RestController |
| | | @AllArgsConstructor |
| | | @RequestMapping("/external") |
| | |
| | | private final BladeLogger bladeLogger; |
| | | |
| | | /** |
| | | * 新增或修改 |
| | | * 新增或修改-对外 |
| | | */ |
| | | @PostMapping("/submitDeptExternal") |
| | | @ApiOperationSupport(order = 6) |
| | | @ApiOperationSupport(order = 1) |
| | | @ApiOperation(value = "机构新增或修改", notes = "传入dept") |
| | | @ApiLog("组织机构信息新增或修改") |
| | | public R submit(@Valid @RequestBody DeptAddParam dept) { |
| | | log.info("机构信息修改-对外{}", JSON.toJSONString(dept)); |
| | | // 参数校验:确保关键字段不为空 |
| | | if (dept.getId() == null) { |
| | | return R.fail("参数缺失:id 不能为空"); |
| | | } |
| | | // 删除操作 |
| | | if (dept.getId() != null && dept.getIsDeleted() == 1) { |
| | | deptService.removeDept(String.valueOf(dept.getId())); |
| | | CacheUtil.clear(SYS_CACHE); // 清理缓存 |
| | | CacheUtil.clear(SYS_CACHE, Boolean.FALSE); |
| | | Kv kv = Kv.create().set("id", String.valueOf(dept.getId())).set("tenantId", dept.getTenantId()) |
| | | .set("deptCategoryName", DictCache.getValue(DictEnum.ORG_CATEGORY, dept.getDeptCategory())); |
| | | return R.data(kv); |
| | | } |
| | | // 新增操作 |
| | | Dept deptEntity = Objects.requireNonNull(BeanUtil.copy(dept, Dept.class)); |
| | | String times = OrderNumUtils.initOrderNum2(WordOrderConstant.ORG_CODE); |
| | | String deptCode = WordOrderConstant.ORG_PREFIX + times; |
| | | deptEntity.setDeptCode(deptCode); |
| | | deptEntity.setAreaCode(HeaderUtils.processAreaCode(StringUtil.isNotBlank(dept.getAreaCode()) ? dept.getAreaCode() : "3608")); |
| | | deptEntity.setCreateTime(new Date()); |
| | | deptEntity.setUpdateTime(new Date()); |
| | | if (deptService.submit(deptEntity)) { |
| | | CacheUtil.clear(SYS_CACHE); |
| | | CacheUtil.clear(SYS_CACHE, Boolean.FALSE); |
| | | List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getDeptId, dept.getId())); |
| | | List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getDeptId, String.valueOf(dept.getId()))); |
| | | if (!userList.isEmpty()) { |
| | | List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList()); |
| | | userService.updateUserAreaCode(dept.getAreaCode(), userIds); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 新增或修改 |
| | | * 新增或修改-对外 后面沟通后不同步角色信息,先注释防止看不懂 |
| | | */ |
| | | @PostMapping("/submitRoleExternal") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperation(value = "角色新增或修改", notes = "传入role") |
| | | @ApiLog("角色信息新增或修改") |
| | | public R submit(@Valid @RequestBody Role role) { |
| | | CacheUtil.clear(SYS_CACHE); |
| | | CacheUtil.clear(SYS_CACHE, Boolean.FALSE); |
| | | return R.status(roleService.submit(role)); |
| | | } |
| | | // @PostMapping("/submitRoleExternal") |
| | | // @ApiOperationSupport(order = 2) |
| | | // @ApiOperation(value = "角色新增或修改", notes = "传入role") |
| | | // @ApiLog("角色信息新增或修改") |
| | | // public R submit(@Valid @RequestBody Role role) { |
| | | // log.info("角色信息修改-对外{}", JSON.toJSONString(role)); |
| | | // // 参数校验:确保关键字段不为空 |
| | | // if (role.getId() == null) { |
| | | // return R.fail("参数缺失:id 不能为空"); |
| | | // } |
| | | // CacheUtil.clear(SYS_CACHE); |
| | | // CacheUtil.clear(SYS_CACHE, Boolean.FALSE); |
| | | // // 删除操作 |
| | | // if (role.getIsDeleted() != null && role.getIsDeleted() == 1) { |
| | | // roleService.removeRole(String.valueOf(role.getId())); |
| | | // return R.status(true); |
| | | // } |
| | | // // 新增操作 |
| | | // return R.status(roleService.submit(role)); |
| | | // } |
| | | |
| | | |
| | | /** |
| | | * 用户信息新增或者修改-对外 |
| | | */ |
| | | @PostMapping("/submitUserExternal") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "新增或修改用户", notes = "传入User,新增或修改用户") |
| | | @ApiLog("用户信息新增或者修改-对外") |
| | | public R submitExternal(@Valid @RequestBody User user) { |
| | | log.info("用户信息修改-对外{}", JSON.toJSONString(user)); |
| | | CacheUtil.clear(USER_CACHE); |
| | | |
| | | boolean isRet = false; |
| | |
| | | if (userInfo != null && userInfo.getUser() != null) { |
| | | bladeLogger.info("用户信息修改", user.toString()); |
| | | user.setId(userInfo.getUser().getId()); |
| | | user.setDeptId(userInfo.getUser().getDeptId()); |
| | | user.setRoleId(userInfo.getUser().getRoleId()); |
| | | user.setDeptId(StringUtil.isBlank(user.getDeptId()) ? userInfo.getUser().getDeptId() : user.getDeptId()); |
| | | user.setRoleId(StringUtil.isBlank(user.getRoleId()) ? userInfo.getUser().getRoleId() : user.getRoleId()); |
| | | user.setIsDeleted(user.getIsDeleted()); |
| | | isRet = userService.updateUser(user); |
| | | } else { |
| | | Dept dept = deptService.getById(1123598813738675201L); |
| | | // 将String类型的deptId转换为Long类型 |
| | | Long deptIdLong = Long.parseLong(user.getDeptId()); |
| | | Dept dept = deptService.getById(deptIdLong); |
| | | user.setAreaCode(HeaderUtils.processAreaCode(dept.getAreaCode())); |
| | | user.setPassword("jadk@2026"); |
| | | user.setDeptId(user.getDeptId() == null ? String.valueOf(dept.getId()) : user.getDeptId()); |
| | | user.setRoleId(user.getRoleId() == null ? "2011678430358691842" : user.getRoleId()); |
| | | isRet = userService.save(user); |
| | | user.setPassword(DigestUtil.encrypt("jadk@2026")); |
| | | user.setDeptId(StringUtil.isBlank(user.getDeptId()) ? String.valueOf(dept.getId()) : user.getDeptId()); |
| | | user.setRoleId(StringUtil.isBlank(user.getRoleId()) ? "2011678430358691842" : user.getRoleId()); |
| | | user.setCreateTime(new Date()); |
| | | isRet = userService.submit(user); |
| | | bladeLogger.info("用户信息新增", user.toString()); |
| | | } |
| | | |