From b176072388747abb438990157bfa305b215b4b90 Mon Sep 17 00:00:00 2001
From: zwl <1051256694@qq.com>
Date: 星期二, 14 四月 2026 21:59:39 +0800
Subject: [PATCH] 我们现在讨论一下系统找库位方案, 如何实现,对现有找库位规则进行整改,数据库也要整改 1、要能方便的填写单伸堆垛机或双伸堆垛机的深浅库位配置 2、根据设备状态分配库位,离线设备不分配 3、库位分配要均衡到每一个设备 4、库位高度需要匹配到对应库位信息,低库位能向上兼容 5、空托盘优先放在locType2库位=1的库位,没有这种库位了,允许放到其他库位 6、给入库站点设置有限去那些堆垛机,其次去那些堆垛机,弄成页面可以配置入库站点 7、在系统配置新增优先放前几列的配置,当入库的货物是高频货物时放在前几列 8、组托中会标识该托盘是高频还是低频,如果是高频则从前往后找库位,如果是低频则从后往前找库位 9、找库位时locMast中whsType字段无用
---
src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java | 434 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 434 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
index f096761..fae0285 100644
--- a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -19,6 +19,7 @@
import com.zy.asrs.utils.Utils;
import com.zy.common.constant.AgvConstant;
import com.zy.common.constant.ArmConstant;
+import com.zy.common.entity.Parameter;
import com.zy.common.model.DetlDto;
import com.zy.common.model.LocDetlDto;
import com.zy.common.model.LocDto;
@@ -33,6 +34,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -42,6 +45,15 @@
@Slf4j
@Service
public class OpenServiceImpl implements OpenService {
+
+ private static final Map<Integer, BigDecimal> INBOUND_WEIGHT_FACTOR_BY_SOURCE_STA;
+ private static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+ static {
+ Map<Integer, BigDecimal> factorMap = new HashMap<>();
+ factorMap.put(112, new BigDecimal("0.98"));
+ INBOUND_WEIGHT_FACTOR_BY_SOURCE_STA = Collections.unmodifiableMap(factorMap);
+ }
@Autowired
private OrderService orderService;
@@ -89,12 +101,22 @@
private String stationAddress;
@Value("${erp.address.URL:}")
private String erpUrl;
+ @Value("${erp.switch.ErpReportOld}")
+ private boolean erpReportOld;
+ @Value("${erp.address.Inaddress:}")
+ private String erpInAddress;
@Value("${erp.address.OutErroraddress:}")
private String erpOutErrorAddress;
@Autowired
private WaitPakinService waitPakinService;
@Autowired
+ private WaitPakinLogService waitPakinLogService;
+ @Autowired
private WrkMastService wrkMastService;
+ @Autowired
+ private WrkMastLogService wrkMastLogService;
+ @Autowired
+ private WrkDetlLogService wrkDetlLogService;
@Autowired
private WcsApiService wcsApiService;
@Autowired
@@ -659,6 +681,117 @@
@Transactional
public List<StockVo> queryStock() {
return locDetlService.queryStockTotal();
+ }
+
+ @Override
+ public R reportPakinHistoryToErp(List<String> barcodes) {
+ List<String> normalizedBarcodes = normalizeBarcodes(barcodes);
+ if (normalizedBarcodes.isEmpty()) {
+ return R.error("鎵樼洏鐮侀泦鍚堜笉鑳戒负绌�");
+ }
+ if (!isErpReportEnabled()) {
+ return R.error("ERP reporting is disabled");
+ }
+ if (Cools.isEmpty(erpInAddress)) {
+ return R.error("ERP鍏ュ簱涓婃姤鍦板潃鏈厤缃�");
+ }
+
+ Map<String, WrkMastLog> latestInboundLogMap = loadLatestInboundHistoryLogMap(normalizedBarcodes);
+ Map<Integer, List<WrkDetlLog>> wrkDetlLogMap = loadWrkDetlLogMap(latestInboundLogMap.values());
+ Map<String, WaitPakinLog> waitPakinLogMap = loadWaitPakinLogMap(normalizedBarcodes);
+ String requestUrl = buildErpInboundRequestUrl();
+
+ List<Map<String, Object>> rows = new ArrayList<>();
+ int successCount = 0;
+ int failCount = 0;
+
+ for (String barcode : normalizedBarcodes) {
+ Map<String, Object> row = new LinkedHashMap<>();
+ row.put("barcode", barcode);
+
+ WrkMastLog wrkMastLog = latestInboundLogMap.get(barcode);
+ if (wrkMastLog == null) {
+ row.put("success", false);
+ row.put("message", "鏈壘鍒版渶鏂板叆搴撳巻鍙茶褰�");
+ rows.add(row);
+ failCount++;
+ continue;
+ }
+
+ WaitPakinLog waitPakinLog = waitPakinLogMap.get(barcode);
+ List<WrkDetlLog> wrkDetlLogs = wrkDetlLogMap.getOrDefault(wrkMastLog.getWrkNo(), Collections.emptyList());
+ ErpPakinReportParam param = buildInboundErpParam(barcode, wrkMastLog, wrkDetlLogs, waitPakinLog);
+ if (Cools.isEmpty(param.getPalletId())) {
+ row.put("success", false);
+ row.put("message", "鎵樼洏鐮佺己灏戜笂鎶ュ瓧娈礫palletId]");
+ rows.add(row);
+ failCount++;
+ continue;
+ }
+ if (Cools.isEmpty(param.getLocId())) {
+ row.put("success", false);
+ row.put("message", "鎵樼洏鐮佺己灏戜笂鎶ュ瓧娈礫locId]");
+ rows.add(row);
+ failCount++;
+ continue;
+ }
+
+ String request = JSON.toJSONString(param);
+ String response = "";
+ boolean success = false;
+ String errorMsg = null;
+ try {
+ response = new HttpHandler.Builder()
+ .setUri(erpUrl)
+ .setPath(erpInAddress)
+ .setJson(request)
+ .build()
+ .doPost();
+ success = isErpCallSuccess(response);
+ if (!success) {
+ errorMsg = extractErpCallError(response);
+ }
+ } catch (Exception e) {
+ errorMsg = e.getMessage();
+ } finally {
+ try {
+ apiLogService.save(
+ "Inbound ERP Report",
+ requestUrl,
+ null,
+ "127.0.0.1",
+ request,
+ response,
+ success,
+ "barcode=" + barcode + ",workNo=" + wrkMastLog.getWrkNo()
+ );
+ } catch (Exception logEx) {
+ log.error("save inbound erp api log failed", logEx);
+ }
+ }
+
+ row.put("workNo", wrkMastLog.getWrkNo());
+ Integer sourceStaNo = resolveInboundSourceStaNo(wrkMastLog);
+ row.put("sourceStaNo", sourceStaNo);
+ row.put("weightFactor", resolveInboundWeightFactor(sourceStaNo));
+ row.put("erpWeight", param.getWeight());
+ row.put("success", success);
+ row.put("message", success ? "OK" : errorMsg);
+ rows.add(row);
+
+ if (success) {
+ successCount++;
+ } else {
+ failCount++;
+ }
+ }
+
+ Map<String, Object> result = new LinkedHashMap<>();
+ result.put("total", normalizedBarcodes.size());
+ result.put("successCount", successCount);
+ result.put("failCount", failCount);
+ result.put("rows", rows);
+ return R.ok().add(result);
}
@Override
@@ -1337,6 +1470,7 @@
waitPakin.setIoStatus("N"); // 鍏ュ嚭鐘舵��
waitPakin.setAnfme(param.getAnfme()); // 鏁伴噺
+ waitPakin.setFreqType(param.getFreqType());
waitPakin.setStatus("Y"); // 鐘舵��
waitPakin.setAppeUser(9995L);
waitPakin.setAppeTime(now);
@@ -1662,6 +1796,306 @@
return response;
}
+ private boolean isErpReportEnabled() {
+ if (!erpReportOld) {
+ return false;
+ }
+ String erpReport = Parameter.get().getErpReport();
+ return Cools.isEmpty(erpReport) || "true".equalsIgnoreCase(erpReport);
+ }
+
+ private List<String> normalizeBarcodes(List<String> barcodes) {
+ if (barcodes == null || barcodes.isEmpty()) {
+ return Collections.emptyList();
+ }
+ LinkedHashSet<String> normalized = new LinkedHashSet<>();
+ for (String barcode : barcodes) {
+ if (barcode == null) {
+ continue;
+ }
+ String value = barcode.trim();
+ if (!value.isEmpty()) {
+ normalized.add(value);
+ }
+ }
+ return new ArrayList<>(normalized);
+ }
+
+ private Map<String, WrkMastLog> loadLatestInboundHistoryLogMap(List<String> barcodes) {
+ Map<String, WrkMastLog> latestInboundLogMap = new LinkedHashMap<>();
+ if (barcodes == null || barcodes.isEmpty()) {
+ return latestInboundLogMap;
+ }
+ List<WrkMastLog> wrkMastLogs = wrkMastLogService.selectList(new EntityWrapper<WrkMastLog>()
+ .in("barcode", barcodes)
+ .orderBy("barcode", true)
+ .orderBy("io_time", false)
+ .orderBy("wrk_no", false));
+ if (Cools.isEmpty(wrkMastLogs)) {
+ return latestInboundLogMap;
+ }
+ for (WrkMastLog wrkMastLog : wrkMastLogs) {
+ if (wrkMastLog == null || Cools.isEmpty(wrkMastLog.getBarcode())) {
+ continue;
+ }
+ if (!isInboundHistoryLog(wrkMastLog.getIoType())) {
+ continue;
+ }
+ latestInboundLogMap.putIfAbsent(wrkMastLog.getBarcode(), wrkMastLog);
+ }
+ return latestInboundLogMap;
+ }
+
+ private boolean isInboundHistoryLog(Integer ioType) {
+ if (ioType == null) {
+ return false;
+ }
+ // 鍘嗗彶琛ㄩ噷鏃㈡湁鍏ュ簱瀹屾垚锛屼篃鏈夊簱瀛樿皟鏁达紱杩欓噷鍙彇鐪熸鐨勫叆搴撶被璁板綍銆�
+ return ioType < 19 || ioType == 53 || ioType == 54 || ioType == 57;
+ }
+
+ private Map<Integer, List<WrkDetlLog>> loadWrkDetlLogMap(Collection<WrkMastLog> wrkMastLogs) {
+ Map<Integer, List<WrkDetlLog>> wrkDetlLogMap = new HashMap<>();
+ if (wrkMastLogs == null || wrkMastLogs.isEmpty()) {
+ return wrkDetlLogMap;
+ }
+ LinkedHashSet<Integer> wrkNos = new LinkedHashSet<>();
+ for (WrkMastLog wrkMastLog : wrkMastLogs) {
+ if (wrkMastLog != null && wrkMastLog.getWrkNo() != null) {
+ wrkNos.add(wrkMastLog.getWrkNo());
+ }
+ }
+ if (wrkNos.isEmpty()) {
+ return wrkDetlLogMap;
+ }
+ List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectList(new EntityWrapper<WrkDetlLog>().in("wrk_no", wrkNos));
+ if (Cools.isEmpty(wrkDetlLogs)) {
+ return wrkDetlLogMap;
+ }
+ for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
+ if (wrkDetlLog == null || wrkDetlLog.getWrkNo() == null) {
+ continue;
+ }
+ wrkDetlLogMap.computeIfAbsent(wrkDetlLog.getWrkNo(), k -> new ArrayList<>()).add(wrkDetlLog);
+ }
+ return wrkDetlLogMap;
+ }
+
+ private Map<String, WaitPakinLog> loadWaitPakinLogMap(List<String> barcodes) {
+ Map<String, WaitPakinLog> waitPakinLogMap = new LinkedHashMap<>();
+ if (barcodes == null || barcodes.isEmpty()) {
+ return waitPakinLogMap;
+ }
+ List<WaitPakinLog> waitPakinLogs = waitPakinLogService.selectList(new EntityWrapper<WaitPakinLog>()
+ .in("zpallet", barcodes)
+ .orderBy("zpallet", true)
+ .orderBy("appe_time", false)
+ .orderBy("modi_time", false));
+ if (Cools.isEmpty(waitPakinLogs)) {
+ return waitPakinLogMap;
+ }
+ for (WaitPakinLog waitPakinLog : waitPakinLogs) {
+ if (waitPakinLog == null || Cools.isEmpty(waitPakinLog.getZpallet())) {
+ continue;
+ }
+ waitPakinLogMap.putIfAbsent(waitPakinLog.getZpallet(), waitPakinLog);
+ }
+ return waitPakinLogMap;
+ }
+
+ private ErpPakinReportParam buildInboundErpParam(String barcode,
+ WrkMastLog wrkMastLog,
+ List<WrkDetlLog> wrkDetlLogs,
+ WaitPakinLog waitPakinLog) {
+ ErpPakinReportParam param = new ErpPakinReportParam();
+ param.setPalletId(resolvePalletId(barcode, wrkMastLog, wrkDetlLogs, waitPakinLog));
+ param.setAnfme(resolveInboundAnfme(wrkDetlLogs, waitPakinLog));
+ param.setLocId(transformInboundLocId(resolveInboundLocNo(wrkMastLog, waitPakinLog)));
+ param.setWeight(resolveInboundWeight(wrkMastLog, waitPakinLog));
+ param.setCreateTime(formatDate(resolveInboundCreateTime(wrkMastLog)));
+ param.setBizNo(resolveInboundBizNo(wrkDetlLogs, waitPakinLog));
+ param.setStartTime(formatDate(resolveInboundStartTime(wrkMastLog, waitPakinLog)));
+ return param;
+ }
+
+ private String resolvePalletId(String barcode,
+ WrkMastLog wrkMastLog,
+ List<WrkDetlLog> wrkDetlLogs,
+ WaitPakinLog waitPakinLog) {
+ if (wrkMastLog != null && !Cools.isEmpty(wrkMastLog.getBarcode())) {
+ return wrkMastLog.getBarcode();
+ }
+ if (wrkDetlLogs != null) {
+ for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
+ if (wrkDetlLog != null && !Cools.isEmpty(wrkDetlLog.getZpallet())) {
+ return wrkDetlLog.getZpallet();
+ }
+ }
+ }
+ if (waitPakinLog != null && !Cools.isEmpty(waitPakinLog.getZpallet())) {
+ return waitPakinLog.getZpallet();
+ }
+ return barcode;
+ }
+
+ private Double resolveInboundAnfme(List<WrkDetlLog> wrkDetlLogs, WaitPakinLog waitPakinLog) {
+ double total = 0D;
+ boolean hasDetail = false;
+ if (wrkDetlLogs != null) {
+ for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
+ if (wrkDetlLog == null || wrkDetlLog.getAnfme() == null) {
+ continue;
+ }
+ total += wrkDetlLog.getAnfme();
+ hasDetail = true;
+ }
+ }
+ if (hasDetail) {
+ return total;
+ }
+ if (waitPakinLog != null && waitPakinLog.getAnfme() != null) {
+ return waitPakinLog.getAnfme();
+ }
+ return total;
+ }
+
+ private BigDecimal resolveInboundWeight(WrkMastLog wrkMastLog, WaitPakinLog waitPakinLog) {
+ BigDecimal baseWeight = BigDecimal.ZERO;
+ if (wrkMastLog != null && wrkMastLog.getScWeight() != null) {
+ baseWeight = BigDecimal.valueOf(wrkMastLog.getScWeight());
+ } else if (waitPakinLog != null && waitPakinLog.getWeight() != null) {
+ baseWeight = BigDecimal.valueOf(waitPakinLog.getWeight());
+ }
+ Integer sourceStaNo = resolveInboundSourceStaNo(wrkMastLog);
+ return baseWeight.multiply(resolveInboundWeightFactor(sourceStaNo));
+ }
+
+ private Integer resolveInboundSourceStaNo(WrkMastLog wrkMastLog) {
+ if (wrkMastLog == null) {
+ return null;
+ }
+ if (wrkMastLog.getSourceStaNo() != null) {
+ return wrkMastLog.getSourceStaNo();
+ }
+ return wrkMastLog.getStaNo();
+ }
+
+ private BigDecimal resolveInboundWeightFactor(Integer sourceStaNo) {
+ if (sourceStaNo == null) {
+ return BigDecimal.ONE;
+ }
+ BigDecimal factor = INBOUND_WEIGHT_FACTOR_BY_SOURCE_STA.get(sourceStaNo);
+ return factor == null ? BigDecimal.ONE : factor;
+ }
+
+ private String resolveInboundLocNo(WrkMastLog wrkMastLog, WaitPakinLog waitPakinLog) {
+ if (wrkMastLog != null && !Cools.isEmpty(wrkMastLog.getLocNo())) {
+ return wrkMastLog.getLocNo();
+ }
+ if (waitPakinLog != null && !Cools.isEmpty(waitPakinLog.getLocNo())) {
+ return waitPakinLog.getLocNo();
+ }
+ return null;
+ }
+
+ private Date resolveInboundCreateTime(WrkMastLog wrkMastLog) {
+ if (wrkMastLog == null) {
+ return new Date();
+ }
+ if (wrkMastLog.getCrnEndTime() != null) {
+ return wrkMastLog.getCrnEndTime();
+ }
+ if (wrkMastLog.getModiTime() != null) {
+ return wrkMastLog.getModiTime();
+ }
+ if (wrkMastLog.getIoTime() != null) {
+ return wrkMastLog.getIoTime();
+ }
+ return new Date();
+ }
+
+ private Date resolveInboundStartTime(WrkMastLog wrkMastLog, WaitPakinLog waitPakinLog) {
+ if (waitPakinLog != null && waitPakinLog.getAppeTime() != null) {
+ return waitPakinLog.getAppeTime();
+ }
+ if (wrkMastLog == null) {
+ return new Date();
+ }
+ if (wrkMastLog.getAppeTime() != null) {
+ return wrkMastLog.getAppeTime();
+ }
+ if (wrkMastLog.getIoTime() != null) {
+ return wrkMastLog.getIoTime();
+ }
+ if (wrkMastLog.getModiTime() != null) {
+ return wrkMastLog.getModiTime();
+ }
+ return new Date();
+ }
+
+ private String resolveInboundBizNo(List<WrkDetlLog> wrkDetlLogs, WaitPakinLog waitPakinLog) {
+ if (wrkDetlLogs != null) {
+ for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
+ if (wrkDetlLog != null && !Cools.isEmpty(wrkDetlLog.getThreeCode())) {
+ return wrkDetlLog.getThreeCode();
+ }
+ }
+ }
+ if (waitPakinLog != null && !Cools.isEmpty(waitPakinLog.getThreeCode())) {
+ return waitPakinLog.getThreeCode();
+ }
+ return null;
+ }
+
+ private String transformInboundLocId(String locId) {
+ if (Cools.isEmpty(locId)) {
+ return null;
+ }
+ String trimmed = locId.trim();
+ if (trimmed.length() < 7) {
+ return trimmed;
+ }
+ String row = trimmed.substring(0, 2);
+ String col = trimmed.substring(2, 5);
+ String lev = trimmed.substring(5, 7);
+ try {
+ int rowNo = Integer.parseInt(row);
+ if (rowNo >= 37) {
+ row = "C" + row;
+ } else if (rowNo >= 13) {
+ row = "B" + row;
+ } else {
+ row = "A" + row;
+ }
+ } catch (Exception ignore) {
+ return trimmed;
+ }
+ return row + "-" + col + "-" + lev;
+ }
+
+ private String formatDate(Date date) {
+ if (date == null) {
+ return null;
+ }
+ return new SimpleDateFormat(DATE_TIME_PATTERN).format(date);
+ }
+
+ private String buildErpInboundRequestUrl() {
+ if (Cools.isEmpty(erpUrl)) {
+ return erpInAddress;
+ }
+ if (erpInAddress == null) {
+ return erpUrl;
+ }
+ if (erpUrl.endsWith("/") && erpInAddress.startsWith("/")) {
+ return erpUrl + erpInAddress.substring(1);
+ }
+ if (!erpUrl.endsWith("/") && !erpInAddress.startsWith("/")) {
+ return erpUrl + "/" + erpInAddress;
+ }
+ return erpUrl + erpInAddress;
+ }
+
private String buildErpOutErrorRequestUrl() {
if (Cools.isEmpty(erpUrl)) {
return erpOutErrorAddress;
--
Gitblit v1.9.1