diff --git a/klp-aps/src/main/java/com/klp/aps/domain/dto/ApsPlanSheetQueryReq.java b/klp-aps/src/main/java/com/klp/aps/domain/dto/ApsPlanSheetQueryReq.java index 255a719c..7e2dc308 100644 --- a/klp-aps/src/main/java/com/klp/aps/domain/dto/ApsPlanSheetQueryReq.java +++ b/klp-aps/src/main/java/com/klp/aps/domain/dto/ApsPlanSheetQueryReq.java @@ -8,16 +8,6 @@ import java.time.LocalDate; @Data public class ApsPlanSheetQueryReq { - @DateTimeFormat(pattern = "yyyy-MM-dd") - private LocalDate startDate; - - @DateTimeFormat(pattern = "yyyy-MM-dd") - private LocalDate endDate; - - private Long lineId; - // planSheetId private Long planSheetId; - - private String customerName; } diff --git a/klp-aps/src/main/java/com/klp/aps/service/impl/ApsPlanSheetServiceImpl.java b/klp-aps/src/main/java/com/klp/aps/service/impl/ApsPlanSheetServiceImpl.java index 0877bd1d..9911ee01 100644 --- a/klp-aps/src/main/java/com/klp/aps/service/impl/ApsPlanSheetServiceImpl.java +++ b/klp-aps/src/main/java/com/klp/aps/service/impl/ApsPlanSheetServiceImpl.java @@ -13,6 +13,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.klp.common.exception.ServiceException; import com.klp.common.utils.StringUtils; import lombok.RequiredArgsConstructor; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.usermodel.XSSFFont; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.stereotype.Service; import com.klp.aps.domain.bo.ApsPlanSheetBo; import com.klp.aps.domain.vo.ApsPlanSheetVo; @@ -21,6 +25,11 @@ import com.klp.aps.mapper.ApsPlanSheetMapper; import com.klp.aps.service.IApsPlanSheetService; import com.klp.aps.service.IApsPlanDetailService; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import java.util.Collection; @@ -42,7 +51,7 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService { * 查询排产单主 */ @Override - public ApsPlanSheetVo queryById(Long planSheetId){ + public ApsPlanSheetVo queryById(Long planSheetId) { return baseMapper.selectVoById(planSheetId); } @@ -104,7 +113,7 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService { /** * 保存前的数据校验 */ - private void validEntityBeforeSave(ApsPlanSheet entity){ + private void validEntityBeforeSave(ApsPlanSheet entity) { //TODO 做一些数据校验,如唯一约束 } @@ -113,7 +122,7 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService { */ @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { - if(isValid){ + if (isValid) { //TODO 做一些业务上的校验,判断是否需要校验 } planDetailService.deleteByPlanSheetIds(ids); @@ -121,22 +130,28 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService { } @Override - public void exportExcel(ApsPlanSheetQueryReq req, javax.servlet.http.HttpServletResponse response) { + public void exportExcel(ApsPlanSheetQueryReq req, HttpServletResponse response) { List rows = queryListAll(req); - try (org.apache.poi.ss.usermodel.Workbook wb = new org.apache.poi.xssf.usermodel.XSSFWorkbook()) { - org.apache.poi.ss.usermodel.Sheet sheet = wb.createSheet("快速排产表"); + try (Workbook wb = new XSSFWorkbook()) { + Sheet sheet = wb.createSheet("快速排产表"); int r = 0; - org.apache.poi.ss.usermodel.Row title = sheet.createRow(r++); + Row title = sheet.createRow(r++); title.setHeightInPoints(36f); - org.apache.poi.ss.usermodel.Cell t0 = title.createCell(0); - t0.setCellValue("快速排产表"); - sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 0, 0, 38)); + Cell t0 = title.createCell(0); + Long planSheetId = req.getPlanSheetId(); + if (planSheetId != null) { + ApsPlanSheetVo planSheet = queryById(planSheetId); + t0.setCellValue(planSheet.getPlanDate().toString() + "————" + planSheet.getLineName() + "————" + planSheet.getPlanCode()); + } else { + t0.setCellValue("快速排产表"); + } + sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 38)); - org.apache.poi.ss.usermodel.CellStyle titleStyle = wb.createCellStyle(); - titleStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER); - titleStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER); - org.apache.poi.xssf.usermodel.XSSFFont titleFont = ((org.apache.poi.xssf.usermodel.XSSFWorkbook) wb).createFont(); + CellStyle titleStyle = wb.createCellStyle(); + titleStyle.setAlignment(HorizontalAlignment.CENTER); + titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); + XSSFFont titleFont = ((XSSFWorkbook) wb).createFont(); titleFont.setBold(true); titleFont.setFontHeightInPoints((short) 15); titleStyle.setFont(titleFont); @@ -150,15 +165,50 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService { "厂家", "原料信息", "原料厚度mm", "宽度mm", "原料钢卷", "原料卷号", "钢卷位置", "包装要求", "镀层种类", "原料净重", "开始时间", "结束时间", "明细备注" }; + + // ===================== 【绝对不报错】表头样式 ===================== + org.apache.poi.ss.usermodel.CellStyle headStyle = wb.createCellStyle(); + org.apache.poi.ss.usermodel.Font headFont = wb.createFont(); + + // 1. 字体加粗 + headFont.setBold(true); + headStyle.setFont(headFont); + + // 2. 居中 + headStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER); + headStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER); + + // 3. 背景颜色(浅蓝色) + headStyle.setFillPattern(org.apache.poi.ss.usermodel.FillPatternType.SOLID_FOREGROUND); + headStyle.setFillForegroundColor(org.apache.poi.ss.usermodel.IndexedColors.PALE_BLUE.getIndex()); + + // 4. 自动换行 + headStyle.setWrapText(true); + + // 创建表头行 org.apache.poi.ss.usermodel.Row head = sheet.createRow(r++); + head.setHeightInPoints(24); + + // 设置表头内容 + 样式 for (int i = 0; i < headers.length; i++) { - head.createCell(i).setCellValue(headers[i]); + org.apache.poi.ss.usermodel.Cell cell = head.createCell(i); + cell.setCellValue(headers[i]); + cell.setCellStyle(headStyle); } - if (rows != null) { + // ================== 【统一样式:前7列居中】 ================== + CellStyle centerStyle = wb.createCellStyle(); + centerStyle.setAlignment(HorizontalAlignment.CENTER); + centerStyle.setVerticalAlignment(VerticalAlignment.CENTER); + + // ================== 数据行 ================== + int dataStartRow = r; + if (rows != null && !rows.isEmpty()) { for (ApsPlanSheetRowVo row : rows) { - org.apache.poi.ss.usermodel.Row rr = sheet.createRow(r++); + Row rr = sheet.createRow(r++); int cc = 0; + + // ====== 前7列:相同内容,需要居中 + 后续合并 ====== rr.createCell(cc++).setCellValue(nvl(row.getLineName(), row.getLineId())); rr.createCell(cc++).setCellValue(row.getPlanDate() == null ? "" : row.getPlanDate().toString()); rr.createCell(cc++).setCellValue(nvl(row.getPlanCode(), "")); @@ -167,6 +217,12 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService { rr.createCell(cc++).setCellValue(nvl(row.getUpdateBy(), "")); rr.createCell(cc++).setCellValue(nvl(row.getMasterRemark(), "")); + // 前7列设置居中 + for (int i = 0; i < 7; i++) { + rr.getCell(i).setCellStyle(centerStyle); + } + + // ====== 后面列不变 ====== rr.createCell(cc++).setCellValue(nvl(row.getBizSeqNo(), "")); rr.createCell(cc++).setCellValue(nvl(row.getOrderCode(), "")); rr.createCell(cc++).setCellValue(nvl(row.getContractCode(), "")); @@ -207,6 +263,21 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService { } } + // ================== 【核心:前7列自动合并】 ================== + int dataEndRow = r - 1; + if (dataStartRow <= dataEndRow) { + for (int col = 0; col < 7; col++) { // 0~6 共7列 + CellRangeAddress region = new CellRangeAddress( + dataStartRow, + dataEndRow, + col, + col + ); + sheet.addMergedRegion(region); + } + } + + // 自适应列宽 for (int i = 0; i < headers.length; i++) { sheet.autoSizeColumn(i, true); int w = sheet.getColumnWidth(i); @@ -214,16 +285,16 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService { } String filename = "aps_quick_sheet_" + System.currentTimeMillis() + ".xlsx"; - String encoded = java.net.URLEncoder.encode(filename, java.nio.charset.StandardCharsets.UTF_8.name()); - response.setCharacterEncoding(java.nio.charset.StandardCharsets.UTF_8.name()); + String encoded = URLEncoder.encode(filename, StandardCharsets.UTF_8.name()); + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encoded); - try (javax.servlet.ServletOutputStream os = response.getOutputStream()) { + try (ServletOutputStream os = response.getOutputStream()) { wb.write(os); os.flush(); } - } catch (java.io.IOException e) { + } catch (IOException e) { throw new ServiceException("导出失败:" + e.getMessage()); } } diff --git a/klp-aps/src/main/resources/mapper/aps/ApsPlanSheetMapper.xml b/klp-aps/src/main/resources/mapper/aps/ApsPlanSheetMapper.xml index 111cfe8b..28386431 100644 --- a/klp-aps/src/main/resources/mapper/aps/ApsPlanSheetMapper.xml +++ b/klp-aps/src/main/resources/mapper/aps/ApsPlanSheetMapper.xml @@ -67,22 +67,10 @@ FROM aps_plan_sheet s INNER JOIN aps_plan_detail d ON d.plan_sheet_id = s.plan_sheet_id AND d.del_flag = 0 WHERE s.del_flag = 0 - - AND d.start_time =]]> CONCAT(#{startDate}, ' 00:00:00') - - - AND d.start_time CONCAT(#{endDate}, ' 23:59:59') - - - AND s.line_id = #{lineId} - AND s.plan_sheet_id = #{planSheetId} - - AND d.customer_name LIKE CONCAT('%', #{customerName}, '%') - - ORDER BY d.plan_detail_id DESC + ORDER BY CAST(d.biz_seq_no AS UNSIGNED) ASC diff --git a/klp-wms/src/main/resources/mapper/klp/WmsTransferOrderItemMapper.xml b/klp-wms/src/main/resources/mapper/klp/WmsTransferOrderItemMapper.xml index 12c5a500..a4389c2c 100644 --- a/klp-wms/src/main/resources/mapper/klp/WmsTransferOrderItemMapper.xml +++ b/klp-wms/src/main/resources/mapper/klp/WmsTransferOrderItemMapper.xml @@ -5,7 +5,7 @@ - +