add:增加需求单自动分配

This commit is contained in:
zhangzq
2026-08-04 18:45:25 +08:00
parent defa77dfd6
commit 68395f18a0
7 changed files with 132 additions and 16 deletions

View File

@@ -94,4 +94,12 @@ public class PmDemandController {
pmDemandService.issueReturnBill(ids);
return ResponseData.build();
}
@PostMapping("/autoAllcation")
@Log("自动分配需求单")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<Object> autoAllcation(@RequestBody Set<String> ids) {
pmDemandService.autoAllcation(ids);
return ResponseData.build();
}
}

View File

@@ -54,4 +54,5 @@ public interface IPmDemandService extends IService<PmDemand> {
*/
void pushDemand(List<PmDemandDto> pmDemandDto);
void issueReturnBill(Set<String> ids);
void autoAllcation(Set<String> ids);
}

View File

@@ -55,6 +55,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -216,6 +217,12 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
demandDto.setHouseName(dto.getStorName());
resultList.add(demandDto);
}
}else {
DemandInventryDto demandDto = new DemandInventryDto();
demandDto.setSkuCode(skuCode);
demandDto.setQty(BigDecimal.ZERO);
demandDto.setHouseCode("6.011");
demandDto.setHouseName("'五期装配原材料平库'");
}
ResponseEntity<List<ZDInventory>> responseEntity = wmsToZDWmdService.queryInventory(skuCode);
List<ZDInventory> zdInventorys = responseEntity.getBody();
@@ -234,6 +241,14 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
demandDto.setHouseName("五期原材料立库6.002");
resultList.add(demandDto);
}
}else {
DemandInventryDto demandDto = new DemandInventryDto();
demandDto.setSkuCode(skuCode);
demandDto.setSkuName(null);
demandDto.setQty(BigDecimal.ZERO);
demandDto.setHouseCode("6.002");
demandDto.setHouseName("五期原材料立库6.002");
resultList.add(demandDto);
}
return resultList;
}
@@ -420,4 +435,31 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
.set(PmDemand::getStatus,DemandStatus.FINISH.getValue())
.in(PmDemand::getId,ids));
}
@Override
public void autoAllcation(Set<String> ids) {
final List<PmDemand> pmDemands = this.listByIds(ids);
final List<PmDemand> needAllcation = new ArrayList<>();
for (PmDemand pmDemand : pmDemands) {
if (pmDemand.getStatus().equals(DemandStatus.CREATE.getValue())){
throw new BadRequestException("当前单子不是生成状态无法勾选");
}
final List<DemandInventryDto> demandInventryDtos = this.queryInventory(pmDemand.getSku_code());
final Map<String, DemandInventryDto> inventryDtoMap = demandInventryDtos.stream().collect(Collectors.toMap(DemandInventryDto::getHouseCode, Function.identity()));
final DemandInventryDto demandInventryDto = inventryDtoMap.get("6.002");
final DemandInventryDto pInventryDto = inventryDtoMap.get("6.011");
if (demandInventryDto !=null && demandInventryDto.getQty()!=null && demandInventryDto.getQty().compareTo(pmDemand.getQty())>=0){
pmDemand.setInventory_dis("6.002");
pmDemand.setStatus(DemandStatus.DIS.getValue());
needAllcation.add(pmDemand);
}else if (pInventryDto !=null && pInventryDto.getQty()!=null && pInventryDto.getQty().compareTo(pmDemand.getQty())>=0){
pmDemand.setInventory_dis("6.011");
pmDemand.setStatus(DemandStatus.DIS.getValue());
}else {
pmDemand.setInventory_dis("库存不足请手动分配");
}
needAllcation.add(pmDemand);
}
this.updateBatchById(needAllcation);
}
}