From dd8b2d9d8c08e1872a774612a1ffa309a13fbb90 Mon Sep 17 00:00:00 2001 From: zhaoxiaolin Date: Tue, 10 Sep 2024 21:47:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A8=E9=87=8Fcpk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/utils/poi/ExcelMapUtil.java | 1 + .../impl/MesPrepareDetailServiceImpl.java | 9 ++- .../controller/QcStaticTableController.java | 62 +++++++++++----- .../java/com/op/quality/domain/QcCPKDTO.java | 71 +++++++++++++++++++ .../impl/QcStaticTableServiceImpl.java | 29 +++++--- 5 files changed, 143 insertions(+), 29 deletions(-) create mode 100644 op-modules/op-quality/src/main/java/com/op/quality/domain/QcCPKDTO.java 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 f58dfdbc..a22e6414 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 @@ -118,6 +118,7 @@ public class ExcelMapUtil { cellStyle.setBorderLeft(BorderStyle.THIN); // 设置右边框 cellStyle.setBorderRight(BorderStyle.THIN); + cellStyle.setFillBackgroundColor(IndexedColors.AQUA.getIndex()); return cellStyle; } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesPrepareDetailServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesPrepareDetailServiceImpl.java index 99828f87..fefd8f1d 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesPrepareDetailServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesPrepareDetailServiceImpl.java @@ -1,6 +1,7 @@ package com.op.mes.service.impl; import java.util.List; +import java.util.stream.Collectors; import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.utils.DateUtils; @@ -114,7 +115,9 @@ public class MesPrepareDetailServiceImpl implements IMesPrepareDetailService { .replace("]]","")); PrintPrepareVo printPrepareVo = new PrintPrepareVo(); printPrepareVo.setMesPrepare(mesPrepare); - printPrepareVo.setMesPrepareDetailList(mesPrepareDetailList); + printPrepareVo.setMesPrepareDetailList(mesPrepareDetailList.stream() + .filter(dto ->!dto.getQuantity().equals("0.00")) + .collect(Collectors.toList())); return AjaxResult.success(printPrepareVo); } @@ -133,7 +136,9 @@ public class MesPrepareDetailServiceImpl implements IMesPrepareDetailService { List mesPrepareDetailList = mesPrepareDetailMapper.selectPreDetailHzList(qodetail); PrintPrepareVo printPrepareVo = new PrintPrepareVo(); printPrepareVo.setMesPrepare(mesPrepare); - printPrepareVo.setMesPrepareDetailList(mesPrepareDetailList); + printPrepareVo.setMesPrepareDetailList(mesPrepareDetailList.stream() + .filter(dto ->!dto.getQuantity().equals("0.00")) + .collect(Collectors.toList())); return AjaxResult.success(printPrepareVo); } } 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 91ef6450..763c53da 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 @@ -14,9 +14,7 @@ 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.QcCheckDetail; -import com.op.quality.domain.QcCheckProject; -import com.op.quality.domain.QcCheckType; +import com.op.quality.domain.*; import com.op.system.api.domain.quality.ChartDTO; import com.op.system.api.domain.quality.ChartSeriesDTO; import com.op.system.api.domain.quality.FactoryDto; @@ -35,7 +33,6 @@ import org.springframework.web.bind.annotation.RestController; import com.op.common.log.annotation.Log; import com.op.common.log.enums.BusinessType; import com.op.common.security.annotation.RequiresPermissions; -import com.op.quality.domain.QcStaticTable; import com.op.quality.service.IQcStaticTableService; import com.op.common.core.web.controller.BaseController; import com.op.common.core.web.domain.AjaxResult; @@ -421,20 +418,53 @@ public class QcStaticTableController extends BaseController { return getDataTable(list); } - @PostMapping("/exportProduceAnalysis") - public void exportProduceAnalysis(HttpServletResponse response, QcStaticTable qcStaticTable) { - //默认时间范围T 00:00:00~T+1 00:00:00 - if (StringUtils.isEmpty(qcStaticTable.getYmArrayStart())) { - LocalDate date = LocalDate.now(); - DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - String ymStr = dtf.format(date); - qcStaticTable.setYmArrayStart(ymStr); - qcStaticTable.setYmArrayEnd(ymStr); + @PostMapping("/exportCPK") + public void exportCPK(HttpServletResponse response, QcStaticTable qcStaticTable) { + QcStaticTable resultInfo = qcStaticTableService.getDLTableCPKInfo(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 < title1Cols.size(); m++) { + for (int n = 0; n < title2Cols.size(); n++) { + excelCols.add(new ExcelCol(title2Cols.get(n), "mcode" + m + "Pcode" + n, 80)); + titleKeys.add("mcode" + m + "Pcode" + n); + } } - List list = qcStaticTableService.getQmsRateTable(qcStaticTable); - ExcelUtil util = new ExcelUtil(QcStaticTable.class); - util.exportExcel(response, list, "质检不良统计"); + //第三行开始数据 + List list = new ArrayList<>(); + //具体数据 + List dxData = resultInfo.getDxData(); + for (HashMap mapdto : dxData) { + list.add(mapdto); + } + + + String titleName = "定量检测项测量值CPK"; + 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/QcCPKDTO.java b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCPKDTO.java new file mode 100644 index 00000000..4f0a4e05 --- /dev/null +++ b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcCPKDTO.java @@ -0,0 +1,71 @@ +package com.op.quality.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.op.common.core.annotation.Excel; +import com.op.common.core.web.domain.BaseEntity; +import com.op.system.api.domain.quality.ChartDTO; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.List; + +/** + * 质量系统报对象 qc_static_table + * + * @author Open Platform + * @date 2024-09-10 + */ +public class QcCPKDTO{ + + @Excel(name = "检验节点") + private String checkType; + @Excel(name = "检验日期") + private String checkDate; + @Excel(name = "产品编码") + private String materialCode; + @Excel(name = "产品名称") + private String materialName; + @Excel(name = "CPK值") + private String cpkVal; + + public String getCheckType() { + return checkType; + } + + public void setCheckType(String checkType) { + this.checkType = checkType; + } + + public String getCheckDate() { + return checkDate; + } + + public void setCheckDate(String checkDate) { + this.checkDate = checkDate; + } + + public String getMaterialCode() { + return materialCode; + } + + public void setMaterialCode(String materialCode) { + this.materialCode = materialCode; + } + + public String getMaterialName() { + return materialName; + } + + public void setMaterialName(String materialName) { + this.materialName = materialName; + } + + public String getCpkVal() { + return cpkVal; + } + + public void setCpkVal(String cpkVal) { + this.cpkVal = cpkVal; + } +} 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 18ec9778..5a0cfaa0 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 @@ -707,7 +707,11 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService { List avgArray = Arrays.asList(avgArrayStr.split(",")); BigDecimal addVal = new BigDecimal("0.00"); for (String avgVal : avgArray) { - addVal = addVal.add(new BigDecimal(avgVal)); + if(avgVal.matches(".*\\..*\\..*")){ + addVal = addVal.add(new BigDecimal(avgVal.substring(2))); + }else{ + addVal = addVal.add(new BigDecimal(avgVal)); + } } BigDecimal avg = addVal.divide(new BigDecimal(avgArray.size()), 2, BigDecimal.ROUND_HALF_UP); result.put("mcode" + m + "Pcode" + n, avg); @@ -779,7 +783,7 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService { for (String day : days) { HashMap result = new HashMap(); - result.put("ymdms", day + " AVG"); + result.put("ymdms", day + " CPK"); int i = 0, j = 0; for (int m = 0; m < colCode1.size(); m++) { for (int n = 0; n < colCode2.size(); n++) { @@ -789,7 +793,15 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService { String avgArrayStr = avgdto.getQuality().replace("[", "") .replace("]", "") .replace("\"", ""); - List avgArray = Arrays.asList(avgArrayStr.split(",")); + List avgArray0 = Arrays.asList(avgArrayStr.split(",")); + List avgArray = new ArrayList<>(); + for(String avg:avgArray0){ + if(avg.matches(".*\\..*\\..*")){ + avgArray.add(avg.substring(2)); + }else{ + avgArray.add(avg); + } + } double[] data = avgArray.stream() .mapToDouble(Double::parseDouble) // 将String转换为double .toArray(); // 转换为double数组 ; @@ -847,6 +859,7 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService { } return Math.sqrt(temp / (data.length - 1)); } + @Override @DS("#header.poolName") public List getProjectList(String checkType) { @@ -1152,13 +1165,7 @@ public class QcStaticTableServiceImpl implements IQcStaticTableService { } public static void main(String args[]){ - List months = new ArrayList<>(); - for (Month month : Month.values()) { - // 使用String.format来构造"yyyy-MM"格式的字符串 - // %d用于整数(年份和月份),但月份需要前面补0(使用%02d) - String formattedMonth = String.format("%d-%02d",2024, month.getValue()); - months.add(formattedMonth); - } - System.out.println(months); + String ymd = "1、0.4016"; + System.out.println(ymd.substring(2)); } }