Commit 250f93a6 authored by 李博今's avatar 李博今

增加导入内部去重

parent 125e6b82
......@@ -145,7 +145,7 @@ public class BClassServiceImpl implements BClassService {
public PersistModel administrativeImportExcel(HSSFWorkbook hwb, String token) throws IOException {
ArrayList<BClass> bClasses = new ArrayList<BClass>();
ArrayList<String> repeatCode = new ArrayList<String>();
String innerRepeatResult = "";
String[] headers = {"班级编号","学号","所属年级"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false,1); //获取excel数据
//判断年级是否存在
......@@ -155,7 +155,8 @@ public class BClassServiceImpl implements BClassService {
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
}
for(String[] value:values){ //将数据封装到entity
//外循环
outLoop : for(String[] value:values){ //将数据封装到entity
BClass bClass = null;
BClass b = new BClass(value[0]);
if(value[0]==null||value[0].equals("")||value[1]==null||value[1].equals("")){
......@@ -172,6 +173,13 @@ public class BClassServiceImpl implements BClassService {
valuesGrade.add(value[2]);
continue;
}
//表中去重
for(BClass bClass1 : bClasses){
if(b1.getCode().equals(bClass1.getCode())){
innerRepeatResult += "编号 " + b1.getCode() + " 在Excel中重复出现,除第一条以外的数据插入失败 ";
continue outLoop;
}
}
bClass= new BClass(value[0],value[1]);
bClass.setGradeCode(value[2]);
......@@ -197,7 +205,7 @@ public class BClassServiceImpl implements BClassService {
result+="以下班级的所属年级信息不存在:"+ JSON.toJSONString(valuesGrade)+"。";
}
return new PersistModel(line,result);
return new PersistModel(line,result + innerRepeatResult);
}
@Override
......@@ -205,7 +213,7 @@ public class BClassServiceImpl implements BClassService {
ArrayList<BClass> bClasses = new ArrayList<BClass>();
ArrayList<String> repeatCode = new ArrayList<String>();
ArrayList<String> AgencyCode = new ArrayList<String>();
String innerRepeatResult = "";
String[] headers = {"班级编号","班级名称","所属年级","教学单位"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false,1); //获取excel数据
//判断年级是否存在
......@@ -215,7 +223,7 @@ public class BClassServiceImpl implements BClassService {
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
}
for(String[] value:values){ //将数据封装到entity
outLoop : for(String[] value:values){ //将数据封装到entity
BClass bClass = null;
BClass b = new BClass(value[0]);
if(value[0]==null||value[0].equals("")||value[1]==null||value[1].equals("")){
......@@ -246,6 +254,13 @@ public class BClassServiceImpl implements BClassService {
bClass.setType("1");
bClass.setCommonBusinessId();
UserUtil.setCurrentPersistOperation(bClass);
//表中去重
for(BClass bClass1 : bClasses){
if(b1.getBusinessId().equals(bClass1.getBusinessId())){
innerRepeatResult += "班级编号 " + b1.getBusinessId() + " 在Excel中重复出现,除第一条以外的数据插入失败 ";
continue outLoop;
}
}
if(!bClasses.contains(bClass)){
bClasses.add(bClass);
......@@ -269,7 +284,7 @@ public class BClassServiceImpl implements BClassService {
result+="以下教学单位不存在:"+ JSON.toJSONString(AgencyCode)+"。";
}
return new PersistModel(line,result);
return new PersistModel(line,result + innerRepeatResult);
}
@Override
......
......@@ -115,7 +115,8 @@ public class BLessonServiceImpl implements BLessonService {
ArrayList<String> direction = new ArrayList<String>();
List<String> isChinese = new ArrayList<>();
List<String> isNegative = new ArrayList<>();
List<String> currentlyCode = new ArrayList<>();
String innerRepeatResult = "";
String[] headers = {"课程编号","课程名称","课程方向编号","学时","学分"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false,1); //获取excel数据
......@@ -159,8 +160,13 @@ public class BLessonServiceImpl implements BLessonService {
bLesson= new BLesson(value[0],value[1],value[3],value[4]);
bLesson.setDefaultUrl(global.getDEFAULT_COURSE_LOCATION());
UserUtil.setCurrentPersistOperation(bLesson);
//表中去重
if(currentlyCode.contains(bLesson.getCode())){
innerRepeatResult += "编号 " + value[1] + " 在Excel中重复出现,除第一条以外的数据插入失败 \n";
continue;
}
if(!lessons.contains(bLesson)){
currentlyCode.add(bLesson.getCode());
lessons.add(bLesson);
BLessonDirection bDirection = new BLessonDirection();
......@@ -203,7 +209,7 @@ public class BLessonServiceImpl implements BLessonService {
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST.getCode(),result);
}
return new PersistModel(1,result);
return new PersistModel(1,result + innerRepeatResult);
}
......
......@@ -86,7 +86,8 @@ public class BRClassStudentServiceImpl implements BRClassStudentService {
ArrayList<String> classCode = new ArrayList<String>();
ArrayList<String> repeatCode = new ArrayList<String>();
List<String> valuesGrade = new ArrayList<>();
List<String> currenty = new ArrayList<>();
String innerRepeatResult = "";
String[] headers = {"班级编号","学号"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false,1); //获取excel数据
......@@ -128,10 +129,16 @@ public class BRClassStudentServiceImpl implements BRClassStudentService {
//1.4 构造学生班级信息
brClassStudent= new BRClassStudent(value[0],value[1]);
if(currenty.contains(brClassStudent.toString())){
innerRepeatResult += "班级编号,学号分别为 " + value[0] + " " + value[1] + " 的数据,在Excel中重复出现,除第一条以外的数据插入失败 \n";
continue;
}
currenty.add(brClassStudent.toString());
brClassStudent.setCommonBusinessId();
//UserUtils.setCurrentPersistOperation(brClassStudent);
if(!brClassStudents.contains(brClassStudent)){
brClassStudents.add(brClassStudent);
}
}
......@@ -175,7 +182,7 @@ public class BRClassStudentServiceImpl implements BRClassStudentService {
int l1 = MapUtils.getInteger(map,"result",-2);
if(l1<=0)
throw new ServiceException(ResultServiceEnums.UPDATE_STUDENT_NUM_ERROR);
return new PersistModel(1,result.toString());
return new PersistModel(1,result.toString() + innerRepeatResult);
}
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
......
......@@ -87,7 +87,8 @@ public class BRSlStudentServiceImpl implements BRSlStudentService {
ArrayList<String> studentCode = new ArrayList<String>();
/*ArrayList<String> gitlabP = new ArrayList<String>();
ArrayList<String> gitlabUser = new ArrayList<String>();*/
String innerRepeatResult = "";
List<String> currently = new ArrayList<>();
String[] headers = {"课序号","学号"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false,1); //获取excel数据
......@@ -144,9 +145,14 @@ public class BRSlStudentServiceImpl implements BRSlStudentService {
//3.封装学生选课信息
brSlStudent= new BRSlStudent(value[1],value[0]);
if(currently.contains(brSlStudent.toString())){
innerRepeatResult += "课序号,学号分别为 " + value[0] + " " + value[1] + " 的数据,在Excel中重复出现,除第一条以外的数据插入失败 \n";
continue;
}
currently.add(brSlStudent.toString());
brSlStudent.setBusinessId(IdGen.uuid());
if(!brSlStudents.contains(brSlStudent)){
brSlStudents.add(brSlStudent);
}
}
......@@ -180,12 +186,11 @@ public class BRSlStudentServiceImpl implements BRSlStudentService {
}*/
result+=nullResult;
if(brSlStudents.size()<1){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR.getCode(),result);
}
return new PersistModel(1,result+nullResult.toString());
return new PersistModel(1,result+nullResult.toString() + innerRepeatResult);
}
static String sub(String str) {
......
......@@ -156,6 +156,8 @@ public class BSlServiceImpl implements BSlService {
ArrayList<String> lessonCode = new ArrayList<String>();
ArrayList<String> teacherCode = new ArrayList<String>();
ArrayList<String> termCode = new ArrayList<String>();
List<String> currentlyCode = new ArrayList<>();
String innerRepeatResult = "";
//ArrayList<String> direction = new ArrayList<String>();
//List<BSl> repeatSl = new ArrayList<>();
Map map = new HashMap();
......@@ -218,11 +220,18 @@ public class BSlServiceImpl implements BSlService {
bSl.setSlCoverUrl(bLesson.getDefaultUrl());
bSl.setCredits(bLesson.getCredits());
bSl.setClassHour(bLesson.getClassHour());
if(currentlyCode.contains(bSl.getCode())){
innerRepeatResult += "编号 " + bSl.getCode() + " 在Excel中重复出现,除第一条以外的数据插入失败 \n";
continue;
}
currentlyCode.add(bSl.getCode());
UserUtil.setCurrentPersistOperation(bSl);
BLessonDirection bDirection = new BLessonDirection();
if (!bSls.contains(bSl)) {
bSls.add(bSl);
bDirection.setDirectionId(bLesson.getDirectionId());
bDirection.setBusinessId(IdGen.uuid());
......@@ -269,7 +278,7 @@ public class BSlServiceImpl implements BSlService {
if(bSls.size()<1){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR.getCode(),result);
}
return new PersistModel(1,result);
return new PersistModel(1,result + innerRepeatResult);
}
@Override
......
......@@ -124,7 +124,8 @@ public class BStudentServiceImpl implements BStudentService {
@Override
public PersistModel importExcel(HSSFWorkbook hwb,String token) throws IOException {
ArrayList<BStudent> students = new ArrayList<BStudent>();
List<String> currentlyCode = new ArrayList<>();
String innerRepeatResult = "";
ArrayList<SysUser> users = new ArrayList<SysUser>();
ArrayList<UserRole> userRoles = new ArrayList<UserRole>();
List<String> valuesIncomplete = new ArrayList<>();
......@@ -235,7 +236,12 @@ public class BStudentServiceImpl implements BStudentService {
bStudent.setGradeCode(value[3]);
bStudent.setRemarks(value[4]);
UserUtil.setCurrentPersistOperation(bStudent);
if(currentlyCode.contains(bStudent.getCode())){
innerRepeatResult += "编号 " + value[0] + " 在Excel中重复出现,除第一条以外的数据插入失败 \n";
continue;
}
if (!students.contains(bStudent)) {
currentlyCode.add(bStudent.getCode());
students.add(bStudent);
users.add(user);
userRoles.add(userRole);
......@@ -281,7 +287,7 @@ public class BStudentServiceImpl implements BStudentService {
if (valuesOK.size()<1){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR.getCode(),result);
}
return new PersistModel(1, result);
return new PersistModel(1, result + innerRepeatResult);
......
......@@ -85,8 +85,8 @@ public class BTeacherServiceImpl implements BTeacherService {
public PersistModel importExcel(HSSFWorkbook hwb, String token) throws IOException, InterruptedException {
ArrayList<BTeacher> teachers = new ArrayList<BTeacher>();
ArrayList<SysUser> users = new ArrayList<SysUser>();
String innerRepeatResult = "";
List<String> currentlyCode = new ArrayList<>();
ArrayList<UserRole> userRoles = new ArrayList<UserRole>();
String[] headers = {"教师工号", "教师姓名", "性别","教学单位编号","备注"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,true,1); //获取excel数据
......@@ -192,7 +192,12 @@ public class BTeacherServiceImpl implements BTeacherService {
BTeacher bTeacher= new BTeacher(value[0],value[3]);
bTeacher.setRemarks(value[4]);
UserUtil.setCurrentPersistOperation(bTeacher);
if(currentlyCode.contains(bTeacher.getCode())){
innerRepeatResult += "编号 " + bTeacher.getCode() + " 在Excel中重复出现,除第一条以外的数据插入失败 ";
continue;
}
if (!teachers.contains(bTeacher)) {
currentlyCode.add(bTeacher.getCode());
teachers.add(bTeacher);
users.add(user);
userRoles.add(userRole);
......@@ -234,7 +239,7 @@ public class BTeacherServiceImpl implements BTeacherService {
}
return new PersistModel(1, result);
return new PersistModel(1, result + innerRepeatResult);
}
......
......@@ -106,6 +106,15 @@ public class ExcelUtil {
return values;
}
// public static boolean isRepeat(List<String[]> totalValue,String[] value){
// for(int i = 0 ; i < totalValue.size() ; i++){
// for(int j = 0 ; j < value.length ; j++){
// if(((String)value[j]).equals((String)totalValue.get(i)[j])){
// return true;
// }
// }
// }
// }
/**
* 重复数据检查
......
......@@ -11,8 +11,8 @@ server:
# org.springframework.web: DEBUG
druid:
#url: jdbc:mysql://192.168.1.125:13318/new_edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
url: jdbc:mysql://120.52.179.75:13318/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
#url: jdbc:mysql://120.52.179.75:13318/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
username: root
password: 123456
initial-size: 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment