|
|
|
@ -11,6 +11,7 @@ import com.gaotao.modules.mr.entity.MrIssue; |
|
|
|
import com.gaotao.modules.mr.entity.dto.*; |
|
|
|
import com.gaotao.modules.mr.mapper.MrIssueMapper; |
|
|
|
import com.gaotao.modules.mr.service.MrService; |
|
|
|
import com.gaotao.modules.outsourcing.dao.OutsourcingIssueMapper; |
|
|
|
import com.gaotao.modules.outsourcing.entity.dto.MrIssueMaterialDto; |
|
|
|
import com.gaotao.modules.production.entity.ProductionIssue; |
|
|
|
import com.gaotao.modules.production.entity.dto.MaterialLabelInfo; |
|
|
|
@ -20,6 +21,7 @@ import com.gaotao.modules.trans.entity.TransCommonSubDto; |
|
|
|
import com.gaotao.modules.trans.entity.TransDetail; |
|
|
|
import com.gaotao.modules.trans.entity.TransDetailDto; |
|
|
|
import com.gaotao.modules.trans.service.TransHeaderService; |
|
|
|
import com.gaotao.modules.trans.service.ValidateInventoryPartInStockService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
@ -27,6 +29,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@ -44,13 +47,17 @@ public class MrServiceImpl implements MrService { |
|
|
|
private TransHeaderService transHeaderService; |
|
|
|
@Autowired |
|
|
|
private IfsApiIssueAndReturnService ifsApiIssueAndReturnService; |
|
|
|
@Autowired |
|
|
|
private ValidateInventoryPartInStockService validateInventoryPartInStockService; |
|
|
|
@Autowired |
|
|
|
private OutsourcingIssueMapper outsourcingIssueMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<MaterialRequisitionVo> getMrList(MrDto mrDto) { |
|
|
|
List<MaterialRequisitionVo> materialRequisition = ifsApiIssueAndReturnService.getMaterialRequisition(mrDto.getOrderNo(), mrDto.getSite()); |
|
|
|
Set<String> allowedStatuses = new HashSet<>(Arrays.asList("Released", "Reserved", "Started")); |
|
|
|
List<MaterialRequisitionVo> collect = materialRequisition.stream().filter(item -> allowedStatuses.contains(item.getStatusCode())).collect(Collectors.toList()); |
|
|
|
return collect; |
|
|
|
/*Set<String> allowedStatuses = new HashSet<>(Arrays.asList("Released", "Reserved", "Started")); |
|
|
|
List<MaterialRequisitionVo> collect = materialRequisition.stream().filter(item -> allowedStatuses.contains(item.getStatusCode())).collect(Collectors.toList());*/ |
|
|
|
return materialRequisition; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -80,12 +87,19 @@ public class MrServiceImpl implements MrService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void confirmMrIssue(MrIssueDto mrIssueDto) throws Exception{ |
|
|
|
public List<String> confirmMrIssue(MrIssueDto mrIssueDto) throws Exception{ |
|
|
|
// 验证MR状态 |
|
|
|
if (!validateMrStatus(mrIssueDto.getOrderNo(), mrIssueDto.getSite())) { |
|
|
|
throw new XJException("MR状态不允许发料"); |
|
|
|
} |
|
|
|
|
|
|
|
if(mrIssueDto.getSelectedMaterials() != null && mrIssueDto.getSelectedMaterials().size()>0){ |
|
|
|
boolean b = validateHandingUnitQty(mrIssueDto.getSelectedMaterials()); |
|
|
|
if(b){ |
|
|
|
throw new Exception("输入数量大于数据库标签数量,不允许发料"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 解析物料标签 |
|
|
|
List<TransCommonSubDto> subList = new ArrayList<>(); |
|
|
|
|
|
|
|
@ -129,9 +143,61 @@ public class MrServiceImpl implements MrService { |
|
|
|
subList.add(subDto); |
|
|
|
seqNo++; |
|
|
|
} |
|
|
|
String s1 = validateInventoryPartInStockService.validateInventoryPartInStock(mrIssueDto.getPartNo(), mrIssueDto.getSite(), subList); |
|
|
|
if(!"200".equals(s1)){ |
|
|
|
throw new XJException("物料"+mrIssueDto.getPartNo()+"已被预留或库存不足,无法发料"); |
|
|
|
} |
|
|
|
transCommonRequestDto.setSubList(subList); |
|
|
|
List<TransDetail> out = transHeaderService.genTransAndChangeInventoryStock(transCommonRequestDto, "OUT"); |
|
|
|
|
|
|
|
|
|
|
|
List<String> ids = new ArrayList<>(); |
|
|
|
|
|
|
|
//跟新HandlingUnit的长度和数量 |
|
|
|
BigDecimal issueQty = BigDecimal.ZERO; |
|
|
|
List<HandlingUnit> handlingUnits = new ArrayList<>(); |
|
|
|
Set<String> unitIds = mrIssueDto.getSelectedMaterials().stream() |
|
|
|
.map(MrIssueMaterialDto::getLabelCode) |
|
|
|
.filter(Objects::nonNull) |
|
|
|
.collect(Collectors.toSet()); |
|
|
|
if (unitIds.isEmpty()) { |
|
|
|
throw new IllegalArgumentException("列表中标签号均为空,无法查询数据库"); |
|
|
|
} |
|
|
|
List<HandlingUnit> huList = outsourcingIssueMapper.selectByUnitIds(unitIds); |
|
|
|
|
|
|
|
Map<String, HandlingUnit> huMap = huList.stream() |
|
|
|
.collect(Collectors.toMap(HandlingUnit::getUnitId, hu -> hu, (existing, replacement) -> existing)); |
|
|
|
|
|
|
|
for (MrIssueMaterialDto material : mrIssueDto.getSelectedMaterials()) { |
|
|
|
HandlingUnit hu = new HandlingUnit(); |
|
|
|
hu.setUnitId(material.getLabelCode()); |
|
|
|
hu.setHeight(material.getHeight() == null ? BigDecimal.ZERO : material.getHeight()); |
|
|
|
|
|
|
|
String unitId = material.getLabelCode(); |
|
|
|
if (unitId != null && huMap.containsKey(unitId)) { |
|
|
|
//减去要出的hu上的数量 |
|
|
|
HandlingUnit unit = huMap.get(unitId); |
|
|
|
BigDecimal qty = unit.getQty(); |
|
|
|
BigDecimal materialIssueQty = material.getIssueQty(); |
|
|
|
if (qty != null && materialIssueQty != null) { |
|
|
|
BigDecimal nowQty = qty.subtract(materialIssueQty).setScale(6, RoundingMode.HALF_UP); |
|
|
|
hu.setQty(nowQty); |
|
|
|
} |
|
|
|
} |
|
|
|
if(BigDecimal.ZERO.compareTo(hu.getQty()) !=0){ |
|
|
|
hu.setInStockFlag("Y"); |
|
|
|
}else{ |
|
|
|
hu.setInStockFlag("N"); |
|
|
|
} |
|
|
|
handlingUnits.add(hu); |
|
|
|
if (material.getIssueQty() != null) { |
|
|
|
issueQty = issueQty.add(material.getIssueQty()); |
|
|
|
} |
|
|
|
if(BigDecimal.ZERO.compareTo(hu.getQty()) != 0){ |
|
|
|
ids.add(hu.getUnitId()); |
|
|
|
} |
|
|
|
} |
|
|
|
outsourcingIssueMapper.updateHandingUnit(handlingUnits); |
|
|
|
//返回出库中间表 |
|
|
|
for (TransDetail issue : out){ |
|
|
|
MaterialRequisitionIssueDto materialRequisitionIssueDto = new MaterialRequisitionIssueDto(); |
|
|
|
@ -150,9 +216,9 @@ public class MrServiceImpl implements MrService { |
|
|
|
materialRequisitionIssueDto.setIfsHandlingUntitID(BigDecimal.ZERO); |
|
|
|
materialRequisitionIssueDto.setIfsQuantity(issue.getTransQty()); |
|
|
|
String s = ifsApiIssueAndReturnService.addMaterialRequisitionReserve(materialRequisitionIssueDto); |
|
|
|
String s1 = ifsApiIssueAndReturnService.addMaterialRequisitionIssue(materialRequisitionIssueDto); |
|
|
|
String s2 = ifsApiIssueAndReturnService.addMaterialRequisitionIssue(materialRequisitionIssueDto); |
|
|
|
} |
|
|
|
|
|
|
|
return ids; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -341,4 +407,39 @@ public class MrServiceImpl implements MrService { |
|
|
|
private List<MrMaterialLineDto> getMockMaterialLines(String orderNo) { |
|
|
|
return getMockMrList(new MrDto()); // 复用模拟数据 |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional |
|
|
|
public boolean validateHandingUnitQty(List<MrIssueMaterialDto> selectedMaterials)throws Exception{ |
|
|
|
Set<String> unitIds = selectedMaterials.stream() |
|
|
|
.map(MrIssueMaterialDto::getLabelCode) |
|
|
|
.filter(Objects::nonNull) |
|
|
|
.collect(Collectors.toSet()); |
|
|
|
if (unitIds.isEmpty()) { |
|
|
|
throw new IllegalArgumentException("列表中标签号均为空,无法查询数据库"); |
|
|
|
} |
|
|
|
List<HandlingUnit> huList = mrIssueMapper.selectByUnitIds(unitIds); |
|
|
|
|
|
|
|
// 创建Map以便快速查找HandlingUnit |
|
|
|
Map<String, HandlingUnit> huMap = huList.stream() |
|
|
|
.collect(Collectors.toMap(HandlingUnit::getUnitId, hu -> hu, (existing, replacement) -> existing)); |
|
|
|
|
|
|
|
// 遍历selectedMaterials,比较issueQty和qty |
|
|
|
int index = 1; |
|
|
|
for (MrIssueMaterialDto material : selectedMaterials) { |
|
|
|
String unitId = material.getLabelCode(); |
|
|
|
if (unitId != null && huMap.containsKey(unitId)) { |
|
|
|
HandlingUnit hu = huMap.get(unitId); |
|
|
|
BigDecimal issueQty = material.getIssueQty(); |
|
|
|
BigDecimal qty = hu.getQty(); |
|
|
|
|
|
|
|
// 如果issueQty大于qty,返回true |
|
|
|
if (issueQty != null && qty != null && issueQty.compareTo(qty) > 0) { |
|
|
|
throw new Exception(String.format("第%s行输入数量大于数据库标签数量,不允许发料", index)); |
|
|
|
} |
|
|
|
} |
|
|
|
index++; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |