更新生产计划、销售订单、工作订单和仓库发料功能

This commit is contained in:
panchengyong
2026-03-13 11:11:37 +08:00
parent 34cbf08144
commit 099e01e518
30 changed files with 681 additions and 185 deletions

View File

@@ -1,11 +1,17 @@
package com.ktg.mes.mp.controller;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.ktg.common.constant.UserConstants;
import com.ktg.mes.mp.domain.MpMbomLine;
import com.ktg.mes.mp.service.IMpMbomLineService;
import com.ktg.mes.wm.domain.WmMaterialStock;
import com.ktg.mes.wm.service.IWmMaterialStockService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
@@ -42,6 +48,9 @@ public class MpMbomController extends BaseController
@Autowired
private IMpMbomLineService mpMbomLineService;
@Autowired
private IWmMaterialStockService wmMaterialStockService;
/**
* 查询物料清单列表
*/
@@ -200,4 +209,70 @@ public class MpMbomController extends BaseController
}
return toAjax(mpMbomService.revokeIssue(mbomId));
}
/**
* 齐套检查:查询物料清单的子件库存情况
*/
@GetMapping("/stock-check/{mbomId}")
public AjaxResult stockCheck(@PathVariable Long mbomId)
{
MpMbom mbom = mpMbomService.selectMpMbomByMbomId(mbomId);
if (mbom == null) {
return AjaxResult.error("物料清单不存在!");
}
// 查询物料清单明细(子件列表)
MpMbomLine query = new MpMbomLine();
query.setMbomId(mbomId);
List<MpMbomLine> lines = mpMbomLineService.selectMpMbomLineList(query);
if (lines == null || lines.isEmpty()) {
return AjaxResult.success(new ArrayList<>());
}
// 查询每个子件的库存并计算缺料情况
List<Map<String, Object>> result = new ArrayList<>();
for (MpMbomLine line : lines) {
if (line.getItemId() == null) {
continue;
}
// 查询物料库存
WmMaterialStock stockQuery = new WmMaterialStock();
stockQuery.setItemId(line.getItemId());
List<WmMaterialStock> stocks = wmMaterialStockService.selectWmMaterialStockList(stockQuery);
// 汇总可用库存(未冻结的库存)
BigDecimal availableQty = BigDecimal.ZERO;
if (stocks != null) {
for (WmMaterialStock stock : stocks) {
if (stock.getQuantityOnhand() != null && !"Y".equals(stock.getFrozenFlag())) {
availableQty = availableQty.add(stock.getQuantityOnhand());
}
}
}
// 需求量
BigDecimal requiredQty = line.getQuantity() != null ? line.getQuantity() : BigDecimal.ZERO;
// 缺料量(需求量 - 可用量,如果 < 0 则为 0
BigDecimal shortage = requiredQty.subtract(availableQty);
if (shortage.compareTo(BigDecimal.ZERO) < 0) {
shortage = BigDecimal.ZERO;
}
Map<String, Object> item = new HashMap<>();
item.put("itemCode", line.getItemCode());
item.put("itemName", line.getItemName());
item.put("unitName", line.getUnitName());
item.put("requiredQty", requiredQty);
item.put("availableQty", availableQty);
item.put("shortage", shortage);
item.put("isShortage", shortage.compareTo(BigDecimal.ZERO) > 0);
result.add(item);
}
return AjaxResult.success(result);
}
}

View File

@@ -62,6 +62,18 @@ public class MpPlan extends BaseEntity
@Excel(name = "销售员")
private String salesUserName;
/** 部门名称(从关联销售订单带入,不持久化) */
private String deptName;
/** 客户ID从关联销售订单带入不持久化 */
private Long clientId;
/** 客户编码(从关联销售订单带入,不持久化) */
private String clientCode;
/** 客户名称(从关联销售订单带入,不持久化) */
private String clientName;
/** 订单交期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "订单交期", width = 30, dateFormat = "yyyy-MM-dd")
@@ -70,6 +82,9 @@ public class MpPlan extends BaseEntity
/** BOM ID */
private Long bomId;
/** BOM编码从关联BOM带入不持久化 */
private String bomCode;
/** BOM版本号 */
@Excel(name = "BOM版本号")
private String bomVersion;
@@ -94,7 +109,7 @@ public class MpPlan extends BaseEntity
private String approverName;
/** 审核日期 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date approveDate;
/** 删除标志 */
@@ -249,6 +264,25 @@ public class MpPlan extends BaseEntity
return salesUserName;
}
public void setDeptName(String deptName)
{
this.deptName = deptName;
}
public String getDeptName()
{
return deptName;
}
public void setClientId(Long clientId) { this.clientId = clientId; }
public Long getClientId() { return clientId; }
public void setClientCode(String clientCode) { this.clientCode = clientCode; }
public String getClientCode() { return clientCode; }
public void setClientName(String clientName) { this.clientName = clientName; }
public String getClientName() { return clientName; }
public void setDeliveryDate(Date deliveryDate)
{
this.deliveryDate = deliveryDate;
@@ -269,6 +303,16 @@ public class MpPlan extends BaseEntity
return bomId;
}
public void setBomCode(String bomCode)
{
this.bomCode = bomCode;
}
public String getBomCode()
{
return bomCode;
}
public void setBomVersion(String bomVersion)
{
this.bomVersion = bomVersion;
@@ -400,6 +444,7 @@ public class MpPlan extends BaseEntity
.append("salesUserName", getSalesUserName())
.append("deliveryDate", getDeliveryDate())
.append("bomId", getBomId())
.append("bomCode", getBomCode())
.append("bomVersion", getBomVersion())
.append("bomDesc", getBomDesc())
.append("totalQuantity", getTotalQuantity())

View File

@@ -77,6 +77,10 @@ public class MpPlanLine extends BaseEntity
private String salesUserName;
/** 订单交期(关联表头,明细视图展示) */
private String deliveryDate;
/** 单据状态(关联表头,明细视图展示) */
private String status;
/** 单据日期(关联表头,明细视图展示) */
private String planDate;
public void setLineId(Long lineId)
{
@@ -256,6 +260,18 @@ public class MpPlanLine extends BaseEntity
public String getDeliveryDate() {
return deliveryDate;
}
public void setStatus(String status) {
this.status = status;
}
public String getStatus() {
return status;
}
public void setPlanDate(String planDate) {
this.planDate = planDate;
}
public String getPlanDate() {
return planDate;
}
@Override
public String toString() {

View File

@@ -342,7 +342,13 @@ public class MpPlanServiceImpl implements IMpPlanService
// 生成物料清单编码(通过通用编码引擎)
mbom.setMbomCode(autoCodeUtil.genSerialCode(UserConstants.MBOM_CODE, ""));
mbom.setMbomDate(new Date());
mbom.setStatus(UserConstants.ORDER_STATUS_PREPARE);
// 当计划已审核时,自动审核物料清单
if (UserConstants.ORDER_STATUS_APPROVED.equals(plan.getStatus())) {
mbom.setStatus(UserConstants.ORDER_STATUS_APPROVED);
mbom.setApproveDate(DateUtils.getNowDate());
} else {
mbom.setStatus(UserConstants.ORDER_STATUS_PREPARE);
}
mbom.setBusinessType("BOM_CALC");
mbom.setPlanId(plan.getPlanId());
mbom.setPlanCode(plan.getPlanCode());

View File

@@ -111,6 +111,7 @@ public class ProWorkorderServiceImpl implements IProWorkorderService
}
}
proWorkorder.setWorkorderName(buildWorkorderName(proWorkorder));
proWorkorder.setCreateTime(DateUtils.getNowDate());
return proWorkorderMapper.insertProWorkorder(proWorkorder);
}
@@ -124,6 +125,7 @@ public class ProWorkorderServiceImpl implements IProWorkorderService
@Override
public int updateProWorkorder(ProWorkorder proWorkorder)
{
proWorkorder.setWorkorderName(buildWorkorderName(proWorkorder));
proWorkorder.setUpdateTime(DateUtils.getNowDate());
return proWorkorderMapper.updateProWorkorder(proWorkorder);
}
@@ -242,4 +244,23 @@ public class ProWorkorderServiceImpl implements IProWorkorderService
List<ProWorkorderHomeVO> collect = proWorkorders.stream().filter(item -> 0L == item.getParentId()).collect(Collectors.toList());
return AjaxResult.success(collect);
}
/**
* 生产工单名称规则JX + 产品名称 + 单据日期(yyyyMMdd)
*/
private String buildWorkorderName(ProWorkorder proWorkorder) {
String productName = StringUtils.trimToEmpty(proWorkorder.getProductName());
if (StringUtils.isEmpty(productName)) {
productName = StringUtils.trimToEmpty(proWorkorder.getProductCode());
}
if (StringUtils.isEmpty(productName)) {
productName = "未命名产品";
}
String docDate = DateUtils.parseDateToStr(
"yyyyMMdd",
proWorkorder.getRequestDate() == null ? DateUtils.getNowDate() : proWorkorder.getRequestDate()
);
return "JX-" + productName + "-" + docDate;
}
}

View File

@@ -123,22 +123,34 @@ public class SlOrderController extends BaseController
}
/**
* 审核销售订单
* 审核销售订单(支持批量,逗号分隔)
*/
@Log(title = "销售订单", businessType = BusinessType.UPDATE)
@PostMapping("/audit/{orderId}")
public AjaxResult audit(@PathVariable Long orderId)
@PostMapping("/audit/{orderIds}")
public AjaxResult audit(@PathVariable String orderIds)
{
return toAjax(slOrderService.auditSlOrder(orderId, getUsername()));
String nickName = getLoginUser().getUser().getNickName();
Long userId = getUserId();
int rows = 0;
for (String id : orderIds.split(","))
{
rows += slOrderService.auditSlOrder(Long.parseLong(id.trim()), nickName, userId);
}
return toAjax(rows);
}
/**
* 反审核销售订单
* 反审核销售订单(支持批量,逗号分隔)
*/
@Log(title = "销售订单", businessType = BusinessType.UPDATE)
@PostMapping("/unaudit/{orderId}")
public AjaxResult unaudit(@PathVariable Long orderId)
@PostMapping("/unaudit/{orderIds}")
public AjaxResult unaudit(@PathVariable String orderIds)
{
return toAjax(slOrderService.unauditSlOrder(orderId, getUsername()));
int rows = 0;
for (String id : orderIds.split(","))
{
rows += slOrderService.unauditSlOrder(Long.parseLong(id.trim()), getUsername());
}
return toAjax(rows);
}
}

View File

@@ -71,10 +71,11 @@ public interface ISlOrderService
* 审核销售订单
*
* @param orderId 销售订单ID
* @param username 审核人
* @param approverName 审核人昵称
* @param approverId 审核人ID
* @return 结果
*/
public int auditSlOrder(Long orderId, String username);
public int auditSlOrder(Long orderId, String approverName, Long approverId);
/**
* 反审核销售订单

View File

@@ -221,11 +221,12 @@ public class SlOrderServiceImpl implements ISlOrderService
* 审核销售订单
*
* @param orderId 销售订单ID
* @param username 审核人
* @param approverName 审核人昵称
* @param approverId 审核人ID
* @return 结果
*/
@Override
public int auditSlOrder(Long orderId, String username)
public int auditSlOrder(Long orderId, String approverName, Long approverId)
{
SlOrder order = slOrderMapper.selectSlOrderByOrderId(orderId);
if (order == null)
@@ -233,9 +234,10 @@ public class SlOrderServiceImpl implements ISlOrderService
return 0;
}
order.setStatus(UserConstants.ORDER_STATUS_APPROVED);
order.setApproverName(username);
order.setApproverId(approverId);
order.setApproverName(approverName);
order.setApproveDate(DateUtils.getNowDate());
order.setUpdateBy(username);
order.setUpdateBy(approverName);
order.setUpdateTime(DateUtils.getNowDate());
return slOrderMapper.updateSlOrder(order);
}

View File

@@ -26,6 +26,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="salesOrderCode" column="sales_order_code" />
<result property="salesUserName" column="sales_user_name" />
<result property="deliveryDate" column="delivery_date" />
<result property="status" column="status" />
<result property="planDate" column="plan_date" />
</resultMap>
<sql id="selectMpPlanLineVo">
@@ -52,8 +54,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select l.line_id, l.plan_id, l.plan_code, l.line_no, l.pp_number, l.item_id, l.item_code,
l.item_name, l.specification, l.unit_name, l.quantity, l.remark,
l.del_flag, l.create_time, l.tenant_id,
p.sales_order_code, p.sales_user_name,
date_format(p.delivery_date, '%Y-%m-%d') as delivery_date
p.sales_order_code, p.sales_user_name, p.status,
date_format(p.delivery_date, '%Y-%m-%d') as delivery_date,
date_format(p.plan_date, '%Y-%m-%d') as plan_date
from erp_mp_plan_line l
left join erp_mp_plan p on l.plan_id = p.plan_id and p.del_flag = '0'
<where>

View File

@@ -17,8 +17,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="salesOrderCode" column="sales_order_code" />
<result property="salesUserId" column="sales_user_id" />
<result property="salesUserName" column="sales_user_name" />
<result property="deptName" column="dept_name" />
<result property="clientId" column="client_id" />
<result property="clientCode" column="client_code" />
<result property="clientName" column="client_name" />
<result property="deliveryDate" column="delivery_date" />
<result property="bomId" column="bom_id" />
<result property="bomCode" column="bom_code" />
<result property="bomVersion" column="bom_version" />
<result property="bomDesc" column="bom_desc" />
<result property="totalQuantity" column="total_quantity" />
@@ -36,48 +41,52 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectMpPlanVo">
select plan_id, tenant_id, plan_code, plan_date, status, business_status, business_type,
work_type, sales_order_id, sales_order_code, sales_user_name,
delivery_date, bom_id, bom_version, bom_desc, total_quantity, remark,
del_flag, create_by, create_time, update_by, update_time
from erp_mp_plan
select p.plan_id, p.tenant_id, p.plan_code, p.plan_date, p.status, p.business_status, p.business_type,
p.work_type, p.sales_order_id, p.sales_order_code, p.sales_user_name,
p.delivery_date, p.bom_id, p.bom_version, p.bom_desc, p.total_quantity, p.remark,
p.operator_id, p.operator_name, p.approver_id, p.approver_name, p.approve_date,
p.del_flag, p.create_by, p.create_time, p.update_by, p.update_time,
so.dept_name, so.client_id, so.client_code, so.client_name, b.bom_code
from erp_mp_plan p
left join erp_sl_order so on p.sales_order_id = so.order_id and so.del_flag = '0'
left join md_bom b on p.bom_id = b.bom_id and b.del_flag = '0'
</sql>
<select id="selectMpPlanList" parameterType="MpPlan" resultMap="MpPlanResult">
<include refid="selectMpPlanVo"/>
<where>
del_flag = '0'
<if test="planCode != null and planCode != ''"> and plan_code like concat('%', #{planCode}, '%')</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="businessStatus != null and businessStatus != ''"> and business_status = #{businessStatus}</if>
<if test="businessType != null and businessType != ''"> and business_type = #{businessType}</if>
<if test="workType != null"> and work_type = #{workType}</if>
<if test="salesOrderId != null"> and sales_order_id = #{salesOrderId}</if>
<if test="salesOrderCode != null and salesOrderCode != ''"> and sales_order_code like concat('%', #{salesOrderCode}, '%')</if>
<if test="salesUserName != null and salesUserName != ''"> and sales_user_name like concat('%', #{salesUserName}, '%')</if>
p.del_flag = '0'
<if test="planCode != null and planCode != ''"> and p.plan_code like concat('%', #{planCode}, '%')</if>
<if test="status != null and status != ''"> and p.status = #{status}</if>
<if test="businessStatus != null and businessStatus != ''"> and p.business_status = #{businessStatus}</if>
<if test="businessType != null and businessType != ''"> and p.business_type = #{businessType}</if>
<if test="workType != null"> and p.work_type = #{workType}</if>
<if test="salesOrderId != null"> and p.sales_order_id = #{salesOrderId}</if>
<if test="salesOrderCode != null and salesOrderCode != ''"> and p.sales_order_code like concat('%', #{salesOrderCode}, '%')</if>
<if test="salesUserName != null and salesUserName != ''"> and p.sales_user_name like concat('%', #{salesUserName}, '%')</if>
<if test="params.beginPlanDate != null and params.beginPlanDate != '' and params.endPlanDate != null and params.endPlanDate != ''">
and plan_date between #{params.beginPlanDate} and #{params.endPlanDate}
and p.plan_date between #{params.beginPlanDate} and #{params.endPlanDate}
</if>
<if test="params.beginDeliveryDate != null and params.beginDeliveryDate != '' and params.endDeliveryDate != null and params.endDeliveryDate != ''">
and delivery_date between #{params.beginDeliveryDate} and #{params.endDeliveryDate}
and p.delivery_date between #{params.beginDeliveryDate} and #{params.endDeliveryDate}
</if>
</where>
order by create_time desc
order by p.create_time desc
</select>
<select id="selectMpPlanByPlanId" parameterType="Long" resultMap="MpPlanResult">
<include refid="selectMpPlanVo"/>
where plan_id = #{planId} and del_flag = '0'
where p.plan_id = #{planId} and p.del_flag = '0'
</select>
<select id="selectMpPlanByPlanCode" parameterType="String" resultMap="MpPlanResult">
<include refid="selectMpPlanVo"/>
where plan_code = #{planCode} and del_flag = '0'
where p.plan_code = #{planCode} and p.del_flag = '0'
</select>
<select id="checkPlanCodeUnique" parameterType="MpPlan" resultMap="MpPlanResult">
<include refid="selectMpPlanVo"/>
where plan_code = #{planCode} and del_flag = '0' limit 1
where p.plan_code = #{planCode} and p.del_flag = '0' limit 1
</select>
<select id="selectMaxPlanCode" parameterType="String" resultType="String">
@@ -109,6 +118,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="bomDesc != null">bom_desc,</if>
<if test="totalQuantity != null">total_quantity,</if>
<if test="remark != null">remark,</if>
<if test="operatorId != null">operator_id,</if>
<if test="operatorName != null">operator_name,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
@@ -130,6 +141,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="bomDesc != null">#{bomDesc},</if>
<if test="totalQuantity != null">#{totalQuantity},</if>
<if test="remark != null">#{remark},</if>
<if test="operatorId != null">#{operatorId},</if>
<if test="operatorName != null">#{operatorName},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
@@ -153,6 +166,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="bomDesc != null">bom_desc = #{bomDesc},</if>
<if test="totalQuantity != null">total_quantity = #{totalQuantity},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="operatorId != null">operator_id = #{operatorId},</if>
<if test="operatorName != null">operator_name = #{operatorName},</if>
<if test="approverId != null">approver_id = #{approverId},</if>
<if test="approverName != null">approver_name = #{approverName},</if>
<if test="approveDate != null">approve_date = #{approveDate},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>

View File

@@ -46,7 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectProWorkorderVo">
select workorder_id, workorder_code, workorder_name, workorder_type, order_source, source_code, product_id, product_code, product_name, product_spc, unit_of_measure, unit_name, batch_code, quantity,quantity_produced, client_id, client_code, client_name, vendor_id, vendor_code, vendor_name, request_date, parent_id, ancestors, finish_date, cancel_date, status, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from pro_workorder
select workorder_id, workorder_code, workorder_name, workorder_type, order_source, source_code, product_id, product_code, product_name, product_spc, unit_of_measure, unit_name, batch_code, quantity, quantity_produced, quantity_changed, quantity_scheduled, client_id, client_code, client_name, vendor_id, vendor_code, vendor_name, request_date, parent_id, ancestors, finish_date, cancel_date, status, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from pro_workorder
</sql>
<select id="selectProWorkorderList" parameterType="ProWorkorder" resultMap="ProWorkorderResult">

View File

@@ -86,7 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
inner join erp_sl_order o on ol.order_id = o.order_id
<where>
ol.del_flag = '0' and o.del_flag = '0'
and o.status = '审核'
and o.status = 'APPROVED'
and (ol.quantity - ifnull(ol.delivered_qty, 0)) > 0
<if test="orderCode != null and orderCode != ''"> and ol.order_code like concat('%', #{orderCode}, '%')</if>
<if test="trackCode != null and trackCode != ''"> and ol.track_code like concat('%', #{trackCode}, '%')</if>