|
@@ -1,12 +1,215 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.client.ICSSManServiceClient;
|
|
|
+import com.diagbot.client.UserServiceClient;
|
|
|
+import com.diagbot.dto.LisMappingPageDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.entity.Concept;
|
|
|
+import com.diagbot.entity.LisMapping;
|
|
|
+import com.diagbot.entity.QuestionInfo;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.impl.LisMappingServiceImpl;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.RespDTOUtil;
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.GetUniqueNameVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
+import com.diagbot.vo.LisMappingPageVO;
|
|
|
+import com.diagbot.vo.LisMappingVO;
|
|
|
+import com.diagbot.vo.QuestionIndexVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* @Description:
|
|
|
* @Author:zhaops
|
|
|
* @time: 2019/9/19 11:42
|
|
|
*/
|
|
|
@Component
|
|
|
-public class LisMappingFacade {
|
|
|
+public class LisMappingFacade extends LisMappingServiceImpl {
|
|
|
+ @Autowired
|
|
|
+ private ConceptFacade conceptFacade;
|
|
|
+ @Autowired
|
|
|
+ private UserServiceClient userServiceClient;
|
|
|
+ @Autowired
|
|
|
+ private ICSSManServiceClient icssManServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 化验公表映射分页信息
|
|
|
+ *
|
|
|
+ * @param lisMappingPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<LisMappingPageDTO> getLisMappingPage(LisMappingPageVO lisMappingPageVO) {
|
|
|
+ IPage<LisMappingPageDTO> dtoPage = this.lisMappingPage(lisMappingPageVO);
|
|
|
+ List<LisMappingPageDTO> records = dtoPage.getRecords();
|
|
|
+ List<String> userIds = records.stream().map(record -> record.getModifier()).collect(Collectors.toList());
|
|
|
+ RespDTO<Map<String, String>> data = userServiceClient.getUserInfoByIds(userIds);
|
|
|
+ Map<String, String> userInfos = data.data;
|
|
|
+ for (LisMappingPageDTO record : records) {
|
|
|
+ record.setGmtOperate(record.getGmtModified());
|
|
|
+ record.setOperator(record.getModifier());
|
|
|
+ record.setOperatorName(userInfos.get(record.getModifier()));
|
|
|
+ }
|
|
|
+ dtoPage.setRecords(records);
|
|
|
+ return dtoPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存化验公表映射关系
|
|
|
+ *
|
|
|
+ * @param lisMappingVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveLisMapping(LisMappingVO lisMappingVO) {
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ LisMapping lisMapping = new LisMapping();
|
|
|
+ lisMapping.setCreator(userId);
|
|
|
+ lisMapping.setGmtCreate(now);
|
|
|
+
|
|
|
+ //验证医学术语是否存在
|
|
|
+ Concept mealConcept = conceptFacade.getById(lisMappingVO.getMealId());
|
|
|
+ if (mealConcept == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "化验套餐项术语不存在");
|
|
|
+ }
|
|
|
+ if (lisMappingVO.getItemId() != null && !lisMappingVO.getItemId().equals(0L)) {
|
|
|
+ Concept itemConcept = conceptFacade.getById(lisMappingVO.getItemId());
|
|
|
+ if (itemConcept == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "化验明细项术语不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Concept uniqueConcept = conceptFacade.getById(lisMappingVO.getUniqueId());
|
|
|
+ if (uniqueConcept == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "化验公表项项术语不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<LisMapping> lisMappingQueryWrapper = new QueryWrapper<>();
|
|
|
+ lisMappingQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("meal_id", lisMappingVO.getMealId());
|
|
|
+ if (lisMappingVO.getItemId() == null || lisMappingVO.getItemId().equals(0L)) {
|
|
|
+ lisMappingQueryWrapper.and(i -> i.isNull("item_id").or(j -> j.eq("item_id", "0")));
|
|
|
+ } else {
|
|
|
+ lisMappingQueryWrapper.eq("item_id", lisMappingVO.getItemId());
|
|
|
+ }
|
|
|
+ List<LisMapping> lisMappingList = this.list(lisMappingQueryWrapper);
|
|
|
+ if (lisMappingList.size() > 1) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "存在多条映射关系,请删除重复映射");
|
|
|
+ } else if (lisMappingList.size() == 1) {
|
|
|
+ lisMapping = lisMappingList.get(0);
|
|
|
+ }
|
|
|
+ lisMapping.setMealId(lisMappingVO.getMealId());
|
|
|
+ if (lisMappingVO.getItemId() == null || lisMappingVO.getItemId().equals(0L)) {
|
|
|
+ lisMapping.setItemId(0L);
|
|
|
+ } else {
|
|
|
+ lisMapping.setItemId(lisMappingVO.getItemId());
|
|
|
+ }
|
|
|
+ lisMapping.setUniqueId(lisMappingVO.getUniqueId());
|
|
|
+ lisMapping.setModifier(userId);
|
|
|
+ lisMapping.setGmtModified(now);
|
|
|
+ lisMapping.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ Boolean state = this.saveOrUpdate(lisMapping);
|
|
|
+
|
|
|
+ //清除缓存
|
|
|
+ QuestionIndexVO questionIndexVO = new QuestionIndexVO();
|
|
|
+ questionIndexVO.setName(mealConcept.getLibName());
|
|
|
+ questionIndexVO.setType(5);
|
|
|
+ List<Integer> tagTypes = Lists.newArrayList();
|
|
|
+ tagTypes.add(7);
|
|
|
+ questionIndexVO.setTagType(tagTypes);
|
|
|
+ RespDTO<List<QuestionInfo>> respDTO = icssManServiceClient.index(questionIndexVO);
|
|
|
+ if (RespDTOUtil.respIsOK(respDTO)) {
|
|
|
+ List<QuestionInfo> questionInfoList = respDTO.data;
|
|
|
+ IdVO idVO = new IdVO();
|
|
|
+ idVO.setId(questionInfoList.get(0).getId());
|
|
|
+ RespDTO<Boolean> cacheRespDTO = icssManServiceClient.clearCache(idVO);
|
|
|
+ }
|
|
|
+ return state;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断映射关系是否已存在
|
|
|
+ *
|
|
|
+ * @param lisMappingVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean hasLisMapping(LisMappingVO lisMappingVO) {
|
|
|
+ QueryWrapper<LisMapping> lisMappingQueryWrapper = new QueryWrapper<>();
|
|
|
+ lisMappingQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("meal_id", lisMappingVO.getMealId());
|
|
|
+ if (lisMappingVO.getItemId() == null || lisMappingVO.getItemId().equals(0L)) {
|
|
|
+ lisMappingQueryWrapper.and(i -> i.isNull("item_id").or(j -> j.eq("item_id", "0")));
|
|
|
+ } else {
|
|
|
+ lisMappingQueryWrapper.eq("item_id", lisMappingVO.getItemId());
|
|
|
+ }
|
|
|
+ List<LisMapping> lisMappingList = this.list(lisMappingQueryWrapper);
|
|
|
+ if (ListUtil.isNotEmpty(lisMappingList)) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除单条化验公表映射关系
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean delLisMappingById(IdVO idVO) {
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ LisMapping lisMapping = this.getById(idVO.getId());
|
|
|
+ if (lisMapping == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "映射关系不存在,不允许删除");
|
|
|
+ }
|
|
|
+ lisMapping.setIsDeleted(IsDeleteEnum.Y.getKey());
|
|
|
+ lisMapping.setModifier(userId);
|
|
|
+ lisMapping.setGmtModified(now);
|
|
|
+ Boolean state = this.updateById(lisMapping);
|
|
|
+ return state;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取化验公表名称
|
|
|
+ *
|
|
|
+ * @param getUniqueNameVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getLisUniqueName(GetUniqueNameVO getUniqueNameVO) {
|
|
|
+ String uniqueName = "";
|
|
|
+ Concept mealConcept = conceptFacade.getById(getUniqueNameVO.getMealName());
|
|
|
+ Concept itemConcept = null;
|
|
|
+ if (getUniqueNameVO.getItemName() != null && !getUniqueNameVO.getItemName().equals(0L)) {
|
|
|
+ itemConcept = conceptFacade.getById(getUniqueNameVO.getItemName());
|
|
|
+ }
|
|
|
+ QueryWrapper<LisMapping> lisMappingQueryWrapper = new QueryWrapper<>();
|
|
|
+ lisMappingQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("meal_id", mealConcept.getId());
|
|
|
+ if (itemConcept == null) {
|
|
|
+ lisMappingQueryWrapper.and(i -> i.isNull("item_id").or(j -> j.eq("item_id", 0)));
|
|
|
+ } else {
|
|
|
+ lisMappingQueryWrapper.eq("item_id", itemConcept.getId());
|
|
|
+ }
|
|
|
+ List<LisMapping> lisMappingList = this.list(lisMappingQueryWrapper);
|
|
|
+ if (ListUtil.isNotEmpty(lisMappingList)) {
|
|
|
+ Concept uniqueConcept = conceptFacade.getById(lisMappingList.get(0).getId());
|
|
|
+ if (uniqueConcept != null) {
|
|
|
+ uniqueName = uniqueConcept.getLibName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return uniqueName;
|
|
|
+ }
|
|
|
}
|