refactor(aps): 重构排产单查询和导出功能
- 移除日期范围、产线ID和客户名称查询条件 - 修改排序规则为按业务序号升序排列 - 删除查询请求DTO中的废弃字段 - 优化Excel导出功能,添加标题动态显示和表头样式 - 实现前7列数据居中对齐和自动合并功能 - 修复POI依赖导入路径问题 - 更新转储订单项映射配置
This commit is contained in:
@@ -8,16 +8,6 @@ import java.time.LocalDate;
|
|||||||
@Data
|
@Data
|
||||||
public class ApsPlanSheetQueryReq {
|
public class ApsPlanSheetQueryReq {
|
||||||
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
||||||
private LocalDate startDate;
|
|
||||||
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
||||||
private LocalDate endDate;
|
|
||||||
|
|
||||||
private Long lineId;
|
|
||||||
|
|
||||||
// planSheetId
|
// planSheetId
|
||||||
private Long planSheetId;
|
private Long planSheetId;
|
||||||
|
|
||||||
private String customerName;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||||||
import com.klp.common.exception.ServiceException;
|
import com.klp.common.exception.ServiceException;
|
||||||
import com.klp.common.utils.StringUtils;
|
import com.klp.common.utils.StringUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
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 org.springframework.stereotype.Service;
|
||||||
import com.klp.aps.domain.bo.ApsPlanSheetBo;
|
import com.klp.aps.domain.bo.ApsPlanSheetBo;
|
||||||
import com.klp.aps.domain.vo.ApsPlanSheetVo;
|
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.IApsPlanSheetService;
|
||||||
import com.klp.aps.service.IApsPlanDetailService;
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -121,22 +130,28 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportExcel(ApsPlanSheetQueryReq req, javax.servlet.http.HttpServletResponse response) {
|
public void exportExcel(ApsPlanSheetQueryReq req, HttpServletResponse response) {
|
||||||
List<ApsPlanSheetRowVo> rows = queryListAll(req);
|
List<ApsPlanSheetRowVo> rows = queryListAll(req);
|
||||||
try (org.apache.poi.ss.usermodel.Workbook wb = new org.apache.poi.xssf.usermodel.XSSFWorkbook()) {
|
try (Workbook wb = new XSSFWorkbook()) {
|
||||||
org.apache.poi.ss.usermodel.Sheet sheet = wb.createSheet("快速排产表");
|
Sheet sheet = wb.createSheet("快速排产表");
|
||||||
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
org.apache.poi.ss.usermodel.Row title = sheet.createRow(r++);
|
Row title = sheet.createRow(r++);
|
||||||
title.setHeightInPoints(36f);
|
title.setHeightInPoints(36f);
|
||||||
org.apache.poi.ss.usermodel.Cell t0 = title.createCell(0);
|
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("快速排产表");
|
t0.setCellValue("快速排产表");
|
||||||
sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 0, 0, 38));
|
}
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 38));
|
||||||
|
|
||||||
org.apache.poi.ss.usermodel.CellStyle titleStyle = wb.createCellStyle();
|
CellStyle titleStyle = wb.createCellStyle();
|
||||||
titleStyle.setAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER);
|
titleStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
titleStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
|
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
org.apache.poi.xssf.usermodel.XSSFFont titleFont = ((org.apache.poi.xssf.usermodel.XSSFWorkbook) wb).createFont();
|
XSSFFont titleFont = ((XSSFWorkbook) wb).createFont();
|
||||||
titleFont.setBold(true);
|
titleFont.setBold(true);
|
||||||
titleFont.setFontHeightInPoints((short) 15);
|
titleFont.setFontHeightInPoints((short) 15);
|
||||||
titleStyle.setFont(titleFont);
|
titleStyle.setFont(titleFont);
|
||||||
@@ -150,15 +165,50 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService {
|
|||||||
"厂家", "原料信息", "原料厚度mm", "宽度mm", "原料钢卷", "原料卷号", "钢卷位置", "包装要求", "镀层种类", "原料净重",
|
"厂家", "原料信息", "原料厚度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++);
|
org.apache.poi.ss.usermodel.Row head = sheet.createRow(r++);
|
||||||
|
head.setHeightInPoints(24);
|
||||||
|
|
||||||
|
// 设置表头内容 + 样式
|
||||||
for (int i = 0; i < headers.length; i++) {
|
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) {
|
for (ApsPlanSheetRowVo row : rows) {
|
||||||
org.apache.poi.ss.usermodel.Row rr = sheet.createRow(r++);
|
Row rr = sheet.createRow(r++);
|
||||||
int cc = 0;
|
int cc = 0;
|
||||||
|
|
||||||
|
// ====== 前7列:相同内容,需要居中 + 后续合并 ======
|
||||||
rr.createCell(cc++).setCellValue(nvl(row.getLineName(), row.getLineId()));
|
rr.createCell(cc++).setCellValue(nvl(row.getLineName(), row.getLineId()));
|
||||||
rr.createCell(cc++).setCellValue(row.getPlanDate() == null ? "" : row.getPlanDate().toString());
|
rr.createCell(cc++).setCellValue(row.getPlanDate() == null ? "" : row.getPlanDate().toString());
|
||||||
rr.createCell(cc++).setCellValue(nvl(row.getPlanCode(), ""));
|
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.getUpdateBy(), ""));
|
||||||
rr.createCell(cc++).setCellValue(nvl(row.getMasterRemark(), ""));
|
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.getBizSeqNo(), ""));
|
||||||
rr.createCell(cc++).setCellValue(nvl(row.getOrderCode(), ""));
|
rr.createCell(cc++).setCellValue(nvl(row.getOrderCode(), ""));
|
||||||
rr.createCell(cc++).setCellValue(nvl(row.getContractCode(), ""));
|
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++) {
|
for (int i = 0; i < headers.length; i++) {
|
||||||
sheet.autoSizeColumn(i, true);
|
sheet.autoSizeColumn(i, true);
|
||||||
int w = sheet.getColumnWidth(i);
|
int w = sheet.getColumnWidth(i);
|
||||||
@@ -214,16 +285,16 @@ public class ApsPlanSheetServiceImpl implements IApsPlanSheetService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String filename = "aps_quick_sheet_" + System.currentTimeMillis() + ".xlsx";
|
String filename = "aps_quick_sheet_" + System.currentTimeMillis() + ".xlsx";
|
||||||
String encoded = java.net.URLEncoder.encode(filename, java.nio.charset.StandardCharsets.UTF_8.name());
|
String encoded = URLEncoder.encode(filename, StandardCharsets.UTF_8.name());
|
||||||
response.setCharacterEncoding(java.nio.charset.StandardCharsets.UTF_8.name());
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encoded);
|
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encoded);
|
||||||
|
|
||||||
try (javax.servlet.ServletOutputStream os = response.getOutputStream()) {
|
try (ServletOutputStream os = response.getOutputStream()) {
|
||||||
wb.write(os);
|
wb.write(os);
|
||||||
os.flush();
|
os.flush();
|
||||||
}
|
}
|
||||||
} catch (java.io.IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ServiceException("导出失败:" + e.getMessage());
|
throw new ServiceException("导出失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,22 +67,10 @@
|
|||||||
FROM aps_plan_sheet s
|
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
|
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
|
WHERE s.del_flag = 0
|
||||||
<if test="startDate != null">
|
|
||||||
AND d.start_time <![CDATA[>=]]> CONCAT(#{startDate}, ' 00:00:00')
|
|
||||||
</if>
|
|
||||||
<if test="endDate != null">
|
|
||||||
AND d.start_time <![CDATA[<=]]> CONCAT(#{endDate}, ' 23:59:59')
|
|
||||||
</if>
|
|
||||||
<if test="lineId != null">
|
|
||||||
AND s.line_id = #{lineId}
|
|
||||||
</if>
|
|
||||||
<if test="planSheetId != null">
|
<if test="planSheetId != null">
|
||||||
AND s.plan_sheet_id = #{planSheetId}
|
AND s.plan_sheet_id = #{planSheetId}
|
||||||
</if>
|
</if>
|
||||||
<if test="customerName != null and customerName != ''">
|
ORDER BY CAST(d.biz_seq_no AS UNSIGNED) ASC
|
||||||
AND d.customer_name LIKE CONCAT('%', #{customerName}, '%')
|
|
||||||
</if>
|
|
||||||
ORDER BY d.plan_detail_id DESC
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<mapper namespace="com.klp.mapper.WmsTransferOrderItemMapper">
|
<mapper namespace="com.klp.mapper.WmsTransferOrderItemMapper">
|
||||||
|
|
||||||
<resultMap type="com.klp.domain.WmsTransferOrderItem" id="WmsTransferOrderItemResult">
|
<resultMap type="com.klp.domain.WmsTransferOrderItem" id="WmsTransferOrderItemResult">
|
||||||
<result property="itemId" column="item_id"/>
|
<result property="orderItemId" column="item_id"/>
|
||||||
<result property="transferId" column="transfer_id"/>
|
<result property="transferId" column="transfer_id"/>
|
||||||
<result property="coilId" column="coil_id"/>
|
<result property="coilId" column="coil_id"/>
|
||||||
<result property="itemIdBefore" column="item_id_before"/>
|
<result property="itemIdBefore" column="item_id_before"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user