瀏覽代碼

导入修改为重复覆盖

宋悦 7 年之前
父節點
當前提交
5388cb7664

+ 11 - 17
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseService.java

@@ -61,27 +61,25 @@ public class CourseService {
             	}
                 ExcelError error = importCheck(course);
                 if (error == null) {
-					addCourse(list,course);
+					addCourse(course);
                 }
                 return error;
             }
         });
-        List<Course> courseList = courseRepo.save(list);
-		for(Course course:courseList){
-			dataSendService.sendCourse(course);
-		}
 		return excelErrors;
 	}
 
-	private void addCourse(List<Course> courses,Course course){
-		for(Course tempCourse:courses){
-			if(tempCourse.getCode().equals(course.getCode())){
-				tempCourse.setName(course.getName());
-				tempCourse.setUpdateTime(new Date());
-				return;
-			}
+	private void addCourse(Course course){
+		Course old = courseRepo.findByOrgIdAndCode(course.getOrgId(),course.getCode());
+		if(old == null){
+			Course tempCourse = courseRepo.save(course);
+			dataSendService.sendCourse(tempCourse);
+		}else{
+			old.setName(course.getName());
+			old.setUpdateTime(new Date());
+			Course tempCourse = courseRepo.save(old);
+			dataSendService.sendCourse(tempCourse);
 		}
-		courses.add(course);
 	}
 
 	private ExcelError importCheck(Course course) {
@@ -94,10 +92,6 @@ public class CourseService {
 		if(null == course.getLevel()){
 			return new ExcelError("层次不能为空");
 		}
-		Course domain = courseRepo.findByOrgIdAndCode(course.getOrgId(),course.getCode());
-		if(domain != null){
-			return new ExcelError("代码已存在");
-		}
 		return null;
 	}
 	

+ 11 - 17
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/SpecialtyService.java

@@ -51,27 +51,25 @@ public class SpecialtyService {
 				specialty.setEnable(true);
 				ExcelError error = importCheck(specialty);
 				if (error == null) {
-					addSpecialty(list,specialty);
+					addSpecialty(specialty);
 				}
 				return error;
 			}
 		});
-		specialtyRepo.save(list);
-		for (Specialty specialty : list) {
-			dataSendService.sendSpecialty(specialty);
-		}
 		return excelErrors;
 	}
 
-	private void addSpecialty(List<Specialty> specialties,Specialty specialty){
-		for(Specialty tempSpecialty:specialties){
-			if(tempSpecialty.getCode().equals(specialty.getCode())){
-				tempSpecialty.setName(specialty.getName());
-				tempSpecialty.setUpdateTime(new Date());
-				return;
-			}
+	private void addSpecialty(Specialty specialty){
+		Specialty old = specialtyRepo.findByOrgIdAndCode(specialty.getOrgId(),specialty.getCode());
+		if(old == null){
+			Specialty tempSpecialty = specialtyRepo.save(specialty);
+			dataSendService.sendSpecialty(tempSpecialty);
+		}else{
+			old.setName(specialty.getName());
+			old.setUpdateTime(new Date());
+			Specialty tempSpecialty = specialtyRepo.save(old);
+			dataSendService.sendSpecialty(tempSpecialty);
 		}
-		specialties.add(specialty);
 	}
 
 	private ExcelError importCheck(Specialty specialty) {
@@ -81,10 +79,6 @@ public class SpecialtyService {
 		if(StringUtils.isEmpty(specialty.getName())){
 			return new ExcelError("名称不能为空");
 		}
-		Specialty domain = specialtyRepo.findByOrgIdAndCode(specialty.getOrgId(),specialty.getCode());
-		if(domain != null){
-			return new ExcelError("代码已存在");
-		}
 		return null;
 	}