diff --git a/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs b/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs
index a947d04..84d5006 100644
--- a/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs
+++ b/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs
@@ -612,6 +612,10 @@ namespace DOAN.Admin.WebApi.Controllers
}
var response = _ProWorkorderMaterialService.ShipProduct(request);
+ if (!response)
+ {
+ return ToResponse(new ApiResult(500, "出货失败!"));
+ }
return SUCCESS(response);
}
catch (Exception ex)
diff --git a/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs b/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs
index c68cab3..496b62a 100644
--- a/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs
+++ b/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs
@@ -58,9 +58,10 @@ namespace DOAN.Model.MES.product.Dto
public string Unit { get; set; }
- public int? PlanNum { get; set; } = 0;
- public int? ShipmentNum { get; set; } = 0;
- public int? DefectNum { get; set; } = 0;
+ public int PlanNum { get; set; } = 0;
+ public int ShipmentNum { get; set; } = 0;
+ public int ProductNum { get; set; } = 0;
+ public int DefectNum { get; set; } = 0;
public int? Sort { get; set; }
public DateTime? WorkorderDate { get; set; }
diff --git a/DOAN.Model/MES/Product/ProWorkorder.cs b/DOAN.Model/MES/Product/ProWorkorder.cs
index 4ae36e5..fdca62b 100644
--- a/DOAN.Model/MES/Product/ProWorkorder.cs
+++ b/DOAN.Model/MES/Product/ProWorkorder.cs
@@ -39,20 +39,26 @@ namespace DOAN.Model.MES.product
/// 计划数量
///
[SugarColumn(ColumnName = "plan_num")]
- public int? PlanNum { get; set; }
+ public int PlanNum { get; set; } = 0;
///
/// 出货数量
///
[SugarColumn(ColumnName = "shipment_num")]
- public int? ShipmentNum { get; set; }
+ public int ShipmentNum { get; set; } = 0;
///
/// 缺陷数量
///
[SugarColumn(ColumnName = "defect_num")]
- public int? DefectNum { get; set; }
+ public int DefectNum { get; set; } = 0;
+
+ ///
+ /// 成品入库数量
+ ///
+ [SugarColumn(ColumnName = "product_num")]
+ public int ProductNum { get; set; } = 0;
///
/// 序号
diff --git a/DOAN.Service/MES/Material/MmInventoryService.cs b/DOAN.Service/MES/Material/MmInventoryService.cs
index 4985de9..7107173 100644
--- a/DOAN.Service/MES/Material/MmInventoryService.cs
+++ b/DOAN.Service/MES/Material/MmInventoryService.cs
@@ -907,7 +907,7 @@ namespace DOAN.Service.BZFM
{
return $"此记录已撤销过,不可重复撤销";
}
- //做出库红单
+ //做入库红单
InboundReceiptDto revokeRecepitDto = new()
{
ReceiptType = 2,
@@ -925,16 +925,36 @@ namespace DOAN.Service.BZFM
Remarks = $"撤销操作,入库单号:{recordInbound.InboundNo}",
};
string result = CreateInboundReceipt(revokeRecepitDto);
- if (result == "ok")
- {
- recordInbound.Remarks = "已撤销";
- Context.Updateable(recordInbound).ExecuteCommand();
- return result;
- }
- else
+ if (result != "ok")
{
return result;
}
+ // 如果是成品入库则还要减少工单记录数量
+ Context.Ado.BeginTran();
+ if (recordInbound.TransactionType == "生产入库")
+ {
+ var workorderInfo = Context
+ .Queryable()
+ .Where(it => it.Workorder == recordInbound.Workorder)
+ .First();
+ if (workorderInfo == null)
+ {
+ Context.Ado.RollbackTran();
+ return "工单不存在";
+ }
+ // 数量调整
+ workorderInfo.ProductNum -= Math.Abs((int)recordInbound.Quantity);
+ if (workorderInfo.ProductNum < 0)
+ {
+ workorderInfo.ProductNum = 0;
+ }
+ Context.Updateable(workorderInfo).ExecuteCommand();
+ }
+
+ recordInbound.Remarks = "已撤销";
+ Context.Updateable(recordInbound).ExecuteCommand();
+ Context.Ado.CommitTran();
+ return result;
}
else
{
@@ -950,7 +970,7 @@ namespace DOAN.Service.BZFM
{
return $"此记录已撤销过,不可重复撤销";
}
-
+
//做出库红单
OutboundReceiptDto revokeRecepitDto = new()
{
@@ -968,11 +988,11 @@ namespace DOAN.Service.BZFM
Remarks = $"撤销操作,出库单号:{recordOutbound.OutboundNo}",
};
string result = CreateOutboundReceipt(revokeRecepitDto);
- if(result != "ok")
+ if (result != "ok")
{
return result;
}
- // 如果是出货则还要减少出货单库存
+ // 如果是出货则还要减少出货单库存和工单出货数量
Context.Ado.BeginTran();
if (recordOutbound.TransactionType == "出货出库")
{
@@ -995,19 +1015,19 @@ namespace DOAN.Service.BZFM
Context.Ado.RollbackTran();
return "订单号不存在";
}
- Context
- .Updateable()
- .Where(it => it.Workorder == recordOutbound.Workorder)
- .SetColumns(it => it.ShipmentNum == 0)
- .SetColumns(it => it.CustomerOrder == string.Empty)
- .ExecuteCommand();
+ // 数量调整
+ workorderInfo.ShipmentNum -= Math.Abs((int)recordOutbound.Quantity);
+ if (workorderInfo.ShipmentNum < 0)
+ {
+ workorderInfo.ShipmentNum = 0;
+ }
+ workorderInfo.CustomerOrder = string.Empty;
+ Context.Updateable(workorderInfo).ExecuteCommand();
// 修改采购订单是否完成
- int newQuantity =
- Context
- .Queryable()
- .Where(it => it.CustomerOrder == orderPurchase.OrderNoMes)
- .Sum(it => it.ShipmentNum)
- ?? 0;
+ int newQuantity = Context
+ .Queryable()
+ .Where(it => it.CustomerOrder == orderPurchase.OrderNoMes)
+ .Sum(it => it.ShipmentNum);
orderPurchase.DeliveryQuantity = newQuantity;
if (orderPurchase.DeliveryQuantity > orderPurchase.DemandQuantity)
{
@@ -1198,7 +1218,7 @@ namespace DOAN.Service.BZFM
.First();
// 计算累计出货数量(使用delta值,考虑单据类型的影响)
- int currentShipmentNum = workorderInfo.ShipmentNum ?? 0;
+ int currentShipmentNum = workorderInfo.ShipmentNum;
int newShipmentNum = currentShipmentNum + (int)delta;
// 验证出货数量有效性
@@ -1223,12 +1243,10 @@ namespace DOAN.Service.BZFM
.First();
if (orderPurchase != null)
{
- int newQuantity =
- Context
- .Queryable()
- .Where(it => it.CustomerOrder == parm.CustomerOrder)
- .Sum(it => it.ShipmentNum)
- ?? 0;
+ int newQuantity = Context
+ .Queryable()
+ .Where(it => it.CustomerOrder == parm.CustomerOrder)
+ .Sum(it => it.ShipmentNum);
orderPurchase.DeliveryQuantity = newQuantity;
if (orderPurchase.DeliveryQuantity > orderPurchase.DemandQuantity)
diff --git a/DOAN.Service/MES/Product/ProWorkorderMaterialService.cs b/DOAN.Service/MES/Product/ProWorkorderMaterialService.cs
index c1586b3..e06c39d 100644
--- a/DOAN.Service/MES/Product/ProWorkorderMaterialService.cs
+++ b/DOAN.Service/MES/Product/ProWorkorderMaterialService.cs
@@ -377,13 +377,33 @@ namespace DOAN.Service.MES.product
customerOrder,
worker
);
+ if (result == 0)
+ {
+ throw new Exception("数据库操作失败");
+ }
+ if (result == 2)
+ {
+ throw new Exception("订单号不存在");
+ }
+ if (result == 3)
+ {
+ throw new Exception("订单超额");
+ }
+ if (result == 4)
+ {
+ throw new Exception("工单不存在");
+ }
+ if (result == 5)
+ {
+ throw new Exception("主体型号和订单物料不匹配");
+ }
return result == 1;
}
catch (Exception ex)
{
// 集成现有系统的日志记录
// Log.Error("出货操作失败", ex);
- throw;
+ throw new Exception(ex.Message);
}
}
@@ -429,8 +449,8 @@ namespace DOAN.Service.MES.product
productionCode = mri.MaterialName,
MaterialCode = mri.MaterialCode,
MaterialName = mri.MaterialName,
- ShipmentNum = pro.ShipmentNum ?? 0,
- PlanNum = pro.PlanNum ?? 0,
+ ShipmentNum = pro.ShipmentNum,
+ PlanNum = pro.PlanNum,
Remark01 = mri.Remarks
},
true
diff --git a/DOAN.Service/MES/SmartScreen/Product/ProductSmartScreenService.cs b/DOAN.Service/MES/SmartScreen/Product/ProductSmartScreenService.cs
index a26128b..68e9cc1 100644
--- a/DOAN.Service/MES/SmartScreen/Product/ProductSmartScreenService.cs
+++ b/DOAN.Service/MES/SmartScreen/Product/ProductSmartScreenService.cs
@@ -49,7 +49,7 @@ namespace DOAN.Service.MES.SmartScreen.Product
digital.ProductionPlanQuantity = Context
.Queryable()
.Where(it => it.WorkorderDate == DateTime.Today)
- .Sum(it => it.PlanNum ?? 0);
+ .Sum(it => it.PlanNum);
//digital.ProductionFinishQuantity = Context.Queryable().Where(it => it.JobDateTime >= DateTime.Today && it.JobDateTime < DateTime.Today.AddDays(1))
// .Where(it => it.ProcessId == 90).Sum(it => it.FinishNum??0);
diff --git a/DOAN.Service/Mobile/ReportFlowService.cs b/DOAN.Service/Mobile/ReportFlowService.cs
index b803dd4..5426c41 100644
--- a/DOAN.Service/Mobile/ReportFlowService.cs
+++ b/DOAN.Service/Mobile/ReportFlowService.cs
@@ -171,7 +171,7 @@ public class ReportFlowService : BaseService, IReportFlowServic
Context.Ado.RollbackTran();
throw new Exception($"原材料工单无成品入库记录:{workorderRaw}");
}
- int newShipmentNum = (proWorkorderRawInfo.ShipmentNum ?? 0) + finish_num;
+ int newShipmentNum = (proWorkorderRawInfo.ShipmentNum) + finish_num;
if (newShipmentNum > inboundRecord.Quantity)
{
Context.Ado.RollbackTran();
@@ -341,12 +341,6 @@ public class ReportFlowService : BaseService, IReportFlowServic
}
if (process == 70)
{
- MmRecordInbound inboundRecord = Context
- .Queryable()
- .Where(it => it.Workorder == workorder)
- .Where(it => it.TransactionType == "生产入库")
- .Where(it => it.Remarks != "已撤销")
- .First();
MmMaterial mmMaterial = Context
.Queryable()
.Where(it => it.MaterialCode == proWorkorder.productionCode)
@@ -358,7 +352,9 @@ public class ReportFlowService : BaseService, IReportFlowServic
$"物料档案不存在,无法成品入库:{proWorkorder.productionCode}"
);
}
- if (inboundRecord == null)
+
+ proWorkorder.ProductNum += finish_num;
+ if (proWorkorder.PlanNum >= proWorkorder.ProductNum)
{
//做生产入库单
// 暂时默认成品入库与出库批次号都为000
@@ -387,11 +383,12 @@ public class ReportFlowService : BaseService, IReportFlowServic
Context.Ado.RollbackTran();
throw new Exception(createReceiptresult);
}
+ Context.Updateable(proWorkorder).ExecuteCommand();
}
else
{
Context.Ado.RollbackTran();
- throw new Exception("重新成品入库前请先撤销已有物料生产入库记录!");
+ throw new Exception("成品入库数超出计划数!");
}
}
Context.Ado.CommitTran();
@@ -503,13 +500,9 @@ public class ReportFlowService : BaseService, IReportFlowServic
}
// XXX 成品库出库
- MmRecordOutbound outboundDto = Context
- .Queryable()
- .Where(it => it.Workorder == workorder)
- .Where(it => it.TransactionType == "出货出库")
- .Where(it => it.Remarks != "已撤销")
- .First();
- if (outboundDto == null)
+ // 需要保证已入库数大于等于已出货数+现在要出货的数量
+ workorderInfo.ShipmentNum += finish_num;
+ if (workorderInfo.ProductNum >= workorderInfo.ShipmentNum)
{
// Todo找还有库存的成品库
@@ -541,23 +534,16 @@ public class ReportFlowService : BaseService, IReportFlowServic
else
{
Context.Ado.RollbackTran();
- throw new Exception("重新出货前请先撤销物料出货出库记录");
+ throw new Exception("出货数超出工单成品入库数!");
}
-
+ workorderInfo.CustomerOrder = customer_order;
// 修改工单信息
- Context
- .Updateable()
- .Where(it => it.Workorder == workorder)
- .SetColumns(it => it.ShipmentNum == finish_num)
- .SetColumns(it => it.CustomerOrder == customer_order)
- .ExecuteCommand();
+ Context.Updateable(workorderInfo).ExecuteCommand();
// 修改采购订单是否完成
- int newQuantity =
- Context
- .Queryable()
- .Where(it => it.CustomerOrder == customer_order)
- .Sum(it => it.ShipmentNum)
- ?? 0;
+ int newQuantity = Context
+ .Queryable()
+ .Where(it => it.CustomerOrder == customer_order)
+ .Sum(it => it.ShipmentNum);
orderPurchase.DeliveryQuantity = newQuantity;
if (orderPurchase.DeliveryQuantity > orderPurchase.DemandQuantity)
{
@@ -577,10 +563,10 @@ public class ReportFlowService : BaseService, IReportFlowServic
Context.Ado.CommitTran();
return result > 0 ? 1 : 0;
}
- catch (Exception)
+ catch (Exception ex)
{
Context.Ado.RollbackTran();
- throw;
+ throw new Exception(ex.Message);
}
}