diff --git a/src/main/java/com/gaotao/modules/mr/controller/MrController.java b/src/main/java/com/gaotao/modules/mr/controller/MrController.java index f2986deb..ba25c42a 100644 --- a/src/main/java/com/gaotao/modules/mr/controller/MrController.java +++ b/src/main/java/com/gaotao/modules/mr/controller/MrController.java @@ -79,8 +79,12 @@ public class MrController extends AbstractController { */ @PostMapping("confirmMrIssue") public R confirmMrIssue(@RequestBody MrIssueDto mrIssueDto) throws Exception{ - mrService.confirmMrIssue(mrIssueDto); - return R.ok(); + try{ + List ids = mrService.confirmMrIssue(mrIssueDto); + return R.ok().put("unitIds",ids); + } catch (Exception e) { + return R.error(e.getMessage()); + } } @PostMapping("getReturnMrInfo") public R getReturnMrInfo(@RequestBody MrDto mrDto){ diff --git a/src/main/java/com/gaotao/modules/mr/mapper/MrIssueMapper.java b/src/main/java/com/gaotao/modules/mr/mapper/MrIssueMapper.java index fff2e050..da69d011 100644 --- a/src/main/java/com/gaotao/modules/mr/mapper/MrIssueMapper.java +++ b/src/main/java/com/gaotao/modules/mr/mapper/MrIssueMapper.java @@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; +import java.util.Set; /** * MR发料记录Mapper @@ -25,4 +26,6 @@ public interface MrIssueMapper extends BaseMapper { HandlingUnit scanMaterialLabelNotInStock(@Param("site") String site,@Param("labelCode")String labelCode,@Param("partNo")String partNo); void updateHandingUnit(List list); + + List selectByUnitIds(@Param("unitIds") Set unitIds); } diff --git a/src/main/java/com/gaotao/modules/mr/service/MrService.java b/src/main/java/com/gaotao/modules/mr/service/MrService.java index 3c7d85e7..5e12ce12 100644 --- a/src/main/java/com/gaotao/modules/mr/service/MrService.java +++ b/src/main/java/com/gaotao/modules/mr/service/MrService.java @@ -46,7 +46,7 @@ public interface MrService { * 确认MR发料 * @param mrIssueDto MR发料信息 */ - void confirmMrIssue(MrIssueDto mrIssueDto)throws Exception; + List confirmMrIssue(MrIssueDto mrIssueDto)throws Exception; List getReturnMrInfo(MrDto mrDto); diff --git a/src/main/java/com/gaotao/modules/mr/service/impl/MrServiceImpl.java b/src/main/java/com/gaotao/modules/mr/service/impl/MrServiceImpl.java index 5817fcec..99b39e87 100644 --- a/src/main/java/com/gaotao/modules/mr/service/impl/MrServiceImpl.java +++ b/src/main/java/com/gaotao/modules/mr/service/impl/MrServiceImpl.java @@ -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 getMrList(MrDto mrDto) { List materialRequisition = ifsApiIssueAndReturnService.getMaterialRequisition(mrDto.getOrderNo(), mrDto.getSite()); - Set allowedStatuses = new HashSet<>(Arrays.asList("Released", "Reserved", "Started")); - List collect = materialRequisition.stream().filter(item -> allowedStatuses.contains(item.getStatusCode())).collect(Collectors.toList()); - return collect; + /*Set allowedStatuses = new HashSet<>(Arrays.asList("Released", "Reserved", "Started")); + List 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 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 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 out = transHeaderService.genTransAndChangeInventoryStock(transCommonRequestDto, "OUT"); + + List ids = new ArrayList<>(); + + //跟新HandlingUnit的长度和数量 + BigDecimal issueQty = BigDecimal.ZERO; + List handlingUnits = new ArrayList<>(); + Set unitIds = mrIssueDto.getSelectedMaterials().stream() + .map(MrIssueMaterialDto::getLabelCode) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + if (unitIds.isEmpty()) { + throw new IllegalArgumentException("列表中标签号均为空,无法查询数据库"); + } + List huList = outsourcingIssueMapper.selectByUnitIds(unitIds); + + Map 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 getMockMaterialLines(String orderNo) { return getMockMrList(new MrDto()); // 复用模拟数据 } + + @Transactional + public boolean validateHandingUnitQty(List selectedMaterials)throws Exception{ + Set unitIds = selectedMaterials.stream() + .map(MrIssueMaterialDto::getLabelCode) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + if (unitIds.isEmpty()) { + throw new IllegalArgumentException("列表中标签号均为空,无法查询数据库"); + } + List huList = mrIssueMapper.selectByUnitIds(unitIds); + + // 创建Map以便快速查找HandlingUnit + Map 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; + } } diff --git a/src/main/resources/mapper/mr/MrIssueMapper.xml b/src/main/resources/mapper/mr/MrIssueMapper.xml index 036be614..399a2169 100644 --- a/src/main/resources/mapper/mr/MrIssueMapper.xml +++ b/src/main/resources/mapper/mr/MrIssueMapper.xml @@ -74,4 +74,14 @@ WHERE unit_id = #{hu.unitId} +