|
@@ -3,6 +3,7 @@ package com.factory.controller.web;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.factory.base.entity.aggregates.ResponseBean;
|
|
|
import com.factory.base.util.res.ResponseBeanBuilder;
|
|
|
+import com.factory.web.entity.excel.Utility;
|
|
|
import com.factory.web.entity.fa.FirstArticleTitle;
|
|
|
import com.factory.web.entity.pm.OnsiteTitle;
|
|
|
import com.factory.web.entity.pm.OnsiteTitleBlob;
|
|
@@ -15,23 +16,38 @@ import com.factory.web.service.impl.FileServiceImpl;
|
|
|
import com.factory.web.service.pm.OnsiteTitleBlobService;
|
|
|
import com.factory.web.service.pm.PreventMistakeService;
|
|
|
|
|
|
+import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+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.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.BufferedInputStream;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.OutputStream;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.*;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
@Api(tags = "本特勒 - 附件上传下载")
|
|
@@ -45,13 +61,12 @@ public class FileBlobController {
|
|
|
private OnsiteTitleBlobService blobService;
|
|
|
|
|
|
@Autowired
|
|
|
- private PreventMistakeService preventMistakeService;
|
|
|
+ private PreventMistakeService preventMistakeService;
|
|
|
|
|
|
@Autowired
|
|
|
private FirstArticleService firstArticleService;
|
|
|
|
|
|
|
|
|
-
|
|
|
@PostMapping("/addFile")
|
|
|
@ApiOperation(value = "上传附件-附件参数名称file")
|
|
|
public ResponseBean addFile(@RequestParam("file") MultipartFile file) throws IOException {
|
|
@@ -75,16 +90,17 @@ public class FileBlobController {
|
|
|
|
|
|
long id = -1;
|
|
|
if (param.getType() == 2) {
|
|
|
- OnsiteTitle onsiteTitle = preventMistakeService.getTitle(param.getPlanId());
|
|
|
- id = Long.parseLong(onsiteTitle.getUploadAttachmentId());
|
|
|
+ OnsiteTitle onsiteTitle = preventMistakeService.getTitle(param.getPlanId());
|
|
|
+ id = Long.parseLong(onsiteTitle.getUploadAttachmentId());
|
|
|
} else {
|
|
|
- FirstArticleTitle title=firstArticleService.getFaTitle(param.getPlanId());
|
|
|
+ FirstArticleTitle title = firstArticleService.getFaTitle(param.getPlanId());
|
|
|
id = Long.parseLong(title.getUploadAttachmentId());
|
|
|
}
|
|
|
|
|
|
download(id, response);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void download(long id, HttpServletResponse response) {
|
|
|
FileEntry file = fileService.getById(id);
|
|
|
byte[] buff = null;
|
|
@@ -127,6 +143,209 @@ public class FileBlobController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) throws IOException {
|
|
|
+// System.out.println(LocalDate.now().getDayOfMonth());
|
|
|
+
|
|
|
+ Workbook wb = new SXSSFWorkbook(500);
|
|
|
+ Sheet sheet = Utility.createSheet(wb, "纠错检查");
|
|
|
+ XSSFCellStyle cellStyle = Utility.getTitleCellStyle(wb);
|
|
|
+ XSSFCellStyle cellStyleLeft = Utility.getTitleCellLeftStyle(wb,(short)10);
|
|
|
+
|
|
|
+ FileInputStream in = new FileInputStream(new File("/Users/hisoka/Downloads/ben.png"));
|
|
|
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
+ byte[] b = new byte[1024];
|
|
|
+ int len = -1;
|
|
|
+ while ((len = in.read(b)) != -1) {
|
|
|
+ bos.write(b, 0, len);
|
|
|
+ }
|
|
|
+ ByteArrayInputStream inb = new ByteArrayInputStream(bos.toByteArray()); //将b作为输入流;
|
|
|
+ BufferedImage bufferImg = ImageIO.read(inb);
|
|
|
+ String[] data = new String[]{"Benteler Automotive (shenyang) Co. , Ltd",
|
|
|
+ "Pokayoke Checking Sheet for Production",
|
|
|
+ "模板编号: T.0702.Eng.022.An.02\n" +
|
|
|
+ "发布日期: 2020-10-26\n" +
|
|
|
+ "模板版本: 11\n" +
|
|
|
+ "部门:工程部\n" +
|
|
|
+ "上一版本: 2019-11-01"
|
|
|
+ };
|
|
|
+ createTitle1(wb, sheet, cellStyle, 0, data, bufferImg);
|
|
|
+ data = new String[]{"{companyName}",
|
|
|
+ "{name}"
|
|
|
+ };
|
|
|
+ createTitle2(sheet, cellStyle, 1, data);
|
|
|
+ data = new String[]{"Production line: {productionLine}",
|
|
|
+ "Shift:{shift}",
|
|
|
+ "Setter/Jumper:{setter}",
|
|
|
+ "Year:{year}",
|
|
|
+ "Month:{month}"
|
|
|
+ };
|
|
|
+ createTitle3(sheet, cellStyle, 2, data);
|
|
|
+ createItemInfoTitle(sheet, cellStyle, 3);
|
|
|
+ data = new String[]{"点检负责人", "", ""};
|
|
|
+ createOperaterTitle(sheet, cellStyle, 5, data);
|
|
|
+
|
|
|
+ data=new String[]{"防错点检在每班开班后按规定频次进行,防错点检不合格,不允许进行批量生产。防错系统维修后,需重新进行防错点检;若防错短时间内无法修复,需填写特殊放行申请《0702,QM,201-2》及按照不合格品管理流程进行追溯。\n" +
|
|
|
+ "检查结果记录方法The Method of filling form: 符合: 打√ 不符合打×, 立即通知倒班主任及维修人员,在点检表背面记录异常。"};
|
|
|
+ createTitle4(sheet, cellStyleLeft, 6, data);
|
|
|
+ data = new String[]{"Edited By: {editedBy}", "Checked By:{checkedBy}", "Approved By:{approvedBy}"};
|
|
|
+ createTitle5(sheet, cellStyle, 7, data);
|
|
|
+ FileOutputStream out = new FileOutputStream("/Users/hisoka/Downloads/1.xlsx");
|
|
|
+ wb.write(out);
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param sheet
|
|
|
+ * @param cellStyle
|
|
|
+ * @param rowIndex
|
|
|
+ * @param data
|
|
|
+ */
|
|
|
+ private static void createTitle1(Workbook wb, Sheet sheet, XSSFCellStyle cellStyle, int rowIndex, String[] data, BufferedImage bufferImg) throws IOException {
|
|
|
+ Row row = sheet.createRow(rowIndex);
|
|
|
+ row.setHeight((short) (34 * 20));
|
|
|
+ CellRangeAddress cra = new CellRangeAddress(rowIndex, rowIndex, 0, 2);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 3, 20);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex + 1, 21, 27);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex + 1, 28, 36);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ for (int i = 0; i < 37; i++) {
|
|
|
+ row.createCell(i).setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ Utility.addCellValForStr(row.getCell(0), data[0], cellStyle);
|
|
|
+ Utility.addCellValForStr(row.getCell(3), data[1], Utility.getTitleCellStyle(wb, (short) 15));
|
|
|
+ Utility.addCellValForStr(row.getCell(21), data[2], cellStyle);
|
|
|
+
|
|
|
+ ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
|
+ // 将图片写入流中
|
|
|
+ ImageIO.write(bufferImg, "png", byteArrayOut);
|
|
|
+ // 利用HSSFPatriarch将图片写入EXCEL
|
|
|
+ XSSFDrawing patriarch = (XSSFDrawing) sheet.createDrawingPatriarch();
|
|
|
+ //图片一导出到单元格B2中
|
|
|
+ XSSFClientAnchor anchor = new XSSFClientAnchor(10, 10, 255, 255,
|
|
|
+ (short) 28, 0, (short) 36, 2);
|
|
|
+ // 插入图片
|
|
|
+ patriarch.createPicture(anchor, wb.addPicture(byteArrayOut
|
|
|
+ .toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG));
|
|
|
+ byteArrayOut.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void createTitle2(Sheet sheet, XSSFCellStyle cellStyle, int rowIndex, String[] data) {
|
|
|
+ Row row = sheet.createRow(rowIndex);
|
|
|
+ row.setHeight((short) (39.5 * 20));
|
|
|
+ CellRangeAddress cra = new CellRangeAddress(rowIndex, rowIndex, 0, 2);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 3, 20);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ for (int i = 0; i < 37; i++) {
|
|
|
+ row.createCell(i).setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static void createTitle3(Sheet sheet, XSSFCellStyle cellStyle, int rowIndex, String[] data) {
|
|
|
+ Row row = sheet.createRow(rowIndex);
|
|
|
+ row.setHeight((short) (25.5 * 20));
|
|
|
+ CellRangeAddress cra = new CellRangeAddress(rowIndex, rowIndex, 0, 2);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 3, 6);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 7, 20);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 21, 27);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 28, 36);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ for (int i = 0; i < 37; i++) {
|
|
|
+ row.createCell(i).setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ Utility.addCellValForStr(row.getCell(0), data[0], cellStyle);
|
|
|
+ Utility.addCellValForStr(row.getCell(3), data[1], cellStyle);
|
|
|
+ Utility.addCellValForStr(row.getCell(7), data[2], cellStyle);
|
|
|
+ Utility.addCellValForStr(row.getCell(21), data[3], cellStyle);
|
|
|
+ Utility.addCellValForStr(row.getCell(28), data[4], cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void createTitle4(Sheet sheet, XSSFCellStyle cellStyle, int rowIndex, String[] data) {
|
|
|
+ Row row = sheet.createRow(rowIndex);
|
|
|
+ row.setHeight((short) (33.25 * 20));
|
|
|
+ CellRangeAddress cra = new CellRangeAddress(rowIndex, rowIndex, 0, 36);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ for (int i = 0; i < 37; i++) {
|
|
|
+ row.createCell(i).setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ Utility.addCellValForStr(row.getCell(0), data[0], cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void createTitle5(Sheet sheet, XSSFCellStyle cellStyle, int rowIndex, String[] data) {
|
|
|
+ Row row = sheet.createRow(rowIndex);
|
|
|
+ row.setHeight((short) (25 * 20));
|
|
|
+ CellRangeAddress cra = new CellRangeAddress(rowIndex, rowIndex, 0, 5);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 6, 21);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 22, 36);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ for (int i = 0; i < 37; i++) {
|
|
|
+ row.createCell(i).setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ Utility.addCellValForStr(row.getCell(0), data[0], cellStyle);
|
|
|
+ Utility.addCellValForStr(row.getCell(6), data[1], cellStyle);
|
|
|
+ Utility.addCellValForStr(row.getCell(22), data[2], cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static void createOperaterTitle(Sheet sheet, XSSFCellStyle cellStyle, int rowIndex, String[] data) {
|
|
|
+ Row row = sheet.createRow(rowIndex);
|
|
|
+ row.setHeight((short) (25 * 20));
|
|
|
+ CellRangeAddress cra = new CellRangeAddress(rowIndex, rowIndex, 0, 2);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 3, 18);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 19, 33);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ cra = new CellRangeAddress(rowIndex, rowIndex, 34, 36);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+
|
|
|
+ for (int i = 0; i < 37; i++) {
|
|
|
+ row.createCell(i).setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ Utility.addCellValForStr(row.getCell(0), data[0], cellStyle);
|
|
|
+ Utility.addCellValForStr(row.getCell(3), data[1], cellStyle);
|
|
|
+ Utility.addCellValForStr(row.getCell(19), data[2], cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void createItemInfoTitle(Sheet sheet, XSSFCellStyle cellStyle, int rowIndex) {
|
|
|
+ List<String> head = new ArrayList<>();
|
|
|
+ HashMap<Integer, Integer> cwMap = new HashMap<>();
|
|
|
+ head.addAll(Arrays.asList("频次", "OP", "点检内容"));
|
|
|
+ cwMap.put(0, (short) 6.6 * 256);
|
|
|
+ cwMap.put(1, (short) 6.6 * 256);
|
|
|
+ cwMap.put(2, (short) 38.7 * 256);
|
|
|
+ for (int i = 1; i <= 31; i++) {
|
|
|
+ head.add(i + "");
|
|
|
+ cwMap.put(i + 2, (short) 4 * 256);
|
|
|
+ }
|
|
|
+ head.add("防错维修后点检");
|
|
|
+ cwMap.put(34, (short) 8 * 256);
|
|
|
+ cwMap.put(35, (short) 8 * 256);
|
|
|
+ cwMap.put(36, (short) 3.5 * 256);
|
|
|
+ CellRangeAddress cra = new CellRangeAddress(rowIndex, rowIndex, 34, 36);
|
|
|
+ sheet.addMergedRegion(cra);
|
|
|
+ Row row = sheet.createRow(rowIndex);
|
|
|
+ row.setHeight((short) (23.75 * 20));
|
|
|
+ for (int i = 0; i < head.size() + 2; i++) {
|
|
|
+ sheet.setColumnWidth((short) i, (short) cwMap.get(i).intValue());
|
|
|
+ row.createCell(i).setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < head.size(); i++) {
|
|
|
+ Utility.addCellValForStr(row.getCell(i), head.get(i), cellStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// @GetMapping("/addIniPlan")
|
|
|
// public void addIniPlan(HttpServletRequest request) {
|
|
|
//
|