|
|
|
@ -1950,6 +1950,137 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 编辑模式「同步运输周期」(新增方法,不改动原有逻辑): |
|
|
|
* 对勾选行按新增口径重取 ori_transit_cycle 并连带重算 standard_tt/c_crd/c_eta。 |
|
|
|
* 1) 取行内当前 departure/destination/shipVia(含未保存编辑);三项缺一则跳过; |
|
|
|
* 2) 先回写 header 三字段,再复用原有 calculateCrd(loadPoHeader 会拿到最新值); |
|
|
|
* 3) 复用原有 resolveOriTransitCycle(POHeader),用临时 header 取周期,不改动其实现; |
|
|
|
* 4) c_crd_ori 不覆盖,仅库中为空且本次有 crd 时回填;单行失败不中断整批。 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Map<String, Object> syncOriTransitCycle(List<PODetailVo> rows) { |
|
|
|
List<Map<String, Object>> updatedRows = new ArrayList<>(); |
|
|
|
List<Map<String, Object>> skipDetails = new ArrayList<>(); |
|
|
|
int successCount = 0; |
|
|
|
int unmatchedCount = 0; |
|
|
|
int skipCount = 0; |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(rows)) { |
|
|
|
return buildSyncResult(updatedRows, skipDetails, successCount, unmatchedCount, skipCount); |
|
|
|
} |
|
|
|
|
|
|
|
String site = poFieldAuthSupport.requireSite(rows.get(0).getSite()); |
|
|
|
String customer = poFieldAuthSupport.requireCustomer(rows.get(0).getCustomer()); |
|
|
|
poFieldAuthSupport.validateWriteContext(site, customer); |
|
|
|
|
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
String currentUserName = currentUser != null ? currentUser.getUsername() : "system"; |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
String currentTimeStr = sdf.format(new Date()); |
|
|
|
|
|
|
|
for (PODetailVo model : rows) { |
|
|
|
if (!StringUtils.hasText(model.getOrderNo()) |
|
|
|
|| !StringUtils.hasText(model.getSite()) |
|
|
|
|| model.getItemNo() == null) { |
|
|
|
skipCount++; |
|
|
|
skipDetails.add(buildSyncSkip(model, "主键不完整,需包含 site、orderNo、itemNo")); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!StringUtils.hasText(model.getDeparture()) |
|
|
|
|| !StringUtils.hasText(model.getDestination()) |
|
|
|
|| !StringUtils.hasText(model.getShipVia())) { |
|
|
|
skipCount++; |
|
|
|
skipDetails.add(buildSyncSkip(model, "始发港/目的港/运输方式不完整,无法同步")); |
|
|
|
continue; |
|
|
|
} |
|
|
|
PODetail existing = baseMapper.selectByPK( |
|
|
|
model.getOrderNo(), model.getSite(), model.getItemNo()); |
|
|
|
if (existing == null) { |
|
|
|
skipCount++; |
|
|
|
skipDetails.add(buildSyncSkip(model, "未找到订单明细")); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// 先回写 header 三字段(updatePoHeaderForEdit 只更新非空列),保证头/明细一致 |
|
|
|
POHeader portPatch = new POHeader(); |
|
|
|
portPatch.setSite(model.getSite()); |
|
|
|
portPatch.setOrderNo(model.getOrderNo()); |
|
|
|
portPatch.setDeparture(model.getDeparture()); |
|
|
|
portPatch.setDestination(model.getDestination()); |
|
|
|
portPatch.setShipVia(model.getShipVia()); |
|
|
|
poHeaderMapper.updatePoHeaderForEdit(portPatch); |
|
|
|
|
|
|
|
// 复用原有 resolveOriTransitCycle(POHeader):用临时 header 传行内当前值,不改动其实现 |
|
|
|
POHeader transientHeader = new POHeader(); |
|
|
|
transientHeader.setDeparture(model.getDeparture()); |
|
|
|
transientHeader.setDestination(model.getDestination()); |
|
|
|
transientHeader.setShipVia(model.getShipVia()); |
|
|
|
Integer ori = resolveOriTransitCycle(transientHeader); |
|
|
|
|
|
|
|
// 复用原有 calculateCrd 重算相关日期(已先写 header,loadPoHeader 会取到最新值) |
|
|
|
PODetail calc = new PODetail(); |
|
|
|
calculateCrd(model, calc); |
|
|
|
|
|
|
|
PODetailVo upd = new PODetailVo(); |
|
|
|
upd.setSite(model.getSite()); |
|
|
|
upd.setOrderNo(model.getOrderNo()); |
|
|
|
upd.setItemNo(model.getItemNo()); |
|
|
|
upd.setOriTransitCycle(ori); |
|
|
|
upd.setStandardTt(calc.getStandardTt()); |
|
|
|
upd.setCrd(calc.getCrd()); |
|
|
|
upd.setEta(calc.getEta()); |
|
|
|
if (existing.getCrdOri() == null && calc.getCrd() != null) { |
|
|
|
upd.setCrdOri(calc.getCrd()); |
|
|
|
} |
|
|
|
upd.setEdit(currentTimeStr); |
|
|
|
upd.setEndPlanner(currentUserName); |
|
|
|
|
|
|
|
baseMapper.updatePoDetailForEdit(upd); |
|
|
|
|
|
|
|
if (ori == null) { |
|
|
|
unmatchedCount++; |
|
|
|
} |
|
|
|
successCount++; |
|
|
|
|
|
|
|
Map<String, Object> r = new HashMap<>(); |
|
|
|
r.put("orderNo", model.getOrderNo()); |
|
|
|
r.put("itemNo", model.getItemNo()); |
|
|
|
r.put("oriTransitCycle", ori); |
|
|
|
r.put("standardTt", calc.getStandardTt()); |
|
|
|
r.put("crd", calc.getCrd()); |
|
|
|
r.put("eta", calc.getEta()); |
|
|
|
updatedRows.add(r); |
|
|
|
} |
|
|
|
|
|
|
|
return buildSyncResult(updatedRows, skipDetails, successCount, unmatchedCount, skipCount); |
|
|
|
} |
|
|
|
|
|
|
|
/** 组装同步返回:summary 汇总 + rows 明细(新增私有方法)。 */ |
|
|
|
private Map<String, Object> buildSyncResult(List<Map<String, Object>> updatedRows, |
|
|
|
List<Map<String, Object>> skipDetails, |
|
|
|
int successCount, int unmatchedCount, int skipCount) { |
|
|
|
Map<String, Object> summary = new HashMap<>(); |
|
|
|
summary.put("successCount", successCount); |
|
|
|
summary.put("unmatchedCount", unmatchedCount); |
|
|
|
summary.put("skipCount", skipCount); |
|
|
|
summary.put("skipDetails", skipDetails); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
result.put("summary", summary); |
|
|
|
result.put("rows", updatedRows); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** 跳过行明细(新增私有方法)。 */ |
|
|
|
private Map<String, Object> buildSyncSkip(PODetailVo model, String reason) { |
|
|
|
Map<String, Object> m = new HashMap<>(); |
|
|
|
m.put("orderNo", model == null ? null : model.getOrderNo()); |
|
|
|
m.put("itemNo", model == null ? null : model.getItemNo()); |
|
|
|
m.put("reason", reason); |
|
|
|
return m; |
|
|
|
} |
|
|
|
|
|
|
|
private void validatePoDetailUpdate(PODetailVo model, PODetail existingDetail) { |
|
|
|
if (model.getAQty() != null) { |
|
|
|
// A_Qty 是唯一工作数量:校验申请、通过及累计发货不能超过本次目标数量 - rqrq |
|
|
|
|