diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesProductOrderController.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesProductOrderController.java index f33806f..3c68512 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesProductOrderController.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesProductOrderController.java @@ -182,5 +182,14 @@ public class MesProductOrderController extends BaseController { return getDataTable(list); } + /** + * 查询物料使用情况 + */ +// @RequiresPermissions("mes:productplan:add") + @GetMapping("/getMaterialUsages") + public AjaxResult getMaterialUsages(MesProductOrder mesProductOrder) { + return success(mesProductOrderService.getMaterialUsages(mesProductOrder)); + } + } diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesProductPlanController.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesProductPlanController.java index 74940ad..077d7c1 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesProductPlanController.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesProductPlanController.java @@ -139,6 +139,7 @@ public class MesProductPlanController extends BaseController { return success(mesProductPlanService.getDispatchCode()); } + /** * 生产工单新增生产派工List */ diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/domain/MesMaterialBom.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/domain/MesMaterialBom.java index 58b53e4..729f709 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/domain/MesMaterialBom.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/domain/MesMaterialBom.java @@ -2,6 +2,7 @@ package com.hw.mes.domain; import java.math.BigDecimal; +import com.hw.common.core.utils.StringUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.hw.common.core.annotation.Excel; @@ -80,6 +81,8 @@ public class MesMaterialBom extends TreeEntity { */ private String materialNameDesc; + private String materialSpec; + /** * 安装时长 */ @@ -182,6 +185,21 @@ public class MesMaterialBom extends TreeEntity { this.materialCode = materialCode; } + public String getMaterialSpec() { + return materialSpec; + } + + public void setMaterialSpec(String materialSpec) { + this.materialSpec = materialSpec; + } + + public String getGroupBy() { + String materialCode = StringUtils.isEmpty(this.materialCode) ? " " : this.materialCode; + String materialName = StringUtils.isEmpty(this.materialName) ? " " : this.materialName; + String materialSpec = StringUtils.isEmpty(this.materialSpec) ? " " : this.materialSpec; + return this.materialId + "-" + materialCode + "-" + materialName + "-" + materialSpec; + } + @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesProductOrderService.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesProductOrderService.java index 27e13ce..e6f404b 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesProductOrderService.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesProductOrderService.java @@ -1,6 +1,8 @@ package com.hw.mes.service; import java.util.List; + +import com.hw.mes.domain.MesMaterialBom; import com.hw.mes.domain.MesProductOrder; /** @@ -103,4 +105,9 @@ public interface IMesProductOrderService */ public int batchEditingProductOrder(List productOrderList); + /** + * 在生产派工时校验库存信息 + * @param mesProductOrder + */ + public List getMaterialUsages(MesProductOrder mesProductOrder); } diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesProductPlanService.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesProductPlanService.java index f74acd8..6ad2000 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesProductPlanService.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesProductPlanService.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import com.hw.mes.domain.MesBaseAttachInfo; +import com.hw.mes.domain.MesMaterialBom; import com.hw.mes.domain.MesProductOrder; import com.hw.mes.domain.MesProductPlan; import com.hw.mes.domain.vo.MesAssignTaskVo; diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesProductOrderServiceImpl.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesProductOrderServiceImpl.java index fc653f6..1458bba 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesProductOrderServiceImpl.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesProductOrderServiceImpl.java @@ -1,10 +1,8 @@ package com.hw.mes.service.impl; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; import com.hw.common.core.constant.MesConstants; import com.hw.common.core.exception.ServiceException; @@ -14,6 +12,7 @@ import com.hw.common.core.utils.uuid.Seq; import com.hw.common.security.utils.SecurityUtils; import com.hw.mes.domain.MesMaterialBom; import com.hw.mes.domain.MesProductPlan; +import com.hw.mes.mapper.MesMaterialBomMapper; import com.hw.mes.mapper.MesProductPlanMapper; import com.hw.mes.service.IMesMaterialBomService; import org.apache.commons.lang3.time.DateFormatUtils; @@ -42,6 +41,9 @@ public class MesProductOrderServiceImpl implements IMesProductOrderService { @Autowired private MesProductPlanMapper mesProductPlanMapper; + @Autowired + private MesMaterialBomMapper mesMaterialBomMapper; + /** * 查询生产工单 * @@ -333,6 +335,70 @@ public class MesProductOrderServiceImpl implements IMesProductOrderService { return result; } + + + + /** + * 在生产派工时校验库存信息 + * @param mesProductOrder + */ + @Override + public List getMaterialUsages(MesProductOrder mesProductOrder) { + String saleType = mesProductOrder.getSaleType(); + MesProductOrder queryProductOrder = new MesProductOrder(); + if (saleType.equals(MesConstants.MES_PRODUCT_ORDER_SALE)) {//外部销售 + Long materialId = mesProductOrder.getMaterialId(); + queryProductOrder.setMaterialId(materialId); + } else {//对内生产 + Long produceMaterialId = mesProductOrder.getProduceMaterialId(); + queryProductOrder.setProduceMaterialId(produceMaterialId); + } + queryProductOrder.setSaleOrderId(mesProductOrder.getSaleOrderId()); + List mesProductOrders = mesProductOrderMapper.selectMesProductOrderList(queryProductOrder); + //工单状态:0-待发布;1-已发布;2-已完成;3-已开始;4-暂停;8-已撤回;9-已删除 + //找到派工数量大于0,并且状态是已发布或者已开始的或者暂停的 + List filterProductOrders = mesProductOrders.stream().filter(p -> + (p.getDispatchAmount().compareTo(BigDecimal.ONE) >= 0) && + (p.getOrderStatus().equals(MesConstants.PUBLISHED) || p.getOrderStatus().equals(MesConstants.BEGIN) || p.getOrderStatus().equals(MesConstants.PAUSE)) + ).collect(Collectors.toList()); + + //先根据saleorderid和安全库存查询总库存和已出库的数量 + //查询各生产任务需要物料的数量 + List> materialBomAllList = new ArrayList<>(); + for (MesProductOrder filterProductOrder : filterProductOrders) { + Long materialBomId = filterProductOrder.getMaterialBomId(); + MesMaterialBom queryMaterialBom = new MesMaterialBom(); + queryMaterialBom.setParentId(materialBomId); + List materialBomList = mesMaterialBomMapper.selectMesMaterialBomJoinList(queryMaterialBom); + materialBomAllList.add(materialBomList); + } + + // 使用流处理合并所有列表并计数(计算每个物料需要的数量) + Map standardCountMap = materialBomAllList.stream() + .flatMap(List::stream) // 将所有列表扁平化为一个流 + .collect(Collectors.groupingBy( + MesMaterialBom::getGroupBy, + Collectors.reducing(BigDecimal.ZERO, MesMaterialBom::getStandardAmount, BigDecimal::add))); + + List mesMaterialBoms = new ArrayList<>(); + standardCountMap.forEach((groupBy, sum) -> { + System.out.println("groupBy: " + groupBy + ", Sum of values: " + sum); + MesMaterialBom mesMaterialBom = new MesMaterialBom(); + String[] groupByArr = groupBy.split("-"); + mesMaterialBom.setMaterialId(Long.valueOf(groupByArr[0])); + mesMaterialBom.setMaterialCode(groupByArr[1]); + mesMaterialBom.setMaterialName(groupByArr[2]); + mesMaterialBom.setMaterialSpec(groupByArr[3]); + mesMaterialBom.setStandardAmount(sum); + mesMaterialBoms.add(mesMaterialBom); + }); + +// select * from wms_stock_total wst left join wms_raw_outstock wro on wst.stock_total_id=wro.stock_total_id +// and wst.sale_order_id=0; + return mesMaterialBoms; + } + + // 递归查找最顶级节点 private MesProductOrder findTopLevelOrder(Long productOrderId) { MesProductOrder currentOrder = mesProductOrderMapper.selectMesProductOrderByProductOrderId(productOrderId); diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesProductPlanServiceImpl.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesProductPlanServiceImpl.java index f1a7113..763f1de 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesProductPlanServiceImpl.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesProductPlanServiceImpl.java @@ -218,6 +218,56 @@ public class MesProductPlanServiceImpl implements IMesProductPlanService { return Seq.getId(Seq.dispatchCodeSeqType, Seq.dispatchCodeCode); } + +// /** +// * 在生产派工时校验库存信息 +// * @param mesProductOrder +// */ +// @Override +// public int checkProductPlanUserConflictAndRawStock(MesProductOrder mesProductOrder) { +// String saleType = mesProductOrder.getSaleType(); +// MesProductOrder queryProductOrder = new MesProductOrder(); +// if (saleType.equals(MesConstants.MES_PRODUCT_ORDER_SALE)) {//外部销售 +// Long materialId = mesProductOrder.getMaterialId(); +// queryProductOrder.setMaterialId(materialId); +// } else {//对内生产 +// Long produceMaterialId = mesProductOrder.getProduceMaterialId(); +// queryProductOrder.setProduceMaterialId(produceMaterialId); +// } +// queryProductOrder.setSaleOrderId(mesProductOrder.getSaleOrderId()); +// List mesProductOrders = mesProductOrderMapper.selectMesProductOrderList(queryProductOrder); +// //工单状态:0-待发布;1-已发布;2-已完成;3-已开始;4-暂停;8-已撤回;9-已删除 +// //找到派工数量大于0,并且状态是已发布或者已开始的或者暂停的 +// List filterProductOrders = mesProductOrders.stream().filter(p -> +// (p.getDispatchAmount().compareTo(BigDecimal.ONE) >= 0) && +// (p.getOrderStatus().equals(MesConstants.PUBLISHED) || p.getOrderStatus().equals(MesConstants.BEGIN) || p.getOrderStatus().equals(MesConstants.PAUSE)) +// ).collect(Collectors.toList()); +// +// //先根据saleorderid和安全库存查询总库存和已出库的数量 +// //查询各生产任务需要物料的数量 +// List> materialBomAllList = new ArrayList<>(); +// for (MesProductOrder filterProductOrder : filterProductOrders) { +// Long materialBomId = filterProductOrder.getMaterialBomId(); +// MesMaterialBom queryMaterialBom = new MesMaterialBom(); +// queryMaterialBom.setParentId(materialBomId); +// List materialBomList = mesMaterialBomMapper.selectMesMaterialBomJoinList(queryMaterialBom); +// materialBomAllList.add(materialBomList); +// } +// +// // 使用流处理合并所有列表并计数(计算每个物料需要的数量) +// Map standardCountMap = materialBomAllList.stream() +// .flatMap(List::stream) // 将所有列表扁平化为一个流 +// .collect(Collectors.groupingBy( +// MesMaterialBom::getMaterialId, +// Collectors.reducing(BigDecimal.ZERO, MesMaterialBom::getStandardAmount, BigDecimal::add))); +// +// standardCountMap.forEach((id, sum) -> System.out.println("ID: " + id + ", Sum of values: " + sum)); +// +//// select * from wms_stock_total wst left join wms_raw_outstock wro on wst.stock_total_id=wro.stock_total_id +//// and wst.sale_order_id=0; +// return 1; +// } + /** * 生产工单新增生产派工List * diff --git a/hw-modules/hw-mes/src/main/resources/mapper/mes/MesMaterialBomMapper.xml b/hw-modules/hw-mes/src/main/resources/mapper/mes/MesMaterialBomMapper.xml index d5afa8f..c4b5129 100644 --- a/hw-modules/hw-mes/src/main/resources/mapper/mes/MesMaterialBomMapper.xml +++ b/hw-modules/hw-mes/src/main/resources/mapper/mes/MesMaterialBomMapper.xml @@ -24,6 +24,8 @@ + + @@ -151,7 +153,7 @@ select wst.stock_total_id, wst.warehouse_id, wst.warehouse_floor, wst.stock_type, wst.material_id, - wst.total_amount, wst.frozen_amount, wst.occupy_amount,wst.safe_flag, + wst.total_amount, wst.frozen_amount, wst.occupy_amount,wst.safe_flag,wst.sale_order_id, mbmi.material_code,mbmi.material_name,mbmi.material_spec, (select sum(wro.outstock_amount) from wms_raw_outstock wro where wro.stock_total_id=wst.stock_total_id and wro.plan_code=#{planCode} and wro.plan_detail_code=#{planDetailCode}) outstock_amount @@ -165,4 +165,33 @@ + + + + diff --git a/hw-ui/src/api/mes/productOrder.js b/hw-ui/src/api/mes/productOrder.js index 6a47b1f..e74c0b0 100644 --- a/hw-ui/src/api/mes/productOrder.js +++ b/hw-ui/src/api/mes/productOrder.js @@ -114,3 +114,21 @@ export function batchEditingProductOrder(data) { data: data }) } + +// 获取生产成品需要的物料 不分页 +export function getMaterialUsages(query) { + return request({ + url: '/mes/productOrder/getMaterialUsages', + method: 'get', + params: query + }) +} + +// 获取库存使用情况 不分页 +export function getStockTotalWithRawOutstocks(query) { + return request({ + url: '/wms/stocktotal/getStockTotalWithRawOutstocks', + method: 'get', + params: query + }) +} diff --git a/hw-ui/src/api/mes/productplan.js b/hw-ui/src/api/mes/productplan.js index e7ba142..365aa18 100644 --- a/hw-ui/src/api/mes/productplan.js +++ b/hw-ui/src/api/mes/productplan.js @@ -51,6 +51,16 @@ export function getDispatchCode() { }) } +// 生产派工校验 +// export function checkProductPlanUserConflictAndRawStock(data) { +// return request({ +// url: '/mes/productplan/checkProductPlanUserConflictAndRawStock', +// method: 'post', +// data: data +// }) +// } + + // 生产工单新增生产派工List export function orderAddMesProductPlanList(data) { return request({ diff --git a/hw-ui/src/views/mes/productOrder/index.vue b/hw-ui/src/views/mes/productOrder/index.vue index e7bee04..d87460a 100644 --- a/hw-ui/src/views/mes/productOrder/index.vue +++ b/hw-ui/src/views/mes/productOrder/index.vue @@ -262,6 +262,13 @@ @click="handleDispatch(scope.row)" >生产派工 + 库存使用 + @@ -505,6 +512,22 @@ + + + + + + + + + + + + + + @@ -515,6 +538,7 @@ import { delProductOrder, addProductOrder, updateProductOrder, + getMaterialUsages, getStockTotalWithRawOutstocks, getOrderCode, productOrderLockInventory, productOrderPublish, productOrderRecall } from "@/api/mes/productOrder"; import addSaleOrder from '@//views/mes/productOrder/addSaleOrder.vue'; @@ -565,6 +589,10 @@ export default { selectType: "", // 是否显示生产弹出层 productOrderOpen: false, + + materialUsageOpen: false, + materialUsageList: [], + // 查询参数 queryParams: { pageNum: 1, @@ -1016,6 +1044,34 @@ export default { this.$tab.closeOpenPage(router.currentRoute); this.$tab.openPage("工单[" + orderCode + "]排产", '/mes/production-scheduling/index/' + productOrderId, params); }, + + handleMaterialUsage(row) { + this.materialUsageOpen = true; + this.materialUsageList = []; + getMaterialUsages(row).then(response => { + let materialUsageList = response.data; + getStockTotalWithRawOutstocks({saleOrderId: row.saleOrderId}).then(response => { + let stockMapJson = response.data; + let totalAmountMap = stockMapJson.totalAmountMap; + let occupyAmountMap = stockMapJson.occupyAmountMap; + let outstockAmountMap = stockMapJson.outstockAmountMap; + // console.log(stocks) + // const stockMap = new Map(stocks.map(obj => [obj.materialId + "-" + obj.saleOrderId, obj])); + materialUsageList.map(objA => { + objA.totalAmount = totalAmountMap[objA.materialId]; + objA.outstockAmount = outstockAmountMap[objA.materialId]; + objA.occupyAmount = occupyAmountMap[objA.materialId]; + objA.availableAmount = objA.totalAmount -objA.occupyAmount; + // return returnObj; // 如果没有找到匹配项,则直接返回原对象 + }); + + this.materialUsageList = materialUsageList; + // console.log(this.materialUsageList) + }) + + }) + }, + /** 销售订单新增提交按钮 */ submitForm() { this.$refs["form"].validate(valid => { diff --git a/hw-ui/src/views/mes/productplan/editProductPlan.vue b/hw-ui/src/views/mes/productplan/editProductPlan.vue index cd283eb..0f0ce6b 100644 --- a/hw-ui/src/views/mes/productplan/editProductPlan.vue +++ b/hw-ui/src/views/mes/productplan/editProductPlan.vue @@ -69,8 +69,8 @@ + :disabled="scope.row.addFlag !=='1' + || form.orderStatus===ORDER_STATUS.FINISHED || form.orderStatus===ORDER_STATUS.RECALLED || form.orderStatus===ORDER_STATUS.DELETED"> @@ -206,7 +206,7 @@ type="danger" @click="handleDeleteDispatchUser(scope.row)" v-if="(scope.row.children == null || false) " - :disabled = "(scope.row.planStatus !== PLAN_STATUS.TO_DISPATCH && scope.row.planStatus !== PLAN_STATUS.DISPATCHED) || form.orderStatus===ORDER_STATUS.FINISHED || form.orderStatus===ORDER_STATUS.RECALLED || form.orderStatus===ORDER_STATUS.DELETED" + :disabled="(scope.row.planStatus !== PLAN_STATUS.TO_DISPATCH && scope.row.planStatus !== PLAN_STATUS.DISPATCHED) || form.orderStatus===ORDER_STATUS.FINISHED || form.orderStatus===ORDER_STATUS.RECALLED || form.orderStatus===ORDER_STATUS.DELETED" >删除 @@ -409,7 +409,7 @@ let deepSearch = (arr, target) => { export default { name: "productPlanEdit", - dicts: ['plan_status','product_status', 'mes_dispatch_flag'], + dicts: ['plan_status', 'product_status', 'mes_dispatch_flag'], components: { 'apply-raw-outstock': applyRawOutstock, }, @@ -614,7 +614,7 @@ export default { let i = 0; let processType; productPlansByDispatch.forEach(groupedProductPlan => { - if(groupedProductPlan.planStatus !== this.PLAN_STATUS.FINISHED){ + if (groupedProductPlan.planStatus !== this.PLAN_STATUS.FINISHED) { obj.addFlag = "1"; } @@ -836,7 +836,18 @@ export default { // console.log(JSON.stringify(toUpdatedProductPlans)); // alert(this.toDeletedPlanIds) // return; + // checkProductPlanUserConflictAndRawStock( + // { + // productOrderId: this.form.productOrderId, + // dispatchAmount: currentDispatchAmount, + // saleOrderId: this.form.saleOrderId + // }) + // .then(res => { + // this.$modal.msgSuccess(res.msg); + // this.close(); + // }); + return; orderAddMesProductPlanList( { @@ -858,18 +869,18 @@ export default { this.$modal.confirm('是否确认删除生产派工单号为"' + dispatchCode + '"的数据项?').then(function () { return true; }).then(() => { - if(this.form.orderStatus === this.ORDER_STATUS.RECALLED){ - this.$modal.msgError("此生产任务已经撤回,不能删除") ; + if (this.form.orderStatus === this.ORDER_STATUS.RECALLED) { + this.$modal.msgError("此生产任务已经撤回,不能删除"); return; } - if(this.form.orderStatus === this.ORDER_STATUS.FINISHED){ - this.$modal.msgError("此生产任务已经完成,不能删除") ; + if (this.form.orderStatus === this.ORDER_STATUS.FINISHED) { + this.$modal.msgError("此生产任务已经完成,不能删除"); return; } - if(this.form.orderStatus === this.ORDER_STATUS.DELETED){ - this.$modal.msgError("此生产任务已经删除,不能删除") ; + if (this.form.orderStatus === this.ORDER_STATUS.DELETED) { + this.$modal.msgError("此生产任务已经删除,不能删除"); return; }