From f3711dd0815e1f3d8136e6c0ca72fd21f8c18dc3 Mon Sep 17 00:00:00 2001 From: zhaoxiaolin Date: Tue, 30 Jan 2024 15:21:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E9=87=8F=E5=80=BC=E5=88=86=E6=9E=90?= =?UTF-8?q?=E6=8A=A5=E8=A1=A8V1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/utils/poi/ExcelMapUtil.java | 74 ++++++++++++------- .../controller/MesReportWorkController.java | 2 +- .../plan/controller/ProOrderController.java | 2 +- .../controller/QcStaticTableController.java | 65 +++++++++++++++- .../op/quality/domain/QcCheckTaskProduce.java | 27 +++++++ .../com/op/quality/domain/QcStaticTable.java | 9 +++ .../impl/QcStaticTableServiceImpl.java | 3 +- .../quality/QcCheckTaskProduceMapper.xml | 10 ++- .../mapper/quality/QcStaticTableMapper.xml | 46 ++++++++++-- .../controller/BaseEquipmentController.java | 4 +- 10 files changed, 201 insertions(+), 41 deletions(-) diff --git a/op-common/op-common-core/src/main/java/com/op/common/core/utils/poi/ExcelMapUtil.java b/op-common/op-common-core/src/main/java/com/op/common/core/utils/poi/ExcelMapUtil.java index 99391226..a94ac60f 100644 --- a/op-common/op-common-core/src/main/java/com/op/common/core/utils/poi/ExcelMapUtil.java +++ b/op-common/op-common-core/src/main/java/com/op/common/core/utils/poi/ExcelMapUtil.java @@ -2,18 +2,11 @@ package com.op.common.core.utils.poi; import com.alibaba.fastjson2.JSONObject; import com.op.common.core.domain.ExcelCol; -import org.apache.poi.hssf.usermodel.HSSFCellStyle; 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 org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -35,22 +28,45 @@ public class ExcelMapUtil { }else{ sheet = workbook.createSheet(sheetName); } -// //创建主标题行(第一行) -// Row sheetTitleRow = sheet.createRow(0); -// Cell titleCell = sheetTitleRow.createCell(0);//创建第一行第一个单元格 -// titleCell.setCellValue(title);//传值 -// titleCell.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式 -// //主标题行合并单元格 -// CellRangeAddress cellAddresses = new CellRangeAddress(0, 0, 0, colSize - 1); -// sheet.addMergedRegion(cellAddresses); - //创建表头行(第二行) - Row sheetHeadRow = sheet.createRow(0);//1 - //遍历表头名称,创建表头单元格 - for(int i = 0 ; i < colSize ; i++){ - sheet.setColumnWidth(i,(excelCol.get(i).getWidth())*256);//宽度单位是字符的256分之一 - Cell headCell = sheetHeadRow.createCell(i); - headCell.setCellValue(excelCol.get(i).getTitle());//传值 - headCell.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式 + if(title != null){//定量分析 + String[] title1s = title.split(","); + int rangeVal = colSize/title1s.length; + //创建主标题行(第一行) + Row sheetTitleRow = sheet.createRow(0); + + Cell titleCell0 = sheetTitleRow.createCell(0);//创建第一行第一个单元格 + titleCell0.setCellValue("");//传值 + titleCell0.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式 + + //遍历表头名称,创建表头单元格 + for (int i = 0; i < title1s.length; i++) { + Cell titleCell = sheetTitleRow.createCell(i*rangeVal+1);//创建第一行第一个单元格 + titleCell.setCellValue(title1s[i]);//传值 + titleCell.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式 + //主标题行合并单元格 + CellRangeAddress cellAddresses = new CellRangeAddress(0, 0, i*rangeVal+1, (i+1)*rangeVal); + sheet.addMergedRegion(cellAddresses); + } + + //创建表头行(第二行) + Row sheetHeadRow = sheet.createRow(1);//1 + //遍历表头名称,创建表头单元格 + for (int i = 0; i < colSize; i++) { + sheet.setColumnWidth(i, (excelCol.get(i).getWidth()) * 256);//宽度单位是字符的256分之一 + Cell headCell = sheetHeadRow.createCell(i); + headCell.setCellValue(excelCol.get(i).getTitle());//传值 + headCell.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式 + } + }else { + //创建表头行(第二行) + Row sheetHeadRow = sheet.createRow(0);//1 + //遍历表头名称,创建表头单元格 + for (int i = 0; i < colSize; i++) { + sheet.setColumnWidth(i, (excelCol.get(i).getWidth()) * 256);//宽度单位是字符的256分之一 + Cell headCell = sheetHeadRow.createCell(i); + headCell.setCellValue(excelCol.get(i).getTitle());//传值 + headCell.setCellStyle(getHeaderFont(sheet.getWorkbook()));//设置样式 + } } //将data中的值填充到excel @@ -65,12 +81,15 @@ public class ExcelMapUtil { for (int i = 0 ; i < colSize ; i++ ){ Cell dataCell = dataRow.createCell(i); dataCell.setCellStyle(getDataFont(workbook)); - if(i>=2){ - dataCell.setCellValue(getValueNum(jsonObject.get(excelCol.get(i).getField()))); - }else{ + if(title!=null){//定量分析 dataCell.setCellValue(getValue(jsonObject.get(excelCol.get(i).getField()))); + }else{ + if(i>=2){ + dataCell.setCellValue(getValueNum(jsonObject.get(excelCol.get(i).getField()))); + }else{ + dataCell.setCellValue(getValue(jsonObject.get(excelCol.get(i).getField()))); + } } - } iterator.remove(); rowNum++; @@ -110,6 +129,7 @@ public class ExcelMapUtil { cellStyle.setFont(font); cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);//设置水平居中 cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//设置垂直居中 + cellStyle.setWrapText(true);//设置单元格内容自动换行 return cellStyle; } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/controller/MesReportWorkController.java b/op-modules/op-mes/src/main/java/com/op/mes/controller/MesReportWorkController.java index 7d218a9d..32a2566e 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/controller/MesReportWorkController.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/controller/MesReportWorkController.java @@ -346,7 +346,7 @@ public class MesReportWorkController extends BaseController { response.setContentType("application/octet-stream;charset=UTF-8"); ServletOutputStream outputStream = response.getOutputStream(); //调用工具类 - workbook = ExcelMapUtil.initWorkbook(titleName, titleName, excelCols, list); + workbook = ExcelMapUtil.initWorkbook(titleName, null, excelCols, list); workbook.write(outputStream); } catch (Exception e) { e.printStackTrace(); diff --git a/op-modules/op-plan/src/main/java/com/op/plan/controller/ProOrderController.java b/op-modules/op-plan/src/main/java/com/op/plan/controller/ProOrderController.java index 22c11cdc..65d98aa3 100644 --- a/op-modules/op-plan/src/main/java/com/op/plan/controller/ProOrderController.java +++ b/op-modules/op-plan/src/main/java/com/op/plan/controller/ProOrderController.java @@ -105,7 +105,7 @@ public class ProOrderController extends BaseController { response.setContentType("application/octet-stream;charset=UTF-8"); ServletOutputStream outputStream = response.getOutputStream(); //调用工具类 - workbook = ExcelMapUtil.initWorkbook(titleName, titleName, excelCols, null); + workbook = ExcelMapUtil.initWorkbook(titleName, null, excelCols, null); workbook.write(outputStream); } catch (Exception e) { e.printStackTrace(); diff --git a/op-modules/op-quality/src/main/java/com/op/quality/controller/QcStaticTableController.java b/op-modules/op-quality/src/main/java/com/op/quality/controller/QcStaticTableController.java index 2ed01e06..94adec2b 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/controller/QcStaticTableController.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/controller/QcStaticTableController.java @@ -8,15 +8,19 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; +import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; +import com.op.common.core.domain.ExcelCol; import com.op.common.core.utils.DateUtils; +import com.op.common.core.utils.poi.ExcelMapUtil; import com.op.quality.domain.QcCheckProject; import com.op.quality.domain.QcCheckType; import com.op.system.api.domain.quality.ChartDTO; import com.op.system.api.domain.quality.ChartSeriesDTO; import com.op.system.api.domain.quality.FactoryDto; import org.apache.commons.lang.StringUtils; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -240,7 +244,7 @@ public class QcStaticTableController extends BaseController { return qcStaticTableService.getSupplierList(typeCode); } - @GetMapping("/getProjectList/{checkType}") + @GetMapping("/getProjectOptionList/{checkType}") public List getProjectList(@PathVariable("checkType") String checkType) { return qcStaticTableService.getProjectList(checkType); } @@ -323,4 +327,63 @@ public class QcStaticTableController extends BaseController { public QcStaticTable getDLTableAvgInfo(QcStaticTable qcStaticTable) { return qcStaticTableService.getDLTableAvgInfo(qcStaticTable); } + @PostMapping("/exportDLTable") + public void exportDLTable(HttpServletResponse response, QcStaticTable qcStaticTable) { + + QcStaticTable resultInfo = qcStaticTableService.getDLTableAvgInfo(qcStaticTable); + + //第一行标题 + List title1Cols = resultInfo.getTitleCol1(); + //第二行标题 + List title2Cols = resultInfo.getTitleCol2(); + String titleRow1 = String.join(",", title1Cols); + //表格结构数据 + ArrayList excelCols = new ArrayList<>(); + excelCols.add(new ExcelCol("日期","ymdms",30)); + List titleKeys = new ArrayList<>(); + for(int m = 0; m list = new ArrayList<>(); + //具体数据 + List dxData = resultInfo.getDxData(); + for(HashMap mapdto:dxData){ + list.add(mapdto); + List detailMap0 = (List) mapdto.get("details"); + HashMap detailMap1 = new HashMap(); + for(String titleKey:titleKeys){ + detailMap1.put(titleKey,detailMap0.get(0).get(titleKey+"Detail")); + } + if(StringUtils.isNotBlank((String)detailMap1.get(titleKeys.get(0)))){ + list.add(detailMap1); + } + + } + + + 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, titleRow1, excelCols, list); + workbook.write(outputStream); + } catch (Exception e) { + e.printStackTrace(); + }finally { + if (workbook!=null){ + workbook.dispose(); + } + } + } + } diff --git a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskProduce.java b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskProduce.java index 1daa776a..a2404425 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskProduce.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCheckTaskProduce.java @@ -154,6 +154,33 @@ public class QcCheckTaskProduce extends BaseEntity { private String productType; private String confirmManCode; private String confirmManName; + private String confirm; + private String confirmRemark; + private String confirmTime; + + public String getConfirm() { + return confirm; + } + + public void setConfirm(String confirm) { + this.confirm = confirm; + } + + public String getConfirmRemark() { + return confirmRemark; + } + + public void setConfirmRemark(String confirmRemark) { + this.confirmRemark = confirmRemark; + } + + public String getConfirmTime() { + return confirmTime; + } + + public void setConfirmTime(String confirmTime) { + this.confirmTime = confirmTime; + } public String getConfirmManCode() { return confirmManCode; diff --git a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcStaticTable.java b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcStaticTable.java index 771fe3d8..63953ef0 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcStaticTable.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcStaticTable.java @@ -104,6 +104,15 @@ public class QcStaticTable extends BaseEntity { private List titleCol2; private List dxData; private List details; + private String[] projectNoArray; + + public String[] getProjectNoArray() { + return projectNoArray; + } + + public void setProjectNoArray(String[] projectNoArray) { + this.projectNoArray = projectNoArray; + } public List getDetails() { return details; diff --git a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcStaticTableServiceImpl.java b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcStaticTableServiceImpl.java index cfc1f8cd..87c494d8 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcStaticTableServiceImpl.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcStaticTableServiceImpl.java @@ -480,7 +480,6 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService { qcStaticTable.getYmArrayEnd(),"ymd"); qcStaticTable.setDataType("ymd"); - List titleList = qcStaticTableMapper.getDLTableTitle(qcStaticTable); Map titleMap = titleList.stream().collect(Collectors.toMap(QcStaticTable::getYearMonth, (a) -> a)); //表头:第一行 @@ -498,7 +497,7 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService { HashMap result = new HashMap(); List detailsData = new ArrayList<>(); HashMap detailResult = new HashMap(); - result.put("ymdms",day+"均值"); + result.put("ymdms",day+" AVG"); int i=0,j=0; for(int m=0;m + + + + + @@ -86,7 +91,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" check_man_code, check_man_name, check_time, check_result, status, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time, factory_code, del_flag , check_type,sample_quality,noOk_quality, - aNoOkquality,bNoOkquality,cNoOkquality,reason,product_type + aNoOkquality,bNoOkquality,cNoOkquality,reason,product_type, + confirm,confirm_man_code,confirm_man_name,confirm_remark ,confirm_time from qc_check_task @@ -167,7 +173,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" qct.confirm_man_name confirmManName from qc_check_task qct left join pro_order_workorder pow on qct.order_no = pow.workorder_code - where check_type = 'checkTypeSCXJ' + where check_type = 'checkTypeSCXJ' and qct.del_flag = '0' and pow.del_flag = '0' and CONVERT(varchar(10),income_time, 120) = CONVERT(varchar(10),GETDATE(), 120) and pow.status = 'w2' and pow.parent_order = '0' group by qct.factory_code, diff --git a/op-modules/op-quality/src/main/resources/mapper/quality/QcStaticTableMapper.xml b/op-modules/op-quality/src/main/resources/mapper/quality/QcStaticTableMapper.xml index d22d2dc0..b2a1e0bc 100644 --- a/op-modules/op-quality/src/main/resources/mapper/quality/QcStaticTableMapper.xml +++ b/op-modules/op-quality/src/main/resources/mapper/quality/QcStaticTableMapper.xml @@ -281,11 +281,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" CONVERT(varchar(10),qct.income_time, 120) ymdms, qctd.rule_name, qctd.project_no,qctd.actual_value from qc_check_task qct - left join qc_check_task_detail qctd on qct.record_id = qctd.belong_to - where qct.check_type = 'checkTypeLL' and qctd.property_code = '1' and qct.check_time is not null + left join qc_check_task_detail qctd on qct.record_id = qctd.belong_to + where qct.check_type = #{checkType} and qctd.property_code = '1' and qct.check_time is not null and CONVERT(varchar(10),qct.income_time, 120) >= CONVERT(varchar(10),#{ymArrayStart}, 120) and CONVERT(varchar(10),#{ymArrayEnd}, 120)>=CONVERT(varchar(10),qct.income_time, 120) - ) t + and qctd.project_id in( + + #{projectId} + + ) + + + and qct.order_no = #{orderNo} + + + and qct.material_code = #{materialCode} + + + and qct.supplier_code = #{supplierCode} + + + ) t WHERE t.material_code = q.material_code and t.project_no = q.project_no and t.ymdms=q.ymdms FOR xml path('') ),1,1,'' @@ -297,13 +313,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" qctd.rule_name,qctd.project_no,qctd.actual_value from qc_check_task qct left join qc_check_task_detail qctd on qct.record_id = qctd.belong_to - where qct.check_type = 'checkTypeLL' and qctd.property_code = '1' and qct.check_time is not null + where qct.check_type = #{checkType} and qctd.property_code = '1' and qct.check_time is not null and CONVERT(varchar(10),qct.income_time, 120) >= CONVERT(varchar(10),#{ymArrayStart}, 120) and CONVERT(varchar(10),#{ymArrayEnd}, 120)>=CONVERT(varchar(10),qct.income_time, 120) + and qctd.project_id in( + + #{projectId} + + ) + + + and qct.order_no = #{orderNo} + + + and qct.material_code = #{materialCode} + + + and qct.supplier_code = #{supplierCode} + ) q GROUP BY q.material_code,q.material_name, q.ymdms,q.rule_name,q.project_no diff --git a/op-modules/op-wms/src/main/java/com/op/wms/controller/BaseEquipmentController.java b/op-modules/op-wms/src/main/java/com/op/wms/controller/BaseEquipmentController.java index fecad0b3..b90324a9 100644 --- a/op-modules/op-wms/src/main/java/com/op/wms/controller/BaseEquipmentController.java +++ b/op-modules/op-wms/src/main/java/com/op/wms/controller/BaseEquipmentController.java @@ -34,7 +34,7 @@ import org.springframework.web.multipart.MultipartFile; /** * 设备管理Controller - * + * * @author Open Platform * @date 2023-07-20 */ @@ -199,7 +199,7 @@ public class BaseEquipmentController extends BaseController { response.setContentType("application/octet-stream;charset=UTF-8"); ServletOutputStream outputStream = response.getOutputStream(); //调用工具类 - workbook = ExcelMapUtil.initWorkbook(titleName, titleName, excelCols, null); + workbook = ExcelMapUtil.initWorkbook(titleName, null, excelCols, null); workbook.write(outputStream); } catch (Exception e) { e.printStackTrace();