瀏覽代碼

化验导入修改提示语

wangfeng 5 年之前
父節點
當前提交
c2445698e1
共有 1 個文件被更改,包括 250 次插入250 次删除
  1. 250 250
      icss-service/src/main/java/com/diagbot/facade/LisExcelResFacade.java

+ 250 - 250
icss-service/src/main/java/com/diagbot/facade/LisExcelResFacade.java

@@ -1,250 +1,250 @@
-package com.diagbot.facade;
-
-import com.diagbot.client.TranServiceClient;
-import com.diagbot.dto.LisConfigDTO;
-import com.diagbot.dto.RespDTO;
-import com.diagbot.exception.CommonErrorCode;
-import com.diagbot.exception.CommonException;
-import com.diagbot.util.ListUtil;
-import com.diagbot.util.StringUtil;
-import com.diagbot.vo.LisExcelResVO;
-import com.diagbot.vo.LisExcelWrapperVO;
-import com.diagbot.vo.LisHospitalCodeVO;
-import com.diagbot.vo.LitAssayVO;
-import org.apache.commons.lang.time.DateFormatUtils;
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.servlet.http.HttpServletRequest;
-import java.io.InputStream;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * @author wangfeng
- * @Description: 化验导入
- * @date 2018年11月29日 上午10:16:35
- */
-@Component
-public class LisExcelResFacade {
-
-    /*@Autowired
-    LisConfigFacade lisConfigFacade;*/
-    @Autowired
-    TranServiceClient tranServiceClient;
-
-    @SuppressWarnings("null")
-    public RespDTO<LitAssayVO> lisExcelAnalysis(MultipartFile file, LisHospitalCodeVO lisHospitalCodeVO, HttpServletRequest request) {
-
-        List<String> messages = new ArrayList<>();
-        List<LisExcelWrapperVO> lisExcelWrapperList = new ArrayList<>();
-        InputStream inputStream = null;
-        List<String> assemblys = new ArrayList<String>();
-        Workbook wb = null;
-        try {
-            if (!file.isEmpty()) {
-                inputStream = file.getInputStream();
-                if (inputStream.available() > 512000) {
-                    messages.add("化验文件最大支持500KB!");
-                } else {
-                    String fileName = file.getOriginalFilename();
-                    if (fileName.lastIndexOf(".") != -1) {
-                        String type = fileName.substring(fileName.lastIndexOf("."));
-                        if (type.equals(".xls")) {
-                            wb = new HSSFWorkbook(inputStream);
-                        } else if (type.equals(".xlsx")) {
-                            wb = new XSSFWorkbook(inputStream);
-                        }
-                        if (wb != null) {
-                            Sheet sheet = wb.getSheetAt(0);
-                            int count = 0;
-                            String mealName, itemName, unit, value, max, min, time;
-                            for (Row row : sheet) {
-                                count++;
-                                try {
-                                    if (row != null) {
-                                        mealName = getValue(row.getCell(0)).trim().replace(" ", "");
-                                        itemName = getValue(row.getCell(1)).trim().replace(" ", "");
-                                        unit = getValue(row.getCell(2)).trim();
-                                        value = getValue(row.getCell(3)).trim();
-                                        min = getValue(row.getCell(4)).trim();
-                                        max = getValue(row.getCell(5)).trim();
-                                        time = getValue(row.getCell(6)).trim();
-                                        type = getValue(row.getCell(7)).trim();
-                                    } else {
-                                        mealName = null;
-                                        itemName = null;
-                                        unit = null;
-                                        value = null;
-                                        min = null;
-                                        max = null;
-                                        time = null;
-                                        type = null;
-                                    }
-
-                                    if (StringUtil.isEmpty(mealName) && StringUtil.isEmpty(itemName)
-                                            && StringUtil.isEmpty(value) && StringUtil.isEmpty(type)) {
-                                        continue;
-                                    }
-
-                                    if (count == 1 && mealName.equals("套餐名")) {
-                                        continue;
-                                    }
-
-                                    if (StringUtil.isEmpty(mealName) || StringUtil.isEmpty(itemName)
-                                            || StringUtil.isEmpty(value) || StringUtil.isEmpty(type)) {
-                                        messages.add("第" + count + "行数据不规范,套餐名、项目名、结果、是否异常四项必填;");
-                                        continue;
-                                    }
-                                    LisExcelWrapperVO lisExcelWrapper = new LisExcelWrapperVO();
-
-
-                                    lisExcelWrapper.setMealName(mealName);
-                                    lisExcelWrapper.setItemName(itemName);
-                                    String assembly = mealName + "--";
-                                    if (!assemblys.contains(assembly)) {
-                                        assemblys.add(assembly);
-                                    }
-                                    assembly = mealName + "--" + itemName;
-                                    if (!assemblys.contains(assembly)) {
-                                        assemblys.add(assembly);
-                                    }
-                                    //  lisExcelWrapper.setUniqueName(uniqueName);
-                                    lisExcelWrapper.setUnit(unit);
-                                    lisExcelWrapper.setValue(value);
-                                    lisExcelWrapper.setMax(max);
-                                    lisExcelWrapper.setMin(min);
-                                    lisExcelWrapper.setTime(time);
-                                    lisExcelWrapper.setType(type);
-                                    lisExcelWrapperList.add(lisExcelWrapper);
-                                } catch (Exception e) {
-                                    e.printStackTrace();
-                                    throw new CommonException(CommonErrorCode.NOT_EXISTS, e.toString());
-                                    // logger.error("",e);
-                                }
-                            }
-                        } else {
-                            // throw new
-                            // CommonException(CommonErrorCode.NOT_EXISTS,
-                            // "非excel文件无法解析!");
-                            messages.add("非excel文件无法解析!");
-                        }
-                    } else {
-                        // throw new CommonException(CommonErrorCode.NOT_EXISTS,
-                        // "未知文件无法解析!");
-                        messages.add("未知文件无法解析!");
-                    }
-                }
-            } else {
-                // throw new CommonException(CommonErrorCode.NOT_EXISTS,
-                // "无文件上传!");
-                messages.add("无文件上传!");
-            }
-            //匹配公表名
-            lisHospitalCodeVO.setAssemblys(assemblys);
-            RespDTO<List<LisConfigDTO>> litDatas = tranServiceClient.getLisConfigByhospitalId(lisHospitalCodeVO);
-            if (litDatas == null || !"0".equals(litDatas.code)) {
-                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
-                        "获取匹配公表名信息失败");
-            }
-            List<LisConfigDTO> litData = litDatas.data;
-
-            //导入的数据跟公表数据进行配对
-            if (ListUtil.isNotEmpty(litData)) {
-                Map<String, String> listMap = litData.stream()
-                        .collect(Collectors.toMap(LisConfigDTO::getAssembly, LisConfigDTO::getUniqueName));
-                List<LisExcelWrapperVO> lisExcelWrapperListNew = new ArrayList<>();
-                for (LisExcelWrapperVO lisExcelWrapperNew : lisExcelWrapperList) {
-                    String assemblymeal = lisExcelWrapperNew.getMealName() + "--";
-                    if (null != listMap.get(assemblymeal)) {
-                        lisExcelWrapperNew.setUniquemealName(listMap.get(assemblymeal));
-                    }
-                    String item = lisExcelWrapperNew.getMealName() + "--" + lisExcelWrapperNew.getItemName();
-                    if (null != listMap.get(item)) {
-                        lisExcelWrapperNew.setUniqueName(listMap.get(item));
-                    }
-                    lisExcelWrapperListNew.add(lisExcelWrapperNew);
-                }
-                lisExcelWrapperList = lisExcelWrapperListNew;
-            }
-
-
-            Map<String, List<LisExcelWrapperVO>> lixExMap = lisExcelWrapperList.stream()
-                    .collect(Collectors.groupingBy(LisExcelWrapperVO::getMealName));
-            List<LisExcelResVO> LisExcelReslist = new ArrayList<LisExcelResVO>();
-            for (String str : lixExMap.keySet()) {
-                LisExcelResVO lisExcelResVO = new LisExcelResVO();
-                lisExcelResVO.setMenus(str);
-                lisExcelResVO.setLisExcelItem(lixExMap.get(str));
-
-                LisExcelReslist.add(lisExcelResVO);
-            }
-
-            LitAssayVO litAssay = new LitAssayVO();
-            litAssay.setMessages(messages);
-            litAssay.setLisExcelRes(LisExcelReslist);
-            return RespDTO.onSuc(litAssay);
-        } catch (Exception e) {
-            e.printStackTrace();
-            throw new CommonException(CommonErrorCode.NOT_EXISTS, "化验excel文件解析出错!");
-            // return response.failure("化验excel文件解析出错!");
-        } finally {
-            try {
-                if (inputStream != null) {
-                    inputStream.close();
-                }
-                if (wb != null) {
-                    wb.close();
-                }
-            } catch (Exception e) {
-            }
-        }
-    }
-
-    private String getValue(Cell cell) {
-        try {
-            Object obj = null;
-            switch (cell.getCellTypeEnum()) {
-                case BOOLEAN:
-                    obj = cell.getBooleanCellValue();
-                    break;
-                case ERROR:
-                    obj = cell.getErrorCellValue();
-                    break;
-                case NUMERIC:
-                    if (HSSFDateUtil.isCellDateFormatted(cell)) {
-                        Date date = cell.getDateCellValue();
-                        obj = DateFormatUtils.format(date, "yyyy-MM-dd");
-                    } else {
-                        obj = cell.getNumericCellValue();
-                        DecimalFormat df = new DecimalFormat();
-                        obj = df.format(obj);
-                    }
-
-                    // obj = cell.getNumericCellValue();
-                    break;
-                case STRING:
-                    obj = cell.getStringCellValue();
-                    break;
-                default:
-                    break;
-            }
-            return obj.toString();
-        } catch (Exception e) {
-            return "";
-        }
-    }
-
-}
+package com.diagbot.facade;
+
+import com.diagbot.client.TranServiceClient;
+import com.diagbot.dto.LisConfigDTO;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
+import com.diagbot.util.ListUtil;
+import com.diagbot.util.StringUtil;
+import com.diagbot.vo.LisExcelResVO;
+import com.diagbot.vo.LisExcelWrapperVO;
+import com.diagbot.vo.LisHospitalCodeVO;
+import com.diagbot.vo.LitAssayVO;
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.InputStream;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author wangfeng
+ * @Description: 化验导入
+ * @date 2018年11月29日 上午10:16:35
+ */
+@Component
+public class LisExcelResFacade {
+
+    /*@Autowired
+    LisConfigFacade lisConfigFacade;*/
+    @Autowired
+    TranServiceClient tranServiceClient;
+
+    @SuppressWarnings("null")
+    public RespDTO<LitAssayVO> lisExcelAnalysis(MultipartFile file, LisHospitalCodeVO lisHospitalCodeVO, HttpServletRequest request) {
+
+        List<String> messages = new ArrayList<>();
+        List<LisExcelWrapperVO> lisExcelWrapperList = new ArrayList<>();
+        InputStream inputStream = null;
+        List<String> assemblys = new ArrayList<String>();
+        Workbook wb = null;
+        try {
+            if (!file.isEmpty()) {
+                inputStream = file.getInputStream();
+                if (inputStream.available() > 512000) {
+                    messages.add("化验文件最大支持500KB!");
+                } else {
+                    String fileName = file.getOriginalFilename();
+                    if (fileName.lastIndexOf(".") != -1) {
+                        String type = fileName.substring(fileName.lastIndexOf("."));
+                        if (type.equals(".xls")) {
+                            wb = new HSSFWorkbook(inputStream);
+                        } else if (type.equals(".xlsx")) {
+                            wb = new XSSFWorkbook(inputStream);
+                        }
+                        if (wb != null) {
+                            Sheet sheet = wb.getSheetAt(0);
+                            int count = 0;
+                            String mealName, itemName, unit, value, max, min, time;
+                            for (Row row : sheet) {
+                                count++;
+                                try {
+                                    if (row != null) {
+                                        mealName = getValue(row.getCell(0)).trim().replace(" ", "");
+                                        itemName = getValue(row.getCell(1)).trim().replace(" ", "");
+                                        unit = getValue(row.getCell(2)).trim();
+                                        value = getValue(row.getCell(3)).trim();
+                                        min = getValue(row.getCell(4)).trim();
+                                        max = getValue(row.getCell(5)).trim();
+                                        time = getValue(row.getCell(6)).trim();
+                                        type = getValue(row.getCell(7)).trim();
+                                    } else {
+                                        mealName = null;
+                                        itemName = null;
+                                        unit = null;
+                                        value = null;
+                                        min = null;
+                                        max = null;
+                                        time = null;
+                                        type = null;
+                                    }
+
+                                    if (StringUtil.isEmpty(mealName) && StringUtil.isEmpty(itemName)
+                                            && StringUtil.isEmpty(value) && StringUtil.isEmpty(type)) {
+                                        continue;
+                                    }
+
+                                    if (count == 1 && mealName.equals("套餐名")) {
+                                        continue;
+                                    }
+
+                                    if (StringUtil.isEmpty(mealName) || StringUtil.isEmpty(itemName)
+                                            || StringUtil.isEmpty(value) || StringUtil.isEmpty(type)) {
+                                        messages.add("第" + count + "行数据不规范,套餐名、项目名、结果、是否异常四项必填;");
+                                        continue;
+                                    }
+                                    LisExcelWrapperVO lisExcelWrapper = new LisExcelWrapperVO();
+
+
+                                    lisExcelWrapper.setMealName(mealName);
+                                    lisExcelWrapper.setItemName(itemName);
+                                    String assembly = mealName + "--";
+                                    if (!assemblys.contains(assembly)) {
+                                        assemblys.add(assembly);
+                                    }
+                                    assembly = mealName + "--" + itemName;
+                                    if (!assemblys.contains(assembly)) {
+                                        assemblys.add(assembly);
+                                    }
+                                    //  lisExcelWrapper.setUniqueName(uniqueName);
+                                    lisExcelWrapper.setUnit(unit);
+                                    lisExcelWrapper.setValue(value);
+                                    lisExcelWrapper.setMax(max);
+                                    lisExcelWrapper.setMin(min);
+                                    lisExcelWrapper.setTime(time);
+                                    lisExcelWrapper.setType(type);
+                                    lisExcelWrapperList.add(lisExcelWrapper);
+                                } catch (Exception e) {
+                                    e.printStackTrace();
+                                    throw new CommonException(CommonErrorCode.NOT_EXISTS, e.toString());
+                                    // logger.error("",e);
+                                }
+                            }
+                        } else {
+                            // throw new
+                            // CommonException(CommonErrorCode.NOT_EXISTS,
+                            // "非excel文件无法解析!");
+                            messages.add("非excel文件无法解析!");
+                        }
+                    } else {
+                        // throw new CommonException(CommonErrorCode.NOT_EXISTS,
+                        // "未知文件无法解析!");
+                        messages.add("未知文件无法解析!");
+                    }
+                }
+            } else {
+                // throw new CommonException(CommonErrorCode.NOT_EXISTS,
+                // "无文件上传!");
+                messages.add("无文件上传!");
+            }
+            //匹配公表名
+            lisHospitalCodeVO.setAssemblys(assemblys);
+            RespDTO<List<LisConfigDTO>> litDatas = tranServiceClient.getLisConfigByhospitalId(lisHospitalCodeVO);
+            if (litDatas == null || !"0".equals(litDatas.code)) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                        "获取匹配公表名信息失败");
+            }
+            List<LisConfigDTO> litData = litDatas.data;
+
+            //导入的数据跟公表数据进行配对
+            if (ListUtil.isNotEmpty(litData)) {
+                Map<String, String> listMap = litData.stream()
+                        .collect(Collectors.toMap(LisConfigDTO::getAssembly, LisConfigDTO::getUniqueName));
+                List<LisExcelWrapperVO> lisExcelWrapperListNew = new ArrayList<>();
+                for (LisExcelWrapperVO lisExcelWrapperNew : lisExcelWrapperList) {
+                    String assemblymeal = lisExcelWrapperNew.getMealName() + "--";
+                    if (null != listMap.get(assemblymeal)) {
+                        lisExcelWrapperNew.setUniquemealName(listMap.get(assemblymeal));
+                    }
+                    String item = lisExcelWrapperNew.getMealName() + "--" + lisExcelWrapperNew.getItemName();
+                    if (null != listMap.get(item)) {
+                        lisExcelWrapperNew.setUniqueName(listMap.get(item));
+                    }
+                    lisExcelWrapperListNew.add(lisExcelWrapperNew);
+                }
+                lisExcelWrapperList = lisExcelWrapperListNew;
+            }
+
+
+            Map<String, List<LisExcelWrapperVO>> lixExMap = lisExcelWrapperList.stream()
+                    .collect(Collectors.groupingBy(LisExcelWrapperVO::getMealName));
+            List<LisExcelResVO> LisExcelReslist = new ArrayList<LisExcelResVO>();
+            for (String str : lixExMap.keySet()) {
+                LisExcelResVO lisExcelResVO = new LisExcelResVO();
+                lisExcelResVO.setMenus(str);
+                lisExcelResVO.setLisExcelItem(lixExMap.get(str));
+
+                LisExcelReslist.add(lisExcelResVO);
+            }
+
+            LitAssayVO litAssay = new LitAssayVO();
+            litAssay.setMessages(messages);
+            litAssay.setLisExcelRes(LisExcelReslist);
+            return RespDTO.onSuc(litAssay);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new CommonException(CommonErrorCode.NOT_EXISTS, "请导入正确格式的excel文件!");
+            // return response.failure("化验excel文件解析出错!");
+        } finally {
+            try {
+                if (inputStream != null) {
+                    inputStream.close();
+                }
+                if (wb != null) {
+                    wb.close();
+                }
+            } catch (Exception e) {
+            }
+        }
+    }
+
+    private String getValue(Cell cell) {
+        try {
+            Object obj = null;
+            switch (cell.getCellTypeEnum()) {
+                case BOOLEAN:
+                    obj = cell.getBooleanCellValue();
+                    break;
+                case ERROR:
+                    obj = cell.getErrorCellValue();
+                    break;
+                case NUMERIC:
+                    if (HSSFDateUtil.isCellDateFormatted(cell)) {
+                        Date date = cell.getDateCellValue();
+                        obj = DateFormatUtils.format(date, "yyyy-MM-dd");
+                    } else {
+                        obj = cell.getNumericCellValue();
+                        DecimalFormat df = new DecimalFormat();
+                        obj = df.format(obj);
+                    }
+
+                    // obj = cell.getNumericCellValue();
+                    break;
+                case STRING:
+                    obj = cell.getStringCellValue();
+                    break;
+                default:
+                    break;
+            }
+            return obj.toString();
+        } catch (Exception e) {
+            return "";
+        }
+    }
+
+}