法规清单--模板下载
This commit is contained in:
+34
@@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -330,4 +331,37 @@ public class ProjectLawsInventoryEOController extends JeroController<ProjectLaws
|
||||
return Result.OK(dummyInventoryBaseEO.getCut(),pageList);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "模板下载")
|
||||
@GetMapping(value = "/exportTemplate")
|
||||
public void exportTemplate(ProjectLawsInventoryEO projectLawsInventoryEO, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||||
projectLawsInventoryEOService.exportTemplate(projectLawsInventoryEO,response,request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param request
|
||||
* @param projectLawsInventoryEO
|
||||
*/
|
||||
@RequestMapping(value = "/exportData")
|
||||
public void exportData(HttpServletResponse response,
|
||||
HttpServletRequest request,
|
||||
ProjectLawsInventoryEO projectLawsInventoryEO) {
|
||||
projectLawsInventoryEOService.exportData(response,request, projectLawsInventoryEO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @param file
|
||||
* @param projectLawsInventoryEO
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/importData", method = RequestMethod.POST)
|
||||
public Result<?> importData(@RequestParam(value = "file", required = false) MultipartFile file,
|
||||
ProjectLawsInventoryEO projectLawsInventoryEO) {
|
||||
projectLawsInventoryEOService.importData(file,projectLawsInventoryEO);
|
||||
return Result.OK("导入成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
@@ -4,8 +4,10 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.modules.project.entity.ProjectLawsInventoryEO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -97,4 +99,19 @@ public interface IProjectLawsInventoryEOService extends IService<ProjectLawsInve
|
||||
* @param projectLawsInventoryEO
|
||||
*/
|
||||
void setBatch(ProjectLawsInventoryEO projectLawsInventoryEO);
|
||||
|
||||
/**
|
||||
* 模板下载
|
||||
* @param projectLawsInventoryEO
|
||||
* @param response
|
||||
* @param request
|
||||
*/
|
||||
void exportTemplate(ProjectLawsInventoryEO projectLawsInventoryEO, HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
void exportData(HttpServletResponse response,
|
||||
HttpServletRequest request,
|
||||
ProjectLawsInventoryEO projectLawsInventoryEO);
|
||||
|
||||
void importData(MultipartFile file,
|
||||
ProjectLawsInventoryEO projectLawsInventoryEO);
|
||||
}
|
||||
|
||||
+173
@@ -1,6 +1,7 @@
|
||||
package com.jero.modules.project.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyuncs.utils.IOUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
@@ -45,14 +46,28 @@ import com.jero.modules.system.service.ISysUserService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -103,6 +118,8 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
|
||||
private ProjectNameInfoEOMapper projectNameInfoEOMapper;
|
||||
@Autowired
|
||||
private IDummyInventoryInfoEOService dummyInventoryInfoEOService;
|
||||
@Value(value = "${jero.path.upload}")
|
||||
private String uploadpath;
|
||||
|
||||
/**
|
||||
* 保存
|
||||
@@ -1310,6 +1327,162 @@ public class ProjectLawsInventoryEOServiceImpl extends ServiceImpl<ProjectLawsIn
|
||||
projectLawsInventoryEO.setVerifyDuty(dummyInventoryInfoEO.getVerifyDuty());
|
||||
}
|
||||
return projectLawsInventoryEO;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exportTemplate(ProjectLawsInventoryEO projectLawsInventoryEO, HttpServletResponse response, HttpServletRequest request) {
|
||||
OutputStream os = null;
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
String fileOriName = "法规清单导入模板.xls";
|
||||
String filePath = uploadpath + File.separator + fileOriName;
|
||||
try {
|
||||
String titleOne = "";
|
||||
String titleTwo = "";
|
||||
if(CutEnum.CN.getValue().equals(projectLawsInventoryEO.getCut())){
|
||||
titleOne = "*编号,子标题,WVTA ID," +
|
||||
"实施类别,认证类型,*认证级别," +
|
||||
"*责任领域,*法规工程师,*认证工程师,*工程接口人," +
|
||||
"备注," +
|
||||
"设计符合性确认,Pre-homo确认,验证符合性确认";
|
||||
titleTwo = "交付物类型,交付物模板,发起人,责任人,截止时间,交付物类型,交付物模板,发起人,责任人,截止时间,交付物类型,交付物模板,发起人,责任人,截止时间,";
|
||||
}else{
|
||||
titleOne = "*serial number,subtitle,WVTA ID," +
|
||||
"*implementation category,certification type,*certification level," +
|
||||
"*area of responsibility,*laws engineer,*authentication engineer,*engineering interface person," +
|
||||
"remarks," +
|
||||
"design compliance check,pre-homo check,validation compliance chech";
|
||||
titleTwo = "type of deliverables,deliverable template,initiator,person liable,deadline," +
|
||||
"type of deliverables,deliverable template,initiator,person liable,deadline," +
|
||||
"type of deliverables,deliverable template,initiator,person liable,deadline";
|
||||
}
|
||||
|
||||
|
||||
List<String> list = Arrays.asList(titleOne.split(","));
|
||||
int index = 0;
|
||||
if(CutEnum.CN.getValue().equals(projectLawsInventoryEO.getCut())){
|
||||
index = list.indexOf("备注") + 1;
|
||||
}else{
|
||||
index = list.indexOf("remarks") + 1;
|
||||
}
|
||||
|
||||
//创建临时文件夹
|
||||
File nowFile = new File(filePath);
|
||||
if (nowFile.exists()) {
|
||||
nowFile.delete();
|
||||
}
|
||||
nowFile.mkdirs();
|
||||
HSSFSheet sheet = workbook.createSheet("虚拟清单导入模板");
|
||||
sheet.setDefaultColumnWidth(16);//列宽
|
||||
HSSFCellStyle cellStyle = workbook.createCellStyle();
|
||||
cellStyle.setWrapText(true);//自动换行
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);//垂直居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//水平居中
|
||||
|
||||
HSSFCellStyle cellStyleTemp = workbook.createCellStyle();
|
||||
cellStyleTemp.setWrapText(true);//自动换行
|
||||
|
||||
|
||||
int count = 1;
|
||||
int startLine = 0;
|
||||
int endLine = 0;
|
||||
int line = 4;
|
||||
for (int i = 0; i < index; i++) {
|
||||
//合并单元格
|
||||
CellRangeAddress region1 =
|
||||
new CellRangeAddress(0, 1, i, i);
|
||||
sheet.addMergedRegion(region1);
|
||||
}
|
||||
for (int i = index; i < 15; i++) {
|
||||
if(count > 1){
|
||||
startLine = startLine + line + 1;
|
||||
endLine = startLine + line;
|
||||
}else{
|
||||
startLine = i;
|
||||
endLine = i + line;
|
||||
}
|
||||
//合并单元格
|
||||
CellRangeAddress region1 =
|
||||
new CellRangeAddress(0, 0, startLine, endLine); //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列
|
||||
sheet.addMergedRegion(region1);
|
||||
count ++;
|
||||
}
|
||||
CellRangeAddress region =
|
||||
new CellRangeAddress(2, 2, 0, 25); //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列
|
||||
sheet.addMergedRegion(region);
|
||||
String explain= "";
|
||||
if(CutEnum.CN.getValue().equals(projectLawsInventoryEO.getCut())){
|
||||
explain = "填写说明\n" +
|
||||
"1.导入数据从第四行开始\n" +
|
||||
"2.所有带*号的字段必须填写\n"+
|
||||
"3.认证类型,认证级别,实施类别,交付物类型,发起人,责任人,字段是单选属性,必须和系统中的对应字段选项相匹配\n" +
|
||||
"4.责任领域,字段是多选属性,必须和系统中的对应字段选项相匹配,填写多个时采用英文或中文逗号分割\n" +
|
||||
"5.编号,子标题,WVTA ID,备注,填写文本内容\n" +
|
||||
"6.交付物模板字段为文件属性,填写时需要在本文件同级目录下以标准号为名称建立文件夹,并在文件夹下放置文件,假设在AAA标准号下放置了B.docx,则应填写AAA/B.docx";
|
||||
}else{
|
||||
explain = "filling explanation\n" +
|
||||
"1.import data starts at the fourth line\n" +
|
||||
"2.all fields marked with * must be filled in\n"+
|
||||
"3.certification type,certification level,implementation category,type of deliverables,initiator,person liable,Fields are radio attributes that must match the corresponding field option in the system\n" +
|
||||
"4.area of responsibility, field is a multi-select attribute and must match the corresponding field in the system. If multiple fields are filled in, separate them by commas (,)\n" +
|
||||
"5.serial number,subtitle,WVTA ID,remarks,Fill in the text\n" +
|
||||
"6.deliverable template,When filling in the field, you need to create a folder in the directory of the same level as the file with the name of the standard number and place the file in the folder. If b. diocx is stored under the AAA standard number, enter AAA/B. diocx";
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
//表头
|
||||
Row row = sheet.createRow(i);//开始创建标题行
|
||||
String[] headerArr = titleOne.split(",");
|
||||
int lineTemp = index;
|
||||
if (i == 0) {
|
||||
for (int m = 0; m < headerArr.length; m++) {
|
||||
if(m < index){
|
||||
row.createCell(m).setCellValue(headerArr[m]);
|
||||
}else{
|
||||
row.createCell(lineTemp).setCellValue(headerArr[m]);
|
||||
Cell cell = row.getCell(lineTemp);
|
||||
cell.setCellStyle(cellStyle);
|
||||
lineTemp = lineTemp + 5;
|
||||
}
|
||||
}
|
||||
|
||||
}else if(i == 1){
|
||||
//titleTwo
|
||||
String[] headerArrTwo = titleTwo.split(",");
|
||||
for (int j = 0; j < headerArrTwo.length; j++) {
|
||||
row.createCell(11+j).setCellValue(headerArrTwo[j]);
|
||||
}
|
||||
}else{
|
||||
short height = (short) (7 * 252);
|
||||
row.setHeight((short) height);
|
||||
Cell cell = row.createCell(0);
|
||||
cell.setCellStyle(cellStyleTemp);
|
||||
cell.setCellValue(new HSSFRichTextString(explain));
|
||||
}
|
||||
}
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment; filename=\"" + fileOriName + ".xls");
|
||||
response.setContentType("application/force-download");
|
||||
response.flushBuffer();
|
||||
os = response.getOutputStream();
|
||||
workbook.write(os);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new JeroBootException("下载文件失败,请重试");
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportData(HttpServletResponse response, HttpServletRequest request, ProjectLawsInventoryEO projectLawsInventoryEO) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importData(MultipartFile file, ProjectLawsInventoryEO projectLawsInventoryEO) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user