Browse Source

移库

master
han\hanst 3 months ago
parent
commit
66f286346e
  1. 24
      src/main/java/com/gaotao/modules/other/service/impl/InventoryMoveServiceImpl.java
  2. 3
      src/main/java/com/gaotao/modules/po/service/impl/PoServiceImpl.java

24
src/main/java/com/gaotao/modules/other/service/impl/InventoryMoveServiceImpl.java

@ -29,6 +29,7 @@ import com.gaotao.modules.sys.entity.SysUserEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -234,12 +235,14 @@ public class InventoryMoveServiceImpl implements InventoryMoveService {
*/ */
private void syncToIFSBatch(InventoryMoveRequestDto dto, List<HandlingUnit> handlingUnits) { private void syncToIFSBatch(InventoryMoveRequestDto dto, List<HandlingUnit> handlingUnits) {
try { try {
// 按sitepartNo原库位lotBatchNo分组合并数量
// 按sitepartNo原库位lotBatchNoexpiredDate分组合并数量
Map<String, MoveGroup> moveGroups = new HashMap<>(); Map<String, MoveGroup> moveGroups = new HashMap<>();
for (HandlingUnit hu : handlingUnits) { for (HandlingUnit hu : handlingUnits) {
String groupKey = String.format("%s|%s|%s|%s",
hu.getSite(), hu.getPartNo(), hu.getLocationId(), hu.getBatchNo());
String expiredDateStr = hu.getExpiredDate() != null ?
new SimpleDateFormat("yyyy-MM-dd").format(hu.getExpiredDate()) : "null";
String groupKey = String.format("%s|%s|%s|%s|%s",
hu.getSite(), hu.getPartNo(), hu.getLocationId(), hu.getBatchNo(), expiredDateStr);
MoveGroup group = moveGroups.computeIfAbsent(groupKey, k -> { MoveGroup group = moveGroups.computeIfAbsent(groupKey, k -> {
MoveGroup newGroup = new MoveGroup(); MoveGroup newGroup = new MoveGroup();
@ -248,6 +251,7 @@ public class InventoryMoveServiceImpl implements InventoryMoveService {
newGroup.sourceLocationNo = hu.getLocationId(); // 注意这里使用的是更新前的原库位 newGroup.sourceLocationNo = hu.getLocationId(); // 注意这里使用的是更新前的原库位
newGroup.destLocationNo = dto.getTargetLocationId(); newGroup.destLocationNo = dto.getTargetLocationId();
newGroup.lotBatchNo = hu.getBatchNo(); newGroup.lotBatchNo = hu.getBatchNo();
newGroup.expiredDate = hu.getExpiredDate();
newGroup.totalQty = BigDecimal.ZERO; newGroup.totalQty = BigDecimal.ZERO;
return newGroup; return newGroup;
}); });
@ -283,13 +287,22 @@ public class InventoryMoveServiceImpl implements InventoryMoveService {
params.put("destLocationNo", group.destLocationNo); // 目标库位 params.put("destLocationNo", group.destLocationNo); // 目标库位
params.put("lotBatchNo", group.lotBatchNo); params.put("lotBatchNo", group.lotBatchNo);
// 添加过期日期参数
if (group.expiredDate != null) {
params.put("expiredDate", new SimpleDateFormat("yyyy-MM-dd").format(group.expiredDate));
} else {
params.put("expiredDate", null);
}
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
String jsonBody = objectMapper.writeValueAsString(params); String jsonBody = objectMapper.writeValueAsString(params);
String ifsResponse = HttpUtils.doPost(ifsUrl + "MoveInventoryPart", jsonBody, null); String ifsResponse = HttpUtils.doPost(ifsUrl + "MoveInventoryPart", jsonBody, null);
if ("IFSUpdated".equals(ifsResponse) || "\"IFSUpdated\"".equals(ifsResponse)) { if ("IFSUpdated".equals(ifsResponse) || "\"IFSUpdated\"".equals(ifsResponse)) {
log.info("IFS移库同步成功 - 物料: {}, 批次: {}, 数量: {}, 从 {} 到 {}",
group.partNo, group.lotBatchNo, group.totalQty, group.sourceLocationNo, group.destLocationNo);
log.info("IFS移库同步成功 - 物料: {}, 批次: {}, 过期日期: {}, 数量: {}, 从 {} 到 {}",
group.partNo, group.lotBatchNo,
group.expiredDate != null ? new SimpleDateFormat("yyyy-MM-dd").format(group.expiredDate) : "无",
group.totalQty, group.sourceLocationNo, group.destLocationNo);
} else { } else {
String errorMessage = IfsErrorMessageUtils.extractOracleErrorMessage(ifsResponse); String errorMessage = IfsErrorMessageUtils.extractOracleErrorMessage(ifsResponse);
log.warn("IFS移库同步失败 - 物料: {}, 批次: {}, 响应: {}", log.warn("IFS移库同步失败 - 物料: {}, 批次: {}, 响应: {}",
@ -422,6 +435,7 @@ public class InventoryMoveServiceImpl implements InventoryMoveService {
String destLocationNo; String destLocationNo;
String lotBatchNo; String lotBatchNo;
BigDecimal totalQty; BigDecimal totalQty;
Date expiredDate;
} }
/** /**

3
src/main/java/com/gaotao/modules/po/service/impl/PoServiceImpl.java

@ -463,7 +463,8 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
} else { } else {
log.error("IFS同步失败,PO号: {}, 响应: {}", inData.getOrderNo(), ifsResponse); log.error("IFS同步失败,PO号: {}, 响应: {}", inData.getOrderNo(), ifsResponse);
// 同步失败需要回滚前面所有的数据库操作 // 同步失败需要回滚前面所有的数据库操作
throw new XJException("IFS同步失败,响应: " + ifsResponse);
String errorMessage = IfsErrorMessageUtils.extractOracleErrorMessage(ifsResponse);
throw new XJException(errorMessage);
} }
} catch (XJException e) { } catch (XJException e) {
// 重新抛出业务异常确保事务回滚 // 重新抛出业务异常确保事务回滚

Loading…
Cancel
Save