From d4ce34c3325eb695b990fffb2785030f17d59437 Mon Sep 17 00:00:00 2001 From: zhaoxiaolin Date: Mon, 16 Oct 2023 17:01:37 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=9C=8B=E6=9D=BF=E6=96=99=E7=BD=90?= =?UTF-8?q?=E8=BD=A6=E6=95=B0=E8=8E=B7=E5=8F=96=EF=BC=9B2=E3=80=81?= =?UTF-8?q?=E5=B0=8F=E6=97=B6=E4=BA=A7=E9=87=8F=E5=8A=A0=E7=8F=AD=E6=AC=A1?= =?UTF-8?q?=E3=80=81=E5=88=86=E9=92=9F=E6=95=B0=E5=81=9A=E6=B4=BB,?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD=EF=BC=9B3=E3=80=81?= =?UTF-8?q?=E5=B7=A5=E5=BA=8F=E5=AE=8C=E6=88=90=E8=AE=B0=E5=BD=95=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E7=8F=AD=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/op/common/core/domain/ExcelCol.java | 49 ++++++++ .../common/core/utils/poi/ExcelMapUtil.java | 118 ++++++++++++++++++ .../controller/MesReportWorkController.java | 77 ++++++++++-- .../controller/WCSInterfaceController.java | 2 +- .../java/com/op/mes/domain/MesHourReport.java | 9 ++ .../com/op/mes/domain/MesProcessReport.java | 9 ++ .../main/java/com/op/mes/domain/MesShift.java | 39 ++++++ .../op/mes/mapper/MesReportWorkMapper.java | 2 + .../op/mes/service/IMesReportWorkService.java | 2 + .../service/impl/IWCInterfaceServiceImpl.java | 3 +- .../impl/MesReportWorkServiceImpl.java | 10 ++ .../main/resources/mapper/mes/MesMapper.xml | 20 +-- .../mapper/mes/MesReportWorkMapper.xml | 14 ++- 13 files changed, 333 insertions(+), 21 deletions(-) create mode 100644 op-common/op-common-core/src/main/java/com/op/common/core/domain/ExcelCol.java create mode 100644 op-common/op-common-core/src/main/java/com/op/common/core/utils/poi/ExcelMapUtil.java create mode 100644 op-modules/op-mes/src/main/java/com/op/mes/domain/MesShift.java diff --git a/op-common/op-common-core/src/main/java/com/op/common/core/domain/ExcelCol.java b/op-common/op-common-core/src/main/java/com/op/common/core/domain/ExcelCol.java new file mode 100644 index 00000000..b9087a38 --- /dev/null +++ b/op-common/op-common-core/src/main/java/com/op/common/core/domain/ExcelCol.java @@ -0,0 +1,49 @@ +package com.op.common.core.domain; + +import com.op.common.core.annotation.Excel; +import com.op.common.core.web.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 附件对象 base_file + * + * @author Open Platform + * @date 2023-07-10 + */ +public class ExcelCol extends BaseEntity { + private static final long serialVersionUID = 1L; + private String title;//表头名称 + private String field;//内容名称(与数据库传回的参数字段对应) + private int width;//单元格宽度 + + public ExcelCol(String title, String field, int width) { + this.title = title; + this.field = field; + this.width = width; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } +} 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 new file mode 100644 index 00000000..62af9527 --- /dev/null +++ b/op-common/op-common-core/src/main/java/com/op/common/core/utils/poi/ExcelMapUtil.java @@ -0,0 +1,118 @@ +package com.op.common.core.utils.poi; + +import com.alibaba.fastjson2.JSONObject; +import com.op.common.core.domain.ExcelCol; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; +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; + +/** + * Excel相关处理 + * + * @author OP + */ +public class ExcelMapUtil { + //下载 + public static SXSSFWorkbook initWorkbook(String sheetName , String title , List excelCol , List data){ + SXSSFWorkbook workbook = new SXSSFWorkbook(); + int colSize = excelCol.size(); + + //创建Sheet(工作簿) + Sheet sheet = null; + if (!StringUtils.hasText(sheetName)){ + sheet = workbook.createSheet(); + }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()));//设置样式 + } + + //将data中的值填充到excel + int rowNum = sheet.getLastRowNum()+1; + Iterator iterator = data.iterator(); + //遍历数据 + for (;iterator.hasNext();){ + Row dataRow = sheet.createRow(rowNum);//创建行 + T obj = iterator.next();//获取当前行对应的数据 + JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(obj)); + 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{ + dataCell.setCellValue(getValue(jsonObject.get(excelCol.get(i).getField()))); + } + + } + iterator.remove(); + rowNum++; + } + return workbook; + } + + //标题样式 + public static CellStyle getHeaderFont(Workbook workbook){ + Font font = workbook.createFont(); + font.setFontHeightInPoints((short) 16);//字体大小 + font.setBold(true);//加粗 + CellStyle cellStyle = workbook.createCellStyle(); + cellStyle.setFont(font); + cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);//设置水平居中 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//设置垂直居中 + return cellStyle; + } + + //内容样式 + public static CellStyle getDataFont(Workbook workbook){ + Font font = workbook.createFont(); + font.setFontHeightInPoints((short) 12);//字体大小 + font.setBold(false);//不加粗 + CellStyle cellStyle = workbook.createCellStyle(); + cellStyle.setFont(font); + cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);//设置水平居中 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//设置垂直居中 + return cellStyle; + } + + //处理数据 + 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()); + } + } +} 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 716b708b..8b5c90ac 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 @@ -4,18 +4,19 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +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.common.core.utils.uuid.IdUtils; import com.op.mes.domain.*; import com.op.mes.domain.dto.LineChartDto; import com.op.mes.domain.dto.SysFactoryDto; -import com.op.mes.mapper.MesReportWorkMapper; 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; @@ -196,7 +197,7 @@ public class MesReportWorkController extends BaseController { */ @RequiresPermissions("mes:hourProduction:list") @GetMapping("/getHourProductionTitle") - public List getProcessFinishList(MesHourReport mesHourReport) { + public List getHourProductionTitle(MesHourReport mesHourReport) { //默认时间范围T 00:00:00~T+1 00:00:00 if(StringUtils.isEmpty(mesHourReport.getProductDateStart())){ mesHourReport.setProductDateStart(DateUtils.getDate()+" 00:00:00");//start @@ -210,8 +211,20 @@ public class MesReportWorkController extends BaseController { List dayHours = new ArrayList(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH"); try { - Date start = dateFormat.parse(mesHourReport.getProductDateStart()); - Date end = dateFormat.parse(mesHourReport.getProductDateEnd()); + + Date start = dateFormat.parse(mesHourReport.getProductDateStart());//开始 + Date end = dateFormat.parse(mesHourReport.getProductDateEnd());//结束 + + //如果有分钟数,默认加一小时 + String endTimeStr1 = mesHourReport.getProductDateEnd(); + String[] endTime2 = endTimeStr1.split(" "); + String endTime3 = endTime2[1].split(":")[1]; + if(Integer.parseInt(endTime3)!=0){ + Calendar calendar = Calendar.getInstance(); + calendar.setTime(end); + calendar.add(Calendar.HOUR_OF_DAY, 1); + end = calendar.getTime(); + } Calendar tempStart = Calendar.getInstance(); tempStart.setTime(start); @@ -228,18 +241,68 @@ public class MesReportWorkController extends BaseController { return dayHours; } + + /** + * 获取班次信息list + * + * @return + */ + @GetMapping("/getProShifts") + public AjaxResult getProShifts() { + return success(mesReportWorkService.getProShifts()); + } + /** * 小时产量数据体 */ @RequiresPermissions("mes:hourProduction:list") @GetMapping("/getHourProductionList") public List getHourProductionList(MesHourReport mesHourReport) { - List hourNames = this.getProcessFinishList(mesHourReport); + List hourNames = this.getHourProductionTitle(mesHourReport); mesHourReport.setHourNames(hourNames); List list = mesReportWorkService.getHourProductionList(mesHourReport); return list; } + @RequiresPermissions("mes:hourProduction:list") + @PostMapping("/getHourProductionExport") + public void getHourProductionExport(HttpServletResponse response,MesHourReport mesHourReport) { + List hourNames = this.getHourProductionTitle(mesHourReport); + mesHourReport.setHourNames(hourNames); + List list = mesReportWorkService.getHourProductionList(mesHourReport); + + //表格结构数据 + String title = "表主标题"; + ArrayList excelCols = new ArrayList<>(); + excelCols.add(new ExcelCol("设备编码","equCode",20)); + excelCols.add(new ExcelCol("设备名称","equName",20)); + excelCols.add(new ExcelCol("设备总产量","quantity",20)); + + for(int n = 0;n lgdtos) { if(CollectionUtils.isEmpty(lgdtos)){ diff --git a/op-modules/op-mes/src/main/java/com/op/mes/domain/MesHourReport.java b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesHourReport.java index 9a5d0750..4fb23bda 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/domain/MesHourReport.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesHourReport.java @@ -28,6 +28,15 @@ public class MesHourReport extends BaseEntity { private String workorderCode; private List hourNames; private String equCodeHour; + private String shiftId; + + public String getShiftId() { + return shiftId; + } + + public void setShiftId(String shiftId) { + this.shiftId = shiftId; + } public String getEquCodeHour() { return equCodeHour; diff --git a/op-modules/op-mes/src/main/java/com/op/mes/domain/MesProcessReport.java b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesProcessReport.java index 56edadb9..ab8e26ee 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/domain/MesProcessReport.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesProcessReport.java @@ -46,6 +46,15 @@ public class MesProcessReport extends BaseEntity { private String unit; private String productDateStart; private String productDateEnd; + private String shiftId; + + public String getShiftId() { + return shiftId; + } + + public void setShiftId(String shiftId) { + this.shiftId = shiftId; + } public String getEquCode() { return equCode; diff --git a/op-modules/op-mes/src/main/java/com/op/mes/domain/MesShift.java b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesShift.java new file mode 100644 index 00000000..f10d8353 --- /dev/null +++ b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesShift.java @@ -0,0 +1,39 @@ +package com.op.mes.domain; + +//班次实体类 +public class MesShift { + private Integer shiftId; + private String shiftDesc; + + @Override + public String toString() { + return "ProShift{" + + "shiftId=" + shiftId + + ", shiftDesc='" + shiftDesc + '\'' + + '}'; + } + + public Integer getShiftId() { + return shiftId; + } + + public void setShiftId(Integer shiftId) { + this.shiftId = shiftId; + } + + public String getShiftDesc() { + return shiftDesc; + } + + public void setShiftDesc(String shiftDesc) { + this.shiftDesc = shiftDesc; + } + + public MesShift(Integer shiftId, String shiftDesc) { + this.shiftId = shiftId; + this.shiftDesc = shiftDesc; + } + + public MesShift() { + } +} diff --git a/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesReportWorkMapper.java b/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesReportWorkMapper.java index c8f777df..0a15f017 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesReportWorkMapper.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesReportWorkMapper.java @@ -85,4 +85,6 @@ public interface MesReportWorkMapper { Map getHourProductionList(MesHourReport mesHourReport); List getEquNames(MesHourReport mesHourReport); + + List selectProShift(); } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/IMesReportWorkService.java b/op-modules/op-mes/src/main/java/com/op/mes/service/IMesReportWorkService.java index 4583c09e..3a358882 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/IMesReportWorkService.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/IMesReportWorkService.java @@ -75,4 +75,6 @@ public interface IMesReportWorkService { LineChartDto getLineChartData(MesReportProduction mesReportProduction); List getHourProductionList(MesHourReport mesHourReport); + + List getProShifts(); } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/IWCInterfaceServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/IWCInterfaceServiceImpl.java index a58c50d7..58062566 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/IWCInterfaceServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/IWCInterfaceServiceImpl.java @@ -150,7 +150,7 @@ public class IWCInterfaceServiceImpl implements IWCSInterfaceService { List totals = null; List everys = null; if("equ_type_lg".equals(boardDTO.getEquTypeCode())){//equ_type_lg 湿料罐 - boardDTO.setYmd(boardDTO.getYmd().replace("-","")); + totals = mesMapper.getTotalNumL(boardDTO); everys = mesMapper.getEveryNumL(boardDTO); }else{//成型机、烘房、收坯机 @@ -158,7 +158,6 @@ public class IWCInterfaceServiceImpl implements IWCSInterfaceService { everys = mesMapper.getEveryNum(boardDTO); } - boardMap.put("totalNum", totals); boardMap.put("everyNum", everys); return boardMap; diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesReportWorkServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesReportWorkServiceImpl.java index ebd15a20..13963b84 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesReportWorkServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesReportWorkServiceImpl.java @@ -289,6 +289,16 @@ public class MesReportWorkServiceImpl implements IMesReportWorkService { return days; } + /** + * 获取班次信息list + * @return + */ + @Override + @DS("#header.poolName") + public List getProShifts() { + return mesReportWorkMapper.selectProShift(); + } + public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); diff --git a/op-modules/op-mes/src/main/resources/mapper/mes/MesMapper.xml b/op-modules/op-mes/src/main/resources/mapper/mes/MesMapper.xml index 04cd7632..f08736df 100644 --- a/op-modules/op-mes/src/main/resources/mapper/mes/MesMapper.xml +++ b/op-modules/op-mes/src/main/resources/mapper/mes/MesMapper.xml @@ -116,23 +116,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(0) totalNum, equ.equipment_type_code equTypeCode, equ.equipment_type_name equTypeName - from pro_lg_used_log mt - left join base_equipment equ on mt.device_code = equ.equipment_code - where mt.createDate = #{ymd} and equ.equipment_name is not null - and equ.equipment_type_code = #{equTypeCode} + from mes_material_transfer_result mt + left join base_equipment equ on mt.equipmentCode = equ.equipment_code + where CONVERT(varchar(10),mt.create_time, 120) = #{ymd} and equ.equipment_name is not null + and equ.equipment_type_code = #{equTypeCode} and mt.status = 2 group by equ.equipment_type_code, equ.equipment_type_name diff --git a/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml b/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml index 61c3a72d..1d1c7b47 100644 --- a/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml +++ b/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml @@ -105,6 +105,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join pro_order_workorder pow on pow.workorder_id = mt.OrderCode left join pro_process ps on ps.process_id = mt.now_process_id where pow.order_code is not null + + and pow.shift_id = #{shiftId} + and pow.order_code like concat('%', #{orderCode}, '%') @@ -255,6 +258,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where 1=1 and CONVERT(varchar(30),mt.update_time, 120) >= #{productDateStart} and #{productDateEnd} > CONVERT(varchar(30),mt.update_time, 120) + + and pow.shift_id = #{shiftId} + and pow.order_code like concat('%', #{orderCode}, '%') @@ -297,7 +303,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join base_equipment equ on mt.equipmentCode = equ.equipment_code left join pro_order_workorder pow on pow.workorder_id = mt.OrderCode where pow.order_code is not null - + + and pow.shift_id = #{shiftId} + and pow.order_code like concat('%', #{orderCode}, '%') @@ -318,6 +326,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mt.equipmentCode, equ.equipment_name + insert into mes_report_work