diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysMakeorderBom.java b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysMakeorderBom.java index f1c56077..435f932d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysMakeorderBom.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysMakeorderBom.java @@ -78,7 +78,7 @@ public class SysMakeorderBom extends BaseEntity /** 损耗率 */ @Excel(name = "损耗率") - private BigDecimal lossRate; + private String lossRate; /** 层级 */ @Excel(name = "层级") @@ -223,16 +223,16 @@ public class SysMakeorderBom extends BaseEntity { return useNum; } - public void setLossRate(BigDecimal lossRate) - { - this.lossRate = lossRate; - } - public BigDecimal getLossRate() - { + public String getLossRate() { return lossRate; } - public void setLevel(Long level) + + public void setLossRate(String lossRate) { + this.lossRate = lossRate; + } + + public void setLevel(Long level) { this.level = level; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysMakeorderPickDetail.java b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysMakeorderPickDetail.java index cb644469..6fafaaf2 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysMakeorderPickDetail.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysMakeorderPickDetail.java @@ -43,6 +43,10 @@ public class SysMakeorderPickDetail extends BaseEntity @Excel(name = "领料数量") private Long pickNum; + /** 已领料数量 */ + @Excel(name = "已领料数量") + private Long hasPickNum; + /** bom号 */ private String bomNo; /** bom的图片地址 */ @@ -132,6 +136,14 @@ public class SysMakeorderPickDetail extends BaseEntity return pickNum; } + public Long getHasPickNum() { + return hasPickNum; + } + + public void setHasPickNum(Long hasPickNum) { + this.hasPickNum = hasPickNum; + } + public String getBomNo() { return bomNo; } @@ -243,6 +255,7 @@ public class SysMakeorderPickDetail extends BaseEntity .append("materialNo", getMaterialNo()) .append("makeorderBomId", getMakeorderBomId()) .append("pickNum", getPickNum()) + .append("hasPickNum", getHasPickNum()) .toString(); } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeorderPickDetailMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeorderPickDetailMapper.java index b234c08f..4a600d76 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeorderPickDetailMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeorderPickDetailMapper.java @@ -80,4 +80,10 @@ public interface SysMakeorderPickDetailMapper * 根据生产单号和领料单号查询 领料单详情信息 * */ List selectSysMakeorderPickDetailByNo(SysMakeorderPickDetail sysMakeorderPickDetail); + + /* + * 根据生产单号和领料单号以及物料号查询领料单详情信息 + * */ + public SysMakeorderPickDetail selectSysMakeorderPickDetailByThreeNo(SysMakeorderPickDetail sysMakeorderPickDetail); + } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java index 89a274a6..edd751f8 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java @@ -30,6 +30,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -271,6 +272,7 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService orderBom.setMakeNo(makeNo); orderBom.setSalesOrderCode(saleNo); orderBom.setSalesOrderMaterialNo(materialCode); + orderBom.setLossRate(subBom.getLossRate()); //如果sys_makeorder_bom数据表里面没有入库部门.这里给他加入 //orderBom.setWarehouseDept(subBom.getWarehouseDept()); sortNo++; @@ -288,6 +290,7 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService orderBom.setMakeNo(makeNo); orderBom.setSalesOrderCode(saleNo); orderBom.setSalesOrderMaterialNo(materialCode); + orderBom.setLossRate(subBom.getLossRate()); sortNo++; orderBom.setSortNo(sortNo); makeorderBomService.insertSysMakeorderBom(orderBom); @@ -347,7 +350,8 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService } sysMakeOrder.setMakeNo(makeNo); - sysMakeOrder.setEceiptNum((long) warehouseStorageOrder.getStorageNum()); + //只有生产入库才能更新生产订单的已入库数 + //sysMakeOrder.setEceiptNum((long) warehouseStorageOrder.getStorageNum()); //更新生产订单的数据 int updateResult = sysMakeOrderMapper.updateByMakeNo(sysMakeOrder); if (updateResult <= 0){ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeorderPickDetailServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeorderPickDetailServiceImpl.java index 2c5c251b..b1feae62 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeorderPickDetailServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeorderPickDetailServiceImpl.java @@ -58,6 +58,28 @@ public class SysMakeorderPickDetailServiceImpl implements ISysMakeorderPickDetai String loginName = ShiroUtils.getLoginName(); sysMakeorderPickDetail.setCreateBy(loginName); sysMakeorderPickDetail.setCreateTime(DateUtils.getNowDate()); + + SysMakeorderPickDetail tempMakeorderPickDetail = sysMakeorderPickDetailMapper.selectSysMakeorderPickDetailByThreeNo(sysMakeorderPickDetail); + if (tempMakeorderPickDetail != null){ + + if (tempMakeorderPickDetail.getHasPickNum() != null ){ + // 如果刚开始 领料详细数据不为空,并且已经有已领料数了,说明也有领料数,再领料,已领料数会累加 本次领料数; + Long hasPickNum = tempMakeorderPickDetail.getHasPickNum() + sysMakeorderPickDetail.getPickNum(); + sysMakeorderPickDetail.setHasPickNum(hasPickNum); + } + + }else { + // 如果刚开始 领料详细数据为空,已领料数等于领料数 + sysMakeorderPickDetail.setHasPickNum(sysMakeorderPickDetail.getPickNum()); + } + + // 缓存sysMakeorderPickDetail的领料数,避免多次调用 下面代码等同于上面的逻辑 +// Long pickNum = sysMakeorderPickDetail.getPickNum(); +// Long hasPickNum = (tempMakeorderPickDetail != null && tempMakeorderPickDetail.getHasPickNum() != null) +// ? tempMakeorderPickDetail.getHasPickNum() + pickNum +// : pickNum; +// sysMakeorderPickDetail.setHasPickNum(hasPickNum); + return sysMakeorderPickDetailMapper.insertSysMakeorderPickDetail(sysMakeorderPickDetail); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeorderPickServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeorderPickServiceImpl.java index 9562dcdb..048b9fd0 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeorderPickServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeorderPickServiceImpl.java @@ -7,6 +7,7 @@ import com.ruoyi.common.core.page.PageDomain; import com.ruoyi.common.core.page.TableSupport; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.StringUtils; @@ -20,6 +21,7 @@ import com.ruoyi.system.mapper.SysUserMapper; import com.ruoyi.system.service.ISysMakeorderPickDetailService; import com.ruoyi.system.service.ISysMakeorderPickService; import com.ruoyi.system.service.ISysRoleService; +import com.ruoyi.warehouse.service.IWarehouseOutOrderService; import org.activiti.engine.TaskService; import org.activiti.engine.impl.persistence.entity.TaskEntityImpl; import org.activiti.engine.runtime.ProcessInstance; @@ -33,6 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** * 生产领料单Service业务层处理 @@ -172,13 +175,23 @@ public class SysMakeorderPickServiceImpl implements ISysMakeorderPickService String billNo = redisCache.generateBillNo("SCLL"); sysMakeorderPick.setPickNo(billNo); int id = sysMakeorderPickMapper.insertSysMakeorderPick(sysMakeorderPick); + //保留领料单数不为空的数据 + List filterPickDetails = pickDetails.stream().filter(details -> details.getPickNum() != null).collect(Collectors.toList()); + // 插入子表 - for (int i = 0; i < pickDetails.size(); i++) { - SysMakeorderPickDetail pickDetail = pickDetails.get(i); + for (int i = 0; i < filterPickDetails.size(); i++) { + //获取过滤后的领料单详情 + SysMakeorderPickDetail pickDetail = filterPickDetails.get(i); pickDetail.setPickNo(billNo); pickDetail.setMakeNo(makeNo); - makeorderPickDetailService.insertSysMakeorderPickDetail(pickDetail); + int insertMakeorderPickDetailResult = makeorderPickDetailService.insertSysMakeorderPickDetail(pickDetail); + if (insertMakeorderPickDetailResult <= 0){ + throw new BusinessException("新增生产领料单详情失败"); + } } + + + return id; } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java index 7d97fdb8..e6f31336 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOutOrderServiceImpl.java @@ -1,7 +1,7 @@ package com.ruoyi.warehouse.service.impl; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; import com.ruoyi.common.core.redis.RedisCache; 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.SysSalesOrderMapper; import com.ruoyi.warehouse.domain.WarehouseOutOrderDetail; +import com.ruoyi.warehouse.domain.WarehouseStorageOrderDetail; import com.ruoyi.warehouse.mapper.WarehouseOutOrderDetailMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -260,13 +261,41 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService warehouseOutOrder.setMakeNo(tempSysMakeorderPickVo.getMakeNo()); //标明来源是生产订单 warehouseOutOrder.setWarehouseOrderType("1"); + //标明是生产领料 warehouseOutOrder.setWarehouseOutType("1"); - warehouseOutOrder.setMaterialSum(tempSysMakeorderPickVo.getMaterialSum()); - warehouseOutOrder.setEnterpriseSum(tempSysMakeorderPickVo.getEnterpriseSum()); - - warehouseOutOrder.setCreateBy(sysMakeorderPickVo.getApplyUser()); + warehouseOutOrder.setBusinessName(ShiroUtils.getLoginName()); + warehouseOutOrder.setCreateBy(ShiroUtils.getLoginName()); warehouseOutOrder.setCreateTime(new Date()); warehouseOutOrder.setApplyName(sysMakeorderPickVo.getApplyUser()); + List sysMakeorderPickDetails = getSysMakeorderPickDetails(sysMakeorderPickVo); + //对物料相同的数据进行合并操作,并合计领料数 + List 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); if (insertResult <= 0){ @@ -274,18 +303,41 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService throw new BusinessException("添加出库单信息失败"); } //生成出库单详情相关信息 - generateWarehouseOutOrder(sysMakeorderPickVo, tempSysMakeorderPickVo, outOrderCode); + generateWarehouseOutOrder(sysMakeorderPickVo, tempSysMakeorderPickVo, outOrderCode,mergeMakeorderPickDetails); return insertResult; } + /* + * 对物料相同的数据进行合并操作,并合计领料数 + * */ + public List mergeMakeorderPickDetails(List sysMakeorderPickDetails) { + Map 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 mergedDetails = new ArrayList<>(); + for (Map.Entry 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) { - SysMakeorderPickDetail tempMakeorderPickDetail = new SysMakeorderPickDetail(); - tempMakeorderPickDetail.setPickNo(tempSysMakeorderPickVo.getPickNo()); - tempMakeorderPickDetail.setMakeNo(tempSysMakeorderPickVo.getMakeNo()); - //查询生产物料领料单详情 - List sysMakeorderPickDetails = makeorderPickDetailMapper.selectSysMakeorderPickDetailByNo(tempMakeorderPickDetail); - for (SysMakeorderPickDetail sysMakeorderPickDetail : sysMakeorderPickDetails) { + private void generateWarehouseOutOrder(SysMakeorderPickVo sysMakeorderPickVo, SysMakeorderPickVo tempSysMakeorderPickVo, String outOrderCode,List mergeMakeorderPickDetails) { + + for (SysMakeorderPickDetail sysMakeorderPickDetail : mergeMakeorderPickDetails) { WarehouseOutOrderDetail warehouseOutOrderDetail = new WarehouseOutOrderDetail(); warehouseOutOrderDetail.setOutOrderCode(outOrderCode); warehouseOutOrderDetail.setWarehouseOutStatus("4"); @@ -297,7 +349,7 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService warehouseOutOrderDetail.setMaterialSum(tempSysMakeorderPickVo.getMaterialSum()); warehouseOutOrderDetail.setEnterpriseSum(tempSysMakeorderPickVo.getEnterpriseSum()); - warehouseOutOrderDetail.setCreateBy(sysMakeorderPickVo.getApplyUser()); + warehouseOutOrderDetail.setCreateBy(ShiroUtils.getLoginName()); warehouseOutOrderDetail.setCreateTime(new Date()); warehouseOutOrderDetail.setApplyName(sysMakeorderPickVo.getApplyUser()); //物料相关信息 @@ -308,15 +360,35 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService warehouseOutOrderDetail.setMaterialBrand(sysMakeorderPickDetail.getBrand()); warehouseOutOrderDetail.setMaterialProcessMethod(sysMakeorderPickDetail.getProcessMethod()); warehouseOutOrderDetail.setMakeNum(tempSysMakeorderPickVo.getMaterialSum()); - if (StringUtils.isNotEmpty(sysMakeorderPickDetail.getDescribe())){ + //添加申请出库数量 + warehouseOutOrderDetail.setApplyOutOrderSum(Math.toIntExact(sysMakeorderPickDetail.getPickNum())); + + if (StringUtils.isNotEmpty(sysMakeorderPickDetail.getDescribe())) { String[] splitDescribe = sysMakeorderPickDetail.getDescribe().split(","); - warehouseOutOrderDetail.setMaterialModel(splitDescribe[0]); - warehouseOutOrderDetail.setMaterialSpecification(splitDescribe[1]); + if (splitDescribe.length >= 2) { + warehouseOutOrderDetail.setMaterialModel(splitDescribe[0]); + warehouseOutOrderDetail.setMaterialSpecification(splitDescribe[1]); + } + } + int insertOutOrderDetailResult = outOrderDetailMapper.insertWarehouseOutOrderDetail(warehouseOutOrderDetail); + if (insertOutOrderDetailResult <= 0){ + throw new BusinessException("新增出库单详情数据失败"); } - outOrderDetailMapper.insertWarehouseOutOrderDetail(warehouseOutOrderDetail); } } + private List getSysMakeorderPickDetails(SysMakeorderPickVo tempSysMakeorderPickVo) { + SysMakeorderPickDetail tempMakeorderPickDetail = new SysMakeorderPickDetail(); + tempMakeorderPickDetail.setPickNo(tempSysMakeorderPickVo.getPickNo()); + tempMakeorderPickDetail.setMakeNo(tempSysMakeorderPickVo.getMakeNo()); + + //查询生产物料领料单详情 + List sysMakeorderPickDetails = makeorderPickDetailMapper.selectSysMakeorderPickDetailByNo(tempMakeorderPickDetail); + //保留领料单数不为空的数据 + List filterPickDetails = sysMakeorderPickDetails.stream().filter(details -> details.getPickNum() != null).collect(Collectors.toList()); + return filterPickDetails; + } + /* * 生产单-出库 * */ diff --git a/ruoyi-admin/src/main/resources/mapper/system/SysMakeorderPickDetailMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/SysMakeorderPickDetailMapper.xml index 5ee983b3..c9675145 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/SysMakeorderPickDetailMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/SysMakeorderPickDetailMapper.xml @@ -17,6 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -33,7 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select a.id, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.remark - , a.make_no, a.pick_no, a.material_no, a.makeorder_bom_id, a.pick_num + , a.make_no, a.pick_no, a.material_no, a.makeorder_bom_id, a.pick_num, a.has_pick_num ,b.bom_no,b.photoUrl,b.material_name,b.material_type,b.process_method,b.unit,b.brand ,b.describe,b.use_num,b.loss_rate,b.level,b.sort_no from sys_makeorder_pick_detail a @@ -66,6 +67,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + insert into sys_makeorder_pick_detail @@ -80,6 +88,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" material_no, makeorder_bom_id, pick_num, + has_pick_num, #{delFlag}, @@ -93,6 +102,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{materialNo}, #{makeorderBomId}, #{pickNum}, + #{hasPickNum}, @@ -110,6 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" material_no = #{materialNo}, makeorder_bom_id = #{makeorderBomId}, pick_num = #{pickNum}, + has_pick_num = #{hasPickNum}, where id = #{id} diff --git a/ruoyi-admin/src/main/resources/templates/system/makeorder/addpick.html b/ruoyi-admin/src/main/resources/templates/system/makeorder/addpick.html index e2afe31d..6f165ced 100644 --- a/ruoyi-admin/src/main/resources/templates/system/makeorder/addpick.html +++ b/ruoyi-admin/src/main/resources/templates/system/makeorder/addpick.html @@ -151,6 +151,11 @@ field: 'materialNum', align: 'center', title: '订单数量' + }, + { + field: 'finishNum', + align: 'center', + title: '已完成数' } ] }; @@ -302,6 +307,10 @@ return parentRow.materialNum * row.useNum; } }, + { + field: 'hasPickNum', + title: '已领料数量', + }, { field: 'pickNum', title: '本次领料数量', diff --git a/ruoyi-admin/src/main/resources/templates/system/makeorderpick/detail.html b/ruoyi-admin/src/main/resources/templates/system/makeorderpick/detail.html index 7e4dcce1..4c7ec2b7 100644 --- a/ruoyi-admin/src/main/resources/templates/system/makeorderpick/detail.html +++ b/ruoyi-admin/src/main/resources/templates/system/makeorderpick/detail.html @@ -293,6 +293,12 @@ return parentRow.materialNum * row.useNum; } }, + + { + field: 'hasPickNum', + title: '已领料数', + }, + { field: 'pickNum', title: '本次领料数量',