|
|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.gaotao.modules.other.service.impl; |
|
|
|
|
|
|
|
import com.gaotao.common.exception.XJException; |
|
|
|
import com.gaotao.common.utils.IfsErrorMessageUtils; |
|
|
|
import com.gaotao.modules.api.service.IfsApiIssueAndReturnService; |
|
|
|
import com.gaotao.modules.handlingunit.entity.HandlingUnit; |
|
|
|
import com.gaotao.modules.handlingunit.service.HandlingUnitService; |
|
|
|
@ -80,33 +81,36 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
// 5. 调用独立的其它出库方法生成记录和变更库存 |
|
|
|
List<TransDetail> detailList = genOtherOutboundTransAndChangeStock(transRequest, "OUT"); |
|
|
|
|
|
|
|
// // 6. 调用IFS接口同步出库信息 |
|
|
|
// for (TransDetail detail : detailList) { |
|
|
|
// OtherTransactionIfsDto ifsDto = new OtherTransactionIfsDto(); |
|
|
|
// ifsDto.setIfsSiteID(dto.getSite()); |
|
|
|
// ifsDto.setIfsPartNo(detail.getPartNo()); |
|
|
|
// ifsDto.setIfsLocationNo(detail.getLocationId()); |
|
|
|
// ifsDto.setIfsLotBatchNo(detail.getBatchNo()); |
|
|
|
// ifsDto.setIfsSerialNo("*"); |
|
|
|
// ifsDto.setIfsWdrNo(detail.getWdrNo()); |
|
|
|
// ifsDto.setIfsEngChgLevel("1"); |
|
|
|
// ifsDto.setIfsActivitySeq(BigDecimal.ZERO); |
|
|
|
// ifsDto.setIfsHandlingUntitID(BigDecimal.ZERO); |
|
|
|
// ifsDto.setIfsQuantity(detail.getTransQty()); |
|
|
|
// ifsDto.setIfsTransactionType("OUT"); |
|
|
|
// ifsDto.setIfsReason(dto.getOutboundReason()); |
|
|
|
// ifsDto.setIfsOperator(dto.getOperatorName()); |
|
|
|
// |
|
|
|
// try { |
|
|
|
// String ifsResponse = ifsApiIssueAndReturnService.addOtherOutbound(ifsDto); |
|
|
|
// // 检查IFS响应,如果失败可能需要回滚事务 |
|
|
|
// if (!"IFSUpdated".equals(ifsResponse) && !"\"IFSUpdated\"".equals(ifsResponse)) { |
|
|
|
// throw new XJException("IFS同步失败,响应: " + ifsResponse); |
|
|
|
// } |
|
|
|
// } catch (Exception ifsException) { |
|
|
|
// throw new XJException("其它出库IFS同步失败: " + ifsException.getMessage()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// 6. 调用IFS接口同步出库信息 |
|
|
|
for (TransDetail detail : detailList) { |
|
|
|
OtherTransactionIfsDto ifsDto = new OtherTransactionIfsDto(); |
|
|
|
ifsDto.setIfsSiteID(dto.getSite()); |
|
|
|
ifsDto.setIfsPartNo(detail.getPartNo()); |
|
|
|
ifsDto.setIfsLocationNo(detail.getLocationId()); |
|
|
|
ifsDto.setIfsLotBatchNo(detail.getBatchNo()); |
|
|
|
ifsDto.setIfsSerialNo("*"); |
|
|
|
ifsDto.setIfsWdrNo(detail.getWdrNo()); |
|
|
|
ifsDto.setIfsEngChgLevel("1"); |
|
|
|
ifsDto.setIfsActivitySeq(BigDecimal.ZERO); |
|
|
|
ifsDto.setIfsHandlingUnitID(BigDecimal.ZERO); |
|
|
|
ifsDto.setIfsQuantity(detail.getTransQty()); |
|
|
|
ifsDto.setIfsTransactionType("OUT"); |
|
|
|
ifsDto.setIfsReason(dto.getOutboundReason()); |
|
|
|
ifsDto.setIfsOperator(dto.getOperatorName()); |
|
|
|
|
|
|
|
try { |
|
|
|
String ifsResponse = ifsApiIssueAndReturnService.addOtherOutbound(ifsDto); |
|
|
|
// 检查IFS响应,如果失败可能需要回滚事务 |
|
|
|
if (!"IFSUpdated".equals(ifsResponse) && !"\"IFSUpdated\"".equals(ifsResponse)) { |
|
|
|
throw new XJException("IFS同步失败,响应: " + ifsResponse); |
|
|
|
} else { |
|
|
|
String errorMessage = IfsErrorMessageUtils.extractOracleErrorMessage(ifsResponse); |
|
|
|
throw new Exception(errorMessage); |
|
|
|
} |
|
|
|
} catch (Exception ifsException) { |
|
|
|
throw new XJException("其它出库IFS同步失败: " + ifsException.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 7. 更新HandlingUnit状态 |
|
|
|
updateHandlingUnitStatus(handlingUnits, detailList, currentUser); |
|
|
|
@ -122,7 +126,7 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
// 这里应该通过Mapper查询数据库 |
|
|
|
// 暂时返回模拟数据,实际项目中需要实现具体的查询逻辑 |
|
|
|
List<OtherOutboundHistoryDto> historyList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 可以添加一些模拟数据用于测试 |
|
|
|
OtherOutboundHistoryDto history1 = new OtherOutboundHistoryDto(); |
|
|
|
history1.setTransNo("OO" + new SimpleDateFormat("yyMMddHHmmss").format(new Date()) + "001"); |
|
|
|
@ -134,9 +138,9 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
history1.setOutboundReason("其它出库测试"); |
|
|
|
history1.setOutboundDate(new Date()); |
|
|
|
history1.setSite(site); |
|
|
|
|
|
|
|
|
|
|
|
historyList.add(history1); |
|
|
|
|
|
|
|
|
|
|
|
return historyList; |
|
|
|
} catch (Exception e) { |
|
|
|
throw new XJException("查询其它出库历史失败: " + e.getMessage()); |
|
|
|
@ -148,17 +152,17 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
*/ |
|
|
|
private List<HandlingUnit> validateHandlingUnits(OtherOutboundRequestDto dto) { |
|
|
|
List<HandlingUnit> handlingUnits = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
for (String unitId : dto.getHandlingUnitIds()) { |
|
|
|
HandlingUnit hu = handlingUnitService.lambdaQuery() |
|
|
|
.eq(HandlingUnit::getUnitId, unitId) |
|
|
|
.eq(HandlingUnit::getSite, dto.getSite()) |
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
if (hu == null) { |
|
|
|
throw new XJException("HandlingUnit不存在: " + unitId); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查HandlingUnit状态 |
|
|
|
// if (!"AVAILABLE".equals(hu.getStatus()) && !"A".equals(hu.getStatusDb())) { |
|
|
|
// throw new XJException("HandlingUnit状态不可用: " + unitId); |
|
|
|
@ -168,10 +172,10 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
if (!"Y".equals(hu.getInStockFlag())) { |
|
|
|
throw new XJException("HandlingUnit不在库,无法出库: " + unitId); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handlingUnits.add(hu); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return handlingUnits; |
|
|
|
} |
|
|
|
|
|
|
|
@ -195,7 +199,7 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
|
|
|
|
// 检查库存数量是否足够 |
|
|
|
if (stock.getQtyOnHand().compareTo(hu.getQty()) < 0) { |
|
|
|
throw new XJException("库存不足,无法出库: " + hu.getPartNo() + |
|
|
|
throw new XJException("库存不足,无法出库: " + hu.getPartNo() + |
|
|
|
" 当前库存:" + stock.getQtyOnHand() + " 需要出库:" + hu.getQty()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -209,10 +213,10 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
transRequest.setSite(dto.getSite()); |
|
|
|
transRequest.setTransType("OO"); // 其它出库类型 |
|
|
|
transRequest.setStatus("C"); // 完成状态 |
|
|
|
|
|
|
|
|
|
|
|
// 备注信息 出库原因 |
|
|
|
transRequest.setRemark(dto.getOutboundReason()); |
|
|
|
|
|
|
|
|
|
|
|
return transRequest; |
|
|
|
} |
|
|
|
|
|
|
|
@ -221,7 +225,7 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
*/ |
|
|
|
private List<OtherOutboundTransSubDto> buildOtherOutboundSubList(List<HandlingUnit> handlingUnits) { |
|
|
|
List<OtherOutboundTransSubDto> subList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
for (HandlingUnit hu : handlingUnits) { |
|
|
|
OtherOutboundTransSubDto subDto = new OtherOutboundTransSubDto(); |
|
|
|
subDto.setPartNo(hu.getPartNo()); |
|
|
|
@ -232,10 +236,10 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
subDto.setTransQty(hu.getQty().toString()); |
|
|
|
subDto.setDirection("-"); // 出库方向 |
|
|
|
subDto.setWdrNo("*"); |
|
|
|
|
|
|
|
|
|
|
|
subList.add(subDto); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return subList; |
|
|
|
} |
|
|
|
|
|
|
|
@ -272,7 +276,7 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
|
|
|
|
List<TransDetail> detailList = new ArrayList<>(); |
|
|
|
List<TransDetailSub> detailSubs = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
//保存sub |
|
|
|
for (OtherOutboundTransSubDto subDto : dto.getSubList()){ |
|
|
|
TransDetailSub detailSub = new TransDetailSub(); |
|
|
|
@ -293,7 +297,7 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
.eq(HandlingUnit::getSite, dto.getSite()) |
|
|
|
.eq(HandlingUnit::getUnitId, subDto.getSubNo()) |
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
if (handlingUnit != null) { |
|
|
|
if("OUT".equals(fangxiang)){ |
|
|
|
handlingUnit.setInStockFlag("N"); |
|
|
|
@ -309,18 +313,18 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
|
|
|
|
detailSubs.add(detailSub); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//总计sub数量添加到list |
|
|
|
Map<List<String>, Double> collect = detailSubs.stream().collect( |
|
|
|
Collectors.groupingBy(item -> Arrays.asList( |
|
|
|
item.getSite(), |
|
|
|
item.getPartNo(), |
|
|
|
item.getBatchNo(), |
|
|
|
item.getLocationId(), |
|
|
|
item.getSite(), |
|
|
|
item.getPartNo(), |
|
|
|
item.getBatchNo(), |
|
|
|
item.getLocationId(), |
|
|
|
item.getOrderRef3(), |
|
|
|
item.getOrderRef4() |
|
|
|
), Collectors.summingDouble(TransDetailSub::getSubQty))); |
|
|
|
|
|
|
|
|
|
|
|
Double index = 1.0; |
|
|
|
for (Map.Entry<List<String>, Double> entry : collect.entrySet()) { |
|
|
|
List<String> key = entry.getKey(); |
|
|
|
@ -381,7 +385,7 @@ public class OtherOutboundServiceImpl implements OtherOutboundService { |
|
|
|
hu.setInStockFlag("N"); // 设置为不在库状态 |
|
|
|
hu.setStatus("ISSUED"); // 设置为已出库状态 |
|
|
|
hu.setStatusDb("I"); // 设置为已出库状态DB |
|
|
|
|
|
|
|
|
|
|
|
handlingUnitService.updateById(hu); |
|
|
|
} |
|
|
|
} |
|
|
|
|