|
|
@@ -18,6 +18,7 @@ import cc.iotkit.common.utils.StringUtils;
|
|
|
import cc.iotkit.common.validate.EditGroup;
|
|
|
import cc.iotkit.common.validate.QueryGroup;
|
|
|
import cc.iotkit.common.web.core.BaseController;
|
|
|
+import cc.iotkit.model.InvokeResult;
|
|
|
import cc.iotkit.model.system.SysDept;
|
|
|
import cc.iotkit.system.dto.bo.SysDeptBo;
|
|
|
import cc.iotkit.system.dto.bo.SysUserBo;
|
|
|
@@ -26,6 +27,7 @@ import cc.iotkit.system.dto.vo.*;
|
|
|
import cc.iotkit.system.listener.SysUserImportListener;
|
|
|
import cc.iotkit.system.service.*;
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
import cn.dev33.satoken.secure.BCrypt;
|
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
@@ -33,6 +35,7 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.http.MediaType;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
@@ -309,4 +312,83 @@ public class SysUserController extends BaseController {
|
|
|
return deptService.selectDeptTreeList(reqDept.getData());
|
|
|
}
|
|
|
|
|
|
+ @SaIgnore
|
|
|
+ @ApiOperation(value = "同步用户数据", notes = "同步用户数据", httpMethod = "POST")
|
|
|
+ @PostMapping("/syncUserInfo")
|
|
|
+ @Transactional
|
|
|
+ public Map<String, Object> syncUserInfo(@RequestBody Map<String,Object> sysUserInfo) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String companyName = (String) sysUserInfo.get("companyName");
|
|
|
+ String companyCode = (String) sysUserInfo.get("companyCode");
|
|
|
+ String instName = (String) sysUserInfo.get("instName");
|
|
|
+ String instCode = (String) sysUserInfo.get("instCode");
|
|
|
+ String userName = (String) sysUserInfo.get("userName");
|
|
|
+ String nickName = (String) sysUserInfo.get("nickName");
|
|
|
+ String mobile = (String) sysUserInfo.get("mobile");
|
|
|
+ if(StringUtils.isNotEmpty(companyName) && StringUtils.isNotEmpty(instName)){
|
|
|
+ if(companyName.equals(instName)){
|
|
|
+ instName = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建分公司机构
|
|
|
+ SysDept company = null;
|
|
|
+ SysDept inst = null;
|
|
|
+ if(Objects.nonNull(companyCode)){
|
|
|
+ company = deptService.selectDeptByCode(companyCode);
|
|
|
+ if(Objects.isNull(company)){
|
|
|
+ company = createNewDept(companyName,companyCode,100L);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(instName)){
|
|
|
+ inst = deptService.selectDeptByCode(instCode);
|
|
|
+ if(Objects.isNull(inst)){
|
|
|
+ inst = createNewDept(instName,instCode,company.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建user
|
|
|
+ SysUserVo sysUserVo = userService.selectUserByUserName(userName);
|
|
|
+ if(Objects.nonNull(sysUserVo)){
|
|
|
+ sysUserVo.setNickName(nickName);
|
|
|
+ sysUserVo.setPhonenumber(mobile);
|
|
|
+ userService.updateBaseUser(sysUserVo);
|
|
|
+ }else{
|
|
|
+ SysUserBo user =new SysUserBo();
|
|
|
+ user.setNickName(nickName);
|
|
|
+ user.setUserName(userName);
|
|
|
+ user.setPhonenumber(mobile);
|
|
|
+ user.setPassword(BCrypt.hashpw("Mm#"+mobile));
|
|
|
+ user.setRoleIds(Collections.singletonList(2L));
|
|
|
+ user.setUserType("sys_user");
|
|
|
+ user.setTenantId("000000");
|
|
|
+ if(Objects.nonNull(inst)){
|
|
|
+ user.setDeptId(inst.getId());
|
|
|
+ }else if(Objects.nonNull(company)){
|
|
|
+ user.setDeptId(company.getId());
|
|
|
+ }else{
|
|
|
+ user.setDeptId(100L);
|
|
|
+ }
|
|
|
+ userService.insertUser(user);
|
|
|
+ }
|
|
|
+ userService.syncUserInfo(companyName,instName,userName,nickName);
|
|
|
+ } catch (Exception e) {
|
|
|
+ map.put("resp_code", 1);
|
|
|
+ map.put("resp_msg", e.getMessage());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ map.put("resp_code", 0);//状态码:0-成功,1-失败
|
|
|
+ map.put("resp_msg", "");//响应结果详细信息
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysDept createNewDept(String name, String code, Long parentId) {
|
|
|
+ SysDeptBo dept = new SysDeptBo();
|
|
|
+ dept.setDeptName(name);
|
|
|
+ dept.setDeptCode(code);
|
|
|
+ dept.setParentId(parentId);
|
|
|
+ dept.setStatus("0");
|
|
|
+ dept.setTenantId("0000000");
|
|
|
+ return deptService.createNewDept(dept);
|
|
|
+ }
|
|
|
+
|
|
|
}
|