add:按行确认收货,调拨推中鼎单据类型修复
This commit is contained in:
@@ -68,9 +68,15 @@
|
||||
- 修改单据仅允许调整明细「存储地点」或删除明细行,其余字段只读;
|
||||
- 收货确认弹窗可勾选「批量修改存储地点」,选定仓库后:所选交货单全部明细的 `lgort` 更新为该仓库,
|
||||
并按该存储地点组装 MM054(`POST /api/sapDelivery/confirmReceipt`,body `{vbelns:[...], lgort:"H002"}`,`lgort` 为空则按明细原存储地点)。
|
||||
- **按行收货确认**:
|
||||
- `POST /api/sapDelivery/confirmItems`(body `{vbeln, itemIds:[...], lgort}`):只把勾选的明细行(含其委外组件)回传 MM054;
|
||||
- 明细行维护 `sap_delivery_item.confirm_status`(0未确认/1已确认)、`confirm_time`、`mblnr`(该行确认产生的物料凭证号);
|
||||
- 整单确认(`/confirmReceipt`)会自动过滤已确认的行,只回传剩余行;全部行确认完才把单据置为完成,否则保持生成状态可继续按行确认;
|
||||
- 已有确认明细的交货单不允许再修改/删除,避免与 SAP 已过账凭证脱节;PDA 查询明细时也不再下发已确认行。
|
||||
- **物料凭证号与操作人**:MM054 响应 `body[0].response_key1` 即 SAP 生成的物料凭证号,收货确认时连确认人一起写入
|
||||
`sap_delivery_order.mblnr / operate_id / operate_name`;SAP 随后推送物料凭证(`POST /insertSapRkd`)时,
|
||||
按 `mblnr` 反查交货单,把操作人写到 `material_document.operate_id / operate_name`,
|
||||
`sap_delivery_order.mblnr / operate_id / operate_name`;按行确认会一单多凭证,凭证号同时记在
|
||||
`sap_delivery_item.mblnr`。SAP 随后推送物料凭证(`POST /insertSapRkd`)时按 `mblnr` 反查交货单
|
||||
(表头查不到再按明细兜底),把操作人写到 `material_document.operate_id / operate_name`,
|
||||
物料凭证列表即可按「操作人」筛选(`params.operate_name`)。
|
||||
|
||||
### PDA 扫码入库(物料凭证 / 交货单)
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -76,6 +77,17 @@ public class SapDeliveryPdaServiceImpl implements SapDeliveryPdaService {
|
||||
.eq(SapDeliveryItem::getHeader_vbeln, order.getVbeln())
|
||||
.orderByAsc(SapDeliveryItem::getPosnr)
|
||||
.orderByAsc(SapDeliveryItem::getRspos));
|
||||
// 已按行确认过的明细不再下发到 PDA,避免重复收货
|
||||
Set<String> confirmedPosnr = items.stream()
|
||||
.filter(i -> (i.getRspos() == null || i.getRspos() == 0)
|
||||
&& "1".equals(StrUtil.trim(i.getConfirm_status())))
|
||||
.map(SapDeliveryItem::getPosnr)
|
||||
.collect(Collectors.toSet());
|
||||
if (!confirmedPosnr.isEmpty()) {
|
||||
items = items.stream()
|
||||
.filter(i -> !confirmedPosnr.contains(i.getPosnr()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
SapDeliveryDetailVo vo = new SapDeliveryDetailVo();
|
||||
vo.setId(order.getId());
|
||||
|
||||
@@ -29,7 +29,9 @@ import org.nl.wms.pm_manage.sap.materialDocument.service.dao.MaterialDocumentIte
|
||||
import org.nl.wms.pm_manage.sap.materialDocument.service.dao.mapper.MaterialDocumentItemMapper;
|
||||
import org.nl.wms.pm_manage.sap.materialDocument.service.dao.mapper.MaterialDocumentMapper;
|
||||
import org.nl.wms.pm_manage.sap.materialDocument.service.dto.*;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dao.SapDeliveryItem;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dao.SapDeliveryOrder;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dao.mapper.SapDeliveryItemMapper;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dao.mapper.SapDeliveryOrderMapper;
|
||||
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.IOutBillService;
|
||||
@@ -57,6 +59,7 @@ public class MaterialDocumentServiceImpl implements MaterialDocumentService {
|
||||
private final ZDWmsApi zdWmsApi;
|
||||
private final SapSupplierQueryService supplierQueryService;
|
||||
private final SapDeliveryOrderMapper sapDeliveryOrderMapper;
|
||||
private final SapDeliveryItemMapper sapDeliveryItemMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -190,6 +193,19 @@ public class MaterialDocumentServiceImpl implements MaterialDocumentService {
|
||||
.isNotNull(SapDeliveryOrder::getOperate_name)
|
||||
.orderByDesc(SapDeliveryOrder::getId)
|
||||
.last("LIMIT 1"));
|
||||
if (delivery == null) {
|
||||
// 按行确认时一张交货单会生成多张物料凭证:凭证号记在明细行上,需再按明细反查
|
||||
SapDeliveryItem item = sapDeliveryItemMapper.selectOne(new LambdaQueryWrapper<SapDeliveryItem>()
|
||||
.eq(SapDeliveryItem::getMblnr, mblnr)
|
||||
.orderByDesc(SapDeliveryItem::getId)
|
||||
.last("LIMIT 1"));
|
||||
if (item == null || StrUtil.isBlank(item.getHeader_vbeln())) {
|
||||
return;
|
||||
}
|
||||
delivery = sapDeliveryOrderMapper.selectOne(new LambdaQueryWrapper<SapDeliveryOrder>()
|
||||
.eq(SapDeliveryOrder::getVbeln, item.getHeader_vbeln())
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
if (delivery == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -500,6 +500,9 @@ public class OutboundDeliveryServiceImpl extends ServiceImpl<OutboundDeliveryMap
|
||||
if (CollectionUtils.isEmpty(items)) {
|
||||
throw new BadRequestException("下推失败:单据" + order.getVbeln() + "明细不存在");
|
||||
}
|
||||
if (OutboundDeliveryBillType.ofCode(order.getBilltype()) == OutboundDeliveryBillType.TRANSFER_IN) {
|
||||
order.setBilltype(OutboundDeliveryBillType.TRANSFER_OUT.getCode());
|
||||
}
|
||||
zdWmsApi.insertSapJhd(order, items, zdBillType, order.getBilltype());
|
||||
order.setStatus(OutboundDeliveryStatus.POSTED.getCode());
|
||||
orderMapper.updateById(order);
|
||||
@@ -509,7 +512,7 @@ public class OutboundDeliveryServiceImpl extends ServiceImpl<OutboundDeliveryMap
|
||||
private Integer zdBillType(String billType) {
|
||||
OutboundDeliveryBillType type = OutboundDeliveryBillType.ofCode(billType);
|
||||
if (type == OutboundDeliveryBillType.TRANSFER_IN) {
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
if (type == OutboundDeliveryBillType.SALES_RETURN_IN) {
|
||||
return 1;
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.wms.ext_manage.sap.api.SapApi;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.SapDeliveryService;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.SapDeliveryConfirmDto;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.SapDeliveryConfirmItemsDto;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.SapDeliveryOrderDto;
|
||||
import org.nl.wms.pm_manage.sap.sapDelivery.service.dto.SapDeliveryQuery;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -108,6 +109,17 @@ public class SapDeliveryController {
|
||||
return ResponseData.build(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/confirmItems")
|
||||
@Log("SAP交货单按行收货确认")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> confirmItems(@RequestBody SapDeliveryConfirmItemsDto dto) {
|
||||
if (dto == null || dto.getVbeln() == null || dto.getVbeln().trim().isEmpty()) {
|
||||
throw new BadRequestException("按行确认失败:交货单号为空");
|
||||
}
|
||||
JSONObject result = sapDeliveryService.confirmItems(dto.getVbeln().trim(), dto.getItemIds(), dto.getLgort());
|
||||
return ResponseData.build(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Log("删除SAP交货单")
|
||||
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
|
||||
|
||||
@@ -23,6 +23,11 @@ public interface SapDeliveryService {
|
||||
*/
|
||||
JSONObject confirmReceipt(String vbeln, String lgort);
|
||||
|
||||
/**
|
||||
* 按行收货确认:只确认勾选的明细行,已确认的行不会重复回传
|
||||
*/
|
||||
JSONObject confirmItems(String vbeln, List<Long> itemIds, String lgort);
|
||||
|
||||
IPage<SapDeliveryOrder> queryPage(SapDeliveryQuery query, PageQuery page);
|
||||
|
||||
SapDeliveryOrderDto getDetail(String vbeln);
|
||||
|
||||
@@ -62,6 +62,15 @@ public class SapDeliveryItem implements Serializable {
|
||||
|
||||
private Double component_qty;
|
||||
|
||||
/** 行确认状态:0未确认 1已确认(委外组件行不维护) */
|
||||
private String confirm_status;
|
||||
|
||||
/** 行确认时间 */
|
||||
private String confirm_time;
|
||||
|
||||
/** 该行收货确认(MM054)返回的物料凭证号 */
|
||||
private String mblnr;
|
||||
|
||||
private LocalDateTime created_at;
|
||||
|
||||
private LocalDateTime updated_at;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.nl.wms.pm_manage.sap.sapDelivery.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 交货单按行收货确认入参
|
||||
*/
|
||||
@Data
|
||||
public class SapDeliveryConfirmItemsDto {
|
||||
|
||||
/** 交货单号 */
|
||||
private String vbeln;
|
||||
|
||||
/** 勾选确认的明细行ID(主行) */
|
||||
private List<Long> itemIds;
|
||||
|
||||
/** 批量指定的存储地点,为空则按明细原存储地点 */
|
||||
private String lgort;
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import java.util.List;
|
||||
@Data
|
||||
public class SapDeliveryItemDto {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String posnr;
|
||||
|
||||
private String material;
|
||||
@@ -43,5 +45,14 @@ public class SapDeliveryItemDto {
|
||||
|
||||
private String lifexpos;
|
||||
|
||||
/** 行确认状态:0未确认 1已确认 */
|
||||
private String confirm_status;
|
||||
|
||||
/** 行确认时间 */
|
||||
private String confirm_time;
|
||||
|
||||
/** 该行收货确认返回的物料凭证号 */
|
||||
private String mblnr;
|
||||
|
||||
private List<SapDeliveryComponentDto> components;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.nl.wms.pm_manage.sap.sapDelivery.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -30,6 +31,7 @@ import org.springframework.util.CollectionUtils;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@@ -39,6 +41,11 @@ public class SapDeliveryServiceImpl implements SapDeliveryService {
|
||||
|
||||
private static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
|
||||
/** 行确认状态:未确认 */
|
||||
private static final String CONFIRM_STATUS_UNCONFIRMED = "0";
|
||||
/** 行确认状态:已确认 */
|
||||
private static final String CONFIRM_STATUS_CONFIRMED = "1";
|
||||
|
||||
private final SapDeliveryOrderMapper orderMapper;
|
||||
private final SapDeliveryItemMapper itemMapper;
|
||||
private final SapApi sapApi;
|
||||
@@ -109,41 +116,87 @@ public class SapDeliveryServiceImpl implements SapDeliveryService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public JSONObject confirmReceipt(String vbeln, String lgort) {
|
||||
if (StrUtil.isBlank(vbeln)) {
|
||||
throw new BadRequestException("收货确认失败:交货单号为空");
|
||||
SapDeliveryOrder order = loadConfirmableOrder(vbeln, "收货确认失败");
|
||||
List<SapDeliveryItem> items = listAllItems(vbeln);
|
||||
// 整单确认:过滤掉已按行确认过的明细
|
||||
Set<String> pendingPosnr = mainItems(items).stream()
|
||||
.filter(item -> !isConfirmed(item))
|
||||
.map(SapDeliveryItem::getPosnr)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
if (pendingPosnr.isEmpty()) {
|
||||
throw new BadRequestException("收货确认失败:交货单" + vbeln + "的明细已全部确认");
|
||||
}
|
||||
SapDeliveryOrder order = orderMapper.selectOne(new LambdaQueryWrapper<SapDeliveryOrder>()
|
||||
.eq(SapDeliveryOrder::getVbeln, vbeln));
|
||||
if (order == null) {
|
||||
throw new BadRequestException("收货确认失败:交货单" + vbeln + "不存在");
|
||||
}
|
||||
if (!SapDeliveryStatus.CREATED.getCode().equals(order.getStatus())) {
|
||||
throw new BadRequestException("收货确认失败:交货单" + vbeln + "非生成状态,无法确认");
|
||||
}
|
||||
List<SapDeliveryItem> items = itemMapper.selectList(new LambdaQueryWrapper<SapDeliveryItem>()
|
||||
.eq(SapDeliveryItem::getHeader_vbeln, vbeln));
|
||||
return doConfirm(order, items, pendingPosnr, lgort);
|
||||
}
|
||||
|
||||
// 收货确认时可批量指定存储地点:明细一并更新,MM054 与单据保持一致
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public JSONObject confirmItems(String vbeln, List<Long> itemIds, String lgort) {
|
||||
if (CollectionUtils.isEmpty(itemIds)) {
|
||||
throw new BadRequestException("按行确认失败:未选择要确认的明细行");
|
||||
}
|
||||
SapDeliveryOrder order = loadConfirmableOrder(vbeln, "按行确认失败");
|
||||
List<SapDeliveryItem> items = listAllItems(vbeln);
|
||||
Map<Long, SapDeliveryItem> mainById = mainItems(items).stream()
|
||||
.filter(item -> item.getId() != null)
|
||||
.collect(Collectors.toMap(SapDeliveryItem::getId, Function.identity(), (a, b) -> a));
|
||||
Set<String> targetPosnr = new LinkedHashSet<>();
|
||||
for (Long itemId : itemIds) {
|
||||
SapDeliveryItem item = itemId == null ? null : mainById.get(itemId);
|
||||
if (item == null) {
|
||||
throw new BadRequestException("按行确认失败:交货单" + vbeln + "中不存在明细行" + itemId);
|
||||
}
|
||||
if (isConfirmed(item)) {
|
||||
throw new BadRequestException("按行确认失败:行项目" + item.getPosnr() + "已确认,请勿重复确认");
|
||||
}
|
||||
targetPosnr.add(item.getPosnr());
|
||||
}
|
||||
return doConfirm(order, items, targetPosnr, lgort);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收货确认共用逻辑:只把 targetPosnr 对应行(含委外组件)回传 MM054,
|
||||
* 成功后维护行确认状态,全部行确认完才把整单置为完成。
|
||||
*/
|
||||
private JSONObject doConfirm(SapDeliveryOrder order, List<SapDeliveryItem> allItems,
|
||||
Set<String> targetPosnr, String lgort) {
|
||||
if (CollectionUtils.isEmpty(targetPosnr)) {
|
||||
throw new BadRequestException("确认失败:未匹配到待确认的明细行");
|
||||
}
|
||||
List<SapDeliveryItem> targetItems = allItems.stream()
|
||||
.filter(item -> targetPosnr.contains(StrUtil.trim(item.getPosnr())))
|
||||
.collect(Collectors.toList());
|
||||
if (targetItems.isEmpty()) {
|
||||
throw new BadRequestException("确认失败:未匹配到待确认的明细行");
|
||||
}
|
||||
|
||||
// 收货确认时可批量指定存储地点:只更新本次确认的主行
|
||||
String targetLgort = StrUtil.trim(lgort);
|
||||
if (StrUtil.isNotBlank(targetLgort)) {
|
||||
for (SapDeliveryItem item : items) {
|
||||
if (item.getRspos() == null || item.getRspos() == 0) {
|
||||
for (SapDeliveryItem item : targetItems) {
|
||||
if (isMainItem(item)) {
|
||||
item.setLgort(targetLgort);
|
||||
}
|
||||
}
|
||||
itemMapper.update(null, new LambdaUpdateWrapper<SapDeliveryItem>()
|
||||
.set(SapDeliveryItem::getLgort, targetLgort)
|
||||
.eq(SapDeliveryItem::getHeader_vbeln, vbeln)
|
||||
.eq(SapDeliveryItem::getHeader_vbeln, order.getVbeln())
|
||||
.in(SapDeliveryItem::getPosnr, targetPosnr)
|
||||
.and(w -> w.isNull(SapDeliveryItem::getRspos).or().eq(SapDeliveryItem::getRspos, 0)));
|
||||
}
|
||||
|
||||
order.setStatus(SapDeliveryStatus.EXECUTING.getCode());
|
||||
orderMapper.updateById(order);
|
||||
ReceiptConfirmRequest request = buildReceiptConfirmRequest(order, items);
|
||||
final String lgort1 = items.get(0).getLgort();
|
||||
if (lgort1.equals("R004")){
|
||||
|
||||
ReceiptConfirmRequest request = buildReceiptConfirmRequest(order, targetItems);
|
||||
String confirmLgort = mainItems(targetItems).stream()
|
||||
.map(SapDeliveryItem::getLgort)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if ("R004".equals(confirmLgort)) {
|
||||
for (ReceiptConfirmBody receiptConfirmBody : request.getBody()) {
|
||||
receiptConfirmBody.getItems().forEach(a->a.setCharg(order.getLfdat()));
|
||||
receiptConfirmBody.getItems().forEach(a -> a.setCharg(order.getLfdat()));
|
||||
}
|
||||
}
|
||||
JSONObject sapResult;
|
||||
@@ -156,21 +209,85 @@ public class SapDeliveryServiceImpl implements SapDeliveryService {
|
||||
}
|
||||
|
||||
// MM054 返回物料凭证号(response_key1),连同收货确认人一起留存,供物料凭证同步时反查操作人
|
||||
order.setMblnr(extractMaterialDocNo(sapResult, vbeln));
|
||||
String mblnr = extractMaterialDocNo(sapResult, order.getVbeln());
|
||||
String now = DateUtil.now();
|
||||
itemMapper.update(null, new LambdaUpdateWrapper<SapDeliveryItem>()
|
||||
.set(SapDeliveryItem::getConfirm_status, CONFIRM_STATUS_CONFIRMED)
|
||||
.set(SapDeliveryItem::getConfirm_time, now)
|
||||
.set(SapDeliveryItem::getMblnr, mblnr)
|
||||
.eq(SapDeliveryItem::getHeader_vbeln, order.getVbeln())
|
||||
.in(SapDeliveryItem::getPosnr, targetPosnr)
|
||||
.and(w -> w.isNull(SapDeliveryItem::getRspos).or().eq(SapDeliveryItem::getRspos, 0)));
|
||||
|
||||
long unconfirmed = mainItems(listAllItems(order.getVbeln())).stream()
|
||||
.filter(item -> !isConfirmed(item))
|
||||
.count();
|
||||
order.setMblnr(mblnr);
|
||||
order.setOperate_id(SecurityUtils.getCurrentUserId());
|
||||
order.setOperate_name(StrUtil.blankToDefault(SecurityUtils.getCurrentNickName(),
|
||||
SecurityUtils.getCurrentUsername()));
|
||||
order.setStatus(SapDeliveryStatus.COMPLETED.getCode());
|
||||
order.setStatus(unconfirmed == 0
|
||||
? SapDeliveryStatus.COMPLETED.getCode()
|
||||
: SapDeliveryStatus.CREATED.getCode());
|
||||
orderMapper.updateById(order);
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("respCode", 0);
|
||||
result.put("respMsg", "收货确认成功");
|
||||
result.put("respMsg", unconfirmed == 0
|
||||
? "收货确认成功"
|
||||
: "按行确认成功,剩余" + unconfirmed + "行未确认");
|
||||
result.put("sapResult", sapResult);
|
||||
result.put("mblnr", order.getMblnr());
|
||||
result.put("mblnr", mblnr);
|
||||
result.put("confirmedCount", targetPosnr.size());
|
||||
result.put("unconfirmedCount", unconfirmed);
|
||||
result.put("status", order.getStatus());
|
||||
return result;
|
||||
}
|
||||
|
||||
private SapDeliveryOrder loadConfirmableOrder(String vbeln, String scene) {
|
||||
if (StrUtil.isBlank(vbeln)) {
|
||||
throw new BadRequestException(scene + ":交货单号为空");
|
||||
}
|
||||
SapDeliveryOrder order = orderMapper.selectOne(new LambdaQueryWrapper<SapDeliveryOrder>()
|
||||
.eq(SapDeliveryOrder::getVbeln, vbeln));
|
||||
if (order == null) {
|
||||
throw new BadRequestException(scene + ":交货单" + vbeln + "不存在");
|
||||
}
|
||||
if (!SapDeliveryStatus.CREATED.getCode().equals(order.getStatus())) {
|
||||
throw new BadRequestException(scene + ":交货单" + vbeln + "非生成状态,无法确认");
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
private List<SapDeliveryItem> listAllItems(String vbeln) {
|
||||
return itemMapper.selectList(new LambdaQueryWrapper<SapDeliveryItem>()
|
||||
.eq(SapDeliveryItem::getHeader_vbeln, vbeln)
|
||||
.orderByAsc(SapDeliveryItem::getPosnr)
|
||||
.orderByAsc(SapDeliveryItem::getRspos));
|
||||
}
|
||||
|
||||
private List<SapDeliveryItem> mainItems(List<SapDeliveryItem> items) {
|
||||
return items.stream().filter(this::isMainItem).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean isMainItem(SapDeliveryItem item) {
|
||||
return item.getRspos() == null || item.getRspos() == 0;
|
||||
}
|
||||
|
||||
private boolean isConfirmed(SapDeliveryItem item) {
|
||||
return CONFIRM_STATUS_CONFIRMED.equals(StrUtil.trim(item.getConfirm_status()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单据是否已有确认过的明细(有则不允许修改/删除,避免确认状态与 SAP 已过账凭证脱节)
|
||||
*/
|
||||
private boolean hasConfirmedItem(String vbeln) {
|
||||
Integer count = itemMapper.selectCount(new LambdaQueryWrapper<SapDeliveryItem>()
|
||||
.eq(SapDeliveryItem::getHeader_vbeln, vbeln)
|
||||
.eq(SapDeliveryItem::getConfirm_status, CONFIRM_STATUS_CONFIRMED));
|
||||
return count != null && count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MM054 响应取物料凭证号:body[0].response_key1
|
||||
*/
|
||||
@@ -261,6 +378,9 @@ public class SapDeliveryServiceImpl implements SapDeliveryService {
|
||||
throw new BadRequestException("修改失败:交货单不存在");
|
||||
}
|
||||
assertEditable(order, "修改");
|
||||
if (hasConfirmedItem(order.getVbeln())) {
|
||||
throw new BadRequestException("修改失败:交货单" + order.getVbeln() + "已有确认过的明细,不能再修改");
|
||||
}
|
||||
if (!StrUtil.equals(order.getVbeln(), dto.getVbeln().trim())) {
|
||||
SapDeliveryOrder duplicated = findByVbeln(dto.getVbeln());
|
||||
if (duplicated != null && !duplicated.getId().equals(order.getId())) {
|
||||
@@ -292,6 +412,9 @@ public class SapDeliveryServiceImpl implements SapDeliveryService {
|
||||
|| SapDeliveryStatus.COMPLETED.getCode().equals(order.getStatus())) {
|
||||
throw new BadRequestException("删除失败:交货单" + order.getVbeln() + "已在执行或已完成");
|
||||
}
|
||||
if (hasConfirmedItem(order.getVbeln())) {
|
||||
throw new BadRequestException("删除失败:交货单" + order.getVbeln() + "已有确认过的明细,不能再删除");
|
||||
}
|
||||
itemMapper.delete(new LambdaQueryWrapper<SapDeliveryItem>()
|
||||
.eq(SapDeliveryItem::getHeader_vbeln, order.getVbeln()));
|
||||
orderMapper.deleteById(order.getId());
|
||||
@@ -320,6 +443,7 @@ public class SapDeliveryServiceImpl implements SapDeliveryService {
|
||||
item.setUntto(itemBody.getUntto());
|
||||
item.setLifexpos(itemBody.getLifexpos());
|
||||
item.setRspos(0);
|
||||
item.setConfirm_status(CONFIRM_STATUS_UNCONFIRMED);
|
||||
itemMapper.insert(item);
|
||||
}
|
||||
|
||||
@@ -501,6 +625,7 @@ public class SapDeliveryServiceImpl implements SapDeliveryService {
|
||||
main.setUntto(dto.getUntto());
|
||||
main.setLifexpos(dto.getLifexpos());
|
||||
main.setRspos(0);
|
||||
main.setConfirm_status(CONFIRM_STATUS_UNCONFIRMED);
|
||||
itemMapper.insert(main);
|
||||
if (CollectionUtils.isEmpty(dto.getComponents())) {
|
||||
continue;
|
||||
@@ -559,6 +684,7 @@ public class SapDeliveryServiceImpl implements SapDeliveryService {
|
||||
continue;
|
||||
}
|
||||
SapDeliveryItemDto itemDto = new SapDeliveryItemDto();
|
||||
itemDto.setId(mainItem.getId());
|
||||
itemDto.setPosnr(mainItem.getPosnr());
|
||||
itemDto.setMaterial(mainItem.getMaterial());
|
||||
itemDto.setMatl_desc(mainItem.getMatl_desc());
|
||||
@@ -577,6 +703,9 @@ public class SapDeliveryServiceImpl implements SapDeliveryService {
|
||||
itemDto.setUebto(mainItem.getUebto());
|
||||
itemDto.setUntto(mainItem.getUntto());
|
||||
itemDto.setLifexpos(mainItem.getLifexpos());
|
||||
itemDto.setConfirm_status(StrUtil.blankToDefault(mainItem.getConfirm_status(), CONFIRM_STATUS_UNCONFIRMED));
|
||||
itemDto.setConfirm_time(mainItem.getConfirm_time());
|
||||
itemDto.setMblnr(mainItem.getMblnr());
|
||||
List<SapDeliveryComponentDto> components = posnrItems.stream()
|
||||
.filter(i -> i.getRspos() != null && i.getRspos() > 0)
|
||||
.map(item -> {
|
||||
|
||||
@@ -40,9 +40,13 @@ CREATE TABLE sap_delivery_item (
|
||||
rspos INT COMMENT '委外行号(组件序号)',
|
||||
component_material VARCHAR(40) COMMENT '组件物料编码',
|
||||
component_qty DOUBLE COMMENT '组件需求数量',
|
||||
confirm_status VARCHAR(2) DEFAULT '0' COMMENT '行确认状态:0未确认 1已确认',
|
||||
confirm_time VARCHAR(30) COMMENT '行确认时间',
|
||||
mblnr VARCHAR(20) COMMENT '该行收货确认返回的物料凭证号',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
INDEX idx_header_vbeln (header_vbeln),
|
||||
INDEX idx_mblnr (mblnr),
|
||||
UNIQUE KEY uk_header_posnr_rspos (header_vbeln, posnr, rspos)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='SAP交货单明细表(含委外组件)';
|
||||
CREATE TABLE material_document (
|
||||
|
||||
Reference in New Issue
Block a user