Browse Source

当用户选择供应商生产日期时,失效日期需要按供应商生产日期+有效期重新同步到IFS

master
han\hanst 1 month ago
parent
commit
79b6358d1e
  1. 130
      src/main/java/com/gaotao/modules/po/service/impl/PoServiceImpl.java

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

@ -7,12 +7,15 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gaotao.common.exception.XJException;
import com.gaotao.common.utils.*;
import com.gaotao.modules.api.entity.dto.IfsChangeExpiryDateDto;
import com.gaotao.modules.api.entity.issueAndReturnVo.InventoryPartVo;
import com.gaotao.modules.api.service.IfsApiIssueAndReturnService;
import com.gaotao.modules.api.service.IfsApiService;
import com.gaotao.modules.factory.dao.AccessSiteMapper;
import com.gaotao.modules.factory.dao.PartAttributeMapper;
import com.gaotao.modules.factory.entity.PartAttribute;
import com.gaotao.modules.factory.entity.Site;
import com.gaotao.modules.warehouse.mapper.HandlingUnitSpecialMapper;
import lombok.extern.slf4j.Slf4j;
import java.math.RoundingMode;
@ -86,6 +89,11 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
private PartAttributeMapper partAttributeMapper;
@Autowired
private IfsApiIssueAndReturnService ifsApiIssueAndReturnService;
@Autowired
private IfsApiService ifsApiService;
@Autowired
private HandlingUnitSpecialMapper handlingUnitSpecialMapper;
@Value("${custom.ifs-url}")
private String ifsUrl;
@ -237,7 +245,19 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
handlePartAttribute(inData);
// 同步到IFS
syncToIFS(inData);
// 当用户选择供应商生产日期时失效日期需要按供应商生产日期+有效期重新同步到IFS
if (inData.getSupplierManufactureDate() != null) {
Date supplierExpiryDate = calculateExpiryDate(inData.getSupplierManufactureDate(), shelfLife);
if (supplierExpiryDate != null) {
inData.setExpiredDate(supplierExpiryDate);
List<HandlingUnit> currentHandlingUnits = handlingUnitService.lambdaQuery()
.eq(HandlingUnit::getSite, inData.getSite())
.eq(HandlingUnit::getSourceType, "PO_RECEIVE")
.eq(HandlingUnit::getSourceRef, transHeader.getTransNo())
.list();
changeExpiryDate(currentHandlingUnits, inData);
}
}
return receiptNo;
} catch (Exception e) {
log.error("采购入库失败,PO号: {}, 错误: {}", inData.getPoNo(), e.getMessage());
@ -487,40 +507,88 @@ public class PoServiceImpl extends ServiceImpl<PoMapper, PurchaseOrder> implemen
}
}
private Map<String, Object> isWeiwai(TransDetailDto inData) {
private void changeExpiryDate(List<HandlingUnit> handlingUnits, TransDetailDto inData) {
if (handlingUnits == null || handlingUnits.isEmpty()) {
log.warn("供应商生产日期模式下未查询到标签信息,跳过失效日期同步,transNo={}", inData.getTransNo());
return;
}
if (inData.getExpiredDate() == null) {
log.warn("供应商生产日期模式下失效日期为空,跳过失效日期同步,transNo={}", inData.getTransNo());
return;
}
String ifsExpiryDate = DateUtils.format(inData.getExpiredDate(), DateUtils.DATE_PATTERN);
String modifiedBy = "SYSTEM";
try {
Map<String, Object> POLineSupplierMaterialParams = Map.of("ifsDBName", ifsDBName, "domainUserID", getCurrentDomainUserID(),
"ifsSiteID", inData.getSite(),
"ifsPurchaseOrderNo", inData.getOrderNo()
);
ObjectMapper objectMapper = new ObjectMapper();
String pmJsonBody = objectMapper.writeValueAsString(POLineSupplierMaterialParams);
log.info("IFS请求接口名称:{},请求参数: {}","POLineSupplierMaterial", pmJsonBody);
String pmResponse = HttpUtils.doGetWithBody(ifsUrl+"POLineSupplierMaterial",pmJsonBody,null);
List<Map<String, Object>> poLineData = objectMapper.readValue(pmResponse, new TypeReference<>() {});
if (poLineData.isEmpty()) {
log.info("普通ordinary PO,PO号: {}", inData.getOrderNo());
return null;
} else {
// 获取对应行号和releaseNo的数据
for (Map<String, Object> line : poLineData) {
String lineNo = line.get("lineNo") != null ? line.get("lineNo").toString() : "";
String releaseNo = line.get("releaseNo") != null ? line.get("releaseNo").toString() : "";
if (inData.getLineNo().equals(lineNo) && (inData.getReleaseNo() != null && inData.getReleaseNo().equals(releaseNo))) {
log.info("委外ordinary PO,PO号: {}", inData.getOrderNo());
return line;
}
}
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
if (currentUser != null && StringUtils.isNotBlank(currentUser.getUserDisplay())) {
modifiedBy = currentUser.getUserDisplay();
}
return null;
} catch (XJException e) {
// 重新抛出业务异常确保事务回滚
throw e;
} catch (Exception e) {
log.error("IFS同步异常,PO号: {}, 错误: {}", inData.getOrderNo(), e.getMessage());
// 同步异常需要回滚前面所有的数据库操作
throw new XJException("IFS同步异常: " + e.getMessage());
log.warn("获取当前用户失败,失效日期同步将使用默认操作人");
}
// 参考标签特殊信息批量修改逻辑按库存关键字去重后调用IFS
Map<String, HandlingUnit> inventoryKeyMap = new LinkedHashMap<>();
for (HandlingUnit item : handlingUnits) {
String key = buildInventoryKey(item);
if (!inventoryKeyMap.containsKey(key)) {
inventoryKeyMap.put(key, item);
}
}
log.info("供应商生产日期模式开始同步失效日期,标签数:{},去重后调用次数:{},新失效日期:{}",
handlingUnits.size(), inventoryKeyMap.size(), ifsExpiryDate);
for (HandlingUnit item : inventoryKeyMap.values()) {
try {
IfsChangeExpiryDateDto dto = new IfsChangeExpiryDateDto();
dto.setIfsSiteID(item.getSite());
dto.setIfsPartNo(item.getPartNo());
dto.setIfsLocationNo(item.getLocationId());
dto.setIfsLotBatchNo(item.getBatchNo());
dto.setIfsWdrNo(StringUtils.isNotBlank(item.getWdr()) ? item.getWdr() : "*");
dto.setIfsEngChgLevel(StringUtils.isNotBlank(item.getEngChgLevel()) ? item.getEngChgLevel() : "1");
dto.setIfsExpiryDate(ifsExpiryDate);
ifsApiService.changeExpiryDate(dto);
int updatedRows = handlingUnitSpecialMapper.updateExpiryDateByInventoryKey(
item.getSite(),
item.getPartNo(),
item.getLocationId(),
item.getBatchNo(),
StringUtils.isNotBlank(item.getWdr()) ? item.getWdr() : "*",
StringUtils.isNotBlank(item.getEngChgLevel()) ? item.getEngChgLevel() : "1",
ifsExpiryDate,
modifiedBy
);
log.info("失效日期同步成功,unitId={},影响行数={}", item.getUnitId(), updatedRows);
} catch (Exception e) {
log.error("失效日期同步失败,unitId={},error={}", item.getUnitId(), e.getMessage(), e);
}
}
}
private String buildInventoryKey(HandlingUnit item) {
return String.join("|",
item.getSite() != null ? item.getSite() : "",
item.getPartNo() != null ? item.getPartNo() : "",
item.getLocationId() != null ? item.getLocationId() : "",
item.getBatchNo() != null ? item.getBatchNo() : "",
item.getWdr() != null ? item.getWdr() : "",
item.getEngChgLevel() != null ? item.getEngChgLevel() : ""
);
}
private Date calculateExpiryDate(Date baseDate, Integer shelfLife) {
if (baseDate == null || shelfLife == null || shelfLife <= 0) {
return null;
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(baseDate);
calendar.add(Calendar.DAY_OF_YEAR, shelfLife);
return calendar.getTime();
}
/**

Loading…
Cancel
Save