Browse Source

用户导入调整、添加用户导入模版

zsf 1 year ago
parent
commit
ca20a3b754

+ 19 - 19
src/main/java/com/rf/psychological/rest/ServerController.java

@@ -1,5 +1,6 @@
 package com.rf.psychological.rest;
 
+import cn.hutool.core.lang.Validator;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.rf.psychological.base.rest.BaseController;
@@ -1015,13 +1016,17 @@ public class ServerController extends BaseController {
     @ApiOperation(value = "用户导入")
     @Transactional(rollbackFor = Exception.class)
     @PostMapping("userImport")
-    public Result userImport(String institutionNo, MultipartFile file, HttpServletResponse response) throws Exception {
+    public Result userImport(String institutionNo,String structureNo, MultipartFile file, HttpServletResponse response) throws Exception {
         if (file == null) {
             return fail("文件为空");
         }
         if (institutionNo == null) {
             return fail("机构编号为空");
         }
+        InstitutionEntity institutionEntity = this.institutionService.findByInstitutionNo(institutionNo);
+        if (institutionEntity == null){
+            return fail("机构不存在");
+        }
         String fileName = file.getOriginalFilename();
         List<List<Object>> datas = ExcelUtil.getBankListByExcelForUserImport(file.getInputStream(), fileName);
         if(CollectionUtils.isEmpty(datas)){
@@ -1035,7 +1040,7 @@ public class ServerController extends BaseController {
             int y = 0;
             for (int i = 0; i < datas.size(); i++) {
                 List<Object> users = datas.get(i);
-                if (users.size()<7) {
+                if (users.size()<5) {
                     y = i + 1;
                     result.append("第" + y +"条数据信息不完整").append("\r\n");
                     isExist = true;
@@ -1043,18 +1048,14 @@ public class ServerController extends BaseController {
                 }
                 Object petName = users.get(0);
                 Object phone = users.get(1);
-                Object password = users.get(2);
-                Object gender = users.get(3);
-                Object idCard = users.get(4);
-                Object mobile = users.get(5);
-                Object orgNum = users.get(6);
+                Object gender = users.get(2);
+                Object mobile = users.get(3);
+                Object profession = users.get(4);
                 if (petName == null || petName == "" ||
                         phone == null || phone == "" ||
-                        password == null || password == "" ||
                         gender == null || gender == "" ||
-                        idCard == null || idCard == "" ||
                         mobile == null || mobile == "" ||
-                        orgNum == null || orgNum == "") {
+                        profession == null || profession == "") {
                     y = i + 1;
                     result.append("第" + y +"条数据信息不完整").append("\r\n");
                     isExist = true;
@@ -1066,35 +1067,34 @@ public class ServerController extends BaseController {
                     isExist = true;
                     continue;
                 }
-                if (phone.toString().length() > 18 || phone.toString().length() < 3 || phone.toString().contains(" ")){
+                if (Validator.isCitizenId(phone.toString())){
                     y = i + 1;
-                    result.append("第" + y +"条数据账号长度未在3~18位之间或有空格").append("\r\n");
+                    result.append("第" + y +"账号不符合身份证规则").append("\r\n");
                     isExist = true;
                     continue;
                 }
-                if (password.toString().length() < 6 || password.toString().length() > 18 || password.toString().contains(" ")){
+                if (phone.toString().length() > 18 || phone.toString().length() < 3 || phone.toString().contains(" ")){
                     y = i + 1;
-                    result.append("第" + y +"条数据密码长度未在6~18位之间或有空格").append("\r\n");
+                    result.append("第" + y +"条数据账号长度未在3~18位之间或有空格").append("\r\n");
                     isExist = true;
                     continue;
                 }
+                String idCardStr = phone.toString();
                 //插入数据库的信息
                 UserEntity tempUserDB = new UserEntity();
                 //设置组id,未分组时组id为0
-                InstitutionEntity institutionEntity = this.institutionService.findByInstitutionNo(institutionNo);
+
                 tempUserDB.setInstitutionName(institutionEntity.getInstitutionName());
                 //姓名、账号、密码格式未效验
                 tempUserDB.setPetName(petName.toString());
                 tempUserDB.setPhone(phone.toString());
-                tempUserDB.setPassword(DigestUtils.md5DigestAsHex(password.toString().getBytes(StandardCharsets.UTF_8)));
+                tempUserDB.setPassword(DigestUtils.md5DigestAsHex(idCardStr.substring(12).getBytes(StandardCharsets.UTF_8)));
                 tempUserDB.setGender(gender.toString());
                 tempUserDB.setInstitutionNo(institutionNo);
                 tempUserDB.setUserStatus(Constant.USER_STATUS_NORMAL);
-                tempUserDB.setGId(orgNum.toString());
-                tempUserDB.setStructureNo(orgNum.toString());
+                tempUserDB.setStructureNo(structureNo);
                 tempUserDB.setModel(mobile.toString());
                 tempUserDB.setRoleType(UserRole.COMMON.getType());
-                String idCardStr = idCard.toString();
                 tempUserDB.setBirthday(idCardStr.substring(6,10)+"-"+idCardStr.substring(10,12)+"-"+idCardStr.substring(12,14));
                 tempUserDB.setIdCard(idCardStr);
                 //查看当前用户是否已经在数据库存在

+ 25 - 0
src/main/java/com/rf/psychological/user/rest/SystemController.java

@@ -287,4 +287,29 @@ public class SystemController extends BaseController {
             return fail();
         }
     }
+
+
+    @ApiOperation(value = "登出",notes = "json字符串形式传参(加密),data参数包括:institutionNo:机构编号,phone:账号或电话,roleType:用户角色" )
+    @PostMapping("/logout")
+    public Result logout(@RequestBody String jsonParam){
+        try {
+            JSONObject dataParam = JSONObject.parseObject(AesEncryptUtils.decrypt(JSONObject.parseObject(jsonParam).getString("data")));
+            String phone = dataParam.getString("phone");
+            String institutionNo = dataParam.getString("institutionNo");
+            String roleType = dataParam.getString("roleType");
+            if ( StringUtils.isEmpty( phone)   || StringUtils.isEmpty( institutionNo ) ) {
+                return fail("", "请按要求填写所需信息");
+            }
+            //首先校验用户是否存在
+            UserEntity userEntity = userService.findPhoneAndInstitutionNoAndRoleType(phone,institutionNo,roleType);
+            if (userEntity == null){
+                return fail(null,"用户不存在");
+            }
+
+            return success();
+        }catch (Exception e){
+            e.printStackTrace();
+            return fail();
+        }
+    }
 }

+ 0 - 1
src/main/java/com/rf/psychological/user/rest/UserController.java

@@ -270,7 +270,6 @@ public class UserController extends BaseController {
         String profession = jsonData.getString("profession");
         String newModelPhone = jsonData.getString("newModelPhone");
         String roleType = jsonData.getString("roleType");
-        //UserEntity userEntity = userService.updateUserInfo(phone, institutionNo, newModelPhone, petName, gender, birthday, profession);
         UserEntity userEntity = userService.findPhoneAndInstitutionNoAndRoleType(phone,institutionNo,roleType);
         if (userEntity == null){
             return fail("用户不存在");

BIN
userTemplate/importTemplate.xlsx