根据生产bom拆分子工单代码调整
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,14 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
|
||||
{
|
||||
public class GenSubMoCrInput
|
||||
{
|
||||
public string bom_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父工单id
|
||||
/// </summary>
|
||||
public string mo_id { get; set; }
|
||||
/// <summary>
|
||||
/// 子物料ids
|
||||
/// 工序ids
|
||||
/// </summary>
|
||||
public List<string> ids { get; set; }
|
||||
|
||||
|
||||
@@ -7,8 +7,12 @@ using JNPF.Common.Security;
|
||||
|
||||
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; }
|
||||
/// <summary>
|
||||
/// 工单id
|
||||
@@ -25,6 +29,10 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
|
||||
/// 物料编号
|
||||
/// </summary>
|
||||
public string? material_code { get; set; }
|
||||
/// <summary>
|
||||
/// 物料名称
|
||||
/// </summary>
|
||||
public string material_name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工单类型:1-正常工单、2-返工工单、3-试制工单
|
||||
@@ -39,37 +47,37 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
|
||||
/// <summary>
|
||||
/// 计划生产数量
|
||||
/// </summary>
|
||||
public int? plan_qty { get; set; }
|
||||
public string plan_qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 已投入数量
|
||||
/// </summary>
|
||||
public int? input_qty { get; set; }
|
||||
public string input_qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 已完工数量
|
||||
/// </summary>
|
||||
public int? complete_qty { get; set; }
|
||||
public string complete_qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 报废数量
|
||||
/// </summary>
|
||||
public int? scrap_qty { get; set; }
|
||||
public string scrap_qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 计划开始时间
|
||||
/// </summary>
|
||||
public DateTime? plan_start_date { get; set; }
|
||||
public string plan_start_date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 计划结束时间
|
||||
/// </summary>
|
||||
public DateTime? plan_end_date { get; set; }
|
||||
public string plan_end_date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否生派工单
|
||||
/// </summary>
|
||||
public int? is_create_dispatch { get; set; }
|
||||
public string is_create_dispatch { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -80,7 +88,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
|
||||
/// <summary>
|
||||
/// 是否合并
|
||||
/// </summary>
|
||||
public int? is_merge { get; set; }
|
||||
public string is_merge { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 组合工单
|
||||
@@ -100,7 +108,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime? create_time { get; set; }
|
||||
public string create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
@@ -110,19 +118,20 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
public string modify_time { get; set; }
|
||||
/// <summary>
|
||||
/// 物料ID
|
||||
/// </summary>
|
||||
public string? material_id { get; set; }
|
||||
|
||||
public string? material_id_id { get; set; }
|
||||
/// <summary>
|
||||
/// 已排产数量
|
||||
/// </summary>
|
||||
public int? scheduled_qty { get; set; }
|
||||
public string scheduled_qty { get; set; }
|
||||
/// <summary>
|
||||
/// 父工单id
|
||||
/// </summary>
|
||||
public string parent_id { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,5 +48,9 @@ public partial class PrdMoTaskDefect : BaseEntity<string>
|
||||
/// 批次
|
||||
/// </summary>
|
||||
public string? batch { get; set; }
|
||||
/// <summary>
|
||||
/// 报废数量
|
||||
/// </summary>
|
||||
public int scrap_qty { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,11 @@ using Aspose.Cells.Drawing.Texts;
|
||||
using JNPF.Systems.Entitys.Permission;
|
||||
using WebSocketSharp.Frame;
|
||||
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
|
||||
{
|
||||
@@ -45,6 +50,7 @@ namespace Tnb.ProductionMgr
|
||||
public class PrdMoTaskService : IOverideVisualDevService, IPrdMoTaskService, IDynamicApiController, ITransient
|
||||
{
|
||||
private const string ModuleId = "25567924238373";
|
||||
private const string MoModuleId = "25018860321301";
|
||||
private readonly ISqlSugarRepository<PrdTask> _repository;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IDictionaryDataService _dictionaryDataService;
|
||||
@@ -98,12 +104,12 @@ namespace Tnb.ProductionMgr
|
||||
[HttpGet("{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>()
|
||||
.InnerJoin<ToolMolds>((a, b) => a.mold_id == b.id)
|
||||
.InnerJoin<BasMaterial>((a, b, c) => a.material_id == c.id)
|
||||
.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_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)
|
||||
.Where((a, b) => a.mold_id == moldId)
|
||||
.Select((a, b) => new EquipmentListOutput
|
||||
.Select((a, b) => new Entities.Dto.EquipmentListOutput
|
||||
{
|
||||
eqp_id = b.id,
|
||||
eqp_code = b.code,
|
||||
@@ -255,7 +261,7 @@ namespace Tnb.ProductionMgr
|
||||
material_code = materialCode,
|
||||
material_name = materialName,
|
||||
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 =>
|
||||
{
|
||||
@@ -271,7 +277,7 @@ namespace Tnb.ProductionMgr
|
||||
icmo_qty = db.Queryable<PrdMoTask>().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty,
|
||||
reported_work_qty = 0,
|
||||
prd_qty = 0,
|
||||
//scrap_qty = 0,
|
||||
scrap_qty = 0,
|
||||
};
|
||||
return res;
|
||||
}
|
||||
@@ -471,29 +477,74 @@ namespace Tnb.ProductionMgr
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<dynamic> GetUnSchedulingList()
|
||||
public async Task<dynamic> GetUnSchedulingList([FromQuery] VisualDevModelListQueryInput input)
|
||||
{
|
||||
List<PrdMotreeOutput> trees = new();
|
||||
var list = await _db.Queryable<PrdMo>().Where(it => string.IsNullOrEmpty(it.parent_id) && it.mo_status == DictConst.ScheduledId).ToListAsync();
|
||||
foreach (var item in list)
|
||||
List<PrdMoTreeOutput> trees = new();
|
||||
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(MoModuleId, true);
|
||||
var data = await _runService.GetListResult(templateEntity, input);
|
||||
|
||||
if (data?.list?.Count > 0)
|
||||
{
|
||||
var node = item.Adapt<PrdMotreeOutput>();
|
||||
node.mo_id = item.id;
|
||||
node.id = SnowflakeIdHelper.NextId();
|
||||
node.parentId = "0";
|
||||
var items = await _db.Queryable<PrdMo>().Where(it => it.parent_id == item.id).ToListAsync();
|
||||
if (items?.Count() > 0)
|
||||
var parentIdField = nameof(PrdMo.parent_id);
|
||||
var nodes = data.list.Where(it => it.ContainsKey(parentIdField) && it[parentIdField].IsNullOrEmpty()).ToList();
|
||||
foreach (var row in nodes)
|
||||
{
|
||||
var childNodes = items.Adapt<List<PrdMotreeOutput>>();
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
var pkName = "material_id_id";
|
||||
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
|
||||
@@ -769,7 +820,7 @@ namespace Tnb.ProductionMgr
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("组装包装排产时报错", ex);
|
||||
JNPF.Logging.Log.Error("组装包装排产时报错", ex);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
}
|
||||
return row > 0;
|
||||
@@ -1037,7 +1088,7 @@ namespace Tnb.ProductionMgr
|
||||
defect.defective_item = dItem.defective_item;
|
||||
defect.defective_item_qty = dItem.defective_item_qty;
|
||||
defect.create_id = _userManager.UserId;
|
||||
|
||||
defect.scrap_qty = input.scrap_qty;
|
||||
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");
|
||||
var curMo = await _db.Queryable<PrdMo>().FirstAsync(it => it.id == input.mo_id);
|
||||
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))
|
||||
.Select((a, b) => new
|
||||
|
||||
|
||||
var outMaterials = await _db.Queryable<BasMbom>().InnerJoin<BasMbomProcess>((a, b) => a.id == b.mbom_id)
|
||||
.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,
|
||||
material_code = a.code,
|
||||
num = b.num,
|
||||
})
|
||||
.ToListAsync();
|
||||
foreach (var om in outputMaterials)
|
||||
{
|
||||
PrdMo subMo = new();
|
||||
subMo.material_id = om.material_id;
|
||||
subMo.material_code = om.material_code;
|
||||
subMo.plan_qty = om.num.ParseToInt() * curMo.plan_qty;
|
||||
subMo.mo_type = curMo.mo_type;
|
||||
subMo.parent_id = curMo.id;
|
||||
subMo.plan_start_date = curMo.plan_start_date;
|
||||
subMo.plan_end_date = curMo.plan_end_date;
|
||||
subMo.create_id = _userManager.UserId;
|
||||
subMo.create_time = DateTime.Now;
|
||||
subMo.mo_status = DictConst.WaitProductId;
|
||||
subMoList.Add(subMo);
|
||||
PrdMo subMo = new();
|
||||
subMo.material_id = om.id;
|
||||
subMo.material_code = om.code;
|
||||
subMo.plan_qty = dicOutMaterialNum.ContainsKey(om.id) ? dicOutMaterialNum[om.id] * curMo.plan_qty : 0;
|
||||
subMo.mo_type = curMo.mo_type;
|
||||
subMo.parent_id = curMo.id;
|
||||
subMo.plan_start_date = curMo.plan_start_date;
|
||||
subMo.plan_end_date = curMo.plan_end_date;
|
||||
subMo.create_id = _userManager.UserId;
|
||||
subMo.create_time = DateTime.Now;
|
||||
subMo.mo_status = DictConst.WaitProductId;
|
||||
subMoList.Add(subMo);
|
||||
}
|
||||
//生成子工单编码
|
||||
for (int i = 0; i < subMoList.Count; i++)
|
||||
{
|
||||
var num = (i + 1).ToString().PadLeft(2, '0');
|
||||
subMoList[i].mo_code = $"{curMo.mo_code}-{num}";
|
||||
}
|
||||
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
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user