|
@@ -0,0 +1,439 @@
|
|
|
+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.QuestionDTO;
|
|
|
+import com.diagbot.dto.QuestionPageDTO;
|
|
|
+import com.diagbot.entity.CommonParam;
|
|
|
+import com.diagbot.entity.QcQuestionInfo;
|
|
|
+import com.diagbot.entity.QcQuestionMapping;
|
|
|
+import com.diagbot.entity.wrapper.QuestionInfoWrapper;
|
|
|
+import com.diagbot.entity.wrapper.QuestionMappingWrapper;
|
|
|
+import com.diagbot.entity.wrapper.QuestionWrapper;
|
|
|
+import com.diagbot.enums.InsertOrUpdateEnum;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.QcQuestionMappingService;
|
|
|
+import com.diagbot.service.impl.QcQuestionInfoServiceImpl;
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.DeleteQuestionVO;
|
|
|
+import com.diagbot.vo.QuestionIdsVO;
|
|
|
+import com.diagbot.vo.QuestionIndexVO;
|
|
|
+import com.diagbot.vo.QuestionPageVO;
|
|
|
+import com.diagbot.vo.QuestionSaveVO;
|
|
|
+import com.diagbot.vo.QuestionVO;
|
|
|
+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.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhoutg
|
|
|
+ * @time: 2018/11/23 11:37
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class QcQuestionFacade extends QcQuestionInfoServiceImpl {
|
|
|
+
|
|
|
+// @Autowired
|
|
|
+// @Qualifier("questionInfoServiceImpl")
|
|
|
+// QuestionInfoService questionInfoService;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("qcQuestionMappingServiceImpl")
|
|
|
+ QcQuestionMappingService qcQuestionMappingService;
|
|
|
+ @Autowired
|
|
|
+ QcQuestionMappingFacade qcQuestionMappingFacade;
|
|
|
+ @Autowired
|
|
|
+ UserServiceClient userServiceClient;
|
|
|
+// @Autowired
|
|
|
+// ModuleDetailFacade moduleDetailFacade;
|
|
|
+// @Autowired
|
|
|
+// ModuleInfoFacade moduleInfoFacade;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 标签保存
|
|
|
+ *
|
|
|
+ * @param questionSaveVO
|
|
|
+ */
|
|
|
+ public void saveOrUpdate(QuestionSaveVO questionSaveVO) {
|
|
|
+ QuestionWrapper questionWrapper = questionSaveVO.getQuestionWrapper();
|
|
|
+ CommonParam param = initCommonParam();
|
|
|
+ //保存|修改主表信息
|
|
|
+ saveQuestionInfo(questionWrapper, param);
|
|
|
+ // 保存映射表
|
|
|
+ saveQuestionMapping(questionWrapper, param);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化参数
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public CommonParam initCommonParam() {
|
|
|
+ CommonParam param = new CommonParam();
|
|
|
+ String person = UserUtils.getCurrentPrincipleID();
|
|
|
+ param.setNow(DateUtil.now());
|
|
|
+ param.setPerson(person);
|
|
|
+ param.setInsertOrUpdate(InsertOrUpdateEnum.Insert.getKey());
|
|
|
+ return param;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存映射关系
|
|
|
+ *
|
|
|
+ * @param questionWrapper
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void saveQuestionMapping(QuestionWrapper questionWrapper, CommonParam param) {
|
|
|
+ QcQuestionInfo questionInfo = param.getQcQuestionInfo();
|
|
|
+ Date now = param.getNow();
|
|
|
+ String person = param.getPerson();
|
|
|
+ //先删除原明细,再插入新明细
|
|
|
+ List<QuestionMappingWrapper> questionMappings = questionWrapper.getQuestionMappings();
|
|
|
+ if (ListUtil.isNotEmpty(questionMappings)) {
|
|
|
+ deleteMapping(questionInfo.getId(), param);//删除原映射关系
|
|
|
+ saveMapping(questionMappings, person, now, questionInfo.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除映射关系
|
|
|
+ *
|
|
|
+ * @param questionId
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void deleteMapping(Long questionId, CommonParam param) {
|
|
|
+ qcQuestionMappingFacade.update(new QcQuestionMapping(),
|
|
|
+ new UpdateWrapper<QcQuestionMapping>()
|
|
|
+ .eq("parent_question", questionId)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .set("gmt_modified", param.getNow())
|
|
|
+ .set("modifier", param.getPerson())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存映射关系
|
|
|
+ *
|
|
|
+ * @param questionMappings
|
|
|
+ * @param person
|
|
|
+ * @param now
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ public void saveMapping(List<QuestionMappingWrapper> questionMappings, String person, Date now, Long id) {
|
|
|
+ List<QcQuestionMapping> saveMapping = new ArrayList<>();
|
|
|
+ for (QuestionMappingWrapper mapping : questionMappings) {
|
|
|
+ QcQuestionMapping bean = new QcQuestionMapping();
|
|
|
+ BeanUtil.copyProperties(mapping, bean);
|
|
|
+ bean.setId(null); //防止前端传参,将前端的id置空自动插入
|
|
|
+ bean.setCreator(person);
|
|
|
+ bean.setGmtCreate(now);
|
|
|
+ bean.setModifier(person);
|
|
|
+ bean.setGmtModified(now);
|
|
|
+ bean.setParentQuestion(id);
|
|
|
+ saveMapping.add(bean);
|
|
|
+ }
|
|
|
+ qcQuestionMappingService.saveBatch(saveMapping);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存主表
|
|
|
+ *
|
|
|
+ * @param questionWrapper
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void saveQuestionInfo(QuestionWrapper questionWrapper, CommonParam param) {
|
|
|
+ QcQuestionInfo qcQuestionInfo = new QcQuestionInfo();
|
|
|
+ if (questionWrapper.getId() != null) {
|
|
|
+ qcQuestionInfo = this.getOne(new QueryWrapper<QcQuestionInfo>()
|
|
|
+ .eq("id", questionWrapper.getId())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()), false);
|
|
|
+ if (qcQuestionInfo == null) { //校验
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标签不存在");
|
|
|
+ }
|
|
|
+ param.setInsertOrUpdate(InsertOrUpdateEnum.Update.getKey());
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(questionWrapper, qcQuestionInfo);
|
|
|
+ List<QcQuestionInfo> questionInfoList = this.list(new QueryWrapper<QcQuestionInfo>()
|
|
|
+ .eq("tag_name", qcQuestionInfo.getTagName())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("mode_id", qcQuestionInfo.getModeId())
|
|
|
+ .eq("hospital_id", qcQuestionInfo.getHospitalId())
|
|
|
+ .ne("id", qcQuestionInfo.getId() == null ? -1 : qcQuestionInfo.getId()));
|
|
|
+ if (ListUtil.isNotEmpty(questionInfoList)) { //标签type、tagName唯一
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "系统名称已重复,无法建立");
|
|
|
+ }
|
|
|
+ if (InsertOrUpdateEnum.Insert.getKey() == param.getInsertOrUpdate()) {
|
|
|
+ qcQuestionInfo.setCreator(param.getPerson()); //创建人
|
|
|
+ qcQuestionInfo.setGmtCreate(param.getNow());//创建时间
|
|
|
+ }
|
|
|
+ qcQuestionInfo.setGmtModified(param.getNow());//修改时间
|
|
|
+ qcQuestionInfo.setModifier(param.getPerson());//修改人
|
|
|
+ param.setQcQuestionInfo(qcQuestionInfo);
|
|
|
+ this.saveOrUpdate(qcQuestionInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 标签列表
|
|
|
+ *
|
|
|
+ * @param questionPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<QuestionPageDTO> getListFac(QuestionPageVO questionPageVO) {
|
|
|
+ IPage<QuestionPageDTO> res = this.getList(questionPageVO);
|
|
|
+// if (res.getTotal() <= 0) {
|
|
|
+// return res;
|
|
|
+// }
|
|
|
+// List<String> personIds = res.getRecords().stream().map(row -> row.getModifier()).collect(Collectors.toList());
|
|
|
+// RespDTO<Map<String, String>> mapRespDTO = userServiceClient.getUserInfoByIds(personIds);
|
|
|
+// if (mapRespDTO == null || !CommonErrorCode.OK.getCode().equals(mapRespDTO.code)) {
|
|
|
+// throw new CommonException(CommonErrorCode.RPC_ERROR, "获取操作人失败");
|
|
|
+// }
|
|
|
+// for (QuestionPageDTO bean : res.getRecords()) {
|
|
|
+// bean.setModifier(mapRespDTO.data.get(bean.getModifier()));
|
|
|
+// }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id删除标签
|
|
|
+ *
|
|
|
+ * @param deleteQuestionVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteByIdsFac(DeleteQuestionVO deleteQuestionVO) {
|
|
|
+ String ids = deleteQuestionVO.getIds();
|
|
|
+ if (StringUtil.isEmpty(ids)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ List<String> idList = Arrays.asList(ids.split(","));
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ String person = UserUtils.getCurrentPrincipleID();
|
|
|
+ for (String id : idList) {
|
|
|
+ Map paramMap = new HashMap<>();
|
|
|
+ paramMap.put("delete", IsDeleteEnum.Y.getKey());
|
|
|
+ paramMap.put("ids", Arrays.asList(ids.split(",")));
|
|
|
+ paramMap.put("gmtModified", now);
|
|
|
+ paramMap.put("modifier", person);
|
|
|
+ // 映射关系删除校验,如果有父项关联,不能删除
|
|
|
+ List<QcQuestionInfo> questionInfoList = getParentQuestion(Long.parseLong(id));
|
|
|
+ if (ListUtil.isNotEmpty(questionInfoList)) {
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ sb.append("请先删除上级关联:");
|
|
|
+ for (QcQuestionInfo ques : questionInfoList) {
|
|
|
+ sb.append("【" + ques.getTagName() + "】");
|
|
|
+ }
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
|
|
|
+ sb.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO 从模板中查找是否有关联
|
|
|
+// List<ModuleDetail> moduleDetails = moduleDetailFacade.list(new QueryWrapper<ModuleDetail>()
|
|
|
+// .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+// .eq("question_id", Long.parseLong(id)));
|
|
|
+// if (ListUtil.isNotEmpty(moduleDetails)) {
|
|
|
+// StringBuffer errMsg = new StringBuffer();
|
|
|
+// StringBuffer finalMsg = new StringBuffer();
|
|
|
+// List<Long> moduleIds = moduleDetails.stream().map(row -> row.getModuleId()).collect(Collectors.toList());
|
|
|
+// List<String> moduleNames = moduleInfoFacade.list(new QueryWrapper<ModuleInfo>()
|
|
|
+// .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+// .in("id", moduleIds))
|
|
|
+// .stream().map(row -> row.getName()).collect(Collectors.toList());
|
|
|
+// for (String mouduleName : moduleNames) {
|
|
|
+// if (moduleNames.get(moduleNames.size() - 1).equals(mouduleName)) {//如果当前元素是最后一个,不追加顿号
|
|
|
+// errMsg.append("【" + mouduleName + "】");
|
|
|
+// } else {
|
|
|
+// errMsg.append("【" + mouduleName + "】").append("、");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// finalMsg.append("该标签已关联模板").append(errMsg);
|
|
|
+// throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
|
|
|
+// finalMsg.toString());
|
|
|
+// }
|
|
|
+
|
|
|
+ //删除自身
|
|
|
+ this.deleteByIds(paramMap);
|
|
|
+
|
|
|
+ //删除映射关系
|
|
|
+ qcQuestionMappingFacade.deleteByIdsFac(paramMap);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检索
|
|
|
+ *
|
|
|
+ * @param questionIndexVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<QcQuestionInfo> indexFac(QuestionIndexVO questionIndexVO) {
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
+ paramMap.put("hospitalId", questionIndexVO.getHospitalId());
|
|
|
+ paramMap.put("modeId", questionIndexVO.getModeId());
|
|
|
+ paramMap.put("tagName", questionIndexVO.getTagName());
|
|
|
+ paramMap.put("controlType", questionIndexVO.getControlType());
|
|
|
+ paramMap.put("notIds", questionIndexVO.getNotIds());
|
|
|
+ paramMap.put("tagType", questionIndexVO.getTagType());
|
|
|
+ paramMap.put("notTagType", questionIndexVO.getNotTagType());
|
|
|
+ paramMap.put("notControlType", questionIndexVO.getNotControlType());
|
|
|
+ List<QcQuestionInfo> res = this.index(paramMap);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 根据主标签id 检索子标签
|
|
|
+// *
|
|
|
+// * @param questionIndexSubVO
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public List<QuestionInfo> indexSub(QuestionIndexSubVO questionIndexSubVO) {
|
|
|
+// Map<String, Object> paramMap = new HashMap<>();
|
|
|
+// paramMap.put("age", questionIndexSubVO.getAge());
|
|
|
+// paramMap.put("sexType", questionIndexSubVO.getSexType());
|
|
|
+// paramMap.put("tagName", questionIndexSubVO.getTagName());
|
|
|
+// paramMap.put("type", questionIndexSubVO.getType());
|
|
|
+// paramMap.put("controlType", questionIndexSubVO.getControlType());
|
|
|
+// paramMap.put("notIds", questionIndexSubVO.getNotIds());
|
|
|
+// paramMap.put("tagType", questionIndexSubVO.getTagType());
|
|
|
+// paramMap.put("existName", questionIndexSubVO.getExistName());
|
|
|
+// paramMap.put("notTagType", questionIndexSubVO.getNotTagType());
|
|
|
+// paramMap.put("notControlType", questionIndexSubVO.getNotControlType());
|
|
|
+//
|
|
|
+// QueryWrapper<QuestionMapping> questionMappingQueryWrapper = new QueryWrapper<>();
|
|
|
+// questionMappingQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+// .eq("parent_question", questionIndexSubVO.getParentId());
|
|
|
+// List<QuestionMapping> questionMappingList = questionMappingFacade.list(questionMappingQueryWrapper);
|
|
|
+// if (ListUtil.isNotEmpty(questionMappingList)) {
|
|
|
+// List<Long> sonIds = questionMappingList.stream().map(questionMapping -> questionMapping.getSonQuestion())
|
|
|
+// .collect(Collectors.toList());
|
|
|
+// paramMap.put("ids", sonIds);
|
|
|
+// }
|
|
|
+// List<QuestionInfo> res = this.index(paramMap);
|
|
|
+// return res;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据参数返回标签内容
|
|
|
+ *
|
|
|
+ * @param questionVO 获取标签内容参数
|
|
|
+ * @return 标签内容
|
|
|
+ */
|
|
|
+ public QuestionDTO getById(QuestionVO questionVO) {
|
|
|
+ Map paramMap = new HashMap<>();
|
|
|
+ paramMap.put("id", questionVO.getId());
|
|
|
+
|
|
|
+ QcQuestionInfo questionInfo = this.getOne(new QueryWrapper<QcQuestionInfo>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", questionVO.getId()), false
|
|
|
+ );
|
|
|
+ if (questionInfo == null) { //无数据直接返回,不通过报错的形式返回
|
|
|
+ return new QuestionDTO();
|
|
|
+ }
|
|
|
+ QuestionDTO res = new QuestionDTO();
|
|
|
+ BeanUtil.copyProperties(questionInfo, res);
|
|
|
+
|
|
|
+ //获取子标签
|
|
|
+ List<QuestionInfoWrapper> questionMapping = this.getByQuestionMapping(paramMap);
|
|
|
+ List<QuestionDTO> sonQuestionList = BeanUtil.listCopyTo(questionMapping, QuestionDTO.class);
|
|
|
+ res.setQuestionMapping(sonQuestionList);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询多个id返回标签内容
|
|
|
+ *
|
|
|
+ * @param questionIdsVO 获取标签内容参数
|
|
|
+ * @return 标签内容
|
|
|
+ */
|
|
|
+ public Map<Long, Object> getByIds(QuestionIdsVO questionIdsVO) {
|
|
|
+ Map<Long, Object> data = new HashMap<>();
|
|
|
+ if (StringUtil.isEmpty(questionIdsVO.getIds())) {
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ String[] ids = questionIdsVO.getIds().split(",");
|
|
|
+ for (String id : ids) {
|
|
|
+ QuestionVO questionVO = new QuestionVO();
|
|
|
+ questionVO.setId(Long.parseLong(id));
|
|
|
+ QuestionDTO item = this.getById(questionVO);
|
|
|
+ data.put(item.getId(), item);
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 根据id返回被引用的父标签
|
|
|
+// *
|
|
|
+// * @param subQuestionVO 获取父标签内容参数
|
|
|
+// * @return 标签内容
|
|
|
+// */
|
|
|
+// public List<QuestionInfo> getBySubQuestionId(SubQuestionVO subQuestionVO) {
|
|
|
+// List<QuestionDetail> list = questionDetailFacade.list(new QueryWrapper<QuestionDetail>()
|
|
|
+// .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+// .apply("find_in_set({0}, sub_question)", subQuestionVO.getId())
|
|
|
+// );
|
|
|
+// if (ListUtil.isNotEmpty(list)) {
|
|
|
+// List<Long> ids = list.stream().map(r -> r.getQuestionId()).distinct().collect(Collectors.toList());
|
|
|
+// return this.list(new QueryWrapper<QuestionInfo>()
|
|
|
+// .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+// .in("id", ids)
|
|
|
+// );
|
|
|
+// }
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 获取所有需要删除的缓存id列表
|
|
|
+// *
|
|
|
+// * @param id
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public List<Long> getDeleteId(Long id) {
|
|
|
+// List<Long> list = new ArrayList<>();
|
|
|
+// list.add(id); //添加自身id
|
|
|
+// getParent(id, list); //添加父级
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// public void getParent(Long id, List<Long> list) {
|
|
|
+// List<QuestionMapping> questionMappingList = questionMappingFacade.list(
|
|
|
+// new QueryWrapper<QuestionMapping>()
|
|
|
+// .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+// .eq("son_question", id)
|
|
|
+// );
|
|
|
+// if (ListUtil.isNotEmpty(questionMappingList)) {
|
|
|
+// for (QuestionMapping questionMapping : questionMappingList) {
|
|
|
+// Long parentId = questionMapping.getParentQuestion();
|
|
|
+// if (!list.contains(parentId)) {
|
|
|
+// list.add(parentId);
|
|
|
+// getParent(parentId, list);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+}
|