|
@@ -0,0 +1,275 @@
|
|
|
+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.dto.HosRelationNumDTO;
|
|
|
+import com.diagbot.entity.TransfusionConfig;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.service.TransfusionConfigService;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.ExcelUtils;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.TransfusionConfigListVO;
|
|
|
+import com.diagbot.vo.TransfusionConfigPageVO;
|
|
|
+import com.diagbot.vo.HosRelationNumPageVO;
|
|
|
+import com.diagbot.vo.HospitalIdVO;
|
|
|
+import com.diagbot.vo.IdListVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhaops
|
|
|
+ * @time: 2020/9/1 11:03
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class TransfusionConfigFacade {
|
|
|
+ @Autowired
|
|
|
+ private TransfusionConfigService transfusionConfigService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否已存在
|
|
|
+ *
|
|
|
+ * @param transfusionConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean isExistRecord(TransfusionConfig transfusionConfig) {
|
|
|
+ QueryWrapper<TransfusionConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ TransfusionConfig oldRecord = new TransfusionConfig();
|
|
|
+ if (transfusionConfig.getId() != null) {
|
|
|
+ oldRecord = transfusionConfigService.getById(transfusionConfig.getId());
|
|
|
+ if (oldRecord != null && oldRecord.getIsDeleted().equals(IsDeleteEnum.N.getKey())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(transfusionConfig.getHisName())) {
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", transfusionConfig.getHospitalId())
|
|
|
+ .eq("his_name", transfusionConfig.getHisName())
|
|
|
+ .eq("unique_name", transfusionConfig.getUniqueName());
|
|
|
+ oldRecord = transfusionConfigService.getOne(queryWrapper);
|
|
|
+ if (oldRecord != null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-单条
|
|
|
+ *
|
|
|
+ * @param transfusionConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecord(TransfusionConfig transfusionConfig) {
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ transfusionConfig.setModifier(userId);
|
|
|
+ transfusionConfig.setGmtModified(now);
|
|
|
+ //新增数据
|
|
|
+ if (transfusionConfig.getId() == null) {
|
|
|
+ transfusionConfig.setCreator(userId);
|
|
|
+ transfusionConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (transfusionConfig.getIsDeleted() == null) {
|
|
|
+ transfusionConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ transfusionConfigService.saveOrUpdate(transfusionConfig);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-批量
|
|
|
+ *
|
|
|
+ * @param transfusionConfigListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecords(TransfusionConfigListVO transfusionConfigListVO) {
|
|
|
+ if (ListUtil.isEmpty(transfusionConfigListVO.getTransfusionConfigList())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return saveOrUpdateRecords(transfusionConfigListVO.getTransfusionConfigList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量保存
|
|
|
+ *
|
|
|
+ * @param transfusionConfigList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecords(List<TransfusionConfig> transfusionConfigList) {
|
|
|
+ if (ListUtil.isEmpty(transfusionConfigList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ //数据不完整的不保存
|
|
|
+ //过滤外部名称或公表名为空的数据
|
|
|
+ transfusionConfigList = transfusionConfigList
|
|
|
+ .stream()
|
|
|
+ .filter(i -> i.getHospitalId() != null)
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (ListUtil.isEmpty(transfusionConfigList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long hospitalId = transfusionConfigList.get(0).getHospitalId();
|
|
|
+
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
+ Map<String, Map<String, Long>> configMap
|
|
|
+ = getConfigMap(hospitalId, null, null);
|
|
|
+ transfusionConfigList.forEach(transfusionConfig -> {
|
|
|
+ transfusionConfig.setModifier(userId);
|
|
|
+ transfusionConfig.setGmtModified(now);
|
|
|
+ if (transfusionConfig.getId() == null) {
|
|
|
+ if (configMap.containsKey(transfusionConfig.getHisName())) {
|
|
|
+ deleteIds.add(configMap.get(transfusionConfig.getHisName()).get(transfusionConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ transfusionConfig.setCreator(userId);
|
|
|
+ transfusionConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (transfusionConfig.getIsDeleted() == null) {
|
|
|
+ transfusionConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //删除已存在映射关系
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ transfusionConfigService.saveOrUpdateBatch(transfusionConfigList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-单条
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecord(IdVO idVO) {
|
|
|
+ UpdateWrapper<TransfusionConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", idVO.getId())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ transfusionConfigService.removeById(idVO.getId());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-批量
|
|
|
+ *
|
|
|
+ * @param idListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecords(IdListVO idListVO) {
|
|
|
+ if (ListUtil.isEmpty(idListVO.getIds())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ UpdateWrapper<TransfusionConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.in("id", idListVO.getIds())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ transfusionConfigService.removeByIds(idListVO.getIds());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param transfusionConfigPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<TransfusionConfig> getPage(TransfusionConfigPageVO transfusionConfigPageVO) {
|
|
|
+ return transfusionConfigService.getPage(transfusionConfigPageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导入
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param hospitalIdVO
|
|
|
+ */
|
|
|
+ public void importExcel(MultipartFile file, HospitalIdVO hospitalIdVO) {
|
|
|
+ List<TransfusionConfig> transfusionConfigList = ExcelUtils.importExcel(file, 0, 1, TransfusionConfig.class);
|
|
|
+ if (ListUtil.isNotEmpty(transfusionConfigList)) {
|
|
|
+ transfusionConfigList.forEach(transfusionConfig -> {
|
|
|
+ transfusionConfig.setHospitalId(hospitalIdVO.getHospitalId());
|
|
|
+ });
|
|
|
+ saveOrUpdateRecords(transfusionConfigList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-公表名
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Map<String, Long>> getConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, Long>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<TransfusionConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalId);
|
|
|
+ if (ListUtil.isNotEmpty(hisNames)) {
|
|
|
+ queryWrapper.in("his_name", hisNames);
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(uniqueNames)) {
|
|
|
+ queryWrapper.in("unique_name", uniqueNames);
|
|
|
+ }
|
|
|
+ List<TransfusionConfig> records = transfusionConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, List<TransfusionConfig>> configMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<TransfusionConfig>> entry : configMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ retMap.put(entry.getKey(), EntityUtil.makeMapWithKeyValue(entry.getValue(), "uniqueName", "id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param hospitalIdVO
|
|
|
+ */
|
|
|
+ public void exportExcel(HttpServletResponse response, HospitalIdVO hospitalIdVO) {
|
|
|
+ QueryWrapper<TransfusionConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalIdVO.getHospitalId());
|
|
|
+ List<TransfusionConfig> records = transfusionConfigService.list(queryWrapper);
|
|
|
+ String fileName = "输血映射.xls";
|
|
|
+ ExcelUtils.exportExcel(records, null, "sheet1", TransfusionConfig.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 各医院映射关系数列表
|
|
|
+ *
|
|
|
+ * @param hosRelationNumPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<HosRelationNumDTO> getRelationNumPage(HosRelationNumPageVO hosRelationNumPageVO) {
|
|
|
+ return transfusionConfigService.getRelationNumPage(hosRelationNumPageVO);
|
|
|
+ }
|
|
|
+}
|