From dd049ceeed2b73af076096af5a0b42363b2ccf13 Mon Sep 17 00:00:00 2001
From: zhoukeda <1315948824@qq.com>
Date: Tue, 11 Jul 2023 14:39:34 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E5=A4=87=E4=BB=B6=E9=A2=86=E7=94=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Consts/CodeTemplateConst.cs | 5 +
.../Entity/EqpSparePartsInstockD.cs | 52 +++++++
.../Entity/EqpSparePartsInstockH.cs | 82 +++++++++++
.../Entity/EqpSparePartsRequisitionD.cs | 47 ++++++
.../Entity/EqpSparePartsRequisitionH.cs | 87 ++++++++++++
.../IEqpSparePartsRequisitionHService.cs | 10 ++
.../EqpSparePartsRequisitionHService.cs | 134 ++++++++++++++++++
7 files changed, 417 insertions(+)
create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockD.cs
create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockH.cs
create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionD.cs
create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionH.cs
create mode 100644 EquipMgr/Tnb.EquipMgr.Interfaces/IEqpSparePartsRequisitionHService.cs
create mode 100644 EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs
diff --git a/BasicData/Tnb.BasicData.Entities/Consts/CodeTemplateConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/CodeTemplateConst.cs
index a62d9c12..96890e79 100644
--- a/BasicData/Tnb.BasicData.Entities/Consts/CodeTemplateConst.cs
+++ b/BasicData/Tnb.BasicData.Entities/Consts/CodeTemplateConst.cs
@@ -19,5 +19,10 @@ namespace Tnb.BasicData
/// 生产任务单号单据模板编码
///
public const string PRDMOTASK_CODE = "ProductionPlanAndSchedule";
+
+ ///
+ /// 备件领用
+ ///
+ public const string SPAREPARTSREQUISITION_CODE = "SparePartsRequisition";
}
}
\ No newline at end of file
diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockD.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockD.cs
new file mode 100644
index 00000000..9797a1a9
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockD.cs
@@ -0,0 +1,52 @@
+using JNPF.Common.Contracts;
+using JNPF.Common.Security;
+using SqlSugar;
+
+namespace Tnb.EquipMgr.Entities;
+
+///
+/// 备件入库子表
+///
+[SugarTable("eqp_spare_parts_instock_d")]
+public partial class EqpSparePartsInstockD : BaseEntity
+{
+ public EqpSparePartsInstockD()
+ {
+ id = SnowflakeIdHelper.NextId();
+ }
+ ///
+ /// 备件入库单id
+ ///
+ public string? instock_id { get; set; }
+
+ ///
+ /// 备件id
+ ///
+ public string? spare_parts_id { get; set; }
+
+ ///
+ /// 入库数量
+ ///
+ public int quantity { get; set; }
+
+ ///
+ /// 库位id
+ ///
+ public string? location_id { get; set; }
+
+ ///
+ /// 质保开始时间
+ ///
+ public DateTime? warranty_start_time { get; set; }
+
+ ///
+ /// 质保结束时间
+ ///
+ public DateTime? warranty_end_time { get; set; }
+
+ ///
+ /// 已领数量
+ ///
+ public int use_quantity { get; set; }
+
+}
\ No newline at end of file
diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockH.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockH.cs
new file mode 100644
index 00000000..46754943
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsInstockH.cs
@@ -0,0 +1,82 @@
+using JNPF.Common.Contracts;
+using JNPF.Common.Security;
+using SqlSugar;
+
+namespace Tnb.EquipMgr.Entities;
+
+///
+/// 备件入库
+///
+[SugarTable("eqp_spare_parts_instock_h")]
+public partial class EqpSparePartsInstockH : BaseEntity
+{
+ public EqpSparePartsInstockH()
+ {
+ id = SnowflakeIdHelper.NextId();
+ }
+ ///
+ /// 入库单编号
+ ///
+ public string? code { get; set; }
+
+ ///
+ /// 入库时间
+ ///
+ public string? instock_time { get; set; }
+
+ ///
+ /// 入库人员
+ ///
+ public string? instock_id { get; set; }
+
+ ///
+ /// 库位号
+ ///
+ public string? location_id { get; set; }
+
+ ///
+ /// 备件id
+ ///
+ public string? spare_parts_id { get; set; }
+
+ ///
+ /// 描述
+ ///
+ public string? descrip { get; set; }
+
+ ///
+ /// 创建用户
+ ///
+ public string? create_id { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ public DateTime? create_time { get; set; }
+
+ ///
+ /// 修改用户
+ ///
+ public string? modify_id { get; set; }
+
+ ///
+ /// 修改时间
+ ///
+ public DateTime? modify_time { get; set; }
+
+ ///
+ /// 所属组织
+ ///
+ public string? org_id { get; set; }
+
+ ///
+ /// 流程任务Id
+ ///
+ public string? f_flowtaskid { get; set; }
+
+ ///
+ /// 流程引擎Id
+ ///
+ public string? f_flowid { get; set; }
+
+}
\ No newline at end of file
diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionD.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionD.cs
new file mode 100644
index 00000000..e3fef537
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionD.cs
@@ -0,0 +1,47 @@
+using JNPF.Common.Contracts;
+using JNPF.Common.Security;
+using SqlSugar;
+
+namespace Tnb.EquipMgr.Entities;
+
+///
+/// 备件领用子表
+///
+[SugarTable("eqp_spare_parts_requisition_d")]
+public partial class EqpSparePartsRequisitionD : BaseEntity
+{
+ public EqpSparePartsRequisitionD()
+ {
+ id = SnowflakeIdHelper.NextId();
+ }
+ ///
+ /// 备件id
+ ///
+ public string spare_parts_id { get; set; } = string.Empty;
+
+ ///
+ /// 批号
+ ///
+ public string? batch { get; set; }
+
+ ///
+ /// 数量
+ ///
+ public int quantity { get; set; }
+
+ ///
+ /// 备件领用主表id
+ ///
+ public string spare_parts_requisition_id { get; set; } = string.Empty;
+
+ ///
+ /// 设备id
+ ///
+ public string? equip_id { get; set; }
+
+ ///
+ /// 备件入库id
+ ///
+ public string? instock_detail_id { get; set; }
+
+}
\ No newline at end of file
diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionH.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionH.cs
new file mode 100644
index 00000000..2eac0c08
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSparePartsRequisitionH.cs
@@ -0,0 +1,87 @@
+using JNPF.Common.Contracts;
+using JNPF.Common.Security;
+using SqlSugar;
+
+namespace Tnb.EquipMgr.Entities;
+
+///
+/// 备件领用主表
+///
+[SugarTable("eqp_spare_parts_requisition_h")]
+public partial class EqpSparePartsRequisitionH : BaseEntity
+{
+ public EqpSparePartsRequisitionH()
+ {
+ id = SnowflakeIdHelper.NextId();
+ }
+ ///
+ /// 领用单编号
+ ///
+ public string? code { get; set; }
+
+ ///
+ /// 作用设备id
+ ///
+ public string? equip_id { get; set; }
+
+ ///
+ /// 使用部门
+ ///
+ public string? department { get; set; }
+
+ ///
+ /// 领用目的
+ ///
+ public string? requisition_purpose { get; set; }
+
+ ///
+ /// 库位号
+ ///
+ public string? location_id { get; set; }
+
+ ///
+ /// 备件id
+ ///
+ public string? spare_parts_id { get; set; }
+
+ ///
+ /// 领用人
+ ///
+ public string? recipient_id { get; set; }
+
+ ///
+ /// 创建用户
+ ///
+ public string? create_id { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ public DateTime? create_time { get; set; }
+
+ ///
+ /// 修改用户
+ ///
+ public string? modify_id { get; set; }
+
+ ///
+ /// 修改时间
+ ///
+ public DateTime? modify_time { get; set; }
+
+ ///
+ /// 所属组织
+ ///
+ public string? org_id { get; set; }
+
+ ///
+ /// 流程任务Id
+ ///
+ public string? f_flowtaskid { get; set; }
+
+ ///
+ /// 流程引擎Id
+ ///
+ public string? f_flowid { get; set; }
+
+}
\ No newline at end of file
diff --git a/EquipMgr/Tnb.EquipMgr.Interfaces/IEqpSparePartsRequisitionHService.cs b/EquipMgr/Tnb.EquipMgr.Interfaces/IEqpSparePartsRequisitionHService.cs
new file mode 100644
index 00000000..85b1bb7a
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Interfaces/IEqpSparePartsRequisitionHService.cs
@@ -0,0 +1,10 @@
+namespace Tnb.EquipMgr.Interfaces
+{
+ ///
+ /// 备品备件领用服务
+ ///
+ public interface IEqpSparePartsRequisitionHService
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs b/EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs
new file mode 100644
index 00000000..66a40260
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs
@@ -0,0 +1,134 @@
+using JNPF.Common.Core.Manager;
+using JNPF.Common.Dtos.VisualDev;
+using JNPF.Common.Enums;
+using JNPF.Common.Security;
+using JNPF.DependencyInjection;
+using JNPF.DynamicApiController;
+using JNPF.FriendlyException;
+using JNPF.Systems.Interfaces.System;
+using JNPF.VisualDev;
+using JNPF.VisualDev.Entitys;
+using JNPF.VisualDev.Interfaces;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.ClearScript.Util.Web;
+using SqlSugar;
+using Tnb.EquipMgr.Entities;
+using Tnb.EquipMgr.Entities.Dto;
+using Tnb.EquipMgr.Interfaces;
+
+namespace Tnb.EquipMgr
+{
+ ///
+ /// 备品备件领用服务
+ ///
+ [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
+ [Route("api/[area]/[controller]/[action]")]
+ [OverideVisualDev(ModuleId)]
+ public class EqpSparePartsRequisitionHService : IEqpSparePartsRequisitionHService, IOverideVisualDevService,IDynamicApiController, ITransient
+ {
+ private const string ModuleId = "27338205223957";
+ private readonly ISqlSugarRepository _repository;
+ private readonly IVisualDevService _visualDevService;
+ private readonly IRunService _runService;
+ private readonly IUserManager _userManager;
+ private readonly IBillRullService _billRuleService;
+
+ public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
+
+ public EqpSparePartsRequisitionHService(ISqlSugarRepository repository,
+ IRunService runService,
+ IVisualDevService visualDevService,
+ IBillRullService billRuleService,
+ IUserManager userManager)
+ {
+ _repository = repository;
+ _visualDevService = visualDevService;
+ _runService = runService;
+ _userManager = userManager;
+ _billRuleService = billRuleService;
+ OverideFuncs.CreateAsync = Create;
+ }
+
+ private async Task Create(VisualDevModelDataCrInput input)
+ {
+ var db = _repository.AsSugarClient();
+ DbResult result = await db.Ado.UseTranAsync(async () =>
+ {
+ // VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
+ // await _runService.Create(templateEntity, input);
+ var code = await _billRuleService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.SPAREPARTSREQUISITION_CODE);
+ EqpSparePartsRequisitionH eqpSparePartsRequisitionH = new EqpSparePartsRequisitionH()
+ {
+ code = code,
+ equip_id = input.data.ContainsKey("equip_id") ? input.data["equip_id"].ToString() : "",
+ department = input.data.ContainsKey("department") ? input.data["department"].ToString() : "",
+ recipient_id = input.data.ContainsKey("recipient_id") ? input.data["recipient_id"].ToString() : "",
+ requisition_purpose = input.data.ContainsKey("requisition_purpose") ? input.data["requisition_purpose"].ToString() : "",
+ create_id = _userManager.UserId,
+ create_time = DateTime.Now,
+ org_id = _userManager.GetUserInfo().Result.organizeId,
+ };
+
+ await db.Insertable(eqpSparePartsRequisitionH).ExecuteCommandAsync();
+
+ if (input.data.TryGetValue("tablefield120", out var value))
+ {
+ var details = value.ToObject>>();
+ List eqpSparePartsList = new List();
+ List eqpSparePartsRequisitionDs = new List(){};
+ foreach (var detail in details)
+ {
+ string instockDetailId = detail.ContainsKey("instock_detail_id") ? detail["instock_detail_id"] : "";
+ string sparePartsId = detail.ContainsKey("spare_parts_id") ? detail["spare_parts_id"] : "";
+ int quantity = Convert.ToInt32(detail.ContainsKey("quantity") ? detail["quantity"] : "");
+
+ eqpSparePartsRequisitionDs.Add(new EqpSparePartsRequisitionD
+ {
+ instock_detail_id = instockDetailId,
+ spare_parts_id = sparePartsId,
+ quantity = quantity,
+ equip_id = eqpSparePartsRequisitionH.equip_id,
+ spare_parts_requisition_id = eqpSparePartsRequisitionH.id,
+ });
+
+ if (await db.Queryable()
+ .AnyAsync(x => x.id == instockDetailId && (x.quantity - x.use_quantity - quantity) >= 0))
+ {
+ eqpSparePartsList.Add(new EqpEquipSpareParts
+ {
+ equip_id = input.data["equip_id"]?.ToString() ?? "",
+ spare_parts_id = sparePartsId,
+ create_id = _userManager.UserId,
+ create_time = DateTime.Now,
+ org_id = _userManager.GetUserInfo().Result.organizeId
+ });
+
+ await db.Updateable()
+ .SetColumns(x => x.use_quantity == x.use_quantity + quantity)
+ .Where(x => x.id == instockDetailId).ExecuteCommandAsync();
+ }
+ else
+ {
+ throw new Exception("库存不够");
+ }
+
+ }
+
+ if (eqpSparePartsRequisitionDs.Count > 0)
+ {
+ await db.Insertable(eqpSparePartsRequisitionDs).ExecuteCommandAsync();
+ }
+
+ if (eqpSparePartsList.Count > 0)
+ {
+ await db.Insertable(eqpSparePartsList).ExecuteCommandAsync();
+ }
+ }
+
+ });
+
+ if (!result.IsSuccess) throw Oops.Bah(result.ErrorMessage);
+ return result.IsSuccess ? "保存成功" : result.ErrorMessage;
+ }
+ }
+}
\ No newline at end of file
From 252ae13496241df71731946cda3227648bb42b8c Mon Sep 17 00:00:00 2001
From: zhoukeda <1315948824@qq.com>
Date: Tue, 11 Jul 2023 15:36:23 +0800
Subject: [PATCH 2/2] bug
---
BasicData/Tnb.BasicData/BasMbomService.cs | 559 +++++++++---------
.../Tnb.ProductionMgr/PrdMoTaskService.cs | 28 +-
2 files changed, 296 insertions(+), 291 deletions(-)
diff --git a/BasicData/Tnb.BasicData/BasMbomService.cs b/BasicData/Tnb.BasicData/BasMbomService.cs
index 48152663..787c8bbf 100644
--- a/BasicData/Tnb.BasicData/BasMbomService.cs
+++ b/BasicData/Tnb.BasicData/BasMbomService.cs
@@ -237,280 +237,281 @@ namespace Tnb.BasicData
})
.ToListAsync();
}
- ///
- /// 保存生产bom
- ///
- ///
- ///
- [HttpPost]
- public async Task SaveData(MbomSaveDataInput mbomSaveDataInput)
- {
- ErrorCode errorCode = ErrorCode.COM1008;
- DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
- {
- //新增
- if (string.IsNullOrEmpty(mbomSaveDataInput.id))
- {
- string mbomId = SnowflakeIdHelper.NextId();
- string orgId = _userManager.GetUserInfo().Result.organizeId;
- BasMbom mbom = new BasMbom()
- {
- id = mbomId,
- org_id = orgId,
- material_id = mbomSaveDataInput.material_id,
- num = mbomSaveDataInput.num,
- unit_id = mbomSaveDataInput.unit_id,
- version = mbomSaveDataInput.version,
- start_time = mbomSaveDataInput.start_time,
- end_time = mbomSaveDataInput.end_time,
- ebom_id = mbomSaveDataInput.ebom_id,
- route_id = mbomSaveDataInput.route_id,
- is_first = mbomSaveDataInput.is_first,
- remark = mbomSaveDataInput.remark,
- create_id = _userManager.UserId,
- create_time = DateTime.Now,
-
- };
-
- if (await _repository.IsAnyAsync(x =>
- x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version))
- {
- errorCode = ErrorCode.COM1004;
- throw Oops.Oh(ErrorCode.COM1004);
- }
- await _repository.InsertAsync(mbom);
- List processes = new List();
- List inputs = new List();
- List outputs = new List();
-
- if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
- {
- int index = 0;
- foreach (var process in mbomSaveDataInput.processes)
- {
- string mbomProcessId = SnowflakeIdHelper.NextId();
- processes.Add(new BasMbomProcess()
- {
- id = mbomProcessId,
- org_id = orgId,
- mbom_id = mbomId,
- process_id = process?.process_id ?? "",
- preparation_time = process?.preparation_time ?? 0,
- station = process?.station ?? "",
- byproduct_status = process?.byproduct_status ?? 0,
- production_method = process?.production_method,
- route_detail_id = process?.route_detail_id ?? "",
- ordinal = ++index,
- is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0,
-
- });
-
- if (process!.inputs != null)
- {
- foreach (var input in process.inputs)
- {
- string inputId = SnowflakeIdHelper.NextId();
- inputs.Add(new BasMbomInput()
- {
- id = inputId,
- mbom_id = mbomId,
- mbom_process_id = mbomProcessId,
- process_id = process?.process_id ?? "",
- material_id = input.material_id,
- num = input.num,
- org_id = orgId,
- });
- }
- }
-
- if (process.outputs != null)
- {
- foreach (var output in process.outputs)
- {
- string outputId = SnowflakeIdHelper.NextId();
- outputs.Add(new BasMbomOutput()
- {
- id = outputId,
- mbom_id = mbomId,
- mbom_process_id = mbomProcessId,
- process_id = process?.process_id ?? "",
- material_id = output.material_id,
- num = output.num,
- org_id = orgId,
- });
- }
- }
- }
- }
-
- if (processes.Count > 0)
- {
- await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync();
- }
-
- if (inputs.Count > 0)
- {
- await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync();
- }
-
- if (outputs.Count > 0)
- {
- await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync();
- }
- }
- else//修改
- {
- if (await _repository.IsAnyAsync(x =>
- x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version && x.id != mbomSaveDataInput.id))
- {
- errorCode = ErrorCode.COM1004;
- throw Oops.Oh(ErrorCode.COM1004);
- }
-
- string orgId = _userManager.GetUserInfo().Result.organizeId;
- if (mbomSaveDataInput != null)
- {
- await _repository.UpdateAsync(x => new BasMbom()
- {
- // org_id = orgId,
- material_id = mbomSaveDataInput.material_id,
- num = mbomSaveDataInput.num,
- unit_id = mbomSaveDataInput.unit_id,
- version = mbomSaveDataInput.version,
- start_time = mbomSaveDataInput.start_time,
- end_time = mbomSaveDataInput.end_time,
- ebom_id = mbomSaveDataInput.ebom_id,
- route_id = mbomSaveDataInput.route_id,
- is_first = mbomSaveDataInput.is_first,
- remark = mbomSaveDataInput.remark,
- modify_id = _userManager.UserId,
- modify_time = DateTime.Now,
-
- }, x => x.id == mbomSaveDataInput.id);
- }
- // List processes = new List();
- List inputs = new List();
- List outputs = new List();
-
- if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
- {
- foreach (var process in mbomSaveDataInput.processes)
- {
- string mbomProcessId = process.id;
- // string mbomProcessId = SnowflakeIdHelper.NextId();
- // processes.Add(new BasMbomProcess()
- // {
- // id = mbomProcessId,
- // org_id = orgId ?? "",
- // mbom_id = mbomSaveDataInput?.id ?? "",
- // process_id = process?.process_id ?? "",
- // preparation_time = process?.preparation_time ?? 0,
- // station = process.station,
- // byproduct_status = process.byproduct_status,
- // production_method = process.production_method,
- // route_detail_id = process.route_detail_id,
- //
- // });
-
- decimal preparation_time = process?.preparation_time ?? 0;
- await _repository.AsSugarClient().Updateable()
- .SetColumns(x => x.preparation_time == preparation_time)
- .SetColumns(x => x.station == process!.station)
- .SetColumns(x => x.byproduct_status == process!.byproduct_status)
- .SetColumns(x => x.production_method == process!.production_method)
- .Where(x => x.id == process!.id).ExecuteCommandAsync();
-
- if (process!.inputs != null)
- {
- foreach (var input in process.inputs)
- {
- string inputId = SnowflakeIdHelper.NextId();
- inputs.Add(new BasMbomInput()
- {
- id = inputId,
- mbom_id = mbomSaveDataInput?.id ?? "",
- mbom_process_id = mbomProcessId,
- process_id = process?.process_id ?? "",
- material_id = input.material_id,
- num = input.num,
- org_id = orgId,
- });
- }
- }
-
- if (process.outputs != null)
- {
- foreach (var output in process.outputs)
- {
- string outputId = SnowflakeIdHelper.NextId();
- outputs.Add(new BasMbomOutput()
- {
- id = outputId,
- mbom_id = mbomSaveDataInput?.id ?? "",
- mbom_process_id = mbomProcessId,
- process_id = process?.process_id ?? "",
- material_id = output.material_id,
- num = output.num,
- org_id = orgId,
- });
- }
- }
-
- }
- }
-
- if (mbomSaveDataInput != null && !string.IsNullOrEmpty(mbomSaveDataInput.id))
- {
- // await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
- await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
- await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
- }
- // if (processes.Count > 0)
- // {
- // await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync();
- // }
-
- if (inputs.Count > 0)
- {
- await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync();
- }
-
- if (outputs.Count > 0)
- {
- await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync();
- }
- }
-
- });
-
- if (!result.IsSuccess)
- {
- if (!string.IsNullOrEmpty(mbomSaveDataInput.id))
- {
- if (errorCode != ErrorCode.COM1004)
- {
- throw Oops.Oh(ErrorCode.COM1001);
- }
- else
- {
- throw Oops.Oh(errorCode);
- }
- }
- else
- {
- if (errorCode != ErrorCode.COM1004)
- {
- throw Oops.Oh(ErrorCode.COM1000);
- }
- else
- {
- throw Oops.Oh(errorCode);
- }
- }
-
- }
- return result.IsSuccess ? "保存成功" : result.ErrorMessage;
- }
+
+ // ///
+ // /// 保存生产bom
+ // ///
+ // ///
+ // ///
+ // [HttpPost]
+ // public async Task SaveData(MbomSaveDataInput mbomSaveDataInput)
+ // {
+ // ErrorCode errorCode = ErrorCode.COM1008;
+ // DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
+ // {
+ // //新增
+ // if (string.IsNullOrEmpty(mbomSaveDataInput.id))
+ // {
+ // string mbomId = SnowflakeIdHelper.NextId();
+ // string orgId = _userManager.GetUserInfo().Result.organizeId;
+ // BasMbom mbom = new BasMbom()
+ // {
+ // id = mbomId,
+ // org_id = orgId,
+ // material_id = mbomSaveDataInput.material_id,
+ // num = mbomSaveDataInput.num,
+ // unit_id = mbomSaveDataInput.unit_id,
+ // version = mbomSaveDataInput.version,
+ // start_time = mbomSaveDataInput.start_time,
+ // end_time = mbomSaveDataInput.end_time,
+ // ebom_id = mbomSaveDataInput.ebom_id,
+ // route_id = mbomSaveDataInput.route_id,
+ // is_first = mbomSaveDataInput.is_first,
+ // remark = mbomSaveDataInput.remark,
+ // create_id = _userManager.UserId,
+ // create_time = DateTime.Now,
+ //
+ // };
+ //
+ // if (await _repository.IsAnyAsync(x =>
+ // x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version))
+ // {
+ // errorCode = ErrorCode.COM1004;
+ // throw Oops.Oh(ErrorCode.COM1004);
+ // }
+ // await _repository.InsertAsync(mbom);
+ // List processes = new List();
+ // List inputs = new List();
+ // List outputs = new List();
+ //
+ // if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
+ // {
+ // int index = 0;
+ // foreach (var process in mbomSaveDataInput.processes)
+ // {
+ // string mbomProcessId = SnowflakeIdHelper.NextId();
+ // processes.Add(new BasMbomProcess()
+ // {
+ // id = mbomProcessId,
+ // org_id = orgId,
+ // mbom_id = mbomId,
+ // process_id = process?.process_id ?? "",
+ // preparation_time = process?.preparation_time ?? 0,
+ // station = process?.station ?? "",
+ // byproduct_status = process?.byproduct_status ?? 0,
+ // production_method = process?.production_method,
+ // route_detail_id = process?.route_detail_id ?? "",
+ // ordinal = ++index,
+ // is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0,
+ //
+ // });
+ //
+ // if (process!.inputs != null)
+ // {
+ // foreach (var input in process.inputs)
+ // {
+ // string inputId = SnowflakeIdHelper.NextId();
+ // inputs.Add(new BasMbomInput()
+ // {
+ // id = inputId,
+ // mbom_id = mbomId,
+ // mbom_process_id = mbomProcessId,
+ // process_id = process?.process_id ?? "",
+ // material_id = input.material_id,
+ // num = input.num,
+ // org_id = orgId,
+ // });
+ // }
+ // }
+ //
+ // if (process.outputs != null)
+ // {
+ // foreach (var output in process.outputs)
+ // {
+ // string outputId = SnowflakeIdHelper.NextId();
+ // outputs.Add(new BasMbomOutput()
+ // {
+ // id = outputId,
+ // mbom_id = mbomId,
+ // mbom_process_id = mbomProcessId,
+ // process_id = process?.process_id ?? "",
+ // material_id = output.material_id,
+ // num = output.num,
+ // org_id = orgId,
+ // });
+ // }
+ // }
+ // }
+ // }
+ //
+ // if (processes.Count > 0)
+ // {
+ // await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync();
+ // }
+ //
+ // if (inputs.Count > 0)
+ // {
+ // await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync();
+ // }
+ //
+ // if (outputs.Count > 0)
+ // {
+ // await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync();
+ // }
+ // }
+ // else//修改
+ // {
+ // if (await _repository.IsAnyAsync(x =>
+ // x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version && x.id != mbomSaveDataInput.id))
+ // {
+ // errorCode = ErrorCode.COM1004;
+ // throw Oops.Oh(ErrorCode.COM1004);
+ // }
+ //
+ // string orgId = _userManager.GetUserInfo().Result.organizeId;
+ // if (mbomSaveDataInput != null)
+ // {
+ // await _repository.UpdateAsync(x => new BasMbom()
+ // {
+ // // org_id = orgId,
+ // material_id = mbomSaveDataInput.material_id,
+ // num = mbomSaveDataInput.num,
+ // unit_id = mbomSaveDataInput.unit_id,
+ // version = mbomSaveDataInput.version,
+ // start_time = mbomSaveDataInput.start_time,
+ // end_time = mbomSaveDataInput.end_time,
+ // ebom_id = mbomSaveDataInput.ebom_id,
+ // route_id = mbomSaveDataInput.route_id,
+ // is_first = mbomSaveDataInput.is_first,
+ // remark = mbomSaveDataInput.remark,
+ // modify_id = _userManager.UserId,
+ // modify_time = DateTime.Now,
+ //
+ // }, x => x.id == mbomSaveDataInput.id);
+ // }
+ // // List processes = new List();
+ // List inputs = new List();
+ // List outputs = new List();
+ //
+ // if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
+ // {
+ // foreach (var process in mbomSaveDataInput.processes)
+ // {
+ // string mbomProcessId = process.id;
+ // // string mbomProcessId = SnowflakeIdHelper.NextId();
+ // // processes.Add(new BasMbomProcess()
+ // // {
+ // // id = mbomProcessId,
+ // // org_id = orgId ?? "",
+ // // mbom_id = mbomSaveDataInput?.id ?? "",
+ // // process_id = process?.process_id ?? "",
+ // // preparation_time = process?.preparation_time ?? 0,
+ // // station = process.station,
+ // // byproduct_status = process.byproduct_status,
+ // // production_method = process.production_method,
+ // // route_detail_id = process.route_detail_id,
+ // //
+ // // });
+ //
+ // decimal preparation_time = process?.preparation_time ?? 0;
+ // await _repository.AsSugarClient().Updateable()
+ // .SetColumns(x => x.preparation_time == preparation_time)
+ // .SetColumns(x => x.station == process!.station)
+ // .SetColumns(x => x.byproduct_status == process!.byproduct_status)
+ // .SetColumns(x => x.production_method == process!.production_method)
+ // .Where(x => x.id == process!.id).ExecuteCommandAsync();
+ //
+ // if (process!.inputs != null)
+ // {
+ // foreach (var input in process.inputs)
+ // {
+ // string inputId = SnowflakeIdHelper.NextId();
+ // inputs.Add(new BasMbomInput()
+ // {
+ // id = inputId,
+ // mbom_id = mbomSaveDataInput?.id ?? "",
+ // mbom_process_id = mbomProcessId,
+ // process_id = process?.process_id ?? "",
+ // material_id = input.material_id,
+ // num = input.num,
+ // org_id = orgId,
+ // });
+ // }
+ // }
+ //
+ // if (process.outputs != null)
+ // {
+ // foreach (var output in process.outputs)
+ // {
+ // string outputId = SnowflakeIdHelper.NextId();
+ // outputs.Add(new BasMbomOutput()
+ // {
+ // id = outputId,
+ // mbom_id = mbomSaveDataInput?.id ?? "",
+ // mbom_process_id = mbomProcessId,
+ // process_id = process?.process_id ?? "",
+ // material_id = output.material_id,
+ // num = output.num,
+ // org_id = orgId,
+ // });
+ // }
+ // }
+ //
+ // }
+ // }
+ //
+ // if (mbomSaveDataInput != null && !string.IsNullOrEmpty(mbomSaveDataInput.id))
+ // {
+ // // await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
+ // await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
+ // await _repository.AsSugarClient().Deleteable().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
+ // }
+ // // if (processes.Count > 0)
+ // // {
+ // // await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync();
+ // // }
+ //
+ // if (inputs.Count > 0)
+ // {
+ // await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync();
+ // }
+ //
+ // if (outputs.Count > 0)
+ // {
+ // await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync();
+ // }
+ // }
+ //
+ // });
+ //
+ // if (!result.IsSuccess)
+ // {
+ // if (!string.IsNullOrEmpty(mbomSaveDataInput.id))
+ // {
+ // if (errorCode != ErrorCode.COM1004)
+ // {
+ // throw Oops.Oh(ErrorCode.COM1001);
+ // }
+ // else
+ // {
+ // throw Oops.Oh(errorCode);
+ // }
+ // }
+ // else
+ // {
+ // if (errorCode != ErrorCode.COM1004)
+ // {
+ // throw Oops.Oh(ErrorCode.COM1000);
+ // }
+ // else
+ // {
+ // throw Oops.Oh(errorCode);
+ // }
+ // }
+ //
+ // }
+ // return result.IsSuccess ? "保存成功" : result.ErrorMessage;
+ // }
///
/// 保存生产bom
@@ -573,13 +574,13 @@ namespace Tnb.BasicData
preparation_time = process?.preparation_time ?? 0,
station = process?.station ?? "",
byproduct_status = process!.byproduct_status,
- production_method = process!.production_method,
- route_detail_id = process!.route_detail_id,
+ production_method = process.production_method,
+ route_detail_id = process.route_detail_id,
ordinal = ++index,
- is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0,
+ is_last = string.IsNullOrEmpty(process.next_process_no) ? 1 : 0,
no = process!.no,
- last_process_no = process!.last_process_no,
- next_process_no = process!.next_process_no,
+ last_process_no = process.last_process_no,
+ next_process_no = process.next_process_no,
});
diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs
index f78051c0..4ac5daf9 100644
--- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs
+++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs
@@ -1278,20 +1278,24 @@ namespace Tnb.ProductionMgr
.SetColumns(x => x.reported_work_qty == x.reported_work_qty + input.reported_qty)
.Where(x => x.id == input.mo_task_id).ExecuteCommandAsync();
}
- var mbomProcess = await db.Queryable().SingleAsync(x => x.id == prdMoTask.mbom_process_id);
- if (mbomProcess.is_last==1 && prdMoTask != null && !string.IsNullOrEmpty(prdMoTask.parent_id))
+
+ if (prdMoTask.schedule_type == 2 && !string.IsNullOrEmpty(prdMoTask.mbom_process_id))
{
- var parentMoTask = await db.Queryable().SingleAsync(x => x.id == prdMoTask.parent_id);
- if (parentMoTask?.last_process_complete_qty == null)
+ var mbomProcess = await db.Queryable().SingleAsync(x => x.id == prdMoTask.mbom_process_id);
+ if (mbomProcess.is_last==1 && prdMoTask != null && !string.IsNullOrEmpty(prdMoTask.parent_id))
{
- await db.Updateable()
- .SetColumns(x => x.last_process_complete_qty == input.reported_qty)
- .Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync();
- }else if (parentMoTask?.last_process_complete_qty != null)
- {
- await db.Updateable()
- .SetColumns(x => x.last_process_complete_qty == x.last_process_complete_qty + input.reported_qty)
- .Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync();
+ var parentMoTask = await db.Queryable().SingleAsync(x => x.id == prdMoTask.parent_id);
+ if (parentMoTask?.last_process_complete_qty == null)
+ {
+ await db.Updateable()
+ .SetColumns(x => x.last_process_complete_qty == input.reported_qty)
+ .Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync();
+ }else if (parentMoTask?.last_process_complete_qty != null)
+ {
+ await db.Updateable()
+ .SetColumns(x => x.last_process_complete_qty == x.last_process_complete_qty + input.reported_qty)
+ .Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync();
+ }
}
}