郑永安
2023-08-30 af0956c9c4e28a80a81b6707bc2224fc01360bf7
src/main/java/com/gk/hotwork/Controller/UserController.java
@@ -180,7 +180,10 @@
        if (StringUtils.isNotBlank(job)){
            condition.put("job",job.trim());
        }
        Integer type = getUser().getType();
        if(type.equals(3)){
            condition.put("companyid",getUser().getCompanyid());
        }
        pageInfo.setCondition(condition);
        userService.selectCompanyUserDataGrid(pageInfo);
@@ -198,9 +201,12 @@
            @ApiImplicitParam(name = "company",value = "单位名称"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证号"),
            @ApiImplicitParam(name = "province",value = "省"),
            @ApiImplicitParam(name = "city",value = "市"),
            @ApiImplicitParam(name = "county",value = "县"),
    })
    public Msg getSuperviseUserInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort,String order,
                                  String username,String company,String realname, String idcard){
                                  String username,String company,String realname, String idcard, String province,String city,String county){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
@@ -223,16 +229,29 @@
        if (StringUtils.isNotBlank(idcard)){
            condition.put("idcard",idcard.trim());
        }
        if (StringUtils.isNotBlank(province)){
            condition.put("province",province.trim());
        if(StringUtils.isNotBlank(userInfoCurrent.getProvince())){
            condition.put("province", userInfoCurrent.getProvince());
            if(StringUtils.isNotBlank(city)){
                condition.put("city", city);
            }
            if(StringUtils.isNotBlank(county)){
                condition.put("county", county);
            }
        }else {
            if(StringUtils.isNotBlank(userInfoCurrent.getProvince())){
                condition.put("province", userInfoCurrent.getProvince());
            }
            if(StringUtils.isNotBlank(userInfoCurrent.getCity())){
                condition.put("city", userInfoCurrent.getCity());
            }
            if(StringUtils.isNotBlank(userInfoCurrent.getCounty())){
                condition.put("county", userInfoCurrent.getCounty());
            }
        }
        if(StringUtils.isNotBlank(userInfoCurrent.getCity())){
            condition.put("city", userInfoCurrent.getCity());
        }
        if(StringUtils.isNotBlank(userInfoCurrent.getCounty())){
            condition.put("county", userInfoCurrent.getCounty());
        }
        pageInfo.setCondition(condition);
        userService.selectSuperviseUserDataGrid(pageInfo);
@@ -2683,9 +2702,6 @@
    /**
     * 获取监管辖区内的企业
     */
    /**
     * 获取专家用户列表
     */
    @GetMapping("/company/list")
    @ApiOperation(value = "获取监管辖区企业数据",response = Msg.class)
    @ApiImplicitParams({
@@ -2698,4 +2714,255 @@
        msg.setResult(companyService.selectCompanyList(companyName,getUser()));
        return msg;
    }
    /**
     * 安科院用户-新增
     * @param jsonObject
     * @return
     */
    @PostMapping("/add/safetyInstitute/user")
    @ApiOperation(value = "添加安科院用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "手机号",required = true),
            @ApiImplicitParam(name = "password",value = "密码",required = true),
            @ApiImplicitParam(name = "email",value = "邮箱"),
            @ApiImplicitParam(name = "company",value = "单位名称"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证"),
    })
    public Msg addSafetyInstituteUserInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        UserInfo userInfo = new UserInfo();
        String password = jsonObject.getString("password");
        String PW_PATTERN = "(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,}";
        if (!password.matches(PW_PATTERN)){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("密码必须8位以上,并且包含大小写字母、数字、特殊符号三种以上");
            return msg;
        }else {
            userInfo.setPassword(MD5Utils.encode(password));
        }
        String username = jsonObject.getString("username");
        if (StringUtils.isNotBlank(username) && username.length() == 11){
            userInfo.setUsername(username);
        }else{
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("手机号必须为11位数");
            return msg;
        }
        String realname = jsonObject.getString("realname");
        if (StringUtils.isBlank(realname)){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("姓名不能为空");
            return msg;
        }
        String idcard = jsonObject.getString("idcard");
        if (StringUtils.isNotBlank(idcard)){
            UserInfo idCardExist = userService.selectByIdCard(null,idcard);
            if (null != idCardExist){
                msg.setCode(ErrorCode.ERROR_10004.getCode());
                msg.setMessage("身份证重复");
                return msg;
            }else{
                userInfo.setIdcard(idcard);
            }
            if (!IdCardUtil.strongVerifyIdNumber(idcard)) {
                msg.setCode(ErrorCode.ERROR_10004.getCode());
                msg.setMessage("身份证非法");
                return msg;
            }
        }
        String company = jsonObject.getString("company");
        CompanyInfo companyInfo = companyService.selectByName(company);
        if (companyInfo != null) {
           userInfo.setCompanyid(companyInfo.getId());
            userInfo.setCompany(companyInfo.getCompany());
        }
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setJob(jsonObject.getString("job"));
        userInfo.setStatus((byte)1);
        userInfo.setType(2);
        userInfo.setCreatedby(getUser().getRealname());
        userInfo.setRealname(realname);
        userInfo.setCreateddate(new Date());
        userInfo.setLastmodifiedby(getUser().getRealname());
        userInfo.setLastmodifieddate(new Date());
        userInfo.setIsdel((byte)0);
        userInfo.setIsupload((byte)0);
        List<UserInfo> userInfoExist = userService.selectUserInfo(null,userInfo.getUsername());
        if (userInfoExist.size() > 0){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("用户名重复");
            return msg;
        }
        int userSize = userService.selectUserSize();
        int sli = (userSize + 1) % sliceSize;
        userInfo.setSlice(sli + "");
        if (sli == 0)
            userInfo.setSlice(sliceSize + "");
        userService.save(userInfo);
        UserInfo user = userService.selectByUser(userInfo.getUsername());
        UserRolesInfo userRolesInfo = new UserRolesInfo();
        List<RoleInfo> list = roleService.selectPageForRole("安科院", 0, 10000);
        if(list.isEmpty() || list.size()==0){
            msg.setCode(ErrorCode.ERROR_50004.getCode());
            msg.setMessage("安科院角色不存在");
        }
        userRolesInfo.setRoleid(list.get(0).getId());
        userRolesInfo.setUserid(user.getId());
        userRolesService.save(userRolesInfo);
        return msg;
    }
    /**
     * 安科院用户-修改
     * @param jsonObject
     * @return
     */
    @PostMapping("/put/safetyInstitute/user")
    @ApiOperation(value = "修改安科院用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id",required = true),
            @ApiImplicitParam(name = "username",value = "手机号",required = true),
            @ApiImplicitParam(name = "password",value = "密码",required = true),
            @ApiImplicitParam(name = "email",value = "邮箱"),
            @ApiImplicitParam(name = "company",value = "单位"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证"),
    })
    public Msg putSafetyInstituteUserInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        UserInfo userInfo = new UserInfo();
        Long id = jsonObject.getLong("id");
        if (id == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("主键参数为空");
            return msg;
        }else {
            userInfo.setId(id);
        }
        String password = jsonObject.getString("password");
        String PW_PATTERN = "(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,}";
        if (StringUtils.isNotBlank(password)){
            if (!password.matches(PW_PATTERN)){
                msg.setCode(ErrorCode.ERROR_10004.getCode());
                msg.setMessage("密码必须8位以上,并且包含大小写字母、数字、特殊符号三种以上");
                return msg;
            }else {
                userInfo.setPassword(MD5Utils.encode(password));
            }
        }
        String username = jsonObject.getString("username");
        if (StringUtils.isNotBlank(username) && username.length() == 11){
            userInfo.setUsername(username);
        }else{
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("手机号必须为11位数");
            return msg;
        }
        String realname = jsonObject.getString("realname");
        if (StringUtils.isBlank(realname)){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("姓名不能为空");
            return msg;
        }
        String idcard = jsonObject.getString("idcard");
        if (StringUtils.isNotBlank(idcard)){
            UserInfo idCardExist = userService.selectByIdCard(userInfo.getId(),idcard);
            if (null != idCardExist){
                msg.setCode(ErrorCode.ERROR_10004.getCode());
                msg.setMessage("身份证重复");
                return msg;
            }else{
                userInfo.setIdcard(idcard);
            }
            if (!IdCardUtil.strongVerifyIdNumber(idcard)) {
                msg.setCode(ErrorCode.ERROR_10004.getCode());
                msg.setMessage("身份证非法");
                return msg;
            }
        }
        String company = jsonObject.getString("company");
        CompanyInfo companyInfo = companyService.selectByName(company);
        if (companyInfo != null) {
           userInfo.setCompanyid(companyInfo.getId());
        }
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setCompany(company);
        userInfo.setJob(jsonObject.getString("job"));
        userInfo.setLastmodifiedby(getUser().getRealname());
        userInfo.setLastmodifieddate(new Date());
        userInfo.setIsdel((byte)0);
        userInfo.setRealname(realname);
        List<UserInfo> userInfoExist = userService.selectUserInfo(userInfo.getId(),userInfo.getUsername());
        if (userInfoExist.size() > 0){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("用户名重复");
            return msg;
        }
        userService.updateById(userInfo);
        return msg;
    }
    @GetMapping("/safetyInstitute/user/list")
    @ApiOperation(value = "获取安科院用户数据-分页",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "sort",value = "排序规则"),
            @ApiImplicitParam(name = "order",value = "排序字段"),
            @ApiImplicitParam(name = "username",value = "用户名"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证号"),
    })
    public Msg getSafetyInstituteUserInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort,String order,
                                  String username,String realname, String idcard){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
        HashMap<String, Object> condition = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(username)) {
            condition.put("username", username.trim());
        }
        condition.put("company", "安科院");
        if (StringUtils.isNotBlank(realname)){
            condition.put("realname",realname.trim());
        }
        if (StringUtils.isNotBlank(idcard)){
            condition.put("idcard",idcard.trim());
        }
        pageInfo.setCondition(condition);
        userService.selectUserDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
}