feat: 三标通用-模板下载
This commit is contained in:
+117
-15
@@ -39,14 +39,15 @@ import com.jero.modules.system.service.ISysDictItemService;
|
|||||||
import com.jero.modules.system.service.ISysUserService;
|
import com.jero.modules.system.service.ISysUserService;
|
||||||
import com.jero.modules.tag.entity.LawsArea;
|
import com.jero.modules.tag.entity.LawsArea;
|
||||||
import com.jero.modules.tag.entity.LawsTag;
|
import com.jero.modules.tag.entity.LawsTag;
|
||||||
|
import com.jero.modules.tag.enums.FieldShowTypeEnum;
|
||||||
import com.jero.modules.tag.enums.TableNameEnum;
|
import com.jero.modules.tag.enums.TableNameEnum;
|
||||||
import com.jero.modules.tag.enums.LawsFieldTypeEnum;
|
import com.jero.modules.tag.enums.LawsFieldTypeEnum;
|
||||||
import com.jero.modules.tag.service.ILawsAreaService;
|
import com.jero.modules.tag.service.ILawsAreaService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
@@ -56,8 +57,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -1111,19 +1111,121 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入模板
|
||||||
|
* @param response
|
||||||
|
* @param tableName
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void templateDownload(HttpServletResponse response, String tableName) {
|
public void templateDownload(HttpServletResponse response, String tableName) {
|
||||||
//TODO 模板下载
|
// 获取全部字段
|
||||||
// // 获取全部字段
|
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||||
// List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
|
||||||
//
|
// 筛选出新增要用的字段
|
||||||
// // 筛选出新增要用的字段
|
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||||
// fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
.equals(lawsTag.getIsShowFormCreate().toString())).collect(Collectors.toList());
|
||||||
// .equals(lawsTag.getIsShowFormCreate().toString())).collect(Collectors.toList());
|
|
||||||
//
|
// 创建一个Excel工作簿
|
||||||
//
|
Workbook workbook = new XSSFWorkbook();
|
||||||
//
|
|
||||||
// return areaMap;
|
// 创建一个工作表
|
||||||
|
Sheet sheet = workbook.createSheet("导入模板");
|
||||||
|
// 设置列宽
|
||||||
|
for (int i = 0; i < fieldList.size(); i++) {
|
||||||
|
sheet.setColumnWidth(i, 15 * 256);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建红色字体
|
||||||
|
Font redFont = workbook.createFont();
|
||||||
|
redFont.setColor(IndexedColors.RED.getIndex());
|
||||||
|
|
||||||
|
// 创建默认字体(黑色)
|
||||||
|
Font defaultFont = workbook.createFont();
|
||||||
|
defaultFont.setColor(IndexedColors.BLACK.getIndex());
|
||||||
|
|
||||||
|
// 创建第一行并添加字段
|
||||||
|
Row row1 = sheet.createRow(0);
|
||||||
|
for (int i = 0; i < fieldList.size(); i++) {
|
||||||
|
LawsTag tag = fieldList.get(i);
|
||||||
|
String cellValue = tag.getDbFieldTxt();
|
||||||
|
|
||||||
|
// 创建单元格
|
||||||
|
Cell cell = row1.createCell(i);
|
||||||
|
|
||||||
|
// 判断是否为必填项
|
||||||
|
if (YesOrNoEnum.YES.getValue().equals(tag.getFieldMustInput())) {
|
||||||
|
// 创建富文本字符串
|
||||||
|
CreationHelper createHelper = workbook.getCreationHelper();
|
||||||
|
RichTextString richString = createHelper.createRichTextString("*" + cellValue);
|
||||||
|
|
||||||
|
// 设置 * 为红色
|
||||||
|
richString.applyFont(0, 1, redFont);
|
||||||
|
|
||||||
|
// 设置其他文字为默认样式(黑色)
|
||||||
|
richString.applyFont(1, richString.length(), defaultFont);
|
||||||
|
|
||||||
|
// 设置单元格的值
|
||||||
|
cell.setCellValue(richString);
|
||||||
|
} else {
|
||||||
|
cell.setCellValue(cellValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建第二行并合并单元格
|
||||||
|
Row row2 = sheet.createRow(1);
|
||||||
|
row2.setHeightInPoints(95);
|
||||||
|
// 创建一个单元格样式,并设置为自动换行
|
||||||
|
CellStyle style = workbook.createCellStyle();
|
||||||
|
style.setWrapText(true);
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
fieldList.size() - 1
|
||||||
|
));
|
||||||
|
Cell cell2 = row2.createCell(0);
|
||||||
|
cell2.setCellValue("填写说明:\n" +
|
||||||
|
"1.所有带星号的为必填\n" +
|
||||||
|
"2.导入数据从第四行开始,第一行为表头,第二行为填写说明,第三行为示例。第四行才是正式数据\n" +
|
||||||
|
"3.字段为多选属性,必须与系统中对应选项字段相匹配,填写多个时使用逗号隔开\n" +
|
||||||
|
"4.字段为文件属性,填写时需在本文件同级目录下以标准号为名称建立文件夹,并在文件夹内放置文件。假设在A标准号的文件夹内放置了A1文件,那么单元格需填写:A/A1.pdf");
|
||||||
|
// 应用样式到单元格
|
||||||
|
cell2.setCellStyle(style);
|
||||||
|
// 创建第三行并添加固定内容
|
||||||
|
Row row3 = sheet.createRow(2);
|
||||||
|
row3.setHeightInPoints(105);
|
||||||
|
this.setRow3CellValue(row3, fieldList);
|
||||||
|
|
||||||
|
// 设置HTTP响应头
|
||||||
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=\"导入模板.xlsx\"");
|
||||||
|
|
||||||
|
// 获取响应输出流并写入Excel
|
||||||
|
try (OutputStream out = response.getOutputStream()) {
|
||||||
|
workbook.write(out);
|
||||||
|
out.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("导出Excel失败", e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
workbook.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("导出Excel失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置导入模板的第三行提示内容
|
||||||
|
* @param row3
|
||||||
|
* @param fieldList
|
||||||
|
*/
|
||||||
|
private void setRow3CellValue(Row row3, List<LawsTag> fieldList) {
|
||||||
|
for (int i = 0; i < fieldList.size(); i++) {
|
||||||
|
// 创建单元格
|
||||||
|
Cell cell = row3.createCell(i);
|
||||||
|
cell.setCellValue(FieldShowTypeEnum.getDescription(fieldList.get(i).getFieldShowType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+7
@@ -153,4 +153,11 @@ public class LawsDomesticController {
|
|||||||
lawsCommonService.exportDataWithFile(response, parameterMap, "国标导出", "国标导出");
|
lawsCommonService.exportDataWithFile(response, parameterMap, "国标导出", "国标导出");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AutoLog(value = "国内法规标准-模板下载")
|
||||||
|
@ApiOperation(value="国内法规标准-模板下载", notes="国内法规标准-模板下载")
|
||||||
|
@GetMapping("/templateDownload")
|
||||||
|
public void templateDownload(HttpServletResponse response) {
|
||||||
|
lawsCommonService.templateDownload(response, TableNameEnum.DOMESTIC_REGULATIONS.getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -210,7 +210,7 @@ public class LawsEnterpriseController {
|
|||||||
|
|
||||||
@AutoLog(value = "企业法规标准-模板下载")
|
@AutoLog(value = "企业法规标准-模板下载")
|
||||||
@ApiOperation(value="企业法规标准-模板下载", notes="企业法规标准-模板下载")
|
@ApiOperation(value="企业法规标准-模板下载", notes="企业法规标准-模板下载")
|
||||||
@PostMapping("/templateDownload")
|
@GetMapping("/templateDownload")
|
||||||
public void templateDownload(HttpServletResponse response) {
|
public void templateDownload(HttpServletResponse response) {
|
||||||
lawsCommonService.templateDownload(response, TableNameEnum.ENTERPRISE_STANDARDS.getTableName());
|
lawsCommonService.templateDownload(response, TableNameEnum.ENTERPRISE_STANDARDS.getTableName());
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -152,4 +152,11 @@ public class LawsOverseasController {
|
|||||||
public void exportDataWithFile(HttpServletResponse response, @RequestBody(required = false) Map<String,Object> parameterMap) {
|
public void exportDataWithFile(HttpServletResponse response, @RequestBody(required = false) Map<String,Object> parameterMap) {
|
||||||
lawsCommonService.exportDataWithFile(response, parameterMap, "外标导出", "外标导出");
|
lawsCommonService.exportDataWithFile(response, parameterMap, "外标导出", "外标导出");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AutoLog(value = "海外法规标准-模板下载")
|
||||||
|
@ApiOperation(value="海外法规标准-模板下载", notes="海外法规标准-模板下载")
|
||||||
|
@GetMapping("/templateDownload")
|
||||||
|
public void templateDownload(HttpServletResponse response) {
|
||||||
|
lawsCommonService.templateDownload(response, TableNameEnum.FOREIGN_REGULATIONS.getTableName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.jero.modules.tag.enums;
|
||||||
|
|
||||||
|
import com.jero.common.exception.JeroBootException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: Mzaxd
|
||||||
|
* @Date: 2023/9/25 15:42
|
||||||
|
*/
|
||||||
|
public enum FieldShowTypeEnum {
|
||||||
|
|
||||||
|
SINGLE_DATE_PICKER("单日期选择","1","请填写选项中包含的文本"),
|
||||||
|
SINGLE_USER_DIALOG("单选用户弹框","2","请填写选项中包含的文本"),
|
||||||
|
SINGLE_ORGANIZATION_DIALOG("单选组织机构弹框","3","请填写选项中包含的文本"),
|
||||||
|
MULTI_DATE_PICKER("多日期选择","4","4"),
|
||||||
|
MULTI_TEXT("多行文本","5","文本输入"),
|
||||||
|
MULTI_STANDARD_DIALOG("多选标准弹框","6","请填写选项中包含的文本,多填以逗号隔开"),
|
||||||
|
MULTI_ORGANIZATION_DIALOG("多选组织机构弹框","7","请填写选项中包含的文本,多填以逗号隔开"),
|
||||||
|
FILE_UPLOAD("上传文件","8","文件属性,请输入:标准号/文件名称.文件格式"),
|
||||||
|
TEXT_BOX("文本框","9","文本输入"),
|
||||||
|
DROPDOWN_SINGLE_SELECT("下拉单选","10","4"),
|
||||||
|
DROPDOWN_MULTI_SELECT("下拉多选","11","请填写选项中包含的文本,多填以逗号隔开"),
|
||||||
|
TREE_STRUCTURE_MULTI_SELECT("条款拆分","12","请填写选项中包含的文本,多填以逗号隔开"),
|
||||||
|
LINK_INPUT_BOX("输入框(链接)","13","请填写选项中包含的文本"),
|
||||||
|
YEAR_SELECT("条款拆分","14","请填写选项中包含的文本"),
|
||||||
|
TREE_STRUCTURE_SINGLE_SELECT("树形结构(单选)","15","请填写选项中包含的文本")
|
||||||
|
;
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
final String value;
|
||||||
|
final String description;
|
||||||
|
|
||||||
|
FieldShowTypeEnum(String name, String value, String description) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDescription(String value){
|
||||||
|
for (FieldShowTypeEnum fieldShowTypeEnum : values()) {
|
||||||
|
if (fieldShowTypeEnum.getValue().equals(value)) {
|
||||||
|
return fieldShowTypeEnum.getDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new JeroBootException("标签类型不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user