Jelajahi Sumber

云开试题导入

xiatian 1 tahun lalu
induk
melakukan
256c5725b5

+ 5 - 5
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/core/questions/api/controller/ImportPaperController.java

@@ -175,11 +175,11 @@ public class ImportPaperController extends ControllerSupport {
 		return new ResponseEntity<>(HttpStatus.OK);
 	}
 
-	@ApiOperation(value = "云开导入前清理课程属性、试题属性")
-	@PostMapping(value = "/importYunkaiProp/clear")
-	public void importYunkaiPropClear(Long rootOrgId, @RequestParam String batch) {
-		yunkaiService.propClear(rootOrgId, batch);
-	}
+//	@ApiOperation(value = "云开导入前清理课程属性、试题属性")
+//	@PostMapping(value = "/importYunkaiProp/clear")
+//	public void importYunkaiPropClear(Long rootOrgId, @RequestParam String batch) {
+//		yunkaiService.propClear(rootOrgId, batch);
+//	}
 
 	@ApiOperation(value = "云开导入课程属性、试题属性")
 	@PostMapping(value = "/importYunkaiProp")

+ 2 - 0
examcloud-core-questions-dao/src/main/java/cn/com/qmth/examcloud/core/questions/dao/CoursePropertyRepo.java

@@ -39,5 +39,7 @@ public interface CoursePropertyRepo extends MongoRepository<CourseProperty, Stri
 	List<CourseProperty> findByOrgId(Long orgId);
 
 	void deleteByOrgIdAndBatch(Long rootOrgId, String batch);
+	
+	CourseProperty findByOrgIdAndCourseIdAndBatch(Long rootOrgId,Long courseId, String batch);
 
 }

+ 60 - 28
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/yunkai/YunkaiService.java

@@ -5,7 +5,9 @@ import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 import org.apache.commons.collections4.CollectionUtils;
@@ -71,6 +73,19 @@ public class YunkaiService {
 
 	@Autowired
 	private PropertyRepo propertyRepo;
+	
+	private Map<String,String> allProperty(String coursePropertyId){
+		List<Property> list=propertyRepo.findByCoursePropertyIdOrderByNumber(coursePropertyId);
+		Map<String,String> map=new HashMap<>();
+		if(CollectionUtils.isNotEmpty(list)) {
+			for(Property p:list) {
+				if(StringUtils.isNotBlank(p.getFromId())) {
+					map.put(p.getFromId(), p.getId());
+				}
+			}
+		}
+		return map; 
+	}
 
 	private void savePropOneCourse(User user, File zfile, Long rootOrgId, String courseCode, String batch) {
 		GetCourseReq req = new GetCourseReq();
@@ -78,15 +93,22 @@ public class YunkaiService {
 		req.setCode(courseCode);
 		GetCourseResp res = courseCloudService.getCourse(req);
 
-		CourseProperty cp = new CourseProperty();
-		cp.setCourseCode(courseCode);
-		cp.setCourseId(res.getCourseBean().getId());
-		cp.setCourseName(res.getCourseBean().getName());
-		cp.setEnable(true);
-		cp.setOrgId(rootOrgId);
-		cp.setName(res.getCourseBean().getName() + "课程属性" + batch);
-		cp.setBatch(batch);
-		coursePropertyRepo.save(cp);
+		CourseProperty cp =coursePropertyRepo.findByOrgIdAndCourseIdAndBatch(rootOrgId, res.getCourseBean().getId(),batch);
+		Map<String,String> allProperty=new HashMap<>();
+		if(cp==null) {
+			cp= new CourseProperty();
+			cp.setCourseCode(courseCode);
+			cp.setCourseId(res.getCourseBean().getId());
+			cp.setCourseName(res.getCourseBean().getName());
+			cp.setEnable(true);
+			cp.setOrgId(rootOrgId);
+			cp.setName(res.getCourseBean().getName() + "课程属性" + batch);
+			cp.setBatch(batch);
+			coursePropertyRepo.save(cp);
+		}else {
+			allProperty=allProperty(cp.getId());
+		}
+		
 		String json;
 		try {
 			json = FileUtils.readFileToString(zfile, "utf-8");
@@ -98,34 +120,44 @@ public class YunkaiService {
 		for (PropertyDto pd : pds) {
 			num++;
 			Property p = new Property();
-			p.setCode(pd.getName());
-			p.setCoursePropertyId(cp.getId());
-			p.setName(pd.getName());
-			p.setNumber(num);
-			p.setOrgId(rootOrgId);
-			p.setParentId("0");
-			p.setFromId(pd.getId().toString());
-			propertyRepo.save(p);
+			if(!allProperty.keySet().contains(pd.getId().toString())) {
+				p.setCode(pd.getName());
+				p.setCoursePropertyId(cp.getId());
+				p.setName(pd.getName());
+				p.setNumber(num);
+				p.setOrgId(rootOrgId);
+				p.setParentId("0");
+				p.setFromId(pd.getId().toString());
+				p.setBatch(batch);
+				propertyRepo.save(p);
+			}else {
+				p.setId(allProperty.get(pd.getId().toString()));
+			}
 			if (CollectionUtils.isNotEmpty(pd.getSubPropertyDto())) {
 				int subnum = 0;
 				List<Property> ps = new ArrayList<>();
 				for (PropertyDto subpd : pd.getSubPropertyDto()) {
 					subnum++;
-					Property subp = new Property();
-					subp.setCode(subpd.getName());
-					subp.setCoursePropertyId(cp.getId());
-					subp.setName(subpd.getName());
-					subp.setNumber(subnum);
-					subp.setOrgId(rootOrgId);
-					subp.setParentId(p.getId());
-					subp.setFromId(subpd.getId().toString());
-					ps.add(subp);
+					if(!allProperty.keySet().contains(subpd.getId().toString())) {
+						Property subp = new Property();
+						subp.setCode(subpd.getName());
+						subp.setCoursePropertyId(cp.getId());
+						subp.setName(subpd.getName());
+						subp.setNumber(subnum);
+						subp.setOrgId(rootOrgId);
+						subp.setParentId(p.getId());
+						subp.setFromId(subpd.getId().toString());
+						subp.setBatch(batch);
+						ps.add(subp);
+					}
+				}
+				if(ps.size()>0) {
+					propertyRepo.saveAll(ps);
 				}
-				propertyRepo.saveAll(ps);
 			}
 		}
 	}
-
+	
 	@Transactional
 	public void saveProp(User user, MultipartFile dataFile, Long rootOrgId, List<String> courseCodes, String batch) {
 		String tempDir = systemProperties.getTempDataDir();