|
@@ -0,0 +1,230 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.dto.ConceptCollectionDTO;
|
|
|
+import com.diagbot.dto.DictionaryInfoDTO;
|
|
|
+import com.diagbot.entity.KlConcept;
|
|
|
+import com.diagbot.entity.KlLibraryInfo;
|
|
|
+import com.diagbot.entity.KlRelation;
|
|
|
+import com.diagbot.entity.KlRelationOrder;
|
|
|
+import com.diagbot.entity.KlRule;
|
|
|
+import com.diagbot.entity.KlRuleBase;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.enums.LexiconEnum;
|
|
|
+import com.diagbot.enums.StatusEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.KlRuleConditionService;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.vo.ConceptCollectionBaseVO;
|
|
|
+import com.diagbot.vo.ConceptCollectionPageVO;
|
|
|
+import com.diagbot.vo.ConceptCollectionSaveVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhaops
|
|
|
+ * @time: 2021/8/5 17:25
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class KlConceptCollectionFacade {
|
|
|
+ @Autowired
|
|
|
+ KlConceptFacade klConceptFacade;
|
|
|
+ @Autowired
|
|
|
+ KlLibraryInfoFacade klLibraryInfoFacade;
|
|
|
+ @Autowired
|
|
|
+ KlRelationFacade klRelationFacade;
|
|
|
+ @Autowired
|
|
|
+ KlRelationOrderFacade klRelationOrderFacade;
|
|
|
+ @Autowired
|
|
|
+ KlDictionaryInfoFacade klDictionaryInfoFacade;
|
|
|
+ @Autowired
|
|
|
+ KlRuleFacade klRuleFacade;
|
|
|
+ @Autowired
|
|
|
+ KlRuleBaseFacade klRuleBaseFacade;
|
|
|
+ @Autowired
|
|
|
+ KlRuleConditionService klRuleConditionService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取术语集合列表
|
|
|
+ *
|
|
|
+ * @param conceptCollectionPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<ConceptCollectionDTO> getConceptCollectionPage(ConceptCollectionPageVO conceptCollectionPageVO) {
|
|
|
+ return klRelationFacade.getConceptCollectionPage(conceptCollectionPageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //todo 保存
|
|
|
+ /**
|
|
|
+ * 保存(新增和修改)
|
|
|
+ * @param conceptCollectionSaveVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecord(ConceptCollectionSaveVO conceptCollectionSaveVO) {
|
|
|
+ Map<Long, List<DictionaryInfoDTO>> allDictionaryMap = klDictionaryInfoFacade.getListByGroupType();
|
|
|
+ List<DictionaryInfoDTO> dictionary = allDictionaryMap.get(61);
|
|
|
+ Map<String, String> dictionaryMap
|
|
|
+ = dictionary.stream().collect(Collectors.toMap(DictionaryInfoDTO::getName, DictionaryInfoDTO::getVal));
|
|
|
+ if (null == conceptCollectionSaveVO.getCollectionId()) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "术语集合不允许为空,保存失败");
|
|
|
+ }
|
|
|
+ if (ListUtil.isEmpty(conceptCollectionSaveVO.getConcepts())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "基础术语列表不允许为空,保存失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ KlConcept collection = klConceptFacade.getById(conceptCollectionSaveVO.getCollectionId());
|
|
|
+ if (null == collection) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "术语集合不存在,保存失败");
|
|
|
+ } else if (collection.getStatus().equals(StatusEnum.Disable.getKey())) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "集合已禁用,保存失败");
|
|
|
+ } else if (!collection.getLibName().equals(conceptCollectionSaveVO.getCollectionLibName())) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "术语集合名称不允许修改,保存失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验术语集合和基础术语类型是否对应
|
|
|
+ String dicVal = dictionaryMap.get(LexiconEnum.getName(conceptCollectionSaveVO.getCollectionLibType()));
|
|
|
+ if(StringUtils.isBlank(dicVal)){
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "术语集合和基础术语关联字典未维护,请维护字典");
|
|
|
+ }
|
|
|
+ Integer conceptLibType=Integer.valueOf(dicVal.split("-")[2]);
|
|
|
+ for (ConceptCollectionBaseVO concept : conceptCollectionSaveVO.concepts) {
|
|
|
+ if (!concept.getConceptLibType().equals(conceptLibType)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
+ "集合【" + LexiconEnum.getName(conceptCollectionSaveVO.getCollectionLibType())
|
|
|
+ + "】和基础术语【" + LexiconEnum.getName(conceptLibType) + "】不是对应关系,保存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //检验基础术语
|
|
|
+
|
|
|
+ //todo 过滤已禁用基础术语
|
|
|
+
|
|
|
+ //todo 删除已有记录
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据术语集合id获取集合相关信息
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ConceptCollectionSaveVO getRecordById(IdVO idVO) {
|
|
|
+ ConceptCollectionSaveVO retItem = new ConceptCollectionSaveVO();
|
|
|
+ KlConcept collection = klConceptFacade.getById(idVO.getId());
|
|
|
+ if (null == collection) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ retItem.setCollectionId(idVO.getId());
|
|
|
+ retItem.setCollectionLibName(collection.getLibName());
|
|
|
+ retItem.setCollectionLibType(collection.getLibType());
|
|
|
+ //remark
|
|
|
+ KlLibraryInfo libraryInfo = klLibraryInfoFacade.getOne(new QueryWrapper<KlLibraryInfo>()
|
|
|
+ .eq("concept_id", collection.getId())
|
|
|
+ .eq("is_concept", 1));
|
|
|
+ if (null != libraryInfo) {
|
|
|
+ retItem.setCollectionRemark(libraryInfo.getRemark());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<KlRelation> relationList = klRelationFacade.list(new QueryWrapper<KlRelation>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("start_id", idVO.getId())
|
|
|
+ .eq("relation_id", 600));
|
|
|
+
|
|
|
+ if (ListUtil.isEmpty(relationList)) {
|
|
|
+ return retItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, KlRelation> relationMap = relationList.stream().collect(Collectors.toMap(KlRelation::getId, v -> v));
|
|
|
+ List<Long> conceptIds = relationList.stream().map(KlRelation::getEndId).collect(Collectors.toList());
|
|
|
+ List<Long> relationIds = relationList.stream().map(KlRelation::getId).collect(Collectors.toList());
|
|
|
+ List<KlRelationOrder> relationOrderList = klRelationOrderFacade.list(new QueryWrapper<KlRelationOrder>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("t_relation_id", relationIds)
|
|
|
+ .orderByAsc("order_no"));
|
|
|
+
|
|
|
+ List<KlConcept> conceptList = klConceptFacade.list(new QueryWrapper<KlConcept>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("status", StatusEnum.Enable.getKey())
|
|
|
+ .in("id", conceptIds));
|
|
|
+ Map<Long, KlConcept> conceptMap = conceptList.stream().collect(Collectors.toMap(KlConcept::getId, v -> v));
|
|
|
+
|
|
|
+ List<ConceptCollectionBaseVO> subConceptList = Lists.newLinkedList();
|
|
|
+ if (ListUtil.isNotEmpty(relationOrderList)) {
|
|
|
+ for (KlRelationOrder order : relationOrderList) {
|
|
|
+ KlConcept concept = conceptMap.get(relationMap.get(order.gettRelationId()).getEndId());
|
|
|
+ if (null != concept) {
|
|
|
+ ConceptCollectionBaseVO conceptVO = new ConceptCollectionBaseVO();
|
|
|
+ conceptVO.setConceptId(concept.getId());
|
|
|
+ conceptVO.setConceptLibName(concept.getLibName());
|
|
|
+ conceptVO.setConceptLibType(concept.getLibType());
|
|
|
+ subConceptList.add(conceptVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (KlConcept concept : conceptList) {
|
|
|
+ ConceptCollectionBaseVO conceptVO = new ConceptCollectionBaseVO();
|
|
|
+ conceptVO.setConceptId(concept.getId());
|
|
|
+ conceptVO.setConceptLibName(concept.getLibName());
|
|
|
+ conceptVO.setConceptLibType(concept.getLibType());
|
|
|
+ subConceptList.add(conceptVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ retItem.setConcepts(subConceptList);
|
|
|
+
|
|
|
+ return retItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除术语集合关联关系
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteById(IdVO idVO) {
|
|
|
+ KlConcept collection = klConceptFacade.getById(idVO.getId());
|
|
|
+ if (null == collection) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "术语集合不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验术语集合是否被使用
|
|
|
+ List<KlRule> ruleList = klRuleFacade.list(new QueryWrapper<KlRule>()
|
|
|
+ .eq("concept_id", collection.getId()));
|
|
|
+ if (ListUtil.isNotEmpty(ruleList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.FAIL, "删除失败,【" + collection.getLibName() + "】已在规则中使用");
|
|
|
+ }
|
|
|
+ List<KlRuleBase> baseRuleList = klRuleBaseFacade.list(new QueryWrapper<KlRuleBase>()
|
|
|
+ .eq("concept_id", collection.getId()));
|
|
|
+ if (ListUtil.isNotEmpty(baseRuleList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.FAIL, "删除失败,【" + collection.getLibName() + "】已在规则中使用");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<KlRelation> relationList = klRelationFacade.list(new QueryWrapper<KlRelation>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("start_id", idVO.getId())
|
|
|
+ .eq("relation_id", 600));
|
|
|
+
|
|
|
+ if (ListUtil.isEmpty(relationList)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> relationIds = relationList.stream().map(KlRelation::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ klRelationFacade.remove(new QueryWrapper<KlRelation>().in("id", relationIds));
|
|
|
+ klRelationOrderFacade.remove(new QueryWrapper<KlRelationOrder>().in("t_relation_id", relationIds));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|