MES:
-生产任务:可根据某生产任务查看其他生产任务使用的库存使用情况和库存可用情况
master
xs 3 months ago
parent 7b525deeeb
commit 2c8623c7e5

@ -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));
}
}

@ -139,6 +139,7 @@ public class MesProductPlanController extends BaseController {
return success(mesProductPlanService.getDispatchCode());
}
/**
* List
*/

@ -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)

@ -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<MesProductOrder> productOrderList);
/**
*
* @param mesProductOrder
*/
public List<MesMaterialBom> getMaterialUsages(MesProductOrder mesProductOrder);
}

@ -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;

@ -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<MesMaterialBom> 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<MesProductOrder> mesProductOrders = mesProductOrderMapper.selectMesProductOrderList(queryProductOrder);
//工单状态0-待发布1-已发布2-已完成3-已开始4-暂停8-已撤回9-已删除
//找到派工数量大于0并且状态是已发布或者已开始的或者暂停的
List<MesProductOrder> 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<List<MesMaterialBom>> materialBomAllList = new ArrayList<>();
for (MesProductOrder filterProductOrder : filterProductOrders) {
Long materialBomId = filterProductOrder.getMaterialBomId();
MesMaterialBom queryMaterialBom = new MesMaterialBom();
queryMaterialBom.setParentId(materialBomId);
List<MesMaterialBom> materialBomList = mesMaterialBomMapper.selectMesMaterialBomJoinList(queryMaterialBom);
materialBomAllList.add(materialBomList);
}
// 使用流处理合并所有列表并计数(计算每个物料需要的数量)
Map<String, BigDecimal> standardCountMap = materialBomAllList.stream()
.flatMap(List::stream) // 将所有列表扁平化为一个流
.collect(Collectors.groupingBy(
MesMaterialBom::getGroupBy,
Collectors.reducing(BigDecimal.ZERO, MesMaterialBom::getStandardAmount, BigDecimal::add)));
List<MesMaterialBom> 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);

@ -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<MesProductOrder> mesProductOrders = mesProductOrderMapper.selectMesProductOrderList(queryProductOrder);
// //工单状态0-待发布1-已发布2-已完成3-已开始4-暂停8-已撤回9-已删除
// //找到派工数量大于0并且状态是已发布或者已开始的或者暂停的
// List<MesProductOrder> 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<List<MesMaterialBom>> materialBomAllList = new ArrayList<>();
// for (MesProductOrder filterProductOrder : filterProductOrders) {
// Long materialBomId = filterProductOrder.getMaterialBomId();
// MesMaterialBom queryMaterialBom = new MesMaterialBom();
// queryMaterialBom.setParentId(materialBomId);
// List<MesMaterialBom> materialBomList = mesMaterialBomMapper.selectMesMaterialBomJoinList(queryMaterialBom);
// materialBomAllList.add(materialBomList);
// }
//
// // 使用流处理合并所有列表并计数(计算每个物料需要的数量)
// Map<Long, BigDecimal> 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
*

@ -24,6 +24,8 @@
<result property="materialBomDesc" column="material_bom_desc"/>
<result property="materialNameDesc" column="materialNameDesc"/>
<result property="assembleTime" column="assemble_time"/>
<result property="materialSpec" column="material_spec"/>
</resultMap>
<sql id="selectMesMaterialBomVo">
@ -151,7 +153,7 @@
<select id="selectMesMaterialBomJoinList" parameterType="MesMaterialBom" resultMap="MesMaterialBomResult">
select mmb.material_id,mbmi.material_code,mbmi.material_name,mmb.standard_amount
select mmb.material_id,mbmi.material_code,mbmi.material_name,mbmi.material_spec,mmb.standard_amount
from mes_material_bom mmb left join mes_base_material_info mbmi on mmb.material_id=mbmi.material_id
<where>
<if test="parentId != null ">and mmb.parent_id = #{parentId}</if>

@ -2,6 +2,8 @@ package com.hw.wms.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -101,4 +103,16 @@ public class WmsStockTotalController extends BaseController
{
return toAjax(wmsStockTotalService.deleteWmsStockTotalByStockTotalIds(stockTotalIds));
}
/**
* with wms_raw_outstock
*/
// @RequiresPermissions("wms:stocktotal:list")
@GetMapping("/getStockTotalWithRawOutstocks")
public AjaxResult getStockTotalWithRawOutstocks(WmsStockTotal wmsStockTotal)
{
JSONObject returnObj = wmsStockTotalService.selectWmsStockTotalJoinRealListBySaleOrder(wmsStockTotal);
return success(returnObj);
}
}

@ -65,11 +65,19 @@ public interface WmsStockTotalMapper
/**
* ()
* (plancodeplandetailcode)
*
* @param wmsStockTotal
* @return
*/
public List<WmsStockTotal> selectWmsStockTotalJoinListBySaleOrder(WmsStockTotal wmsStockTotal);
/**
* ()
*
* @param wmsStockTotal
* @return
*/
public List<WmsStockTotal> selectWmsStockTotalJoinRealListBySaleOrder(WmsStockTotal wmsStockTotal);
}

@ -1,6 +1,10 @@
package com.hw.wms.service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson2.JSONObject;
import com.hw.wms.domain.WmsStockTotal;
/**
@ -67,4 +71,12 @@ public interface IWmsStockTotalService
* @return
*/
public List<WmsStockTotal> selectWmsStockTotalJoinListBySaleOrder(WmsStockTotal wmsStockTotal);
/**
* (()),Join material
*
* @param wmsStockTotal
* @return
*/
public JSONObject selectWmsStockTotalJoinRealListBySaleOrder(WmsStockTotal wmsStockTotal);
}

@ -1276,8 +1276,6 @@ public class WmsRawOutstockServiceImpl implements IWmsRawOutstockService {
wcsAgvCompleteUrl, entity, WcsReturnMsgVo.class);
WcsReturnMsgVo wcsReturnMsgVo = response.getBody();
// System.out.println("Response Status: " + response.getStatusCode());
// System.out.println("Response Status: " + wcsReturnMsgVo);
if (response.getStatusCodeValue() != 200) {
throw new ServiceException("调度异常,请重试");
}

@ -1,6 +1,12 @@
package com.hw.wms.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hw.wms.mapper.WmsStockTotalMapper;
@ -98,7 +104,7 @@ public class WmsStockTotalServiceImpl implements IWmsStockTotalService
/**
* (),Join material
* (plancodeplandetailcode),Join material
*
* @param wmsStockTotal
* @return
@ -109,4 +115,45 @@ public class WmsStockTotalServiceImpl implements IWmsStockTotalService
return wmsStockTotalMapper.selectWmsStockTotalJoinListBySaleOrder(wmsStockTotal);
}
/**
* (()),Join material
*
* @param wmsStockTotal
* @return
*/
@Override
public JSONObject selectWmsStockTotalJoinRealListBySaleOrder(WmsStockTotal wmsStockTotal)
{
List<WmsStockTotal> wmsStockTotals = wmsStockTotalMapper.selectWmsStockTotalJoinRealListBySaleOrder(wmsStockTotal);
// 使用流处理合并所有列表并计数(计算每个物料总库存数量)
Map<Long, BigDecimal> totalAmountMap = wmsStockTotals.stream().filter(w->w.getTotalAmount()!=null)
.collect(Collectors.groupingBy(
WmsStockTotal::getMaterialId, // 根据id分组
Collectors.reducing(BigDecimal.ZERO, // 初始化求和值为0
WmsStockTotal::getTotalAmount, BigDecimal::add)));
// 使用流处理合并所有列表并计数(计算每个物料总占用数量)
Map<Long, BigDecimal> occupyAmountMap = wmsStockTotals.stream().filter(w->w.getOccupyAmount()!=null)
.collect(Collectors.groupingBy(
WmsStockTotal::getMaterialId, // 根据id分组
Collectors.reducing(BigDecimal.ZERO, // 初始化求和值为0
WmsStockTotal::getOccupyAmount, BigDecimal::add)));
// 使用流处理合并所有列表并计数(计算每个物料总使用数量)
Map<Long, BigDecimal> realOutstockAmountMap = wmsStockTotals.stream().filter(w->w.getOutstockAmount()!=null)
.collect(Collectors.groupingBy(
WmsStockTotal::getMaterialId, // 根据id分组
Collectors.reducing(BigDecimal.ZERO, // 初始化求和值为0
WmsStockTotal::getOutstockAmount, BigDecimal::add)));
JSONObject returnObj = new JSONObject();
returnObj.put("totalAmountMap",totalAmountMap);
returnObj.put("occupyAmountMap",occupyAmountMap);
returnObj.put("outstockAmountMap",realOutstockAmountMap);
return returnObj;
}
}

@ -140,7 +140,7 @@
<select id="selectWmsStockTotalJoinListBySaleOrder" parameterType="WmsStockTotal" resultMap="WmsStockTotalResult">
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 @@
</where>
</select>
<select id="selectWmsStockTotalJoinRealListBySaleOrder" parameterType="WmsStockTotal" resultMap="WmsStockTotalResult">
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.sale_order_id,
mbmi.material_code,mbmi.material_name,mbmi.material_spec,
(select sum(wro.real_outstock_amount) from wms_raw_outstock wro where wro.stock_total_id=wst.stock_total_id
and (wro.execute_status='0' or wro.execute_status='1')) outstock_amount
from wms_stock_total wst left join mes_base_material_info mbmi on wst.material_id = mbmi.material_id
<where>
and wst.total_amount>=0
<if test="warehouseId != null ">and wst.warehouse_id = #{warehouseId}</if>
<if test="warehouseFloor != null ">and wst.warehouse_floor = #{warehouseFloor}</if>
<if test="stockType != null and stockType != ''">and wst.stock_type = #{stockType}</if>
<if test="materialId != null ">and wst.material_id = #{materialId}</if>
<if test="materialName != null and materialName != ''">and mbmi.material_name like concat('%',
#{materialName},
'%')
</if>
<if test="saleOrderId != null ">and (wst.sale_order_id = #{saleOrderId} or wst.sale_order_id=0)</if>
<if test="saleOrderId == null ">and wst.safe_flag='1'</if>
<if test="materialCodeNameSpec != null and materialCodeNameSpec != ''">and (mbmi.material_code like concat('%',
#{materialCodeNameSpec},'%') or mbmi.material_name like concat('%',#{materialCodeNameSpec},'%')
or mbmi.material_spec like concat('%',#{materialCodeNameSpec},'%'))
</if>
</where>
</select>
</mapper>

@ -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
})
}

@ -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({

@ -262,6 +262,13 @@
@click="handleDispatch(scope.row)"
>生产派工
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-right"
@click="handleMaterialUsage(scope.row)"
>库存使用
</el-button>
</template>
</el-table-column>
</el-table>
@ -505,6 +512,22 @@
</div>
</el-dialog>
<el-dialog title="库存使用信息" :visible.sync="materialUsageOpen" width="1000px" append-to-body>
<el-table v-loading="loading" :data="materialUsageList">
<!--el-table-column label="库存ID" align="center" prop="stockTotalId"/>
<el-table-column label="物料ID" align="center" prop="materialId"/>
<el-table-column label="物料编码" align="center" prop="materialCode"/-->
<el-table-column label="物料名称" align="center" prop="materialName"/>
<el-table-column label="物料规格" align="center" prop="materialSpec"/>
<el-table-column label="需要数量" align="center" prop="standardAmount" width="100"/>
<el-table-column label="已使用数量" align="center" prop="outstockAmount" width="100"/>
<el-table-column label="库存总数量" align="center" prop="totalAmount" width="100"/>
<el-table-column label="库存可用数量" align="center" prop="availableAmount" width="100"/>
</el-table>
</el-dialog>
</div>
</template>
@ -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 => {

@ -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(
{

Loading…
Cancel
Save