From 58fc5c5043427bdb707bf263dd03a89b5e13b788 Mon Sep 17 00:00:00 2001 From: "277151821@qq.com" <277151821@qq.com> Date: Mon, 29 Apr 2024 08:35:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E4=BF=AE=E6=94=B9=E3=80=81=E4=BB=8E=E4=B8=9A=E4=BA=BA?= =?UTF-8?q?=E5=91=98=20=E4=BA=BA=E5=91=98=E7=B1=BB=E5=9E=8B=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/UsersController.java | 288 ++++++++++++++++++ .../datasource/system/UserInfoMapper.java | 3 + .../service/system/UserInfoService.java | 4 + .../system/impl/UserInfoServiceImpl.java | 8 + .../service/system/impl/UsersServiceImpl.java | 9 + .../datasource/system/UserInfoMapper.xml | 23 +- .../mybatis/datasource/system/UsersMapper.xml | 8 +- 7 files changed, 338 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/zcloud/controller/system/UsersController.java b/src/main/java/com/zcloud/controller/system/UsersController.java index 394b35c..5d575cb 100644 --- a/src/main/java/com/zcloud/controller/system/UsersController.java +++ b/src/main/java/com/zcloud/controller/system/UsersController.java @@ -2778,6 +2778,17 @@ public class UsersController extends BaseController { pd.put("AUTHENTICATION", "0"); userInfoService.delete(pd); userInfoService.save(pd); + + PageData pdd = new PageData(); + pdd.put("USER_ID", pd.getString("USER_ID")); + userInfoService.delUserInfoPersonnelType(pdd); + String[] PERSONNEL_TYPES = pd.getString("PERSONNEL_TYPE").split(","); + for (String str : PERSONNEL_TYPES) { + pdd.put("ID", Warden.get32UUID()); + pdd.put("PERSONNEL_TYPE", str); + userInfoService.addUserInfoPersonnelType(pdd); + } + // 如果修改了部门/岗位,将该用户所有清单都删除 if (pd.get("OPERATIONTYPE") != null && pd.get("OPERATIONTYPE").toString() != null && Tools.notEmpty(pd.get("OPERATIONTYPE").toString())) { List listIds = listManagerService.listListByUser(pd); @@ -3038,4 +3049,281 @@ public class UsersController extends BaseController { map.put("result", errInfo); return map; } + + + /** + * 从EXCEL导入到数据库 + * + * @param file + * @return + * @throws Exception + */ + @RequestMapping(value = "/readExcel4") +// // @RequiresPermissions("fromExcel") + @SuppressWarnings("unchecked") + @ResponseBody + @Transactional + @LogAnno(menuType = "双重预防", menuServer = "企业管理", instructionsOperate = "用户管理", instructionsType = "从EXCEL导入到数据库") + public Object readExcel4(@RequestParam(value = "FFILE", required = false) MultipartFile file) throws Exception { + Map map = new HashMap(); + String errInfo = "success"; + StringBuffer errorStr = new StringBuffer(); + + if (null != file && !file.isEmpty()) { + File tempFile = new File(file.getOriginalFilename()); //新建file + FileUtils.copyInputStreamToFile(file.getInputStream(), tempFile); //将MultipartFile复制到File + List listPd = (List) ObjectExcelRead.readExcel(tempFile, 1, 0, 0); //执行读EXCEL操作,读出的数据导入List 2:从第3行开始;0:从第A列开始;0:第0个sheet + /** + * var0 :部门 + * var1 :岗位 + * var2 :手机号 + * var3 :姓名 + * var4 :身份证号 + * var5 :人员类型 + */ + + List header = new ArrayList(); + header.add("部门"); + header.add("岗位"); + header.add("手机号"); + header.add("姓名"); + header.add("身份证号"); + header.add("人员类型"); + + try { + if (listPd.size() > 0 && listPd.size() <= 1000) { + + /** 获取企业下的所有部门信息*/ + PageData departPd = new PageData(); + departPd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); + List userInfoMap = usersService.getUserCardNoAll(departPd); + HashMap userInfos = new HashMap<>(); + + for (PageData pageData : userInfoMap) { + userInfos.put(pageData.getString("CARDNO"), pageData.getString("USERNAME")); + } + List departList = departmentService.listAll(departPd); + Map departMap = new HashMap(); + for (PageData pageData : departList) { + departMap.put(Tools.excelHandle(pageData.getString("NAME")), pageData); + } + /** 获取所有岗位信息 */ + PageData postPd = new PageData(); + postPd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); + List postList = postService.listAll(postPd); + Map> postMap = new HashMap<>(); //部门id,岗位map + for (PageData pageData : postList) { + Map postValMap = new HashMap<>(); + String postDept = pageData.getString("DEPARTMENT_ID"); + if (postMap.containsKey(postDept)) { + postValMap = postMap.get(postDept); + } + postValMap.put(Tools.excelHandle(pageData.getString("NAME")), pageData); + postMap.put(postDept, postValMap); + } + /** 获取所有岗位信息结束 */ + + /** 获取所有用户信息 用于判断姓名是否重复 */ + PageData userPd = new PageData(); + userPd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); + List userList = usersService.findUserNameAll(userPd); + List userEList = usersService.findAllUser(userPd); + Map userMap = new HashMap<>(); + Map emailMap = new HashMap<>(); + for (PageData pageData : userList) { + userMap.put(pageData.getString("USERNAME"), JSON.toJSONString(pageData)); + } + for (PageData pageData : userEList) { + emailMap.put(pageData.getString("USERNAME"), ""); + } + PageData rolePd = new PageData(); + rolePd.put("ISMAIN", "0"); + rolePd.put("PARENT_ID", Jurisdiction.getVIPLEVEL()); + rolePd.put("ROLE_NAME", "个人账号"); + PageData role = roleService.findByPidAndMain(rolePd); + if (Tools.isEmpty(role)) { + errorStr.append("未找到默认角色信息!请联系管理员"); + map.put("result", errInfo); //返回结果 + map.put("msg", ""); //返回结果 + return map; + } + /** + * 判断是否填写必填 + * 判断excel是有有重复数据 + * 判断数据库是否有重复数据 + * 导入 Page + * + * 企业分级账号 + */ + Map hasUserNameChongfu = new HashMap<>();//判断重复数据 + + Map emailChongfu = new HashMap<>();//判断重复数据 + Integer number = 0;//行数,用于提示用户 + List addUserList = new ArrayList<>(); + List editUserList = new ArrayList<>(); + for (PageData lpd : listPd) { + number++; + for (int i = 0; i < 6; i++) { + if (Tools.isEmpty(lpd.get("var" + i))) { + errorStr.append("第" + number + "行的\"" + header.get(i) + "\"无数据;\n"); + } + } + + String dept = Tools.isEmpty(lpd.get("var0")) ? "" : Tools.excelHandle(lpd.get("var0"));//部门 + String postName = Tools.isEmpty(lpd.get("var1")) ? "" : lpd.get("var1").toString();//岗位 + String userName = Tools.isEmpty(lpd.get("var2")) ? "" : lpd.get("var2").toString();//手机号 + Pattern patternPhone = Pattern.compile(RegexPatterns.PHONE_REGEX); + Matcher matcher = patternPhone.matcher(lpd.getString("var2")); + if (!matcher.matches()) { + errorStr.append("第" + number + "行,"); + errorStr.append("手机号格式不正确,请重新确认数据;\n"); + continue; + } + String name = Tools.isEmpty(lpd.get("var3")) ? "" : lpd.get("var3").toString();//姓名 + String IDNumber = Tools.isEmpty(lpd.get("var4")) ? "" : lpd.get("var4").toString();//身份证号 + Pattern patternCard = Pattern.compile(RegexPatterns.USERID_CARD); + Matcher matchercard = patternCard.matcher(lpd.getString("var4")); + if (!matchercard.matches()) { + errorStr.append("第" + number + "行,"); + errorStr.append("身份证号格式不正确,请重新确认数据;\n"); + continue; + } + String PERSONNEL_TYPE = Tools.isEmpty(lpd.get("var5")) ? "" : lpd.get("var5").toString();//人员类型 + PageData renyuanleixing = new PageData(); + if (!Tools.isEmpty(PERSONNEL_TYPE)) {//人员类型 + renyuanleixing = dictionariesService.findByName(PERSONNEL_TYPE, "0b62f92b0b624aab8e89a77304a64d5e");//人员类型 + if (null == renyuanleixing) { + errorStr.append("第" + number + "行,"); + errorStr.append("未找到人员类型信息,请重新确认数据;\n"); + continue; + } + } + + /** 部门信息 **/ + String departId = ""; + if (departMap.containsKey(dept)) { + PageData depart = (PageData) departMap.get(dept); + departId = depart.get("DEPARTMENT_ID").toString(); + } else { + errorStr.append("第" + number + "行,部门信息错误,系统未找到该部门,请重新确认数据;\n"); + continue; + } + /** 部门信息 结束**/ + /** 岗位 **/ + Map postValMap = postMap.get(departId);//这个部门下的所有岗位信息 + String postId = ""; + if (postValMap != null) { + PageData o = (PageData) postValMap.get(postName); + if (o != null) { + postId = o.getString("POST_ID"); + } + } + /** 岗位 结束**/ + + if (hasUserNameChongfu.containsKey(userName)) { + errorStr.append("第" + number + "行,"); + errorStr.append("手机号重复,请重新确认数据;\n"); + continue; + } + + hasUserNameChongfu.put(userName, name); + + PageData user = new PageData(); + user.put("USER_ID", this.get32UUID()); + user.put("USERNAME", userName); + user.put("USER_ID_CARD", IDNumber); + user.put("PERSONNEL_TYPE", renyuanleixing.get("DICTIONARIES_ID")); + user.put("PASSWORD", new SimpleHash("SHA-1", userName, "Aa@123456").toString()); + user.put("NAME", name); + user.put("CARDNO", ""); + user.put("ROLE_ID", role.getString("ROLE_ID")); + user.put("LAST_LOGIN", ""); + user.put("IP", ""); + user.put("STATUS", "0"); + user.put("BZ", ""); + user.put("SKIN", "pcoded-navbar navbar-image-3,navbar pcoded-header navbar-expand-lg navbar-light header-dark,"); + user.put("EMAIL", ""); + user.put("NUMBER", ""); + user.put("PHONE", ""); + user.put("ROLE_IDS", ""); + user.put("DEPARTMENT_ID", departId); + user.put("POST_ID", postId); + user.put("ISMAIN", "0"); + user.put("FUN_IDS", ""); + user.put("RIGHTS", "788664966448"); + user.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); + user.put("ISSTUDENT", "0");// 在线学习情况 + user.put("DURATION", "-1");// 工作状态持 + + if (userMap.containsKey(userName)) { + PageData useredit = JSON.parseObject(userMap.get(userName), PageData.class); + useredit.put("NAME", name); + useredit.put("CARDNO", ""); + useredit.put("USER_ID_CARD", IDNumber); + useredit.put("PERSONNEL_TYPE", renyuanleixing.get("DICTIONARIES_ID")); + useredit.put("ROLE_ID", role.getString("ROLE_ID")); + useredit.put("LAST_LOGIN", ""); + useredit.put("IP", ""); + useredit.put("STATUS", "0"); + useredit.put("BZ", ""); + useredit.put("SKIN", "pcoded-navbar navbar-image-3,navbar pcoded-header navbar-expand-lg navbar-light header-dark,"); + useredit.put("EMAIL", ""); + useredit.put("NUMBER", ""); + useredit.put("PHONE", ""); + useredit.put("ROLE_IDS", ""); + useredit.put("DEPARTMENT_ID", departId); + useredit.put("POST_ID", postId); + useredit.put("ISMAIN", "0"); + useredit.put("FUN_IDS", ""); + useredit.put("RIGHTS", "788664966448"); + useredit.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); + useredit.put("ISSTUDENT", "0");// 在线学习情况 + useredit.put("DURATION", "-1");// 工作状态持 + editUserList.add(useredit); + } else { + addUserList.add(user); + } + } + + if (Tools.isEmpty(errorStr.toString())) { + for (PageData pageData : addUserList) { + usersService.saveUser(pageData); + } + for (PageData pageData : editUserList) { +// if (PLSUtil.editUser(pageData)) { + usersService.editUser(pageData); +// } + } + errorStr.append("成功导入" + addUserList.size() + "条数据!"); + errorStr.append("成功修改" + editUserList.size() + "条数据!"); + } else { + errInfo = "error"; + } + FileUtils.deleteQuietly(tempFile);//删除临时文件 + } else { + map.put("result", "error"); //返回结果 + if(listPd.size() > 1000){ + map.put("msg", "Excel数据大于1000条不支持上传,请检查数据后,重新上传!"); + } else { + map.put("msg", "Excel数据为空,请检查数据后,重新上传!"); + } + FileUtils.deleteQuietly(tempFile);//删除临时文件 + return map; + } + } catch (Exception e) { + map.put("result", "fail"); //返回结果 + map.put("msg", e.toString()); + e.printStackTrace(); + return map; + } + + } + map.put("result", errInfo); //返回结果 + map.put("msg", errorStr.toString()); //返回结果 + map.put("isExcel", "1"); //返回类型 + map.put("resultStr", errorStr.toString()); + return map; + } + + } diff --git a/src/main/java/com/zcloud/mapper/datasource/system/UserInfoMapper.java b/src/main/java/com/zcloud/mapper/datasource/system/UserInfoMapper.java index cb04f88..81f8908 100644 --- a/src/main/java/com/zcloud/mapper/datasource/system/UserInfoMapper.java +++ b/src/main/java/com/zcloud/mapper/datasource/system/UserInfoMapper.java @@ -94,5 +94,8 @@ public interface UserInfoMapper{ * @throws Exception */ void editUserInfo(PageData pd); + + void delUserInfoPersonnelType(PageData pd); + void addUserInfoPersonnelType(PageData pd); } diff --git a/src/main/java/com/zcloud/service/system/UserInfoService.java b/src/main/java/com/zcloud/service/system/UserInfoService.java index 28049e7..f62836e 100644 --- a/src/main/java/com/zcloud/service/system/UserInfoService.java +++ b/src/main/java/com/zcloud/service/system/UserInfoService.java @@ -83,6 +83,10 @@ public interface UserInfoService{ void editAuthentication(PageData pd) throws Exception; void editUserInfo(PageData user) throws Exception; + + public void delUserInfoPersonnelType(PageData pd)throws Exception; + + public void addUserInfoPersonnelType(PageData pd)throws Exception; } diff --git a/src/main/java/com/zcloud/service/system/impl/UserInfoServiceImpl.java b/src/main/java/com/zcloud/service/system/impl/UserInfoServiceImpl.java index 0c155bc..8fafeb5 100644 --- a/src/main/java/com/zcloud/service/system/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/zcloud/service/system/impl/UserInfoServiceImpl.java @@ -149,5 +149,13 @@ public class UserInfoServiceImpl implements UserInfoService { public void editUserInfo(PageData pd) throws Exception { userinfoMapper.editUserInfo(pd); } + + public void delUserInfoPersonnelType(PageData pd)throws Exception{ + userinfoMapper.delUserInfoPersonnelType(pd); + } + + public void addUserInfoPersonnelType(PageData pd)throws Exception{ + userinfoMapper.addUserInfoPersonnelType(pd); + } } diff --git a/src/main/java/com/zcloud/service/system/impl/UsersServiceImpl.java b/src/main/java/com/zcloud/service/system/impl/UsersServiceImpl.java index d0c427a..65a3292 100644 --- a/src/main/java/com/zcloud/service/system/impl/UsersServiceImpl.java +++ b/src/main/java/com/zcloud/service/system/impl/UsersServiceImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.entity.system.User; +import com.zcloud.mapper.datasource.system.UserInfoMapper; import com.zcloud.mapper.datasource.system.UsersMapper; import com.zcloud.service.corp.CorpInfoService; import com.zcloud.service.system.*; @@ -1315,6 +1316,14 @@ public class UsersServiceImpl implements UsersService { pd.put("WORKSTATUS", ""); // pd.put("WORKPERIOD", ""); // usersMapper.saveUser(pd); + String[] PERSONNEL_TYPES = pd.getString("PERSONNEL_TYPE").split(","); + for (String str : PERSONNEL_TYPES) { + PageData pdd = new PageData(); + pdd.put("ID", Warden.get32UUID()); + pdd.put("USER_ID", pd.getString("USER_ID")); + pdd.put("PERSONNEL_TYPE", str); + userInfoService.addUserInfoPersonnelType(pdd); + } return ReturnMap.ok(); } return ReturnMap.error("保存失败"); diff --git a/src/main/resources/mybatis/datasource/system/UserInfoMapper.xml b/src/main/resources/mybatis/datasource/system/UserInfoMapper.xml index abc6380..3ec4920 100644 --- a/src/main/resources/mybatis/datasource/system/UserInfoMapper.xml +++ b/src/main/resources/mybatis/datasource/system/UserInfoMapper.xml @@ -166,8 +166,11 @@ du.NAME AS DUTIES_NAME, ti.NAME AS TITLE_NAME, w.NAME AS TYPE_OF_WORK_NAME, - pt.NAME AS PERSONNEL_TYPE_NAME - + + (SELECT GROUP_CONCAT(dic.NAME SEPARATOR ',') from SYS_DICTIONARIES dic + where dic.PARENT_ID = '0b62f92b0b624aab8e89a77304a64d5e' + and dic.BIANMA like '%TRAFFIC_EMPLOYMENT_DRIVE%' + and FIND_IN_SET(dic.DICTIONARIES_ID,f.PERSONNEL_TYPE)) as PERSONNEL_TYPE_NAME from f left join SYS_DICTIONARIES s on s.DICTIONARIES_ID = f.SEX @@ -176,7 +179,7 @@ left join SYS_DICTIONARIES d on d.DICTIONARIES_ID = f.DEGREE_OF_EDUCATION left join SYS_DICTIONARIES_CORP du on du.DICTIONARIES_ID = f.DUTIES left join SYS_DICTIONARIES_CORP w on w.DICTIONARIES_ID = f.TYPE_OF_WORK - left join SYS_DICTIONARIES pt on pt.DICTIONARIES_ID = f.PERSONNEL_TYPE + left join SYS_DICTIONARIES_CORP ti on ti.DICTIONARIES_ID = f.TITLE where f.USER_ID = #{USER_ID} @@ -366,4 +369,18 @@ where USER_ID = #{USER_ID} + + + insert into sys_userinfo_personnel_type + ( + ID,USER_ID,PERSONNEL_TYPE + ) values ( + #{ID},#{USER_ID},#{PERSONNEL_TYPE} + ) + + + + delete from sys_userinfo_personnel_type where USER_ID = #{USER_ID} + + diff --git a/src/main/resources/mybatis/datasource/system/UsersMapper.xml b/src/main/resources/mybatis/datasource/system/UsersMapper.xml index 5344e4d..08ac69f 100644 --- a/src/main/resources/mybatis/datasource/system/UsersMapper.xml +++ b/src/main/resources/mybatis/datasource/system/UsersMapper.xml @@ -1690,7 +1690,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ,info.DUTIES ,info.TITLE ,info.ENTRY_DATE - ,dic.`NAME` as PERSONNEL_TYPE_NAME + + ,(SELECT GROUP_CONCAT(dic.NAME SEPARATOR ',') from SYS_DICTIONARIES dic + where dic.PARENT_ID = '0b62f92b0b624aab8e89a77304a64d5e' + and dic.BIANMA like '%TRAFFIC_EMPLOYMENT_DRIVE%' + and FIND_IN_SET(dic.DICTIONARIES_ID,info.PERSONNEL_TYPE)) as PERSONNEL_TYPE_NAME ,uc.USER_CORP_ID ,uc.APPLY_TYPE ,uc.APPLY_STATUS @@ -1701,7 +1705,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join BUS_SHIFTWORKRULES sw on sw.SHIFTWORKRULES_ID = u.SHIFTDUTYONE left join BUS_SHIFTWORKRULES swr on swr.SHIFTWORKRULES_ID = u.SHIFTDUTYTWO left join SYS_USERINFO info on info.USER_ID = u.USER_ID - left join SYS_DICTIONARIES dic on dic.DICTIONARIES_ID = info.PERSONNEL_TYPE + left join ( SELECT t1.USER_CORP_ID, t1.CORPINFO_ID, t1.USER_ID, t1.APPLY_TYPE, t1.APPLY_STATUS, t1.ISDELETE FROM SYS_USER_CORP t1