|
@@ -1,24 +1,39 @@
|
|
|
package com.lantone.daqe.facade;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.lantone.common.api.CommonResult;
|
|
|
import com.lantone.common.exception.Asserts;
|
|
|
import com.lantone.common.util.BeanUtil;
|
|
|
+import com.lantone.common.util.ListUtil;
|
|
|
import com.lantone.common.util.StringUtil;
|
|
|
+import com.lantone.daqe.dto.ExportImportDrugErrDTO;
|
|
|
import com.lantone.daqe.dto.GetDrugPageDTO;
|
|
|
import com.lantone.daqe.entity.DrugInfo;
|
|
|
+import com.lantone.daqe.entity.OperationInfo;
|
|
|
import com.lantone.daqe.facade.base.DrugInfoFacade;
|
|
|
+import com.lantone.daqe.service.impl.DrugInfoServiceImpl;
|
|
|
+import com.lantone.daqe.util.ExcelUtils;
|
|
|
import com.lantone.daqe.vo.AddDrugVO;
|
|
|
import com.lantone.daqe.vo.DelDrugByIdVO;
|
|
|
import com.lantone.daqe.vo.GetDrugPageVO;
|
|
|
+import com.lantone.daqe.vo.ImportDrugVO;
|
|
|
import com.lantone.daqe.vo.MatchingDrugVO;
|
|
|
import com.lantone.daqe.vo.UpDrugByIdVO;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
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.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 药品管理-业务处理类
|
|
@@ -31,6 +46,9 @@ public class DrugManagementFacade {
|
|
|
@Autowired
|
|
|
private DrugInfoFacade drugInfoFacade;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DrugInfoServiceImpl drugInfoServiceImpl;
|
|
|
+
|
|
|
public IPage<GetDrugPageDTO> getDrugPage(GetDrugPageVO getDrugPageVO) {
|
|
|
Page<GetDrugPageDTO> getDrugPageDTOPage = new Page<>();
|
|
|
|
|
@@ -104,6 +122,8 @@ public class DrugManagementFacade {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 匹配药品信息
|
|
|
+ *
|
|
|
* @param matchingDrugVO
|
|
|
* @Return java.lang.Boolean
|
|
|
*/
|
|
@@ -111,6 +131,80 @@ public class DrugManagementFacade {
|
|
|
|
|
|
DrugInfo drugInfo = new DrugInfo();
|
|
|
BeanUtils.copyProperties(matchingDrugVO, drugInfo);
|
|
|
+ drugInfo.setStandard(matchingDrugVO.getStandard() + "_" + matchingDrugVO.getForm());
|
|
|
return drugInfoFacade.updateById(drugInfo);
|
|
|
}
|
|
|
+
|
|
|
+ public void importDrug(HttpServletResponse response, MultipartFile file) {
|
|
|
+ List<ImportDrugVO> operationExcelVOS = ExcelUtils.importExcel(file, 0, 1, ImportDrugVO.class);
|
|
|
+ if (ListUtil.isEmpty(operationExcelVOS)) {
|
|
|
+ Asserts.fail("Excel文件为空");
|
|
|
+ }
|
|
|
+ //数据规范校验
|
|
|
+ List<ExportImportDrugErrDTO> errExports = new ArrayList<>();
|
|
|
+ if (checkData(operationExcelVOS, errExports)) {
|
|
|
+ String fileName = "药品匹配信息导入异常.xls";
|
|
|
+ ExcelUtils.exportExcelUser(errExports, null, "sheet1", ExportImportDrugErrDTO.class, fileName, response);
|
|
|
+ } else {
|
|
|
+ //去重
|
|
|
+ List<ImportDrugVO> temp = delRepeat(operationExcelVOS);
|
|
|
+ List<DrugInfo> insert = new ArrayList<>();
|
|
|
+ //导入数据转换
|
|
|
+ temp.stream().forEach(importDrugVO -> {
|
|
|
+ DrugInfo drugInfo = new DrugInfo();
|
|
|
+ BeanUtils.copyProperties(importDrugVO,drugInfo);
|
|
|
+ drugInfo.setStandard(importDrugVO.getStandard()+"_"+importDrugVO.getForm());
|
|
|
+ });
|
|
|
+ boolean out = drugInfoServiceImpl.saveBatch(insert);
|
|
|
+ CommonResult<String> outMsg = null;
|
|
|
+ response.setContentType("text/html;charset=utf-8");
|
|
|
+ if (out) {
|
|
|
+ outMsg = CommonResult.success(String.format("模板成功导入%s条数据", insert.size()));
|
|
|
+ try {
|
|
|
+ response.getWriter().println(JSONObject.toJSONString(outMsg));
|
|
|
+ response.flushBuffer();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Asserts.fail("数据插入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据校验
|
|
|
+ *
|
|
|
+ * @param importDrugVOS 导入数据
|
|
|
+ * @param errExports 导出异常i
|
|
|
+ * @Return java.lang.Boolean
|
|
|
+ */
|
|
|
+ private Boolean checkData(List<ImportDrugVO> importDrugVOS, List<ExportImportDrugErrDTO> errExports) {
|
|
|
+ AtomicBoolean errorFlog = new AtomicBoolean(false);
|
|
|
+ importDrugVOS.stream().forEach(importDrugVO -> {
|
|
|
+ ExportImportDrugErrDTO exportImportDrugErrDTO = new ExportImportDrugErrDTO();
|
|
|
+ BeanUtil.copyProperties(importDrugVO, exportImportDrugErrDTO);
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ //数据校验
|
|
|
+ if (StringUtil.isEmpty(importDrugVO.getName())) {
|
|
|
+ errMsg.append("医院手术/操作名称为空").append(";");
|
|
|
+ errorFlog.set(true);
|
|
|
+ }
|
|
|
+ if (StringUtil.isEmpty(importDrugVO.getStandard())) {
|
|
|
+ errMsg.append("标准手术/操作名称为空").append(";");
|
|
|
+ errorFlog.set(true);
|
|
|
+ }
|
|
|
+ exportImportDrugErrDTO.setErrMsg(errMsg.toString());
|
|
|
+ errExports.add(exportImportDrugErrDTO);
|
|
|
+ });
|
|
|
+ return errorFlog.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ImportDrugVO> delRepeat(List<ImportDrugVO> importDrugVOS) {
|
|
|
+ //通过标准词去重
|
|
|
+ LinkedHashMap<String, ImportDrugVO> tempMap = importDrugVOS.stream()
|
|
|
+ .collect(Collectors.toMap(ImportDrugVO::getName, ImportDrugVO -> ImportDrugVO, (k1, k2) -> k1, LinkedHashMap::new));
|
|
|
+ return tempMap.values().stream().collect(Collectors.toList());
|
|
|
+ }
|
|
|
}
|