更新快速排查功能
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user