|
@ -1,7 +1,7 @@ |
|
|
package com.ruoyi.warehouse.service.impl; |
|
|
package com.ruoyi.warehouse.service.impl; |
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
import com.ruoyi.common.exception.BusinessException; |
|
|
import com.ruoyi.common.exception.BusinessException; |
|
@ -17,6 +17,7 @@ import com.ruoyi.system.mapper.SysMakeorderPickDetailMapper; |
|
|
import com.ruoyi.system.mapper.SysMakeorderPickMapper; |
|
|
import com.ruoyi.system.mapper.SysMakeorderPickMapper; |
|
|
import com.ruoyi.system.mapper.SysSalesOrderMapper; |
|
|
import com.ruoyi.system.mapper.SysSalesOrderMapper; |
|
|
import com.ruoyi.warehouse.domain.WarehouseOutOrderDetail; |
|
|
import com.ruoyi.warehouse.domain.WarehouseOutOrderDetail; |
|
|
|
|
|
import com.ruoyi.warehouse.domain.WarehouseStorageOrderDetail; |
|
|
import com.ruoyi.warehouse.mapper.WarehouseOutOrderDetailMapper; |
|
|
import com.ruoyi.warehouse.mapper.WarehouseOutOrderDetailMapper; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
@ -260,13 +261,41 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService |
|
|
warehouseOutOrder.setMakeNo(tempSysMakeorderPickVo.getMakeNo()); |
|
|
warehouseOutOrder.setMakeNo(tempSysMakeorderPickVo.getMakeNo()); |
|
|
//标明来源是生产订单
|
|
|
//标明来源是生产订单
|
|
|
warehouseOutOrder.setWarehouseOrderType("1"); |
|
|
warehouseOutOrder.setWarehouseOrderType("1"); |
|
|
|
|
|
//标明是生产领料
|
|
|
warehouseOutOrder.setWarehouseOutType("1"); |
|
|
warehouseOutOrder.setWarehouseOutType("1"); |
|
|
warehouseOutOrder.setMaterialSum(tempSysMakeorderPickVo.getMaterialSum()); |
|
|
warehouseOutOrder.setBusinessName(ShiroUtils.getLoginName()); |
|
|
warehouseOutOrder.setEnterpriseSum(tempSysMakeorderPickVo.getEnterpriseSum()); |
|
|
warehouseOutOrder.setCreateBy(ShiroUtils.getLoginName()); |
|
|
|
|
|
|
|
|
warehouseOutOrder.setCreateBy(sysMakeorderPickVo.getApplyUser()); |
|
|
|
|
|
warehouseOutOrder.setCreateTime(new Date()); |
|
|
warehouseOutOrder.setCreateTime(new Date()); |
|
|
warehouseOutOrder.setApplyName(sysMakeorderPickVo.getApplyUser()); |
|
|
warehouseOutOrder.setApplyName(sysMakeorderPickVo.getApplyUser()); |
|
|
|
|
|
List<SysMakeorderPickDetail> sysMakeorderPickDetails = getSysMakeorderPickDetails(sysMakeorderPickVo); |
|
|
|
|
|
//对物料相同的数据进行合并操作,并合计领料数
|
|
|
|
|
|
List<SysMakeorderPickDetail> mergeMakeorderPickDetails = mergeMakeorderPickDetails(sysMakeorderPickDetails); |
|
|
|
|
|
|
|
|
|
|
|
//物料合计
|
|
|
|
|
|
Integer materialSum = 0; |
|
|
|
|
|
|
|
|
|
|
|
//数量合计
|
|
|
|
|
|
Integer enterpriseSum = 0; |
|
|
|
|
|
|
|
|
|
|
|
materialSum = mergeMakeorderPickDetails.size(); |
|
|
|
|
|
|
|
|
|
|
|
// 检查storageNum是否含有null值
|
|
|
|
|
|
boolean hasThisStorageNumNull = mergeMakeorderPickDetails.stream() |
|
|
|
|
|
.anyMatch(item -> item.getPickNum() == null); |
|
|
|
|
|
|
|
|
|
|
|
if (hasThisStorageNumNull) { |
|
|
|
|
|
throw new BusinessException("存在入库数为空,请检查!"); |
|
|
|
|
|
} |
|
|
|
|
|
// 计算各个字段的总和
|
|
|
|
|
|
long enterpriseSumLong = mergeMakeorderPickDetails.stream() |
|
|
|
|
|
.mapToLong(SysMakeorderPickDetail::getPickNum) |
|
|
|
|
|
.sum(); |
|
|
|
|
|
|
|
|
|
|
|
// 确保转换前不会造成数据溢出
|
|
|
|
|
|
enterpriseSum = (int)enterpriseSumLong; |
|
|
|
|
|
|
|
|
|
|
|
warehouseOutOrder.setMaterialSum(materialSum); |
|
|
|
|
|
warehouseOutOrder.setEnterpriseSum(enterpriseSum); |
|
|
//生成出库单数据
|
|
|
//生成出库单数据
|
|
|
int insertResult = warehouseOutOrderMapper.insertWarehouseOutOrder(warehouseOutOrder); |
|
|
int insertResult = warehouseOutOrderMapper.insertWarehouseOutOrder(warehouseOutOrder); |
|
|
if (insertResult <= 0){ |
|
|
if (insertResult <= 0){ |
|
@ -274,18 +303,41 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService |
|
|
throw new BusinessException("添加出库单信息失败"); |
|
|
throw new BusinessException("添加出库单信息失败"); |
|
|
} |
|
|
} |
|
|
//生成出库单详情相关信息
|
|
|
//生成出库单详情相关信息
|
|
|
generateWarehouseOutOrder(sysMakeorderPickVo, tempSysMakeorderPickVo, outOrderCode); |
|
|
generateWarehouseOutOrder(sysMakeorderPickVo, tempSysMakeorderPickVo, outOrderCode,mergeMakeorderPickDetails); |
|
|
return insertResult; |
|
|
return insertResult; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* 对物料相同的数据进行合并操作,并合计领料数 |
|
|
|
|
|
* */ |
|
|
|
|
|
public List<SysMakeorderPickDetail> mergeMakeorderPickDetails(List<SysMakeorderPickDetail> sysMakeorderPickDetails) { |
|
|
|
|
|
Map<String, Long> materialMap = new HashMap<>(); |
|
|
|
|
|
for (SysMakeorderPickDetail detail : sysMakeorderPickDetails) { |
|
|
|
|
|
String materialNo = detail.getMaterialNo(); |
|
|
|
|
|
Long pickNum = detail.getPickNum(); |
|
|
|
|
|
if (materialMap.containsKey(materialNo)) { |
|
|
|
|
|
materialMap.put(materialNo, materialMap.get(materialNo) + pickNum); |
|
|
|
|
|
} else { |
|
|
|
|
|
materialMap.put(materialNo, pickNum); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<SysMakeorderPickDetail> mergedDetails = new ArrayList<>(); |
|
|
|
|
|
for (Map.Entry<String, Long> entry : materialMap.entrySet()) { |
|
|
|
|
|
SysMakeorderPickDetail mergedDetail = new SysMakeorderPickDetail(); |
|
|
|
|
|
mergedDetail.setMaterialNo(entry.getKey()); |
|
|
|
|
|
mergedDetail.setPickNum(entry.getValue()); |
|
|
|
|
|
mergedDetails.add(mergedDetail); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return mergedDetails; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成出库单详情相关信息
|
|
|
//生成出库单详情相关信息
|
|
|
private void generateWarehouseOutOrder(SysMakeorderPickVo sysMakeorderPickVo, SysMakeorderPickVo tempSysMakeorderPickVo, String outOrderCode) { |
|
|
private void generateWarehouseOutOrder(SysMakeorderPickVo sysMakeorderPickVo, SysMakeorderPickVo tempSysMakeorderPickVo, String outOrderCode,List<SysMakeorderPickDetail> mergeMakeorderPickDetails) { |
|
|
SysMakeorderPickDetail tempMakeorderPickDetail = new SysMakeorderPickDetail(); |
|
|
|
|
|
tempMakeorderPickDetail.setPickNo(tempSysMakeorderPickVo.getPickNo()); |
|
|
for (SysMakeorderPickDetail sysMakeorderPickDetail : mergeMakeorderPickDetails) { |
|
|
tempMakeorderPickDetail.setMakeNo(tempSysMakeorderPickVo.getMakeNo()); |
|
|
|
|
|
//查询生产物料领料单详情
|
|
|
|
|
|
List<SysMakeorderPickDetail> sysMakeorderPickDetails = makeorderPickDetailMapper.selectSysMakeorderPickDetailByNo(tempMakeorderPickDetail); |
|
|
|
|
|
for (SysMakeorderPickDetail sysMakeorderPickDetail : sysMakeorderPickDetails) { |
|
|
|
|
|
WarehouseOutOrderDetail warehouseOutOrderDetail = new WarehouseOutOrderDetail(); |
|
|
WarehouseOutOrderDetail warehouseOutOrderDetail = new WarehouseOutOrderDetail(); |
|
|
warehouseOutOrderDetail.setOutOrderCode(outOrderCode); |
|
|
warehouseOutOrderDetail.setOutOrderCode(outOrderCode); |
|
|
warehouseOutOrderDetail.setWarehouseOutStatus("4"); |
|
|
warehouseOutOrderDetail.setWarehouseOutStatus("4"); |
|
@ -297,7 +349,7 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService |
|
|
warehouseOutOrderDetail.setMaterialSum(tempSysMakeorderPickVo.getMaterialSum()); |
|
|
warehouseOutOrderDetail.setMaterialSum(tempSysMakeorderPickVo.getMaterialSum()); |
|
|
warehouseOutOrderDetail.setEnterpriseSum(tempSysMakeorderPickVo.getEnterpriseSum()); |
|
|
warehouseOutOrderDetail.setEnterpriseSum(tempSysMakeorderPickVo.getEnterpriseSum()); |
|
|
|
|
|
|
|
|
warehouseOutOrderDetail.setCreateBy(sysMakeorderPickVo.getApplyUser()); |
|
|
warehouseOutOrderDetail.setCreateBy(ShiroUtils.getLoginName()); |
|
|
warehouseOutOrderDetail.setCreateTime(new Date()); |
|
|
warehouseOutOrderDetail.setCreateTime(new Date()); |
|
|
warehouseOutOrderDetail.setApplyName(sysMakeorderPickVo.getApplyUser()); |
|
|
warehouseOutOrderDetail.setApplyName(sysMakeorderPickVo.getApplyUser()); |
|
|
//物料相关信息
|
|
|
//物料相关信息
|
|
@ -308,13 +360,33 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService |
|
|
warehouseOutOrderDetail.setMaterialBrand(sysMakeorderPickDetail.getBrand()); |
|
|
warehouseOutOrderDetail.setMaterialBrand(sysMakeorderPickDetail.getBrand()); |
|
|
warehouseOutOrderDetail.setMaterialProcessMethod(sysMakeorderPickDetail.getProcessMethod()); |
|
|
warehouseOutOrderDetail.setMaterialProcessMethod(sysMakeorderPickDetail.getProcessMethod()); |
|
|
warehouseOutOrderDetail.setMakeNum(tempSysMakeorderPickVo.getMaterialSum()); |
|
|
warehouseOutOrderDetail.setMakeNum(tempSysMakeorderPickVo.getMaterialSum()); |
|
|
|
|
|
//添加申请出库数量
|
|
|
|
|
|
warehouseOutOrderDetail.setApplyOutOrderSum(Math.toIntExact(sysMakeorderPickDetail.getPickNum())); |
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(sysMakeorderPickDetail.getDescribe())) { |
|
|
if (StringUtils.isNotEmpty(sysMakeorderPickDetail.getDescribe())) { |
|
|
String[] splitDescribe = sysMakeorderPickDetail.getDescribe().split(","); |
|
|
String[] splitDescribe = sysMakeorderPickDetail.getDescribe().split(","); |
|
|
|
|
|
if (splitDescribe.length >= 2) { |
|
|
warehouseOutOrderDetail.setMaterialModel(splitDescribe[0]); |
|
|
warehouseOutOrderDetail.setMaterialModel(splitDescribe[0]); |
|
|
warehouseOutOrderDetail.setMaterialSpecification(splitDescribe[1]); |
|
|
warehouseOutOrderDetail.setMaterialSpecification(splitDescribe[1]); |
|
|
} |
|
|
} |
|
|
outOrderDetailMapper.insertWarehouseOutOrderDetail(warehouseOutOrderDetail); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
int insertOutOrderDetailResult = outOrderDetailMapper.insertWarehouseOutOrderDetail(warehouseOutOrderDetail); |
|
|
|
|
|
if (insertOutOrderDetailResult <= 0){ |
|
|
|
|
|
throw new BusinessException("新增出库单详情数据失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<SysMakeorderPickDetail> getSysMakeorderPickDetails(SysMakeorderPickVo tempSysMakeorderPickVo) { |
|
|
|
|
|
SysMakeorderPickDetail tempMakeorderPickDetail = new SysMakeorderPickDetail(); |
|
|
|
|
|
tempMakeorderPickDetail.setPickNo(tempSysMakeorderPickVo.getPickNo()); |
|
|
|
|
|
tempMakeorderPickDetail.setMakeNo(tempSysMakeorderPickVo.getMakeNo()); |
|
|
|
|
|
|
|
|
|
|
|
//查询生产物料领料单详情
|
|
|
|
|
|
List<SysMakeorderPickDetail> sysMakeorderPickDetails = makeorderPickDetailMapper.selectSysMakeorderPickDetailByNo(tempMakeorderPickDetail); |
|
|
|
|
|
//保留领料单数不为空的数据
|
|
|
|
|
|
List<SysMakeorderPickDetail> filterPickDetails = sysMakeorderPickDetails.stream().filter(details -> details.getPickNum() != null).collect(Collectors.toList()); |
|
|
|
|
|
return filterPickDetails; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|