根据生产bom拆分子工单代码调整

This commit is contained in:
DEVICE8\12494
2023-05-24 23:31:13 +08:00
parent 65072abc04
commit d12e05d737
16 changed files with 336 additions and 98 deletions

View File

@@ -35,5 +35,26 @@ namespace Tnb.BasicData.Entities.Dto
/// 数量 /// 数量
/// </summary> /// </summary>
public string num { get; set;} public string num { get; set;}
/// <summary>
/// 单位id
/// </summary>
public string unit_id { get; set; }
/// <summary>
/// bomid
/// </summary>
public string bom_id { get; set; }
/// <summary>
/// 工序id
/// </summary>
public string process_id { get; set; }
/// <summary>
/// bom版本
/// </summary>
public string version { get; set; }
/// <summary>
/// 工艺路线名称
/// </summary>
public string route_name { get; set; }
} }
} }

View File

@@ -133,35 +133,51 @@ namespace Tnb.BasicData
/// <summary> /// <summary>
/// 根据bomid获取对应的子bom列表 /// 根据bomid获取对应的子bom列表
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="bomId">bomId</param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <remarks>
/// returns:
/// <br/>{
/// <br/> version:bom版本
/// <br/> unit_id:单位id
/// <br/> route_name:工艺路线名称
/// <br/> process_id工序id
/// <br/> material_id:物料id
/// <br/> material_code物料编码
/// <br/> material_name:物料名称
/// <br/> material_category_code类别code
/// <br/> output_qty输出参数
/// <br/>}
/// </remarks>
[HttpGet] [HttpGet]
public async Task<dynamic> GetSubMoListByBomId([FromRoute] string bomId) public async Task<dynamic> GetSubMoListByBomId([FromRoute] string bomId)
{ {
if (string.IsNullOrEmpty(bomId)) throw new ArgumentException($"parameter {nameof(bomId)} not be null or empty"); if (string.IsNullOrEmpty(bomId)) throw new ArgumentException($"parameter {nameof(bomId)} not be null or empty");
var result = await _db.Queryable<BasMbom>().LeftJoin<BasRouteD>((a, b) => a.route_id == b.route_id) var result = await _db.Queryable<BasMbom>()
.LeftJoin<BasProcess>((a, b, c) => b.process_id == c.id) .LeftJoin<BasRouteH>((a, b) => a.route_id == b.id)
.LeftJoin<BasMbomOutput>((a, b, c, d) => c.id == d.process_id) .LeftJoin<BasRouteD>((a, b, c) => b.id == c.route_id)
.LeftJoin<BasMaterial>((a, b, c, d, e) => d.material_id == e.id) .LeftJoin<BasMbomProcess>((a, b, c, d) => c.process_id == d.process_id)
.LeftJoin<BasMaterialCategory>((a, b, c, d, e, f) => e.category_id == f.id) .LeftJoin<BasMbomOutput>((a, b, c, d, e) => e.mbom_id == a.id && e.mbom_process_id == d.id)
.Where((a, b, c, d, e, f) => a.id == bomId) .Where((a, b, c, d, e) => a.id == bomId && a.material_id != e.material_id && !string.IsNullOrEmpty(e.material_id))
.Select((a, b, c, d, e, f) => new SubBomListOutput .Select((a, b, c, d, e) => new SubBomListOutput
{ {
material_id = e.id, version = a.version,
material_code = e.code, unit_id = a.unit_id,
material_name = e.name, route_name = b.name,
material_category_code = f.category_code, process_id = c.process_id,
num = d.num material_id = SqlFunc.Subqueryable<BasMaterial>().Where(it => it.id == e.material_id).Select(it => it.id),
}) material_code = SqlFunc.Subqueryable<BasMaterial>().Where(it => it.id == e.material_id).Select(it => it.code),
.Mapper(it => it.output_qty = it.num.ParseToInt()) material_name = SqlFunc.Subqueryable<BasMaterial>().Where(it => it.id == e.material_id).Select(it => it.name),
.Distinct() material_category_code = "",
.ToListAsync(); num = e.num,
})
.Mapper(it => it.output_qty = it.num.ParseToInt())
.ToListAsync();
return result; return result;
} }
/// <summary> /// <summary>
/// 根据物料id获取生产bom /// 根据物料id获取生产bom
/// </summary> /// </summary>
@@ -182,6 +198,7 @@ namespace Tnb.BasicData
[HttpGet] [HttpGet]
public async Task<dynamic> GetMBomListByMaterialId([FromRoute] string materialId) public async Task<dynamic> GetMBomListByMaterialId([FromRoute] string materialId)
{ {
return await _db.Queryable<BasMbom>() return await _db.Queryable<BasMbom>()
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id) .LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
.LeftJoin<BasRouteH>((a, b, c) => a.route_id == c.id) .LeftJoin<BasRouteH>((a, b, c) => a.route_id == c.id)

View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities;
using Tnb.EquipMgr.Entities.Dto; using Tnb.EquipMgr.Entities.Dto;
using Tnb.ProductionMgr.Entities.Dto;
namespace Tnb.EquipMgr.Interfaces namespace Tnb.EquipMgr.Interfaces
{ {
@@ -16,7 +17,7 @@ namespace Tnb.EquipMgr.Interfaces
/// </summary> /// </summary>
/// <param name="mold"></param> /// <param name="mold"></param>
/// <returns></returns> /// <returns></returns>
public Task<List<EquipmentListOutput>> GetEquipmentLists(ToolMoldInput ToolMoldInput); public Task<List<Entities.Dto.EquipmentListOutput>> GetEquipmentLists(ToolMoldInput ToolMoldInput);
/// <summary> /// <summary>
/// 增加模具设备绑定 /// 增加模具设备绑定
/// </summary> /// </summary>

View File

@@ -8,6 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ProductionMgr\Tnb.ProductionMgr.Entities\Tnb.ProductionMgr.Entities.csproj" />
<ProjectReference Include="..\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" /> <ProjectReference Include="..\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -141,6 +141,7 @@ namespace Tnb.EquipMgr
await _db.Ado.BeginTranAsync(); await _db.Ado.BeginTranAsync();
var maintainRules = await _db.Queryable<ToolMoldMaintainRule>().Where(it => input.ruleIds.Contains(it.id)).ToListAsync(); var maintainRules = await _db.Queryable<ToolMoldMaintainRule>().Where(it => input.ruleIds.Contains(it.id)).ToListAsync();
var ruleMoldRelations = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(it=>input.ruleIds.Contains(it.rule_id)).ToListAsync();
if (maintainRules?.Count > 0) if (maintainRules?.Count > 0)
{ {
List<ToolMoldMaintainPlan> maintainPlans = new(); List<ToolMoldMaintainPlan> maintainPlans = new();

View File

@@ -47,7 +47,7 @@ namespace Tnb.EquipMgr
public async Task<dynamic> GetMaintainInfoFromByPlanId([FromRoute] string planId) public async Task<dynamic> GetMaintainInfoFromByPlanId([FromRoute] string planId)
{ {
dynamic info = new ExpandoObject(); dynamic info = new ExpandoObject();
var planMoldRelation = await _db.Queryable<ToolMoldMaintainPlanRelation>().FirstAsync(it => it.id == planId); var planMoldRelation = await _db.Queryable<ToolMoldMaintainPlanRelation>().FirstAsync(it => it.maintain_plan_id == planId);
if (planMoldRelation != null) if (planMoldRelation != null)
{ {
var mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == planMoldRelation.mold_id); var mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == planMoldRelation.mold_id);

View File

@@ -18,6 +18,7 @@ using SqlSugar;
using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities;
using Tnb.EquipMgr.Entities.Dto; using Tnb.EquipMgr.Entities.Dto;
using Tnb.EquipMgr.Interfaces; using Tnb.EquipMgr.Interfaces;
using Tnb.ProductionMgr.Entities.Dto;
namespace Tnb.EquipMgr namespace Tnb.EquipMgr
{ /// <summary> { /// <summary>
@@ -67,7 +68,7 @@ namespace Tnb.EquipMgr
/// <param name="mold"></param> /// <param name="mold"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<List<EquipmentListOutput>> GetEquipmentLists(ToolMoldInput ToolMoldInput) public async Task<List<Tnb.EquipMgr.Entities.Dto.EquipmentListOutput>> GetEquipmentLists(ToolMoldInput ToolMoldInput)
{ {
var db = _repository.AsSugarClient(); var db = _repository.AsSugarClient();
var list = await db.Queryable<EqpEquipment, ToolMoldsEquipment>((a, b) => new object[] var list = await db.Queryable<EqpEquipment, ToolMoldsEquipment>((a, b) => new object[]
@@ -75,7 +76,7 @@ namespace Tnb.EquipMgr
JoinType.Inner, a.id == b.equipment_id, JoinType.Inner, a.id == b.equipment_id,
}) })
.Where((a, b) => b.mold_id == ToolMoldInput.mold) .Where((a, b) => b.mold_id == ToolMoldInput.mold)
.Select((a, b) => new EquipmentListOutput .Select((a, b) => new Tnb.EquipMgr.Entities.Dto.EquipmentListOutput
{ {
id = a.id, id = a.id,
eqp_code = a.code, eqp_code = a.code,

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.ProductionMgr.Entities.Dto
{
public class DictionaryTreeOutput
{
public string id { get; set; }
public string parentId { get; set; }
public List<dynamic> Child { get; set; }
public bool HasChild { get; set; }
}
}

View File

@@ -8,12 +8,14 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
{ {
public class GenSubMoCrInput public class GenSubMoCrInput
{ {
public string bom_id { get; set; }
/// <summary> /// <summary>
/// 父工单id /// 父工单id
/// </summary> /// </summary>
public string mo_id { get; set; } public string mo_id { get; set; }
/// <summary> /// <summary>
/// 子物料ids /// 工序ids
/// </summary> /// </summary>
public List<string> ids { get; set; } public List<string> ids { get; set; }

View File

@@ -7,8 +7,12 @@ using JNPF.Common.Security;
namespace Tnb.ProductionMgr.Entities.Dto.PrdManage namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
{ {
public class PrdMotreeOutput : TreeModel public class PrdMoTreeOutput : TreeModel
{ {
//public Dictionary<string, object> row { get; set; }
#region
public string? org_id { get; set; } public string? org_id { get; set; }
/// <summary> /// <summary>
/// 工单id /// 工单id
@@ -25,6 +29,10 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
/// 物料编号 /// 物料编号
/// </summary> /// </summary>
public string? material_code { get; set; } public string? material_code { get; set; }
/// <summary>
/// 物料名称
/// </summary>
public string material_name { get; set; }
/// <summary> /// <summary>
/// 工单类型1-正常工单、2-返工工单、3-试制工单 /// 工单类型1-正常工单、2-返工工单、3-试制工单
@@ -39,37 +47,37 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
/// <summary> /// <summary>
/// 计划生产数量 /// 计划生产数量
/// </summary> /// </summary>
public int? plan_qty { get; set; } public string plan_qty { get; set; }
/// <summary> /// <summary>
/// 已投入数量 /// 已投入数量
/// </summary> /// </summary>
public int? input_qty { get; set; } public string input_qty { get; set; }
/// <summary> /// <summary>
/// 已完工数量 /// 已完工数量
/// </summary> /// </summary>
public int? complete_qty { get; set; } public string complete_qty { get; set; }
/// <summary> /// <summary>
/// 报废数量 /// 报废数量
/// </summary> /// </summary>
public int? scrap_qty { get; set; } public string scrap_qty { get; set; }
/// <summary> /// <summary>
/// 计划开始时间 /// 计划开始时间
/// </summary> /// </summary>
public DateTime? plan_start_date { get; set; } public string plan_start_date { get; set; }
/// <summary> /// <summary>
/// 计划结束时间 /// 计划结束时间
/// </summary> /// </summary>
public DateTime? plan_end_date { get; set; } public string plan_end_date { get; set; }
/// <summary> /// <summary>
/// 是否生派工单 /// 是否生派工单
/// </summary> /// </summary>
public int? is_create_dispatch { get; set; } public string is_create_dispatch { get; set; }
/// <summary> /// <summary>
@@ -80,7 +88,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
/// <summary> /// <summary>
/// 是否合并 /// 是否合并
/// </summary> /// </summary>
public int? is_merge { get; set; } public string is_merge { get; set; }
/// <summary> /// <summary>
/// 组合工单 /// 组合工单
@@ -100,7 +108,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
/// <summary> /// <summary>
/// 创建时间 /// 创建时间
/// </summary> /// </summary>
public DateTime? create_time { get; set; } public string create_time { get; set; }
/// <summary> /// <summary>
/// 修改用户 /// 修改用户
@@ -110,19 +118,20 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
/// <summary> /// <summary>
/// 修改时间 /// 修改时间
/// </summary> /// </summary>
public DateTime? modify_time { get; set; } public string modify_time { get; set; }
/// <summary> /// <summary>
/// 物料ID /// 物料ID
/// </summary> /// </summary>
public string? material_id { get; set; } public string? material_id { get; set; }
public string? material_id_id { get; set; }
/// <summary> /// <summary>
/// 已排产数量 /// 已排产数量
/// </summary> /// </summary>
public int? scheduled_qty { get; set; } public string scheduled_qty { get; set; }
/// <summary> /// <summary>
/// 父工单id /// 父工单id
/// </summary> /// </summary>
public string parent_id { get; set; } public string parent_id { get; set; }
#endregion
} }
} }

View File

@@ -48,5 +48,9 @@ public partial class PrdMoTaskDefect : BaseEntity<string>
/// 批次 /// 批次
/// </summary> /// </summary>
public string? batch { get; set; } public string? batch { get; set; }
/// <summary>
/// 报废数量
/// </summary>
public int scrap_qty { get; set; }
} }

View File

@@ -35,6 +35,11 @@ using Aspose.Cells.Drawing.Texts;
using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Entitys.Permission;
using WebSocketSharp.Frame; using WebSocketSharp.Frame;
using JNPF.Logging; using JNPF.Logging;
using System.Dynamic;
using Tnb.EquipMgr.Entities.Dto;
using JNPF.Common.Filter;
using Tnb.BasicData.Entities.Dto;
using NPOI.SS.Formula.Functions;
namespace Tnb.ProductionMgr namespace Tnb.ProductionMgr
{ {
@@ -45,6 +50,7 @@ namespace Tnb.ProductionMgr
public class PrdMoTaskService : IOverideVisualDevService, IPrdMoTaskService, IDynamicApiController, ITransient public class PrdMoTaskService : IOverideVisualDevService, IPrdMoTaskService, IDynamicApiController, ITransient
{ {
private const string ModuleId = "25567924238373"; private const string ModuleId = "25567924238373";
private const string MoModuleId = "25018860321301";
private readonly ISqlSugarRepository<PrdTask> _repository; private readonly ISqlSugarRepository<PrdTask> _repository;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IDictionaryDataService _dictionaryDataService; private readonly IDictionaryDataService _dictionaryDataService;
@@ -98,12 +104,12 @@ namespace Tnb.ProductionMgr
[HttpGet("{materialId}")] [HttpGet("{materialId}")]
public async Task<dynamic> GetMoldListByItemId(string materialId) public async Task<dynamic> GetMoldListByItemId(string materialId)
{ {
var result = new List<MoldListOutput>(); var result = new List<Tnb.ProductionMgr.Entities.Dto.MoldListOutput>();
result = await _db.Queryable<ToolMoldsMaterial>() result = await _db.Queryable<ToolMoldsMaterial>()
.InnerJoin<ToolMolds>((a, b) => a.mold_id == b.id) .InnerJoin<ToolMolds>((a, b) => a.mold_id == b.id)
.InnerJoin<BasMaterial>((a, b, c) => a.material_id == c.id) .InnerJoin<BasMaterial>((a, b, c) => a.material_id == c.id)
.Where((a, b, c) => a.material_id == materialId) .Where((a, b, c) => a.material_id == materialId)
.Select((a, b, c) => new MoldListOutput .Select((a, b, c) => new Tnb.ProductionMgr.Entities.Dto.MoldListOutput
{ {
mold_id = a.id, mold_id = a.id,
mold_code = b.mold_code, mold_code = b.mold_code,
@@ -125,7 +131,7 @@ namespace Tnb.ProductionMgr
{ {
var items = await _db.Queryable<ToolMoldsEquipment>().InnerJoin<EqpEquipment>((a, b) => a.equipment_id == b.id) var items = await _db.Queryable<ToolMoldsEquipment>().InnerJoin<EqpEquipment>((a, b) => a.equipment_id == b.id)
.Where((a, b) => a.mold_id == moldId) .Where((a, b) => a.mold_id == moldId)
.Select((a, b) => new EquipmentListOutput .Select((a, b) => new Entities.Dto.EquipmentListOutput
{ {
eqp_id = b.id, eqp_id = b.id,
eqp_code = b.code, eqp_code = b.code,
@@ -255,7 +261,7 @@ namespace Tnb.ProductionMgr
material_code = materialCode, material_code = materialCode,
material_name = materialName, material_name = materialName,
prd_qty = it.prd_qty, prd_qty = it.prd_qty,
//scrap_qty = SqlFunc.Subqueryable<PrdScrapped>().Select(x => x.scrap_qty), scrap_qty = SqlFunc.Subqueryable<PrdMoTaskDefect>().Where(pmtd => pmtd.mo_task_id == it.mo_task_id).Select(x => x.scrap_qty),
}) })
.Mapper(it => .Mapper(it =>
{ {
@@ -271,7 +277,7 @@ namespace Tnb.ProductionMgr
icmo_qty = db.Queryable<PrdMoTask>().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty, icmo_qty = db.Queryable<PrdMoTask>().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty,
reported_work_qty = 0, reported_work_qty = 0,
prd_qty = 0, prd_qty = 0,
//scrap_qty = 0, scrap_qty = 0,
}; };
return res; return res;
} }
@@ -471,29 +477,74 @@ namespace Tnb.ProductionMgr
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<dynamic> GetUnSchedulingList() public async Task<dynamic> GetUnSchedulingList([FromQuery] VisualDevModelListQueryInput input)
{ {
List<PrdMotreeOutput> trees = new(); List<PrdMoTreeOutput> trees = new();
var list = await _db.Queryable<PrdMo>().Where(it => string.IsNullOrEmpty(it.parent_id) && it.mo_status == DictConst.ScheduledId).ToListAsync(); VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(MoModuleId, true);
foreach (var item in list) var data = await _runService.GetListResult(templateEntity, input);
if (data?.list?.Count > 0)
{ {
var node = item.Adapt<PrdMotreeOutput>(); var parentIdField = nameof(PrdMo.parent_id);
node.mo_id = item.id; var nodes = data.list.Where(it => it.ContainsKey(parentIdField) && it[parentIdField].IsNullOrEmpty()).ToList();
node.id = SnowflakeIdHelper.NextId(); foreach (var row in nodes)
node.parentId = "0";
var items = await _db.Queryable<PrdMo>().Where(it => it.parent_id == item.id).ToListAsync();
if (items?.Count() > 0)
{ {
var childNodes = items.Adapt<List<PrdMotreeOutput>>(); var pkName = "material_id_id";
for (int i = 0; i < items.Count; i++) var dic = row.ToDictionary(x => x.Key, x => x.Value);
PrdMoTreeOutput node = DictionaryToObject<PrdMoTreeOutput>(row);
node.parentId = "0";
node.mo_id = node.id;
if (dic.ContainsKey(pkName))
{ {
childNodes[i].mo_id = items[i].id; var materialId = dic[pkName]?.ToString();
var material = await _db.Queryable<BasMaterial>().FirstAsync(it => it.id == materialId);
node.material_id_id = materialId;
node.material_code = material?.code;
node.material_name = material?.name;
} }
trees.AddRange(childNodes);
var queryObj = new { parent_id = node.id };
input.superQueryJson = "";
input.queryJson = queryObj.ToJsonString();
var subData = await _runService.GetListResult(templateEntity, input);
if (subData?.list?.Count > 0)
{
var childNodes = new List<PrdMoTreeOutput>();
foreach (var item in subData.list)
{
dic = item.ToDictionary(x => x.Key, x => x.Value);
PrdMoTreeOutput subNode = DictionaryToObject<PrdMoTreeOutput>(item);
subNode.parentId = node.id;
subNode.mo_id = subNode.id;
if (dic.ContainsKey(pkName))
{
var materialId = dic[pkName]?.ToString();
var material = await _db.Queryable<BasMaterial>().FirstAsync(it => it.id == materialId);
subNode.material_id_id = materialId;
subNode.material_code = material?.code;
subNode.material_name = material?.name;
}
childNodes.Add(subNode);
}
trees.AddRange(childNodes);
}
trees.Add(node);
} }
trees.Add(node);
} }
return trees.ToTree(); var treeList = trees.ToTree();
var list = treeList.Skip(input.currentPage - 1).Take(input.pageSize).ToList();
SqlSugarPagedList<PrdMoTreeOutput> pagedList = new()
{
list = treeList,
pagination = new Pagination
{
CurrentPage = input.currentPage,
PageSize = input.pageSize,
Total = treeList.Count
}
};
return PageResult<PrdMoTreeOutput>.SqlSugarPageResult(pagedList);
} }
#endregion #endregion
@@ -769,7 +820,7 @@ namespace Tnb.ProductionMgr
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("组装包装排产时报错", ex); JNPF.Logging.Log.Error("组装包装排产时报错", ex);
await _db.Ado.RollbackTranAsync(); await _db.Ado.RollbackTranAsync();
} }
return row > 0; return row > 0;
@@ -1037,7 +1088,7 @@ namespace Tnb.ProductionMgr
defect.defective_item = dItem.defective_item; defect.defective_item = dItem.defective_item;
defect.defective_item_qty = dItem.defective_item_qty; defect.defective_item_qty = dItem.defective_item_qty;
defect.create_id = _userManager.UserId; defect.create_id = _userManager.UserId;
defect.scrap_qty = input.scrap_qty;
destDefects.Add(defect); destDefects.Add(defect);
} }
} }
@@ -1084,45 +1135,92 @@ namespace Tnb.ProductionMgr
if (input.ids is null || input.ids.Count == 0) throw new ArgumentException($"{nameof(input.ids)} not be null or count zero"); if (input.ids is null || input.ids.Count == 0) throw new ArgumentException($"{nameof(input.ids)} not be null or count zero");
var curMo = await _db.Queryable<PrdMo>().FirstAsync(it => it.id == input.mo_id); var curMo = await _db.Queryable<PrdMo>().FirstAsync(it => it.id == input.mo_id);
if (curMo == null) throw new ArgumentNullException("创建子工单时的父工单不能为null"); if (curMo == null) throw new ArgumentNullException("创建子工单时的父工单不能为null");
List<PrdMo> subMoList = new();
var outputMaterials = await _db.Queryable<BasMaterial>().LeftJoin<BasMbomOutput>((a, b) => a.id == b.material_id)
.Where((a, b) => input.ids.Contains(a.id)) var outMaterials = await _db.Queryable<BasMbom>().InnerJoin<BasMbomProcess>((a, b) => a.id == b.mbom_id)
.Select((a, b) => new .InnerJoin<BasMbomOutput>((a, b, c) => a.id == c.mbom_id && b.id == c.mbom_process_id)
.Where((a, b, c) => a.id == input.bom_id && input.ids.Contains(b.process_id))
.Select((a, b, c) => new
{
material_id = a.material_id,
num = c.num,
})
.ToListAsync();
if (outMaterials?.Count > 0)
{
var mids = await _db.Queryable<PrdMo>().Where(it => it.id == input.mo_id).Select(it => it.material_id).ToListAsync();
var ids = outMaterials.Select(x => x.material_id).Except(mids).ToList();
var dicOutMaterialNum = outMaterials.ToDictionary(x => x.material_id, x => x.num.ParseToInt());
List<PrdMo> subMoList = new();
var outputMaterials = await _db.Queryable<BasMaterial>().Where(it => ids.Contains(it.id)).ToListAsync();
foreach (var om in outputMaterials)
{ {
material_id = a.id, PrdMo subMo = new();
material_code = a.code, subMo.material_id = om.id;
num = b.num, subMo.material_code = om.code;
}) subMo.plan_qty = dicOutMaterialNum.ContainsKey(om.id) ? dicOutMaterialNum[om.id] * curMo.plan_qty : 0;
.ToListAsync(); subMo.mo_type = curMo.mo_type;
foreach (var om in outputMaterials) subMo.parent_id = curMo.id;
{ subMo.plan_start_date = curMo.plan_start_date;
PrdMo subMo = new(); subMo.plan_end_date = curMo.plan_end_date;
subMo.material_id = om.material_id; subMo.create_id = _userManager.UserId;
subMo.material_code = om.material_code; subMo.create_time = DateTime.Now;
subMo.plan_qty = om.num.ParseToInt() * curMo.plan_qty; subMo.mo_status = DictConst.WaitProductId;
subMo.mo_type = curMo.mo_type; subMoList.Add(subMo);
subMo.parent_id = curMo.id; }
subMo.plan_start_date = curMo.plan_start_date; //生成子工单编码
subMo.plan_end_date = curMo.plan_end_date; for (int i = 0; i < subMoList.Count; i++)
subMo.create_id = _userManager.UserId; {
subMo.create_time = DateTime.Now; var num = (i + 1).ToString().PadLeft(2, '0');
subMo.mo_status = DictConst.WaitProductId; subMoList[i].mo_code = $"{curMo.mo_code}-{num}";
subMoList.Add(subMo); }
var row = await _db.Insertable(subMoList).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
} }
//生成子工单编码
for (int i = 0; i < subMoList.Count; i++)
{
var num = (i + 1).ToString().PadLeft(2, '0');
subMoList[i].mo_code = $"{subMoList[i].mo_code}-{num}";
}
var row = await _db.Insertable(subMoList).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
} }
#endregion #endregion
private static dynamic DictionaryToObject(IDictionary<String, Object> dictionary)
{
var expandoObj = new ExpandoObject();
var expandoObjCollection = (ICollection<KeyValuePair<String, Object>>)expandoObj;
foreach (var keyValuePair in dictionary)
{
expandoObjCollection.Add(keyValuePair);
}
dynamic eoDynamic = expandoObj;
return eoDynamic;
}
private static Dictionary<string, string[]> dicProperties = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
private static T DictionaryToObject<T>(IDictionary<String, Object> dictionary) where T : class, new()
{
var name = typeof(T).Name;
T instance = new();
if (!dicProperties.TryGetValue(name, out string[] properies))
{
properies = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(p => p.Name).ToArray();
dicProperties[name] = properies;
}
//var properies = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(p => p.Name).ToArray();
foreach (var pn in properies)
{
if (dictionary.ContainsKey(pn))
{
instance.PropertySetValue(pn, dictionary[pn]);
}
}
return instance;
}
private async Task<dynamic> GetList(VisualDevModelListQueryInput input) private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
{ {

View File

@@ -1,4 +1,5 @@
using JNPF.DependencyInjection; using System.Reflection;
using JNPF.DependencyInjection;
namespace JNPF.Common.Extension; namespace JNPF.Common.Extension;
@@ -8,6 +9,7 @@ namespace JNPF.Common.Extension;
[SuppressSniffer] [SuppressSniffer]
public static class DictionaryExtensions public static class DictionaryExtensions
{ {
/// <summary> /// <summary>
/// 从字典中获取值,不存在则返回字典<typeparamref name="TValue"/>类型的默认值. /// 从字典中获取值,不存在则返回字典<typeparamref name="TValue"/>类型的默认值.
/// </summary> /// </summary>
@@ -55,4 +57,31 @@ public static class DictionaryExtensions
} }
} }
} }
private static Dictionary<string, string[]> dicProperties = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// 字典转换成指定类型实例
/// added by ly on 20230524
/// </summary>
/// <typeparam name="T">转换的目标类型</typeparam>
/// <param name="dictionary">被转换的字典</param>
/// <returns>转换后的目标类型对象实例</returns>
public static T ToObject<T>(this Dictionary<String, Object> dictionary) where T : class, new()
{
var name = typeof(T).Name;
T instance = new();
if (!dicProperties.TryGetValue(name, out string[] properies))
{
properies = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(p => p.Name).ToArray();
dicProperties[name] = properies;
}
foreach (var pn in properies)
{
if (dictionary.ContainsKey(pn))
{
instance.PropertySetValue(pn, dictionary[pn]);
}
}
return instance;
}
} }

View File

@@ -18,11 +18,22 @@ namespace JNPF.Common.Extension
} }
setAction(instance, value); setAction(instance, value);
} }
public static void PropertySetValue<T>(this T instance, string propertyName, object value)
{
if (!PropertySet<T>.ValueFactories2.TryGetValue(propertyName, out Action<T, object> setAction))
{
setAction = PropertySet<T>.CreateSetPropertyValueAction2(propertyName);
PropertySet<T>.ValueFactories2.Add(propertyName, setAction);
}
setAction(instance, value);
}
} }
public class PropertySet<T> public class PropertySet<T>
{ {
public static Dictionary<string, Action<object, object>> ValueFactories = new Dictionary<string, Action<object, object>>(StringComparer.OrdinalIgnoreCase); public static Dictionary<string, Action<object, object>> ValueFactories = new Dictionary<string, Action<object, object>>(StringComparer.OrdinalIgnoreCase);
public static Dictionary<string, Action<T, object>> ValueFactories2 = new Dictionary<string, Action<T, object>>(StringComparer.OrdinalIgnoreCase);
public static Action<object, object> CreateSetPropertyValueAction(string propertyName) public static Action<object, object> CreateSetPropertyValueAction(string propertyName)
{ {
@@ -35,5 +46,17 @@ namespace JNPF.Common.Extension
return Expression.Lambda<Action<object, object>>(setPropertyValue, target, propertyValue).Compile(); return Expression.Lambda<Action<object, object>>(setPropertyValue, target, propertyValue).Compile();
} }
public static Action<T, object> CreateSetPropertyValueAction2(string propertyName)
{
var property = typeof(T).GetProperty(propertyName);
var target = Expression.Parameter(typeof(T));
var propExp = Expression.Property(target, propertyName);
var propertyValue = Expression.Parameter(typeof(object));
var castPropertyValue = Expression.Convert(propertyValue, property!.PropertyType);
var assignExp = Expression.Assign(propExp, castPropertyValue);
return Expression.Lambda<Action<T, object>>(assignExp, new[] { target,propertyValue }).Compile();
}
} }
} }

View File

@@ -43,6 +43,8 @@ public static class TreeHelper
return resData; return resData;
} }
#region #region
/// <summary> /// <summary>

View File

@@ -3023,7 +3023,11 @@ public class RunService : IRunService, ITransient
{ {
if (item.Value.IsNullOrEmpty()) continue; if (item.Value.IsNullOrEmpty()) continue;
var itemValue = item.Value.ToString().Contains("[") ? item.Value.ToJsonString() : item.Value.ToString(); var itemValue = item.Value.ToString().Contains("[") ? item.Value.ToJsonString() : item.Value.ToString();
JArray jarr = null;
if (itemValue!.Contains("["))
{
jarr = JArray.Parse(itemValue);
}
if (model.searchType == 1) if (model.searchType == 1)
{ {
conModels.Add(new ConditionalCollections() conModels.Add(new ConditionalCollections()
@@ -3041,9 +3045,17 @@ public class RunService : IRunService, ITransient
} }
else else
{ {
conModels.Add(new ConditionalCollections() if (jarr?.Children() != null && jarr?.Children().ToList().Count > 1)
{ {
ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>() var values = string.Join(",", jarr.ToList().Select(t => t.Value<string>()));
conModels.Add(new ConditionalModel { FieldName = item.Key, ConditionalType = ConditionalType.In, FieldValue = values });
}
else
{
conModels.Add(new ConditionalCollections()
{
ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
{ {
new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel
{ {
@@ -3052,7 +3064,8 @@ public class RunService : IRunService, ITransient
FieldValue = itemValue FieldValue = itemValue
}) })
} }
}); });
}
} }
} }