Browse Source

2025-12-20

报价时的estimatedMaterialCost从接口获取
master
fengyuan_yang 4 months ago
parent
commit
bb75510a6b
  1. 3
      src/main/java/com/spring/modules/quote/service/QuoteDetailBomTreeService.java
  2. 29
      src/main/java/com/spring/modules/quote/service/impl/QuoteDetailBomTreeServiceImpl.java
  3. 4
      src/main/java/com/spring/modules/quote/service/impl/QuoteDetailServiceImpl.java

3
src/main/java/com/spring/modules/quote/service/QuoteDetailBomTreeService.java

@ -33,7 +33,8 @@ public interface QuoteDetailBomTreeService extends IService<QuoteDetailBomTree>
* 根据物料编码查询预估材料成本 * 根据物料编码查询预估材料成本
* @param site 站点 * @param site 站点
* @param partNo 物料编码 * @param partNo 物料编码
* @param status 物料状态 (Y=正式物料调用IFS接口, N=非正式物料查询数据库)
* @return 预估材料成本estimated_material_cost * @return 预估材料成本estimated_material_cost
*/ */
BigDecimal queryEstimatedMaterialCost(String site, String partNo);
BigDecimal queryEstimatedMaterialCost(String site, String partNo, String status);
} }

29
src/main/java/com/spring/modules/quote/service/impl/QuoteDetailBomTreeServiceImpl.java

@ -497,16 +497,29 @@ public class QuoteDetailBomTreeServiceImpl extends ServiceImpl<QuoteDetailBomTre
} }
@Override @Override
public BigDecimal queryEstimatedMaterialCost(String site, String partNo) {
public BigDecimal queryEstimatedMaterialCost(String site, String partNo, String status) {
log.info("queryEstimatedMaterialCost - Request params: site={}, partNo={}, status={}", site, partNo, status);
// 非正式物料(status='N')直接从数据库查询
if (!"Y".equals(status)) {
BigDecimal cost = baseMapper.queryEstimatedMaterialCost(site, partNo);
BigDecimal result = cost != null ? cost : BigDecimal.ZERO;
log.info("queryEstimatedMaterialCost - Unofficial part, query from database. Result: {}", result);
return result;
}
// 正式物料(status='Y')调用IFS接口
try { try {
// 获取当前用户的IFS连接 // 获取当前用户的IFS连接
String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername(); String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
SysUserEntity ifsUser = sysUserDao.selectOne(new QueryWrapper<SysUserEntity>().eq("username", username)); SysUserEntity ifsUser = sysUserDao.selectOne(new QueryWrapper<SysUserEntity>().eq("username", username));
if (ifsUser == null || !org.apache.commons.lang3.StringUtils.isNotBlank(ifsUser.getIfsUsername()) if (ifsUser == null || !org.apache.commons.lang3.StringUtils.isNotBlank(ifsUser.getIfsUsername())
|| !org.apache.commons.lang3.StringUtils.isNotBlank(ifsUser.getIfsPassword())) { || !org.apache.commons.lang3.StringUtils.isNotBlank(ifsUser.getIfsPassword())) {
log.warn("用户 {} 未维护IFS账号,使用数据库查询estimatedMaterialCost", username);
log.warn("queryEstimatedMaterialCost - User {} has no IFS account configured, fallback to database query", username);
BigDecimal cost = baseMapper.queryEstimatedMaterialCost(site, partNo); BigDecimal cost = baseMapper.queryEstimatedMaterialCost(site, partNo);
return cost != null ? cost : BigDecimal.ZERO;
BigDecimal result = cost != null ? cost : BigDecimal.ZERO;
log.info("queryEstimatedMaterialCost - Fallback result from database: {}", result);
return result;
} }
Server ifsCon = ifsServer.getIfsServer(ifsUser.getIfsUsername(), ifsUser.getIfsPassword()); Server ifsCon = ifsServer.getIfsServer(ifsUser.getIfsUsername(), ifsUser.getIfsPassword());
@ -514,19 +527,23 @@ public class QuoteDetailBomTreeServiceImpl extends ServiceImpl<QuoteDetailBomTre
PartInformationEntity part = new PartInformationEntity(); PartInformationEntity part = new PartInformationEntity();
part.setSite(site); part.setSite(site);
part.setPartNo(partNo); part.setPartNo(partNo);
log.info("queryEstimatedMaterialCost - Calling IFS API with params: site={}, partNo={}", site, partNo);
Map<String, String> map = baseSearchBean.getInventoryEstimatedMaterialCostByPartNo(ifsCon, part); Map<String, String> map = baseSearchBean.getInventoryEstimatedMaterialCostByPartNo(ifsCon, part);
log.info("queryEstimatedMaterialCost - IFS API response: {}", map);
if (Objects.equals(map.get("resultCode"), "200")) { if (Objects.equals(map.get("resultCode"), "200")) {
InventoryPartUnitCostSumVo unitCostSumVo = JSONObject.parseObject(map.get("obj"), InventoryPartUnitCostSumVo.class); InventoryPartUnitCostSumVo unitCostSumVo = JSONObject.parseObject(map.get("obj"), InventoryPartUnitCostSumVo.class);
BigDecimal estimatedCost = new BigDecimal(unitCostSumVo.getInventoryValue()); BigDecimal estimatedCost = new BigDecimal(unitCostSumVo.getInventoryValue());
log.info("物料 {} 从IFS获取预估材料成本: {}", partNo, estimatedCost);
log.info("queryEstimatedMaterialCost - Successfully retrieved estimated material cost from IFS: {}", estimatedCost);
return estimatedCost; return estimatedCost;
} else { } else {
log.warn("物料 {} 从IFS获取预估材料成本失败: {}", partNo, map.get("resultMsg"));
log.warn("queryEstimatedMaterialCost - Failed to retrieve from IFS, resultCode={}, resultMsg={}",
map.get("resultCode"), map.get("resultMsg"));
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
} catch (Exception e) { } catch (Exception e) {
log.error("物料 {} 获取预估材料成本异常: {}", partNo, e.getMessage());
log.error("queryEstimatedMaterialCost - Exception occurred for partNo={}: {}", partNo, e.getMessage(), e);
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
} }

4
src/main/java/com/spring/modules/quote/service/impl/QuoteDetailServiceImpl.java

@ -271,9 +271,9 @@ public class QuoteDetailServiceImpl extends ServiceImpl<QuoteDetailMapper, Quote
// 如果半成品的BOM类型是Purchase则加上该物料的预估材料成本(estimated_material_cost) // 如果半成品的BOM类型是Purchase则加上该物料的预估材料成本(estimated_material_cost)
if ("Purchase".equals(bomTree.getBomType())) { if ("Purchase".equals(bomTree.getBomType())) {
BigDecimal estimatedMaterialCost = quoteDetailBomTreeService.queryEstimatedMaterialCost( BigDecimal estimatedMaterialCost = quoteDetailBomTreeService.queryEstimatedMaterialCost(
bomTree.getSite(), bomTree.getPartNo());
bomTree.getSite(), bomTree.getPartNo(), bomTree.getStatus());
bomQuotePrice = bomQuotePrice.add(estimatedMaterialCost); bomQuotePrice = bomQuotePrice.add(estimatedMaterialCost);
log.info("半成品 {} 为Purchase类型,加上预估材料成本 {},累计成本为 {}",
log.info("Semi-finished product {} is Purchase type, add estimated material cost {}, accumulated cost is {}",
bomTree.getPartNo(), estimatedMaterialCost, bomQuotePrice); bomTree.getPartNo(), estimatedMaterialCost, bomQuotePrice);
} }
log.info("当前BOM:{}", bomTree.getPartNo()); log.info("当前BOM:{}", bomTree.getPartNo());

Loading…
Cancel
Save