|
@@ -0,0 +1,299 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import java.io.InputStream;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.dto.DiagnosticBasisExportDTO;
|
|
|
+import com.diagbot.dto.EquationDTO;
|
|
|
+import com.diagbot.dto.FeatureDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.entity.DiagnoseQuestion;
|
|
|
+import com.diagbot.enums.DiagnoseFieldEnum;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.enums.TermEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.DiagnoseQuestionService;
|
|
|
+import com.diagbot.util.ExportBeanExcelUtil;
|
|
|
+import com.diagbot.util.GsonUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.vo.DiagnosticBasisExportVO;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author wangfeng
|
|
|
+ * @Description: TODO
|
|
|
+ * @date 2019年8月8日 下午1:30:53
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class DiagnoseImportFacade {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DiagnoseQuestionService diagnoseQuestionService;
|
|
|
+
|
|
|
+ @SuppressWarnings("null")
|
|
|
+ public RespDTO<DiagnoseImportDTO> importDiagnosticBasisAll(MultipartFile file, HttpServletRequest request) {
|
|
|
+
|
|
|
+ List<String> messages = new ArrayList<>();
|
|
|
+ InputStream inputStream = null;
|
|
|
+ DiagnoseImportDTO diagnoseImportDTO = new DiagnoseImportDTO();
|
|
|
+ List<FeatureDTO> featureList = new ArrayList<FeatureDTO>();
|
|
|
+ List<EquationDTO> equationList = new ArrayList<EquationDTO>();
|
|
|
+ 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);
|
|
|
+ diagnoseImportDTO.setDisName(sheet.getSheetName());
|
|
|
+ int count = 0;
|
|
|
+ String name, code, standardWord, associatedWord, consequence;
|
|
|
+ for (Row row : sheet) {
|
|
|
+ count++;
|
|
|
+ try {
|
|
|
+ if (row != null) {
|
|
|
+ name = getValue(row.getCell(0)).trim().replace(" ", "");
|
|
|
+ code = getValue(row.getCell(1)).trim().replace(" ", "");
|
|
|
+ standardWord = getValue(row.getCell(2)).trim();
|
|
|
+ associatedWord = getValue(row.getCell(3)).trim();
|
|
|
+ consequence = getValue(row.getCell(4)).trim();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ name = null;
|
|
|
+ code = null;
|
|
|
+ standardWord = null;
|
|
|
+ associatedWord = null;
|
|
|
+ consequence = null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * if (StringUtil.isEmpty(name) &&
|
|
|
+ * StringUtil.isEmpty(itemName) &&
|
|
|
+ * StringUtil.isEmpty(value) &&
|
|
|
+ * StringUtil.isEmpty(name)) { continue; }
|
|
|
+ */
|
|
|
+
|
|
|
+ if (count == 1 && name.equals("类型")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.isEmpty(name)) {
|
|
|
+ messages.add("第" + count + "行数据不规范,类型必填;");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FeatureDTO feature = new FeatureDTO();
|
|
|
+ EquationDTO equation = new EquationDTO();
|
|
|
+ if (code.equals("")) {
|
|
|
+ equation.setType(name);
|
|
|
+ equation.setAssociated(associatedWord);
|
|
|
+ equationList.add(equation);
|
|
|
+ } else {
|
|
|
+ feature.setType(name);
|
|
|
+ feature.setCode(code);
|
|
|
+ feature.setResult(consequence);
|
|
|
+ feature.setAssociated(associatedWord);
|
|
|
+ feature.setStandard(standardWord);
|
|
|
+ featureList.add(feature);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } 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("无文件上传!");
|
|
|
+ }
|
|
|
+
|
|
|
+ diagnoseImportDTO.setEquation(equationList);
|
|
|
+ diagnoseImportDTO.setFeature(featureList);
|
|
|
+ diagnoseImportDTO.setMessages(messages);
|
|
|
+ return RespDTO.onSuc(diagnoseImportDTO);
|
|
|
+ } 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 "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void exportDiagnosticBasis(DiagnosticBasisExportVO diaExportVO, HttpServletResponse response) {
|
|
|
+ QueryWrapper<DiagnoseQuestion> diaQuery = new QueryWrapper<>();
|
|
|
+ diaQuery.like("dis_name",diaExportVO.getDisName()).like("question_name",diaExportVO.getQuestion()).like("type",diaExportVO.getType()).eq("is_deleted",IsDeleteEnum.N.getKey());
|
|
|
+ List<DiagnoseQuestion> datas = diagnoseQuestionService.list(diaQuery);
|
|
|
+
|
|
|
+ GsonUtil.toJson(datas);
|
|
|
+ System.out.println(GsonUtil.toJson(datas));
|
|
|
+ List<String> listName = new ArrayList<>();
|
|
|
+
|
|
|
+ listName.add("归属诊断");
|
|
|
+ listName.add("标准术语*");
|
|
|
+ listName.add("类型*");
|
|
|
+ listName.add("术语同义词*(多个时用\",\"隔开,必须需要包含本体)");
|
|
|
+ listName.add("标准术语说明");
|
|
|
+ listName.add("性别");
|
|
|
+ listName.add("最小年龄");
|
|
|
+ listName.add("最大年龄");
|
|
|
+
|
|
|
+ List<String> listId = new ArrayList<>();
|
|
|
+ listId.add("disName");
|
|
|
+ listId.add("term");
|
|
|
+ listId.add("type");
|
|
|
+ listId.add("termSynonym");
|
|
|
+ listId.add("TermNote");
|
|
|
+ listId.add("sex");
|
|
|
+ listId.add("minAge");
|
|
|
+ listId.add("maxAge");
|
|
|
+
|
|
|
+ List<DiagnosticBasisExportDTO> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < datas.size(); i++) {
|
|
|
+ DiagnoseQuestion diagnose = datas.get(i);
|
|
|
+ list.add(new DiagnosticBasisExportDTO(diagnose.getDisName(), diagnose.getQuestionName(),
|
|
|
+ getType(diagnose.getType(), diagnose.getQuestionType()), diagnose.getQuestionName(), "", "通用", "0",
|
|
|
+ "200"));
|
|
|
+
|
|
|
+ }
|
|
|
+ response.setContentType("text/html;charset=UTF-8");
|
|
|
+ ExportBeanExcelUtil ex = new ExportBeanExcelUtil();
|
|
|
+ ex.exportExcelNew("诊断依据问题词", listName, listId, list, response);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出类型转换
|
|
|
+ * @param type
|
|
|
+ * @param questionType
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getType(Integer type, Integer questionType) {
|
|
|
+ String typeName = "";
|
|
|
+ if (type == 1) {
|
|
|
+ typeName = TermEnum.getName(1);
|
|
|
+ } else if (type == 2) {
|
|
|
+ typeName = TermEnum.getName(2);
|
|
|
+ } else if (type == 3) {
|
|
|
+ if (questionType == 2) {
|
|
|
+ typeName = TermEnum.getName(3);
|
|
|
+ }
|
|
|
+ if (questionType == 3) {
|
|
|
+ typeName = TermEnum.getName(4);
|
|
|
+ }
|
|
|
+ if (questionType == 4) {
|
|
|
+ typeName = TermEnum.getName(5);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (type == 4) {
|
|
|
+ if (questionType == 2) {
|
|
|
+ typeName = TermEnum.getName(6);
|
|
|
+ }
|
|
|
+ if (questionType == 4) {
|
|
|
+ typeName = TermEnum.getName(7);
|
|
|
+ }
|
|
|
+ } else if (type == 5) {
|
|
|
+ typeName = TermEnum.getName(8);
|
|
|
+ } else if (type == 6) {
|
|
|
+ typeName = TermEnum.getName(8);
|
|
|
+ } else if (type == 7) {
|
|
|
+ typeName = TermEnum.getName(9);
|
|
|
+ } else if (type == 8) {
|
|
|
+ typeName = TermEnum.getName(10);
|
|
|
+ } else if (type == 9) {
|
|
|
+ typeName = TermEnum.getName(10);
|
|
|
+ }
|
|
|
+
|
|
|
+ return typeName;
|
|
|
+ }
|
|
|
+}
|