吉安感知网项目-后端
linwei
2026-06-16 474aabc5d2b4d6ccdd0d141ed06be87eb7559939
drone-service/drone-system/src/main/java/org/sxkj/system/controller/ExternalController.java
@@ -1,10 +1,12 @@
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;
@@ -13,6 +15,7 @@
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.BeanUtil;
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;
@@ -41,6 +44,7 @@
import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;
@NonDS
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/external")
@@ -63,6 +67,7 @@
   @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 不能为空");
@@ -81,13 +86,13 @@
      String times = OrderNumUtils.initOrderNum2(WordOrderConstant.ORG_CODE);
      String deptCode = WordOrderConstant.ORG_PREFIX + times;
      deptEntity.setDeptCode(deptCode);
      deptEntity.setAreaCode(HeaderUtils.processAreaCode(dept.getAreaCode()));
      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);
@@ -102,27 +107,28 @@
   }
   /**
    * 新增或修改-对外
    * 新增或修改-对外  后面沟通后不同步角色信息,先注释防止看不懂
    */
   @PostMapping("/submitRoleExternal")
   @ApiOperationSupport(order = 2)
   @ApiOperation(value = "角色新增或修改", notes = "传入role")
   @ApiLog("角色信息新增或修改")
   public R submit(@Valid @RequestBody Role 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("/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));
   // }
   /**
@@ -133,6 +139,7 @@
   @ApiOperation(value = "新增或修改用户", notes = "传入User,新增或修改用户")
   @ApiLog("用户信息新增或者修改-对外")
   public R submitExternal(@Valid @RequestBody User user) {
      log.info("用户信息修改-对外{}", JSON.toJSONString(user));
      CacheUtil.clear(USER_CACHE);
      boolean isRet = false;
@@ -141,20 +148,29 @@
      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(user.getDeptId());
         // 将String类型的deptId转换为Long类型
         Long deptIdLong = Long.parseLong(user.getDeptId());
         Dept dept = deptService.getById(deptIdLong);
         user.setAreaCode(HeaderUtils.processAreaCode(dept.getAreaCode()));
         user.setPassword(DigestUtil.encrypt("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.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.submitNotPassword(user);
         bladeLogger.info("用户信息新增", user.toString());
      }
      return R.status(isRet);
   }
   public static void main(String[] args) {
      String encrypt = DigestUtil.encrypt("jadk@2026");
      System.out.println(encrypt);
   }
}