|
@@ -1,5 +1,7 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.diagbot.dto.ExportConceptAllDTO;
|
|
|
import com.diagbot.entity.KlConcept;
|
|
@@ -7,6 +9,8 @@ import com.diagbot.entity.KlConceptCommon;
|
|
|
import com.diagbot.entity.KlLexicon;
|
|
|
import com.diagbot.entity.KlLibraryInfo;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.KlConceptCommonService;
|
|
|
import com.diagbot.service.KlConceptService;
|
|
|
import com.diagbot.service.KlDiseaseService;
|
|
@@ -22,12 +26,26 @@ import com.diagbot.util.ListUtil;
|
|
|
import com.diagbot.util.StringUtil;
|
|
|
import com.diagbot.vo.ImportConceptAllVO;
|
|
|
import com.diagbot.vo.ImportConceptSubVO;
|
|
|
+import org.apache.poi.hssf.usermodel.DVConstraint;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
+import org.apache.poi.ss.usermodel.DataFormat;
|
|
|
+import org.apache.poi.ss.usermodel.Name;
|
|
|
+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.ss.util.CellRangeAddressList;
|
|
|
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.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
@@ -100,7 +118,7 @@ public class TermImportFacade {
|
|
|
StringUtil.isBlank(data.getLibName()) ||
|
|
|
null == data.getSexType()
|
|
|
|| null == data.getMinAge()
|
|
|
- || null == data.getMinAge()) {
|
|
|
+ || null == data.getMaxAge()) {
|
|
|
errMsg.put(data.getRowNum(), "--医学标准术语、类型、性别、最小年龄、最大年龄必填--");
|
|
|
} else {
|
|
|
//类型
|
|
@@ -164,7 +182,7 @@ public class TermImportFacade {
|
|
|
libNameMap.put(r.trim() + "_" + libType, termExcelVO.getRowNum());
|
|
|
} else {
|
|
|
errMsg.put(termExcelVO.getRowNum(), errMsg.get(termExcelVO.getRowNum()) == null ? r.trim() + "重复出现--" :
|
|
|
- errMsg.get(termExcelVO.getRowNum()) + r.trim() + "重复出现--");
|
|
|
+ errMsg.get(termExcelVO.getRowNum()) + r.trim() + "重复出现--");
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -177,7 +195,7 @@ public class TermImportFacade {
|
|
|
for (String libName : libNameMap.keySet()) {
|
|
|
Integer integer = libNameMap.get(libName);
|
|
|
if (set.contains(libName)) {
|
|
|
- errMsg.put(integer, errMsg.get(integer) == null ? "--数据库中" + libName + "已存在--" :
|
|
|
+ errMsg.put(integer, errMsg.get(integer) == null ? "--数据库中" + libName + "已存在--" :
|
|
|
errMsg.get(integer) + "--数据库中" + libName + "已存在--");
|
|
|
}
|
|
|
}
|
|
@@ -301,8 +319,82 @@ public class TermImportFacade {
|
|
|
}
|
|
|
|
|
|
public void exportTemplateAll(HttpServletResponse response) {
|
|
|
+ //类型数据
|
|
|
+ QueryWrapper<KlLexicon> klLexiconQuer = new QueryWrapper<>();
|
|
|
+ klLexiconQuer.eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+ List<KlLexicon> klLexiconList = klLexiconFacade.list(klLexiconQuer);
|
|
|
String fileName = "模板.xls";
|
|
|
- ExcelUtils.exportExcel(new ArrayList<>(), null, "sheet1", ExportConceptAllDTO.class, fileName, response, 12.8f);
|
|
|
+ String title = null;
|
|
|
+ // ExcelUtils.exportExcel(new ArrayList<>(), null, "sheet1", ExportConceptAllDTO.class, fileName, response, 12.8f);
|
|
|
+ float height = 12.8f;
|
|
|
+ Boolean havTitle = false;
|
|
|
+ if (StringUtil.isNotBlank(title)) {
|
|
|
+ havTitle = true;
|
|
|
+ }
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(title, "sheet1"), ExportConceptAllDTO.class, new ArrayList<>());
|
|
|
+ if (workbook != null) {
|
|
|
+ //设置第5,6整列只能是数字
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);//创建Excel工作表的行
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();//创建单元格样式
|
|
|
+ DataFormat df = workbook.createDataFormat();// 此处设置数据格式
|
|
|
+ cellStyle.setDataFormat(df.getFormat("#,##0.0"));//保留1位小数点
|
|
|
+ sheet.setDefaultColumnStyle(4, cellStyle);
|
|
|
+ sheet.setDefaultColumnStyle(5, cellStyle);
|
|
|
+
|
|
|
+ //设置第3整列只能指定类型下拉选
|
|
|
+ List<String> typeNames = new ArrayList<>();
|
|
|
+ typeNames = klLexiconList.stream().map(ac -> ac.getName()).collect(Collectors.toList());
|
|
|
+ String[] typeName = typeNames.toArray(new String[typeNames.size()]);
|
|
|
+ HSSFWorkbook wbook = new HSSFWorkbook();
|
|
|
+ Sheet hidden = workbook.createSheet("hidden");
|
|
|
+ HSSFCell cell = null;
|
|
|
+ for (int i = 0, length = typeNames.size(); i < length; i++) {
|
|
|
+ String name = typeNames.get(i);
|
|
|
+ Row row = hidden.createRow(i);
|
|
|
+ Cell cell1 = row.createCell(0);
|
|
|
+ cell1.setCellValue(name);
|
|
|
+ }
|
|
|
+ Name namedCell = workbook.createName();
|
|
|
+ namedCell.setNameName("hidden");
|
|
|
+ namedCell.setRefersToFormula("hidden!$A$1:$A$" + typeNames.size());
|
|
|
+ //加载数据,将名称为hidden的
|
|
|
+ DVConstraint constraint = DVConstraint.createFormulaListConstraint("hidden");
|
|
|
+ CellRangeAddressList regions = new CellRangeAddressList(1, 50000, 2, 2);
|
|
|
+ //DVConstraint constraint = DVConstraint.createExplicitListConstraint(typeName);
|
|
|
+ HSSFDataValidation data_validation = new HSSFDataValidation(regions, constraint);
|
|
|
+ if (null != data_validation) {
|
|
|
+ sheet.addValidationData(data_validation);
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置第3整列只能下拉选1.2.3
|
|
|
+ String[] strings = { "1", "2", "3" };
|
|
|
+ CellRangeAddressList regions2 = new CellRangeAddressList(1, 50000, 3, 3);
|
|
|
+ DVConstraint constraint2 = DVConstraint.createExplicitListConstraint(strings);
|
|
|
+ HSSFDataValidation data_validation2 = new HSSFDataValidation(regions2, constraint2);
|
|
|
+ sheet.addValidationData(data_validation2);
|
|
|
+
|
|
|
+
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ Row row = sheet.getRow(0);
|
|
|
+ int startRowNum = 1;
|
|
|
+ if (havTitle) {
|
|
|
+ startRowNum = 2;
|
|
|
+ }
|
|
|
+ for (int i = startRowNum; i <= rowNum; i++) {
|
|
|
+ row = sheet.getRow(i);
|
|
|
+ row.setHeightInPoints(height);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setHeader("content-Type", "application/vnd.ms-excel");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ } catch (IOException e) {
|
|
|
+ // throw new NormalException(e.getMessage());
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "导出Excel异常");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|