|
@@ -0,0 +1,236 @@
|
|
|
+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.QcCasesEntrySimpleDTO;
|
|
|
+import com.diagbot.dto.QcTypeDTO;
|
|
|
+import com.diagbot.dto.QcTypePageDTO;
|
|
|
+import com.diagbot.entity.CommonParam;
|
|
|
+import com.diagbot.entity.QcType;
|
|
|
+import com.diagbot.entity.QcTypeCasesEntry;
|
|
|
+import com.diagbot.enums.InsertOrUpdateEnum;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.QcTypeCasesEntryService;
|
|
|
+import com.diagbot.service.impl.QcTypeServiceImpl;
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.DeleteQcTypeVO;
|
|
|
+import com.diagbot.vo.QcTypeCasesEntryVO;
|
|
|
+import com.diagbot.vo.QcTypeIndexVO;
|
|
|
+import com.diagbot.vo.QcTypePageVO;
|
|
|
+import com.diagbot.vo.QcTypeSaveVO;
|
|
|
+import com.diagbot.vo.QcTypeVO;
|
|
|
+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.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhoutg
|
|
|
+ * @time: 2018/11/23 11:37
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class QcTypeFacade extends QcTypeServiceImpl {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("qcTypeCasesEntryServiceImpl")
|
|
|
+ QcTypeCasesEntryService qcTypeCasesEntryService;
|
|
|
+ @Autowired
|
|
|
+ UserServiceClient userServiceClient;
|
|
|
+ @Autowired
|
|
|
+ QcCacesEntryFacade qcCacesEntryFacade;
|
|
|
+ @Autowired
|
|
|
+ QcTypeCasesEntryFacade qcTypeCasesEntryFacade;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存
|
|
|
+ *
|
|
|
+ * @param qcTypeSaveVO
|
|
|
+ */
|
|
|
+ public void saveOrUpdate(QcTypeSaveVO qcTypeSaveVO) {
|
|
|
+ CommonParam param = initCommonParam();
|
|
|
+ // 保存主表
|
|
|
+ saveQcType(qcTypeSaveVO, param);
|
|
|
+ // 保存质控类型和质控条目映射关系
|
|
|
+ saveQcTypeCasesEntry(qcTypeSaveVO, 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 qcTypeSaveVO
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void saveQcTypeCasesEntry(QcTypeSaveVO qcTypeSaveVO, CommonParam param) {
|
|
|
+ Date now = param.getNow();
|
|
|
+ String person = param.getPerson();
|
|
|
+ // 先删除原明细(物理删除)
|
|
|
+ qcTypeCasesEntryService.remove(new QueryWrapper<QcTypeCasesEntry>()
|
|
|
+ .eq("type_id", qcTypeSaveVO.getId())
|
|
|
+ );
|
|
|
+ // 再插入新明细
|
|
|
+ List<QcTypeCasesEntryVO> qcTypeCasesEntryVOList = qcTypeSaveVO.getQcTypeCasesEntryVOList();
|
|
|
+ if (ListUtil.isNotEmpty(qcTypeCasesEntryVOList)) {
|
|
|
+ List<QcTypeCasesEntry> saveQcTypeCasesEntry = new ArrayList<>();
|
|
|
+ for (QcTypeCasesEntryVO mapping : qcTypeCasesEntryVOList) {
|
|
|
+ QcTypeCasesEntry bean = new QcTypeCasesEntry();
|
|
|
+ bean.setCaseEntryId(mapping.getCaseEntryId());
|
|
|
+ bean.setCreator(person);
|
|
|
+ bean.setGmtCreate(now);
|
|
|
+ bean.setModifier(person);
|
|
|
+ bean.setGmtModified(now);
|
|
|
+ bean.setTypeId(qcTypeSaveVO.getId());
|
|
|
+ saveQcTypeCasesEntry.add(bean);
|
|
|
+ }
|
|
|
+ qcTypeCasesEntryService.saveBatch(saveQcTypeCasesEntry);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存主表
|
|
|
+ *
|
|
|
+ * @param qcTypeSaveVO
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void saveQcType(QcTypeSaveVO qcTypeSaveVO, CommonParam param) {
|
|
|
+ QcType qcType = new QcType();
|
|
|
+ Long id = qcTypeSaveVO.getId();
|
|
|
+
|
|
|
+ // 保存主表
|
|
|
+ if (qcTypeSaveVO.getId() != null) {
|
|
|
+ qcType = this.getOne(new QueryWrapper<QcType>()
|
|
|
+ .eq("id", id)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()), false);
|
|
|
+ if (qcType == null) { //校验
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "当前质控类型不存在【id=" + id + "】");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(qcTypeSaveVO, qcType);
|
|
|
+ List<QcType> qcTypeList = this.list(new QueryWrapper<QcType>()
|
|
|
+ .eq("name", qcTypeSaveVO.getName())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", qcTypeSaveVO.getHospitalId())
|
|
|
+ .ne("id", id == null ? -1 : id));
|
|
|
+ // 质控类型hospitalId、name唯一
|
|
|
+ if (ListUtil.isNotEmpty(qcTypeList)) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "名称已存在");
|
|
|
+ }
|
|
|
+ if (InsertOrUpdateEnum.Insert.getKey() == param.getInsertOrUpdate()) {
|
|
|
+ qcType.setCreator(param.getPerson()); //创建人
|
|
|
+ qcType.setGmtCreate(param.getNow());//创建时间
|
|
|
+ }
|
|
|
+ qcType.setGmtModified(param.getNow());//修改时间
|
|
|
+ qcType.setModifier(param.getPerson());//修改人
|
|
|
+ this.saveOrUpdate(qcType);
|
|
|
+ qcTypeSaveVO.setId(qcType.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 标签列表
|
|
|
+ *
|
|
|
+ * @param qcTypePageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<QcTypePageDTO> getListFac(QcTypePageVO qcTypePageVO) {
|
|
|
+ IPage<QcTypePageDTO> res = this.getList(qcTypePageVO);
|
|
|
+// 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检索
|
|
|
+ *
|
|
|
+ * @param qcTypeIndexVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<QcCasesEntrySimpleDTO> indexFac(QcTypeIndexVO qcTypeIndexVO) {
|
|
|
+ List<QcCasesEntrySimpleDTO> res = qcCacesEntryFacade.index(qcTypeIndexVO);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据参数返回质控类型内容
|
|
|
+ *
|
|
|
+ * @param qcTypeVO 获取质控类型内容参数
|
|
|
+ * @return 标签内容
|
|
|
+ */
|
|
|
+ public QcTypeDTO getById(QcTypeVO qcTypeVO) {
|
|
|
+ QcTypeDTO qcTypeDTO = new QcTypeDTO();
|
|
|
+ QcType qcType = this.getOne(new QueryWrapper<QcType>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", qcTypeVO.getId()), false
|
|
|
+ );
|
|
|
+ if (qcType == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
|
|
|
+ "当前质控类型不存在或已删除【id=" + qcTypeVO.getId() + "】");
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(qcType, qcTypeDTO);
|
|
|
+ List<QcCasesEntrySimpleDTO> list = qcTypeCasesEntryFacade.getByTypeIdFac(qcTypeVO);
|
|
|
+ qcTypeDTO.setQcCasesEntrySimpleDTOList(list);
|
|
|
+ return qcTypeDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id删除质控类型
|
|
|
+ *
|
|
|
+ * @param deleteQcTypeVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteByIdsFac(DeleteQcTypeVO deleteQcTypeVO) {
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ String person = UserUtils.getCurrentPrincipleID();
|
|
|
+ // 更新主表
|
|
|
+ this.update(new UpdateWrapper<QcType>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("id", deleteQcTypeVO.getIds())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
+ .set("gmt_modified", now)
|
|
|
+ .set("modifier", person)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 删除明细表
|
|
|
+ qcTypeCasesEntryService.removeByIds(deleteQcTypeVO.getIds());
|
|
|
+ if (ListUtil.isNotEmpty(deleteQcTypeVO.getIds())) {
|
|
|
+ qcTypeCasesEntryService.remove(new QueryWrapper<QcTypeCasesEntry>()
|
|
|
+ .in("type_id", deleteQcTypeVO.getIds())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|