更新快速排查功能

This commit is contained in:
2026-03-14 15:06:18 +08:00
parent 8f1e8c9381
commit 8cc5549850
13 changed files with 1540 additions and 1 deletions

View File

@@ -0,0 +1,55 @@
package com.klp.aps.controller;
import com.klp.aps.domain.dto.ApsQuickSheetQueryReq;
import com.klp.aps.domain.dto.ApsQuickSheetSaveReq;
import com.klp.aps.domain.vo.ApsQuickSheetRowVo;
import com.klp.aps.service.ApsQuickSheetService;
import com.klp.common.core.controller.BaseController;
import com.klp.common.core.domain.R;
import com.klp.common.helper.LoginHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RequiredArgsConstructor
@RestController
@RequestMapping("/aps/quick-sheet")
public class ApsQuickSheetController extends BaseController {
private final ApsQuickSheetService quickSheetService;
@GetMapping("/list")
public R<List<ApsQuickSheetRowVo>> list(@Validated ApsQuickSheetQueryReq req) {
return R.ok(quickSheetService.queryList(req));
}
@GetMapping("/preset")
public R<List<ApsQuickSheetRowVo>> preset(@RequestParam(value = "lineId", required = false) Long lineId) {
String salesman = LoginHelper.getNickName();
return R.ok(quickSheetService.buildPresetRows(lineId, salesman));
}
@PostMapping("/save")
public R<Void> save(@Validated @RequestBody ApsQuickSheetSaveReq req) {
quickSheetService.saveRows(req, getUsername());
return R.ok();
}
@GetMapping("/export")
public void export(@Validated ApsQuickSheetQueryReq req, javax.servlet.http.HttpServletResponse response) {
quickSheetService.exportExcel(req, response);
}
@PostMapping("/delete")
public R<Void> delete(@RequestParam("quickSheetId") Long quickSheetId) {
quickSheetService.deleteById(quickSheetId, getUsername());
return R.ok();
}
}

View File

@@ -0,0 +1,20 @@
package com.klp.aps.domain.dto;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
@Data
public class ApsQuickSheetQueryReq {
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate;
private Long lineId;
private String customerName;
}

View File

@@ -0,0 +1,35 @@
package com.klp.aps.domain.dto;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@Data
public class ApsQuickSheetSaveReq {
@NotEmpty(message = "rows 不能为空")
private List<Row> rows;
@Data
public static class Row {
private Long quickSheetId;
private Long lineId;
private String lineName;
private String planCode;
private String orderCode;
private String customerName;
private String salesman;
private String productName;
private String rawMaterialId;
private String rawCoilNos;
private String rawLocation;
private String rawPackaging;
private String rawEdgeReq;
private String rawCoatingType;
private String rawNetWeight;
private String planQty;
private String startTime;
private String endTime;
}
}

View File

@@ -0,0 +1,35 @@
package com.klp.aps.domain.entity;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
public class ApsQuickSheetEntity {
private Long quickSheetId;
private LocalDate planDate;
private Long lineId;
private String lineName;
private String planCode;
private String orderCode;
private String customerName;
private String salesman;
private String productName;
private String rawMaterialId;
private String rawCoilNos;
private String rawLocation;
private String rawPackaging;
private String rawEdgeReq;
private String rawCoatingType;
private BigDecimal rawNetWeight;
private BigDecimal planQty;
private LocalDateTime startTime;
private LocalDateTime endTime;
private String createBy;
private String updateBy;
private LocalDateTime createTime;
private LocalDateTime updateTime;
private Integer delFlag;
}

View File

@@ -0,0 +1,28 @@
package com.klp.aps.domain.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
public class ApsQuickSheetRowVo {
private Long quickSheetId;
private Long lineId;
private String lineName;
private String planCode;
private String orderCode;
private String customerName;
private String salesman;
private String productName;
private String rawMaterialId;
private String rawCoilNos;
private String rawLocation;
private String rawPackaging;
private String rawEdgeReq;
private String rawCoatingType;
private BigDecimal rawNetWeight;
private BigDecimal planQty;
private LocalDateTime startTime;
private LocalDateTime endTime;
}

View File

@@ -0,0 +1,73 @@
package com.klp.aps.mapper;
import com.klp.aps.domain.vo.ApsQuickSheetRowVo;
import com.klp.aps.domain.dto.ApsQuickSheetQueryReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface ApsQuickSheetMapper {
List<ApsQuickSheetRowVo> selectList(ApsQuickSheetQueryReq req);
@Select("SELECT COUNT(1) FROM aps_quick_sheet WHERE del_flag = 0 AND plan_date = #{planDate}")
int countToday(@Param("planDate") java.time.LocalDate planDate);
@Select("SELECT quick_sheet_id FROM aps_quick_sheet WHERE plan_code = #{planCode} AND del_flag = 0 LIMIT 1")
Long selectIdByPlanCode(@Param("planCode") String planCode);
@org.apache.ibatis.annotations.Insert("INSERT INTO aps_quick_sheet (line_id, line_name, plan_date, plan_code, order_code, customer_name, salesman, product_name, raw_material_id, raw_coil_nos, raw_location, raw_packaging, raw_edge_req, raw_coating_type, raw_net_weight, plan_qty, start_time, end_time, create_by, update_by, create_time, update_time, del_flag) "
+ "VALUES (#{lineId}, #{lineName}, #{planDate}, #{planCode}, #{orderCode}, #{customerName}, #{salesman}, #{productName}, #{rawMaterialId}, #{rawCoilNos}, #{rawLocation}, #{rawPackaging}, #{rawEdgeReq}, #{rawCoatingType}, #{rawNetWeight}, #{planQty}, #{startTime}, #{endTime}, #{createBy}, #{updateBy}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 0)")
int insertRow(@Param("lineId") Long lineId,
@Param("lineName") String lineName,
@Param("planDate") java.time.LocalDate planDate,
@Param("planCode") String planCode,
@Param("orderCode") String orderCode,
@Param("customerName") String customerName,
@Param("salesman") String salesman,
@Param("productName") String productName,
@Param("rawMaterialId") String rawMaterialId,
@Param("rawCoilNos") String rawCoilNos,
@Param("rawLocation") String rawLocation,
@Param("rawPackaging") String rawPackaging,
@Param("rawEdgeReq") String rawEdgeReq,
@Param("rawCoatingType") String rawCoatingType,
@Param("rawNetWeight") java.math.BigDecimal rawNetWeight,
@Param("planQty") java.math.BigDecimal planQty,
@Param("startTime") java.time.LocalDateTime startTime,
@Param("endTime") java.time.LocalDateTime endTime,
@Param("createBy") String createBy,
@Param("updateBy") String updateBy);
@org.apache.ibatis.annotations.Update("UPDATE aps_quick_sheet SET line_id = #{lineId}, line_name = #{lineName}, plan_code = #{planCode}, order_code = #{orderCode}, customer_name = #{customerName}, salesman = #{salesman}, product_name = #{productName}, raw_material_id = #{rawMaterialId}, raw_coil_nos = #{rawCoilNos}, raw_location = #{rawLocation}, raw_packaging = #{rawPackaging}, raw_edge_req = #{rawEdgeReq}, raw_coating_type = #{rawCoatingType}, raw_net_weight = #{rawNetWeight}, plan_qty = #{planQty}, start_time = #{startTime}, end_time = #{endTime}, update_by = #{updateBy}, update_time = CURRENT_TIMESTAMP WHERE quick_sheet_id = #{id}")
int updateRow(@Param("id") Long id,
@Param("lineId") Long lineId,
@Param("lineName") String lineName,
@Param("planCode") String planCode,
@Param("orderCode") String orderCode,
@Param("customerName") String customerName,
@Param("salesman") String salesman,
@Param("productName") String productName,
@Param("rawMaterialId") String rawMaterialId,
@Param("rawCoilNos") String rawCoilNos,
@Param("rawLocation") String rawLocation,
@Param("rawPackaging") String rawPackaging,
@Param("rawEdgeReq") String rawEdgeReq,
@Param("rawCoatingType") String rawCoatingType,
@Param("rawNetWeight") java.math.BigDecimal rawNetWeight,
@Param("planQty") java.math.BigDecimal planQty,
@Param("startTime") java.time.LocalDateTime startTime,
@Param("endTime") java.time.LocalDateTime endTime,
@Param("updateBy") String updateBy);
@org.apache.ibatis.annotations.Update("UPDATE aps_quick_sheet SET del_flag = 1, update_by = #{updateBy}, update_time = CURRENT_TIMESTAMP WHERE quick_sheet_id = #{id}")
int deleteRow(@Param("id") Long id, @Param("updateBy") String updateBy);
@org.apache.ibatis.annotations.Update("UPDATE aps_quick_sheet SET del_flag = 1, update_by = #{updateBy}, update_time = CURRENT_TIMESTAMP WHERE quick_sheet_id = #{id}")
int softDelete(@Param("id") Long id,
@Param("updateBy") String updateBy);
@org.apache.ibatis.annotations.Update("UPDATE aps_quick_sheet SET del_flag = 1, update_by = #{updateBy}, update_time = CURRENT_TIMESTAMP WHERE quick_sheet_id = #{id}")
int deleteById(@Param("id") Long id, @Param("updateBy") String updateBy);
}

View File

@@ -0,0 +1,20 @@
package com.klp.aps.service;
import com.klp.aps.domain.dto.ApsQuickSheetQueryReq;
import com.klp.aps.domain.dto.ApsQuickSheetSaveReq;
import com.klp.aps.domain.vo.ApsQuickSheetRowVo;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
public interface ApsQuickSheetService {
List<ApsQuickSheetRowVo> queryList(ApsQuickSheetQueryReq req);
void saveRows(ApsQuickSheetSaveReq req, String operator);
List<ApsQuickSheetRowVo> buildPresetRows(Long lineId, String salesman);
void exportExcel(ApsQuickSheetQueryReq req, HttpServletResponse response);
void deleteById(Long id, String operator);
}

View File

@@ -0,0 +1,214 @@
package com.klp.aps.service.impl;
import com.klp.aps.domain.dto.ApsQuickSheetSaveReq;
import com.klp.aps.domain.vo.ApsQuickSheetRowVo;
import com.klp.aps.mapper.ApsQuickSheetMapper;
import com.klp.aps.service.ApsQuickSheetService;
import com.klp.common.exception.ServiceException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@RequiredArgsConstructor
@Service
public class ApsQuickSheetServiceImpl implements ApsQuickSheetService {
private final ApsQuickSheetMapper quickSheetMapper;
private static final DateTimeFormatter DATE_CODE = DateTimeFormatter.ofPattern("yyyyMMdd");
@Override
public List<ApsQuickSheetRowVo> queryList(com.klp.aps.domain.dto.ApsQuickSheetQueryReq req) {
return quickSheetMapper.selectList(req);
}
@Override
public void saveRows(ApsQuickSheetSaveReq req, String operator) {
if (req == null || req.getRows() == null) {
throw new ServiceException("保存数据不能为空");
}
for (ApsQuickSheetSaveReq.Row row : req.getRows()) {
if (row == null) continue;
Long id = row.getQuickSheetId();
Long lineId = row.getLineId();
String lineName = row.getLineName();
String planCode = row.getPlanCode();
String orderCode = row.getOrderCode();
String customerName = row.getCustomerName();
String salesman = row.getSalesman();
String productName = row.getProductName();
String rawMaterialId = row.getRawMaterialId();
String rawCoilNos = row.getRawCoilNos();
String rawLocation = row.getRawLocation();
String rawPackaging = row.getRawPackaging();
String rawEdgeReq = row.getRawEdgeReq();
String rawCoatingType = row.getRawCoatingType();
BigDecimal rawNetWeight = parseQty(row.getRawNetWeight());
BigDecimal planQty = parseQty(row.getPlanQty());
LocalDateTime startTime = parseTime(row.getStartTime());
LocalDateTime endTime = parseTime(row.getEndTime());
boolean hasAny = lineId != null || isNotBlank(lineName) || isNotBlank(planCode) || isNotBlank(orderCode)
|| isNotBlank(customerName) || isNotBlank(salesman) || isNotBlank(productName)
|| isNotBlank(rawMaterialId) || isNotBlank(rawCoilNos) || isNotBlank(rawLocation)
|| isNotBlank(rawPackaging) || isNotBlank(rawEdgeReq) || isNotBlank(rawCoatingType)
|| rawNetWeight != null || planQty != null || startTime != null || endTime != null;
if (!hasAny) {
continue;
}
if (id == null) {
if (!isNotBlank(planCode)) {
planCode = buildPlanCode();
}
quickSheetMapper.insertRow(lineId, lineName, LocalDate.now(), planCode, orderCode, customerName, salesman, productName,
rawMaterialId, rawCoilNos, rawLocation, rawPackaging, rawEdgeReq, rawCoatingType, rawNetWeight, planQty, startTime, endTime, operator, operator);
} else {
quickSheetMapper.updateRow(id, lineId, lineName, planCode, orderCode, customerName, salesman, productName,
rawMaterialId, rawCoilNos, rawLocation, rawPackaging, rawEdgeReq, rawCoatingType, rawNetWeight, planQty, startTime, endTime, operator);
}
}
}
@Override
public List<ApsQuickSheetRowVo> buildPresetRows(Long lineId, String salesman) {
List<ApsQuickSheetRowVo> rows = new ArrayList<>();
LocalDateTime now = LocalDateTime.now();
LocalDateTime end = now.plusHours(1);
for (int i = 0; i < 3; i++) {
ApsQuickSheetRowVo row = new ApsQuickSheetRowVo();
row.setLineId(lineId);
row.setLineName(lineId == null ? null : ("产线" + lineId));
row.setSalesman(salesman);
row.setPlanQty(BigDecimal.ZERO);
row.setStartTime(now);
row.setEndTime(end);
row.setPlanCode(buildPlanCode());
rows.add(row);
}
return rows;
}
@Override
public void exportExcel(com.klp.aps.domain.dto.ApsQuickSheetQueryReq req, javax.servlet.http.HttpServletResponse response) {
List<ApsQuickSheetRowVo> rows = queryList(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("快速排产表");
int r = 0;
org.apache.poi.ss.usermodel.Row title = sheet.createRow(r++);
title.setHeightInPoints(36f);
org.apache.poi.ss.usermodel.Cell t0 = title.createCell(0);
t0.setCellValue("快速排产表Excel录入");
sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 0, 0, 14));
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();
titleFont.setBold(true);
titleFont.setFontHeightInPoints((short) 15);
titleStyle.setFont(titleFont);
t0.setCellStyle(titleStyle);
String[] headers = new String[]{
"产线", "计划号", "订单号", "客户", "业务员", "产品",
"原料钢卷", "原料卷号", "钢卷位置", "包装要求", "切边要求", "镀层种类",
"原料净重", "计划数量", "开始时间", "结束时间"
};
org.apache.poi.ss.usermodel.Row head = sheet.createRow(r++);
for (int i = 0; i < headers.length; i++) {
head.createCell(i).setCellValue(headers[i]);
}
if (rows != null) {
for (ApsQuickSheetRowVo row : rows) {
org.apache.poi.ss.usermodel.Row rr = sheet.createRow(r++);
int cc = 0;
rr.createCell(cc++).setCellValue(nvl(row.getLineName(), row.getLineId()));
rr.createCell(cc++).setCellValue(nvl(row.getPlanCode(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getOrderCode(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getCustomerName(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getSalesman(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getProductName(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawMaterialId(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawCoilNos(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawLocation(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawPackaging(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawEdgeReq(), ""));
rr.createCell(cc++).setCellValue(nvl(row.getRawCoatingType(), ""));
rr.createCell(cc++).setCellValue(row.getRawNetWeight() == null ? "" : row.getRawNetWeight().toPlainString());
rr.createCell(cc++).setCellValue(row.getPlanQty() == null ? "" : row.getPlanQty().toPlainString());
rr.createCell(cc++).setCellValue(row.getStartTime() == null ? "" : row.getStartTime().toString());
rr.createCell(cc++).setCellValue(row.getEndTime() == null ? "" : row.getEndTime().toString());
}
}
for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i, true);
int w = sheet.getColumnWidth(i);
sheet.setColumnWidth(i, Math.min(Math.max(w, 3000), 12000));
}
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());
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encoded);
try (javax.servlet.ServletOutputStream os = response.getOutputStream()) {
wb.write(os);
os.flush();
}
} catch (java.io.IOException e) {
throw new ServiceException("导出失败:" + e.getMessage());
}
}
private String buildPlanCode() {
LocalDate today = LocalDate.now();
int seq = quickSheetMapper.countToday(today) + 1;
return today.format(DATE_CODE) + String.format("%03d", seq);
}
private String nvl(Object v, Object fallback) {
if (v == null) return String.valueOf(fallback);
String s = String.valueOf(v);
return s == null ? String.valueOf(fallback) : s;
}
@Override
public void deleteById(Long id, String operator) {
if (id == null) return;
quickSheetMapper.deleteRow(id, operator);
}
private BigDecimal parseQty(String val) {
if (val == null || val.trim().isEmpty()) return null;
try {
return new BigDecimal(val.trim());
} catch (Exception e) {
return null;
}
}
private boolean isNotBlank(String val) {
return val != null && !val.trim().isEmpty();
}
private LocalDateTime parseTime(String val) {
if (val == null || val.trim().isEmpty()) return null;
String v = val.trim();
if (v.length() == 16) v = v + ":00";
try {
return LocalDateTime.parse(v, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} catch (Exception e) {
return null;
}
}
}

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.klp.aps.mapper.ApsQuickSheetMapper">
<select id="selectList" parameterType="com.klp.aps.domain.dto.ApsQuickSheetQueryReq" resultType="com.klp.aps.domain.vo.ApsQuickSheetRowVo">
SELECT
quick_sheet_id AS quickSheetId,
line_id AS lineId,
line_name AS lineName,
plan_code AS planCode,
order_code AS orderCode,
customer_name AS customerName,
salesman,
product_name AS productName,
raw_material_id AS rawMaterialId,
raw_coil_nos AS rawCoilNos,
raw_location AS rawLocation,
raw_packaging AS rawPackaging,
raw_edge_req AS rawEdgeReq,
raw_coating_type AS rawCoatingType,
raw_net_weight AS rawNetWeight,
plan_qty AS planQty,
start_time AS startTime,
end_time AS endTime
FROM aps_quick_sheet
WHERE del_flag = 0
<if test="startDate != null">
AND start_time <![CDATA[>=]]> CONCAT(#{startDate}, ' 00:00:00')
</if>
<if test="endDate != null">
AND start_time <![CDATA[<=]]> CONCAT(#{endDate}, ' 23:59:59')
</if>
<if test="lineId != null">
AND line_id = #{lineId}
</if>
<if test="customerName != null and customerName != ''">
AND customer_name LIKE CONCAT('%', #{customerName}, '%')
</if>
ORDER BY quick_sheet_id DESC
</select>
</mapper>