学生、员工导入修改

hehai
rong.liu 4 years ago
parent cf83a5cc0e
commit 3d38d6559a
  1. 2
      src/main/java/com/msdw/tms/TmsApplication.java
  2. 163
      src/main/java/com/msdw/tms/common/utils/ExcelImportHelper.java
  3. 4
      src/main/java/com/msdw/tms/entity/response/CommonCode.java
  4. 14
      src/main/java/com/msdw/tms/entity/vo/StudentImportFailureVo.java
  5. 107
      src/main/java/com/msdw/tms/service/impl/StudentServiceImpl.java
  6. 251
      src/main/java/com/msdw/tms/service/impl/SystemSettingServiceImpl.java
  7. BIN
      src/main/resources/excel-template/学生导入失败数据导出模板(1).xlsx
  8. 2
      src/main/resources/mapper/tms/UserInfoDao.xml

@ -6,7 +6,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling//定时任务 //@EnableScheduling//定时任务
@SpringBootApplication @SpringBootApplication
public class TmsApplication extends SpringBootServletInitializer { public class TmsApplication extends SpringBootServletInitializer {

@ -1,7 +1,12 @@
package com.msdw.tms.common.utils; 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.StaffVo;
import com.msdw.tms.entity.vo.StudentVo; 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.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -13,12 +18,59 @@ import java.util.List;
public class ExcelImportHelper { 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 * @param file
* @return * @return
*/ */
public static List<StudentVo> readStudent(MultipartFile file) { public static List<StudentVo> readStudent(MultipartFile file) throws IOException {
List<StudentVo> list = new ArrayList<StudentVo>(); List<StudentVo> list = new ArrayList<StudentVo>();
Workbook workbook = getWorkbook(file); Workbook workbook = getWorkbook(file);
@ -29,38 +81,57 @@ public class ExcelImportHelper {
if (hssfSheet == null) { if (hssfSheet == null) {
continue; continue;
} }
int count = 1;
// 循环行Row//开始行2 // 循环行Row//开始行2
for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
Row row = hssfSheet.getRow(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 phone;
Cell email; Cell email;
if (row != null) { if (row != null) {
student = new StudentVo(); student = new StudentVo();
row.getCell(0).setCellType(CellType.STRING); row.getCell(0).setCellType(CellType.STRING);
Cell studentName = row.getCell(0); Cell studentName = row.getCell(0);
row.getCell(1).setCellType(CellType.STRING); row.getCell(1).setCellType(CellType.STRING);
Cell schoolAppellationName = row.getCell(1); Cell account = row.getCell(1);
row.getCell(2).setCellType(CellType.STRING); row.getCell(2).setCellType(CellType.STRING);
Cell account = row.getCell(2);
Cell studentNumber = row.getCell(2);
if (row.getCell(3) != null) {
row.getCell(3).setCellType(CellType.STRING); row.getCell(3).setCellType(CellType.STRING);
Cell studentNumber = row.getCell(3); phone = row.getCell(3);
if (row.getCell(4)!=null){
row.getCell(4).setCellType(CellType.STRING);
phone = row.getCell(4);
} else { } else {
phone = row.createCell(4); phone = row.createCell(3);
} }
if (row.getCell(5)!=null){
row.getCell(5).setCellType(CellType.STRING); if (row.getCell(4) != null) {
email = row.getCell(5); row.getCell(4).setCellType(CellType.STRING);
email = row.getCell(4);
} else { } else {
email = row.createCell(5); 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.setRoleId(ConstantUtils.STUDENT_ROLE);
// 学生学号 // 学生学号
student.setWorkNumber(studentNumber.getStringCellValue()); student.setWorkNumber(studentNumber.getStringCellValue());
//所属院校
student.setSchoolAppellationName(schoolAppellationName.getStringCellValue());
//用户账号 //用户账号
student.setAccount(account.getStringCellValue()); student.setAccount(account.getStringCellValue());
//电话 //电话
@ -87,12 +156,15 @@ public class ExcelImportHelper {
return list; return list;
} }
/** /**
* 读取员工管理 * 读取员工管理
*
* @param file * @param file
* @return * @return
*/ */
public static List<StaffVo> readStaff(MultipartFile file) { public static List<StaffVo> readStaff(MultipartFile file) throws IOException {
List<StaffVo> list = new ArrayList<StaffVo>(); List<StaffVo> list = new ArrayList<StaffVo>();
Workbook workbook = getWorkbook(file); Workbook workbook = getWorkbook(file);
@ -103,39 +175,62 @@ public class ExcelImportHelper {
if (hssfSheet == null) { if (hssfSheet == null) {
continue; continue;
} }
int lastRowNum = hssfSheet.getLastRowNum()+1;//最后一行行标,比行数小1 /*int lastRowNum = hssfSheet.getLastRowNum() + 1;//最后一行行标,比行数小1
if (lastRowNum == 2) { if (lastRowNum == 2) {
break; break;
} }*/
int count = 1;
// 循环行Row//开始行2 // 循环行Row//开始行2
for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
Row row = hssfSheet.getRow(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 phone;
Cell email; Cell email;
Cell staffGradeName; Cell staffGradeName;
Cell staffProfessionalArchitectureName; Cell staffProfessionalArchitectureName;
Cell staffGradeNameTwo; Cell staffGradeNameTwo;
Cell staffProfessionalArchitectureNameTwo; Cell staffProfessionalArchitectureNameTwo;
if (row != null) { /*Cell account;
Cell role;
Cell workNumber;*/
Cell userName;
if (row == null) {
continue;
} else {
staff = new StaffVo(); staff = new StaffVo();
if (row.getCell(0) != null) { if (row.getCell(0) != null) {
row.getCell(0).setCellType(CellType.STRING); row.getCell(0).setCellType(CellType.STRING);
userName = row.getCell(0); userName = row.getCell(0);
} else { } else {
continue; userName = row.createCell(0);
} }
//姓名
/* row.getCell(0).setCellType(CellType.STRING);
String userName = row.getCell(0).getStringCellValue();*/
//账号
row.getCell(1).setCellType(CellType.STRING); row.getCell(1).setCellType(CellType.STRING);
Cell account = row.getCell(1); Cell account = row.getCell(1);
//角色
row.getCell(2).setCellType(CellType.STRING); row.getCell(2).setCellType(CellType.STRING);
Cell role = row.getCell(2); Cell role = row.getCell(2);
//工号
row.getCell(3).setCellType(CellType.STRING); row.getCell(3).setCellType(CellType.STRING);
Cell workNumber = row.getCell(3); 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); row.getCell(4).setCellType(CellType.STRING);
staffProfessionalArchitectureName = row.getCell(4); staffProfessionalArchitectureName = row.getCell(4);
@ -160,14 +255,6 @@ public class ExcelImportHelper {
} else { } else {
staffGradeNameTwo = row.createCell(7); 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); row.getCell(8).setCellType(CellType.STRING);
phone = row.getCell(8); phone = row.getCell(8);
@ -180,11 +267,9 @@ public class ExcelImportHelper {
} else { } else {
email = row.createCell(9); 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 roleValue = role.getStringCellValue();
String str; String str;
@ -218,7 +303,7 @@ public class ExcelImportHelper {
//邮箱 //邮箱
staff.setEmail(email.getStringCellValue()); staff.setEmail(email.getStringCellValue());
//所属院校 //所属院校
staff.setSchoolAppellationName(schoolAppellationName.getStringCellValue()); //staff.setSchoolAppellationName(schoolAppellationName.getStringCellValue());
//学校id //学校id
staff.setSchoolId(ConstantUtils.Keda_schoolId); staff.setSchoolId(ConstantUtils.Keda_schoolId);
list.add(staff); list.add(staff);

@ -17,8 +17,12 @@ public enum CommonCode implements ResultCode {
EXCEL_FILE_INVALID(false, 10009, "上传excel文件错误!"), EXCEL_FILE_INVALID(false, 10009, "上传excel文件错误!"),
REPEAT_INEXCEL(false, 10010, "试题在excel表中重复!"), REPEAT_INEXCEL(false, 10010, "试题在excel表中重复!"),
EVALUATION_QUESTION_NUM_INVALID(false, 10011, "当前测评题数设置为0,请先设置测评题数!"), 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, "操作失败!"), FAIL(false, 11111, "操作失败!"),
ROLE_NAME_EXIST(false, 20001, "该角色名称已存在,请重新输入!"), ROLE_NAME_EXIST(false, 20001, "该角色名称已存在,请重新输入!"),
ROLE_EMP_EXIST(false, 44001, "该角色有用户关联,不能删除!"), ROLE_EMP_EXIST(false, 44001, "该角色有用户关联,不能删除!"),
SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!");

@ -15,23 +15,23 @@ public class StudentImportFailureVo {
//用户姓名 //用户姓名
@ExcelAttribute(sort = 0) @ExcelAttribute(sort = 0)
private String userName; private String userName;
//所属院校 /*//所属院校
@ExcelAttribute(sort = 1) @ExcelAttribute(sort = 1)
private String schoolAppellationName; private String schoolAppellationName;*/
//账号 //账号
@ExcelAttribute(sort = 2) @ExcelAttribute(sort = 1)
private String account; private String account;
//学号 //学号
@ExcelAttribute(sort = 3) @ExcelAttribute(sort = 2)
private String workNumber; private String workNumber;
//手机号码 //手机号码
@ExcelAttribute(sort = 4) @ExcelAttribute(sort = 3)
private String phone; private String phone;
//邮箱 //邮箱
@ExcelAttribute(sort = 5) @ExcelAttribute(sort = 4)
private String email; private String email;
//失败原因 //失败原因
@ExcelAttribute(sort = 6) @ExcelAttribute(sort = 5)
private String failureMsg; private String failureMsg;
// //
// @ExcelAttribute(sort = 7) // @ExcelAttribute(sort = 7)

@ -142,7 +142,14 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
@Transactional @Transactional
@Override @Override
public Map<String, String> upload(MultipartFile file, Integer schoolId) throws IOException { public Map<String, String> upload(MultipartFile file, Integer schoolId) throws IOException {
List<StudentVo> students = ExcelImportHelper.readStudent(file); List<StudentVo> students = ExcelImportHelper.readStudent(file);
if (students.size() <= 0) {
ExceptionCast.cast(CommonCode.EXCEL_FILE_FORMAT_ERROR);
}
Map<String, String> errorMap = new HashMap<>();
List<StudentImportFailureVo> failVo1 = new ArrayList<>(); List<StudentImportFailureVo> failVo1 = new ArrayList<>();
// 参数合法性校验,只能上传.xlsx后缀的文件 // 参数合法性校验,只能上传.xlsx后缀的文件
if (StringUtils.isBlank(file.getOriginalFilename()) if (StringUtils.isBlank(file.getOriginalFilename())
@ -155,11 +162,66 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
try { try {
for (int i = 0; i < students.size(); i++) { for (int i = 0; i < students.size(); i++) {
StudentVo student = students.get(i); StudentVo student = students.get(i);
String userName = student.getUserName();
if (userName.equals("")) {
log.error("*姓名不能为空");
StudentImportFailureVo vo = new StudentImportFailureVo();
++ii;
vo.setIndex(ii)
.setUserName(student.getUserName() + " 必填项:((姓名不能为空)")
.setAccount(student.getAccount())
.setWorkNumber(student.getWorkNumber())
.setPhone(student.getPhone()).setEmail(student.getEmail())
;
failVo1.add(vo);
students.remove(i);
i--;
continue;
}
String phone = student.getPhone(); String phone = student.getPhone();
String workNumber = student.getWorkNumber(); String workNumber = student.getWorkNumber();
if (workNumber.equals("")) {
log.error("*学号不能为空");
StudentImportFailureVo vo = new StudentImportFailureVo();
++ii;
vo.setIndex(ii)
.setUserName(student.getUserName())
.setAccount(student.getAccount())
.setWorkNumber(student.getWorkNumber() + " 必填项:(*学号不能为空)")
.setPhone(student.getPhone()).setEmail(student.getEmail())
;
failVo1.add(vo);
students.remove(i);
i--;
continue;
}
String account = student.getAccount(); String account = student.getAccount();
if (account.equals("")) {
log.error("*账号不能为空");
StudentImportFailureVo vo = new StudentImportFailureVo();
++ii;
vo.setIndex(ii)
.setUserName(student.getUserName())
.setAccount(student.getAccount() + " 必填项:(*账号不能为空)")
.setWorkNumber(student.getWorkNumber())
.setPhone(student.getPhone()).setEmail(student.getEmail())
;
failVo1.add(vo);
students.remove(i);
i--;
continue;
}
StudentVo studentVo = new StudentVo(); StudentVo studentVo = new StudentVo();
String schoolAppellationName = student.getSchoolAppellationName(); //String schoolAppellationName = student.getSchoolAppellationName();
List<Integer> result1 = studentDao.queryStudentIdNumber(workNumber, schoolId); List<Integer> result1 = studentDao.queryStudentIdNumber(workNumber, schoolId);
List<StudentEntity> result4 = userInfoDao.queryStudentAccount(account); List<StudentEntity> result4 = userInfoDao.queryStudentAccount(account);
String email = student.getEmail(); String email = student.getEmail();
@ -169,8 +231,12 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
log.error("该号码已被使用"); log.error("该号码已被使用");
StudentImportFailureVo vo = new StudentImportFailureVo(); StudentImportFailureVo vo = new StudentImportFailureVo();
++ii; ++ii;
vo.setIndex(ii).setUserName(student.getUserName()).setSchoolAppellationName(student.getSchoolAppellationName()) vo.setIndex(ii)
.setAccount(student.getAccount()).setWorkNumber(student.getWorkNumber()).setPhone(student.getPhone()+" (重复的号码)").setEmail(student.getEmail()) .setUserName(student.getUserName())
.setAccount(student.getAccount())
.setWorkNumber(student.getWorkNumber())
.setPhone(student.getPhone() + " (重复的号码)")
.setEmail(student.getEmail())
; ;
failVo1.add(vo); failVo1.add(vo);
students.remove(i); students.remove(i);
@ -182,21 +248,26 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
if (email != null && email != "") { if (email != null && email != "") {
studentVo.setEmail(email); studentVo.setEmail(email);
} }
List<Integer> result3 = studentDao.querySchoolName(schoolAppellationName); // List<Integer> result3 = studentDao.querySchoolName(schoolAppellationName);
// 唯一标示性账号 // 唯一标示性账号
studentVo.setUniqueIdentificationAccount(String.valueOf(System.currentTimeMillis())). studentVo.setUniqueIdentificationAccount(String.valueOf(System.currentTimeMillis())).
setPassword(ConstantUtils.INITIAL_PASSWORD).setToken(new ConstantUtils().token) setPassword(ConstantUtils.INITIAL_PASSWORD).setToken(new ConstantUtils().token)
.setSchoolId(ConstantUtils.Keda_schoolId).setRoleId(ConstantUtils.STUDENT_ROLE) .setSchoolId(ConstantUtils.Keda_schoolId).setRoleId(ConstantUtils.STUDENT_ROLE)
; ;
studentVo.setAccount(student.getAccount()).setSchoolAppellationName(schoolAppellationName) studentVo.setAccount(student.getAccount())
.setUserName(student.getUserName()).setIsdel(Constant.IsDel.NOT_DEL.getType()); .setUserName(student.getUserName())
.setIsdel(Constant.IsDel.NOT_DEL.getType());
if (result1.size() >= 1) { if (result1.size() >= 1) {
log.error("该学号已存在"); log.error("该学号已存在");
StudentImportFailureVo vo = new StudentImportFailureVo(); StudentImportFailureVo vo = new StudentImportFailureVo();
++ii; ++ii;
vo.setIndex(ii).setUserName(student.getUserName()).setSchoolAppellationName(student.getSchoolAppellationName()) vo.setIndex(ii)
.setAccount(student.getAccount()).setWorkNumber(student.getWorkNumber()+" (重复的学号)").setPhone(student.getPhone()).setEmail(student.getEmail()) .setUserName(student.getUserName())
.setAccount(student.getAccount())
.setWorkNumber(student.getWorkNumber() + " (重复的学号)")
.setPhone(student.getPhone()).setEmail(student.getEmail())
; ;
// .setFailureMsg("重复的学号"); // .setFailureMsg("重复的学号");
failVo1.add(vo); failVo1.add(vo);
@ -208,8 +279,12 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
log.error("账号已存在"); log.error("账号已存在");
StudentImportFailureVo vo = new StudentImportFailureVo(); StudentImportFailureVo vo = new StudentImportFailureVo();
++ii; ++ii;
vo.setIndex(ii).setUserName(student.getUserName()).setSchoolAppellationName(student.getSchoolAppellationName()) vo.setIndex(ii)
.setAccount(student.getAccount()+" (重复的账号)").setWorkNumber(student.getWorkNumber()).setPhone(student.getPhone()).setEmail(student.getEmail()) .setUserName(student.getUserName())
.setAccount(student.getAccount() + " (重复的账号)")
.setWorkNumber(student.getWorkNumber())
.setPhone(student.getPhone())
.setEmail(student.getEmail())
; ;
// .setFailureMsg("重复的账号"); // .setFailureMsg("重复的账号");
failVo1.add(vo); failVo1.add(vo);
@ -218,7 +293,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
i--; i--;
continue; continue;
} }
else if(result3.size()!=1){ /*else if(result3.size()!=1){
log.error("不存在该院校"); log.error("不存在该院校");
StudentImportFailureVo vo = new StudentImportFailureVo(); StudentImportFailureVo vo = new StudentImportFailureVo();
++ii; ++ii;
@ -230,9 +305,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
students.remove(i); students.remove(i);
i--; i--;
continue; continue;
} }*/
++ii; ++ii;
if (!students.isEmpty() && students.size() > 0) { if (!students.isEmpty() && students.size() > 0) {
studentVo.setSchoolId(schoolId);
userInfoDao.batchSaveUserInfo(studentVo); userInfoDao.batchSaveUserInfo(studentVo);
student.setUserId(studentVo.getUserId()).setIsdel(Constant.IsDel.NOT_DEL.getType()).setPlatformId(ConstantUtils.PLATFORMID); student.setUserId(studentVo.getUserId()).setIsdel(Constant.IsDel.NOT_DEL.getType()).setPlatformId(ConstantUtils.PLATFORMID);
boolean b = studentDao.saveStudent(student); boolean b = studentDao.saveStudent(student);
@ -284,12 +360,12 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
parse.sort(Comparator.comparing(StudentImportFailureVo::getIndex)); parse.sort(Comparator.comparing(StudentImportFailureVo::getIndex));
//2.加载模板流数据 //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(); InputStream inputStream = resource.getInputStream();
//3、通过工具类下载文件 //3、通过工具类下载文件
new ExcelExportUtil(StudentImportFailureVo.class, Constant.ROW_INDEX, Constant.STYLE_INDEX). new ExcelExportUtil(StudentImportFailureVo.class, Constant.ROW_INDEX, Constant.STYLE_INDEX).
export(response, inputStream, parse, "学生信息导入失败表.xlsx"); export(response, inputStream, parse, "学生信息导入失败表(1).xlsx");
} }
@ -299,7 +375,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao,StudentEntity> im
List<StaffVo> vos = userInfoDao.queryAccount(account); List<StaffVo> vos = userInfoDao.queryAccount(account);
if (result.size() > 1) { if (result.size() > 1) {
return R.error("系统存在多个相同的账号:" + account); return R.error("系统存在多个相同的账号:" + account);
}else if (result.size()==1){return R.ok().put("data",result); } else if (result.size() == 1) {
return R.ok().put("data", result);
} else if (vos.size() > 0) { } else if (vos.size() > 0) {
return R.error("账号已存在"); return R.error("账号已存在");
} }

@ -91,7 +91,9 @@ public class SystemSettingServiceImpl implements SystemSetttingService {
StaffEntity entity = staff.get(i); StaffEntity entity = staff.get(i);
entity.setSchoolId(ConstantUtils.Keda_schoolId).setPlatformId(ConstantUtils.PLATFORMID).setUserId(staffVo.getUserId()); entity.setSchoolId(ConstantUtils.Keda_schoolId).setPlatformId(ConstantUtils.PLATFORMID).setUserId(staffVo.getUserId());
boolean result = systemSetttingDao.addStaffN(entity); boolean result = systemSetttingDao.addStaffN(entity);
if (!result) {throw new RuntimeException();} if (!result) {
throw new RuntimeException();
}
} }
// String[] split = staffVo.getRoleId().split(","); // String[] split = staffVo.getRoleId().split(",");
// for (String s : split){ // for (String s : split){
@ -141,14 +143,18 @@ public class SystemSettingServiceImpl implements SystemSetttingService {
if (splitOld.length == splitNew.length && splitNew.length < 3) { if (splitOld.length == splitNew.length && splitNew.length < 3) {
for (int i = 0; i < splitNew.length; i++) { for (int i = 0; i < splitNew.length; i++) {
boolean a = systemSetttingDao.updateStaff(staff.get(i)); boolean a = systemSetttingDao.updateStaff(staff.get(i));
if (!a){throw new RuntimeException();} if (!a) {
throw new RuntimeException();
}
} }
} else if (splitNew.length > splitOld.length) { } else if (splitNew.length > splitOld.length) {
boolean a = systemSetttingDao.updateStaff(staff.get(0)); boolean a = systemSetttingDao.updateStaff(staff.get(0));
StaffEntity staffEntity = staff.get(1); StaffEntity staffEntity = staff.get(1);
staffEntity.setUserId(staffVo.getUserId()); staffEntity.setUserId(staffVo.getUserId());
boolean b = systemSetttingDao.addStaffUpdata(staffEntity); boolean b = systemSetttingDao.addStaffUpdata(staffEntity);
if (!a|!b){throw new RuntimeException();} if (!a | !b) {
throw new RuntimeException();
}
} else if (splitNew.length < splitOld.length) { } else if (splitNew.length < splitOld.length) {
boolean a = systemSetttingDao.deleteStaffOnly(staffVo.getUserId());//删除roleId最大的数据 boolean a = systemSetttingDao.deleteStaffOnly(staffVo.getUserId());//删除roleId最大的数据
staffVo.setStaffRoleId(Integer.parseInt(staffVo.getRoleId())); staffVo.setStaffRoleId(Integer.parseInt(staffVo.getRoleId()));
@ -231,11 +237,17 @@ public class SystemSettingServiceImpl implements SystemSetttingService {
return result; return result;
} }
@Override @Override
@Transactional @Transactional
public Map<String, String> upload(MultipartFile file) throws IOException { public Map<String, String> upload(MultipartFile file) throws IOException {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
List<StaffVo> staffs = ExcelImportHelper.readStaff(file); List<StaffVo> staffs = ExcelImportHelper.readStaff(file);
if (staffs.size() <= 0) {
ExceptionCast.cast(CommonCode.EXCEL_FILE_FORMAT_ERROR_STAFFS);
}
List<StaffExportVo> failVo1 = new ArrayList<>(); List<StaffExportVo> failVo1 = new ArrayList<>();
// 参数合法性校验,只能上传.xlsx后缀的文件 // 参数合法性校验,只能上传.xlsx后缀的文件
if (StringUtils.isBlank(file.getOriginalFilename()) if (StringUtils.isBlank(file.getOriginalFilename())
@ -250,15 +262,226 @@ public class SystemSettingServiceImpl implements SystemSetttingService {
StaffVo staffVo = staffs.get(i); StaffVo staffVo = staffs.get(i);
String phone = staffVo.getPhone(); String phone = staffVo.getPhone();
String email = staffVo.getEmail(); String email = staffVo.getEmail();
String workNumber = staffVo.getWorkNumber();
//校验员工姓名
if (staffVo.getUserName().equals("")) {
StaffExportVo vo = new StaffExportVo();
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());
staffs.remove(i);
i--;
failVo1.add(vo);
continue;
}
//用户账号
String account = staffVo.getAccount(); String account = staffVo.getAccount();
String gradeName = staffVo.getStaffGradeName(); //校验账号
if (account.equals("")) {
StaffExportVo vo = new StaffExportVo();
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());
staffs.remove(i);
i--;
failVo1.add(vo);
continue;
}
//校验角色
String role = staffVo.getRole();
if (role.equals("")) {
StaffExportVo vo = new StaffExportVo();
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());
staffs.remove(i);
i--;
failVo1.add(vo);
continue;
}
//校验工号
String workNumber = staffVo.getWorkNumber();//员工工号
if (workNumber.equals("")) {
StaffExportVo vo = new StaffExportVo();
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());
staffs.remove(i);
i--;
failVo1.add(vo);
continue;
}
//绑定专业名称(*管理员的一级部门)
String architectureName = staffVo.getStaffProfessionalArchitectureName(); String architectureName = staffVo.getStaffProfessionalArchitectureName();
String gradeNameTwo = staffVo.getStaffGradeNameTwo(); //绑定年级名称(*管理员的二级部门)
String gradeName = staffVo.getStaffGradeName();
//老师组织架构名称(*老师的一级部门)
String architectureNameTwo = staffVo.getStaffProfessionalArchitectureNameTwo(); String architectureNameTwo = staffVo.getStaffProfessionalArchitectureNameTwo();
//老师专业组织名称(*老师的二级部门)
String gradeNameTwo = staffVo.getStaffGradeNameTwo();
if (role != null) {
//根据角色校验用户导入的数据
switch (role.trim()) {
case "老师":
if (architectureNameTwo.trim().equals("") || gradeNameTwo.trim().equals("")) {
StaffExportVo vo = new StaffExportVo();
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());
staffs.remove(i);
i--;
failVo1.add(vo);
continue;
}
break;
case "管理员+老师":
if (architectureName.trim().equals("") || gradeName.trim().equals("")) {
StaffExportVo vo = new StaffExportVo();
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());
staffs.remove(i);
i--;
failVo1.add(vo);
continue;
} else if (architectureNameTwo.trim().equals("") || gradeNameTwo.trim().equals("")) {
StaffExportVo vo = new StaffExportVo();
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());
staffs.remove(i);
i--;
failVo1.add(vo);
continue;
} else if ((architectureNameTwo.trim().equals("") || gradeNameTwo.trim().equals(""))
&&
architectureName.trim().equals("") || gradeName.trim().equals("")) {
StaffExportVo vo = new StaffExportVo();
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());
staffs.remove(i);
i--;
failVo1.add(vo);
continue;
}
break;
case "管理员":
//architectureName gradeName
if (architectureName.trim().equals("") || gradeName.trim().equals("")) {
StaffExportVo vo = new StaffExportVo();
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());
staffs.remove(i);
i--;
failVo1.add(vo);
continue;
}
break;
}
}
StaffVo staff = new StaffVo(); StaffVo staff = new StaffVo();
staff.setSchoolId(ConstantUtils.Keda_schoolId);//设定科大学校id staff.setSchoolId(ConstantUtils.Keda_schoolId);//设定科大学校id
String schoolAppellationName = staffVo.getSchoolAppellationName(); //String schoolAppellationName = staffVo.getSchoolAppellationName();
List<Integer> resultW = systemSetttingDao.queryWorkNumber(workNumber); List<Integer> resultW = systemSetttingDao.queryWorkNumber(workNumber);
List<StaffVo> resultA = userInfoDao.queryAccount(account); List<StaffVo> resultA = userInfoDao.queryAccount(account);
List<StaffVo> resultU = userInfoDao.queryUserInfo(staffVo); List<StaffVo> resultU = userInfoDao.queryUserInfo(staffVo);
@ -395,13 +618,17 @@ public class SystemSettingServiceImpl implements SystemSetttingService {
Integer gradeId = systemSetttingDao.queryDepartmentNameGrade(staffVo.getStaffGradeName(), organizationId); Integer gradeId = systemSetttingDao.queryDepartmentNameGrade(staffVo.getStaffGradeName(), organizationId);
staffVo.setStaffGradeId(gradeId).setStaffProfessionalArchitectureId(organizationId); staffVo.setStaffGradeId(gradeId).setStaffProfessionalArchitectureId(organizationId);
boolean b = systemSetttingDao.addStaffManager(staffVo); boolean b = systemSetttingDao.addStaffManager(staffVo);
if(!b){throw new RuntimeException();} if (!b) {
throw new RuntimeException();
}
} else if (Integer.parseInt(str) == 14) {//3 } else if (Integer.parseInt(str) == 14) {//3
Integer organizationId = systemSetttingDao.queryDepartmentNameOrganization(staffVo.getStaffProfessionalArchitectureNameTwo(), ConstantUtils.Keda_schoolId); Integer organizationId = systemSetttingDao.queryDepartmentNameOrganization(staffVo.getStaffProfessionalArchitectureNameTwo(), ConstantUtils.Keda_schoolId);
Integer gradeId = systemSetttingDao.queryDepartmentNameGrade(staffVo.getStaffGradeNameTwo(), organizationId); Integer gradeId = systemSetttingDao.queryDepartmentNameGrade(staffVo.getStaffGradeNameTwo(), organizationId);
staffVo.setStaffGradeId(gradeId).setStaffProfessionalArchitectureId(organizationId); staffVo.setStaffGradeId(gradeId).setStaffProfessionalArchitectureId(organizationId);
boolean b = systemSetttingDao.addStaffTeacher(staffVo); boolean b = systemSetttingDao.addStaffTeacher(staffVo);
if(!b){throw new RuntimeException();} if (!b) {
throw new RuntimeException();
}
} }
} }
@ -459,9 +686,6 @@ public class SystemSettingServiceImpl implements SystemSetttingService {
} }
// //2.加载模板流数据 // //2.加载模板流数据
// org.springframework.core.io.Resource resource = new ClassPathResource("excel-template/staff/测试.xlsx"); // 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"); //// org.springframework.core.io.Resource resource = new FileSystemResource("E:/JavaworkSpace2/msdw_tms/src/main/resources/excel-template/员工信息导入失败模板.xlsx");
@ -486,7 +710,8 @@ public class SystemSettingServiceImpl implements SystemSetttingService {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
List<StaffVo> result = systemSetttingDao.queryAccount(account, schoolId); List<StaffVo> result = systemSetttingDao.queryAccount(account, schoolId);
List<StaffVo> vos = userInfoDao.queryAccount(account); List<StaffVo> vos = userInfoDao.queryAccount(account);
if (result.size()>1){return R.error("系统存在多个相同的账号:"+account); if (result.size() > 1) {
return R.error("系统存在多个相同的账号:" + account);
} else if (result.size() == 1) { } else if (result.size() == 1) {
StaffVo staffVo = result.get(0); StaffVo staffVo = result.get(0);
map.put("user", staffVo); map.put("user", staffVo);

@ -146,7 +146,7 @@
values values
(#{userName}, #{uniqueIdentificationAccount}, (#{userName}, #{uniqueIdentificationAccount},
#{phone}, #{account},#{password},#{roleId}, #{phone}, #{account},#{password},#{roleId},
(SELECT schoolId FROM school WHERE schoolName = #{schoolAppellationName}),now(),#{token}) #{schoolId},now(),#{token})
</insert> </insert>
<insert id="addUserinfo" useGeneratedKeys="true" keyProperty="userId" keyColumn="userId"> <insert id="addUserinfo" useGeneratedKeys="true" keyProperty="userId" keyColumn="userId">
INSERT INTO hr_user_info ( account, userName, roleId, phone, email, uniqueIdentificationAccount, schoolId,creationTime,password,token) INSERT INTO hr_user_info ( account, userName, roleId, phone, email, uniqueIdentificationAccount, schoolId,creationTime,password,token)

Loading…
Cancel
Save