|
@@ -1,5 +1,6 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.diagbot.dto.ConceptCollectionDTO;
|
|
@@ -15,17 +16,23 @@ import com.diagbot.enums.LexiconEnum;
|
|
|
import com.diagbot.enums.StatusEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.KlRelationOrderService;
|
|
|
+import com.diagbot.service.KlRelationService;
|
|
|
import com.diagbot.service.KlRuleConditionService;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
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.apache.commons.lang3.SystemUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -41,10 +48,17 @@ public class KlConceptCollectionFacade {
|
|
|
KlConceptFacade klConceptFacade;
|
|
|
@Autowired
|
|
|
KlLibraryInfoFacade klLibraryInfoFacade;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("klRelationServiceImpl")
|
|
|
+ KlRelationService klRelationService;
|
|
|
@Autowired
|
|
|
KlRelationFacade klRelationFacade;
|
|
|
@Autowired
|
|
|
+ @Qualifier("klRelationOrderServiceImpl")
|
|
|
+ KlRelationOrderService klRelationOrderService;
|
|
|
+ @Autowired
|
|
|
KlRelationOrderFacade klRelationOrderFacade;
|
|
|
+
|
|
|
@Autowired
|
|
|
KlDictionaryInfoFacade klDictionaryInfoFacade;
|
|
|
@Autowired
|
|
@@ -61,19 +75,24 @@ public class KlConceptCollectionFacade {
|
|
|
* @return
|
|
|
*/
|
|
|
public IPage<ConceptCollectionDTO> getConceptCollectionPage(ConceptCollectionPageVO conceptCollectionPageVO) {
|
|
|
+ if (conceptCollectionPageVO.getCollectionLibType() == null
|
|
|
+ || conceptCollectionPageVO.getCollectionLibType().equals(0)) {
|
|
|
+ conceptCollectionPageVO.setCollectionLibType(null);
|
|
|
+ }
|
|
|
+
|
|
|
return klRelationFacade.getConceptCollectionPage(conceptCollectionPageVO);
|
|
|
}
|
|
|
|
|
|
|
|
|
- //todo 保存
|
|
|
/**
|
|
|
* 保存(新增和修改)
|
|
|
* @param conceptCollectionSaveVO
|
|
|
* @return
|
|
|
*/
|
|
|
+ @DSTransactional
|
|
|
public Boolean saveOrUpdateRecord(ConceptCollectionSaveVO conceptCollectionSaveVO) {
|
|
|
Map<Long, List<DictionaryInfoDTO>> allDictionaryMap = klDictionaryInfoFacade.getListByGroupType();
|
|
|
- List<DictionaryInfoDTO> dictionary = allDictionaryMap.get(61);
|
|
|
+ List<DictionaryInfoDTO> dictionary = allDictionaryMap.get(61L);
|
|
|
Map<String, String> dictionaryMap
|
|
|
= dictionary.stream().collect(Collectors.toMap(DictionaryInfoDTO::getName, DictionaryInfoDTO::getVal));
|
|
|
if (null == conceptCollectionSaveVO.getCollectionId()) {
|
|
@@ -94,10 +113,10 @@ public class KlConceptCollectionFacade {
|
|
|
|
|
|
//校验术语集合和基础术语类型是否对应
|
|
|
String dicVal = dictionaryMap.get(LexiconEnum.getName(conceptCollectionSaveVO.getCollectionLibType()));
|
|
|
- if(StringUtils.isBlank(dicVal)){
|
|
|
+ if (StringUtils.isBlank(dicVal)) {
|
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "术语集合和基础术语关联字典未维护,请维护字典");
|
|
|
}
|
|
|
- Integer conceptLibType=Integer.valueOf(dicVal.split("-")[2]);
|
|
|
+ Integer conceptLibType = Integer.valueOf(dicVal.split("-")[2]);
|
|
|
for (ConceptCollectionBaseVO concept : conceptCollectionSaveVO.concepts) {
|
|
|
if (!concept.getConceptLibType().equals(conceptLibType)) {
|
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
@@ -106,11 +125,77 @@ public class KlConceptCollectionFacade {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //检验基础术语
|
|
|
+ //检验基础术语是否存在
|
|
|
+ //过滤已禁用基础术语
|
|
|
+ List<Long> conceptIds = conceptCollectionSaveVO.concepts.stream()
|
|
|
+ .map(ConceptCollectionBaseVO::getConceptId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<KlConcept> concepts = klConceptFacade.list(new QueryWrapper<KlConcept>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("status", StatusEnum.Enable.getKey())
|
|
|
+ .in("id", conceptIds));
|
|
|
+
|
|
|
+ if (ListUtil.isEmpty(concepts)) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "基础术语不存在或已禁用");
|
|
|
+ }
|
|
|
+ List<Long> saveConceptIds = concepts.stream().map(KlConcept::getId).collect(Collectors.toList());
|
|
|
|
|
|
- //todo 过滤已禁用基础术语
|
|
|
+ //删除已有记录
|
|
|
+ List<KlRelation> relationList = klRelationFacade.list(new QueryWrapper<KlRelation>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("start_id", collection.getId())
|
|
|
+ .eq("relation_id", 600));
|
|
|
|
|
|
- //todo 删除已有记录
|
|
|
+ if (ListUtil.isNotEmpty(relationList)) {
|
|
|
+ List<Long> tRelationIds = relationList.stream().map(KlRelation::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //删除管理记录
|
|
|
+ klRelationFacade.remove(new QueryWrapper<KlRelation>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("start_id", collection.getId())
|
|
|
+ .eq("relation_id", 600));
|
|
|
+ klRelationOrderFacade.remove(new QueryWrapper<KlRelationOrder>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("t_relation_id", tRelationIds));
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存
|
|
|
+ Date now = new Date();
|
|
|
+ String useId = UserUtils.getCurrentPrincipleID();
|
|
|
+ List<KlRelation> saveList = Lists.newLinkedList();
|
|
|
+ for (ConceptCollectionBaseVO concept : conceptCollectionSaveVO.concepts) {
|
|
|
+ if (!saveConceptIds.contains(concept.getConceptId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ KlRelation klRelation = new KlRelation();
|
|
|
+ klRelation.setStartId(collection.getId());
|
|
|
+ klRelation.setEndId(concept.getConceptId());
|
|
|
+ klRelation.setRelationId(600);
|
|
|
+
|
|
|
+ klRelation.setCreator(useId);
|
|
|
+ klRelation.setModifier(useId);
|
|
|
+ klRelation.setGmtCreate(now);
|
|
|
+ klRelation.setGmtModified(now);
|
|
|
+
|
|
|
+ saveList.add(klRelation);
|
|
|
+ }
|
|
|
+ klRelationService.saveOrUpdateBatch(saveList);
|
|
|
+
|
|
|
+ List<KlRelationOrder> saveOrderList = Lists.newLinkedList();
|
|
|
+ Integer orderNo = 1;
|
|
|
+ for (KlRelation klRelation : saveList) {
|
|
|
+ KlRelationOrder klRelationOrder = new KlRelationOrder();
|
|
|
+ klRelationOrder.settRelationId(klRelation.getId());
|
|
|
+ klRelationOrder.setOrderNo(orderNo++);
|
|
|
+
|
|
|
+ klRelationOrder.setCreator(useId);
|
|
|
+ klRelationOrder.setModifier(useId);
|
|
|
+ klRelationOrder.setGmtCreate(now);
|
|
|
+ klRelationOrder.setGmtModified(now);
|
|
|
+
|
|
|
+ saveOrderList.add(klRelationOrder);
|
|
|
+ }
|
|
|
+ klRelationOrderService.saveOrUpdateBatch(saveOrderList);
|
|
|
|
|
|
return true;
|
|
|
}
|