|
@@ -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.DeptConfig;
|
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
|
+import com.diagbot.service.DeptConfigService;
|
|
|
|
+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.DeptConfigListVO;
|
|
|
|
+import com.diagbot.vo.DeptConfigPageVO;
|
|
|
|
+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/8/12 14:25
|
|
|
|
+ */
|
|
|
|
+@Component
|
|
|
|
+public class DeptConfigFacade {
|
|
|
|
+ @Autowired
|
|
|
|
+ private DeptConfigService deptConfigService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断是否已存在
|
|
|
|
+ *
|
|
|
|
+ * @param deptConfig
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Boolean isExistRecord(DeptConfig deptConfig) {
|
|
|
|
+ QueryWrapper<DeptConfig> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ DeptConfig oldRecord = new DeptConfig();
|
|
|
|
+ if (deptConfig.getId() != null) {
|
|
|
|
+ oldRecord = deptConfigService.getById(deptConfig.getId());
|
|
|
|
+ if (oldRecord != null && oldRecord.getIsDeleted().equals(IsDeleteEnum.N.getKey())) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isNotBlank(deptConfig.getHisName())) {
|
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
|
+ .eq("hospital_id", deptConfig.getHospitalId())
|
|
|
|
+ .eq("his_name", deptConfig.getHisName())
|
|
|
|
+ .eq("unique_name", deptConfig.getUniqueName());
|
|
|
|
+ oldRecord = deptConfigService.getOne(queryWrapper);
|
|
|
|
+ if (oldRecord != null) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存记录-单条
|
|
|
|
+ *
|
|
|
|
+ * @param deptConfig
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Boolean saveOrUpdateRecord(DeptConfig deptConfig) {
|
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
|
+ Date now = DateUtil.now();
|
|
|
|
+ deptConfig.setModifier(userId);
|
|
|
|
+ deptConfig.setGmtModified(now);
|
|
|
|
+ //新增数据
|
|
|
|
+ if (deptConfig.getId() == null) {
|
|
|
|
+ deptConfig.setCreator(userId);
|
|
|
|
+ deptConfig.setGmtCreate(now);
|
|
|
|
+ }
|
|
|
|
+ if (deptConfig.getIsDeleted() == null) {
|
|
|
|
+ deptConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
|
+ }
|
|
|
|
+ deptConfigService.saveOrUpdate(deptConfig);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存记录-批量
|
|
|
|
+ *
|
|
|
|
+ * @param deptConfigListVO
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Boolean saveOrUpdateRecords(DeptConfigListVO deptConfigListVO) {
|
|
|
|
+ if (ListUtil.isEmpty(deptConfigListVO.getDeptConfigList())) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return saveOrUpdateRecords(deptConfigListVO.getDeptConfigList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量保存
|
|
|
|
+ *
|
|
|
|
+ * @param deptConfigList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Boolean saveOrUpdateRecords(List<DeptConfig> deptConfigList) {
|
|
|
|
+ if (ListUtil.isEmpty(deptConfigList)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
|
+ Date now = DateUtil.now();
|
|
|
|
+
|
|
|
|
+ //数据不完整的不保存
|
|
|
|
+ //过滤外部名称或公表名为空的数据
|
|
|
|
+ deptConfigList = deptConfigList
|
|
|
|
+ .stream()
|
|
|
|
+ .filter(i -> i.getHospitalId() != null)
|
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ if (ListUtil.isEmpty(deptConfigList)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long hospitalId = deptConfigList.get(0).getHospitalId();
|
|
|
|
+
|
|
|
|
+ // 验证数据是否已存在,已存在的先删除
|
|
|
|
+ // 没id的删除重新插入,有id的更新
|
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
|
+ Map<String, Map<String, Long>> configMap
|
|
|
|
+ = getConfigMap(hospitalId, null, null);
|
|
|
|
+ deptConfigList.forEach(deptConfig -> {
|
|
|
|
+ deptConfig.setModifier(userId);
|
|
|
|
+ deptConfig.setGmtModified(now);
|
|
|
|
+ if (deptConfig.getId() == null) {
|
|
|
|
+ if (configMap.containsKey(deptConfig.getHisName())) {
|
|
|
|
+ deleteIds.add(configMap.get(deptConfig.getHisName()).get(deptConfig.getUniqueName()));
|
|
|
|
+ }
|
|
|
|
+ deptConfig.setCreator(userId);
|
|
|
|
+ deptConfig.setGmtCreate(now);
|
|
|
|
+ }
|
|
|
|
+ if (deptConfig.getIsDeleted() == null) {
|
|
|
|
+ deptConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ //删除已存在映射关系
|
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
|
+ deleteRecords(idListVO);
|
|
|
|
+ deptConfigService.saveOrUpdateBatch(deptConfigList);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除记录-单条
|
|
|
|
+ *
|
|
|
|
+ * @param idVO
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Boolean deleteRecord(IdVO idVO) {
|
|
|
|
+ UpdateWrapper<DeptConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
|
+ updateWrapper.eq("id", idVO.getId())
|
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
|
+ deptConfigService.removeById(idVO.getId());
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除记录-批量
|
|
|
|
+ *
|
|
|
|
+ * @param idListVO
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Boolean deleteRecords(IdListVO idListVO) {
|
|
|
|
+ if (ListUtil.isEmpty(idListVO.getIds())) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ UpdateWrapper<DeptConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
|
+ updateWrapper.in("id", idListVO.getIds())
|
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
|
+ deptConfigService.removeByIds(idListVO.getIds());
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 分页查询
|
|
|
|
+ *
|
|
|
|
+ * @param deptConfigPageVO
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public IPage<DeptConfig> getPage(DeptConfigPageVO deptConfigPageVO) {
|
|
|
|
+ return deptConfigService.getPage(deptConfigPageVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 数据导入
|
|
|
|
+ *
|
|
|
|
+ * @param file
|
|
|
|
+ * @param hospitalIdVO
|
|
|
|
+ */
|
|
|
|
+ public void importExcel(MultipartFile file, HospitalIdVO hospitalIdVO) {
|
|
|
|
+ List<DeptConfig> deptConfigList = ExcelUtils.importExcel(file, 0, 1, DeptConfig.class);
|
|
|
|
+ if (ListUtil.isNotEmpty(deptConfigList)) {
|
|
|
|
+ deptConfigList.forEach(deptConfig -> {
|
|
|
|
+ deptConfig.setHospitalId(hospitalIdVO.getHospitalId());
|
|
|
|
+ });
|
|
|
|
+ saveOrUpdateRecords(deptConfigList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取映射关系-公表名
|
|
|
|
+ *
|
|
|
|
+ * @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<DeptConfig> 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<DeptConfig> records = deptConfigService.list(queryWrapper);
|
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
|
+ return retMap;
|
|
|
|
+ }
|
|
|
|
+ Map<String, List<DeptConfig>> configMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
|
+ for (Map.Entry<String, List<DeptConfig>> 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<DeptConfig> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
|
+ .eq("hospital_id", hospitalIdVO.getHospitalId());
|
|
|
|
+ List<DeptConfig> records = deptConfigService.list(queryWrapper);
|
|
|
|
+ String fileName = "科室映射.xls";
|
|
|
|
+ ExcelUtils.exportExcel(records, null, "sheet1", DeptConfig.class, fileName, response, 12.8f);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 各医院映射关系数列表
|
|
|
|
+ *
|
|
|
|
+ * @param hosRelationNumPageVO
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public IPage<HosRelationNumDTO> getRelationNumPage(HosRelationNumPageVO hosRelationNumPageVO) {
|
|
|
|
+ return deptConfigService.getRelationNumPage(hosRelationNumPageVO);
|
|
|
|
+ }
|
|
|
|
+}
|