Merge remote-tracking branch 'origin/dev_2nd_LCYH' into dev_2nd_LCYH
This commit is contained in:
+9
@@ -13,8 +13,10 @@ import com.jero.modules.authDummy.service.IAuthDummyInventoryInfoEOService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.modules.dummy.entity.DummyInventoryInfoEO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -191,4 +193,11 @@ public class AuthDummyInventoryInfoEOController extends JeroController<AuthDummy
|
||||
public Result<?> batchAdd(@RequestBody JSONObject json) {
|
||||
return this.authDummyInventoryInfoEOService.batchAdd(json);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "模板下载")
|
||||
@GetMapping(value = "/exportTemplate")
|
||||
// @RequiresPermissions("authDummyInventoryInfo:exportTemplate")
|
||||
public void exportTemplate(AuthDummyInventoryInfoEO authDummyInventoryInfoEO, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||||
authDummyInventoryInfoEOService.exportTemplate(authDummyInventoryInfoEO,response,request);
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -4,6 +4,10 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.modules.authDummy.entity.AuthDummyInventoryInfoEO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.modules.dummy.entity.DummyInventoryInfoEO;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -82,4 +86,12 @@ public interface IAuthDummyInventoryInfoEOService extends IService<AuthDummyInve
|
||||
* @return
|
||||
*/
|
||||
Result<?> batchAdd(JSONObject json);
|
||||
|
||||
/**
|
||||
* 模板下载
|
||||
* @param authDummyInventoryInfoEO
|
||||
* @param response
|
||||
* @param request
|
||||
*/
|
||||
void exportTemplate(AuthDummyInventoryInfoEO authDummyInventoryInfoEO, HttpServletResponse response, HttpServletRequest request);
|
||||
}
|
||||
|
||||
+179
@@ -2,6 +2,7 @@ package com.jero.modules.authDummy.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyuncs.utils.IOUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
@@ -11,11 +12,24 @@ import com.jero.modules.authDummy.entity.AuthDummyInventoryInfoEO;
|
||||
import com.jero.modules.authDummy.mapper.AuthDummyInventoryInfoEOMapper;
|
||||
import com.jero.modules.authDummy.service.IAuthDummyInventoryBaseEOService;
|
||||
import com.jero.modules.authDummy.service.IAuthDummyInventoryInfoEOService;
|
||||
import com.jero.modules.dummy.entity.DummyInventoryInfoEO;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.util.*;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -23,6 +37,9 @@ import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @Description: 认证虚拟清单详情表
|
||||
* @Author: jero-boot
|
||||
@@ -36,6 +53,8 @@ public class AuthDummyInventoryInfoEOServiceImpl extends ServiceImpl<AuthDummyIn
|
||||
@Autowired
|
||||
private IAuthDummyInventoryBaseEOService authDummyInventoryBaseEOService;
|
||||
|
||||
@Value(value = "${jero.path.upload}")
|
||||
private String uploadpath;
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
@@ -222,4 +241,164 @@ public class AuthDummyInventoryInfoEOServiceImpl extends ServiceImpl<AuthDummyIn
|
||||
}
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板下载
|
||||
* @param authDummyInventoryInfoEO
|
||||
* @param response
|
||||
* @param request
|
||||
*/
|
||||
@Override
|
||||
public void exportTemplate(AuthDummyInventoryInfoEO authDummyInventoryInfoEO, 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(authDummyInventoryInfoEO.getCut())){
|
||||
// titleOne = "编号,子标题,实施类别," +
|
||||
// "WVTA ID,认证类型," +
|
||||
// "*认证级别," +"适用增补件,"+
|
||||
// "*责任领域,备注," +
|
||||
// "设计符合性确认,Pre-homo确认,验证符合性确认";
|
||||
titleOne="类别,检验项目," +
|
||||
"WVTA ID,编号," +
|
||||
"*责任领域,交付物";
|
||||
// titleTwo = "交付物类型,交付物模板,发起人,责任人,交付物说明," +
|
||||
// "交付物类型,交付物模板,发起人,责任人,交付物说明," +
|
||||
// "交付物类型,交付物模板,发起人,责任人,交付物说明";
|
||||
}else{
|
||||
// titleOne = "*Number,Sub-Title,Usage," +
|
||||
// "WVTA ID,Certification Type," +
|
||||
// "*Certification Level," +"Applicable Supplement,"+
|
||||
// "*Responsible Field,Comments," +
|
||||
// "Design compliance check,Pre-homo check,Validation compliance chech";
|
||||
titleOne = "Type,检验项目," +
|
||||
"WVTA ID,*Number," +
|
||||
"*Responsible Field,交付物";
|
||||
// titleTwo = "Type of deliverables,Deliverable template,Initiator,Person liable,Deliverables description," +
|
||||
// "Type of deliverables,Deliverable template,Initiator,Person liable,Deliverables description," +
|
||||
// "Type of deliverables,Deliverable template,Initiator,Person liable,Deliverables description";
|
||||
}
|
||||
|
||||
|
||||
List<String> list = Arrays.asList(titleOne.split(","));
|
||||
int index = 0;
|
||||
if(CutEnum.CN.getValue().equals(authDummyInventoryInfoEO.getCut())){
|
||||
index = list.indexOf("备注") + 1;
|
||||
}else{
|
||||
index = list.indexOf("Comments") + 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 < 12; 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, 23); //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列
|
||||
sheet.addMergedRegion(region);
|
||||
// String explain= "";
|
||||
// if(CutEnum.CN.getValue().equals(authDummyInventoryInfoEO.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.Implementation category,Type of deliverables,Initiator,Person liable,Fields are radio attributes that must match the corresponding field option in the system\n" +
|
||||
// "4.Certification Type,Certification Level,Responsible Field, 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.Number,Sub-Title,WVTA ID,Comments,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(9+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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user