|
@@ -6,13 +6,16 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.diagbot.dto.GetQuestionInfoDTO;
|
|
|
import com.diagbot.dto.QuestionIndexDTO;
|
|
|
import com.diagbot.dto.QuestionPageDTO;
|
|
|
+import com.diagbot.entity.CommonParam;
|
|
|
import com.diagbot.entity.QuestionDetail;
|
|
|
import com.diagbot.entity.QuestionInfo;
|
|
|
+import com.diagbot.entity.QuestionMapping;
|
|
|
import com.diagbot.entity.wrapper.QuestionWrapper;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.QuestionDetailService;
|
|
|
+import com.diagbot.service.QuestionMappingService;
|
|
|
import com.diagbot.service.impl.QuestionInfoServiceImpl;
|
|
|
import com.diagbot.util.BeanUtil;
|
|
|
import com.diagbot.util.DateUtil;
|
|
@@ -48,6 +51,9 @@ public class QuestionInfoFacade extends QuestionInfoServiceImpl {
|
|
|
@Qualifier("questionDetailServiceImpl")
|
|
|
QuestionDetailService questionDetailService;
|
|
|
@Autowired
|
|
|
+ @Qualifier("questionMappingServiceImpl")
|
|
|
+ QuestionMappingService questionMappingService;
|
|
|
+ @Autowired
|
|
|
QuestionMappingFacade questionMappingFacade;
|
|
|
@Autowired
|
|
|
ModuleDetailFacade moduleDetailFacade;
|
|
@@ -59,48 +65,110 @@ public class QuestionInfoFacade extends QuestionInfoServiceImpl {
|
|
|
* @param questionSaveVO
|
|
|
*/
|
|
|
public void saveOrUpdate(QuestionSaveVO questionSaveVO) {
|
|
|
-
|
|
|
-// String person = UserUtils.getCurrentPrincipleID(); //TODO person
|
|
|
- String person = "default";
|
|
|
QuestionWrapper questionWrapper = questionSaveVO.getQuestionWrapper();
|
|
|
- //1、主表信息
|
|
|
+ CommonParam param = initCommonParam();
|
|
|
+ saveQuestionInfo(questionWrapper, param);
|
|
|
+ switch (questionWrapper.getTagType()) {
|
|
|
+ case "1": //单项,例如:程度、体温
|
|
|
+ saveQuestionDetail(questionWrapper, param);
|
|
|
+ break;
|
|
|
+ case "2": //组合项,例如:杂音,修改主表和mapping
|
|
|
+ saveQuestionMapping(questionWrapper, param);
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ break;
|
|
|
+ case "5":
|
|
|
+ break;
|
|
|
+ case "6":
|
|
|
+ break;
|
|
|
+ case "7":
|
|
|
+ break;
|
|
|
+ case "8":
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "请选择标签显示类型");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化参数
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public CommonParam initCommonParam() {
|
|
|
+ CommonParam param = new CommonParam();
|
|
|
+ //String person = UserUtils.getCurrentPrincipleID(); //TODO person
|
|
|
+ String person = "1";
|
|
|
+ param.setNow(DateUtil.now());
|
|
|
+ param.setPerson(person);
|
|
|
+ param.setSaveOrUpdate("save");
|
|
|
QuestionInfo questionInfo = new QuestionInfo();
|
|
|
- String saveOrUpdate = "save"; //新增或修改的标识
|
|
|
- if(questionWrapper.getId() != null) {
|
|
|
- questionInfo = this.getOne(new QueryWrapper<QuestionInfo>()
|
|
|
- .eq("id", questionWrapper.getId())
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
- if(questionInfo == null) {
|
|
|
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标签不存在");
|
|
|
+ param.setQuestionInfo(questionInfo);
|
|
|
+ return param;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存映射关系
|
|
|
+ *
|
|
|
+ * @param questionWrapper
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void saveQuestionMapping(QuestionWrapper questionWrapper, CommonParam param) {
|
|
|
+ QuestionInfo questionInfo = param.getQuestionInfo();
|
|
|
+ Date now = param.getNow();
|
|
|
+ String person = param.getPerson();
|
|
|
+ //先删除原明细,再插入新明细
|
|
|
+ questionMappingFacade.update(new QuestionMapping(), //删除原映射关系
|
|
|
+ new UpdateWrapper<QuestionMapping>()
|
|
|
+ .eq("parent_question", questionInfo.getId())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .set("gmt_modified", now)
|
|
|
+ .set("modifier", person)
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey()));
|
|
|
+ List<QuestionMapping> questionMappings = questionWrapper.getQuestionMappings();
|
|
|
+ if(ListUtil.isNotEmpty(questionMappings)) {
|
|
|
+ List<QuestionMapping> saveMapping = new ArrayList<>();
|
|
|
+ int i = 1;
|
|
|
+ for(QuestionMapping mapping : questionMappings) {
|
|
|
+ QuestionMapping bean = new QuestionMapping();
|
|
|
+ BeanUtil.copyProperties(mapping, bean);
|
|
|
+ bean.setId(null); //防止前端传参,将前端的id置空自动插入
|
|
|
+ bean.setCreator(person);
|
|
|
+ bean.setGmtCreate(now);
|
|
|
+ bean.setModifier(person);
|
|
|
+ bean.setGmtModified(now);
|
|
|
+ bean.setOrderNo(i++);
|
|
|
+ saveMapping.add(bean);
|
|
|
}
|
|
|
- saveOrUpdate = "update";
|
|
|
+ questionMappingService.saveBatch(saveMapping);
|
|
|
}
|
|
|
- BeanUtil.copyProperties(questionWrapper, questionInfo);
|
|
|
- List<QuestionInfo> questionInfoList = this.list(new QueryWrapper<QuestionInfo>()
|
|
|
- .eq("tag_name", questionInfo.getTagName())
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("type", questionInfo.getType())
|
|
|
- .ne("id", questionInfo.getId() == null ? 0 : questionInfo.getId()));
|
|
|
- if(questionInfoList.size() > 0) { //标签type、tagName唯一
|
|
|
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标签名已存在");
|
|
|
- }
|
|
|
- Date now = DateUtil.now();
|
|
|
- if("save".equals(saveOrUpdate)) {
|
|
|
- questionInfo.setCreator(person); //创建人
|
|
|
- questionInfo.setGmtCreate(now);//创建时间
|
|
|
- }
|
|
|
- questionInfo.setGmtModified(now);//修改时间
|
|
|
- questionInfo.setModifier(person);//修改人
|
|
|
- this.saveOrUpdate(questionInfo);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- //2、明细信息(先删除原明细,再插入新明细)
|
|
|
+ /**
|
|
|
+ * 保存明细
|
|
|
+ *
|
|
|
+ * @param questionWrapper
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void saveQuestionDetail(QuestionWrapper questionWrapper, CommonParam param) {
|
|
|
+ QuestionInfo questionInfo = param.getQuestionInfo();
|
|
|
+ Date now = param.getNow();
|
|
|
+ String person = param.getPerson();
|
|
|
+ //先删除原明细,再插入新明细
|
|
|
questionDetailFacade.update(new QuestionDetail(), //删除原明细
|
|
|
new UpdateWrapper<QuestionDetail>()
|
|
|
- .eq("question_id", questionInfo.getId())
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .set("gmt_modified", now)
|
|
|
- .set("modifier", person)
|
|
|
- .set("is_deleted", IsDeleteEnum.Y.getKey()));
|
|
|
+ .eq("question_id", questionInfo.getId())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .set("gmt_modified", now)
|
|
|
+ .set("modifier", person)
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey()));
|
|
|
List<QuestionDetail> questionDetails = questionWrapper.getQuestionDetails();
|
|
|
if(ListUtil.isNotEmpty(questionDetails)) {
|
|
|
List<QuestionDetail> saveDetail = new ArrayList<>();
|
|
@@ -119,13 +187,44 @@ public class QuestionInfoFacade extends QuestionInfoServiceImpl {
|
|
|
}
|
|
|
questionDetailService.saveBatch(saveDetail);
|
|
|
}
|
|
|
-
|
|
|
- //3、映射信息
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存主表
|
|
|
+ *
|
|
|
+ * @param questionWrapper
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void saveQuestionInfo(QuestionWrapper questionWrapper, CommonParam param) {
|
|
|
+ QuestionInfo questionInfo = param.getQuestionInfo();
|
|
|
+ if(questionWrapper.getId() != null) {
|
|
|
+ questionInfo = this.getOne(new QueryWrapper<QuestionInfo>()
|
|
|
+ .eq("id", questionWrapper.getId())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
+ if(questionInfo == null) { //校验
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标签不存在");
|
|
|
+ }
|
|
|
+ param.setSaveOrUpdate("update");
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(questionWrapper, questionInfo);
|
|
|
+ List<QuestionInfo> questionInfoList = this.list(new QueryWrapper<QuestionInfo>()
|
|
|
+ .eq("tag_name", questionInfo.getTagName())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("type", questionInfo.getType())
|
|
|
+ .ne("id", questionInfo.getId() == null ? -1 : questionInfo.getId()));
|
|
|
+ if(questionInfoList.size() > 0) { //标签type、tagName唯一
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标签名已存在");
|
|
|
+ }
|
|
|
+ if("save".equals(param.getSaveOrUpdate())) {
|
|
|
+ questionInfo.setCreator(param.getPerson()); //创建人
|
|
|
+ questionInfo.setGmtCreate(param.getNow());//创建时间
|
|
|
+ }
|
|
|
+ questionInfo.setGmtModified(param.getNow());//修改时间
|
|
|
+ questionInfo.setModifier(param.getPerson());//修改人
|
|
|
+ this.saveOrUpdate(questionInfo);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 标签列表
|
|
|
*
|
|
@@ -140,7 +239,6 @@ public class QuestionInfoFacade extends QuestionInfoServiceImpl {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 根据id删除标签
|
|
|
*
|