Bladeren bron

Merge remote-tracking branch 'origin/dev/staticImport_20220518' into test

zhaops 3 jaren geleden
bovenliggende
commit
531f0c7896

File diff suppressed because it is too large
+ 45 - 0
cdssman-service/src/main/java/com/diagbot/entity/StaticExcel.java


+ 26 - 0
cdssman-service/src/main/java/com/diagbot/entity/wrapper/StaticExcelWrapper.java

@@ -0,0 +1,26 @@
+package com.diagbot.entity.wrapper;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import com.diagbot.entity.StaticExcel;
+import com.diagbot.util.StringUtil;
+import lombok.Data;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2022/5/18 15:18
+ */
+@Data
+public class StaticExcelWrapper extends StaticExcel {
+    @Excel(name = "错误原因", width = 40, orderNum = "100", isImportField = "true")
+    private String message;
+
+    private Integer correct = 1;
+
+    public static boolean nonNull(StaticExcelWrapper o) {
+        return !(o == null
+                || (StringUtil.isBlank(o.message)
+                && o.correct == null))
+                || StaticExcel.nonNull(o);
+    }
+}

+ 225 - 0
cdssman-service/src/main/java/com/diagbot/facade/StaticImportFacade.java

@@ -0,0 +1,225 @@
+package com.diagbot.facade;
+
+import cn.afterturn.easypoi.exception.excel.ExcelImportException;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.diagbot.entity.KlConcept;
+import com.diagbot.entity.KlConceptDetail;
+import com.diagbot.entity.KlConceptStatic;
+import com.diagbot.entity.StaticExcel;
+import com.diagbot.entity.wrapper.StaticExcelWrapper;
+import com.diagbot.enums.IsDeleteEnum;
+import com.diagbot.enums.StatusEnum;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
+import com.diagbot.service.KlConceptDetailService;
+import com.diagbot.util.BeanUtil;
+import com.diagbot.util.ExcelUtils;
+import com.diagbot.util.ListUtil;
+import com.diagbot.util.UserUtils;
+import org.apache.commons.compress.utils.Lists;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+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: 2022/5/18 14:42
+ */
+@Component
+public class StaticImportFacade {
+    @Autowired
+    private KlConceptFacade klConceptFacade;
+    @Autowired
+    private KlConceptStaticFacade klConceptStaticFacade;
+    @Qualifier("klConceptDetailServiceImpl")
+    @Autowired
+    private KlConceptDetailService klConceptDetailService;
+
+    /**
+     * 导入模板下载
+     *
+     * @param response
+     */
+    public void exportExcelModule(HttpServletResponse response) {
+        String fileName = "静态知识导入模板.xls";
+        ExcelUtils.exportExcel(Lists.newArrayList(), null, "sheet1", StaticExcel.class, fileName, response, 12.8f);
+    }
+
+    /**
+     * 导出文件标题
+     *
+     * @return
+     */
+    public String getTitle() {
+        String title = "说明\n" +
+                "类型:100-疾病、101-药品通用名、106-手术和操作、107-实验室检查套餐、108-实验室检查子项目、109-辅助检查项目、110-辅助检查子项目、124-量表、123-护理、130-政策法规;\n" +
+                "内容类型:1-静态信息,2-注意事项,3-临床路径,4-治疗方案;";
+        return title;
+    }
+
+    /**
+     * 实体批量导入
+     *
+     * @param response
+     * @param file
+     */
+    public void importExcel(HttpServletResponse response, MultipartFile file) {
+        String userId = UserUtils.getCurrentPrincipleID();
+        List<StaticExcel> originList = readImportData(file);
+        if (ListUtil.isEmpty(originList)) {
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "模板内容为空,请填写后导入!");
+        } else {
+            List<StaticExcelWrapper> list = importDataProcess(originList, userId);
+            List<StaticExcelWrapper> insertList = list.stream().filter(i -> i.getCorrect().equals(1)).collect(Collectors.toList());
+            List<StaticExcelWrapper> errorList = list.stream().filter(i -> i.getCorrect().equals(0)).collect(Collectors.toList());
+            String fileName = "静态知识导入结果.xls";
+            Map<String, Map<Class<?>, List<?>>> map = new HashMap<>();
+            Map<Class<?>, List<?>> errorMap = new HashMap<Class<?>, List<?>>();
+            errorMap.put(StaticExcelWrapper.class, errorList);
+            map.put("导入失败数据", errorMap);
+            Map<Class<?>, List<?>> successMap = new HashMap<Class<?>, List<?>>();
+            successMap.put(StaticExcelWrapper.class, insertList);
+            map.put("导入成功数据", successMap);
+            ExcelUtils.exportExcel(map, null, fileName, response);
+        }
+    }
+
+
+    /**
+     * 读取导入数据
+     *
+     * @param file
+     * @return
+     */
+    public List<StaticExcel> readImportData(MultipartFile file) {
+        List<StaticExcel> originList = Lists.newArrayList();
+        String fileName = file.getOriginalFilename();
+        //是否Excel文件?
+        if (!(fileName.endsWith(".xls") || fileName.endsWith(".xlsx"))) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "校验失败,请根据模板进行数据导入");
+        }
+        try {
+            originList = ExcelUtils.importExcel(file, 0, 1, StaticExcel.class);
+        } catch (ExcelImportException e) {
+
+        } catch (CommonException e) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "校验失败,请根据模板进行数据导入");
+        } catch (Exception e) {
+
+        }
+        return originList;
+    }
+
+    /**
+     * 导入数据处理
+     *
+     * @param originList
+     * @return
+     */
+    public List<StaticExcelWrapper> importDataProcess(List<StaticExcel> originList, String userId) {
+        List<StaticExcelWrapper> retList = Lists.newArrayList();
+        if (ListUtil.isEmpty(originList)) {
+            return retList;
+        }
+
+        List<StaticExcelWrapper> list = Lists.newArrayList();
+        list = BeanUtil.listCopyTo(originList, StaticExcelWrapper.class);
+
+        //删除空行
+        list = list.stream()
+                .filter(StaticExcelWrapper::nonNull)
+                .collect(Collectors.toList());
+
+        List<String> nameAndTypeList = list.stream()
+                .map(i -> i.getName() + "_" + i.getType())
+                .distinct()
+                .collect(Collectors.toList());
+        List<KlConcept> conceptList = klConceptFacade.list(new QueryWrapper<KlConcept>()
+                .eq("is_deleted", IsDeleteEnum.N.getKey())
+                .eq("status", StatusEnum.Enable.getKey())
+                .in("concat(lib_name,'_',lib_type)", nameAndTypeList));
+        Map<String, Long> nameAndTypeMap_exist = new HashMap<>();
+        List<Long> conceptIdList = Lists.newArrayList();
+        if (ListUtil.isNotEmpty(conceptList)) {
+            nameAndTypeMap_exist = conceptList.stream()
+                    .collect(Collectors.toMap(k -> k.getLibName() + "_" + k.getLibType(), v -> v.getId()));
+            conceptIdList = conceptList.stream().map(KlConcept::getId).collect(Collectors.toList());
+        }
+        //校验标准词是否存在
+        for (StaticExcelWrapper item : list) {
+            String nameAndType = item.getName() + "_" + item.getType();
+            if (!nameAndTypeMap_exist.containsKey(nameAndType)) {
+                item.setCorrect(0);
+                item.setMessage("标准词不存在或已禁用");
+            } else {
+                item.setConceptId(nameAndTypeMap_exist.get(nameAndType));
+            }
+        }
+        //标准词校验失败
+        if (ListUtil.isEmpty(conceptList)) {
+            return list;
+        }
+
+        //校验静态知识是否已存在
+        List<KlConceptStatic> staticList_exist = klConceptStaticFacade.list(new QueryWrapper<KlConceptStatic>()
+                .eq("is_deleted", IsDeleteEnum.N.getKey())
+                .in("concept_id", conceptIdList));
+        List<Long> staticConceptIdList = Lists.newArrayList();
+        if (ListUtil.isNotEmpty(staticList_exist)) {
+            staticConceptIdList = staticList_exist.stream()
+                    .map(KlConceptStatic::getConceptId)
+                    .distinct().collect(Collectors.toList());
+        }
+
+        for (StaticExcelWrapper item : list) {
+            if (item.getCorrect().equals(0)) {
+                continue;
+            }
+            if (staticConceptIdList.contains(item.getConceptId())) {
+                item.setCorrect(0);
+                item.setMessage("该术语关联静态知识已维护或已禁用");
+            }
+        }
+
+        List<StaticExcelWrapper> insertList = list.stream().filter(i -> i.getCorrect().equals(1)).collect(Collectors.toList());
+
+        //保存数据(新增)
+        Date now = new Date();
+        Map<Long, List<StaticExcelWrapper>> insertMap = insertList.stream().collect(Collectors.groupingBy(StaticExcelWrapper::getConceptId));
+        for (Map.Entry<Long, List<StaticExcelWrapper>> entry : insertMap.entrySet()) {
+            KlConceptStatic klConceptStatic = new KlConceptStatic();
+            if (ListUtil.isEmpty(entry.getValue())) {
+                continue;
+            }
+            BeanUtils.copyProperties(entry.getValue().get(0), klConceptStatic);
+            klConceptStatic.setGmtCreate(now);
+            klConceptStatic.setCreator(userId);
+            klConceptStatic.setGmtModified(now);
+            klConceptStatic.setModifier(userId);
+            klConceptStaticFacade.saveOrUpdate(klConceptStatic);
+
+            List<KlConceptDetail> detailList = Lists.newArrayList();
+            detailList = BeanUtil.listCopyTo(entry.getValue(), KlConceptDetail.class);
+            for (KlConceptDetail klConceptDetail : detailList) {
+                klConceptDetail.setConceptId(klConceptStatic.getConceptId());
+                klConceptDetail.setGmtCreate(now);
+                klConceptDetail.setCreator(userId);
+                klConceptDetail.setGmtModified(now);
+                klConceptDetail.setModifier(userId);
+            }
+            klConceptDetailService.saveBatch(detailList);
+        }
+
+        return list;
+    }
+}

+ 23 - 1
cdssman-service/src/main/java/com/diagbot/web/ConceptInfoController.java

@@ -7,6 +7,7 @@ import com.diagbot.dto.KlConceptStaticDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.dto.StaticKnowledgeIndexDTO;
 import com.diagbot.facade.KlConceptStaticFacade;
+import com.diagbot.facade.StaticImportFacade;
 import com.diagbot.vo.ChangeStatusVO;
 import com.diagbot.vo.IdVO;
 import com.diagbot.vo.KlConceptStaticPageVO;
@@ -19,8 +20,11 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.util.List;
 
@@ -40,6 +44,8 @@ public class ConceptInfoController {
 
     @Autowired
     private KlConceptStaticFacade klConceptStaticFacade;
+    @Autowired
+    private StaticImportFacade staticImportFacade;
 
     @ApiOperation(value = "医学术语检索-新增静态知识[zhaops]",
             notes = "types: 类型(多选):0-全部、1-诊断、2-药品、3-检验、5-检查、6-手术和操作、8-量表、9-护理、10-政策法规 <br>" +
@@ -120,4 +126,20 @@ public class ConceptInfoController {
         KlConceptStaticDTO data = klConceptStaticFacade.getRecordById(idVO);
         return RespDTO.onSuc(data);
     }
-}
+
+    @ApiOperation(value = "数据导入模板导出[by:zhaops]",
+            notes = "")
+    @PostMapping("/exportExcelModule")
+    @SysLogger("exportExcelModule")
+    public void exportExcelModule(HttpServletResponse response) {
+        staticImportFacade.exportExcelModule(response);
+    }
+
+    @ApiOperation(value = "静态知识导入[zhaops]",
+            notes = "")
+    @PostMapping("/importExcel")
+    @SysLogger("importExcel")
+    public void importExcel(HttpServletResponse response, @RequestParam("file") MultipartFile file) {
+        staticImportFacade.importExcel(response, file);
+    }
+}