|
@@ -1,5 +1,6 @@
|
|
package edu.math.diagnosis.service;
|
|
package edu.math.diagnosis.service;
|
|
|
|
|
|
|
|
+import edu.math.diagnosis.config.Constants;
|
|
import edu.math.diagnosis.dao.BaseMatterRepo;
|
|
import edu.math.diagnosis.dao.BaseMatterRepo;
|
|
import edu.math.diagnosis.dao.CommonMatterRepo;
|
|
import edu.math.diagnosis.dao.CommonMatterRepo;
|
|
import edu.math.diagnosis.dao.KnowledgeMatterRepo;
|
|
import edu.math.diagnosis.dao.KnowledgeMatterRepo;
|
|
@@ -8,9 +9,15 @@ import edu.math.diagnosis.entity.BaseMatter;
|
|
import edu.math.diagnosis.entity.CommonMatter;
|
|
import edu.math.diagnosis.entity.CommonMatter;
|
|
import edu.math.diagnosis.entity.KnowledgeMatter;
|
|
import edu.math.diagnosis.entity.KnowledgeMatter;
|
|
import edu.math.diagnosis.entity.MistakeMatter;
|
|
import edu.math.diagnosis.entity.MistakeMatter;
|
|
|
|
+import edu.math.diagnosis.model.MatterVo;
|
|
|
|
+import edu.math.diagnosis.util.CodeUtil;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -26,13 +33,23 @@ public class MatterService {
|
|
private KnowledgeMatterRepo knowledgeMatterRepo;
|
|
private KnowledgeMatterRepo knowledgeMatterRepo;
|
|
|
|
|
|
public BaseMatter addBase(String name, String code) {
|
|
public BaseMatter addBase(String name, String code) {
|
|
|
|
+ if (existBase(name)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
BaseMatter matter = new BaseMatter();
|
|
BaseMatter matter = new BaseMatter();
|
|
matter.setName(name);
|
|
matter.setName(name);
|
|
matter.setCode(code);
|
|
matter.setCode(code);
|
|
return baseMatterRepo.save(matter);
|
|
return baseMatterRepo.save(matter);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public boolean existBase(String name) {
|
|
|
|
+ return baseMatterRepo.existsByName(name);
|
|
|
|
+ }
|
|
|
|
+
|
|
public MistakeMatter addMistake(String name, String code, String baseMatter) {
|
|
public MistakeMatter addMistake(String name, String code, String baseMatter) {
|
|
|
|
+ if (existMistake(name)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
MistakeMatter matter = new MistakeMatter();
|
|
MistakeMatter matter = new MistakeMatter();
|
|
matter.setName(name);
|
|
matter.setName(name);
|
|
matter.setCode(code);
|
|
matter.setCode(code);
|
|
@@ -40,7 +57,14 @@ public class MatterService {
|
|
return mistakeMatterRepo.save(matter);
|
|
return mistakeMatterRepo.save(matter);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public boolean existMistake(String name) {
|
|
|
|
+ return mistakeMatterRepo.existsByName(name);
|
|
|
|
+ }
|
|
|
|
+
|
|
public CommonMatter addCommon(String name, String code, String mistakeMatter, String baseMatter) {
|
|
public CommonMatter addCommon(String name, String code, String mistakeMatter, String baseMatter) {
|
|
|
|
+ if (existCommon(name)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
CommonMatter matter = new CommonMatter();
|
|
CommonMatter matter = new CommonMatter();
|
|
matter.setName(name);
|
|
matter.setName(name);
|
|
matter.setCode(code);
|
|
matter.setCode(code);
|
|
@@ -49,7 +73,14 @@ public class MatterService {
|
|
return commonMatterRepo.save(matter);
|
|
return commonMatterRepo.save(matter);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public boolean existCommon(String name) {
|
|
|
|
+ return commonMatterRepo.existsByName(name);
|
|
|
|
+ }
|
|
|
|
+
|
|
public KnowledgeMatter addKnowledge(String name, String code, String commonMatter, String mistakeMatter, String baseMatter, Long subjectId, String grade) {
|
|
public KnowledgeMatter addKnowledge(String name, String code, String commonMatter, String mistakeMatter, String baseMatter, Long subjectId, String grade) {
|
|
|
|
+ if (existKnowledge(name, subjectId, grade)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
KnowledgeMatter matter = new KnowledgeMatter();
|
|
KnowledgeMatter matter = new KnowledgeMatter();
|
|
matter.setName(name);
|
|
matter.setName(name);
|
|
matter.setCode(code);
|
|
matter.setCode(code);
|
|
@@ -61,9 +92,35 @@ public class MatterService {
|
|
return knowledgeMatterRepo.save(matter);
|
|
return knowledgeMatterRepo.save(matter);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public boolean existKnowledge(String name, Long subjectId, String grade) {
|
|
|
|
+ return knowledgeMatterRepo.existsByNameAndSubjectIdAndGrade(name, subjectId, grade);
|
|
|
|
+ }
|
|
|
|
+
|
|
public List<KnowledgeMatter> list(Long subjectId, String grade) {
|
|
public List<KnowledgeMatter> list(Long subjectId, String grade) {
|
|
return knowledgeMatterRepo.findAllBySubjectIdAndGrade(subjectId, grade);
|
|
return knowledgeMatterRepo.findAllBySubjectIdAndGrade(subjectId, grade);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void addAll(List<MatterVo> list) {
|
|
|
|
+ for (MatterVo vo : list) {
|
|
|
|
+ String base = convertBaseMatter(vo.getEmotionMatter(), vo.getStudyMatter());
|
|
|
|
+ String mistake = vo.getMistakeMatter();
|
|
|
|
+ String common = vo.getCommonMatter();
|
|
|
|
+ String knowledge = vo.getKnowledgeMatter();
|
|
|
|
+ addMistake(mistake, CodeUtil.generate(4, CodeUtil.ALPHA), base);
|
|
|
|
+ addCommon(common, CodeUtil.generate(4, CodeUtil.ALPHA), mistake, base);
|
|
|
|
+ addKnowledge(knowledge, CodeUtil.generate(4, CodeUtil.ALPHA), common, mistake, base, vo.getSubjectId(), vo.getGrade());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ public String convertBaseMatter(Boolean emotion, Boolean study) {
|
|
|
|
+ List<String> matters = new ArrayList<>();
|
|
|
|
+ if (study != null && study) {
|
|
|
|
+ matters.add(Constants.MATTER_EMOTION);
|
|
|
|
+ }
|
|
|
|
+ if (emotion != null && emotion) {
|
|
|
|
+ matters.add(Constants.MATTER_STUDY);
|
|
|
|
+ }
|
|
|
|
+ return StringUtils.join(matters, ",");
|
|
|
|
+ }
|
|
}
|
|
}
|