|
@@ -0,0 +1,303 @@
|
|
|
+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.entity.LisConfig;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.service.LisConfigService;
|
|
|
+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.HospitalIdVO;
|
|
|
+import com.diagbot.vo.IdListVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
+import com.diagbot.vo.LisConfigListVO;
|
|
|
+import com.diagbot.vo.LisConfigPageVO;
|
|
|
+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/7/29 15:03
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class LisConfigFacade{
|
|
|
+ @Autowired
|
|
|
+ private LisConfigService lisConfigService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否已存在
|
|
|
+ *
|
|
|
+ * @param lisConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean isExistRecord(LisConfig lisConfig) {
|
|
|
+ QueryWrapper<LisConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ LisConfig oldRecord = new LisConfig();
|
|
|
+ if (lisConfig.getId() != null) {
|
|
|
+ oldRecord = lisConfigService.getById(lisConfig.getId());
|
|
|
+ if (oldRecord != null && oldRecord.getIsDeleted().equals(IsDeleteEnum.N.getKey())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } else if (StringUtil.isNotBlank(lisConfig.getHisName())) {
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", lisConfig.getHospitalId())
|
|
|
+ .eq("his_name", lisConfig.getHisName())
|
|
|
+ .eq("unique_name", lisConfig.getUniqueName());
|
|
|
+ if (StringUtil.isBlank(lisConfig.getHisDetailName())) {
|
|
|
+ queryWrapper
|
|
|
+ .isNull("his_detail_name")
|
|
|
+ .or()
|
|
|
+ .eq("his_detail_name", "");
|
|
|
+ } else {
|
|
|
+ queryWrapper
|
|
|
+ .eq("his_detail_name", lisConfig.getHisDetailName());
|
|
|
+ }
|
|
|
+ oldRecord = lisConfigService.getOne(queryWrapper);
|
|
|
+ if (oldRecord != null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-单条
|
|
|
+ *
|
|
|
+ * @param lisConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecord(LisConfig lisConfig) {
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ lisConfig.setModifier(userId);
|
|
|
+ lisConfig.setGmtModified(now);
|
|
|
+ //新增数据
|
|
|
+ if (lisConfig.getId() == null) {
|
|
|
+ lisConfig.setCreator(userId);
|
|
|
+ lisConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (lisConfig.getIsDeleted() == null) {
|
|
|
+ lisConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ lisConfigService.saveOrUpdate(lisConfig);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-批量
|
|
|
+ *
|
|
|
+ * @param lisConfigListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecords(LisConfigListVO lisConfigListVO) {
|
|
|
+ if (ListUtil.isEmpty(lisConfigListVO.getLisConfigList())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return saveOrUpdateRecords(lisConfigListVO.getLisConfigList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量保存
|
|
|
+ *
|
|
|
+ * @param lisConfigList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecords(List<LisConfig> lisConfigList) {
|
|
|
+ if (ListUtil.isEmpty(lisConfigList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ //数据不完整的不保存
|
|
|
+ //过滤套餐或公表名为空的数据,hospitalId不允许为空
|
|
|
+ lisConfigList = lisConfigList
|
|
|
+ .stream()
|
|
|
+ .filter(i->i.getHospitalId()!=null)
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if(ListUtil.isEmpty(lisConfigList)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Long hosptialId=lisConfigList.get(0).getHospitalId();
|
|
|
+
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
+ Map<String, Map<String, Map<String, Long>>> configMap
|
|
|
+ = getConfigMap(hosptialId, null, null);
|
|
|
+ lisConfigList.forEach(lisConfig -> {
|
|
|
+ lisConfig.setModifier(userId);
|
|
|
+ lisConfig.setGmtModified(now);
|
|
|
+ if (lisConfig.getId() == null) {
|
|
|
+ if (configMap.containsKey(lisConfig.getHisName())) {
|
|
|
+ if (lisConfig.getHisDetailName() == null
|
|
|
+ && configMap.get(lisConfig.getHisName()).containsKey("")) {
|
|
|
+ if (configMap.get(lisConfig.getHisName()).get("").containsKey(lisConfig.getUniqueName())) {
|
|
|
+ deleteIds.add(configMap.get(lisConfig.getHisName()).get("").get(lisConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ } else if (configMap.get(lisConfig.getHisName()).containsKey(lisConfig.getHisDetailName())) {
|
|
|
+ if (configMap.get(lisConfig.getHisName()).get(lisConfig.getHisDetailName()).containsKey(lisConfig.getUniqueName())) {
|
|
|
+ deleteIds.add(configMap
|
|
|
+ .get(lisConfig.getHisName())
|
|
|
+ .get(lisConfig.getHisDetailName())
|
|
|
+ .get(lisConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lisConfig.setCreator(userId);
|
|
|
+ lisConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (lisConfig.getIsDeleted() == null) {
|
|
|
+ lisConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //删除已存在映射关系
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+
|
|
|
+ lisConfigService.saveOrUpdateBatch(lisConfigList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-单条
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecord(IdVO idVO) {
|
|
|
+ UpdateWrapper<LisConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", idVO.getId())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ lisConfigService.removeById(idVO.getId());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-批量
|
|
|
+ *
|
|
|
+ * @param idListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecords(IdListVO idListVO) {
|
|
|
+ if (ListUtil.isEmpty(idListVO.getIds())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ UpdateWrapper<LisConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.in("id", idListVO.getIds())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ lisConfigService.removeByIds(idListVO.getIds());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param lisConfigPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<LisConfig> getPage(LisConfigPageVO lisConfigPageVO) {
|
|
|
+ return lisConfigService.getPage(lisConfigPageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导入
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * @param hospitalIdVO
|
|
|
+ */
|
|
|
+ public void importExcel(MultipartFile file, HospitalIdVO hospitalIdVO) {
|
|
|
+ //从Excel读取数据
|
|
|
+ List<LisConfig> lisConfigList = ExcelUtils.importExcel(file, 0, 1, LisConfig.class);
|
|
|
+ if (ListUtil.isNotEmpty(lisConfigList)) {
|
|
|
+ lisConfigList.forEach(lisConfig -> {
|
|
|
+ lisConfig.setHospitalId(hospitalIdVO.getHospitalId());
|
|
|
+ });
|
|
|
+ saveOrUpdateRecords(lisConfigList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-id
|
|
|
+ * Map<hisName,Map<hisDetailName,Map<uniqueName,id>>>
|
|
|
+ *
|
|
|
+ * @param hospitalId
|
|
|
+ * @param hisNames
|
|
|
+ * @param uniqueNames
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Map<String, Map<String, Long>>> getConfigMap(Long hospitalId, List<String> hisNames, List<String> uniqueNames) {
|
|
|
+ Map<String, Map<String, Map<String, Long>>> retMap = new HashMap<>();
|
|
|
+ QueryWrapper<LisConfig> 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<LisConfig> records = lisConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ records.forEach(lisConfig -> {
|
|
|
+ if (lisConfig.getHisDetailName() == null) {
|
|
|
+ lisConfig.setHisDetailName("");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<String, List<LisConfig>> hisNameMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<LisConfig>> entry : hisNameMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ Map<String, Map<String, Long>> detailNameMap = new HashMap<>();
|
|
|
+ //his名称映射到标准词,1:n
|
|
|
+ Map<String, List<LisConfig>> hisDetailNameMap
|
|
|
+ = EntityUtil.makeEntityListMap(entry.getValue(), "hisDetailName");
|
|
|
+ for (Map.Entry<String, List<LisConfig>> detailEntry : hisDetailNameMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(detailEntry.getValue())) {
|
|
|
+ detailNameMap.put(detailEntry.getKey(),
|
|
|
+ EntityUtil.makeMapWithKeyValue(detailEntry.getValue(), "uniqueName", "id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ retMap.put(entry.getKey(), detailNameMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param hospitalIdVO
|
|
|
+ */
|
|
|
+ public void exportExcel(HttpServletResponse response, HospitalIdVO hospitalIdVO) {
|
|
|
+ QueryWrapper<LisConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalIdVO.getHospitalId());
|
|
|
+ List<LisConfig> records = lisConfigService.list(queryWrapper);
|
|
|
+ String fileName = "检验映射.xls";
|
|
|
+ ExcelUtils.exportExcel(records, null, "sheet1", LisConfig.class, fileName, response, 12.8f);
|
|
|
+ }
|
|
|
+}
|