|
@@ -0,0 +1,172 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.client.UserServiceClient;
|
|
|
+import com.diagbot.dto.GetDisScaleAllInfoDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.entity.DisScale;
|
|
|
+import com.diagbot.entity.QuestionInfo;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.DisScaleService;
|
|
|
+import com.diagbot.service.impl.DisScaleServiceImpl;
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.RespDTOUtil;
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.AddDisScaleInfoVO;
|
|
|
+import com.diagbot.vo.DelDisScaleInfoVO;
|
|
|
+import com.diagbot.vo.GetDisScaleAllInfoVO;
|
|
|
+import com.diagbot.vo.GetDisScaleByDisIdVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @author: wangyu
|
|
|
+ * @time: 2019/4/1 13:29
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class DisScaleFacade extends DisScaleServiceImpl {
|
|
|
+ @Autowired
|
|
|
+ private QuestionFacade questionFacade;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("disScaleServiceImpl")
|
|
|
+ private DisScaleService disScaleService;
|
|
|
+ @Autowired
|
|
|
+ private UserServiceClient userServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加诊断量表关联信息
|
|
|
+ *
|
|
|
+ * @param addDisScaleInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean addDisScaleInfo(AddDisScaleInfoVO addDisScaleInfoVO) {
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ //判断诊断是否已被删除
|
|
|
+ QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", addDisScaleInfoVO.getDisId());
|
|
|
+ if (questionFacade.count(questionInfoQueryWrapper) == 0) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS,
|
|
|
+ "关联诊断标签已删除");
|
|
|
+ }
|
|
|
+ //判断该诊断是否关联过量表
|
|
|
+ QueryWrapper<DisScale> disScaleQueryWrapper = new QueryWrapper<>();
|
|
|
+ disScaleQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("dis_id", addDisScaleInfoVO.getDisId());
|
|
|
+ //如果添加过将原来的标签删除
|
|
|
+ if (this.count(disScaleQueryWrapper) != 0) {
|
|
|
+ UpdateWrapper<DisScale> updateWrapper = new UpdateWrapper();
|
|
|
+ updateWrapper.eq("dis_id", addDisScaleInfoVO.getDisId())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
+ .set("modifier", userId)
|
|
|
+ .set("gmt_modified", DateUtil.now());
|
|
|
+ this.update(new DisScale(), updateWrapper);
|
|
|
+ }
|
|
|
+ //重新添加标签
|
|
|
+ DisScale disScale = new DisScale();
|
|
|
+ List<DisScale> addList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < addDisScaleInfoVO.getScaleId().size(); i++) {
|
|
|
+ disScale = new DisScale();
|
|
|
+ disScale.setCreator(userId);
|
|
|
+ disScale.setModifier(userId);
|
|
|
+ disScale.setGmtCreate(DateUtil.now());
|
|
|
+ disScale.setGmtModified(DateUtil.now());
|
|
|
+ disScale.setScaleId(addDisScaleInfoVO.getScaleId().get(i));
|
|
|
+ disScale.setDisId(addDisScaleInfoVO.getDisId());
|
|
|
+ disScale.setOrderNo(i + 1);
|
|
|
+ addList.add(disScale);
|
|
|
+ }
|
|
|
+ disScaleService.saveBatch(addList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页获取诊断关联量表信息
|
|
|
+ *
|
|
|
+ * @param getDisScaleAllInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<GetDisScaleAllInfoDTO> getDisScaleAllInfo(GetDisScaleAllInfoVO getDisScaleAllInfoVO) {
|
|
|
+ IPage<GetDisScaleAllInfoDTO> data = this.getDisScaleInfo(getDisScaleAllInfoVO);
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
+ for (GetDisScaleAllInfoDTO getDisScaleAllInfoDTO : data.getRecords()) {
|
|
|
+ userIds.add(getDisScaleAllInfoDTO.getModifier());
|
|
|
+ }
|
|
|
+ RespDTO<Map<String, String>> userMap = userServiceClient.getUserInfoByIds(userIds);
|
|
|
+ if (RespDTOUtil.respIsNG(userMap)) {
|
|
|
+ throw new CommonException(CommonErrorCode.RPC_ERROR,
|
|
|
+ "获取用户信息失败");
|
|
|
+ }
|
|
|
+ for (GetDisScaleAllInfoDTO getDisScaleAllInfoDTO : data.getRecords()) {
|
|
|
+ getDisScaleAllInfoDTO.setUserName(userMap.data.get(getDisScaleAllInfoDTO.getModifier()));
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改时获取已经添加过得诊断量表关联信息
|
|
|
+ *
|
|
|
+ * @param getDisScaleByDisIdVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<GetDisScaleAllInfoDTO> getDisScaleByDisId(GetDisScaleByDisIdVO getDisScaleByDisIdVO) {
|
|
|
+ //查询诊断量表关联信息
|
|
|
+ QueryWrapper<DisScale> disScaleQueryWrapper = new QueryWrapper<>();
|
|
|
+ disScaleQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("dis_id", getDisScaleByDisIdVO.getDisId());
|
|
|
+ List<DisScale> disScales = this.list(disScaleQueryWrapper);
|
|
|
+ List<Long> questionIds = new ArrayList<>();
|
|
|
+ List<GetDisScaleAllInfoDTO> getDisScaleAllInfoDTOS = BeanUtil.listCopyTo(disScales, GetDisScaleAllInfoDTO.class);
|
|
|
+ for (DisScale disScale : disScales) {
|
|
|
+ questionIds.add(disScale.getDisId());
|
|
|
+ questionIds.add(disScale.getScaleId());
|
|
|
+ }
|
|
|
+ //查询相关标签名称
|
|
|
+ QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("id", questionIds);
|
|
|
+ List<QuestionInfo> questionInfoList = questionFacade.list(questionInfoQueryWrapper);
|
|
|
+ Map<Long, QuestionInfo> questionInfoMap
|
|
|
+ = questionInfoList.stream().collect(Collectors.toMap(QuestionInfo::getId, questionInfo -> questionInfo));
|
|
|
+ //将标签名称放入出参
|
|
|
+ for (GetDisScaleAllInfoDTO getDisScaleAllInfoDTO : getDisScaleAllInfoDTOS) {
|
|
|
+ getDisScaleAllInfoDTO.setDisName(questionInfoMap.get(getDisScaleAllInfoDTO.getDisId()).getName());
|
|
|
+ getDisScaleAllInfoDTO.setScaleName(questionInfoMap.get(getDisScaleAllInfoDTO.getScaleId()).getName());
|
|
|
+ }
|
|
|
+ return getDisScaleAllInfoDTOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除诊断关联量表信息
|
|
|
+ *
|
|
|
+ * @param delDisScaleInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean delDisScaleInfo(DelDisScaleInfoVO delDisScaleInfoVO){
|
|
|
+ UpdateWrapper<DisScale> disScaleUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ if(delDisScaleInfoVO.getDisId() != null){
|
|
|
+ disScaleUpdateWrapper.eq("dis_id",delDisScaleInfoVO.getDisId());
|
|
|
+ }else if (delDisScaleInfoVO.getScaleId() != null){
|
|
|
+ disScaleUpdateWrapper.eq("scale_id",delDisScaleInfoVO.getScaleId());
|
|
|
+ }else {
|
|
|
+ disScaleUpdateWrapper.eq("id",delDisScaleInfoVO.getId());
|
|
|
+ }
|
|
|
+ disScaleUpdateWrapper.set("is_deleted",IsDeleteEnum.Y.getKey())
|
|
|
+ .set("modifier",UserUtils.getCurrentPrincipleID())
|
|
|
+ .set("gmt_modified",DateUtil.now());
|
|
|
+ this.update(new DisScale(),disScaleUpdateWrapper);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|