烘房统计报表+产品追溯

master
zhaoxiaolin 6 months ago
parent 0aafe49643
commit 2cf6bef0ef

@ -0,0 +1,504 @@
package com.op.common.core.utils.poi;
import com.alibaba.fastjson2.JSONObject;
import com.op.common.core.domain.ExcelCol;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Excel
*
* @author OP
*/
public class ExcelSCXJReportMapUtil {
//下载
public static <T> SXSSFWorkbook initWorkbook(String sheetName , String title, List<ExcelCol> excelCol , List<T> data, Map<String,String> detailMap,String shiftId) throws IOException {
SXSSFWorkbook workbook = new SXSSFWorkbook();
int colSize = excelCol.size();
//创建Sheet工作簿
Sheet sheet = null;
if (!StringUtils.hasText(sheetName)){
sheet = workbook.createSheet();
}else{
sheet = workbook.createSheet(sheetName);
}
//单元格宽度
for(int md=0;md<14;md++){
if(md==1){
sheet.setColumnWidth(md, 6000);
}else if(md>1){
sheet.setColumnWidth(md, 4000);
}
}
// 从resources目录获取图片字节数组
byte[] imageBytes = getImageBytesFromResources("image/logo.png");
/**logo**/
int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG);
CreationHelper helper = workbook.getCreationHelper();
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(0); // B列
anchor.setRow1(0); // 第2行Excel的行和列都是从0开始计数的
anchor.setCol2(1); // C列图片宽度跨越的列数这里设置为1列宽
anchor.setRow2(2); // 第6行图片高度跨越的行数这里设置为4行高可以根据图片大小调整
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize(); // 根据图片的实际大小调整图片在Excel中的显示大小
/**报告标题**/
sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 13));
// 获取合并后的单元格的第一个单元格即C1并设置值
Row row1 = sheet.getRow(0); // 获取第1行索引为0
if (row1 == null) {row1 = sheet.createRow(0); // 如果第1行不存在则创建它
}
Cell cell = row1.getCell(2); // 获取C列索引为2的单元格
if (cell == null) {
cell = row1.createCell(2); // 如果C列的单元格不存在则创建它
}
cell.setCellValue("中山榄菊日化实业有限公司"); // 设置单元格的值
cell.setCellStyle(getTitelStyle(workbook)); // 应用样式到单元格
/**报告二级标题、检验标准**/
// 合并C3到I4的单元格并设置样式
mergeAndStyleCellsNoBorder(sheet, new CellRangeAddress(2, 3, 2, 9), detailMap.get("title"));
// 合并J3到L4的单元格并设置样式
mergeAndStyleCellsNoBorder(sheet, new CellRangeAddress(2, 3, 10, 12), "编码"+detailMap.get("standardNo"));
/**左右表格1**/
//画边框
for(int r5=4;r5<12;r5++){
Row row05 = sheet.getRow(r5);
if (row05 == null) {row05 = sheet.createRow(r5);}
for (int col = 0; col < 14; col++) {
Cell cell1 = row05.createCell(col);
cell1.setCellStyle(getRowStyle(sheet));
}
}
for(int d5=12;d5<(12+data.size());d5++){
Row row05 = sheet.getRow(d5);
if (row05 == null) {row05 = sheet.createRow(d5);}
for (int col = 0; col < 14; col++) {
Cell cell1 = row05.createCell(col);
cell1.setCellStyle(getDataStyle(sheet));
}
}
Row row5 = sheet.getRow(4);
// 合并A5到B6的单元格并设置样式和内容
mergeAndStyleCells2(sheet,row5, new CellRangeAddress(4, 5, 0, 1), "生产车间/线体", true, true, IndexedColors.GREY_25_PERCENT);
// 合并C5到D6的单元格并设置样式无背景色只有边框和内容居中
mergeAndStyleCells2(sheet,row5, new CellRangeAddress(4, 5, 2, 3), detailMap.get("supplierName")+"/"+detailMap.get("checkLoc"), true, false, null);
// 合并J5到K6的单元格并设置样式和内容
mergeAndStyleCells2(sheet,row5, new CellRangeAddress(4, 5, 4, 4), "产品名称", true, true, IndexedColors.GREY_25_PERCENT);
// 合并L5到N6的单元格并设置样式无背景色只有边框和内容居中
mergeAndStyleCells2(sheet,row5, new CellRangeAddress(4, 5, 5, 8), detailMap.get("materialName"), true, false, null);
mergeAndStyleCells2(sheet,row5, new CellRangeAddress(4, 5, 9, 10), "生产类型", true, true, IndexedColors.GREY_25_PERCENT);
// 合并C5到D6的单元格并设置样式无背景色只有边框和内容居中
mergeAndStyleCells2(sheet,row5, new CellRangeAddress(4, 5, 11, 13), detailMap.get("productType"), true, false, null);
Row row7 = sheet.getRow(6);
// 合并A7到B8的单元格并设置样式和内容
mergeAndStyleCells2(sheet,row7, new CellRangeAddress(6, 7, 0, 1), "检验时间", true, true, IndexedColors.GREY_25_PERCENT);
// 合并C5到D6的单元格并设置样式无背景色只有边框和内容居中
mergeAndStyleCells2(sheet,row7, new CellRangeAddress(6, 7, 2, 3), detailMap.get("incomeTime"), true, false, null);
// 合并E5到F6的单元格并设置样式和内容
mergeAndStyleCells2(sheet,row7, new CellRangeAddress(6, 7, 4, 4), "生产批次", true, true, IndexedColors.GREY_25_PERCENT);
// 合并G5到I6的单元格并设置样式无背景色只有边框和内容居中
mergeAndStyleCells2(sheet,row7, new CellRangeAddress(6, 7, 5, 13), detailMap.get("incomeBatchNo"), true, false, null);
/**上下表格2**///-------------------------------------------------
mergeAndStyleCells(sheet, new CellRangeAddress(8, 9, 0, 0), "序号");
mergeAndStyleCells(sheet, new CellRangeAddress(8, 9, 1, 1), "项目名称");
//画时间区间
if("5".equals(shiftId)){
mergeAndStyleCells(sheet, new CellRangeAddress(8, 8, 2, 5), "上午");
mergeAndStyleCells(sheet, new CellRangeAddress(8, 8, 6, 9), "下午");
mergeAndStyleCells(sheet, new CellRangeAddress(8, 8, 10, 13), "加班");
drawDatatimeDay(sheet);
}else{
mergeAndStyleCells(sheet, new CellRangeAddress(8, 8, 2, 13), "时间");
drawDatatimeNight(sheet);
}
//将data中的值填充到excel
int rowNum = 10;
if(!CollectionUtils.isEmpty(data)){
Iterator<T> iterator = data.iterator();
//遍历数据
for (;iterator.hasNext();){
T obj = iterator.next();//获取当前行对应的数据
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(obj));
Row dataRow = sheet.getRow(rowNum);//创建行
// 假设使用了默认字体和字符宽度来计算行高(这是一个简化的示例)
int cellHeight = (int) (cell.getStringCellValue().length() * 6); // 每个字符大约15个单位高度
dataRow.setHeightInPoints(Math.max(dataRow.getHeightInPoints(), cellHeight));
Cell cellData0 = dataRow.getCell(0);
cellData0.setCellValue(getValue(jsonObject.get(excelCol.get(0).getField())));
cellData0.setCellStyle(getDataStyle(sheet));
Cell cellData1 = dataRow.getCell(1);
cellData1.setCellValue(getValue(jsonObject.get(excelCol.get(1).getField())));
cellData1.setCellStyle(getDataStyle(sheet));
Cell cellData2 = dataRow.getCell(2);
cellData2.setCellValue(getValue(jsonObject.get(excelCol.get(2).getField())));
cellData2.setCellStyle(getDataStyle(sheet));
Cell cellData3 = dataRow.getCell(3);
cellData3.setCellValue(getValue(jsonObject.get(excelCol.get(3).getField())));
cellData3.setCellStyle(getDataStyle(sheet));
Cell cellData4 = dataRow.getCell(4);
cellData4.setCellValue(getValue(jsonObject.get(excelCol.get(4).getField())));
cellData4.setCellStyle(getDataStyle(sheet));
Cell cellData5 = dataRow.getCell(5);
cellData5.setCellValue(getValue(jsonObject.get(excelCol.get(5).getField())));
cellData5.setCellStyle(getDataStyle(sheet));
Cell cellData6 = dataRow.getCell(6);
cellData6.setCellValue(getValue(jsonObject.get(excelCol.get(6).getField())));
cellData6.setCellStyle(getDataStyle(sheet));
Cell cellData7 = dataRow.getCell(7);
cellData7.setCellValue(getValue(jsonObject.get(excelCol.get(7).getField())));
cellData7.setCellStyle(getDataStyle(sheet));
Cell cellData8 = dataRow.getCell(8);
cellData8.setCellValue(getValue(jsonObject.get(excelCol.get(8).getField())));
cellData8.setCellStyle(getDataStyle(sheet));
Cell cellData9 = dataRow.getCell(9);
cellData9.setCellValue(getValue(jsonObject.get(excelCol.get(9).getField())));
cellData9.setCellStyle(getDataStyle(sheet));
Cell cellData10 = dataRow.getCell(10);
cellData10.setCellValue(getValue(jsonObject.get(excelCol.get(10).getField())));
cellData10.setCellStyle(getDataStyle(sheet));
Cell cellData11 = dataRow.getCell(11);
cellData11.setCellValue(getValue(jsonObject.get(excelCol.get(11).getField())));
cellData11.setCellStyle(getDataStyle(sheet));
Cell cellData12 = dataRow.getCell(12);
cellData12.setCellValue(getValue(jsonObject.get(excelCol.get(12).getField())));
cellData12.setCellStyle(getDataStyle(sheet));
if("5".equals(shiftId)){
Cell cellData13 = dataRow.getCell(13);
cellData13.setCellValue(getValue(jsonObject.get(excelCol.get(13).getField())));
cellData13.setCellStyle(getDataStyle(sheet));
}
iterator.remove();
rowNum++;
}
}
//合并
Row rowEnd0 = sheet.createRow(rowNum);
mergeAndStyleCellsNoBorder(sheet,rowEnd0, new CellRangeAddress(rowNum, rowNum+1, 0, 3), "批量或致命性质量异常", true, true, IndexedColors.GREY_25_PERCENT);
mergeAndStyleCellsNoBorder(sheet,rowEnd0, new CellRangeAddress(rowNum, rowNum+1, 4, 13), detailMap.get("remark"), true, true,null);
Row rowEnd1 = sheet.createRow(rowNum+2);
mergeAndStyleCellsNoBorder(sheet,rowEnd1, new CellRangeAddress(rowNum+2, rowNum+3, 0, 6), "备注:无异常的打√,有异常的描述异常及数量比例,有数据的需要填写数据", true, true, IndexedColors.GREY_25_PERCENT);
mergeAndStyleCells(sheet, new CellRangeAddress(rowNum+2, rowNum+3, 7, 7), "说明");
mergeAndStyleCellsNoBorder(sheet,rowEnd1, new CellRangeAddress(rowNum+2, rowNum+3, 8, 13), "", true, true, null);
Row rowEnd2 = sheet.createRow(rowNum+5);
mergeAndStyleCellsNoBorder(sheet,rowEnd2, new CellRangeAddress(rowNum+5, rowNum+5, 0, 1), "检查人", true, true, IndexedColors.GREY_25_PERCENT);
mergeAndStyleCellsNoBorder(sheet,rowEnd2, new CellRangeAddress(rowNum+5, rowNum+5, 2, 3), detailMap.get("checkManName"), true, true,null);
mergeAndStyleCellsNoBorder(sheet,rowEnd2, new CellRangeAddress(rowNum+5, rowNum+5, 7, 8), "品质主管", true, true, IndexedColors.GREY_25_PERCENT);
return workbook;
}
//处理数据
public static String getValue(Object object){
if (object==null){
return "";
}else {
return object.toString();
}
}
// //处理数据
// public static Integer getValueNum(Object object){
// if (object==null){
// return 0;
// }else {
// return Integer.parseInt(object.toString());
// }
// }
// 从resources目录获取图片的字节数组
private static byte[] getImageBytesFromResources(String resourceName) {
try (InputStream inputStream = ExcelSCXJReportMapUtil.class.getClassLoader().getResourceAsStream(resourceName);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
if (inputStream == null) {
throw new RuntimeException("找不到资源: " + resourceName);
}
IOUtils.copy(inputStream, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (IOException e) {
throw new RuntimeException("读取资源时出错: " + resourceName, e);
}
}
//报告大标题样式-1
public static CellStyle getTitelStyle(Workbook workbook){
Font font = workbook.createFont();
// 设置字体为加粗
font.setBold(true);
// 设置字体大小例如设置为16
font.setFontHeightInPoints((short) 24);
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFont(font);
cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);//设置水平居中
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//设置垂直居中
cellStyle.setWrapText(true);//设置单元格内容自动换行
return cellStyle;
}
public static CellStyle getRowStyle(Sheet sheet){
CellStyle style = sheet.getWorkbook().createCellStyle();
// 设置边框线
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
// 设置水平居中
style.setAlignment(HorizontalAlignment.CENTER);
style.setWrapText(true);//设置单元格内容自动换行
// 设置垂直居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
Font font = sheet.getWorkbook().createFont();
font.setBold(true);
// 设置字体大小例如设置为14
font.setFontHeightInPoints((short) 14);
style.setFont(font);
return style;
}
public static CellStyle getDataStyle(Sheet sheet){
CellStyle style = sheet.getWorkbook().createCellStyle();
// 设置边框线
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
Font font = sheet.getWorkbook().createFont();
// 设置字体大小例如设置为14
font.setFontHeightInPoints((short) 14);
style.setFont(font);
style.setWrapText(true);//设置单元格内容自动换行
// 设置水平居中
style.setAlignment(HorizontalAlignment.LEFT);
// 设置垂直居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
private static void mergeAndStyleCells(Sheet sheet, CellRangeAddress cellRangeAddress, String cellValue) {
// 合并单元格
sheet.addMergedRegion(cellRangeAddress);
// 创建一个单元格样式
CellStyle style = sheet.getWorkbook().createCellStyle();
// 设置字体为加粗
Font font = sheet.getWorkbook().createFont();
font.setBold(true);
// 设置字体大小例如设置为14
font.setFontHeightInPoints((short) 14);
style.setFont(font);
// 设置边框线
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
// 设置水平居中
style.setAlignment(HorizontalAlignment.CENTER);
// 设置垂直居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setWrapText(true);//设置单元格内容自动换行
// 获取合并后的单元格的第一个单元格,并设置值
Row row = sheet.getRow(cellRangeAddress.getFirstRow());
if (row == null) {
row = sheet.createRow(cellRangeAddress.getFirstRow());
}
Cell cell = row.getCell(cellRangeAddress.getFirstColumn());
if (cell == null) {
cell = row.createCell(cellRangeAddress.getFirstColumn());
}
cell.setCellValue(cellValue); // 设置单元格的值
cell.setCellStyle(style); // 应用样式到单元格
}
private static void mergeAndStyleCellsNoBorder(Sheet sheet, CellRangeAddress cellRangeAddress, String cellValue) {
// 合并单元格
sheet.addMergedRegion(cellRangeAddress);
// 创建一个单元格样式
CellStyle style = sheet.getWorkbook().createCellStyle();
// 设置字体为加粗
Font font = sheet.getWorkbook().createFont();
font.setBold(true);
// 设置字体大小例如设置为14
font.setFontHeightInPoints((short) 14);
style.setFont(font);
// 设置水平居中
style.setAlignment(HorizontalAlignment.CENTER);
// 设置垂直居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setWrapText(true);//设置单元格内容自动换行
// 获取合并后的单元格的第一个单元格,并设置值
Row row = sheet.getRow(cellRangeAddress.getFirstRow());
if (row == null) {
row = sheet.createRow(cellRangeAddress.getFirstRow());
}
Cell cell = row.getCell(cellRangeAddress.getFirstColumn());
if (cell == null) {
cell = row.createCell(cellRangeAddress.getFirstColumn());
}
cell.setCellValue(cellValue); // 设置单元格的值
cell.setCellStyle(style); // 应用样式到单元格
}
private static void mergeAndStyleCells2(Sheet sheet,Row row, CellRangeAddress cellRangeAddress, String cellValue, boolean centered, boolean hasBackground, IndexedColors backgroundColor) {
// 合并单元格
sheet.addMergedRegion(cellRangeAddress);
// 创建一个单元格样式
CellStyle style = sheet.getWorkbook().createCellStyle();
// 设置边框线
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
// 设置字体居中
if (centered) {
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
}
// 设置背景颜色(如果有)
if (hasBackground && backgroundColor != null) {
style.setFillForegroundColor(backgroundColor.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
}
// 获取合并后的单元格的第一个单元格,并设置值
Cell cell = row.getCell(cellRangeAddress.getFirstColumn());
if (cell == null) {
cell = row.createCell(cellRangeAddress.getFirstColumn());
}
cell.setCellValue(cellValue); // 设置单元格的值
cell.setCellStyle(style); // 应用样式到单元格
}
private static void mergeAndStyleCellsNoBorder(Sheet sheet,Row row, CellRangeAddress cellRangeAddress, String cellValue, boolean centered, boolean hasBackground, IndexedColors backgroundColor) {
// 合并单元格
sheet.addMergedRegion(cellRangeAddress);
// 创建一个单元格样式
CellStyle style = sheet.getWorkbook().createCellStyle();
// 设置字体居中
if (centered) {
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
}
// 设置背景颜色(如果有)
if (hasBackground && backgroundColor != null) {
style.setFillForegroundColor(backgroundColor.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
}
// 获取合并后的单元格的第一个单元格,并设置值
Cell cell = row.getCell(cellRangeAddress.getFirstColumn());
if (cell == null) {
cell = row.createCell(cellRangeAddress.getFirstColumn());
}
cell.setCellValue(cellValue); // 设置单元格的值
cell.setCellStyle(style); // 应用样式到单元格
}
//白班
private static void drawDatatimeDay(Sheet sheet){
Row dataTR1 = sheet.getRow(9);
if (dataTR1 == null) {dataTR1 = sheet.createRow(9);}
Cell dataTC1 = dataTR1.createCell(2);
dataTC1.setCellValue("8:00-9:00");
dataTC1.setCellStyle(getRowStyle(sheet));
Cell dataTC2 = dataTR1.createCell(3);
dataTC2.setCellValue("9:00-10:00");
dataTC2.setCellStyle(getRowStyle(sheet));
Cell dataTC3 = dataTR1.createCell(4);
dataTC3.setCellValue("10:00-11:00");
dataTC3.setCellStyle(getRowStyle(sheet));
Cell dataTC4 = dataTR1.createCell(5);
dataTC4.setCellValue("11:00-12:00");
dataTC4.setCellStyle(getRowStyle(sheet));
Cell dataTC5 = dataTR1.createCell(6);
dataTC5.setCellValue("13:30-14:30");
dataTC5.setCellStyle(getRowStyle(sheet));
Cell dataTC6 = dataTR1.createCell(7);
dataTC6.setCellValue("14:30-15:30");
dataTC6.setCellStyle(getRowStyle(sheet));
Cell dataTC7 = dataTR1.createCell(8);
dataTC7.setCellValue("15:30-16:30");
dataTC7.setCellStyle(getRowStyle(sheet));
Cell dataTC8 = dataTR1.createCell(9);
dataTC8.setCellValue("16:30-17:30");
dataTC8.setCellStyle(getRowStyle(sheet));
Cell dataTC9 = dataTR1.createCell(10);
dataTC9.setCellValue("12:30-13:30");
dataTC9.setCellStyle(getRowStyle(sheet));
Cell dataTC10 = dataTR1.createCell(11);
dataTC10.setCellValue("18:00-19:00");
dataTC10.setCellStyle(getRowStyle(sheet));
Cell dataTC11 = dataTR1.createCell(12);
dataTC11.setCellValue("19:00-20:00");
dataTC11.setCellStyle(getRowStyle(sheet));
Cell dataTC12 = dataTR1.createCell(13);
dataTC12.setCellValue("20:00-21:00");
dataTC12.setCellStyle(getRowStyle(sheet));
}
//白班
private static void drawDatatimeNight(Sheet sheet){
Row dataTR1 = sheet.getRow(9);
if (dataTR1 == null) {dataTR1 = sheet.createRow(9);}
Cell dataTC1 = dataTR1.createCell(2);
dataTC1.setCellValue("20:30-21:30");
dataTC1.setCellStyle(getRowStyle(sheet));
Cell dataTC2 = dataTR1.createCell(3);
dataTC2.setCellValue("21:30-22:30");
dataTC2.setCellStyle(getRowStyle(sheet));
Cell dataTC3 = dataTR1.createCell(4);
dataTC3.setCellValue("22:30-23:30");
dataTC3.setCellStyle(getRowStyle(sheet));
Cell dataTC4 = dataTR1.createCell(5);
dataTC4.setCellValue("23:30-1:30");
dataTC4.setCellStyle(getRowStyle(sheet));
Cell dataTC5 = dataTR1.createCell(6);
dataTC5.setCellValue("1:30-2:30");
dataTC5.setCellStyle(getRowStyle(sheet));
Cell dataTC6 = dataTR1.createCell(7);
dataTC6.setCellValue("2:30-3:30");
dataTC6.setCellStyle(getRowStyle(sheet));
Cell dataTC7 = dataTR1.createCell(8);
dataTC7.setCellValue("3:30-4:30");
dataTC7.setCellStyle(getRowStyle(sheet));
Cell dataTC8 = dataTR1.createCell(9);
dataTC8.setCellValue("4:30-5:30");
dataTC8.setCellStyle(getRowStyle(sheet));
Cell dataTC9 = dataTR1.createCell(10);
dataTC9.setCellValue("5:30-6:30");
dataTC9.setCellStyle(getRowStyle(sheet));
Cell dataTC10 = dataTR1.createCell(11);
dataTC10.setCellValue("6:30-7:30");
dataTC10.setCellStyle(getRowStyle(sheet));
Cell dataTC11 = dataTR1.createCell(12);
dataTC11.setCellValue("7:30-8:30");
dataTC11.setCellStyle(getRowStyle(sheet));
Cell dataTC12 = dataTR1.createCell(13);
}
}

@ -88,6 +88,11 @@ public class MesReportWorksController extends BaseController {
}
/**烘房产量统计**/
@GetMapping("/getHFProductionTitle")
public List<DynamicColumnVo> getHFProductionTitle(HFProduction dto) {
List<DynamicColumnVo> list = mesReportWorksService.getHFProductionTitle(dto);
return list;
}
@GetMapping("/getHFProductionList")
public List<Map<String, Object>> getHFProductionList(HFProduction dto) {
List<DynamicColumnVo> equNames = this.getHFProductionTitle(dto);
@ -95,11 +100,6 @@ public class MesReportWorksController extends BaseController {
List<Map<String, Object>> list = mesReportWorksService.getHFProductionList(dto);
return list;
}
@GetMapping("/getHFProductionTitle")
public List<DynamicColumnVo> getHFProductionTitle(HFProduction dto) {
List<DynamicColumnVo> list = mesReportWorksService.getHFProductionTitle(dto);
return list;
}
@PostMapping("/getHFProductionExport")
public void getHFProductionExport(HttpServletResponse response,HFProduction dto) {
List<DynamicColumnVo> equNames = this.getHFProductionTitle(dto);
@ -116,6 +116,52 @@ public class MesReportWorksController extends BaseController {
String titleName = "烘房产量统计报表";
SXSSFWorkbook workbook = null;
try {
//设置响应头
response.setHeader("Content-disposition",
"attachment; filename="+ titleName);
response.setContentType("application/octet-stream;charset=UTF-8");
ServletOutputStream outputStream = response.getOutputStream();
//调用工具类
workbook = ExcelMapUtil.initWorkbook(titleName, null, excelCols, list);
workbook.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}finally {
if (workbook!=null){
workbook.dispose();
}
}
}
/**成型机产量统计**/
@GetMapping("/getCXJProductionTitle")
public List<DynamicColumnVo> getCXJProductionTitle(HFProduction dto) {
List<DynamicColumnVo> list = mesReportWorksService.getCXJProductionTitle(dto);
return list;
}
@GetMapping("/getCXJProductionList")
public List<Map<String, Object>> getCXJProductionList(HFProduction dto) {
List<DynamicColumnVo> equNames = this.getCXJProductionTitle(dto);
dto.setEquNames(equNames);
List<Map<String, Object>> list = mesReportWorksService.getCXJProductionList(dto);
return list;
}
@PostMapping("/getCXJProductionExport")
public void getCXJProductionExport(HttpServletResponse response,HFProduction dto) {
List<DynamicColumnVo> equNames = this.getCXJProductionTitle(dto);
dto.setEquNames(equNames);
List<Map<String, Object>> list = mesReportWorksService.getCXJProductionList(dto);
ArrayList<ExcelCol> excelCols = new ArrayList<>();
excelCols.add(new ExcelCol("日期","ymd",20));
for (DynamicColumnVo column : equNames) {
excelCols.add(new ExcelCol(column.getLabel(), column.getCode(), 20));
}
excelCols.add(new ExcelCol("总产量","totalQuantity",20));
String titleName = "成型机产量统计报表";
SXSSFWorkbook workbook = null;
try {
//设置响应头
response.setHeader("Content-disposition",

@ -23,8 +23,26 @@ public class HFProduction extends BaseEntity {
private String quality;
private String ymArrayStart;
private String ymArrayEnd;
private String EquTypeCode;
private String shiftId;
private List<DynamicColumnVo> equNames;
public String getShiftId() {
return shiftId;
}
public void setShiftId(String shiftId) {
this.shiftId = shiftId;
}
public String getEquTypeCode() {
return EquTypeCode;
}
public void setEquTypeCode(String equTypeCode) {
EquTypeCode = equTypeCode;
}
public List<DynamicColumnVo> getEquNames() {
return equNames;
}

@ -219,4 +219,6 @@ public interface MesReportWorkMapper {
List<HFProduction> getHFProductionList(HFProduction dto);
List<DynamicColumnVo> getHFProductionTitle(HFProduction dto);
List<HFProduction> getCXJProductionList(HFProduction dto);
}

@ -20,4 +20,8 @@ public interface IMesReportWorksService {
List<Map<String, Object>> getHFProductionList(HFProduction dto);
List<DynamicColumnVo> getHFProductionTitle(HFProduction dto);
List<DynamicColumnVo> getCXJProductionTitle(HFProduction dto);
List<Map<String, Object>> getCXJProductionList(HFProduction dto);
}

@ -831,7 +831,7 @@ public class IWCInterfaceServiceImpl implements IWCSInterfaceService {
}
workOrder.setUploadTime(nowTime);
mesReportWorkMapper.updateSyncSapStatus(workOrder);
//mesReportWorkMapper.updateOrderWorkStatus(workOrder);
return r;
// return R.ok();//测试
}

@ -206,7 +206,6 @@ public class MesReportWorksServiceImpl implements IMesReportWorksService {
@Override
@DS("#header.poolName")
public List<Map<String, Object>> getHFProductionList(HFProduction dto) {
//return mesReportWorkMapper.getHFProductionList(dto);
// 开始日期
String start = dto.getYmArrayStart();
String end = dto.getYmArrayEnd();
@ -253,9 +252,65 @@ public class MesReportWorksServiceImpl implements IMesReportWorksService {
@DS("#header.poolName")
public List<DynamicColumnVo> getHFProductionTitle(HFProduction dto) {
//查询sql数据
dto.setEquTypeCode("equ_type_hf");
List<DynamicColumnVo> data = mesReportWorkMapper.getHFProductionTitle(dto);
return data;
}
@Override
@DS("#header.poolName")
public List<DynamicColumnVo> getCXJProductionTitle(HFProduction dto) {
//查询sql数据
dto.setEquTypeCode("equ_type_cxj");
List<DynamicColumnVo> data = mesReportWorkMapper.getHFProductionTitle(dto);
return data;
}
@Override
@DS("#header.poolName")
public List<Map<String, Object>> getCXJProductionList(HFProduction dto) {
// 开始日期
String start = dto.getYmArrayStart();
String end = dto.getYmArrayEnd();
// 查询出来时间区间
List<String> listDate = getDateInterval(start,end);
List<DynamicColumnVo> allEquNames = dto.getEquNames();
List<HFProduction> dbMProductList = mesReportWorkMapper.getCXJProductionList(dto);
List<Map<String, Object>> results = listDate.stream()
.map(date -> {
Map<String, Object> row = new HashMap<>();
row.put("ymd", date);
//对于每个日期,收集该日期下所有产品的产量数据
Map<String, String> dailyProductQuantities = dbMProductList.stream()
.filter(HFProduction -> HFProduction.getYmd().equals(date))
.collect(Collectors.toMap(
HFProduction::getEquCode,
HFProduction::getQuality
));
// 遍历所有产品如果dailyProduct不存在此产品添加产品产量设为空
for (DynamicColumnVo equ : allEquNames) {
String equCode = equ.getCode();
dailyProductQuantities.putIfAbsent(equCode, "0");
}
row.putAll(dailyProductQuantities);
// 计算并添加当日总产量
int totalQuantity = dailyProductQuantities.values().stream()
.mapToInt(Integer::parseInt)
.sum();
row.put("totalQuantity", totalQuantity);
return row;
}).collect(Collectors.toList());
return results;
}
private List<String> getDateInterval(String start, String end) {
start = start.substring(0,10);
end = end.substring(0,10);

@ -509,7 +509,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mrw.uploadTime,
mrw.uploadMsg,
pow.shift_id shiftId,
bst.Shift_Desc shiftName
bst.Shift_Desc shiftName,
pow.status
from (
select workorder_code workorderCode,
product_code productCode,
@ -1211,12 +1212,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select be.equipment_code code,
be.equipment_name label
from base_equipment be
where be.equipment_type_code ='equ_type_hf' and be.del_flag = '0'
where be.equipment_type_code = #{equTypeCode} and be.del_flag = '0'
<if test="equName != null ">
and be.equipment_name like concat('%', #{equName}, '%')
</if>
order by be.equipment_name
</select>
<select id="getCXJProductionList" resultType="com.op.mes.domain.HFProduction">
select
t.product_date ymd,
t.workorder_name equCode,
be.equipment_name equName,
count(0) quality
from(
select pow.workorder_id,
pow.product_date,
mcp.workorder_name
from pro_order_workorder pow
left join mes_cxj_producted mcp on mcp.workorder_code = pow.workorder_id
where pow.product_date >=#{ymArrayStart}
and #{ymArrayEnd} >= pow.product_date
and pow.del_flag = '0'
and pow.start_work_time is not null
<if test="shiftId != null">and pow.shift_id = #{shiftId}</if>
) t
left join base_equipment be on be.equipment_code = t.workorder_name
where 1=1
<if test="equName != null ">
and be.equipment_name like concat('%', #{equName}, '%')
</if>
GROUP BY t.workorder_name,be.equipment_name,t.product_date
</select>
<insert id="insertMesReportWork" parameterType="MesReportWork">
insert into mes_report_work

@ -311,6 +311,7 @@ public class ProOrderWorkorder extends TreeEntity {
private String pworkorderCodeSap;
/**SAP产线编码*/
@Excel(name = "SAP产线编码")
private String sapCode;
/**SAP产线名称*/
private String sapName;

@ -4,7 +4,7 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.op.plan.mapper.ProOrderWorkorderMapper">
<resultMap type="ProOrderWorkorder" id="ProOrderWorkorderResult">
<resultMap type="com.op.plan.domain.ProOrderWorkorder" id="ProOrderWorkorderResult">
<result property="workorderId" column="workorder_id"/>
<result property="workorderCode" column="workorder_code"/>
<result property="workorderName" column="workorder_name"/>

@ -5,6 +5,7 @@ import com.op.common.core.utils.DateUtils;
import com.op.common.core.utils.StringUtils;
import com.op.common.core.utils.poi.ExcelReportMapUtil;
import com.op.common.core.utils.poi.ExcelSCReportMapUtil;
import com.op.common.core.utils.poi.ExcelSCXJReportMapUtil;
import com.op.common.core.utils.poi.ExcelUtil;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
@ -20,6 +21,7 @@ import com.op.system.api.domain.SysFile;
import com.op.system.api.domain.SysUser;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
@ -206,6 +208,107 @@ public class QcCheckReportProduceController extends BaseController {
}
}
}
@RequiresPermissions("quality:produceReport:export")
@Log(title = "巡检报告导出", businessType = BusinessType.EXPORT)
@PostMapping("/SCXJReportExport")
public void SCXJReportExport(HttpServletResponse response, QcCheckTaskProduce qcCheckTaskProduce) {
Map<String,String> detailMap = new HashMap<>();
detailMap.put("title","产品巡检记录表");
QcCheckTaskProduce detailInfo = qcCheckReportProduceService.getProduceReportXJ(qcCheckTaskProduce);
List<QcStaticTable> listVal = detailInfo.getCheckInfos();
List<Map> list = getMapFromList(listVal);
detailMap.put("checkManName",detailInfo.getCheckManName());
detailMap.put("remark",detailInfo.getRemark());
detailMap.put("standardNo",detailInfo.getFileNo());
detailMap.put("supplierName",detailInfo.getSupplierName());
detailMap.put("checkLoc",detailInfo.getLineName());
detailMap.put("incomeBatchNo",detailInfo.getIncomeBatchNo());
detailMap.put("materialCode",detailInfo.getMaterialCode());
detailMap.put("materialName",detailInfo.getMaterialName());
if("a".equals(detailInfo.getProductType())){
detailMap.put("productType","正常");
}else if("b".equals(detailInfo.getProductType())){
detailMap.put("productType","返修");
}else if("c".equals(detailInfo.getProductType())){
detailMap.put("productType","试产");
}
detailMap.put("incomeTime",detailInfo.getCheckTimeStart());
//表格结构数据
ArrayList<ExcelCol> excelCols = new ArrayList<>();
excelCols.add(new ExcelCol("序号", "xh", 30));
excelCols.add(new ExcelCol("项目名称", "ruleName", 30));
if(qcCheckTaskProduce.getShiftId().equals("5")){
excelCols.add(new ExcelCol("8:00-9:00", "column080090", 30));
excelCols.add(new ExcelCol("9:00-10:00", "column090100", 30));
excelCols.add(new ExcelCol("10:00-11:00", "column100110", 30));
excelCols.add(new ExcelCol("11:00-12:00", "column110120", 30));
excelCols.add(new ExcelCol("13:30-14:30", "column133143", 30));
excelCols.add(new ExcelCol("14:30-15:30", "column143153", 30));
excelCols.add(new ExcelCol("15:30-16:30", "column153163", 30));
excelCols.add(new ExcelCol("16:30-17:30", "column163173", 30));
excelCols.add(new ExcelCol("12:30-13:30", "column123133", 30));
excelCols.add(new ExcelCol("18:00-19:00", "column180190", 30));
excelCols.add(new ExcelCol("19:00-20:00", "column190200", 30));
excelCols.add(new ExcelCol("20:00-21:00", "column200210", 30));
}else if(qcCheckTaskProduce.getShiftId().equals("2")){
excelCols.add(new ExcelCol("20:30-21:30", "column080090", 30));
excelCols.add(new ExcelCol("21:30-22:30", "column090100", 30));
excelCols.add(new ExcelCol("22:30-23:30", "column100110", 30));
excelCols.add(new ExcelCol("23:30-1:30", "column110120", 30));
excelCols.add(new ExcelCol("1:30-2:30", "column133143", 30));
excelCols.add(new ExcelCol("2:30-3:30", "column143153", 30));
excelCols.add(new ExcelCol("3:30-4:30", "column153163", 30));
excelCols.add(new ExcelCol("4:30-5:30", "column163173", 30));
excelCols.add(new ExcelCol("5:30-6:30", "column123133", 30));
excelCols.add(new ExcelCol("6:30-7:30", "column180190", 30));
excelCols.add(new ExcelCol("7:30-8:30", "column190200", 30));
}
String sheetName = "巡检检验报告";
SXSSFWorkbook workbook = null;
try {
//设置响应头
response.setHeader("Content-disposition",
"attachment; filename=" + sheetName);
response.setContentType("application/octet-stream;charset=UTF-8");
ServletOutputStream outputStream = response.getOutputStream();
//调用工具类
workbook = ExcelSCXJReportMapUtil.initWorkbook(sheetName, "-", excelCols, list, detailMap,qcCheckTaskProduce.getShiftId());
workbook.write(outputStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (workbook != null) {
workbook.dispose();
}
}
}
private List<Map> getMapFromList(List<QcStaticTable> dtos){
List<Map> maps = new ArrayList<>();
int n = 1;
for(QcStaticTable dto:dtos){
Map mapdto = new HashMap();
mapdto.put("xh",n++);
mapdto.put("ruleName",dto.getRuleName());
mapdto.put("column080090",dto.getColumn080090());
mapdto.put("column090100",dto.getColumn090100());
mapdto.put("column100110",dto.getColumn100110());
mapdto.put("column110120",dto.getColumn110120());
mapdto.put("column133143",dto.getColumn133143());
mapdto.put("column143153",dto.getColumn143153());
mapdto.put("column153163",dto.getColumn153163());
mapdto.put("column163173",dto.getColumn163173());
mapdto.put("column123133",dto.getColumn123133());
mapdto.put("column180190",dto.getColumn180190());
mapdto.put("column190200",dto.getColumn190200());
mapdto.put("column200210",dto.getColumn200210());
maps.add(mapdto);
}
return maps;
}
/**
*
*/

@ -10,6 +10,7 @@ import com.op.common.core.domain.ExcelCol;
import com.op.common.core.utils.poi.ExcelMapUtil;
import com.op.quality.domain.*;
import com.op.quality.service.IQcMaterialGroupService;
import com.op.system.api.domain.SysDictData;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -205,4 +206,10 @@ public class QcCheckTypeProjectController extends BaseController {
List<QcMaterialGroupDetail> orderList = util.importExcel(file.getInputStream());
return qcCheckTypeProjectService.importOrder(orderList);
}
//获取自动采集字典
@GetMapping("/getAutoDataOption")
public List<SysDictData> getAutoDataOption(SysDictData sysDictData) {
List<SysDictData> list = qcCheckTypeProjectService.getAutoDataOption(sysDictData);
return list;
}
}

@ -3,6 +3,7 @@ package com.op.quality.mapper;
import java.util.List;
import com.op.quality.domain.QcMaterialGroup;
import com.op.system.api.domain.SysDictData;
import org.apache.ibatis.annotations.Mapper;
/**
@ -70,4 +71,6 @@ public interface QcMaterialGroupMapper {
String selectGroupIdByName(String groupName);
void deleteGroupDetailById(String id);
List<SysDictData> getAutoDataOption(SysDictData sysDictData);
}

@ -7,6 +7,7 @@ import com.op.quality.domain.QcCheckProject;
import com.op.quality.domain.QcCheckTypeProject;
import com.op.quality.domain.QcMaterialGroupDetail;
import com.op.quality.domain.QcProjectType;
import com.op.system.api.domain.SysDictData;
/**
* Service
@ -75,4 +76,6 @@ public interface IQcCheckTypeProjectService {
List<QcProjectType> getProjectOptions(QcCheckProject qcCheckProject);
AjaxResult importOrder(List<QcMaterialGroupDetail> orderList);
List<SysDictData> getAutoDataOption(SysDictData sysDictData);
}

@ -303,10 +303,10 @@ public class QcCheckReportProduceServiceImpl implements IQcCheckReportProduceSer
// 解析字符串为 Date 对象
Date date = sdf.parse(produce.getCheckTimeStart());
dto0.setIncomeTime(date);
System.out.println("解析后的日期: " + date);
//System.out.println("解析后的日期: " + date);
} catch (ParseException e) {
// 捕获解析异常并打印错误消息
System.err.println("解析日期字符串时出错: " + e.getMessage());
//System.err.println("解析日期字符串时出错: " + e.getMessage());
}
dto0.setCheckType("checkTypeSCXJ");

@ -205,6 +205,13 @@ public class QcCheckTypeProjectServiceImpl implements IQcCheckTypeProjectService
return checkResult;
}
}
@Override
@DS("#header.poolName")
public List<SysDictData> getAutoDataOption(SysDictData sysDictData) {
return qcMaterialGroupMapper.getAutoDataOption(sysDictData);
}
/**
*
*

@ -140,4 +140,9 @@
<select id="selectGroupIdByName" resultType="java.lang.String">
select id from qc_material_group where group_name = #{groupName} and del_flag = '0'
</select>
<select id="getAutoDataOption" resultType="com.op.system.api.domain.SysDictData">
select dict_value dictValue,dict_label dictLabel
from base_dict_data
where dict_type = #{dictType}
</select>
</mapper>

Loading…
Cancel
Save