Sfoglia il codice sorgente

Merge branch 'master' into 'master'

药品计划导入提示优化

See merge request lighter/web-server!146
huangshuhua 2 mesi fa
parent
commit
a308307690

+ 44 - 47
src/main/java/thyyxxk/webserver/service/medicine/YpPlanService.java

@@ -108,7 +108,11 @@ public class YpPlanService {
         MultipartFile file = info.getFile();
         try {
             // 解析导入的数据
-            List<YpPlanDetail> list = callYpPlanImportData(fileId, file, ny);
+            List<YpPlanDetail> list = new ArrayList<>();
+            String str = callYpPlanImportData(list, fileId, file, ny);
+            if(!"0".equals(str)){
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, str);
+            }
             if(list.isEmpty()){
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "导入药品申请与审核药品明细为空,请确认!");
             }
@@ -128,6 +132,11 @@ public class YpPlanService {
             info.setApplyId(user.getCode());
             info.setApplyName(user.getName());
             int c = callSavePlanDetail(info, list);
+            if(c > 0){
+                map.put("msg", "导入药品计划成功!");
+            } else {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "导入药品计划明细存储出错!");
+            }
         } catch (IOException e) {
             log.info("导入药品计划出错:" + e.getMessage());
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "导入药品计划出错:" + e.getMessage());
@@ -137,37 +146,20 @@ public class YpPlanService {
 
     private static final int BATCH_SIZE = 80;
 
-    private int callSavePlanDetail(YpPlanInfo info, List<YpPlanDetail> list) {
-        YpPlanInfo info1 = infoDao.selectYpPlanInfoById(info.getFileId());
-        if (null != info1) {
-            infoDao.deleteYpPlanInfoById(info.getFileId());
-        }
-        infoDao.insert(info);
-        List<YpPlanDetail> listLs = detailDao.selectYpPlanDetailById(info.getFileId());
-        if (null != listLs && !listLs.isEmpty()) {
-            detailDao.deleteYpPlanDetailById(info.getFileId());
-        }
-        return countNum(list);
-    }
-
     /**
      * @Description 药品计划导入数据excel解析
      * @Author hsh
+     * @param impList 导入接收数据
      * @param fileId 文件id
      * @param file 文件
      * @param ny 年月
      * @return list
      * @Date 2025/2/21 16:19
      */
-    public List<YpPlanDetail> callYpPlanImportData(String fileId, MultipartFile file, String ny) throws IOException {
-        InputStream is = null;
+    private String callYpPlanImportData(List<YpPlanDetail> impList, String fileId, MultipartFile file, String ny) throws IOException {
         Workbook workbook;
-        // 导入数据接收list
-        List<YpPlanDetail> impList = new ArrayList<>();
         StringBuilder str = new StringBuilder();
-
-        try {
-            is = file.getInputStream();
+        try (InputStream is = file.getInputStream()) {
             workbook = WorkbookFactory.create(is);
             // 获取第一个活页数据
             Sheet sheet = workbook.getSheetAt(0);
@@ -176,21 +168,18 @@ public class YpPlanService {
             for (int i = rowStart; i <= sheet.getLastRowNum(); i++) {
                 Row row = sheet.getRow(i);
                 // 第二个药品名称必填
-                if(null == row.getCell(1) || StringUtil.isBlank(row.getCell(1).getStringCellValue())){
+                if (null == row.getCell(1) || StringUtil.isBlank(row.getCell(1).getStringCellValue())) {
                     continue;
                 }
                 // 获取行所有单元格数据
                 int colNum = row.getPhysicalNumberOfCells();
                 int j = 0;
-                while(j < colNum){
+                while (j < colNum) {
                     str.append(getCellStringVal(row.getCell(j)).trim()).append("_");
-                    j ++;
+                    j++;
                 }
                 YpPlanDetail imp = new YpPlanDetail();
                 String[] stirs = str.toString().split("_");
-                if("硫酸氢氯吡格雷片(波立维)".equals(stirs[2])){
-                    log.info("硫酸氢氯吡格雷片(波立维)购入价: " + new BigDecimal(stirs[5]));
-                }
                 imp.setRemark(stirs[0]);
                 imp.setSupplyName(stirs[1]);
                 imp.setChargeCode(stirs[2]);
@@ -198,43 +187,43 @@ public class YpPlanService {
                 imp.setSpecification(stirs[4]);
                 imp.setDrugKind(stirs[5]);
                 imp.setIsWinning(stirs[6]);
-                if(StringUtil.notBlank(stirs[7])){
+                if (StringUtil.notBlank(stirs[7])) {
                     imp.setPackRetprice(new BigDecimal(stirs[7]));
                     imp.setPackRetprice1(stirs[7]);
                 }
-                if(StringUtil.notBlank(stirs[8])){
+                if (StringUtil.notBlank(stirs[8])) {
                     imp.setBuyPrice(new BigDecimal(stirs[8]));
                     imp.setBuyPrice1(stirs[8]);
                 }
-                if(StringUtil.notBlank(stirs[9])){
+                if (StringUtil.notBlank(stirs[9])) {
                     imp.setAmount(new BigDecimal(stirs[9]));
                 }
                 imp.setManuName(stirs[10]);
-                if(StringUtil.notBlank(stirs[11])){
+                if (StringUtil.notBlank(stirs[11])) {
                     imp.setAmount3(new BigDecimal(stirs[11]));
                 }
-                if(StringUtil.notBlank(stirs[12])){
+                if (StringUtil.notBlank(stirs[12])) {
                     imp.setAmount7(new BigDecimal(stirs[12]));
                 }
-                if(StringUtil.notBlank(stirs[13])){
+                if (StringUtil.notBlank(stirs[13])) {
                     imp.setAmount14(new BigDecimal(stirs[13]));
                 }
-                if(StringUtil.notBlank(stirs[14])){
+                if (StringUtil.notBlank(stirs[14])) {
                     imp.setAmount30(new BigDecimal(stirs[14]));
                 }
-                if(StringUtil.notBlank(stirs[15])){
+                if (StringUtil.notBlank(stirs[15])) {
                     imp.setAmount60(new BigDecimal(stirs[15]));
                 }
                 imp.setDays(stirs[16]);
-                if(StringUtil.notBlank(stirs[17])){
+                if (StringUtil.notBlank(stirs[17])) {
                     imp.setBuyAmount(new BigDecimal(stirs[17]));
                 }
                 // 单位
-                if(stirs.length >= 19 && StringUtil.notBlank(stirs[18])){
+                if (stirs.length >= 19 && StringUtil.notBlank(stirs[18])) {
                     imp.setUnit(stirs[18]);
                 }
                 // 购入价金额
-                if(null == imp.getBuyPrice() || null == imp.getBuyAmount()){
+                if (null == imp.getBuyPrice() || null == imp.getBuyAmount()) {
                     imp.setBuyFee(BigDecimal.ZERO);
                     imp.setBuyMoney(BigDecimal.ZERO);
                 } else {
@@ -242,7 +231,7 @@ public class YpPlanService {
                     imp.setBuyMoney(DecimalUtil.multiply(imp.getBuyPrice(), imp.getBuyAmount()));
                 }
                 // 主任意见
-                if(stirs.length == 21 && StringUtil.notBlank(stirs[20])){
+                if (stirs.length == 21 && StringUtil.notBlank(stirs[20])) {
                     imp.setContent(stirs[20]);
                 }
                 imp.setFileId(fileId);
@@ -255,17 +244,25 @@ public class YpPlanService {
                 str = new StringBuilder();
             }
             workbook.close();
-            is.close();
         } catch (Exception e) {
-            log.info("导入药品计划出错:" + e.getMessage());
-            ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "药品计划导入失败!" + e.getMessage());
-        } finally {
-            if(is != null){
-                is.close();
-            }
+            log.info("药品计划导入解析excel出错:" + e.getMessage());
+            return "药品计划导入解析excel出错!";
         }
 
-        return impList;
+        return "0";
+    }
+
+    private int callSavePlanDetail(YpPlanInfo info, List<YpPlanDetail> list) {
+        YpPlanInfo info1 = infoDao.selectYpPlanInfoById(info.getFileId());
+        if (null != info1) {
+            infoDao.deleteYpPlanInfoById(info.getFileId());
+        }
+        infoDao.insert(info);
+        List<YpPlanDetail> listLs = detailDao.selectYpPlanDetailById(info.getFileId());
+        if (null != listLs && !listLs.isEmpty()) {
+            detailDao.deleteYpPlanDetailById(info.getFileId());
+        }
+        return countNum(list);
     }
 
     private String getCellStringVal(Cell cell) {