夏文涛 vor 1 Jahr
Ursprung
Commit
56aff21ae8

+ 99 - 71
src/main/java/com/template/controller/SmartUserController.java

@@ -1234,11 +1234,11 @@ public class SmartUserController implements SmartUserControllerAPI {
                             for (int i = 0; i < departmentStrs.length; i++) {
                                 String departmentName = departmentStrs[i];
                                 Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
-                                if(oD != null && oD.isPresent()){
+                                if (oD != null && oD.isPresent()) {
                                     parentDid = oD.get().getId();
-                                }else{
+                                } else {
                                     String bsDepartment = insertDepartmentToBs(departmentName);
-                                    if(bsDepartment == null){
+                                    if (bsDepartment == null) {
                                         return CommonResult.fail(name + "的部门添加到百胜失败");
                                     }
                                     SmartDepartment sdParent = new SmartDepartment();
@@ -1375,7 +1375,7 @@ public class SmartUserController implements SmartUserControllerAPI {
                             }
                             //endregion
                         }
-                    }  else {
+                    } else {
                         //教师导入
                         //使用了getStringCellValue()方法来获取值,POI会判断单元格的类型,如果非字符串类型就会抛出上面的异常。
                         //所以先使用setCellType()方法先将该单元格的类型设置为STRING
@@ -1707,11 +1707,11 @@ public class SmartUserController implements SmartUserControllerAPI {
                             for (int i = 0; i < departmentStrs.length; i++) {
                                 String departmentName = departmentStrs[i];
                                 Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
-                                if(oD != null && oD.isPresent()){
+                                if (oD != null && oD.isPresent()) {
                                     parentDid = oD.get().getId();
-                                }else{
+                                } else {
                                     String bsDepartment = insertDepartmentToBs(departmentName);
-                                    if(bsDepartment == null){
+                                    if (bsDepartment == null) {
                                         return CommonResult.fail(name + "的部门添加到百胜失败");
                                     }
                                     SmartDepartment sdParent = new SmartDepartment();
@@ -2191,6 +2191,8 @@ public class SmartUserController implements SmartUserControllerAPI {
 
         List<SmartClass> classs = smartClassService.list(null);//班级
         List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
+        List<SmartDepartment> departments = smartDepartmentService.list(null);
+
 
         //读取第一张sheet
         HSSFSheet sheetAt = sheets.getSheetAt(0);
@@ -2206,62 +2208,74 @@ public class SmartUserController implements SmartUserControllerAPI {
                     //然后poi会根据字符串读取它
                     //标题 校验
                     if (rowNum == 1) {
-                        String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
-                        if (!xwNo.equals("希沃编号")) {
-                            return CommonResult.fail("导入数据第二列为希沃编号");
-                        }
-                        String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
-                        if (!bsNo.equals("百胜编号")) {
-                            return CommonResult.fail("导入数据第三列为百胜编号");
-                        }
-                        String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
+                        String cardNo = dataFormatter.formatCellValue(row.getCell(1));//学号
                         if (!cardNo.equals("学号")) {
-                            return CommonResult.fail("导入数据第列为学号");
+                            return CommonResult.fail("导入数据第一列为学号");
                         }
-                        String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
+                        String department = dataFormatter.formatCellValue(row.getCell(2));//部门
+                        if (!department.equals("部门")) {
+                            return CommonResult.fail("导入数据第二列为部门");
+                        }
+                        String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
                         if (!name.equals("姓名")) {
-                            return CommonResult.fail("导入数据第五列为姓名");
+                            return CommonResult.fail("导入数据第列为姓名");
                         }
-                        String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
+                        String schoolClass = dataFormatter.formatCellValue(row.getCell(4));//班级
                         if (!schoolClass.equals("班级")) {
-                            return CommonResult.fail("导入数据第列为班级");
+                            return CommonResult.fail("导入数据第列为班级");
                         }
-                        String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
+                        String group = dataFormatter.formatCellValue(row.getCell(5));//时间组
                         if (!group.equals("时间组")) {
-                            return CommonResult.fail("导入数据第列为时间组");
+                            return CommonResult.fail("导入数据第列为时间组");
                         }
                     } else {
                         SmartUser user = new SmartUser();
 
-                        String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
+                        String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
                         if (ObjectUtils.isEmpty(name)) {
-                            return CommonResult.fail("第" + (rowNum) + "条数据的名称不能为空");
-                        }
-
-                        String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
-                        if (ObjectUtils.isEmpty(xwNo)) {
-                            return CommonResult.fail(name + "的希沃编号不能为空");
+                            return CommonResult.fail("第" + (rowNum) + "条数据的姓名不能为空");
                         }
-
-                        String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
-                        if (ObjectUtils.isEmpty(bsNo)) {
-                            return CommonResult.fail(name + "的百胜编号不能为空");
-                        }
-
-                        String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
+                        String cardNo = dataFormatter.formatCellValue(row.getCell(1));//学号
                         if (ObjectUtils.isEmpty(cardNo)) {
                             return CommonResult.fail(name + "的学号不能为空");
                         }
-                        String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
+                        String department = dataFormatter.formatCellValue(row.getCell(2));//学号
+                        if (ObjectUtils.isEmpty(department)) {
+                            return CommonResult.fail(name + "的部门不能为空");
+                        }
+                        String schoolClass = dataFormatter.formatCellValue(row.getCell(4));//班级
                         if (ObjectUtils.isEmpty(schoolClass)) {
                             return CommonResult.fail(name + "的班级不能为空");
                         }
-                        String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
+                        String group = dataFormatter.formatCellValue(row.getCell(5));//时间组
                         if (ObjectUtils.isEmpty(group)) {
                             return CommonResult.fail(name + "的时间组不能为空");
                         }
 
+                        Integer parentDid = null;
+                        Integer departmentId = null;
+                        String[] departmentStrs = department.split("/");
+                        for (int i = 0; i < departmentStrs.length; i++) {
+                            String departmentName = departmentStrs[i];
+                            Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
+                            if (oD != null && oD.isPresent()) {
+                                parentDid = oD.get().getId();
+                            } else {
+                                String bsDepartment = insertDepartmentToBs(departmentName);
+                                if (bsDepartment == null) {
+                                    return CommonResult.fail(name + "的部门添加到百胜失败");
+                                }
+                                SmartDepartment sdParent = new SmartDepartment();
+                                sdParent.setParentId(parentDid);
+                                sdParent.setName(departmentName);
+                                sdParent.setBsDepartmentNo(bsDepartment);
+                                int departmentData = smartDepartmentService.insertSmartDepartment(sdParent);
+                                departmentId = departmentData;
+                                parentDid = departmentData;
+                            }
+                        }
 
+                        user.setDepartmentId(departmentId);
                         user.setCardNo(cardNo == null ? "" : cardNo);
                         user.setName(name == null ? "" : name);
                         user.setIdentityId(eIdentityStatu.Student.getValue());
@@ -2305,6 +2319,8 @@ public class SmartUserController implements SmartUserControllerAPI {
 
         List<SmartClass> classs = smartClassService.list(null);//班级
         List<SmartTimeGroup> timeGroups = smartTimeGroupService.queryTimeGroups();//时间组
+        List<SmartDepartment> departments = smartDepartmentService.list(null);
+
 
         //读取第一张sheet
         XSSFSheet sheetAt = sheets.getSheetAt(0);
@@ -2320,62 +2336,74 @@ public class SmartUserController implements SmartUserControllerAPI {
                     //然后poi会根据字符串读取它
                     //标题 校验
                     if (rowNum == 1) {
-                        String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
-                        if (!xwNo.equals("希沃编号")) {
-                            return CommonResult.fail("导入数据第二列为希沃编号");
-                        }
-                        String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
-                        if (!bsNo.equals("百胜编号")) {
-                            return CommonResult.fail("导入数据第三列为百胜编号");
-                        }
-                        String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
+                        String cardNo = dataFormatter.formatCellValue(row.getCell(1));//学号
                         if (!cardNo.equals("学号")) {
-                            return CommonResult.fail("导入数据第列为学号");
+                            return CommonResult.fail("导入数据第一列为学号");
                         }
-                        String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
+                        String department = dataFormatter.formatCellValue(row.getCell(2));//部门
+                        if (!department.equals("部门")) {
+                            return CommonResult.fail("导入数据第二列为部门");
+                        }
+                        String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
                         if (!name.equals("姓名")) {
-                            return CommonResult.fail("导入数据第五列为姓名");
+                            return CommonResult.fail("导入数据第列为姓名");
                         }
-                        String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
+                        String schoolClass = dataFormatter.formatCellValue(row.getCell(4));//班级
                         if (!schoolClass.equals("班级")) {
-                            return CommonResult.fail("导入数据第列为班级");
+                            return CommonResult.fail("导入数据第列为班级");
                         }
-                        String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
+                        String group = dataFormatter.formatCellValue(row.getCell(5));//时间组
                         if (!group.equals("时间组")) {
-                            return CommonResult.fail("导入数据第列为时间组");
+                            return CommonResult.fail("导入数据第列为时间组");
                         }
                     } else {
                         SmartUser user = new SmartUser();
 
-                        String name = dataFormatter.formatCellValue(row.getCell(4));//姓名
+                        String name = dataFormatter.formatCellValue(row.getCell(3));//姓名
                         if (ObjectUtils.isEmpty(name)) {
-                            return CommonResult.fail("第" + (rowNum) + "条数据的名不能为空");
+                            return CommonResult.fail("第" + (rowNum) + "条数据的名不能为空");
                         }
-
-                        String xwNo = dataFormatter.formatCellValue(row.getCell(1));//希沃编号
-                        if (ObjectUtils.isEmpty(xwNo)) {
-                            return CommonResult.fail(name + "的希沃编号不能为空");
-                        }
-
-                        String bsNo = dataFormatter.formatCellValue(row.getCell(2));//百胜编号
-                        if (ObjectUtils.isEmpty(bsNo)) {
-                            return CommonResult.fail(name + "的百胜编号不能为空");
-                        }
-
-                        String cardNo = dataFormatter.formatCellValue(row.getCell(3));//学号
+                        String cardNo = dataFormatter.formatCellValue(row.getCell(1));//学号
                         if (ObjectUtils.isEmpty(cardNo)) {
                             return CommonResult.fail(name + "的学号不能为空");
                         }
-                        String schoolClass = dataFormatter.formatCellValue(row.getCell(5));//班级
+                        String department = dataFormatter.formatCellValue(row.getCell(2));//学号
+                        if (ObjectUtils.isEmpty(department)) {
+                            return CommonResult.fail(name + "的部门不能为空");
+                        }
+                        String schoolClass = dataFormatter.formatCellValue(row.getCell(4));//班级
                         if (ObjectUtils.isEmpty(schoolClass)) {
                             return CommonResult.fail(name + "的班级不能为空");
                         }
-                        String group = dataFormatter.formatCellValue(row.getCell(6));//时间组
+                        String group = dataFormatter.formatCellValue(row.getCell(5));//时间组
                         if (ObjectUtils.isEmpty(group)) {
                             return CommonResult.fail(name + "的时间组不能为空");
                         }
 
+                        Integer parentDid = null;
+                        Integer departmentId = null;
+                        String[] departmentStrs = department.split("/");
+                        for (int i = 0; i < departmentStrs.length; i++) {
+                            String departmentName = departmentStrs[i];
+                            Optional<SmartDepartment> oD = departments.stream().filter(e -> e.getName().equals(departmentName)).findFirst();
+                            if (oD != null && oD.isPresent()) {
+                                parentDid = oD.get().getId();
+                            } else {
+                                String bsDepartment = insertDepartmentToBs(departmentName);
+                                if (bsDepartment == null) {
+                                    return CommonResult.fail(name + "的部门添加到百胜失败");
+                                }
+                                SmartDepartment sdParent = new SmartDepartment();
+                                sdParent.setParentId(parentDid);
+                                sdParent.setName(departmentName);
+                                sdParent.setBsDepartmentNo(bsDepartment);
+                                int departmentData = smartDepartmentService.insertSmartDepartment(sdParent);
+                                departmentId = departmentData;
+                                parentDid = departmentData;
+                            }
+                        }
 
+                        user.setDepartmentId(departmentId);
                         user.setCardNo(cardNo == null ? "" : cardNo);
                         user.setName(name == null ? "" : name);
                         user.setIdentityId(eIdentityStatu.Student.getValue());

+ 2 - 1
src/main/resources/mapper/template/SmartUserMapper.xml

@@ -84,10 +84,11 @@
         <result property="ofStudent" column="of_student"/>
         <result property="graduate" column="graduate"/>
         <result property="duties" column="duties"/>
+        <result property="timeGroupId" column="time_group_id"/>
     </resultMap>
     <select id="querySmartUsers" resultType="com.template.model.pojo.SmartUser" resultMap="smartUsersMap">
         select
-        card_no,name,identity_id,id_card,sex_id,department_id,head_image,grade,college,speciality,school_class,campus,dormitory_number,
+        card_no,name,identity_id,id_card,sex_id,department_id,head_image,grade,college,time_group_id,speciality,school_class,campus,dormitory_number,
         phone,affiliate,title,address,nation,of_student,graduate,duties from smart_user
         where deleted = 0 and is_cancel = 0
         <if test="departmentIds != null and departmentIds.size() > 0">