diff --git a/src/main/java/com/msdw/tms/TmsApplication.java b/src/main/java/com/msdw/tms/TmsApplication.java index e2715d0..1e5e101 100644 --- a/src/main/java/com/msdw/tms/TmsApplication.java +++ b/src/main/java/com/msdw/tms/TmsApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.scheduling.annotation.EnableScheduling; -@EnableScheduling//定时任务 +//@EnableScheduling//定时任务 @SpringBootApplication public class TmsApplication extends SpringBootServletInitializer { diff --git a/src/main/java/com/msdw/tms/common/utils/ExcelImportHelper.java b/src/main/java/com/msdw/tms/common/utils/ExcelImportHelper.java index 83a3ff9..5de5e0a 100644 --- a/src/main/java/com/msdw/tms/common/utils/ExcelImportHelper.java +++ b/src/main/java/com/msdw/tms/common/utils/ExcelImportHelper.java @@ -1,7 +1,12 @@ package com.msdw.tms.common.utils; +import com.msdw.tms.common.exception.ExceptionCast; +import com.msdw.tms.entity.response.CommonCode; import com.msdw.tms.entity.vo.StaffVo; import com.msdw.tms.entity.vo.StudentVo; +import org.apache.commons.lang.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -13,15 +18,62 @@ import java.util.List; public class ExcelImportHelper { + + //判断row是否为空 + public static boolean isRowEmpty(Row row) { + if (null == row) { + return true; + } + int firstCellNum = row.getFirstCellNum(); //第一个列位置 + int lastCellNum = row.getLastCellNum(); //最后一列位置 + int nullCellNum = 0; //空列数量 + for (int c = firstCellNum; c < lastCellNum; c++) { + Cell cell = row.getCell(c); + if (null == cell || CellType.BLANK == cell.getCellType()) { + nullCellNum++; + continue; + } + cell.setCellType(CellType.STRING); + String cellValue = cell.getStringCellValue().trim(); + if (StringUtils.isEmpty(cellValue)) { + nullCellNum++; + } + } + //所有列都为空 + if (nullCellNum == (lastCellNum - firstCellNum)) { + return true; + } + return false; + } + + //todo 解决POI无法同时读取带多种格式的单元格表格 + public static String getValue(Cell cell) { + if (cell == null) { + + return ""; + + } else if (cell.getCellType() == CellType.BOOLEAN) { + return String.valueOf(cell.getBooleanCellValue()); + } else if (cell.getCellType() == CellType.NUMERIC) { + String value = ""; + return value; + } else { + return String.valueOf(cell.getStringCellValue()); + + } + } + + /** * 读取学生管理 + * * @param file * @return */ - public static List readStudent(MultipartFile file) { + public static List readStudent(MultipartFile file) throws IOException { List list = new ArrayList(); - Workbook workbook=getWorkbook(file); + Workbook workbook = getWorkbook(file); StudentVo student = null; // 循环工作表Sheet for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) { @@ -29,38 +81,57 @@ public class ExcelImportHelper { if (hssfSheet == null) { continue; } + + int count = 1; // 循环行Row//开始行2 for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { Row row = hssfSheet.getRow(rowNum); + + if (isRowEmpty(row)) { + count++; + if (count == hssfSheet.getLastRowNum()) { + ExceptionCast.cast(CommonCode.EXCEL_FILE_NULL); + } + continue; + } + + if (row == null) { + continue; + } else if ( + StringUtils.isEmpty(getValue(row.getCell(0))) && + StringUtils.isEmpty(getValue(row.getCell(1))) && + StringUtils.isEmpty(getValue(row.getCell(2)))) { + continue; + } + Cell phone; Cell email; if (row != null) { student = new StudentVo(); + row.getCell(0).setCellType(CellType.STRING); Cell studentName = row.getCell(0); + + row.getCell(1).setCellType(CellType.STRING); - Cell schoolAppellationName = row.getCell(1); + Cell account = row.getCell(1); row.getCell(2).setCellType(CellType.STRING); - Cell account = row.getCell(2); - row.getCell(3).setCellType(CellType.STRING); - Cell studentNumber = row.getCell(3); - if (row.getCell(4)!=null){ - row.getCell(4).setCellType(CellType.STRING); - phone = row.getCell(4); - }else { - phone = row.createCell(4); + + Cell studentNumber = row.getCell(2); + if (row.getCell(3) != null) { + row.getCell(3).setCellType(CellType.STRING); + phone = row.getCell(3); + } else { + phone = row.createCell(3); } - if (row.getCell(5)!=null){ - row.getCell(5).setCellType(CellType.STRING); - email = row.getCell(5); - }else { - email = row.createCell(5); + + if (row.getCell(4) != null) { + row.getCell(4).setCellType(CellType.STRING); + email = row.getCell(4); + } else { + email = row.createCell(4); } -// row.getCell(4).setCellType(CellType.STRING); -// Cell phone = row.getCell(4); -// row.getCell(5).setCellType(CellType.STRING); -// Cell email = row.getCell(5); // 学生姓名 @@ -69,8 +140,6 @@ public class ExcelImportHelper { student.setRoleId(ConstantUtils.STUDENT_ROLE); // 学生学号 student.setWorkNumber(studentNumber.getStringCellValue()); - //所属院校 - student.setSchoolAppellationName(schoolAppellationName.getStringCellValue()); //用户账号 student.setAccount(account.getStringCellValue()); //电话 @@ -87,15 +156,18 @@ public class ExcelImportHelper { return list; } + + /** * 读取员工管理 + * * @param file * @return */ - public static List readStaff(MultipartFile file) { + public static List readStaff(MultipartFile file) throws IOException { List list = new ArrayList(); - Workbook workbook=getWorkbook(file); + Workbook workbook = getWorkbook(file); StaffVo staff = null; // 循环工作表Sheet for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) { @@ -103,97 +175,110 @@ public class ExcelImportHelper { if (hssfSheet == null) { continue; } - int lastRowNum = hssfSheet.getLastRowNum()+1;//最后一行行标,比行数小1 - if (lastRowNum==2){ + /*int lastRowNum = hssfSheet.getLastRowNum() + 1;//最后一行行标,比行数小1 + if (lastRowNum == 2) { break; - } + }*/ + int count = 1; // 循环行Row//开始行2 for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { Row row = hssfSheet.getRow(rowNum); - Cell userName; + if (isRowEmpty(row)) { + count++; + if (count == hssfSheet.getLastRowNum()) { + ExceptionCast.cast(CommonCode.EXCEL_FILE_NULL); + } + continue; + } + + Cell phone; Cell email; Cell staffGradeName; Cell staffProfessionalArchitectureName; Cell staffGradeNameTwo; Cell staffProfessionalArchitectureNameTwo; - if (row != null) { + /*Cell account; + Cell role; + Cell workNumber;*/ + Cell userName; + + + if (row == null) { + continue; + } else { staff = new StaffVo(); - if (row.getCell(0)!=null){ + if (row.getCell(0) != null) { row.getCell(0).setCellType(CellType.STRING); userName = row.getCell(0); - }else { - continue; + } else { + userName = row.createCell(0); } + //姓名 + /* row.getCell(0).setCellType(CellType.STRING); + String userName = row.getCell(0).getStringCellValue();*/ + //账号 row.getCell(1).setCellType(CellType.STRING); Cell account = row.getCell(1); + //角色 row.getCell(2).setCellType(CellType.STRING); Cell role = row.getCell(2); + //工号 row.getCell(3).setCellType(CellType.STRING); Cell workNumber = row.getCell(3); -// row.getCell(4).setCellType(CellType.STRING); -// Cell staffGradeName = row.getCell(4); - if (row.getCell(4)!=null){ + + + if (row.getCell(4) != null) { row.getCell(4).setCellType(CellType.STRING); staffProfessionalArchitectureName = row.getCell(4); - }else { + } else { staffProfessionalArchitectureName = row.createCell(4); } - if (row.getCell(5)!=null){ + if (row.getCell(5) != null) { row.getCell(5).setCellType(CellType.STRING); staffGradeName = row.getCell(5); - }else { + } else { staffGradeName = row.createCell(5); } - if (row.getCell(6)!=null){ + if (row.getCell(6) != null) { row.getCell(6).setCellType(CellType.STRING); staffProfessionalArchitectureNameTwo = row.getCell(6); - }else { + } else { staffProfessionalArchitectureNameTwo = row.createCell(6); } - if (row.getCell(7)!=null){ + if (row.getCell(7) != null) { row.getCell(7).setCellType(CellType.STRING); staffGradeNameTwo = row.getCell(7); - }else { + } else { staffGradeNameTwo = row.createCell(7); } - - -// row.getCell(5).setCellType(CellType.STRING); -// Cell staffProfessionalArchitectureName = row.getCell(5); -// row.getCell(6).setCellType(CellType.STRING); -// Cell staffGradeNameTwo = row.getCell(6); -// row.getCell(7).setCellType(CellType.STRING); -// Cell staffProfessionalArchitectureNameTwo = row.getCell(7); - if (row.getCell(8)!=null){ + if (row.getCell(8) != null) { row.getCell(8).setCellType(CellType.STRING); phone = row.getCell(8); - }else { + } else { phone = row.createCell(8); } - if (row.getCell(9)!=null){ + if (row.getCell(9) != null) { row.getCell(9).setCellType(CellType.STRING); email = row.getCell(9); - }else { + } else { email = row.createCell(9); } - row.getCell(10).setCellType(CellType.STRING); - Cell schoolAppellationName = row.getCell(10); -// row.getCell(11).setCellType(CellType.STRING); -// Cell failureMsg = row.getCell(11); + /*row.getCell(10).setCellType(CellType.STRING); + Cell schoolAppellationName = row.getCell(10);*/ String roleValue = role.getStringCellValue(); String str; // 角色id - if (roleValue.equals("管理员")){ + if (roleValue.equals("管理员")) { str = "13";//2 - }else if (roleValue.equals("老师")){ + } else if (roleValue.equals("老师")) { str = "14";//3 - }else{ + } else { str = "13,14"; } staff.setRoleId(str); @@ -218,7 +303,7 @@ public class ExcelImportHelper { //邮箱 staff.setEmail(email.getStringCellValue()); //所属院校 - staff.setSchoolAppellationName(schoolAppellationName.getStringCellValue()); + //staff.setSchoolAppellationName(schoolAppellationName.getStringCellValue()); //学校id staff.setSchoolId(ConstantUtils.Keda_schoolId); list.add(staff); @@ -229,7 +314,7 @@ public class ExcelImportHelper { return list; } - private static Workbook getWorkbook(MultipartFile file) { + private static Workbook getWorkbook(MultipartFile file) { String fileName = file.getOriginalFilename(); Workbook workbook = null; @@ -239,7 +324,7 @@ public class ExcelImportHelper { } catch (IOException e) { e.printStackTrace(); } - }else if (fileName.endsWith("xls")) { + } else if (fileName.endsWith("xls")) { try { workbook = new HSSFWorkbook(file.getInputStream()); } catch (IOException e) { diff --git a/src/main/java/com/msdw/tms/entity/response/CommonCode.java b/src/main/java/com/msdw/tms/entity/response/CommonCode.java index c8aa3ce..74889ed 100644 --- a/src/main/java/com/msdw/tms/entity/response/CommonCode.java +++ b/src/main/java/com/msdw/tms/entity/response/CommonCode.java @@ -17,10 +17,14 @@ public enum CommonCode implements ResultCode { EXCEL_FILE_INVALID(false, 10009, "上传excel文件错误!"), REPEAT_INEXCEL(false, 10010, "试题在excel表中重复!"), EVALUATION_QUESTION_NUM_INVALID(false, 10011, "当前测评题数设置为0,请先设置测评题数!"), + EXCEL_FILE_NULL(false, 100011, "导入失败,导入数据为空!"), + EXCEL_FILE_FORMAT_ERROR(false, 100012, "请根据模板使用说明录入正确的学生信息!"), + EXCEL_FILE_FORMAT_ERROR_STAFFS(false, 100012, "请根据模板使用说明录入正确的员工信息!"), FAIL(false, 11111, "操作失败!"), - ROLE_NAME_EXIST(false,20001,"该角色名称已存在,请重新输入!"), - ROLE_EMP_EXIST(false,44001,"该角色有用户关联,不能删除!"), + + ROLE_NAME_EXIST(false, 20001, "该角色名称已存在,请重新输入!"), + ROLE_EMP_EXIST(false, 44001, "该角色有用户关联,不能删除!"), SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); //操作是否成功 boolean success; diff --git a/src/main/java/com/msdw/tms/entity/vo/StudentImportFailureVo.java b/src/main/java/com/msdw/tms/entity/vo/StudentImportFailureVo.java index 9c4429c..ae10562 100644 --- a/src/main/java/com/msdw/tms/entity/vo/StudentImportFailureVo.java +++ b/src/main/java/com/msdw/tms/entity/vo/StudentImportFailureVo.java @@ -15,23 +15,23 @@ public class StudentImportFailureVo { //用户姓名 @ExcelAttribute(sort = 0) private String userName; - //所属院校 + /*//所属院校 @ExcelAttribute(sort = 1) - private String schoolAppellationName; + private String schoolAppellationName;*/ //账号 - @ExcelAttribute(sort = 2) + @ExcelAttribute(sort = 1) private String account; //学号 - @ExcelAttribute(sort = 3) + @ExcelAttribute(sort = 2) private String workNumber; //手机号码 - @ExcelAttribute(sort = 4) + @ExcelAttribute(sort = 3) private String phone; //邮箱 - @ExcelAttribute(sort = 5) + @ExcelAttribute(sort = 4) private String email; //失败原因 - @ExcelAttribute(sort = 6) + @ExcelAttribute(sort = 5) private String failureMsg; // // @ExcelAttribute(sort = 7) diff --git a/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java index e3a099d..13f85c5 100644 --- a/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java @@ -39,7 +39,7 @@ import java.util.*; import java.util.concurrent.TimeUnit; @Service("studentService") -public class StudentServiceImpl extends ServiceImpl implements StudentService { +public class StudentServiceImpl extends ServiceImpl implements StudentService { @Autowired private StudentDao studentDao; @@ -57,11 +57,11 @@ public class StudentServiceImpl extends ServiceImpl im StringRedisTemplate stringRedisTemplate; @Override - public Integer queryStudentIdNumber(String workNumber,Integer schoolId) { - List result = studentDao.queryStudentIdNumber(workNumber,schoolId); - if (result.size()==1){ + public Integer queryStudentIdNumber(String workNumber, Integer schoolId) { + List result = studentDao.queryStudentIdNumber(workNumber, schoolId); + if (result.size() == 1) { return 1; - }else{ + } else { return 0; } } @@ -75,9 +75,9 @@ public class StudentServiceImpl extends ServiceImpl im } @Override - public PageUtils queryStudent(Integer schoolId,String searchContent, Integer page, Integer size) { - Page tPage = new Page<>(page,size); - IPage saveStudent = studentDao.queryStudent(tPage,searchContent,schoolId); + public PageUtils queryStudent(Integer schoolId, String searchContent, Integer page, Integer size) { + Page tPage = new Page<>(page, size); + IPage saveStudent = studentDao.queryStudent(tPage, searchContent, schoolId); PageUtils pageUtils = new PageUtils(saveStudent); return pageUtils; } @@ -85,10 +85,10 @@ public class StudentServiceImpl extends ServiceImpl im @Override public R queryStudentDetails(Integer userId) { StudentVo saveStudent = studentDao.queryStudentDetails(userId); - if (saveStudent!=null){ - return R.ok().put("data",saveStudent); - }else { - return R.error(300,"用户不存在!"); + if (saveStudent != null) { + return R.ok().put("data", saveStudent); + } else { + return R.error(300, "用户不存在!"); } } @@ -99,7 +99,7 @@ public class StudentServiceImpl extends ServiceImpl im try { Integer delete = studentDao.deleteStudent(studentId); return true; - }catch (RuntimeException e){ + } catch (RuntimeException e) { e.printStackTrace(); return false; } @@ -110,7 +110,7 @@ public class StudentServiceImpl extends ServiceImpl im try { Integer update = studentDao.updateStudent(studentVo); return true; - }catch (RuntimeException e){ + } catch (RuntimeException e) { e.printStackTrace(); return false; } @@ -118,16 +118,16 @@ public class StudentServiceImpl extends ServiceImpl im @Override public void updateWorkNumber(Integer studentId) { - studentDao.updateWorkNumber("00",studentId);//将学号重置为00 + studentDao.updateWorkNumber("00", studentId);//将学号重置为00 } @Override public R addStudentInfo(StudentVo studentVo) { R r = new R(); boolean result = studentDao.addStudentInfo(studentVo); - if (result==false){ - throw new RuntimeException();//添加失败,抛出运行时异常让外层事务回滚 - }else{ + if (result == false) { + throw new RuntimeException();//添加失败,抛出运行时异常让外层事务回滚 + } else { return R.ok("注册成功!"); } @@ -141,8 +141,15 @@ public class StudentServiceImpl extends ServiceImpl im @Transactional @Override - public Map upload(MultipartFile file, Integer schoolId) throws IOException{ + public Map upload(MultipartFile file, Integer schoolId) throws IOException { + List students = ExcelImportHelper.readStudent(file); + if (students.size() <= 0) { + ExceptionCast.cast(CommonCode.EXCEL_FILE_FORMAT_ERROR); + } + + Map errorMap = new HashMap<>(); + List failVo1 = new ArrayList<>(); // 参数合法性校验,只能上传.xlsx后缀的文件 if (StringUtils.isBlank(file.getOriginalFilename()) @@ -153,24 +160,83 @@ public class StudentServiceImpl extends ServiceImpl im Map map = new HashMap<>(); Long ii = 1L;//用于记录序列号 try { - for (int i = 0;i result1 = studentDao.queryStudentIdNumber(workNumber,schoolId); + //String schoolAppellationName = student.getSchoolAppellationName(); + List result1 = studentDao.queryStudentIdNumber(workNumber, schoolId); List result4 = userInfoDao.queryStudentAccount(account); String email = student.getEmail(); - if (phone!=null&&phone!=""){ + if (phone != null && phone != "") { List result2 = userInfoDao.queryStudentPhone(phone); - if (result2.size()>=1){ + if (result2.size() >= 1) { log.error("该号码已被使用"); StudentImportFailureVo vo = new StudentImportFailureVo(); ++ii; - vo.setIndex(ii).setUserName(student.getUserName()).setSchoolAppellationName(student.getSchoolAppellationName()) - .setAccount(student.getAccount()).setWorkNumber(student.getWorkNumber()).setPhone(student.getPhone()+" (重复的号码)").setEmail(student.getEmail()) + vo.setIndex(ii) + .setUserName(student.getUserName()) + .setAccount(student.getAccount()) + .setWorkNumber(student.getWorkNumber()) + .setPhone(student.getPhone() + " (重复的号码)") + .setEmail(student.getEmail()) ; failVo1.add(vo); students.remove(i); @@ -179,24 +245,29 @@ public class StudentServiceImpl extends ServiceImpl im } studentVo.setPhone(phone); } - if (email!=null&&email!=""){ + if (email != null && email != "") { studentVo.setEmail(email); } - List result3 = studentDao.querySchoolName(schoolAppellationName); + // List result3 = studentDao.querySchoolName(schoolAppellationName); // 唯一标示性账号 studentVo.setUniqueIdentificationAccount(String.valueOf(System.currentTimeMillis())). setPassword(ConstantUtils.INITIAL_PASSWORD).setToken(new ConstantUtils().token) .setSchoolId(ConstantUtils.Keda_schoolId).setRoleId(ConstantUtils.STUDENT_ROLE) ; - studentVo.setAccount(student.getAccount()).setSchoolAppellationName(schoolAppellationName) - .setUserName(student.getUserName()).setIsdel(Constant.IsDel.NOT_DEL.getType()); + studentVo.setAccount(student.getAccount()) + .setUserName(student.getUserName()) + .setIsdel(Constant.IsDel.NOT_DEL.getType()); + - if (result1.size()>=1){ + if (result1.size() >= 1) { log.error("该学号已存在"); StudentImportFailureVo vo = new StudentImportFailureVo(); ++ii; - vo.setIndex(ii).setUserName(student.getUserName()).setSchoolAppellationName(student.getSchoolAppellationName()) - .setAccount(student.getAccount()).setWorkNumber(student.getWorkNumber()+" (重复的学号)").setPhone(student.getPhone()).setEmail(student.getEmail()) + vo.setIndex(ii) + .setUserName(student.getUserName()) + .setAccount(student.getAccount()) + .setWorkNumber(student.getWorkNumber() + " (重复的学号)") + .setPhone(student.getPhone()).setEmail(student.getEmail()) ; // .setFailureMsg("重复的学号"); failVo1.add(vo); @@ -204,12 +275,16 @@ public class StudentServiceImpl extends ServiceImpl im students.remove(i); i--; continue; - }else if(result4.size()>=1){ + } else if (result4.size() >= 1) { log.error("账号已存在"); StudentImportFailureVo vo = new StudentImportFailureVo(); ++ii; - vo.setIndex(ii).setUserName(student.getUserName()).setSchoolAppellationName(student.getSchoolAppellationName()) - .setAccount(student.getAccount()+" (重复的账号)").setWorkNumber(student.getWorkNumber()).setPhone(student.getPhone()).setEmail(student.getEmail()) + vo.setIndex(ii) + .setUserName(student.getUserName()) + .setAccount(student.getAccount() + " (重复的账号)") + .setWorkNumber(student.getWorkNumber()) + .setPhone(student.getPhone()) + .setEmail(student.getEmail()) ; // .setFailureMsg("重复的账号"); failVo1.add(vo); @@ -218,7 +293,7 @@ public class StudentServiceImpl extends ServiceImpl im i--; continue; } - else if(result3.size()!=1){ + /*else if(result3.size()!=1){ log.error("不存在该院校"); StudentImportFailureVo vo = new StudentImportFailureVo(); ++ii; @@ -230,23 +305,24 @@ public class StudentServiceImpl extends ServiceImpl im students.remove(i); i--; continue; - } + }*/ ++ii; - if (!students.isEmpty()&&students.size()>0){ + if (!students.isEmpty() && students.size() > 0) { + studentVo.setSchoolId(schoolId); userInfoDao.batchSaveUserInfo(studentVo); student.setUserId(studentVo.getUserId()).setIsdel(Constant.IsDel.NOT_DEL.getType()).setPlatformId(ConstantUtils.PLATFORMID); boolean b = studentDao.saveStudent(student); - if (!b){ - throw new RuntimeException(); + if (!b) { + throw new RuntimeException(); } } } - }catch (RuntimeException e){ + } catch (RuntimeException e) { log.error(e.getMessage()); - map.put("failura","添加失败"); - throw new RuntimeException(); + map.put("failura", "添加失败"); + throw new RuntimeException(); } String token = ""; @@ -261,14 +337,14 @@ public class StudentServiceImpl extends ServiceImpl im ops.set(token, failureVOJson, 30 * 60, TimeUnit.SECONDS); } map.put("token", token); - map.put("successNum", (size-failVo1.size())+""); - map.put("failureNum", failVo1.size()+""); + map.put("successNum", (size - failVo1.size()) + ""); + map.put("failureNum", failVo1.size() + ""); return map; } @Override - public void exportFailureRecord(HttpServletResponse response,String token) throws Exception{ + public void exportFailureRecord(HttpServletResponse response, String token) throws Exception { if (StringUtils.isEmpty(token)) { return; } @@ -284,23 +360,24 @@ public class StudentServiceImpl extends ServiceImpl im parse.sort(Comparator.comparing(StudentImportFailureVo::getIndex)); //2.加载模板流数据 - org.springframework.core.io.Resource resource = new ClassPathResource("excel-template/学生导入失败数据导出模板.xlsx"); + org.springframework.core.io.Resource resource = new ClassPathResource("excel-template/学生导入失败数据导出模板(1).xlsx"); InputStream inputStream = resource.getInputStream(); //3、通过工具类下载文件 new ExcelExportUtil(StudentImportFailureVo.class, Constant.ROW_INDEX, Constant.STYLE_INDEX). - export(response, inputStream, parse, "学生信息导入失败表.xlsx"); + export(response, inputStream, parse, "学生信息导入失败表(1).xlsx"); } @Override - public R queryAccount(String account,Integer schoolId) { - List result = studentDao.queryAccount(account,schoolId); + public R queryAccount(String account, Integer schoolId) { + List result = studentDao.queryAccount(account, schoolId); List vos = userInfoDao.queryAccount(account); - if (result.size()>1){ - return R.error("系统存在多个相同的账号:"+account); - }else if (result.size()==1){return R.ok().put("data",result); - }else if (vos.size()>0){ + if (result.size() > 1) { + return R.error("系统存在多个相同的账号:" + account); + } else if (result.size() == 1) { + return R.ok().put("data", result); + } else if (vos.size() > 0) { return R.error("账号已存在"); } return R.ok(); diff --git a/src/main/java/com/msdw/tms/service/impl/SystemSettingServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/SystemSettingServiceImpl.java index e620417..3229994 100644 --- a/src/main/java/com/msdw/tms/service/impl/SystemSettingServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/SystemSettingServiceImpl.java @@ -65,33 +65,35 @@ public class SystemSettingServiceImpl implements SystemSetttingService { String email = staffVo.getEmail(); String workNumber = staffVo.getWorkNumber(); List staff = staffVo.getStaff(); - if (phone!=null&&phone!=""){ + if (phone != null && phone != "") { List resultP = userInfoDao.queryPhone(phone); - if (resultP.size()>0){ - return R.error(400,"手机号不能重复"); + if (resultP.size() > 0) { + return R.error(400, "手机号不能重复"); } } - if (email!=null&&email!=""){ + if (email != null && email != "") { List resultE = userInfoDao.queryEmail(email); - if (resultE.size()>0){ - return R.error(400,"手机号不能重复"); + if (resultE.size() > 0) { + return R.error(400, "手机号不能重复"); } } List resultA = userInfoDao.queryAccount(account); // List resultW = systemSetttingDao.queryWorkNumber(workNumber); - if(resultA.size()>0){ - return R.error(400,"账号不能重复"); + if (resultA.size() > 0) { + return R.error(400, "账号不能重复"); } Integer userId = userInfoDao.addUserinfo(staffVo); - for (int i=0;i resultW = systemSetttingDao.queryWorkNumber(workNumber); - if (resultW.size()>0){ - return R.error(400,"工号不能重复"+workNumber); + if (resultW.size() > 0) { + return R.error(400, "工号不能重复" + workNumber); } StaffEntity entity = staff.get(i); entity.setSchoolId(ConstantUtils.Keda_schoolId).setPlatformId(ConstantUtils.PLATFORMID).setUserId(staffVo.getUserId()); boolean result = systemSetttingDao.addStaffN(entity); - if (!result) {throw new RuntimeException();} + if (!result) { + throw new RuntimeException(); + } } // String[] split = staffVo.getRoleId().split(","); // for (String s : split){ @@ -107,7 +109,7 @@ public class SystemSettingServiceImpl implements SystemSetttingService { @Override public PageUtils queryStaff(StaffVo staffVo) { Page tPage = new Page<>(staffVo.getPage(), staffVo.getSize()); - IPage staff = systemSetttingDao.queryStaff(tPage, staffVo.getSearchContent(),ConstantUtils.Keda_schoolId,staffVo.getStaffGradeIds(),staffVo.getStaffProfessionalArchitectureIds()); + IPage staff = systemSetttingDao.queryStaff(tPage, staffVo.getSearchContent(), ConstantUtils.Keda_schoolId, staffVo.getStaffGradeIds(), staffVo.getStaffProfessionalArchitectureIds()); PageUtils pageUtils = new PageUtils(staff); return pageUtils; } @@ -120,8 +122,8 @@ public class SystemSettingServiceImpl implements SystemSetttingService { List staff = systemSetttingDao.queryStaffInfo(userId); // result.setWorkNumber(staff.getWorkNumber()).setStaffGradeId(staff.getStaffGradeId()).setStaffGradeName(staff.getStaffGradeName()) // .setStaffProfessionalArchitectureId(staff.getStaffProfessionalArchitectureId()).setStaffProfessionalArchitectureName(staff.getStaffProfessionalArchitectureName()); - map.put("userInfo",result); - map.put("staffInfo",staff); + map.put("userInfo", result); + map.put("staffInfo", staff); return map; } @@ -138,45 +140,49 @@ public class SystemSettingServiceImpl implements SystemSetttingService { String roleIds = result.getRoleId(); String[] splitOld = staffVo.getRoleId().split(","); String[] splitNew = roleIds.split(","); - if (splitOld.length==splitNew.length&&splitNew.length<3){ - for (int i = 0;isplitOld.length){ + } else if (splitNew.length > splitOld.length) { boolean a = systemSetttingDao.updateStaff(staff.get(0)); StaffEntity staffEntity = staff.get(1); staffEntity.setUserId(staffVo.getUserId()); boolean b = systemSetttingDao.addStaffUpdata(staffEntity); - if (!a|!b){throw new RuntimeException();} - }else if (splitNew.length resultA = userInfoDao.queryAccount(account); List resultW = systemSetttingDao.queryWorkNumber(workNumber); - if (phone!=null&&phone!=""){ + if (phone != null && phone != "") { List resultP = userInfoDao.queryPhone(phone); - if (resultP.size()>0){ - return R.error(400,"手机号不能重复"); + if (resultP.size() > 0) { + return R.error(400, "手机号不能重复"); } } - if (email!=null&&email!=""){ + if (email != null && email != "") { List resultE = userInfoDao.queryEmail(email); - if (resultE.size()>0){ - return R.error(400,"手机号不能重复"); + if (resultE.size() > 0) { + return R.error(400, "手机号不能重复"); } } - if(resultA.size()>0){ - return R.error(400,"账号不能重复"); - }else if (resultW.size()>0){ - return R.error(400,"工号不能重复"); + if (resultA.size() > 0) { + return R.error(400, "账号不能重复"); + } else if (resultW.size() > 0) { + return R.error(400, "工号不能重复"); } boolean resultUserInfo = userInfoDao.updateUserInfo(staffVo); // String[] split = staffVo.getRoleId().split(","); @@ -206,21 +212,21 @@ public class SystemSettingServiceImpl implements SystemSetttingService { //查询是否存在相同的部门 String departmentName = staffVo.getStaffProfessionalArchitectureName(); String gradeName = staffVo.getStaffGradeName(); - if (gradeName!=null|gradeName!=""){ + if (gradeName != null | gradeName != "") { Integer department = systemSetttingDao.queryGrade(staffVo); - if (department==0){ + if (department == 0) { systemSetttingDao.addDepartment(staffVo); } - map.put("已存在的部门",departmentName); - }else{ + map.put("已存在的部门", departmentName); + } else { Integer department = systemSetttingDao.queryDepartment(staffVo); - if (department==0){ + if (department == 0) { boolean result = systemSetttingDao.addStaffGrade(staffVo); - if (!result){ + if (!result) { throw new RuntimeException(); } } - map.put("已存在的部门",gradeName); + map.put("已存在的部门", gradeName); } return map; } @@ -231,11 +237,17 @@ public class SystemSettingServiceImpl implements SystemSetttingService { return result; } + @Override @Transactional public Map upload(MultipartFile file) throws IOException { HashMap map = new HashMap<>(); List staffs = ExcelImportHelper.readStaff(file); + + if (staffs.size() <= 0) { + ExceptionCast.cast(CommonCode.EXCEL_FILE_FORMAT_ERROR_STAFFS); + } + List failVo1 = new ArrayList<>(); // 参数合法性校验,只能上传.xlsx后缀的文件 if (StringUtils.isBlank(file.getOriginalFilename()) @@ -245,24 +257,235 @@ public class SystemSettingServiceImpl implements SystemSetttingService { int size = staffs.size(); Long ii = 1L; try { - for (int i = 0;i resultW = systemSetttingDao.queryWorkNumber(workNumber); List resultA = userInfoDao.queryAccount(account); List resultU = userInfoDao.queryUserInfo(staffVo); - if (resultU.size()>0){//重复的数据 + if (resultU.size() > 0) {//重复的数据 StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("用户信息已存在"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -270,7 +493,7 @@ public class SystemSettingServiceImpl implements SystemSetttingService { i--; failVo1.add(vo); continue; - }else if (resultW.size()>0){ + } else if (resultW.size() > 0) { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("重复的工号"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -278,7 +501,7 @@ public class SystemSettingServiceImpl implements SystemSetttingService { i--; failVo1.add(vo); continue; - }else if (resultA.size()>0){ + } else if (resultA.size() > 0) { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("重复的账号"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -286,9 +509,9 @@ public class SystemSettingServiceImpl implements SystemSetttingService { i--; failVo1.add(vo); continue; - }else if (phone!=null&&phone!=""){ + } else if (phone != null && phone != "") { List resultP = userInfoDao.queryPhone(phone); - if (resultP.size()>0){ + if (resultP.size() > 0) { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("重复的手机号码"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -297,9 +520,9 @@ public class SystemSettingServiceImpl implements SystemSetttingService { failVo1.add(vo); continue; } - }else if (email!=null&&email!=""){ + } else if (email != null && email != "") { List resultE = userInfoDao.queryEmail(email); - if (resultE.size()>0){ + if (resultE.size() > 0) { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("重复的邮箱号"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -310,18 +533,18 @@ public class SystemSettingServiceImpl implements SystemSetttingService { } } - if (!staffs.isEmpty()&&staffs.size()>0){ + if (!staffs.isEmpty() && staffs.size() > 0) { staffVo.setPassword(ConstantUtils.INITIAL_PASSWORD).setUniqueIdentificationAccount(String.valueOf(System.currentTimeMillis())); staff.setPlatformId(ConstantUtils.PLATFORMID).setUserId(staffVo.getUserId()); staffVo.setPlatformId(ConstantUtils.PLATFORMID).setToken(new ConstantUtils().token); String[] split = staffVo.getRoleId().split(","); String s = ""; for (String str : split) { - s=s+str; + s = s + str; } - if (s.indexOf("13")!=-1){//2 - if (architectureName!=null&&architectureName!=""){ - if (gradeName==null|gradeName==""){ + if (s.indexOf("13") != -1) {//2 + if (architectureName != null && architectureName != "") { + if (gradeName == null | gradeName == "") { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("二级部门不能为空(管理员)"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -329,9 +552,9 @@ public class SystemSettingServiceImpl implements SystemSetttingService { i--; failVo1.add(vo); continue; - }else{ + } else { Integer b = systemSetttingDao.queryDepartmentNameOrganization(architectureName, ConstantUtils.Keda_schoolId); - if (b==null){ + if (b == null) { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("不存在的一级部门(管理员)"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -340,8 +563,8 @@ public class SystemSettingServiceImpl implements SystemSetttingService { failVo1.add(vo); continue; } - List a = systemSetttingDao.judgmentGrade(architectureName,ConstantUtils.Keda_schoolId); - if (a.size()==0){ + List a = systemSetttingDao.judgmentGrade(architectureName, ConstantUtils.Keda_schoolId); + if (a.size() == 0) { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("不存在此子级部门(管理员)"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -353,9 +576,9 @@ public class SystemSettingServiceImpl implements SystemSetttingService { } } } - if (s.indexOf("14")!=-1){//3 - if (architectureNameTwo!=null&&architectureNameTwo!=""){ - if (gradeNameTwo==null|gradeNameTwo==""){ + if (s.indexOf("14") != -1) {//3 + if (architectureNameTwo != null && architectureNameTwo != "") { + if (gradeNameTwo == null | gradeNameTwo == "") { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("二级部门不能为空(老师)"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -363,9 +586,9 @@ public class SystemSettingServiceImpl implements SystemSetttingService { i--; failVo1.add(vo); continue; - }else{ + } else { Integer b = systemSetttingDao.queryDepartmentNameOrganization(architectureNameTwo, ConstantUtils.Keda_schoolId); - if (b==null){ + if (b == null) { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("不存在此的一级部门(老师)"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -374,8 +597,8 @@ public class SystemSettingServiceImpl implements SystemSetttingService { failVo1.add(vo); continue; } - List a = systemSetttingDao.judgmentGrade(architectureNameTwo,ConstantUtils.Keda_schoolId); - if (a.size()==0){ + List a = systemSetttingDao.judgmentGrade(architectureNameTwo, ConstantUtils.Keda_schoolId); + if (a.size() == 0) { StaffExportVo vo = new StaffExportVo(); vo.setFailureMsg("不存在的子级部门(老师)"); vo.setIndex(ii).setUserName(staffVo.getUserName()).setAccount(staffVo.getAccount()).setRole(staffVo.getRole()).setWorkNumber(staffVo.getWorkNumber()).setStaffGradeName(staffVo.getStaffGradeName()).setStaffProfessionalArchitectureName(staffVo.getStaffProfessionalArchitectureName()).setStaffGradeNameTwo(staffVo.getStaffGradeNameTwo()).setStaffProfessionalArchitectureNameTwo(staffVo.getStaffProfessionalArchitectureNameTwo()).setPhone(staffVo.getPhone()).setEmail(staffVo.getEmail()).setSchoolAppellationName(staffVo.getSchoolAppellationName()); @@ -389,25 +612,29 @@ public class SystemSettingServiceImpl implements SystemSetttingService { } userInfoDao.addUserinfo(staffVo); - for (String str : split){ - if (Integer.parseInt(str)==13){//2 - Integer organizationId = systemSetttingDao.queryDepartmentNameOrganization(staffVo.getStaffProfessionalArchitectureName(),ConstantUtils.Keda_schoolId); - Integer gradeId = systemSetttingDao.queryDepartmentNameGrade(staffVo.getStaffGradeName(),organizationId); + for (String str : split) { + if (Integer.parseInt(str) == 13) {//2 + Integer organizationId = systemSetttingDao.queryDepartmentNameOrganization(staffVo.getStaffProfessionalArchitectureName(), ConstantUtils.Keda_schoolId); + Integer gradeId = systemSetttingDao.queryDepartmentNameGrade(staffVo.getStaffGradeName(), organizationId); staffVo.setStaffGradeId(gradeId).setStaffProfessionalArchitectureId(organizationId); boolean b = systemSetttingDao.addStaffManager(staffVo); - if(!b){throw new RuntimeException();} - }else if (Integer.parseInt(str)==14){//3 - Integer organizationId = systemSetttingDao.queryDepartmentNameOrganization(staffVo.getStaffProfessionalArchitectureNameTwo(),ConstantUtils.Keda_schoolId); - Integer gradeId = systemSetttingDao.queryDepartmentNameGrade(staffVo.getStaffGradeNameTwo(),organizationId); + if (!b) { + throw new RuntimeException(); + } + } else if (Integer.parseInt(str) == 14) {//3 + Integer organizationId = systemSetttingDao.queryDepartmentNameOrganization(staffVo.getStaffProfessionalArchitectureNameTwo(), ConstantUtils.Keda_schoolId); + Integer gradeId = systemSetttingDao.queryDepartmentNameGrade(staffVo.getStaffGradeNameTwo(), organizationId); staffVo.setStaffGradeId(gradeId).setStaffProfessionalArchitectureId(organizationId); boolean b = systemSetttingDao.addStaffTeacher(staffVo); - if(!b){throw new RuntimeException();} + if (!b) { + throw new RuntimeException(); + } } } } } - }catch (RuntimeException e){ + } catch (RuntimeException e) { e.printStackTrace(); throw new RuntimeException(); } @@ -424,14 +651,14 @@ public class SystemSettingServiceImpl implements SystemSetttingService { ops.set(token, failureVOJson, 30 * 60, TimeUnit.SECONDS); } map.put("token", token); - map.put("successNum", (size-failVo1.size())+""); - map.put("failureNum", failVo1.size()+""); + map.put("successNum", (size - failVo1.size()) + ""); + map.put("failureNum", failVo1.size() + ""); return map; } @Override - public void exportFailureRecord(HttpServletResponse response, String token) throws Exception{ + public void exportFailureRecord(HttpServletResponse response, String token) throws Exception { if (StringUtils.isEmpty(token)) { return; } @@ -454,14 +681,11 @@ public class SystemSettingServiceImpl implements SystemSetttingService { new ExcelExportUtil(StaffExportVo.class, Constant.ROW_INDEX, Constant.STYLE_INDEX). export(response, inputStream, parse, "导入失败数据表.xlsx"); - if (inputStream!=null){ + if (inputStream != null) { inputStream.close(); } - - - // //2.加载模板流数据 // org.springframework.core.io.Resource resource = new ClassPathResource("excel-template/staff/测试.xlsx"); //// org.springframework.core.io.Resource resource = new FileSystemResource("E:/JavaworkSpace2/msdw_tms/src/main/resources/excel-template/员工信息导入失败模板.xlsx"); @@ -482,18 +706,19 @@ public class SystemSettingServiceImpl implements SystemSetttingService { } @Override - public R queryAccount(String account,Integer schoolId) { + public R queryAccount(String account, Integer schoolId) { HashMap map = new HashMap<>(); - List result = systemSetttingDao.queryAccount(account,schoolId); + List result = systemSetttingDao.queryAccount(account, schoolId); List vos = userInfoDao.queryAccount(account); - if (result.size()>1){return R.error("系统存在多个相同的账号:"+account); - }else if (result.size()==1){ + if (result.size() > 1) { + return R.error("系统存在多个相同的账号:" + account); + } else if (result.size() == 1) { StaffVo staffVo = result.get(0); - map.put("user",staffVo); + map.put("user", staffVo); List staffVos = systemSetttingDao.queryStaffInfo(staffVo.getUserId()); - map.put("staff",staffVos); - return R.ok().put("data",map); - }else if (vos.size()>0){ + map.put("staff", staffVos); + return R.ok().put("data", map); + } else if (vos.size() > 0) { return R.error("账号已存在"); } return R.ok(); @@ -501,14 +726,14 @@ public class SystemSettingServiceImpl implements SystemSetttingService { @Override @Transactional - public R resetPwd(Integer userId,String newPwd) { + public R resetPwd(Integer userId, String newPwd) { UserInfoEntity user = new UserInfoEntity(); user.setPassword(newPwd); int count = userInfoDao.update(user, new QueryWrapper().eq("userId", userId)); - if(count > 0){ + if (count > 0) { return R.ok(); - }else{ - return R.error(20002,"重置失败"); + } else { + return R.error(20002, "重置失败"); } } diff --git a/src/main/resources/excel-template/学生导入失败数据导出模板(1).xlsx b/src/main/resources/excel-template/学生导入失败数据导出模板(1).xlsx new file mode 100644 index 0000000..d44230a Binary files /dev/null and b/src/main/resources/excel-template/学生导入失败数据导出模板(1).xlsx differ diff --git a/src/main/resources/mapper/tms/UserInfoDao.xml b/src/main/resources/mapper/tms/UserInfoDao.xml index 5ec1bd1..9a4642c 100644 --- a/src/main/resources/mapper/tms/UserInfoDao.xml +++ b/src/main/resources/mapper/tms/UserInfoDao.xml @@ -146,7 +146,7 @@ values (#{userName}, #{uniqueIdentificationAccount}, #{phone}, #{account},#{password},#{roleId}, - (SELECT schoolId FROM school WHERE schoolName = #{schoolAppellationName}),now(),#{token}) + #{schoolId},now(),#{token}) INSERT INTO hr_user_info ( account, userName, roleId, phone, email, uniqueIdentificationAccount, schoolId,creationTime,password,token)