郑永安
2023-08-30 af0956c9c4e28a80a81b6707bc2224fc01360bf7
src/main/java/com/gk/hotwork/Controller/UserController.java
@@ -16,6 +16,7 @@
import com.gk.hotwork.Domain.Vo.WorkCertVo;
import com.gk.hotwork.Service.*;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -60,6 +61,8 @@
    private BlackListService blackListService;
    @Autowired
    private DeviceLocationService deviceLocationService;
    @Autowired
    private SpecialityService specialityService;
    @Value("${workname}")
    private String workname;
    @Value("${workCert}")
@@ -134,6 +137,167 @@
        pageInfo.setCondition(condition);
        userService.selectUserDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
    @GetMapping("/company/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 = "company",value = "企业名称"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证号"),
            @ApiImplicitParam(name = "job",value = "身份证号"),
    })
    public Msg getCompanyUserInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort,String order,
                           String username,String company,String realname, String idcard, String job){
        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());
        }
        if (StringUtils.isNotBlank(company)) {
            condition.put("company", company.trim());
        }
        if (StringUtils.isNotBlank(realname)){
            condition.put("realname",realname.trim());
        }
        if (StringUtils.isNotBlank(idcard)){
            condition.put("idcard",idcard.trim());
        }
        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);
        msg.setResult(pageInfo);
        return msg;
    }
    @GetMapping("/supervise/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 = "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 province,String city,String county){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        UserInfo userInfoCurrent = userService.selectByUser(getUser().getUsername());
        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());
        }
        if (StringUtils.isNotBlank(company)) {
            condition.put("company", company.trim());
        }
        if (StringUtils.isNotBlank(realname)){
            condition.put("realname",realname.trim());
        }
        if (StringUtils.isNotBlank(idcard)){
            condition.put("idcard",idcard.trim());
        }
        if (StringUtils.isNotBlank(province)){
            condition.put("province",province.trim());
            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());
            }
        }
        pageInfo.setCondition(condition);
        userService.selectSuperviseUserDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
    @GetMapping("/expert/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 = "company",value = "单位名称"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证号"),
    })
    public Msg getExpertUserInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort,String order,
                                    String username,String company,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());
        }
        if (StringUtils.isNotBlank(company)) {
            condition.put("company", company.trim());
        }
        if (StringUtils.isNotBlank(realname)){
            condition.put("realname",realname.trim());
        }
        if (StringUtils.isNotBlank(idcard)){
            condition.put("idcard",idcard.trim());
        }
        pageInfo.setCondition(condition);
        userService.selectExpertUserDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
@@ -329,6 +493,818 @@
        userService.save(userInfo);
        return msg;
    }
    /**
     * 专家用户-新增
     * @param jsonObject
     * @return
     */
    @PostMapping("/add/expert/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 = "身份证"),
            @ApiImplicitParam(name = "specialityId",value = "专业方向id"),
            @ApiImplicitParam(name = "professionalLevel",value = "职称"),
    })
    public Msg addExpertUserInfo(@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;
            }
        }
        Integer professionalLevel = jsonObject.getInteger("professionalLevel");
        if (professionalLevel == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("职称参数为空");
            return msg;
        }
        Long specialityId = jsonObject.getLong("specialityId");
        if (specialityId == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("专业参数为空");
            return msg;
        }
        SpecialityInfo specialityInfo = specialityService.getById(specialityId);
        if (specialityInfo == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("专业不存在");
            return msg;
        }
        userInfo.setCompany(jsonObject.getString("company"));
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setSpecialityId(specialityId);
        userInfo.setProfessionalLevel(professionalLevel);
        userInfo.setJob(jsonObject.getString("job"));
        userInfo.setStatus((byte)1);
        userInfo.setType(4);
        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();
        userRolesInfo.setRoleid(36l);
        userRolesInfo.setUserid(user.getId());
        userRolesService.save(userRolesInfo);
        return msg;
    }
    /**
     * 专家用户-修改
     * @param jsonObject
     * @return
     */
    @PostMapping("/put/expert/user")
    @ApiOperation(value = "修改专家用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",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 = "身份证"),
            @ApiImplicitParam(name = "specialityId",value = "专业方向id"),
            @ApiImplicitParam(name = "professionalLevel",value = "职称"),
    })
    public Msg putExpertUserInfo(@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(id,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;
            }
        }
        Integer professionalLevel = jsonObject.getInteger("professionalLevel");
        if (professionalLevel == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("职称参数为空");
            return msg;
        }
        Long specialityId = jsonObject.getLong("specialityId");
        if (specialityId == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("专业参数为空");
            return msg;
        }
        SpecialityInfo specialityInfo = specialityService.getById(specialityId);
        if (specialityInfo == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("专业不存在");
            return msg;
        }
        List<UserInfo> userInfoExist = userService.selectUserInfo(userInfo.getId(),userInfo.getUsername());
        if (userInfoExist.size() > 0){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("用户名重复");
            return msg;
        }
        userInfo.setCompany(jsonObject.getString("company"));
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setSpecialityId(specialityId);
        userInfo.setProfessionalLevel(professionalLevel);
        userInfo.setJob(jsonObject.getString("job"));
        userInfo.setStatus((byte)1);
        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);
        int userSize = userService.selectUserSize();
        int sli = (userSize + 1) % sliceSize;
        userInfo.setSlice(sli + "");
        if (sli == 0)
            userInfo.setSlice(sliceSize + "");
        userService.updateById(userInfo);
        return msg;
    }
    /**
     * 企业用户-新增
     * @param jsonObject
     * @return
     */
    @PostMapping("/add/company/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 = "companyid",value = "单位"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证"),
    })
    public Msg addCompanyUserInfo(@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;
            }
        }
        Long companyid = jsonObject.getLong("companyid");
        if (companyid == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("单位参数为空");
            return msg;
        }
        CompanyInfo companyInfo = companyService.getById(companyid);
        if (companyInfo == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("单位不存在");
            return msg;
        }
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setCompany(companyInfo.getCompany());
        userInfo.setCompanyid(companyid);
        userInfo.setJob(jsonObject.getString("job"));
        userInfo.setStatus((byte)1);
        userInfo.setType(3);
        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();
        userRolesInfo.setRoleid(35l);
        userRolesInfo.setUserid(user.getId());
        userRolesService.save(userRolesInfo);
        return msg;
    }
    /**
     * 企业用户-修改
     * @param jsonObject
     * @return
     */
    @PostMapping("/put/company/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 = "companyid",value = "单位"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证"),
    })
    public Msg putCompanyUserInfo(@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;
            }
        }
        Long companyid = jsonObject.getLong("companyid");
        if (companyid == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("单位参数为空");
            return msg;
        }
        CompanyInfo companyInfo = companyService.getById(companyid);
        if (companyInfo == null) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("单位不存在");
            return msg;
        }
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setCompany(companyInfo.getCompany());
        userInfo.setCompanyid(companyInfo.getId());
        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;
    }
    /**
     * 监管用户-新增
     * @param jsonObject
     * @return
     */
    @PostMapping("/add/supervise/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 = "job",value = "职务"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证"),
            @ApiImplicitParam(name = "executiveLevel",value = "行政级别 "),
            @ApiImplicitParam(name = "province",value = "省(自治区)"),
            @ApiImplicitParam(name = "city",value = "地(市、州)"),
            @ApiImplicitParam(name = "county",value = "区/县"),
    })
    public Msg addSuperviseUserInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        UserInfo userInfo = new UserInfo();
        UserInfo userInfoCurrent = userService.selectByUser(getUser().getUsername());
        Integer executiveLevel = jsonObject.getInteger("executiveLevel");
        if (executiveLevel == null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("行政级别不能为空");
            return msg;
        }
        String province = jsonObject.getString("province");
        if (StringUtils.isBlank(province)){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("省(自治区)不能为空");
            return msg;
        }
        String city = jsonObject.getString("city");
        if (executiveLevel == 2 && StringUtils.isBlank(city)){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("地(市、州)不能为空");
            return msg;
        }else {
            userInfo.setCity(city);
        }
        String county = jsonObject.getString("county");
        if (executiveLevel == 3 && (StringUtils.isBlank(city) || StringUtils.isBlank(county))){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("区/县不能为空");
            return msg;
        }else {
            userInfo.setCounty(county);
        }
        if(userInfoCurrent.getType().equals(3) || userInfoCurrent.getType().equals(4)){
            msg.setCode(ErrorCode.ERROR_70001.getCode());
            msg.setMessage("专家或企业用户无权限新增监管用户信息");
            return msg;
        }
        //管理员(监管)
        if(userInfoCurrent.getType().equals(2)){
            //判断当前用户是否有权限新增其管辖下监管机构用户
            Integer currentUserExLevl = userInfoCurrent.getExecutiveLevel();
            if(currentUserExLevl < executiveLevel){
                if(currentUserExLevl == 1){
                    if(!userInfoCurrent.getProvince().equals(province)){
                        msg.setCode(ErrorCode.ERROR_10004.getCode());
                        msg.setMessage("无权新增非自己管辖地区");
                        return msg;
                    }
                }
                if(currentUserExLevl == 2){
                    if(!userInfoCurrent.getProvince().equals(province) || !userInfoCurrent.getCity().equals(city)){
                        msg.setCode(ErrorCode.ERROR_10004.getCode());
                        msg.setMessage("无权新增非自己管辖地区");
                        return msg;
                    }
                }
                if(currentUserExLevl == 3){
                    msg.setCode(ErrorCode.ERROR_10004.getCode());
                    msg.setMessage("当前用户是区县级,无法再新增下一级监管部门");
                    return msg;
                }
            }else {
                msg.setCode(ErrorCode.ERROR_10004.getCode());
                msg.setMessage("当前用户是无权限新增同级、上一级监管部门");
                return msg;
            }
        }
        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 companyName = province + (StringUtils.isBlank(city) ? "" : city) + (StringUtils.isBlank(county) ? "" : county) + "应急管理局";
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setProvince(province);
        userInfo.setExecutiveLevel(executiveLevel);
        userInfo.setCompany(companyName);
        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();
        userRolesInfo.setRoleid(38l);
        userRolesInfo.setUserid(user.getId());
        userRolesService.save(userRolesInfo);
        return msg;
    }
    /**
     * 监管用户-修改
     * @param jsonObject
     * @return
     */
    @PostMapping("/put/supervise/user")
    @ApiOperation(value = "修改监管用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id",required = true),
            @ApiImplicitParam(name = "username",value = "手机号",required = true),
            @ApiImplicitParam(name = "password",value = "密码"),
            @ApiImplicitParam(name = "email",value = "邮箱"),
            @ApiImplicitParam(name = "job",value = "职务"),
            @ApiImplicitParam(name = "realname",value = "姓名"),
            @ApiImplicitParam(name = "idcard",value = "身份证"),
            @ApiImplicitParam(name = "executiveLevel",value = "行政级别"),
            @ApiImplicitParam(name = "province",value = "省(自治区)"),
            @ApiImplicitParam(name = "city",value = "地(市、州)"),
            @ApiImplicitParam(name = "county",value = "区/县"),
    })
    public Msg putSuperviseUserInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        UserInfo userInfo = new UserInfo();
        UserInfo userInfoCurrent = userService.selectByUser(getUser().getUsername());
        Integer executiveLevel = jsonObject.getInteger("executiveLevel");
        if (executiveLevel == null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("行政级别不能为空");
            return msg;
        }
        String province = jsonObject.getString("province");
        if (StringUtils.isBlank(province)){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("省(自治区)不能为空");
            return msg;
        }
        String city = jsonObject.getString("city");
        if (executiveLevel == 2 && StringUtils.isBlank(city)){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("地(市、州)不能为空");
            return msg;
        }
        String county = jsonObject.getString("county");
        if (executiveLevel == 3 && (StringUtils.isBlank(city) || StringUtils.isBlank(county))){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("区/县不能为空");
            return msg;
        }else {
            userInfo.setCounty(county);
        }
        Long id = jsonObject.getLong("id");
        if(id == null){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("用户主键id不能为空");
            return msg;
        }
        userInfo.setId(id);
        if(userInfoCurrent.getType().equals(3) || userInfoCurrent.getType().equals(4)){
            msg.setCode(ErrorCode.ERROR_70001.getCode());
            msg.setMessage("专家或企业用户无权限新增监管用户信息");
            return msg;
        }
        //监管用户 、自己要验证
        if(userInfoCurrent.getType().equals(2) && (!id .equals(userInfoCurrent.getId()))){
            //判断当前用户是否有权限新增其管辖下监管机构用户
            Integer currentUserExLevl = userInfoCurrent.getExecutiveLevel();
            if(currentUserExLevl < executiveLevel){
                if(currentUserExLevl == 1){
                    if(!userInfoCurrent.getProvince().equals(province)){
                        msg.setCode(ErrorCode.ERROR_10004.getCode());
                        msg.setMessage("无权新增非自己管辖地区");
                        return msg;
                    }
                }
                if(currentUserExLevl == 2){
                    if(!userInfoCurrent.getProvince().equals(province) || !userInfoCurrent.getCity().equals(city)){
                        msg.setCode(ErrorCode.ERROR_10004.getCode());
                        msg.setMessage("无权新增非自己管辖地区");
                        return msg;
                    }
                }
                if(currentUserExLevl == 3){
                    msg.setCode(ErrorCode.ERROR_10004.getCode());
                    msg.setMessage("当前用户是区县级,无权修改监管部门");
                    return msg;
                }
            }else {
                msg.setCode(ErrorCode.ERROR_10004.getCode());
                msg.setMessage("当前用户是无权限修改同级、上一级监管部门");
                return msg;
            }
        }
        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;
            }
        }
        //自己无法修改行政级别
        if (userInfoCurrent.getId().equals(id) && !userInfoCurrent.getExecutiveLevel().equals(executiveLevel)) {
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("自己无法修改行政级别");
            return msg;
        }else{
            userInfo.setExecutiveLevel(executiveLevel);
        }
        String companyName = province + (StringUtils.isBlank(city) ? "" : city) + (StringUtils.isBlank(county) ? "" : county) + "应急管理局";
        userInfo.setEmail(jsonObject.getString("email"));
        userInfo.setProvince(province);
        userInfo.setCity(StringUtils.isBlank(city) ? "" :city);
        userInfo.setCounty(StringUtils.isBlank(county) ? "" :county);
        userInfo.setCompany(companyName);
        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;
    }
    @PostMapping("/importUser")
    @ApiOperation(value = "导入用户数据",response = Msg.class)
@@ -803,8 +1779,15 @@
        if (StringUtils.isNotBlank(company)) {
            condition.put("company", company.trim());
        }
        if (StringUtils.isNotBlank(province)) {
        if(getUser().getType() == 3){
            condition.put("companyid", getUser().getCompanyid());
        }
        if(getUser().getType() == 2){
            condition.put("province", getUser().getProvince());
            condition.put("city", getUser().getCity());
            condition.put("area", getUser().getCounty());
        }
        /*if (StringUtils.isNotBlank(province)) {
            condition.put("province", province.trim());
        }
@@ -822,11 +1805,11 @@
        if (StringUtils.isNotBlank(community)) {
            condition.put("community", community.trim());
        }
        UserInfo userInfo = userService.selectByUser(getUser().getUsername());
        }*/
        /*UserInfo userInfo = userService.selectByUser(getUser().getUsername());
        if (!companyService.isMain(userInfo.getCompany())){
            condition.put("company",userInfo.getCompany());
        }
        }*/
        //是系统菜单下的就显示主体,否则非主体
//        if (isMain) {
//            condition.put("isMain", 1);
@@ -835,6 +1818,9 @@
//        }
        pageInfo.setCondition(condition);
        companyService.selectDataGrid(pageInfo);
        if(getUser().getType() ==4 ){
            pageInfo.setResult(new ArrayList());
        }
        msg.setResult(pageInfo);
        return msg;
    }
@@ -851,7 +1837,106 @@
        return msg;
    }
    /**
     * 企业-新增
     * @param jsonObject
     * @return
     */
    @PostMapping("/addCompany")
    @ApiOperation(value = "添加企业信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code",value = "单位代码"),
            @ApiImplicitParam(name = "company",value = "单位名称"),
            @ApiImplicitParam(name = "contactname",value = "联系人"),
            @ApiImplicitParam(name = "contactphone",value = "联系电话"),
            @ApiImplicitParam(name = "province",value = "省份"),
            @ApiImplicitParam(name = "city",value = "城市"),
            @ApiImplicitParam(name = "area",value = "区县"),
            @ApiImplicitParam(name = "town",value = "街道"),
            @ApiImplicitParam(name = "community",value = "社区"),
    })
    public Msg addCompanyInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        CompanyInfo companyInfo = new CompanyInfo();
        companyInfo.setCode(jsonObject.getString("code"));
        companyInfo.setCompany(jsonObject.getString("company"));
        companyInfo.setContactname(jsonObject.getString("contactname"));
        companyInfo.setContactphone(jsonObject.getString("contactphone"));
        companyInfo.setProvince(jsonObject.getString("province"));
        companyInfo.setCity(jsonObject.getString("city"));
        companyInfo.setArea(jsonObject.getString("area"));
        companyInfo.setTown(jsonObject.getString("town"));
        companyInfo.setCommunity(jsonObject.getString("community"));
        companyInfo.setCreatedby(getUser().getRealname());
        companyInfo.setCreateddate(new Date());
        companyInfo.setLastmodifiedby(getUser().getRealname());
        companyInfo.setLastmodifieddate(new Date());
        companyInfo.setIsdel((byte)0);
        CompanyInfo companyInfoExist = companyService.selectExistByName(null,companyInfo.getCompany());
        if (null != companyInfoExist){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("单位名称重复");
            return msg;
        }else {
            companyService.save(companyInfo);
        }
        return msg;
    }
    /**
     * 企业-修改
     * @param jsonObject
     * @return
     */
    @PostMapping("/putCompany")
    @ApiOperation(value = "修改企业信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "单位主键"),
            @ApiImplicitParam(name = "code",value = "单位代码"),
            @ApiImplicitParam(name = "company",value = "单位名称"),
            @ApiImplicitParam(name = "contactname",value = "联系人"),
            @ApiImplicitParam(name = "contactphone",value = "联系电话"),
            @ApiImplicitParam(name = "province",value = "省份"),
            @ApiImplicitParam(name = "city",value = "城市"),
            @ApiImplicitParam(name = "area",value = "区县"),
            @ApiImplicitParam(name = "town",value = "街道"),
            @ApiImplicitParam(name = "community",value = "社区"),
    })
    public Msg putCompanyInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        CompanyInfo companyInfo = new CompanyInfo();
        companyInfo.setId(jsonObject.getLong("id"));
        companyInfo.setCode(jsonObject.getString("code"));
        companyInfo.setCompany(jsonObject.getString("company"));
        companyInfo.setContactname(jsonObject.getString("contactname"));
        companyInfo.setContactphone(jsonObject.getString("contactphone"));
        companyInfo.setProvince(jsonObject.getString("province"));
        companyInfo.setCity(jsonObject.getString("city"));
        companyInfo.setArea(jsonObject.getString("area"));
        companyInfo.setTown(jsonObject.getString("town"));
        companyInfo.setCommunity(jsonObject.getString("community"));
        companyInfo.setLastmodifiedby(getUser().getRealname());
        companyInfo.setLastmodifieddate(new Date());
        companyInfo.setIsdel((byte)0);
        CompanyInfo companyInfoExist = companyService.selectExistByName(companyInfo.getId(),companyInfo.getCompany());
        if (null != companyInfoExist){
            msg.setCode(ErrorCode.ERROR_10004.getCode());
            msg.setMessage("单位名称重复");
            return msg;
        }else {
            companyService.updateById(companyInfo);
        }
        return msg;
    }
    /*@PostMapping("/addCompany")
    @ApiOperation(value = "添加单位信息",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code",value = "单位代码"),
@@ -971,6 +2056,7 @@
        }
        return msg;
    }
     */
    @PostMapping("/delCompany")
    @ApiOperation(value = "删除单位信息", notes = "删除单位信息", response = Msg.class)
@@ -1597,4 +2683,286 @@
        String password = accountBody.getString("department");
        return success(userService.getAccount(username, password));
    }
    /**
     * 获取专家用户列表
     */
    @GetMapping("/expert/list")
    @ApiOperation(value = "获取专家用户数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "realname",value = "姓名"),
    })
    public Msg getExpertUserList(String realname){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        msg.setResult(userService.selectExpertList(realname));
        return msg;
    }
    /**
     * 获取监管辖区内的企业
     */
    @GetMapping("/company/list")
    @ApiOperation(value = "获取监管辖区企业数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyName",value = "企业名称"),
    })
    public Msg getCompanyList(String companyName){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        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;
    }
}