diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/ProducttListOutput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/ProducttListOutput.cs
new file mode 100644
index 00000000..f4561ecb
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/ProducttListOutput.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tnb.EquipMgr.Entities.Dto
+{
+ ///
+ /// 产品列表输出类
+ ///
+ public class ProductListOutput
+ {
+ public string id { get; set; }
+ public string product_code { get; set; }
+ public string product_name { get; set; }
+ public string product_standard { get; set; }
+ public string product_group { get; set; }
+ public int real_cavity_qty { get; set; }
+ }
+ ///
+ /// 模具列表输出类
+ ///
+ public class MoldListOutput
+ {
+ public string id { get; set; }
+ public string mold_code { get; set; }
+ public string mold_name { get; set; }
+ public int cavity_qty { get; set; }
+ public int real_cavity_qty { get; set; }
+ }
+}
diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/ToolMoldInput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/ToolMoldInput.cs
new file mode 100644
index 00000000..5b7ea819
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/ToolMoldInput.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tnb.EquipMgr.Entities.Dto
+{
+ public class ToolMoldInput
+ {
+ public string mold { get; set; }
+ public string[] equipid { get; set; }
+ public string productid { get; set; }
+ public int real_cavity_qty { get; set; }
+ public string[] productids { get; set; }
+
+ public string[] molds { get; set; }
+ }
+
+}
diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/BasProduct.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/BasProduct.cs
new file mode 100644
index 00000000..d6ff9f62
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/BasProduct.cs
@@ -0,0 +1,128 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+using Tnb.Common.Contracts;
+
+namespace Tnb.EquipMgr.Entities.Entity
+{ ///
+ ///产品信息
+ ///
+ [SugarTable("bas_product")]
+ public partial class BasProduct : BaseEntity
+ {
+ public BasProduct()
+ {
+
+
+ }
+
+ ///
+ /// Desc:产品分类ID
+ /// Default:
+ /// Nullable:False
+ ///
+ public string categoryid { get; set; }
+
+ ///
+ /// Desc:关联比例
+ /// Default:
+ /// Nullable:True
+ ///
+ public decimal? relation_ratio { get; set; }
+
+ ///
+ /// Desc:创建时间
+ /// Default:
+ /// Nullable:True
+ ///
+ public DateTime? create_time { get; set; }
+
+ ///
+ /// Desc:修改时间
+ /// Default:
+ /// Nullable:True
+ ///
+ public DateTime? modify_time { get; set; }
+
+ ///
+ /// Desc:扩展字段
+ /// Default:
+ /// Nullable:True
+ ///
+ public string extras { get; set; }
+
+ ///
+ /// Desc:所属组织
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string org_id { get; set; }
+
+ ///
+ /// Desc:产品规格型号
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string product_standard { get; set; }
+
+ ///
+ /// Desc:产品类型: 半成品:SemiManufacture 成品:FinishedProduct
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string product_type { get; set; }
+
+ ///
+ /// Desc:物料ID,BAS_MATERIAL.ID
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string material_id { get; set; }
+
+ ///
+ /// Desc:备注
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string remark { get; set; }
+
+ ///
+ /// Desc:时间戳(用于并发控制)
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string timestamp { get; set; }
+
+ ///
+ /// Desc:创建用户
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string create_id { get; set; }
+
+ ///
+ /// Desc:修改用户
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string modify_id { get; set; }
+
+ ///
+ /// Desc:产品名称
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string product_name { get; set; }
+
+ ///
+ /// Desc:产品代码
+ /// Default:
+ /// Nullable:False
+ ///
+ public string product_code { get; set; }
+
+ }
+}
diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMolds.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMolds.cs
new file mode 100644
index 00000000..c3ea7e12
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMolds.cs
@@ -0,0 +1,192 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+using Tnb.Common.Contracts;
+
+namespace Tnb.EquipMgr.Entities.Entity
+{
+ ///
+ ///模具信息表
+ ///
+ [SugarTable("tool_molds")]
+ public partial class ToolMolds : BaseEntity
+ {
+ public ToolMolds()
+ {
+
+
+ }
+ ///
+ /// Desc:模穴数
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? mold_cavity { get; set; }
+
+
+ ///
+ /// Desc:生产模数
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? production_modulus { get; set; }
+
+ ///
+ /// Desc:日定额
+ /// Default:
+ /// Nullable:True
+ ///
+ public decimal? daily_rate { get; set; }
+
+ ///
+ /// Desc:工时定额(H/PCS)
+ /// Default:
+ /// Nullable:True
+ ///
+ public decimal? hour_norm { get; set; }
+
+ ///
+ /// Desc:成长周期
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? growth_cycle { get; set; }
+
+ ///
+ /// Desc:模具寿命
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? mold_life { get; set; }
+
+ ///
+ /// Desc:备注
+ /// Default:
+ /// Nullable:True
+ ///
+ public string remark { get; set; }
+
+ ///
+ /// Desc:模具编号
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string mold_code { get; set; }
+
+ ///
+ /// Desc:模具名称
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string mold_name { get; set; }
+
+ ///
+ /// Desc:设备Id
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string eqp_id { get; set; }
+
+ ///
+ /// Desc:设备代码
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string eqp_code { get; set; }
+
+ ///
+ /// Desc:磨具使用状态
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string mold_status { get; set; }
+
+ ///
+ /// Desc:保养模次
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? maintain_qty { get; set; }
+
+ ///
+ /// Desc:型腔数
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? cavity_qty { get; set; }
+
+ ///
+ /// Desc:创建时间
+ /// Default:
+ /// Nullable:True
+ ///
+ public DateTime? create_time { get; set; }
+
+ ///
+ /// Desc:修改时间
+ /// Default:
+ /// Nullable:True
+ ///
+ public DateTime? modify_time { get; set; }
+
+ ///
+ /// Desc:扩展字段
+ /// Default:
+ /// Nullable:True
+ ///
+ public string extras { get; set; }
+
+ ///
+ /// Desc:模具剩余寿命
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string mold_remaining_life { get; set; }
+
+ ///
+ /// Desc:库房编号
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string warehosue_id { get; set; }
+
+ ///
+ /// Desc:库位编号
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string location_id { get; set; }
+
+ ///
+ /// Desc:创建用户
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string create_id { get; set; }
+
+ ///
+ /// Desc:修改用户
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string modify_id { get; set; }
+
+ ///
+ /// Desc:模具型号
+ /// Default:
+ /// Nullable:True
+ ///
+ public string mold_type_code { get; set; }
+
+ ///
+ /// Desc:物料Id
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string material_id { get; set; }
+
+ }
+}
diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldsEquipment.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldsEquipment.cs
new file mode 100644
index 00000000..d3739642
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldsEquipment.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+using Tnb.Common.Contracts;
+
+namespace Tnb.EquipMgr.Entities.Entity
+{
+ //
+ ///模具设备关联表
+ ///
+ [SugarTable("tool_molds_equipment")]
+ public partial class ToolMoldsEquipment : BaseEntity
+ {
+ public ToolMoldsEquipment() { }
+
+ ///
+ /// Desc:模具编号
+ /// Default:
+ /// Nullable:False
+ ///
+ public string mold_id { get; set; }
+
+ ///
+ /// Desc:设备编号
+ /// Default:
+ /// Nullable:False
+ ///
+ public string equipment_id { get; set; }
+
+ ///
+ /// Desc:创建用户
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string create_id { get; set; }
+
+ ///
+ /// Desc:创建时间
+ /// Default:
+ /// Nullable:False
+ ///
+ public DateTime create_time { get; set; }
+
+ ///
+ /// Desc:修改用户
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string modify_id { get; set; }
+
+ ///
+ /// Desc:修改时间
+ /// Default:
+ /// Nullable:True
+ ///
+ public DateTime? modify_time { get; set; }
+
+
+ }
+}
diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldsProduct.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldsProduct.cs
new file mode 100644
index 00000000..452adec2
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldsProduct.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+using Tnb.Common.Contracts;
+
+namespace Tnb.EquipMgr.Entities.Entity
+{
+ ///
+ ///模具产品关联表
+ ///
+ [SugarTable("tool_molds_product")]
+ public partial class ToolMoldsProduct : BaseEntity
+ {
+ public ToolMoldsProduct()
+ {
+
+
+ }
+
+ ///
+ /// Desc:模具编号
+ /// Default:
+ /// Nullable:False
+ ///
+ public string mold_id { get; set; }
+
+ ///
+ /// Desc:产品编号
+ /// Default:
+ /// Nullable:False
+ ///
+ public string product_id { get; set; }
+
+ ///
+ /// Desc:创建时间
+ /// Default:
+ /// Nullable:False
+ ///
+ public DateTime create_time { get; set; }
+
+ ///
+ /// Desc:创建用户
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string create_id { get; set; }
+
+ ///
+ /// Desc:修改用户
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string modify_id { get; set; }
+
+ ///
+ /// Desc:修改时间
+ /// Default:
+ /// Nullable:True
+ ///
+ public DateTime? modify_time { get; set; }
+
+ ///
+ /// Desc:实际使用型腔数
+ /// Default:
+ /// Nullable:True
+ ///
+ public int? real_cavity_qty { get; set; }
+ ///
+ /// Desc:产品同组标识
+ /// Default:NULL::character varying
+ /// Nullable:True
+ ///
+ public string product_group { get; set; }
+ }
+}
diff --git a/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldProductService.cs b/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldProductService.cs
new file mode 100644
index 00000000..b7768fe7
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldProductService.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+using Tnb.EquipMgr.Entities.Dto;
+
+namespace Tnb.EquipMgr.Interfaces
+{
+ public interface IToolMoldProductService
+ {
+ ///
+ /// 根据模具id获取设备集合
+ ///
+ ///
+ ///
+ public Task> GetProductLists(ToolMoldInput ToolMoldInput);
+ ///
+ /// 增加模具产品绑定
+ ///
+ ///
+ ///
+ ///
+ ///
+ public Task SaveData(ToolMoldInput ToolMoldInput);
+ ///
+ /// 批量删除模具产品绑定
+ ///
+ ///
+ ///
+ ///
+ public Task DetachMoldData(ToolMoldInput ToolMoldInput);
+ ///
+ /// 产品同组
+ ///
+ ///
+ ///
+ ///
+ public Task SaveProductGroup(ToolMoldInput ToolMoldInput);
+ ///
+ /// 取消产品同组
+ ///
+ ///
+ ///
+ ///
+ public Task CancelProductGroup(ToolMoldInput ToolMoldInput);
+
+ ///
+ /// 根据产品id获取模具集合
+ ///
+ ///
+ ///
+ public Task> GetMoldLists(ToolMoldInput ToolMoldInput);
+ ///
+ /// 批量删除产品模具绑定
+ ///
+ ///
+ ///
+ ///
+
+ public Task DetachProductData(ToolMoldInput ToolMoldInput);
+ }
+}
diff --git a/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldsService.cs b/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldsService.cs
new file mode 100644
index 00000000..18539dc2
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr.Interfaces/IToolMoldsService.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tnb.EquipMgr.Entities.Dto;
+
+namespace Tnb.EquipMgr.Interfaces
+{
+ public interface IToolMoldsService
+ {
+ ///
+ /// 根据模具id获取设备集合
+ ///
+ ///
+ ///
+ public Task> GetEquipmentLists(ToolMoldInput ToolMoldInput);
+ ///
+ /// 增加模具设备绑定
+ ///
+ ///
+ ///
+ ///
+ public Task SaveData(ToolMoldInput ToolMoldInput);
+ ///
+ /// 批量删除模具设备绑定
+ ///
+ ///
+ ///
+ ///
+ public Task DetachData(ToolMoldInput ToolMoldInput);
+ }
+}
diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldProductService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldProductService.cs
new file mode 100644
index 00000000..aa357dcd
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr/ToolMoldProductService.cs
@@ -0,0 +1,192 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Aspose.Cells.Drawing;
+using JNPF.Common.Core.Manager;
+using JNPF.Common.Enums;
+using JNPF.Common.Security;
+using JNPF.DependencyInjection;
+using JNPF.DynamicApiController;
+using JNPF.FriendlyException;
+using Microsoft.AspNetCore.Mvc;
+using SqlSugar;
+using Tnb.EquipMgr.Entities;
+using Tnb.EquipMgr.Entities.Dto;
+using Tnb.EquipMgr.Entities.Entity;
+using Tnb.EquipMgr.Interfaces;
+
+namespace Tnb.EquipMgr
+{
+ [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
+ [Route("api/[area]/[controller]/[action]")]
+ public class ToolMoldProductService : IToolMoldProductService, IDynamicApiController, ITransient
+ {
+ private readonly IUserManager _userManager;
+ private readonly ISqlSugarRepository _repository;
+ public ToolMoldProductService(IUserManager userManager, ISqlSugarRepository repository)
+ {
+ _userManager = userManager;
+ _repository = repository;
+ }
+ ///
+ /// 根据模具id获取产品集合
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task> GetProductLists(ToolMoldInput ToolMoldInput)
+ {
+ var db = _repository.AsSugarClient();
+ var list = await db.Queryable((a, b) => new object[]
+ {
+ JoinType.Inner, a.id == b.product_id,
+ })
+ .Where((a, b) => b.mold_id == ToolMoldInput.mold)
+ .Select((a, b) => new ProductListOutput
+ {
+ id = a.id,
+ product_code = a.product_code,
+ product_name = a.product_name,
+ product_standard = a.product_standard,
+ product_group=b.product_group,
+ real_cavity_qty = b.real_cavity_qty.HasValue ? b.real_cavity_qty.Value : 0
+ }).ToListAsync();
+ return list;
+ }
+ ///
+ /// 增加模具产品绑定
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task SaveData(ToolMoldInput ToolMoldInput)
+ {
+ DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
+ {
+ var ToolMoldsProduct= await _repository.AsSugarClient().Queryable().Where(p=>p.mold_id== ToolMoldInput.mold&&p.product_id== ToolMoldInput.productid).FirstAsync();
+ if (ToolMoldsProduct == null)
+ {
+ var entity = new ToolMoldsProduct();
+ entity.id = SnowflakeIdHelper.NextId();
+ entity.mold_id = ToolMoldInput.mold;
+ entity.product_id = ToolMoldInput.productid;
+ entity.real_cavity_qty = ToolMoldInput.real_cavity_qty;
+ entity.create_time = DateTime.Now;
+ entity.create_id = _userManager.UserId;
+ await _repository.AsSugarClient().Insertable(entity).ExecuteCommandAsync();
+ }
+ else {
+ ToolMoldsProduct.real_cavity_qty= ToolMoldInput.real_cavity_qty;
+ await _repository.AsSugarClient().Updateable(ToolMoldsProduct).ExecuteCommandAsync();
+ }
+
+
+ });
+ if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
+ return result.IsSuccess ? "保存成功" : result.ErrorMessage;
+
+
+ }
+ ///
+ /// 批量删除模具产品绑定
+ ///
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task DetachMoldData(ToolMoldInput ToolMoldInput)
+ {
+ DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
+ {
+ var arr = _repository.AsSugarClient().Queryable().Where(x => x.mold_id == ToolMoldInput.mold && ToolMoldInput.productids.Contains(x.product_id)).ToList();
+ await _repository.AsSugarClient().Deleteable(arr).ExecuteCommandAsync();
+
+ });
+ if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
+ return result.IsSuccess ? "操作成功" : result.ErrorMessage;
+ }
+ ///
+ /// 产品同组
+ ///
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task SaveProductGroup(ToolMoldInput ToolMoldInput)
+ {
+ DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
+ {
+ var arr = _repository.AsSugarClient().Queryable().Where(x => x.mold_id == ToolMoldInput.mold && ToolMoldInput.productids.Contains(x.product_id)).ToList();
+ var sign = SnowflakeIdHelper.NextId();
+ arr.ForEach(p => { p.product_group = sign; });
+ await _repository.AsSugarClient().Updateable(arr).ExecuteCommandAsync();
+
+ });
+ if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
+ return result.IsSuccess ? "操作成功" : result.ErrorMessage;
+ }
+ ///
+ /// 取消产品同组
+ ///
+ ///
+ ///
+ ///
+ public async Task CancelProductGroup(ToolMoldInput ToolMoldInput)
+ {
+ DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
+ {
+ var arr = _repository.AsSugarClient().Queryable().Where(x => x.mold_id == ToolMoldInput.mold && ToolMoldInput.productids.Contains(x.product_id)).ToList();
+ arr.ForEach(p => { p.product_group = string.Empty; });
+ await _repository.AsSugarClient().Updateable(arr).ExecuteCommandAsync();
+
+ });
+ if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
+ return result.IsSuccess ? "操作成功" : result.ErrorMessage;
+ }
+ ///
+ /// 根据产品id获取模具集合
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task> GetMoldLists(ToolMoldInput ToolMoldInput)
+ {
+ var db = _repository.AsSugarClient();
+ var list = await db.Queryable((a, b) => new object[]
+ {
+ JoinType.Inner, a.id == b.mold_id,
+ })
+ .Where((a, b) => b.product_id == ToolMoldInput.productid)
+ .Select((a, b) => new MoldListOutput
+ {
+ id = a.id,
+ mold_code = a.mold_code,
+ mold_name = a.mold_name,
+ cavity_qty = a.cavity_qty.HasValue ? a.cavity_qty.Value : 0,
+ real_cavity_qty = b.real_cavity_qty.HasValue ? b.real_cavity_qty.Value : 0
+ }).ToListAsync();
+ return list;
+ }
+ ///
+ /// 批量删除产品模具绑定
+ ///
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task DetachProductData(ToolMoldInput ToolMoldInput)
+ {
+ DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
+ {
+ var arr = _repository.AsSugarClient().Queryable().Where(x => ToolMoldInput.molds.Contains(x.mold_id) && x.product_id == ToolMoldInput.productid).ToList();
+ await _repository.AsSugarClient().Deleteable(arr).ExecuteCommandAsync();
+ });
+ if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
+ return result.IsSuccess ? "操作成功" : result.ErrorMessage;
+ }
+ }
+}
diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldsService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldsService.cs
new file mode 100644
index 00000000..0c5c02e5
--- /dev/null
+++ b/EquipMgr/Tnb.EquipMgr/ToolMoldsService.cs
@@ -0,0 +1,108 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Aop.Api.Domain;
+using Aspose.Cells.Drawing;
+using JNPF.Common.Core.Manager;
+using JNPF.Common.Enums;
+using JNPF.Common.Filter;
+using JNPF.Common.Security;
+using JNPF.DependencyInjection;
+using JNPF.DynamicApiController;
+using JNPF.FriendlyException;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+using SqlSugar;
+using Tnb.EquipMgr.Entities;
+using Tnb.EquipMgr.Entities.Dto;
+using Tnb.EquipMgr.Entities.Entity;
+using Tnb.EquipMgr.Interfaces;
+
+namespace Tnb.EquipMgr
+{ ///
+ /// 模具管理
+ ///
+ [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
+ [Route("api/[area]/[controller]/[action]")]
+ public class ToolMoldsService : IToolMoldsService, IDynamicApiController, ITransient
+ {
+ private readonly IUserManager _userManager;
+ private readonly ISqlSugarRepository _repository;
+ public ToolMoldsService(IUserManager userManager, ISqlSugarRepository repository)
+ {
+ _userManager = userManager;
+ _repository = repository;
+ }
+ ///
+ /// 根据模具id获取设备集合
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task> GetEquipmentLists(ToolMoldInput ToolMoldInput)
+ {
+ var db = _repository.AsSugarClient();
+ var list = await db.Queryable((a, b) => new object[]
+ {
+ JoinType.Inner, a.id == b.equipment_id,
+ })
+ .Where((a, b) => b.mold_id == ToolMoldInput.mold)
+ .Select((a, b) => new EquipmentListOutput
+ {
+ id = a.id,
+ eqp_code=a.code,
+ eqp_name=a.name
+ }).ToListAsync();
+ return list;
+ }
+ ///
+ /// 增加模具设备绑定
+ ///
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task SaveData(ToolMoldInput ToolMoldInput)
+ {
+ DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
+ {
+ var list = new List();
+ foreach (var equip in ToolMoldInput.equipid)
+ {
+ var entity = new ToolMoldsEquipment();
+ entity.id = SnowflakeIdHelper.NextId();
+ entity.mold_id = ToolMoldInput.mold;
+ entity.equipment_id = equip;
+ entity.create_time = DateTime.Now;
+ entity.create_id = _userManager.UserId;
+ list.Add(entity);
+ }
+ await _repository.AsSugarClient().Insertable(list).ExecuteCommandAsync();
+ });
+ if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
+ return result.IsSuccess ? "保存成功" : result.ErrorMessage;
+
+
+ }
+ ///
+ /// 批量删除模具设备绑定
+ ///
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task DetachData(ToolMoldInput ToolMoldInput)
+ {
+ DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
+ {
+ var arr = _repository.AsSugarClient().Queryable().Where(x => x.mold_id == ToolMoldInput.mold && ToolMoldInput.equipid.Contains(x.equipment_id)).ToList();
+ await _repository.AsSugarClient().Deleteable(arr).ExecuteCommandAsync();
+
+ });
+ if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
+ return result.IsSuccess ? "操作成功" : result.ErrorMessage;
+ }
+ }
+}
diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs
index baed56c1..ad2901da 100644
--- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs
+++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs
@@ -10,14 +10,6 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
/// 组装、包装排产输入参数
///
public class PackSchedlingCrInput
- {
- ///
- /// bom任务集合
- ///
- public List items{ get; set; }
- }
-
- public class PackSchedlingItem
{
///
/// 工单Id
@@ -28,10 +20,6 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
///
public string bom_id { get; set; }
///
- /// 工序id
- ///
- public string process_id { get; set; }
- ///
/// 产线Id
///
public string workline_id { get; set; }
@@ -39,21 +27,26 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
/// 物料Id
///
public string material_id { get; set; }
+
///
- /// 生产任务单号
+ /// 排产数量
///
- public string mo_task_code { get; set; }
+ public string scheduled_qty { get; set; }
+
///
- /// 物料编码
- ///
- public string material_code { get; set; }
+ /// Desc:预计开始时间
+ /// Default:
+ /// Nullable:True
+ ///
+ public DateTime estimated_start_date { get; set; }
+
///
- /// 物料名称
- ///
- public string material_name { get; set; }
- ///
- /// bom产出料数量
- ///
- public string qty { get; set; }
+ /// Desc:预计结束时间
+ /// Default:
+ /// Nullable:True
+ ///
+ public DateTime estimated_end_date { get; set; }
+
+
}
}
diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs
new file mode 100644
index 00000000..5413c2e7
--- /dev/null
+++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.DirectoryServices.Protocols;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
+{
+ ///
+ /// 组装、包装生产任务待下发输出参数列表
+ ///
+ public class PackSechelToBeIssueListOutput
+ {
+ ///
+ /// 生产任务ID
+ ///
+ public string mo_task_id { get; set; }
+ ///
+ /// 生产任务编号
+ ///
+ public string mo_task_code { get; set; }
+ ///
+ /// 物料编号
+ ///
+ public string material_code { get; set; }
+ ///
+ /// 物料名称
+ ///
+ public string material_name { get; set; }
+ ///
+ /// 产线编号
+ ///
+ public string workline_code { get; set; }
+ ///
+ /// 产线名称
+ ///
+ public string workline_name { get; set; }
+ ///
+ /// 任务单状态
+ ///
+ public string mo_task_status { get; set; }
+ ///
+ /// 生产任务数量
+ ///
+ public int scheduled_qty { get; set; }
+ ///
+ /// 计划数量
+ ///
+ public int plan_qty { get; set; }
+ ///
+ /// 工序任务量
+ ///
+ public int process_task_qty { get; set; }
+
+ }
+}
diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoTaskOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoTaskOutput.cs
index e419ce92..dc48353f 100644
--- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoTaskOutput.cs
+++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoTaskOutput.cs
@@ -47,6 +47,14 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
///
public string eqp_type_code { get; set; }
///
+ /// 产线编码
+ ///
+ public string workline_code { get; set; }
+ ///
+ /// 产线名称
+ ///
+ public string workline_name { get; set; }
+ ///
/// 任务单数量
///
public int mo_task_qty { get; set; }
diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs
index c9b236bd..74d97ddb 100644
--- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs
+++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs
@@ -93,6 +93,10 @@ namespace DbModels
///
[SugarColumn(IsPrimaryKey = true)]
public string id { get; set; }
+ ///
+ /// 父任务ID
+ ///
+ public string parent_id { get; set; }
///
/// Desc:生产任务编号
@@ -229,6 +233,10 @@ namespace DbModels
///
[SugarColumn(IsIgnore = true)]
public int mold_cavity_qty { get; set; }
+ ///
+ /// 工序任务量
+ ///
+ public int process_task_qty { get; set; }
}
diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdTaskLog.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdTaskLog.cs
index bf099d85..28792475 100644
--- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdTaskLog.cs
+++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdTaskLog.cs
@@ -108,6 +108,12 @@ namespace Tnb.ProductionMgr.Entities
/// 任务单编号
///
public string mo_task_code { get; set; }
+ ///
+ /// 产线Code
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public string workline_code { get; set; }
+
}
}
diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs
index 0e56704d..79d2f067 100644
--- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs
+++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs
@@ -34,6 +34,7 @@ using Senparc.Weixin.MP.AdvancedAPIs.Card;
using Aspose.Cells.Drawing.Texts;
using JNPF.Systems.Entitys.Permission;
using WebSocketSharp.Frame;
+using JNPF.Logging;
namespace Tnb.ProductionMgr
{
@@ -344,40 +345,130 @@ namespace Tnb.ProductionMgr
///
}
///
[HttpGet("{moId}")]
- public async Task GetPrdTaskInfoByMoId(string moId)
+ public async Task GetPrdTaskInfoByMoId(string moId, int schedType = 1)
{
+ List result = new();
var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId);
- var result = await _db.Queryable().LeftJoin((a, b) => a.mo_id == b.id)
- .LeftJoin((a, b, c) => a.material_id == c.id)
- .LeftJoin((a, b, c, d) => a.mold_id == d.id)
- .LeftJoin((a, b, c, d, e) => a.eqp_id == e.id)
- .Where((a, b, c, d, e) => a.mo_id == moId)
- .Select((a, b, c, d, e) => new PrdMoTaskOutput
- {
- mo_task_code = a.mo_task_code,
- mo_task_status = a.mo_task_status,
- mold_code = d.mold_code,
- mold_name = d.mold_name,
- material_code = c.code,
- material_name = c.name,
- eqp_code = e.code,
- eqp_name = e.name,
- eqp_type_code = SqlFunc.Subqueryable().Where(it => it.id == e.equip_type_id).Select(it => it.code),
- mo_task_qty = SqlFunc.Subqueryable().Where(a => a.mo_id == moId).Count(),
- estimated_start_date = a.estimated_start_date,
- estimated_end_date = a.estimated_end_date,
- plan_qty = b.plan_qty,
- complete_qty = a.complete_qty,
- })
- .Mapper(it =>
- {
- it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "";
- })
- .ToListAsync();
+ if (schedType == 1)
+ {
+ result = await _db.Queryable().LeftJoin((a, b) => a.mo_id == b.id)
+ .LeftJoin((a, b, c) => a.material_id == c.id)
+ .LeftJoin((a, b, c, d) => a.mold_id == d.id)
+ .LeftJoin((a, b, c, d, e) => a.eqp_id == e.id)
+ .Where((a, b, c, d, e) => a.mo_id == moId)
+ .Select((a, b, c, d, e) => new PrdMoTaskOutput
+ {
+ mo_task_code = a.mo_task_code,
+ mo_task_status = a.mo_task_status,
+ mold_code = d.mold_code,
+ mold_name = d.mold_name,
+ material_code = c.code,
+ material_name = c.name,
+ eqp_code = e.code,
+ eqp_name = e.name,
+ eqp_type_code = SqlFunc.Subqueryable().Where(it => it.id == e.equip_type_id).Select(it => it.code),
+ mo_task_qty = SqlFunc.Subqueryable().Where(a => a.mo_id == moId).Count(),
+ estimated_start_date = a.estimated_start_date,
+ estimated_end_date = a.estimated_end_date,
+ plan_qty = b.plan_qty,
+ complete_qty = a.complete_qty,
+ })
+ .Mapper(it =>
+ {
+ it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "";
+ })
+ .ToListAsync();
+ }
+ else
+ {
+ result = await _db.Queryable().LeftJoin((a, b) => a.mo_id == b.id)
+ .LeftJoin((a, b, c) => a.material_id == c.id)
+ .LeftJoin((a, b, c, d) => a.workline_id == d.Id)
+ .Where((a, b, c, d) => a.mo_id == moId)
+ .Select((a, b, c, d) => new PrdMoTaskOutput
+ {
+ mo_task_code = a.mo_task_code,
+ mo_task_status = a.mo_task_status,
+ workline_code = d.EnCode,
+ workline_name = d.FullName,
+ material_code = c.code,
+ material_name = c.name,
+ mo_task_qty = SqlFunc.Subqueryable().Where(a => a.mo_id == moId).Count(),
+ estimated_start_date = a.estimated_start_date,
+ estimated_end_date = a.estimated_end_date,
+ plan_qty = b.plan_qty,
+ complete_qty = a.complete_qty,
+ })
+ .Mapper(it =>
+ {
+ it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "";
+ })
+ .ToListAsync();
+ }
+
return result;
}
+ ///
+ ///组装、包装 获取待下发任务列表
+ ///
+ ///
+ [HttpGet]
+ public async Task GetPackScheldToBeIssueList()
+ {
+ var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId);
+ var result = await _db.Queryable().Where(it => it.schedule_type == 2)
+ .LeftJoin((a, b) => a.material_id == b.id)
+ .LeftJoin((a, b, c) => a.workline_id == c.Id)
+ .LeftJoin((a, b, c, d) => a.mo_id == d.id)
+ .Select((a, b, c, d) => new PackSechelToBeIssueListOutput
+ {
+ mo_task_id = a.id,
+ mo_task_code = a.mo_task_code,
+ material_code = b.code,
+ material_name = b.name,
+ workline_code = c.EnCode,
+ workline_name = c.FullName,
+ mo_task_status = a.mo_task_status,
+ scheduled_qty = a.scheduled_qty,
+ plan_qty = d.plan_qty
+ })
+ .Mapper(it => it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "")
+ .ToListAsync();
+ return result;
+ }
+ ///
+ /// 根据生产任务ID获取子任务列表
+ ///
+ ///
+ ///
+ [HttpGet("{mo_task_id}")]
+ public async Task GetSubMoTaskListByTaskId(string mo_task_id)
+ {
+ var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId);
+ var result = await _db.Queryable()
+ .LeftJoin((a, b) => a.material_id == b.id)
+ .LeftJoin((a, b, c) => a.workline_id == c.Id)
+ .LeftJoin((a, b, c, d) => a.mo_id == d.id)
+ .Where((a, b, c, d) => a.parent_id == mo_task_id)
+ .Select((a, b, c, d) => new PackSechelToBeIssueListOutput
+ {
+ mo_task_id = a.id,
+ mo_task_code = a.mo_task_code,
+ material_code = b.code,
+ material_name = b.name,
+ workline_code = c.EnCode,
+ workline_name = c.FullName,
+ mo_task_status = a.mo_task_status,
+ scheduled_qty = a.scheduled_qty,
+ plan_qty = d.plan_qty,
+ process_task_qty = a.process_task_qty,
+ })
+ .Mapper(it => it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "")
+ .ToListAsync();
+ return result;
+ }
@@ -593,69 +684,126 @@ namespace Tnb.ProductionMgr
[HttpPost]
public async Task PackSchedling(PackSchedlingCrInput input)
{
- if (input.items == null)
+ var row = -1;
+ try
{
- throw new ArgumentNullException(nameof(input.items));
- }
- DbResult dbResult = null;
- if (input.items.Count > 0)
- {
- var moTasks = input.items.Select(x => new PrdMoTask
+ await _db.Ado.BeginTranAsync();
+ var moTask = input.Adapt();
+ moTask.id = SnowflakeIdHelper.NextId();
+ moTask.create_id = _userManager.UserId;
+ moTask.create_time = DateTime.Now;
+ moTask.schedule_type = 2;
+ moTask.mo_task_status = DictConst.ToBeScheduledEncode;
+ moTask.estimated_start_date = input.estimated_start_date;
+ moTask.estimated_end_date = input.estimated_end_date;
+ var mo = await _db.Queryable().FirstAsync(it => it.id == input.mo_id);
+ var moCode = mo?.mo_code;
+ var taskCode = await _db.Queryable().Where(it => !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)).OrderByDescending(it => it.mo_task_code).Select(it => it.mo_task_code).FirstAsync();
+ if (taskCode.IsNullOrEmpty())
{
- id = SnowflakeIdHelper.NextId(),
- mo_task_code = x.mo_task_code,
- material_id = x.material_id,
- mo_id = x.mo_id,
- bom_id = x.bom_id,
- create_id = _userManager.UserId,
- scheduled_qty = x.qty.ParseToInt(),
- create_time = DateTime.Now
- }).ToList();
- dbResult = await _db.Ado.UseTranAsync(async () =>
+ moTask.mo_task_code = $"{moCode}-01";
+ }
+ else
{
- await _db.Insertable(moTasks).ExecuteCommandAsync();
- List taskLogList = new();
- List taskDefectRecordList = new();
-
- foreach (var moTask in moTasks)
+ var pos = taskCode.IndexOf("-", StringComparison.Ordinal);
+ if (pos > -1)
{
- var material = await _db.Queryable().FirstAsync(it => it.id == moTask.material_id);
- var mo = await _db.Queryable().FirstAsync(it => it.id == moTask.mo_id);
- var taskLog = new PrdTaskLog();
- taskLog.id = SnowflakeIdHelper.NextId();
- taskLog.mo_code = mo?.mo_code;
- taskLog.eqp_code = (await _db.Queryable().FirstAsync(it => it.id == moTask.eqp_id))?.code;
- taskLog.mold_code = (await _db.Queryable().FirstAsync(it => it.id == moTask.mold_id))?.mold_code;
- taskLog.item_code = material?.code;
- taskLog.item_standard = material?.material_standard;
- taskLog.status = DictConst.ToBeScheduledEncode;
- taskLog.operator_name = _userManager.RealName;
- taskLog.create_id = _userManager.UserId;
- taskLog.create_time = DateTime.Now;
- taskLog.mo_task_id = moTask.id;
- taskLog.mo_task_code = moTask.mo_task_code;
- taskLogList.Add(taskLog);
- //将生产任务插入到自检报废记录表
- var sacipRecord = new PrdMoTaskDefectRecord();
- sacipRecord.id = SnowflakeIdHelper.NextId();
- sacipRecord.material_code = material?.code;
- sacipRecord.material_name = material?.name;
- sacipRecord.estimated_start_date = mo?.plan_start_date;
- sacipRecord.estimated_end_date = mo?.plan_end_date;
- sacipRecord.plan_qty = moTask.plan_qty;
- sacipRecord.scrap_qty = moTask.scrap_qty;
- sacipRecord.status = moTask.mo_task_status;
- sacipRecord.create_id = _userManager.UserId;
- sacipRecord.create_time = DateTime.Now;
- sacipRecord.mo_task_id = moTask.id;
- sacipRecord.mo_task_code = moTask.mo_task_code;
- taskDefectRecordList.Add(sacipRecord);
+ var num = taskCode.AsSpan().Slice(pos + 1).ToString().ParseToInt();
+ var code = taskCode.AsSpan().Slice(0, pos).ToString();
+ var n = (num + 1).ToString().PadLeft(2, '0');
+ moTask.mo_task_code = $"{code}-{n}";
}
- await _db.Insertable(taskLogList).ExecuteCommandAsync();
- await _db.Insertable(taskDefectRecordList).ExecuteCommandAsync();
- });
+ }
+ row = await _db.Insertable(moTask).ExecuteCommandAsync();
+ var material_h = await _db.Queryable().FirstAsync(it => it.id == moTask.material_id);
+ //添加生产任务操作记录日志s
+ var taskLog = new PrdTaskLog();
+ taskLog.id = SnowflakeIdHelper.NextId();
+ taskLog.mo_code = (await _db.Queryable().FirstAsync(it => it.id == input.mo_id))?.mo_code;
+ //taskLog.eqp_code = (await _db.Queryable().FirstAsync(it => it.id == input.eqp_id))?.code;
+ //taskLog.mold_code = (await _db.Queryable().FirstAsync(it => it.id == input.mold_id))?.mold_code;
+ taskLog.item_code = material_h?.code;
+ taskLog.item_standard = material_h?.material_standard;
+ taskLog.status = DictConst.ToBeScheduledEncode;
+ taskLog.operator_name = _userManager.RealName;
+ taskLog.create_id = _userManager.UserId;
+ taskLog.create_time = DateTime.Now;
+ taskLog.mo_task_id = moTask.id;
+ taskLog.mo_task_code = moTask.mo_task_code;
+ row = await _db.Insertable(taskLog).ExecuteCommandAsync();
+ //根据工单号获取当前工单包含的已排产数
+ var schedQty = _db.Queryable().Where(it => it.mo_id == input.mo_id)?.Sum(d => d.scheduled_qty);
+ if (mo != null)
+ {//判断如果当前 工单的已排产数大于工单计划数量则更新工单状态为 已排产
+ if (schedQty.HasValue && schedQty.Value >= mo.plan_qty)
+ {
+ mo.mo_status = DictConst.AlreadyId;
+ await _db.Updateable(mo).ExecuteCommandAsync();
+ }
+ else
+ {
+ if (schedQty.HasValue)
+ {
+ mo.scheduled_qty += schedQty.Value;
+ await _db.Updateable(mo).ExecuteCommandAsync();
+ }
+ }
+ }
+ //根据生产bomId 拆解生产子任务
+ var outputList = new List();
+ var bom = await _db.Queryable().FirstAsync(it => it.id == input.bom_id);
+ if (bom != null && bom.route_id.IsNotEmptyOrNull())
+ {
+ var routes = await _db.Queryable().Where(it => it.route_id == bom.route_id).ToListAsync();
+ if (routes?.Count > 0)
+ {
+ var processIds = routes.Select(x => x.process_id).ToList();
+ if (processIds?.Count > 0)
+ {
+ var bomOutputs = await _db.Queryable().Where(it => processIds.Contains(it.process_id)).ToListAsync();
+ if (bomOutputs?.Count > 0)
+ {
+ List subMoTasks = new();
+ foreach (var item in bomOutputs)
+ {
+ var material = await _db.Queryable().FirstAsync(it => it.id == item.material_id);
+ PrdMoTask subMoTask = new();
+ subMoTask.id = SnowflakeIdHelper.NextId();
+ subMoTask.schedule_type = 2;
+ subMoTask.parent_id = moTask.id;
+ subMoTask.bom_id = input.bom_id;
+ subMoTask.mo_task_status = DictConst.ToBeScheduledEncode;
+ subMoTask.workline_id = input.workline_id;
+ subMoTask.material_id = item.material_id;
+ subMoTask.process_task_qty = item.num.ParseToInt() * moTask.scheduled_qty;
+ subMoTask.estimated_start_date = input.estimated_start_date;
+ subMoTask.estimated_end_date = input.estimated_end_date;
+ subMoTask.create_id = _userManager.UserId;
+ subMoTask.create_time = DateTime.Now;
+ subMoTasks.Add(subMoTask);
+ }
+ //根据生产任务编号生成子任务编号
+ if (moTask.mo_task_code.IsNotEmptyOrNull())
+ {
+ for (int i = 1; i <= subMoTasks.Count; i++)
+ {
+ string n = i.ToString();
+ subMoTasks[i - 1].mo_task_code = $"{moTask.mo_task_code}-{n.PadLeft(2, '0')}";
+ }
+ }
+ row = await _db.Insertable(subMoTasks).ExecuteCommandAsync();
+ }
+ }
+ }
+ }
+ await _db.Ado.CommitTranAsync();
}
- return dbResult!.IsSuccess;
+ catch (Exception ex)
+ {
+ Log.Error("组装包装排产时报错", ex);
+ await _db.Ado.RollbackTranAsync();
+ }
+ return row > 0;
}
///
@@ -710,57 +858,75 @@ namespace Tnb.ProductionMgr
.SetColumns(it => new PrdMoTask { mo_task_status = status })
.Where(it => input.TaskIds.Contains(it.id))
.ExecuteCommandAsync();
- //插入操作记录日志
- List taskLogEntities = new();
- foreach (var taskId in input.TaskIds)
+ if (row > 0)
{
- var taskLog = await db.Queryable().FirstAsync(it => it.mo_task_id == taskId);
- if (taskLog is null)
+ //更新子任务
+ var subMoTaskList = await db.Queryable().Where(it => input.TaskIds.Contains(it.parent_id)).ToListAsync();
+ if (subMoTaskList?.Count > 0)
{
- var taskItem = list?.Find(x => x.id == taskId);
- taskLog = new PrdTaskLog();
- taskLog.id = SnowflakeIdHelper.NextId();
- if (taskItem != null)
- {
- if (taskItem.mo_id.IsNotEmptyOrNull())
- {
- taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mo_id))?.mo_code;
- }
- if (taskItem.eqp_id.IsNotEmptyOrNull())
- {
- taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.eqp_id))?.code;
- }
- if (taskItem.mold_id.IsNotEmptyOrNull())
- {
- taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mold_id))?.mold_code;
- }
- if (taskItem.material_id.IsNotEmptyOrNull())
- {
- var material = await db.Queryable().FirstAsync(it => it.id == taskItem.material_id);
- taskLog.item_code = material?.code;
- taskLog.item_standard = material?.material_standard;
- }
- taskLog.operator_name = _userManager.RealName;
- taskLog.status = status;
- taskLog.create_id = _userManager.UserId;
- taskLog.create_time = DateTime.Now;
- taskLog.mo_task_id = taskItem.id;
- }
- taskLogEntities.Add(taskLog);
- }
- else
- {
- var records = await db.Queryable().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync();
- if (records != null && !records.Select(x => x.status).Contains(status))
- {
-
- taskLog.id = SnowflakeIdHelper.NextId();
- taskLog.status = status;
- taskLogEntities.Add(taskLog);
- }
+ var subTaskIds = subMoTaskList.Select(it => it.id).ToList();
+ row = await db.Updateable()
+ .SetColumns(it => new PrdMoTask { mo_task_status = status })
+ .Where(it => subTaskIds.Contains(it.id))
+ .ExecuteCommandAsync();
}
}
- row = await db.Insertable(taskLogEntities).ExecuteCommandAsync();
+ //插入操作记录日志
+ var prdMOTasks = await _db.Queryable().Where(it => input.TaskIds.Contains(it.id) && string.IsNullOrEmpty(it.parent_id)).ToListAsync();
+ if (prdMOTasks?.Count > 0)
+ {
+ List taskLogEntities = new();
+ foreach (var taskId in input.TaskIds)
+ {
+ var taskLog = await db.Queryable().FirstAsync(it => it.mo_task_id == taskId);
+ if (taskLog is null)
+ {
+ var taskItem = list?.Find(x => x.id == taskId);
+ taskLog = new PrdTaskLog();
+ taskLog.id = SnowflakeIdHelper.NextId();
+ if (taskItem != null)
+ {
+ if (taskItem.mo_id.IsNotEmptyOrNull())
+ {
+ taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mo_id))?.mo_code;
+ }
+ if (taskItem.eqp_id.IsNotEmptyOrNull())
+ {
+ taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.eqp_id))?.code;
+ }
+ if (taskItem.mold_id.IsNotEmptyOrNull())
+ {
+ taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mold_id))?.mold_code;
+ }
+ if (taskItem.material_id.IsNotEmptyOrNull())
+ {
+ var material = await db.Queryable().FirstAsync(it => it.id == taskItem.material_id);
+ taskLog.item_code = material?.code;
+ taskLog.item_standard = material?.material_standard;
+ }
+ taskLog.operator_name = _userManager.RealName;
+ taskLog.status = status;
+ taskLog.create_id = _userManager.UserId;
+ taskLog.create_time = DateTime.Now;
+ taskLog.mo_task_id = taskItem.id;
+ }
+ taskLogEntities.Add(taskLog);
+ }
+ else
+ {
+ var records = await db.Queryable().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync();
+ if (records != null && !records.Select(x => x.status).Contains(status))
+ {
+
+ taskLog.id = SnowflakeIdHelper.NextId();
+ taskLog.status = status;
+ taskLogEntities.Add(taskLog);
+ }
+ }
+ }
+ row = await db.Insertable(taskLogEntities).ExecuteCommandAsync();
+
+ }
return (row > 0);
}