zzw
2023-11-16 0117a966938d2f689e90eee907bd12bc9e123a18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.zt.life.sys.controller;
 
import com.zt.core.security.Md5Utils;
import com.zt.life.sys.dao.SysUserRegDao;
import com.zt.life.sys.model.SysUserReg;
import com.zt.modules.sys.service.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import springfox.documentation.annotations.ApiIgnore;
 
import com.zt.common.annotation.LogOperation;
import com.zt.common.annotation.QueryParam;
import com.zt.common.constant.Constant;
import com.zt.common.db.query.QueryFilter;
import com.zt.common.servlet.PageResult;
import com.zt.common.servlet.Result;
import com.zt.common.validator.ValidatorUtils;
import com.zt.common.validator.group.AddGroup;
import com.zt.common.validator.group.DefaultGroup;
import com.zt.common.validator.group.UpdateGroup;
import com.zt.core.sys.model.SysUser;
import com.zt.life.sys.dto.SysUserExDto;
import com.zt.life.sys.service.SysUserExtService;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
import com.zt.common.utils.UUIDUtil;
import com.zt.core.sys.model.SysDept;
 
import java.util.Date;
import com.zt.life.sys.service.SysUserRegService;
import com.zt.core.security.Md5Utils;
 
/**
 * 用户管理
 *
 * @author hehz
 * @since 1.0.0 2020-09-01
 */
@RestController
@RequestMapping("/sys/userReg")
@Api(tags = "用户管理")
public class UserRegController {
    @Autowired
    private SysUserRegService sysUserRegService;
 
    @Autowired
    private SysDeptService sysDeptService;
 
    @Autowired
    private SysParamsService paramsService;
 
    @Autowired
    SysJobUserService sysJobUserService;
    @Autowired
    SysPostUserService sysPostUserService;
 
    @Autowired
    SysMapService sysMapService;
 
    @PostMapping
    @ApiOperation("新增")
    @LogOperation("用户管理--->新增")
    //@RequiresPermissions("sys:user")
    @Transactional(rollbackFor = Exception.class)
    public Result<String> insert(@RequestBody SysUserReg  entity) {
        // 效验数据
        //ValidatorUtils.validateEntity(entity, AddGroup.class, DefaultGroup.class);
        String result = "OK";
        Integer hasUser = sysUserRegService.existUsername(entity.getUsername());
        if (hasUser ==0) {
            String password = Md5Utils.hash(paramsService.getValue(Constant.ParamKey.INIT_PASSWORD_KEY));
            entity.setPassword(password);
            entity.setIsLocked(0);
 
            entity.setSuperAdmin(false);
            if (entity.getCreateDate() == null) {
                entity.setCreateDate(new Date());
                entity.setUpdateDate(new Date());
            }
 
            Long id = UUIDUtil.generateId();
            entity.setId(id);
            Long deptId = entity.getDeptId();
            SysDept sysDept = sysDeptService.get(deptId);
            Long companyId = sysDept.getCompanyId();
            entity.setCompanyId(companyId);
            entity.setCreator(id);
            entity.setUpdater(id);
            entity.setCompanyId(sysDeptService.getCompanyIdByDeptId(entity.getDeptId()));
            sysUserRegService.insert(entity);
            // 保存岗位用户关系
            sysPostUserService.saveOrUpdate(entity.getId(), entity.getPostIdList());
            // 保存职位用户关系
            sysJobUserService.saveOrUpdate(entity.getId(), entity.getJobIdList());
 
            sysMapService.saveOrUpdate("userTeamggroup",entity.getId(),entity.getTeamgroupIds());
            sysMapService.saveOrUpdate("userShip",entity.getId(),entity.getShipIds());
        }else{
            result = "该用户名已经被注册,请修改登录用户名!";
        }
 
        return Result.ok(result);
    }
 
    @PostMapping("test")
    @ApiOperation("新增")
    @LogOperation("用户管理--->新增")
    //@RequiresPermissions("sys:user")
    public Result<String> test(@RequestBody SysUserReg  entity) {
        sysUserRegService.test(entity);
        return Result.ok();
    }
}