fix:库存查询,库存对账,
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package org.nl.wms.basedata_manage.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -18,7 +20,11 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
@@ -48,6 +54,50 @@ public class StructIvtController {
|
||||
@Log("库存同步")
|
||||
public ResponseEntity<Object> syncStock(@RequestBody JSONObject param) {
|
||||
String warehouseno = param.getString("warehouseno");
|
||||
return ResponseData.build(iMdPbStoragevehicleextService.syncStock(warehouseno), HttpStatus.OK);
|
||||
return ResponseData.build(iMdPbStoragevehicleextService.syncStock(warehouseno, parseMaterials(param)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析物料清单:支持数组和"一行一个/逗号分隔"的文本
|
||||
*/
|
||||
private List<String> parseMaterials(JSONObject param) {
|
||||
Set<String> codes = new LinkedHashSet<>();
|
||||
if (param == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Object value = param.get("materials");
|
||||
if (value instanceof JSONArray) {
|
||||
for (Object item : (JSONArray) value) {
|
||||
addMaterial(codes, item == null ? null : item.toString());
|
||||
}
|
||||
} else if (value != null) {
|
||||
addMaterialText(codes, value.toString());
|
||||
} else if (param.get("materialCodes") != null) {
|
||||
Object codesValue = param.get("materialCodes");
|
||||
if (codesValue instanceof JSONArray) {
|
||||
for (Object item : (JSONArray) codesValue) {
|
||||
addMaterial(codes, item == null ? null : item.toString());
|
||||
}
|
||||
} else {
|
||||
addMaterialText(codes, codesValue.toString());
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(codes);
|
||||
}
|
||||
|
||||
private void addMaterialText(Set<String> codes, String text) {
|
||||
if (StrUtil.isBlank(text)) {
|
||||
return;
|
||||
}
|
||||
for (String part : text.split("[,,;;\\s]+")) {
|
||||
addMaterial(codes, part);
|
||||
}
|
||||
}
|
||||
|
||||
private void addMaterial(Set<String> codes, String code) {
|
||||
String value = StrUtil.trim(code);
|
||||
if (StrUtil.isNotBlank(value)) {
|
||||
codes.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,17 @@ public interface IMdPbStoragevehicleextService extends IService<MdPbStoragevehic
|
||||
*/
|
||||
List<MdPbStoragevehicleextDto> queryAll(Map whereJson);
|
||||
|
||||
/**
|
||||
* 库存同步(自动物料范围:本库区已有库存物料 + 物料仓库映射)
|
||||
*/
|
||||
JSONObject syncStock(String warehouseno);
|
||||
|
||||
/**
|
||||
* 库存同步(按指定物料清单同步 SAP 库存)
|
||||
*
|
||||
* @param warehouseno 仓库/库区编码
|
||||
* @param materialCodes 物料清单,为空则按自动物料范围同步
|
||||
*/
|
||||
JSONObject syncStock(String warehouseno, List<String> materialCodes);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.IdUtil;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
||||
@@ -18,11 +21,12 @@ import org.nl.wms.basedata_manage.service.dao.Structattr;
|
||||
import org.nl.wms.basedata_manage.service.dao.mapper.MdPbStoragevehicleextMapper;
|
||||
import org.nl.wms.basedata_manage.service.dto.MdPbStoragevehicleextDto;
|
||||
import org.nl.wms.decision_manage.service.strategyConfig.decisioner.impl.diy.InventoryRuleHandler;
|
||||
import org.nl.wms.ext_manage.api.EasApi;
|
||||
import org.nl.wms.ext_manage.api.request.QueryEasStockRequest;
|
||||
import org.nl.wms.ext_manage.api.response.QueryEasStockResponse;
|
||||
import org.nl.wms.ext_manage.sap.dto.SapStockQueryResult;
|
||||
import org.nl.wms.ext_manage.sap.service.SapStockQueryService;
|
||||
import org.nl.wms.ext_manage.service.WmsToZDWmdService;
|
||||
import org.nl.wms.ext_manage.service.dto.ZDInventory;
|
||||
import org.nl.wms.pm_manage.demand.service.IMaterialWarehouseMappingService;
|
||||
import org.nl.wms.pm_manage.demand.service.dao.MaterialWarehouseMapping;
|
||||
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
||||
import org.nl.wms.warehouse_manage.service.IMdPbGroupplateService;
|
||||
import org.nl.wms.warehouse_manage.service.dao.GroupPlate;
|
||||
@@ -41,11 +45,10 @@ import java.util.*;
|
||||
* @author Liuxy
|
||||
* @since 2025-05-23
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MdPbStoragevehicleextServiceImpl extends ServiceImpl<MdPbStoragevehicleextMapper, MdPbStoragevehicleext> implements IMdPbStoragevehicleextService {
|
||||
|
||||
@Autowired
|
||||
private EasApi easApi;
|
||||
@Autowired
|
||||
private IMdPbGroupplateService iMdPbGroupplateService;
|
||||
@Autowired
|
||||
@@ -55,6 +58,10 @@ public class MdPbStoragevehicleextServiceImpl extends ServiceImpl<MdPbStorageveh
|
||||
@Autowired
|
||||
private WmsToZDWmdService wmsToZDWmdService;
|
||||
@Autowired
|
||||
private SapStockQueryService sapStockQueryService;
|
||||
@Autowired
|
||||
private IMaterialWarehouseMappingService materialWarehouseMappingService;
|
||||
@Autowired
|
||||
private InventoryRuleHandler inventoryRuleHandler;
|
||||
|
||||
@Override
|
||||
@@ -69,13 +76,24 @@ public class MdPbStoragevehicleextServiceImpl extends ServiceImpl<MdPbStorageveh
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public JSONObject syncStock(String warehouseno) {
|
||||
return syncStock(warehouseno, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public JSONObject syncStock(String warehouseno, List<String> materialCodes) {
|
||||
if (StringUtils.isBlank(warehouseno)) {
|
||||
throw new BadRequestException("库存同步失败:仓库编码不能为空");
|
||||
}
|
||||
Structattr struct = iStructattrService.getOne(
|
||||
new LambdaQueryWrapper<Structattr>()
|
||||
.eq(Structattr::getSect_code, warehouseno)
|
||||
.last("LIMIT 1"));
|
||||
int updateCount = 0, addCount = 0, deleteCount = 0;
|
||||
if (struct == null) {
|
||||
throw new BadRequestException("库存同步失败:库区" + warehouseno + "未找到对应的库位/载具");
|
||||
}
|
||||
int updateCount = 0, addCount = 0, deleteCount = 0, sapTotal = 0, materialTotal = 0;
|
||||
List<JSONObject> localStocks = this.baseMapper.querySyncByStorCode(warehouseno);
|
||||
|
||||
Map<String, JSONObject> localMap = new HashMap<>();
|
||||
@@ -132,58 +150,75 @@ public class MdPbStoragevehicleextServiceImpl extends ServiceImpl<MdPbStorageveh
|
||||
}
|
||||
}
|
||||
}else{
|
||||
QueryEasStockRequest easRequest = new QueryEasStockRequest();
|
||||
easRequest.setOrgno("01.09.14");
|
||||
easRequest.setWarehouseno(warehouseno);
|
||||
List<QueryEasStockResponse> easStocks = easApi.queryStock(easRequest);
|
||||
Set<String> easKeys = new HashSet<>();
|
||||
// SAP MM027 必须带物料号、body 支持数组批量查询:
|
||||
// 指定了物料清单则只同步清单内物料,否则取本库区已有库存物料 + 物料仓库映射
|
||||
Set<String> scope = new LinkedHashSet<>();
|
||||
boolean specified = materialCodes != null && !materialCodes.isEmpty();
|
||||
if (specified) {
|
||||
for (String code : materialCodes) {
|
||||
String value = StringUtils.trimToNull(code);
|
||||
if (value != null) {
|
||||
scope.add(value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (JSONObject local : localStocks) {
|
||||
String code = StringUtils.trimToNull(local.getString("material_code"));
|
||||
if (code != null) {
|
||||
scope.add(code);
|
||||
}
|
||||
}
|
||||
scope.addAll(listMappedMaterials(warehouseno));
|
||||
}
|
||||
materialTotal = scope.size();
|
||||
log.info("库存同步(库区{}):{}批量查询SAP库存,物料共{}个", warehouseno,
|
||||
specified ? "按指定物料清单" : "按库区库存物料", scope.size());
|
||||
|
||||
for (QueryEasStockResponse eas : easStocks) {
|
||||
String key = eas.getMaterialno();
|
||||
easKeys.add(key);
|
||||
List<String> failedMaterials = new ArrayList<>();
|
||||
Map<String, BigDecimal> sapQtyByMaterial = new HashMap<>();
|
||||
if (!scope.isEmpty()) {
|
||||
SapStockQueryResult sapStock = sapStockQueryService.queryByMaterials(
|
||||
scope, warehouseno, failedMaterials);
|
||||
sapQtyByMaterial = sapStockQueryService.sumQtyByMaterial(sapStock.getBody());
|
||||
}
|
||||
// 查询成功的物料才参与"本地有、SAP无 → 删除"的判断,避免接口异常误删
|
||||
Set<String> queriedKeys = new LinkedHashSet<>(scope);
|
||||
queriedKeys.removeAll(failedMaterials);
|
||||
|
||||
if (localMap.containsKey(key)) {
|
||||
JSONObject local = localMap.get(key);
|
||||
Set<String> sapKeys = new HashSet<>();
|
||||
for (String materialCode : queriedKeys) {
|
||||
BigDecimal sapQty = sapQtyByMaterial.getOrDefault(materialCode, BigDecimal.ZERO);
|
||||
if (sapQty.signum() <= 0) {
|
||||
continue;
|
||||
}
|
||||
sapKeys.add(materialCode);
|
||||
if (localMap.containsKey(materialCode)) {
|
||||
JSONObject local = localMap.get(materialCode);
|
||||
GroupPlate plate = new GroupPlate();
|
||||
plate.setGroup_id(local.getString("group_id"));
|
||||
plate.setQty(new BigDecimal(eas.getQty()));
|
||||
plate.setQty(sapQty);
|
||||
iMdPbGroupplateService.updateById(plate);
|
||||
updateCount++;
|
||||
} else {
|
||||
GroupPlate plate = new GroupPlate();
|
||||
plate.setGroup_id(IdUtil.getStringId());
|
||||
plate.setStoragevehicle_code(struct.getStoragevehicle_code());
|
||||
plate.setMaterial_code(eas.getMaterialno());
|
||||
plate.setPcsn(Optional.ofNullable(eas.getLotnumber()).filter(s -> !s.isEmpty()).orElse("1"));
|
||||
plate.setQty(new BigDecimal(eas.getQty()));
|
||||
plate.setQty_unit_name(eas.getUnitname());
|
||||
plate.setStatus(IOSEnum.GROUP_PLATE_STATUS.code("入库"));
|
||||
plate.setCreate_time(DateUtil.now());
|
||||
plate.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||
plate.setCreate_name(SecurityUtils.getCurrentUsername());
|
||||
|
||||
MdMeMaterialbase material = iMdMeMaterialbaseService.getOne(
|
||||
new LambdaQueryWrapper<MdMeMaterialbase>()
|
||||
.eq(MdMeMaterialbase::getMaterial_code, eas.getMaterialno()));
|
||||
if (material != null) {
|
||||
plate.setQty_unit_id(material.getQty_unit_id());
|
||||
if (plate.getQty_unit_name() == null) {
|
||||
plate.setQty_unit_name(material.getQty_unit_name());
|
||||
}
|
||||
}
|
||||
|
||||
iMdPbGroupplateService.save(plate);
|
||||
|
||||
savePlate(struct, materialCode, sapQty);
|
||||
addCount++;
|
||||
}
|
||||
}
|
||||
|
||||
for (JSONObject local : localStocks) {
|
||||
String key = local.getString("material_code");
|
||||
if (!easKeys.contains(key)) {
|
||||
iMdPbGroupplateService.removeById(local.getString("group_id"));
|
||||
deleteCount++;
|
||||
// 只处理本次同步范围内的物料;查询失败的不动,避免因接口异常误删库存
|
||||
if (key == null || !scope.contains(key) || !queriedKeys.contains(key) || sapKeys.contains(key)) {
|
||||
continue;
|
||||
}
|
||||
iMdPbGroupplateService.removeById(local.getString("group_id"));
|
||||
deleteCount++;
|
||||
}
|
||||
sapTotal = queriedKeys.size();
|
||||
if (!failedMaterials.isEmpty()) {
|
||||
log.warn("库存同步(库区{}):{}个物料查询失败:{}", warehouseno,
|
||||
failedMaterials.size(), failedMaterials.size() > 5
|
||||
? failedMaterials.subList(0, 5) : failedMaterials);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,8 +231,55 @@ public class MdPbStoragevehicleextServiceImpl extends ServiceImpl<MdPbStorageveh
|
||||
result.put("updateCount", updateCount);
|
||||
result.put("addCount", addCount);
|
||||
result.put("deleteCount", deleteCount);
|
||||
result.put("sapTotal", sapTotal);
|
||||
result.put("materialTotal", materialTotal);
|
||||
result.put("localTotal", localStocks.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增组盘记录(SAP 已有库存但 WMS 无记录)
|
||||
*/
|
||||
private void savePlate(Structattr struct, String materialCode, BigDecimal qty) {
|
||||
GroupPlate plate = new GroupPlate();
|
||||
plate.setGroup_id(IdUtil.getStringId());
|
||||
plate.setStoragevehicle_code(struct.getStoragevehicle_code());
|
||||
plate.setMaterial_code(materialCode);
|
||||
plate.setPcsn("1");
|
||||
plate.setQty(qty);
|
||||
plate.setStatus(IOSEnum.GROUP_PLATE_STATUS.code("入库"));
|
||||
plate.setCreate_time(DateUtil.now());
|
||||
plate.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||
plate.setCreate_name(SecurityUtils.getCurrentUsername());
|
||||
MdMeMaterialbase material = iMdMeMaterialbaseService.getOne(
|
||||
new LambdaQueryWrapper<MdMeMaterialbase>()
|
||||
.eq(MdMeMaterialbase::getMaterial_code, materialCode)
|
||||
.last("LIMIT 1"));
|
||||
if (material != null) {
|
||||
plate.setQty_unit_id(material.getQty_unit_id());
|
||||
plate.setQty_unit_name(material.getQty_unit_name());
|
||||
}
|
||||
iMdPbGroupplateService.save(plate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 该库区可能涉及的物料:取物料仓库映射中默认仓为该库区的物料,
|
||||
* 用于发现 SAP 有库存但 WMS 尚无记录的物料。
|
||||
*/
|
||||
private List<String> listMappedMaterials(String warehouseno) {
|
||||
if (StringUtils.isBlank(warehouseno)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<MaterialWarehouseMapping> mappings = materialWarehouseMappingService.list(
|
||||
new LambdaQueryWrapper<MaterialWarehouseMapping>()
|
||||
.eq(MaterialWarehouseMapping::getWarehouseCode, warehouseno));
|
||||
List<String> codes = new ArrayList<>();
|
||||
for (MaterialWarehouseMapping mapping : mappings) {
|
||||
if (mapping != null && StringUtils.isNotBlank(mapping.getMaterialCode())) {
|
||||
codes.add(mapping.getMaterialCode().trim());
|
||||
}
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,4 +17,9 @@ public class BiStockReconcileResult {
|
||||
*/
|
||||
private String compareSourceName;
|
||||
private List<BiStockReconcileRow> rows = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 按库区库存逐个查询 SAP 时,查询失败的物料(已按 SAP 无库存处理,结果里可提示用户)
|
||||
*/
|
||||
private List<String> failedMaterials = new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.nl.wms.bi_manage.service.impl;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -21,10 +19,9 @@ import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||
import org.nl.wms.bi_manage.service.IBiStockService;
|
||||
import org.nl.wms.bi_manage.service.dto.BiStockReconcileResult;
|
||||
import org.nl.wms.bi_manage.service.dto.BiStockReconcileRow;
|
||||
import org.nl.wms.bi_manage.service.dto.SapStockQueryResult;
|
||||
import org.nl.wms.ext_manage.sap.dto.SapStockQueryResult;
|
||||
import org.nl.wms.ext_manage.enums.EXTConstant;
|
||||
import org.nl.wms.ext_manage.sap.api.SapApi;
|
||||
import org.nl.wms.ext_manage.sap.enums.SapConstant;
|
||||
import org.nl.wms.ext_manage.sap.service.SapStockQueryService;
|
||||
import org.nl.wms.ext_manage.service.WmsToZDWmdService;
|
||||
import org.nl.wms.ext_manage.service.dto.ZDInventory;
|
||||
import org.nl.wms.system_manage.service.param.ISysParamService;
|
||||
@@ -56,7 +53,7 @@ import java.util.Set;
|
||||
public class BiStockServiceImpl implements IBiStockService {
|
||||
|
||||
@Autowired
|
||||
private SapApi sapApi;
|
||||
private SapStockQueryService sapStockQueryService;
|
||||
@Autowired
|
||||
private WmsToZDWmdService wmsToZDWmdService;
|
||||
@Autowired
|
||||
@@ -72,13 +69,7 @@ public class BiStockServiceImpl implements IBiStockService {
|
||||
throw new BadRequestException("请选择库区");
|
||||
}
|
||||
sectCode = sectCode.trim();
|
||||
if (StringUtils.isNotBlank(materialCode)) {
|
||||
materialCode = materialCode.trim();
|
||||
}
|
||||
|
||||
JSONObject sapResult = sapApi.stockQuery(materialCode, SapConstant.WERKS, sectCode);
|
||||
SapStockQueryResult sapStock = toSapStock(sapResult);
|
||||
List<SapStockQueryResult.Item> sapStocks = sapStock.getBody();
|
||||
materialCode = StringUtils.trimToNull(materialCode);
|
||||
|
||||
Param zdStorParam = iSysParamService.findByCode(EXTConstant.ZD_STOR_SET);
|
||||
List ZD_STOR_SET;
|
||||
@@ -130,17 +121,23 @@ public class BiStockServiceImpl implements IBiStockService {
|
||||
Map<String, BigDecimal> sapQtyMap = new HashMap<>();
|
||||
Map<String, String> sapNameMap = new HashMap<>();
|
||||
Map<String, String> sapUnitMap = new HashMap<>();
|
||||
for (SapStockQueryResult.Item sap : sapStocks) {
|
||||
String skuCode = StringUtils.trimToEmpty(sap.getMatnr());
|
||||
if (StringUtils.isBlank(skuCode) || !matchMaterial(skuCode, materialCode)) {
|
||||
continue;
|
||||
List<String> failedMaterials = new ArrayList<>();
|
||||
if (materialCode != null) {
|
||||
// 指定物料:只查该物料
|
||||
SapStockQueryResult sapStock = sapStockQueryService.queryByMaterial(materialCode, sectCode);
|
||||
collectSapStock(sapStock.getBody(), materialCode, sapQtyMap, sapNameMap, sapUnitMap);
|
||||
} else {
|
||||
// 未指定物料:先取该库区 WMS 库存物料,再把物料放进 body 数组一次批量查 SAP
|
||||
if (localQtyMap.isEmpty()) {
|
||||
throw new BadRequestException("库区" + sectCode + "在WMS暂无库存,请输入物料编号查询");
|
||||
}
|
||||
sapQtyMap.merge(skuCode, parseQty(sap.stockQty()), BigDecimal::add);
|
||||
if (StringUtils.isNotBlank(sap.getMaktx())) {
|
||||
sapNameMap.putIfAbsent(skuCode, sap.getMaktx().trim());
|
||||
}
|
||||
if (StringUtils.isNotBlank(sap.getMeins())) {
|
||||
sapUnitMap.putIfAbsent(skuCode, sap.getMeins().trim());
|
||||
List<String> materialCodes = new ArrayList<>(localQtyMap.keySet());
|
||||
Collections.sort(materialCodes);
|
||||
log.info("库存对账:库区{}未指定物料,批量查询SAP库存,物料{}个", sectCode, materialCodes.size());
|
||||
SapStockQueryResult sapStock = sapStockQueryService.queryByMaterials(materialCodes, sectCode, failedMaterials);
|
||||
collectSapStock(sapStock.getBody(), null, sapQtyMap, sapNameMap, sapUnitMap);
|
||||
if (!failedMaterials.isEmpty()) {
|
||||
log.warn("库存对账:{}个物料查询SAP库存失败", failedMaterials.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,12 +172,39 @@ public class BiStockServiceImpl implements IBiStockService {
|
||||
result.setSectCode(sectCode);
|
||||
result.setCompareSource(zdStor ? "ZD" : "WMS");
|
||||
result.setCompareSourceName(zdStor ? "中鼎库存" : "WMS库存");
|
||||
result.setFailedMaterials(failedMaterials);
|
||||
result.setRows(rows);
|
||||
log.info("库存对账 sectCode={}, source={}, sapSize={}, localSize={}, rowSize={}",
|
||||
sectCode, result.getCompareSource(), sapStocks.size(), localQtyMap.size(), rows.size());
|
||||
log.info("库存对账 sectCode={}, source={}, sapMaterialSize={}, localSize={}, rowSize={}, failed={}",
|
||||
sectCode, result.getCompareSource(), sapQtyMap.size(), localQtyMap.size(), rows.size(),
|
||||
failedMaterials.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇总 MM027 返回的库存:数量累加,名称/单位取第一条非空
|
||||
*/
|
||||
private void collectSapStock(List<SapStockQueryResult.Item> sapStocks, String materialCode,
|
||||
Map<String, BigDecimal> sapQtyMap,
|
||||
Map<String, String> sapNameMap,
|
||||
Map<String, String> sapUnitMap) {
|
||||
if (sapStocks == null || sapStocks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (SapStockQueryResult.Item sap : sapStocks) {
|
||||
String skuCode = StringUtils.trimToEmpty(sap.getMatnr());
|
||||
if (StringUtils.isBlank(skuCode) || !matchMaterial(skuCode, materialCode)) {
|
||||
continue;
|
||||
}
|
||||
sapQtyMap.merge(skuCode, parseQty(sap.stockQty()), BigDecimal::add);
|
||||
if (StringUtils.isNotBlank(sap.getMaktx())) {
|
||||
sapNameMap.putIfAbsent(skuCode, sap.getMaktx().trim());
|
||||
}
|
||||
if (StringUtils.isNotBlank(sap.getMeins())) {
|
||||
sapUnitMap.putIfAbsent(skuCode, sap.getMeins().trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(String sectCode, String materialCode, Boolean onlyDiff, HttpServletResponse response) throws IOException {
|
||||
BiStockReconcileResult result = reconcile(sectCode, materialCode, onlyDiff);
|
||||
@@ -308,83 +332,4 @@ public class BiStockServiceImpl implements IBiStockService {
|
||||
return StringUtils.isNotBlank(first) ? first : second;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把 MM027 响应转成实体。body 可能是数组,也可能是带 data 的对象。
|
||||
* status=E 且没有物料号时视为查询失败。
|
||||
*/
|
||||
private SapStockQueryResult toSapStock(JSONObject result) {
|
||||
SapStockQueryResult response = new SapStockQueryResult();
|
||||
if (result == null) {
|
||||
return response;
|
||||
}
|
||||
JSONObject headerJson = result.getJSONObject("header");
|
||||
if (headerJson != null) {
|
||||
SapStockQueryResult.Header header = headerJson.toJavaObject(SapStockQueryResult.Header.class);
|
||||
response.setHeader(header);
|
||||
if (header != null && "E".equalsIgnoreCase(StringUtils.trimToEmpty(header.getStatus()))) {
|
||||
throw new BadRequestException(StringUtils.defaultIfBlank(header.getMessage(), "SAP库存查询失败"));
|
||||
}
|
||||
}
|
||||
JSONArray rows = resolveBodyRows(result.get("body"));
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return response;
|
||||
}
|
||||
List<SapStockQueryResult.Item> items = JSON.parseArray(rows.toJSONString(), SapStockQueryResult.Item.class);
|
||||
if (items == null) {
|
||||
return response;
|
||||
}
|
||||
for (SapStockQueryResult.Item item : items) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
if ("E".equalsIgnoreCase(StringUtils.trimToEmpty(item.getStatus())) && StringUtils.isBlank(item.getMatnr())) {
|
||||
throw new BadRequestException(StringUtils.defaultIfBlank(item.getMessage(), "SAP库存查询失败"));
|
||||
}
|
||||
}
|
||||
response.setBody(items);
|
||||
return response;
|
||||
}
|
||||
|
||||
private JSONArray resolveBodyRows(Object body) {
|
||||
if (body == null) {
|
||||
return null;
|
||||
}
|
||||
if (body instanceof JSONArray) {
|
||||
return (JSONArray) body;
|
||||
}
|
||||
if (body instanceof JSONObject) {
|
||||
JSONObject bodyObj = (JSONObject) body;
|
||||
JSONArray rows = firstArray(bodyObj, "data", "item", "items", "result");
|
||||
if (rows != null) {
|
||||
return rows;
|
||||
}
|
||||
JSONArray single = new JSONArray();
|
||||
single.add(bodyObj);
|
||||
return single;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JSONArray firstArray(JSONObject obj, String... keys) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
for (String key : keys) {
|
||||
JSONArray array = obj.getJSONArray(key);
|
||||
if (array != null) {
|
||||
return array;
|
||||
}
|
||||
}
|
||||
for (String actual : obj.keySet()) {
|
||||
for (String key : keys) {
|
||||
if (actual.equalsIgnoreCase(key)) {
|
||||
JSONArray array = obj.getJSONArray(actual);
|
||||
if (array != null) {
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,22 @@
|
||||
- `material_document_item.lifnr_name` — 物料凭证同步 `POST /insertSapRkd`(供应商在行项目上,列表取 `MAX(i.lifnr_name)`)。
|
||||
|
||||
|
||||
## SAP 库存查询(MM027)
|
||||
|
||||
- `SapApi#stockQuery(matnr, werks, lgort)` / `stockQueryBatch(matnrs, ...)`,统一由 `SapStockQueryService` 调用与解析(响应 DTO `ext_manage.sap.dto.SapStockQueryResult`)。
|
||||
- 请求 `body` 是**行项目数组**,一个物料一行,支持一次批量查询多个物料;`SapStockQueryService` 按每批 200 个物料提交。
|
||||
- 响应 `body` 为对象 `{status, message, data:[...], serialnumber:[]}`,`data[]` 中 `labst` 为库存量。
|
||||
- **该接口必须带物料号**,仓库/工厂只用于限定范围,不支持"只传仓库查整仓库存"。
|
||||
- 库存对账 `GET /api/bi/reconcile`:
|
||||
- 传 `materialCode` → 只查该物料;
|
||||
- **不传 `materialCode`** → 先取该库区 WMS(中鼎库区取中鼎)库存物料,构造 body 数组**批量**查 MM027,得到整仓对账结果;
|
||||
某批查询失败会自动退回逐物料查询,真正失败的物料通过 `failedMaterials` 返回(按无库存处理),前端会提示。
|
||||
- 库存同步 `POST /api/structivt/syncStock`:页面弹窗选择仓库 + 粘贴物料清单(一行一个),
|
||||
后端按清单批量调 MM027 并同步到该库区的组盘库存(`md_pb_groupplate`):
|
||||
数量有值 → 更新/新增;清单内物料 SAP 无库存 → 删除本地记录;只处理清单内物料,不影响其他物料。
|
||||
不传 `materials` 时(如定时任务)物料范围 = 该库区已有库存物料 ∪ `pm_material_warehouse_mapping`。
|
||||
查询失败的物料不参与"删除本地库存"判断,避免接口异常误删。
|
||||
|
||||
## 业务模块位置
|
||||
|
||||
业务 CRUD、下推、回传策略等均在 `org.nl.wms.pm_manage.sap` 下:
|
||||
|
||||
@@ -151,14 +151,25 @@ public class SapApi {
|
||||
}
|
||||
|
||||
/**
|
||||
* MM027 库存查询
|
||||
* MM027 库存查询(单物料)
|
||||
*
|
||||
* @param matnr 物料编码
|
||||
* @param werks 工厂,空则默认 1060
|
||||
* @param lgort 仓库编码
|
||||
*/
|
||||
public JSONObject stockQuery(String matnr, String werks, String lgort) {
|
||||
return postQuery("SAP库存查询[" + SapConstant.INTF_MM027 + "]", buildStockQueryRequest(matnr, werks, lgort));
|
||||
return stockQueryBatch(Collections.singletonList(matnr), werks, lgort);
|
||||
}
|
||||
|
||||
/**
|
||||
* MM027 库存查询(批量)。body 是行项目数组,一次可传多个物料。
|
||||
*
|
||||
* @param matnrs 物料编码集合
|
||||
* @param werks 工厂,空则默认 1060
|
||||
* @param lgort 仓库编码
|
||||
*/
|
||||
public JSONObject stockQueryBatch(List<String> matnrs, String werks, String lgort) {
|
||||
return postQuery("SAP库存查询[" + SapConstant.INTF_MM027 + "]", buildStockQueryRequest(matnrs, werks, lgort));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,9 +343,9 @@ public class SapApi {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 MM027 库存查询请求。除物料、工厂、仓库外,其余字段按接口约定固定。
|
||||
* 构建 MM027 库存查询请求:body 为行项目数组,一个物料一行;除物料、工厂、仓库外其余字段按接口约定固定。
|
||||
*/
|
||||
private JSONObject buildStockQueryRequest(String matnr, String werks, String lgort) {
|
||||
private JSONObject buildStockQueryRequest(List<String> matnrs, String werks, String lgort) {
|
||||
JSONObject header = new JSONObject();
|
||||
header.put("intf_id", SapConstant.INTF_MM027);
|
||||
header.put("src_system", SapConstant.MATERIAL_QUERY_SRC_SYSTEM);
|
||||
@@ -344,18 +355,21 @@ public class SapApi {
|
||||
header.put("backup1", "1");
|
||||
header.put("backup2", "2");
|
||||
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("MATNR", StrUtil.blankToDefault(matnr, ""));
|
||||
item.put("WERKS", StrUtil.blankToDefault(werks, SapConstant.WERKS));
|
||||
item.put("LGORT", StrUtil.blankToDefault(lgort, ""));
|
||||
item.put("ZZTRACKNO", "");
|
||||
item.put("ZZCONFIGMAT", "");
|
||||
item.put("VBELN", "");
|
||||
item.put("POSNR", "");
|
||||
item.put("ZFLAG", "X");
|
||||
|
||||
JSONArray body = new JSONArray();
|
||||
body.add(item);
|
||||
if (matnrs != null) {
|
||||
for (String matnr : matnrs) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("MATNR", StrUtil.blankToDefault(StrUtil.trim(matnr), ""));
|
||||
item.put("WERKS", StrUtil.blankToDefault(werks, SapConstant.WERKS));
|
||||
item.put("LGORT", StrUtil.blankToDefault(lgort, ""));
|
||||
item.put("ZZTRACKNO", "");
|
||||
item.put("ZZCONFIGMAT", "");
|
||||
item.put("VBELN", "");
|
||||
item.put("POSNR", "");
|
||||
item.put("ZFLAG", "X");
|
||||
body.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject request = new JSONObject();
|
||||
request.put("header", header);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.nl.wms.bi_manage.service.dto;
|
||||
package org.nl.wms.ext_manage.sap.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
@@ -67,6 +67,7 @@ public class SapBillFeedbackService {
|
||||
return type == OutboundDeliveryBillType.SUBCONTRACT_OUT
|
||||
|| type == OutboundDeliveryBillType.SALES_OUT
|
||||
|| type == OutboundDeliveryBillType.SALES_RETURN_IN
|
||||
|| type == OutboundDeliveryBillType.TRANSFER_OUT
|
||||
|| type == OutboundDeliveryBillType.TRANSFER_IN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
package org.nl.wms.ext_manage.sap.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.wms.ext_manage.sap.api.SapApi;
|
||||
import org.nl.wms.ext_manage.sap.dto.SapStockQueryResult;
|
||||
import org.nl.wms.ext_manage.sap.enums.SapConstant;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* SAP 库存查询(MM027)。
|
||||
* <p>
|
||||
* 该接口<b>必须带物料号</b>,不能只按仓库查询整仓库存;但 body 是行项目数组,支持一次传多个物料批量查询。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SapStockQueryService {
|
||||
|
||||
/** 单次请求的最大物料数,避免报文过大 */
|
||||
private static final int BATCH_SIZE = 200;
|
||||
|
||||
private final SapApi sapApi;
|
||||
|
||||
/**
|
||||
* 按单个物料查询指定仓库的 SAP 库存
|
||||
*
|
||||
* @param matnr 物料号(必填)
|
||||
* @param lgort 仓库/库存地点,空则不限
|
||||
*/
|
||||
public SapStockQueryResult queryByMaterial(String matnr, String lgort) {
|
||||
if (StrUtil.isBlank(matnr)) {
|
||||
throw new BadRequestException("SAP库存查询失败:必须指定物料号");
|
||||
}
|
||||
JSONObject result = sapApi.stockQuery(matnr.trim(), SapConstant.WERKS, StrUtil.trim(lgort));
|
||||
return parse(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量查询多个物料的 SAP 库存:body 组装成行项目数组一次提交。
|
||||
* <p>
|
||||
* 单批失败时退回逐物料查询,把真正失败的物料收集到 failedMaterials,保证个别物料异常不影响整体。
|
||||
*
|
||||
* @param matnrs 物料号集合
|
||||
* @param lgort 仓库/库存地点
|
||||
* @param failedMaterials 失败物料收集(可为 null)
|
||||
*/
|
||||
public SapStockQueryResult queryByMaterials(Collection<String> matnrs, String lgort,
|
||||
List<String> failedMaterials) {
|
||||
List<String> codes = matnrs == null ? new ArrayList<>() : matnrs.stream()
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.map(String::trim)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (codes.isEmpty()) {
|
||||
throw new BadRequestException("SAP库存查询失败:必须指定物料号");
|
||||
}
|
||||
String targetLgort = StrUtil.trim(lgort);
|
||||
SapStockQueryResult merged = new SapStockQueryResult();
|
||||
for (int i = 0; i < codes.size(); i += BATCH_SIZE) {
|
||||
List<String> chunk = codes.subList(i, Math.min(i + BATCH_SIZE, codes.size()));
|
||||
try {
|
||||
JSONObject result = sapApi.stockQueryBatch(chunk, SapConstant.WERKS, targetLgort);
|
||||
mergeInto(merged, parse(result));
|
||||
} catch (Exception e) {
|
||||
log.warn("SAP库存批量查询失败({}个物料),退回逐个查询:{}", chunk.size(), e.getMessage());
|
||||
queryOneByOne(merged, chunk, targetLgort, failedMaterials);
|
||||
}
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量查询,失败直接抛出(适合只查一个物料、需要明确报错的场景)
|
||||
*/
|
||||
public SapStockQueryResult queryByMaterials(Collection<String> matnrs, String lgort) {
|
||||
return queryByMaterials(matnrs, lgort, null);
|
||||
}
|
||||
|
||||
private void queryOneByOne(SapStockQueryResult merged, List<String> codes, String lgort,
|
||||
List<String> failedMaterials) {
|
||||
for (String code : codes) {
|
||||
try {
|
||||
mergeInto(merged, queryByMaterial(code, lgort));
|
||||
} catch (Exception e) {
|
||||
if (failedMaterials != null) {
|
||||
failedMaterials.add(code);
|
||||
}
|
||||
log.warn("SAP库存查询失败:物料{},{}", code, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeInto(SapStockQueryResult target, SapStockQueryResult part) {
|
||||
if (part == null) {
|
||||
return;
|
||||
}
|
||||
if (part.getHeader() != null) {
|
||||
target.setHeader(part.getHeader());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(part.getBody())) {
|
||||
target.getBody().addAll(part.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 某物料在某仓库的 SAP 库存合计
|
||||
*/
|
||||
public BigDecimal sumStockQty(String matnr, String lgort) {
|
||||
return sumQty(queryByMaterial(matnr, lgort).getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* 按物料汇总库存数量:非限制库存优先,其次数量字段
|
||||
*/
|
||||
public Map<String, BigDecimal> sumQtyByMaterial(List<SapStockQueryResult.Item> items) {
|
||||
Map<String, BigDecimal> result = new HashMap<>();
|
||||
if (CollectionUtils.isEmpty(items)) {
|
||||
return result;
|
||||
}
|
||||
for (SapStockQueryResult.Item item : items) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
String matnr = StrUtil.trim(item.getMatnr());
|
||||
if (StrUtil.isBlank(matnr)) {
|
||||
continue;
|
||||
}
|
||||
BigDecimal qty = parseQty(item.stockQty());
|
||||
if (qty != null) {
|
||||
result.merge(matnr, qty, BigDecimal::add);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇总库存数量:非限制库存优先,其次数量字段
|
||||
*/
|
||||
public BigDecimal sumQty(List<SapStockQueryResult.Item> items) {
|
||||
if (CollectionUtils.isEmpty(items)) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
for (SapStockQueryResult.Item item : items) {
|
||||
BigDecimal qty = parseQty(item == null ? null : item.stockQty());
|
||||
if (qty != null) {
|
||||
total = total.add(qty);
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public BigDecimal parseQty(String value) {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new BigDecimal(value.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("SAP库存数量格式不正确:{}", value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把 MM027 响应转成实体。body 可能是数组,也可能是带 data 的对象。
|
||||
* status=E 且没有物料号时视为查询失败。
|
||||
*/
|
||||
private SapStockQueryResult parse(JSONObject result) {
|
||||
SapStockQueryResult response = new SapStockQueryResult();
|
||||
if (result == null) {
|
||||
return response;
|
||||
}
|
||||
JSONObject headerJson = result.getJSONObject("header");
|
||||
if (headerJson != null) {
|
||||
SapStockQueryResult.Header header = headerJson.toJavaObject(SapStockQueryResult.Header.class);
|
||||
response.setHeader(header);
|
||||
if (header != null && "E".equalsIgnoreCase(StrUtil.trimToEmpty(header.getStatus()))) {
|
||||
throw new BadRequestException(StrUtil.blankToDefault(header.getMessage(), "SAP库存查询失败"));
|
||||
}
|
||||
}
|
||||
// 响应 body 为对象:{status, message, data:[...]},错误信息在 body.status/message 上
|
||||
Object bodyValue = result.get("body");
|
||||
if (bodyValue instanceof JSONObject) {
|
||||
JSONObject bodyObj = (JSONObject) bodyValue;
|
||||
if ("E".equalsIgnoreCase(StrUtil.trimToEmpty(bodyObj.getString("status")))) {
|
||||
throw new BadRequestException(StrUtil.blankToDefault(bodyObj.getString("message"), "SAP库存查询失败"));
|
||||
}
|
||||
}
|
||||
JSONArray rows = resolveBodyRows(bodyValue);
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return response;
|
||||
}
|
||||
List<SapStockQueryResult.Item> items = JSON.parseArray(rows.toJSONString(), SapStockQueryResult.Item.class);
|
||||
if (items == null) {
|
||||
return response;
|
||||
}
|
||||
for (SapStockQueryResult.Item item : items) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
if ("E".equalsIgnoreCase(StrUtil.trimToEmpty(item.getStatus())) && StrUtil.isBlank(item.getMatnr())) {
|
||||
throw new BadRequestException(StrUtil.blankToDefault(item.getMessage(), "SAP库存查询失败"));
|
||||
}
|
||||
}
|
||||
response.setBody(items);
|
||||
return response;
|
||||
}
|
||||
|
||||
private JSONArray resolveBodyRows(Object body) {
|
||||
if (body == null) {
|
||||
return null;
|
||||
}
|
||||
if (body instanceof JSONArray) {
|
||||
return (JSONArray) body;
|
||||
}
|
||||
if (body instanceof JSONObject) {
|
||||
JSONObject bodyObj = (JSONObject) body;
|
||||
JSONArray rows = firstArray(bodyObj, "data", "item", "items", "result");
|
||||
if (rows != null) {
|
||||
return rows;
|
||||
}
|
||||
JSONArray single = new JSONArray();
|
||||
single.add(bodyObj);
|
||||
return single;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JSONArray firstArray(JSONObject obj, String... keys) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
for (String key : keys) {
|
||||
JSONArray array = obj.getJSONArray(key);
|
||||
if (array != null) {
|
||||
return array;
|
||||
}
|
||||
}
|
||||
for (String actual : obj.keySet()) {
|
||||
for (String key : keys) {
|
||||
if (actual.equalsIgnoreCase(key)) {
|
||||
JSONArray array = obj.getJSONArray(actual);
|
||||
if (array != null) {
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ package org.nl.wms.pm_manage.sap.materialDocument.enums;
|
||||
*/
|
||||
public enum MaterialDocumentBillType {
|
||||
|
||||
TRANSFER_IN("TRANSFER_IN", "调拨入库", MaterialDocumentIo.IN, "调拨入库"),
|
||||
TRANSFER_OUT("TRANSFER_OUT", "调拨出库", MaterialDocumentIo.OUT, "调拨出库"),
|
||||
// TRANSFER_IN("TRANSFER_IN", "调拨入库", MaterialDocumentIo.IN, "调拨入库"),
|
||||
// TRANSFER_OUT("TRANSFER_OUT", "调拨出库", MaterialDocumentIo.OUT, "调拨出库"),
|
||||
PURCHASE_IN("PURCHASE_IN", "采购入库", MaterialDocumentIo.IN, "采购入库"),
|
||||
SUBCONTRACT_IN("SUBCONTRACT_IN", "委外入库-成品", MaterialDocumentIo.IN, "采购入库"),
|
||||
SUBCONTRACT_RETURN_IN("SUBCONTRACT_RETURN_IN", "委外交货退货入库", MaterialDocumentIo.IN, "其他入库"),
|
||||
|
||||
@@ -55,11 +55,11 @@ public final class MaterialDocumentBillTypeResolver {
|
||||
}
|
||||
Set<String> bwarts = collectBwarts(items);
|
||||
//调拨出入库
|
||||
if (isTransfer(items, bwarts)) {
|
||||
return isTransferOut(items, bwarts)
|
||||
? MaterialDocumentBillType.TRANSFER_OUT
|
||||
: MaterialDocumentBillType.TRANSFER_IN;
|
||||
}
|
||||
// if (isTransfer(items, bwarts)) {
|
||||
// return isTransferOut(items, bwarts)
|
||||
// ? MaterialDocumentBillType.TRANSFER_OUT
|
||||
// : MaterialDocumentBillType.TRANSFER_IN;
|
||||
// }
|
||||
if (containsAny(bwarts, SUBCONTRACT_RETURN_BWART)) {
|
||||
return MaterialDocumentBillType.SUBCONTRACT_RETURN_IN;
|
||||
}
|
||||
|
||||
@@ -449,12 +449,12 @@ public class MaterialDocumentServiceImpl implements MaterialDocumentService {
|
||||
if (type == MaterialDocumentBillType.PURCHASE_IN) {
|
||||
return 1;
|
||||
}
|
||||
if (type == MaterialDocumentBillType.TRANSFER_OUT) {
|
||||
return 106;
|
||||
}
|
||||
if (type == MaterialDocumentBillType.SUBCONTRACT_RETURN_IN) {
|
||||
return 109;
|
||||
}
|
||||
// if (type == MaterialDocumentBillType.TRANSFER_OUT) {
|
||||
// return 106;
|
||||
// }
|
||||
// if (type == MaterialDocumentBillType.SUBCONTRACT_RETURN_IN) {
|
||||
// return 109;
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
v-model="materialCode"
|
||||
clearable
|
||||
size="small"
|
||||
placeholder="请输入物料编号"
|
||||
placeholder="物料编号(不填则按库区库存逐个查SAP)"
|
||||
style="width: 200px;"
|
||||
class="filter-item"
|
||||
@keyup.enter.native="queryReconcile"
|
||||
@@ -53,6 +53,9 @@
|
||||
|
||||
<div v-if="queried" class="summary">
|
||||
对比来源:SAP / {{ compareSourceName }},共 {{ displayData.length }} 条,不一致 {{ diffCount }} 条
|
||||
<span v-if="failedMaterials.length" style="color: #e6a23c; margin-left: 8px;">
|
||||
({{ failedMaterials.length }} 个物料查询SAP库存失败,已按无库存处理)
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
@@ -138,6 +141,7 @@ export default {
|
||||
downloadLoading: false,
|
||||
queried: false,
|
||||
compareSourceName: '对比库存',
|
||||
failedMaterials: [],
|
||||
tableData: [],
|
||||
page: {
|
||||
page: 1,
|
||||
@@ -202,13 +206,21 @@ export default {
|
||||
this.$message.warning('请选择库区')
|
||||
return
|
||||
}
|
||||
const materialCode = (this.materialCode || '').trim()
|
||||
this.loading = true
|
||||
reconcile({ sectCode: this.sectCode, materialCode: this.materialCode }).then(res => {
|
||||
reconcile({ sectCode: this.sectCode, materialCode }).then(res => {
|
||||
const data = res.data || {}
|
||||
this.compareSourceName = data.compareSourceName || '对比库存'
|
||||
this.failedMaterials = data.failedMaterials || []
|
||||
this.tableData = data.rows || []
|
||||
this.page.page = 1
|
||||
this.queried = true
|
||||
if (this.failedMaterials.length) {
|
||||
const preview = this.failedMaterials.slice(0, 5).join('、')
|
||||
this.$message.warning(
|
||||
`${this.failedMaterials.length} 个物料查询SAP库存失败(${preview}${this.failedMaterials.length > 5 ? ' 等' : ''}),已按无库存处理`
|
||||
)
|
||||
}
|
||||
}).catch(() => {
|
||||
this.tableData = []
|
||||
}).finally(() => {
|
||||
@@ -224,7 +236,7 @@ export default {
|
||||
return
|
||||
}
|
||||
this.downloadLoading = true
|
||||
download('/api/bi/reconcile/download', { sectCode: this.sectCode, materialCode: this.materialCode, onlyDiff: this.onlyDiff }).then(result => {
|
||||
download('/api/bi/reconcile/download', { sectCode: this.sectCode, materialCode: (this.materialCode || '').trim(), onlyDiff: this.onlyDiff }).then(result => {
|
||||
downloadFile(result, '库存对账', 'xlsx')
|
||||
}).catch(() => {
|
||||
this.$message.error('导出失败')
|
||||
|
||||
@@ -129,21 +129,37 @@
|
||||
<el-dialog
|
||||
title="库存同步"
|
||||
:visible.sync="syncDialogVisible"
|
||||
width="400px"
|
||||
width="520px"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form label-width="80px" label-suffix=":">
|
||||
<el-form-item label="仓库编码">
|
||||
<el-form label-width="90px" label-suffix=":" size="small">
|
||||
<el-form-item label="仓库">
|
||||
<el-input
|
||||
v-model="syncWarehouseCode"
|
||||
placeholder="请输入仓库编码"
|
||||
v-model.trim="syncWarehouseCode"
|
||||
clearable
|
||||
placeholder="请输入仓库编码"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="物料清单">
|
||||
<el-input
|
||||
v-model="syncMaterials"
|
||||
type="textarea"
|
||||
:rows="8"
|
||||
placeholder="一行一个物料号,可直接从 Excel 粘贴一列"
|
||||
/>
|
||||
<div style="color: #909399; font-size: 12px; line-height: 18px; margin-top: 4px;">
|
||||
按清单逐个物料查询 SAP 库存(MM027),已去重:{{ parsedMaterials.length }} 个
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="syncDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="syncLoading" @click="doSyncStock">确定</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="syncLoading"
|
||||
:disabled="!syncWarehouseCode || !parsedMaterials.length"
|
||||
@click="doSyncStock"
|
||||
>确定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
@@ -237,6 +253,7 @@ export default {
|
||||
rules: {},
|
||||
syncDialogVisible: false,
|
||||
syncWarehouseCode: '',
|
||||
syncMaterials: '',
|
||||
syncLoading: false,
|
||||
exporting: false,
|
||||
printDialogVisible: false,
|
||||
@@ -248,6 +265,17 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
// 物料清单:按换行/逗号/空格拆分,去空去重
|
||||
parsedMaterials() {
|
||||
const text = this.syncMaterials || ''
|
||||
const codes = text
|
||||
.split(/[,,;;\s]+/)
|
||||
.map(item => item.trim())
|
||||
.filter(item => !!item)
|
||||
return Array.from(new Set(codes))
|
||||
}
|
||||
},
|
||||
created() {
|
||||
crudSectattr.getSect({ 'stor_id': '' }).then(res => {
|
||||
this.sects = res.data
|
||||
@@ -337,6 +365,7 @@ export default {
|
||||
},
|
||||
openSyncDialog() {
|
||||
this.syncWarehouseCode = ''
|
||||
this.syncMaterials = ''
|
||||
this.syncDialogVisible = true
|
||||
},
|
||||
doSyncStock() {
|
||||
@@ -344,15 +373,20 @@ export default {
|
||||
this.$message.warning('请输入仓库编码')
|
||||
return
|
||||
}
|
||||
const materials = this.parsedMaterials
|
||||
if (!materials.length) {
|
||||
this.$message.warning('请输入物料清单,一行一个物料号')
|
||||
return
|
||||
}
|
||||
this.syncLoading = true
|
||||
request({
|
||||
url: 'api/structivt/syncStock',
|
||||
method: 'post',
|
||||
data: { warehouseno: this.syncWarehouseCode }
|
||||
data: { warehouseno: this.syncWarehouseCode, materials }
|
||||
}).then(res => {
|
||||
const data = res.data || res
|
||||
this.$message.success(
|
||||
`同步完成!EAS总数:${data.easTotal}, 本地总数:${data.localTotal}, 更新:${data.updateCount}, 新增:${data.addCount}, 删除:${data.deleteCount}`
|
||||
`同步完成!清单物料:${data.materialTotal || 0}, SAP返回物料:${data.sapTotal || 0}, 更新:${data.updateCount}, 新增:${data.addCount}, 删除:${data.deleteCount}`
|
||||
)
|
||||
this.syncDialogVisible = false
|
||||
this.crud.refresh()
|
||||
|
||||
Reference in New Issue
Block a user