|
@@ -1,6 +1,31 @@
|
|
|
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.OperationConfig;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.service.OperationConfigService;
|
|
|
+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.SysUserUtils;
|
|
|
+import com.diagbot.vo.IdListVO;
|
|
|
+import com.diagbot.vo.IdVO;
|
|
|
+import com.diagbot.vo.OperationConfigListVO;
|
|
|
+import com.diagbot.vo.OperationConfigPageVO;
|
|
|
+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 java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description:
|
|
@@ -9,4 +34,228 @@ import org.springframework.stereotype.Component;
|
|
|
*/
|
|
|
@Component
|
|
|
public class OperationConfigFacade {
|
|
|
-}
|
|
|
+ @Autowired
|
|
|
+ private OperationConfigService operationConfigService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否已存在
|
|
|
+ *
|
|
|
+ * @param operationConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean isExistRecord(OperationConfig operationConfig) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ QueryWrapper<OperationConfig> queryWrapper = new QueryWrapper<>();
|
|
|
+ OperationConfig oldRecord = new OperationConfig();
|
|
|
+ if (operationConfig.getId() != null) {
|
|
|
+ oldRecord = operationConfigService.getById(operationConfig.getId());
|
|
|
+ if (oldRecord != null && oldRecord.getIsDeleted().equals(IsDeleteEnum.N.getKey())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(operationConfig.getHisName())) {
|
|
|
+ queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", Long.valueOf(hospitalId))
|
|
|
+ .eq("his_name", operationConfig.getHisName())
|
|
|
+ .eq("unique_name", operationConfig.getUniqueName());
|
|
|
+ oldRecord = operationConfigService.getOne(queryWrapper);
|
|
|
+ if (oldRecord != null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-单条
|
|
|
+ *
|
|
|
+ * @param operationConfig
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecord(OperationConfig operationConfig) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ operationConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ operationConfig.setModifier(userId);
|
|
|
+ operationConfig.setGmtModified(now);
|
|
|
+ //新增数据
|
|
|
+ if (operationConfig.getId() == null) {
|
|
|
+ operationConfig.setCreator(userId);
|
|
|
+ operationConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (operationConfig.getIsDeleted() == null) {
|
|
|
+ operationConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ operationConfigService.saveOrUpdate(operationConfig);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录-批量
|
|
|
+ *
|
|
|
+ * @param operationConfigListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean saveOrUpdateRecords(OperationConfigListVO operationConfigListVO) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ //id为空且已存在的映射关系先删除
|
|
|
+ List<Long> deleteIds = Lists.newLinkedList();
|
|
|
+ Map<String, Map<String, Long>> configMap
|
|
|
+ = getConfigMap(Long.valueOf(hospitalId), null, null);
|
|
|
+ if (ListUtil.isNotEmpty(operationConfigListVO.getOperationConfigList())) {
|
|
|
+ operationConfigListVO.getOperationConfigList().forEach(operationConfig -> {
|
|
|
+ operationConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ operationConfig.setModifier(userId);
|
|
|
+ operationConfig.setGmtModified(now);
|
|
|
+ if (operationConfig.getId() == null) {
|
|
|
+ if (configMap.get(operationConfig.getHisName()) != null
|
|
|
+ && configMap.get(operationConfig.getHisName()).containsKey(operationConfig.getUniqueName())) {
|
|
|
+ deleteIds.add(configMap.get(operationConfig.getHisName()).get(operationConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ operationConfig.setCreator(userId);
|
|
|
+ operationConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ if (operationConfig.getIsDeleted() == null) {
|
|
|
+ operationConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ }
|
|
|
+ //数据不完整的不保存
|
|
|
+ List<OperationConfig> records = operationConfigListVO.getOperationConfigList()
|
|
|
+ .stream()
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ operationConfigService.saveOrUpdateBatch(records);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-单条
|
|
|
+ *
|
|
|
+ * @param idVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecord(IdVO idVO) {
|
|
|
+ UpdateWrapper<OperationConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", idVO.getId())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ operationConfigService.update(updateWrapper);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除记录-批量
|
|
|
+ *
|
|
|
+ * @param idListVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean deleteRecords(IdListVO idListVO) {
|
|
|
+ if (ListUtil.isEmpty(idListVO.getIds())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ UpdateWrapper<OperationConfig> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.in("id", idListVO.getIds())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey());
|
|
|
+ operationConfigService.update(updateWrapper);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param operationConfigPageVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<OperationConfig> getPage(OperationConfigPageVO operationConfigPageVO) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ operationConfigPageVO.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ return operationConfigService.getPage(operationConfigPageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 化验数据导入
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ */
|
|
|
+ public void importExcel(MultipartFile file) {
|
|
|
+ String hospitalId = SysUserUtils.getCurrentHospitalID();
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ List<OperationConfig> operationConfigList = ExcelUtils.importExcel(file, 0, 1, OperationConfig.class);
|
|
|
+ if (ListUtil.isNotEmpty(operationConfigList)) {
|
|
|
+ //过滤不完整数据
|
|
|
+ operationConfigList = operationConfigList
|
|
|
+ .stream()
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getHisName()))
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getUniqueName()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //验证数据是否已存在
|
|
|
+ List<Long> deleteIds = Lists.newArrayList();
|
|
|
+ Map<String, Map<String, Long>> configMap = getConfigMap(Long.valueOf(hospitalId), null, null);
|
|
|
+ operationConfigList.forEach(operationConfig -> {
|
|
|
+ if (configMap.get(operationConfig.getHisName()) != null
|
|
|
+ && configMap.get(operationConfig.getHisName()).containsKey(operationConfig.getUniqueName())) {
|
|
|
+ deleteIds.add(configMap.get(operationConfig.getHisName()).get(operationConfig.getUniqueName()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //删除已存在的映射关系
|
|
|
+ if (ListUtil.isNotEmpty(deleteIds)) {
|
|
|
+ IdListVO idListVO = new IdListVO();
|
|
|
+ idListVO.setIds(deleteIds);
|
|
|
+ deleteRecords(idListVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存数据
|
|
|
+ operationConfigList.forEach(operationConfig -> {
|
|
|
+ operationConfig.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
+ operationConfig.setHospitalId(Long.valueOf(hospitalId));
|
|
|
+ if (operationConfig.getId() == null) {
|
|
|
+ operationConfig.setCreator(userId);
|
|
|
+ operationConfig.setGmtCreate(now);
|
|
|
+ }
|
|
|
+ operationConfig.setModifier(userId);
|
|
|
+ operationConfig.setGmtModified(now);
|
|
|
+ });
|
|
|
+ operationConfigService.saveOrUpdateBatch(operationConfigList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取映射关系-公表名
|
|
|
+ *
|
|
|
+ * @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<OperationConfig> 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<OperationConfig> records = operationConfigService.list(queryWrapper);
|
|
|
+ if (ListUtil.isEmpty(records)) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, List<OperationConfig>> configMap = EntityUtil.makeEntityListMap(records, "hisName");
|
|
|
+ for (Map.Entry<String, List<OperationConfig>> entry : configMap.entrySet()) {
|
|
|
+ if (ListUtil.isNotEmpty(entry.getValue())) {
|
|
|
+ retMap.put(entry.getKey(), EntityUtil.makeMapWithKeyValue(entry.getValue(), "uniqueName", "id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+}
|