feat(工单管理): 新增工单物料查询及生产进度功能
新增工单物料服务接口及实现,包括领料清单、成品入库清单和出货清单查询 添加工单生产进度查询功能及相关DTO定义 完善工单修改日志记录功能 规范工单号字段使用,区分原材料工单号和当前工单号
This commit is contained in:
@@ -387,7 +387,9 @@ namespace DOAN.Service.BZFM
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
// 初始化领料记录参数
|
||||
parm = InitializeMaterialTakeRecord(parm);
|
||||
|
||||
var inboundInfo = Queryable().Where(x => x.Id == parm.Id).First();
|
||||
if (inboundInfo == null)
|
||||
{
|
||||
@@ -397,7 +399,7 @@ namespace DOAN.Service.BZFM
|
||||
{
|
||||
return "该记录已撤销,无法领料!";
|
||||
}
|
||||
if(parm.Quantity > inboundInfo.Quantity)
|
||||
if (parm.Quantity > inboundInfo.Quantity)
|
||||
{
|
||||
return "领料数量超过记录最大值!";
|
||||
}
|
||||
@@ -409,7 +411,10 @@ namespace DOAN.Service.BZFM
|
||||
return "该入库记录对应的工单不存在!";
|
||||
}
|
||||
Context.Ado.BeginTran();
|
||||
inboundInfo.WorkorderRaw = parm.WorkorderRow;
|
||||
// 根据规范:WorkorderRaw字段用于永久性记录原材料最初关联的工单号信息,保持不变
|
||||
// 因此这里不应该修改WorkorderRaw,而是保持其原值
|
||||
// 只更新Workorder字段,动态记录当前操作环节所对应的工单号
|
||||
inboundInfo.Workorder = parm.Workorder;
|
||||
inboundInfo.Remarks += $"[已领料{parm.Quantity}]";
|
||||
Context.Updateable(inboundInfo).ExecuteCommand();
|
||||
// 填写出库单
|
||||
@@ -421,10 +426,10 @@ namespace DOAN.Service.BZFM
|
||||
LocationCode = inboundInfo.LocationCode,
|
||||
WarehouseCode = inboundInfo.WarehouseCode,
|
||||
OrderNo = workorderInfo.CustomerOrder,
|
||||
// 原材料工单号
|
||||
Workorder = inboundInfo.Workorder,
|
||||
// 产成品工单号
|
||||
WorkorderRaw = parm.WorkorderRow,
|
||||
// 原材料工单号:保持原材料最初关联的工单号
|
||||
Workorder = inboundInfo.WorkorderRaw, // 使用WorkorderRaw作为原材料工单号
|
||||
// 产成品工单号:动态记录当前操作对应的工单号
|
||||
WorkorderRaw = parm.Workorder, // 使用传入的Workorder作为产成品工单号
|
||||
Operator = parm.Operator,
|
||||
Quantity = parm.Quantity,
|
||||
TransactionType = "领料出库",
|
||||
@@ -442,5 +447,177 @@ namespace DOAN.Service.BZFM
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化领料记录
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public TakeMaterialRequestDto InitializeMaterialTakeRecord(TakeMaterialRequestDto parm)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 数据验证
|
||||
if (parm == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parm), "领料请求参数不能为空");
|
||||
}
|
||||
|
||||
// 验证必填字段
|
||||
if (parm.Id <= 0)
|
||||
{
|
||||
throw new ArgumentException("记录ID不能为空且必须大于0", nameof(parm.Id));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(parm.Workorder))
|
||||
{
|
||||
throw new ArgumentException("成品工单号不能为空", nameof(parm.Workorder));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(parm.Operator))
|
||||
{
|
||||
throw new ArgumentException("领料人不能为空", nameof(parm.Operator));
|
||||
}
|
||||
|
||||
if (parm.Quantity <= 0)
|
||||
{
|
||||
throw new ArgumentException("领料数量必须大于0", nameof(parm.Quantity));
|
||||
}
|
||||
|
||||
// 默认值设置
|
||||
if (string.IsNullOrEmpty(parm.InboundNo))
|
||||
{
|
||||
// 尝试从入库记录中获取入库单号
|
||||
var inboundInfo = Queryable().Where(x => x.Id == parm.Id).First();
|
||||
if (inboundInfo != null)
|
||||
{
|
||||
parm.InboundNo = inboundInfo.InboundNo;
|
||||
}
|
||||
else
|
||||
{
|
||||
parm.InboundNo = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
// 确保WorkorderRaw和Workorder字段的正确设置
|
||||
// 这里Workorder已经通过验证,确保不为空
|
||||
// WorkorderRaw将在TakeMaterial方法中从入库记录中获取并保持不变
|
||||
|
||||
return parm;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 异常处理
|
||||
throw new Exception($"初始化领料记录失败: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化入库记录数据(适用于成品入库和原材料入库)
|
||||
/// </summary>
|
||||
/// <param name="inboundRecord">入库记录对象</param>
|
||||
/// <param name="currentWorkorder">当前操作工单号</param>
|
||||
/// <param name="rawMaterialWorkorder">原材料工单号(如果有)</param>
|
||||
/// <returns>初始化后的入库记录对象</returns>
|
||||
/// <exception cref="ArgumentException">参数验证异常</exception>
|
||||
public MmRecordInbound InitializeProductStorageRecord(MmRecordInbound inboundRecord, string currentWorkorder, string rawMaterialWorkorder = null)
|
||||
{
|
||||
// 参数验证
|
||||
if (inboundRecord == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(inboundRecord), "入库记录对象不能为空");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(currentWorkorder))
|
||||
{
|
||||
throw new ArgumentException("当前操作工单号不能为空", nameof(currentWorkorder));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(inboundRecord.MaterialCode))
|
||||
{
|
||||
throw new ArgumentException("物料编码不能为空");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(inboundRecord.WarehouseCode))
|
||||
{
|
||||
throw new ArgumentException("仓库编码不能为空");
|
||||
}
|
||||
|
||||
if (inboundRecord.Quantity <= 0)
|
||||
{
|
||||
throw new ArgumentException("入库数量必须大于0");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(inboundRecord.TransactionType))
|
||||
{
|
||||
throw new ArgumentException("入库类型不能为空");
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
if (string.IsNullOrWhiteSpace(inboundRecord.InboundNo))
|
||||
{
|
||||
// 生成入库单号:IN + 年月日时分秒
|
||||
inboundRecord.InboundNo = "IN" + DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
}
|
||||
|
||||
if (inboundRecord.CreatedTime == null)
|
||||
{
|
||||
inboundRecord.CreatedTime = DateTime.Now;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(inboundRecord.Unit))
|
||||
{
|
||||
inboundRecord.Unit = "个";
|
||||
}
|
||||
|
||||
// 字段使用规范:
|
||||
// WorkorderRaw:永久性记录原材料最初关联的工单号信息,保持不变
|
||||
// Workorder:动态记录当前操作环节所对应的工单号,根据实际业务操作场景实时更新
|
||||
if (!string.IsNullOrWhiteSpace(rawMaterialWorkorder))
|
||||
{
|
||||
// 如果提供了原材料工单号,设置为WorkorderRaw
|
||||
inboundRecord.WorkorderRaw = rawMaterialWorkorder;
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(inboundRecord.WorkorderRaw))
|
||||
{
|
||||
// 如果没有提供原材料工单号且WorkorderRaw为空,则使用当前工单号作为初始值
|
||||
inboundRecord.WorkorderRaw = currentWorkorder;
|
||||
}
|
||||
// 注意:如果WorkorderRaw已经有值,保持不变,确保其在整个生命周期中保持恒定
|
||||
|
||||
// 更新当前操作工单号
|
||||
inboundRecord.Workorder = currentWorkorder;
|
||||
|
||||
return inboundRecord;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建并初始化入库记录
|
||||
/// </summary>
|
||||
/// <param name="inboundRecord">入库记录对象</param>
|
||||
/// <param name="currentWorkorder">当前操作工单号</param>
|
||||
/// <param name="rawMaterialWorkorder">原材料工单号(如果有)</param>
|
||||
/// <returns>创建的入库记录对象</returns>
|
||||
public MmRecordInbound CreateAndInitializeProductStorageRecord(MmRecordInbound inboundRecord, string currentWorkorder, string rawMaterialWorkorder = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 初始化入库记录数据
|
||||
var initializedRecord = InitializeProductStorageRecord(inboundRecord, currentWorkorder, rawMaterialWorkorder);
|
||||
|
||||
// 保存到数据库
|
||||
return Insertable(initializedRecord).ExecuteReturnEntity();
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
// 处理参数验证异常
|
||||
throw new Exception($"入库记录初始化失败:{ex.Message}", ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 处理其他异常
|
||||
throw new Exception($"创建入库记录失败:{ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user