夏文涛 1 år sedan
förälder
incheckning
8047908ddc
1 ändrade filer med 113 tillägg och 68 borttagningar
  1. 113 68
      src/main/java/com/template/controller/SmartUserController.java

+ 113 - 68
src/main/java/com/template/controller/SmartUserController.java

@@ -140,10 +140,28 @@ public class SmartUserController implements SmartUserControllerAPI {
     //region 开发自己导数据用的接口
 
     @Override
+    @PassToken
     public CommonResult testDeleteUserById(int userId) throws Exception {
-        SmartUser user = smartUserService.getSmartById(userId);
+        List<SmartUser> users = smartUserService.getSmartUserByIdentity(eIdentityStatu.Parent.getValue());
+        List<SmartUser> StudentUsers = smartUserService.getSmartUserByIdentity(eIdentityStatu.Student.getValue());
+        List<SmartClass> sc = smartClassService.getSmartClasss();
+        List<SmartDepartment> departments = smartDepartmentService.list(null);
+        for (SmartUser user : users) {
+            String[] affs = user.getAffiliate().split(",");
+            if(affs != null && affs.length > 0){
+                Integer first = Integer.valueOf(affs[0]);
+                Optional<SmartUser> osu = StudentUsers.stream().filter(e -> e.getId().intValue() == first.intValue()).findFirst();
+                if(osu != null && osu.isPresent()){
+                    Optional<SmartClass> osc = sc.stream().filter(e -> e.getId().intValue() == osu.get().getSchoolClass().intValue()).findFirst();
+                    Optional<SmartDepartment> od = departments.stream().filter(e -> e.getName().equals(osc.get().getName().contains("2021") ? (osc.get().getName() + "家长") : (osc.get().getName().replace("年级", "") + "家长"))).findFirst();
+                    if(od != null && od.isPresent()) {
+                        user.setDepartmentId(od.get().getId());
+                    }
+                }
+            }
+        }
 
-        bsDeleteStudent(user);
+        smartUserService.updateBatchById(users);
 
         return CommonResult.ok();
     }
@@ -605,6 +623,7 @@ public class SmartUserController implements SmartUserControllerAPI {
                 return CommonResult.fail("文档内容为空,导入失败");
             }
             List<SmartUser> existUsers = smartUserService.querySmartUserByCardNos(cardNos);
+            existUsers = existUsers.stream().filter(e -> e.getIdentityId().intValue() == eIdentityStatu.Student.getValue()).collect(Collectors.toList());
             if (existUsers != null && existUsers.size() > 0) {
                 String names = StringUtils.join(existUsers.stream().map(SmartUser::getName).collect(Collectors.toList()), ",");
                 return CommonResult.fail("系统中已存在" + names + "的信息数据,请勿重复导入");
@@ -1076,6 +1095,7 @@ public class SmartUserController implements SmartUserControllerAPI {
      * @throws IOException
      */
     private CommonResult<List<SmartUser>> readXlsx(InputStream inputStream) throws IOException {
+        int ii = 0;
         List<String> idCards = new ArrayList<>();
         List<String> cardNos = new ArrayList<>();
         List<SmartUser> result = new ArrayList<>();
@@ -1101,7 +1121,12 @@ public class SmartUserController implements SmartUserControllerAPI {
         //endregion
 
         try {
+
             for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
+                ii++;
+                if (ii == 672) {
+                    String sds = "";
+                }
                 XSSFRow row = sheetAt.getRow(rowNum);
                 if (row != null) {
                     if (!isTeacher) {
@@ -1266,14 +1291,14 @@ public class SmartUserController implements SmartUserControllerAPI {
                                 idCards.add(idCard);
                             }
                             if (idCards.stream().distinct().count() != idCards.size()) {
-                                return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
+                                //return CommonResult.fail("导入的Excel中," + name + "的身份证号:" + idCard + "存在重复数据");
                             }
                             user.setCardNo(cardNo == null ? "" : cardNo);
                             user.setName(name == null ? "" : name);
                             user.setIdentityId(eIdentityStatu.Student.getValue());
                             user.setIdCard(idCard == null ? "" : idCard);
-                            user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
-                            user.setDepartmentId(departmentId);
+                            user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex.replace(" ", "")));
+                            user.setDepartmentId(parentDid);
                             String cellImage = dataFormatter.formatCellValue(row.getCell(8));
                             user.setHeadImage(cellImage);
                             user.setDormitoryNumber("");
@@ -1530,6 +1555,7 @@ public class SmartUserController implements SmartUserControllerAPI {
                 }
             }
         } catch (Exception e) {
+            System.out.println(ii);
             return CommonResult.fail("请按模板格式导入数据");
         }
 
@@ -1745,7 +1771,7 @@ public class SmartUserController implements SmartUserControllerAPI {
                             user.setIdentityId(eIdentityStatu.Student.getValue());
                             user.setIdCard(idCard == null ? "" : idCard);
                             user.setSexId(sex == null ? eSexStatu.Man.getValue() : eSexStatu.integerOf(sex));
-                            user.setDepartmentId(departmentId);
+                            user.setDepartmentId(parentDid);
                             String cellImage = dataFormatter.formatCellValue(row.getCell(8));
                             user.setHeadImage(cellImage);
                             user.setDormitoryNumber("");
@@ -2156,7 +2182,7 @@ public class SmartUserController implements SmartUserControllerAPI {
 
         //更新家长
         List<SmartUser> updateParents = result.stream().filter(e -> e.getId() != null && e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList());
-        if(updateParents != null && updateParents.size() > 0){
+        if (updateParents != null && updateParents.size() > 0) {
             boolean updateBatch = smartUserService.updateBatchById(updateParents);
             if (!updateBatch) {
                 return CommonResult.fail("系统批量更新家长出错,导入失败");
@@ -2166,7 +2192,7 @@ public class SmartUserController implements SmartUserControllerAPI {
         //新增家长
         List<SmartUser> insertParentDatas = new ArrayList<>();
         List<SmartUser> insertParents = result.stream().filter(e -> e.getId() == null && e.getIdentityId().intValue() == eIdentityStatu.Parent.getValue()).collect(Collectors.toList());
-        if(insertParents != null && insertParents.size() > 0){
+        if (insertParents != null && insertParents.size() > 0) {
             List<String> familyCardNos = updateStudents.stream().map(SmartUser::getCardNo).distinct().collect(Collectors.toList());
             List<SmartFamilyIndex> indexs = smartFamilyIndexService.querySmartFamilyByCardNo(familyCardNos);
             List<SmartFamilyIndex> familyIndexs = new ArrayList<>();
@@ -2193,7 +2219,7 @@ public class SmartUserController implements SmartUserControllerAPI {
                         List<ParentServiceBatchSaveOrUpdateParentsParam.ParentsItem> parents = new ArrayList<>();
 
                         long indexCount = indexs.stream().filter(e -> e.getStudentNo().equals(student.getCardNo())).count();
-                        int i = (indexCount<= 0 ? 0 : (int)indexCount);
+                        int i = (indexCount <= 0 ? 0 : (int) indexCount);
 
                         for (SmartUser parent : parentDatas) {
                             insertParentDatas.add(parent);
@@ -2263,7 +2289,7 @@ public class SmartUserController implements SmartUserControllerAPI {
             }
 
             List<SmartUser> newParents = new ArrayList<>();
-            if(insertParentDatas != null && insertParentDatas.size() > 0){
+            if (insertParentDatas != null && insertParentDatas.size() > 0) {
                 for (SmartUser parent : insertParentDatas) {
                     Optional<SmartUser> student = updateStudents.stream().filter(e -> e.getCardNo().equals(parent.getAffiliate())).findFirst();
                     if (student != null && student.isPresent()) {
@@ -2319,7 +2345,7 @@ public class SmartUserController implements SmartUserControllerAPI {
         List<SmartUser> insertStudents = result.stream().filter(e -> e.getId() == null).collect(Collectors.toList());
 
         if (insertStudents != null && insertStudents.size() > 0) {
-            if(headImage == null){
+            if (headImage == null) {
                 return CommonResult.fail("更新数据文档中存在新增数据,头像不能为空");
             }
             List<String> uploadImages = Arrays.asList(headImage.split(","));
@@ -2865,9 +2891,9 @@ public class SmartUserController implements SmartUserControllerAPI {
 
                                 SmartUser familyOne = new SmartUser();
                                 Optional<SmartUser> oneParent = parents.stream().filter(e -> e.getPhone().equals(phone)).findFirst();
-                                if(oneParent != null && oneParent.isPresent()){
+                                if (oneParent != null && oneParent.isPresent()) {
                                     familyOne = oneParent.get();
-                                }else{
+                                } else {
                                     familyOne.setAffiliate(user.getCardNo());
                                 }
                                 String family = dataFormatter.formatCellValue(row.getCell(12));//家属
@@ -2890,9 +2916,9 @@ public class SmartUserController implements SmartUserControllerAPI {
                                 }
                                 SmartUser familyTwo = new SmartUser();
                                 Optional<SmartUser> oneParent = parents.stream().filter(e -> e.getPhone().equals(phoneTwo)).findFirst();
-                                if(oneParent != null && oneParent.isPresent()){
+                                if (oneParent != null && oneParent.isPresent()) {
                                     familyTwo = oneParent.get();
-                                }else{
+                                } else {
                                     familyTwo.setAffiliate(user.getCardNo());
                                 }
                                 String familyNameTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
@@ -2908,6 +2934,13 @@ public class SmartUserController implements SmartUserControllerAPI {
                                 result.add(familyTwo);
                             }
                             //endregion
+
+                            //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
+                            if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(14)))) {
+                                if (phone.equals(dataFormatter.formatCellValue(row.getCell(14)))) {
+                                    return CommonResult.fail(name + "的学生家长手机号不可重复");
+                                }
+                            }
                         } else {
                             String name = dataFormatter.formatCellValue(row.getCell(4));
                             //                        if (ObjectUtils.isEmpty(name)) {
@@ -3343,8 +3376,8 @@ public class SmartUserController implements SmartUserControllerAPI {
 
                             //region 家属
 
-                            if(user.getName().equals("张宇霏")){
-                                String sdsd ="";
+                            if (user.getName().equals("张宇霏")) {
+                                String sdsd = "";
                             }
 
                             if (!ObjectUtils.isEmpty(phone)) {
@@ -3354,9 +3387,9 @@ public class SmartUserController implements SmartUserControllerAPI {
 
                                 SmartUser familyOne = new SmartUser();
                                 Optional<SmartUser> oneParent = parents.stream().filter(e -> e.getPhone().equals(phone)).findFirst();
-                                if(oneParent != null && oneParent.isPresent()){
+                                if (oneParent != null && oneParent.isPresent()) {
                                     familyOne = oneParent.get();
-                                }else{
+                                } else {
                                     familyOne.setAffiliate(user.getCardNo());
                                 }
                                 String family = dataFormatter.formatCellValue(row.getCell(12));//家属
@@ -3378,9 +3411,9 @@ public class SmartUserController implements SmartUserControllerAPI {
                                 }
                                 SmartUser familyTwo = new SmartUser();
                                 Optional<SmartUser> oneParent = parents.stream().filter(e -> e.getPhone().equals(phoneTwo)).findFirst();
-                                if(oneParent != null && oneParent.isPresent()){
+                                if (oneParent != null && oneParent.isPresent()) {
                                     familyTwo = oneParent.get();
-                                }else{
+                                } else {
                                     familyTwo.setAffiliate(user.getCardNo());
                                 }
                                 String familyNameTwo = dataFormatter.formatCellValue(row.getCell(15));//家属2
@@ -3396,6 +3429,13 @@ public class SmartUserController implements SmartUserControllerAPI {
                             }
                             //endregion
 
+                            //希沃不允许一个学生家长的两个手机号重复 所以做一个重复性判断
+                            if (!ObjectUtils.isEmpty(phone) && !ObjectUtils.isEmpty(dataFormatter.formatCellValue(row.getCell(14)))) {
+                                if (phone.equals(dataFormatter.formatCellValue(row.getCell(14)))) {
+                                    return CommonResult.fail(name + "的学生家长手机号不可重复");
+                                }
+                            }
+
                         } else {
                             String name = dataFormatter.formatCellValue(row.getCell(4));
                             //                        if (ObjectUtils.isEmpty(name)) {
@@ -4056,9 +4096,9 @@ public class SmartUserController implements SmartUserControllerAPI {
         departmentIds.add(98);
         List<SmartUser> users = smartUserService.queryDatasByDepartments(departmentIds);
 
-        for (SmartUser usur:users) {
+        for (SmartUser usur : users) {
 
-            if(usur.getName().equals("张玉玲")){
+            if (usur.getName().equals("张玉玲")) {
                 String sdsd = "";
             }
             int useXw = 1;
@@ -4126,7 +4166,7 @@ public class SmartUserController implements SmartUserControllerAPI {
 
                 List<SmartUser> studentDatas = smartUserService.getSmartUserIds(affiliates);
 
-                if(studentDatas.size() <= 0){
+                if (studentDatas.size() <= 0) {
                     smartUserService.deleteSmartUserById(usur.getId());
                     continue;
                 }
@@ -4355,29 +4395,32 @@ public class SmartUserController implements SmartUserControllerAPI {
                     //endregion
 
                 } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
-                    //获取班级Uid
-                    SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
-                    if (classData == null) {
-                        return CommonResult.fail("班级数据无效,更新失败");
-                    }
+                    if(oldSchoolClass != null){
+                        //获取班级Uid
+                        SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
+                        if (classData == null) {
+                            return CommonResult.fail("班级数据无效,更新失败");
+                        }
 
-                    //region 希沃删除教师
-                    if (useXw == 1) {
-                        CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
-                        if (!deleteTeacher.isSuccess()) {
-                            return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
+                        //region 希沃删除教师
+                        if (useXw == 1) {
+                            CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
+                            if (!deleteTeacher.isSuccess()) {
+                                return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
+                            }
                         }
-                    }
-                    //endregion
+                        //endregion
 
-                    //region 希沃删除班主任
-                    if (useXw == 1) {
-                        CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), su.getPhone());
-                        if (deleteTeacherMaster.isSuccess()) {
-                            return CommonResult.fail("希沃平台:" + deleteTeacherMaster.getMessage());
+                        //region 希沃删除班主任
+                        if (useXw == 1) {
+                            CommonResult deleteTeacherMaster = SeewoDeleteTeacherMaster(seewoClient, classData.getClassUid(), su.getPhone());
+                            if (deleteTeacherMaster.isSuccess()) {
+                                return CommonResult.fail("希沃平台:" + deleteTeacherMaster.getMessage());
+                            }
                         }
+                        //endregion
                     }
-                    //endregion
+
 
                     //region 百胜删除教师
                     if (useBs == 1) {
@@ -4444,8 +4487,8 @@ public class SmartUserController implements SmartUserControllerAPI {
                             }
 
                             CommonResult changeClass = SeewoChangeClass(seewoClient, seewoConfig.getSchoolId(), su.getXwStudentUid(), oldClassData.getClassUid(), classData.getClassUid());
-                            if(!changeClass.isSuccess()){
-                                return  CommonResult.fail("希沃平台:" + changeClass.getMessage());
+                            if (!changeClass.isSuccess()) {
+                                return CommonResult.fail("希沃平台:" + changeClass.getMessage());
                             }
                         }
 
@@ -4471,7 +4514,7 @@ public class SmartUserController implements SmartUserControllerAPI {
                      */
                     String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
                     String endTime = queryGraduationYear(gradeData.getGradeNo());
-                    CommonResult updateBsStudent = bsUpdateStudent(su, classData.getBsClassNo() ,startTime, endTime);
+                    CommonResult updateBsStudent = bsUpdateStudent(su, classData.getBsClassNo(), startTime, endTime);
                     if (!updateBsStudent.isSuccess()) {
                         if (updateBsStudent.getMessage().equals("人员不存在或已删除")) {
                             //region 百胜新增学生信息
@@ -4503,29 +4546,31 @@ public class SmartUserController implements SmartUserControllerAPI {
                     }
                     //endregion
                 } else if (oldIdentity.intValue() == eIdentityStatu.Teacher.getValue()) {
-                    //获取班级Uid
-                    SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
-                    if (oldClassData == null) {
-                        return CommonResult.fail("班级数据无效,更新失败");
-                    }
+                    if(oldSchoolClass != null){
+                        //获取班级Uid
+                        SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
+                        if (oldClassData == null) {
+                            return CommonResult.fail("班级数据无效,更新失败");
+                        }
 
-                    //region 希沃删除教师
-                    if (useXw == 1) {
-                        CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
-                        if (!deleteTeacher.isSuccess()) {
-                            return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
+                        //region 希沃删除教师
+                        if (useXw == 1) {
+                            CommonResult deleteTeacher = SeewoDeleteTeacher(seewoClient, su.getPhone());
+                            if (!deleteTeacher.isSuccess()) {
+                                return CommonResult.fail("希沃平台:" + deleteTeacher.getMessage());
+                            }
                         }
-                    }
-                    //endregion
+                        //endregion
 
-                    //region 希沃删除班主任
-                    if (useXw == 1) {
-                        CommonResult deleteMaster = SeewoDeleteTeacherMaster(seewoClient, oldClassData.getClassUid(), su.getPhone());
-                        if (!deleteMaster.isSuccess()) {
-                            return CommonResult.fail("希沃平台:" + deleteMaster.getMessage());
+                        //region 希沃删除班主任
+                        if (useXw == 1) {
+                            CommonResult deleteMaster = SeewoDeleteTeacherMaster(seewoClient, oldClassData.getClassUid(), su.getPhone());
+                            if (!deleteMaster.isSuccess()) {
+                                return CommonResult.fail("希沃平台:" + deleteMaster.getMessage());
+                            }
                         }
+                        //endregion
                     }
-                    //endregion
 
                     //region 百胜删除教师
                     if (useBs == 1) {
@@ -4614,7 +4659,7 @@ public class SmartUserController implements SmartUserControllerAPI {
                         return CommonResult.fail("班级数据无效,新增失败");
                     }
 
-                    if (useXw == 1) {
+                    if (useXw == 1 && oldSchoolClass != null) {
                         //获取班级Uid
                         SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
                         if (oldClassData == null) {
@@ -5093,7 +5138,7 @@ public class SmartUserController implements SmartUserControllerAPI {
         }
 
         if (!result.getResponseBody().getCode().equals("000000")) {
-            return CommonResult.fail("希沃平台:" + result.getResponseBody().getMessage());
+            return CommonResult.fail("希沃平台:" +su.getName()+""+ result.getResponseBody().getMessage());
         }
 
         return CommonResult.ok("更新成功");
@@ -6886,7 +6931,7 @@ public class SmartUserController implements SmartUserControllerAPI {
     }
 
 
-    public CommonResult seeWoLostBan(SeewoClient seewoClient,String schoolUid, String classUid, String teacherUid){
+    public CommonResult seeWoLostBan(SeewoClient seewoClient, String schoolUid, String classUid, String teacherUid) {
         MdmTeacherClassApiTeacherLeaveClassParam requestParam = new MdmTeacherClassApiTeacherLeaveClassParam();
         //请求体,MimeType为 application/json
         MdmTeacherClassApiTeacherLeaveClassParam.JSONRequestBody requestBody = MdmTeacherClassApiTeacherLeaveClassParam.JSONRequestBody.builder()
@@ -6903,10 +6948,10 @@ public class SmartUserController implements SmartUserControllerAPI {
                 .build();
         requestBody.setReqDto(reqDto);
         MdmTeacherClassApiTeacherLeaveClassRequest request = new MdmTeacherClassApiTeacherLeaveClassRequest(requestParam);
-        System.out.println("入参:" +request);
+        System.out.println("入参:" + request);
         //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
         MdmTeacherClassApiTeacherLeaveClassResult result = seewoClient.invoke(request);
-        System.out.println("出参:" +result);
+        System.out.println("出参:" + result);
         if (result == null) {
             return CommonResult.fail("希沃教师数据删除失败!");
         }