生产相关列表倒叙,生产工单列表重写

This commit is contained in:
2023-07-28 16:26:27 +08:00
parent 703eda463e
commit c18b937dc1
10 changed files with 163 additions and 59 deletions

View File

@@ -0,0 +1,22 @@
namespace Tnb.ProductionMgr.Entities.Dto
{
public class PrdMoListOuput
{
public string id { get; set; }
public string mo_type { get; set; }
public string mo_source { get; set; }
public string mo_code { get; set; }
public string plan_start_date { get; set; }
public string plan_end_date { get; set; }
public string material_id { get; set; }
public int? plan_qty { get; set; }
public string unit_id { get; set; }
public string mo_status { get; set; }
public string? remark { get; set; }
public string combine_mo_code { get; set; }
public string material_id_id { get; set; }
public List<PrdMoListOuput> children { get; set; } = new List<PrdMoListOuput>();
}
}

View File

@@ -0,0 +1,14 @@
namespace Tnb.ProductionMgr.Entities.Dto
{
public class PrdMoTaskIssueListOutput
{
public string id { get; set; }
public string mo_task_code { get; set; }
public string material_id { get; set; }
public string mold_id { get; set; }
public string mo_task_status { get; set; }
public int? plan_qty { get; set; }
public int? scheduled_qty { get; set; }
public string create_time { get; set; }
}
}

View File

@@ -84,6 +84,8 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
/// 工序名称
/// </summary>
public string process_name { get; set;}
public string create_time { get; set; }
}

View File

@@ -17,5 +17,6 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
public string estimated_start_date { get; set; }
public string estimated_end_date { get; set; }
public string eqp_id { get; set; }
public string create_time { get; set; }
}
}

View File

@@ -227,5 +227,11 @@ public partial class PrdMo : BaseEntity<string>
/// 物料单位
/// </summary>
public string? unit_id { get; set; }
/// <summary>
/// 工单来源
/// </summary>
public string? mo_source { get; set; }
}

View File

@@ -1,28 +1,16 @@
using System.Reflection.Emit;
using System.Text;
using Aop.Api.Domain;
using DbModels;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Core.Manager;
using JNPF.Common.Extension;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extensitions.EventBus;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
using JNPF.VisualDev.Interfaces;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging.Abstractions;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Crypto.Generators;
using Senparc.Weixin.Work.AdvancedAPIs.MailList;
using SqlSugar;
using Tnb.BasicData;
using Tnb.BasicData.Entities;
@@ -74,43 +62,103 @@ namespace Tnb.ProductionMgr
OverideFuncs.GetListAsync = GetList;
}
// private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
// {
// var db = _repository.AsSugarClient();
// VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
// var data = await _runService.GetListResult(templateEntity, input);
// if (data?.list?.Count > 0)
// {
// foreach (var row in data.list)
// {
// var dic = row.ToDictionary(x => x.Key, x => x.Value);
// var pkName = "material_id_id";
// if (dic.ContainsKey(pkName))
// {
// var materialId = dic[pkName]?.ToString();
// var material = await db.Queryable<BasMaterial>().FirstAsync(it => it.id == materialId);
// if (material != null)
// {
// row.Add("material_name", material.name);
// row.Add($"material_attribute", material.attribute);
// if (dic.ContainsKey("material_id"))
// {
// row["material_id"] = material.code + "/" + material.name;
// }
// }
//
// if (dic.ContainsKey("unit_id"))
// {
// string unitId = dic["unit_id"]?.ToString() ?? "";
// var unit = await db.Queryable<DictionaryDataEntity>().SingleAsync(x => x.Id == unitId);
// row["unit_id"] = unit?.FullName ?? "";
// }
// }
// }
// }
// return data!;
// }
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
{
var db = _repository.AsSugarClient();
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
var data = await _runService.GetListResult(templateEntity, input);
if (data?.list?.Count > 0)
{
foreach (var row in data.list)
Dictionary<string, string> queryJson = !string.IsNullOrEmpty(input.queryJson) ? Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson) : new Dictionary<string, string>();
string moCode = queryJson.ContainsKey("mo_code") ? queryJson["mo_code"].ToString() : "";
string moStatus = queryJson.ContainsKey("mo_status") ? queryJson["mo_status"].ToString() : "";
string combineMoCode = queryJson.ContainsKey("combine_mo_code") ? queryJson["combine_mo_code"].ToString() : "";
var result = await db.Queryable<PrdMo>()
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
.LeftJoin<DictionaryTypeEntity>((a, b, c) => c.EnCode == DictConst.MeasurementUnit)
.LeftJoin<DictionaryDataEntity>((a, b, c, d) => c.Id == d.DictionaryTypeId && a.unit_id == d.Id)
.LeftJoin<DictionaryDataEntity>((a, b, c, d, e) => a.mo_status == e.Id)
.LeftJoin<DictionaryDataEntity>((a, b, c, d, e,f) => a.mo_type==f.Id)
.WhereIF(!string.IsNullOrEmpty(moCode), (a, b, c, d, e) => a.mo_code.Contains(moCode))
.WhereIF(!string.IsNullOrEmpty(combineMoCode),
(a, b, c, d, e) => a.combine_mo_code.Contains(combineMoCode))
.WhereIF(!string.IsNullOrEmpty(moStatus), (a, b, c, d, e) => a.mo_status == moStatus)
.Where(a=>SqlFunc.IsNullOrEmpty(a.parent_id))
.OrderByDescending(a=>a.create_time)
.Select((a, b, c, d, e,f) => new PrdMoListOuput
{
var dic = row.ToDictionary(x => x.Key, x => x.Value);
var pkName = "material_id_id";
if (dic.ContainsKey(pkName))
{
var materialId = dic[pkName]?.ToString();
var material = await db.Queryable<BasMaterial>().FirstAsync(it => it.id == materialId);
if (material != null)
id = a.id,
mo_type = f.FullName,
mo_source = a.mo_source=="1" ? "ERP同步" : "新建/导入",
mo_code = a.mo_code,
plan_start_date = a.plan_start_date==null ? "" : a.plan_start_date.Value.ToString("yyyy-MM-dd"),
plan_end_date = a.plan_end_date==null ? "" : a.plan_end_date.Value.ToString("yyyy-MM-dd"),
material_id = b.code+"/"+b.name,
material_id_id = b.id,
plan_qty = a.plan_qty,
unit_id = d.FullName,
mo_status = e.FullName,
remark = a.remark,
children = SqlFunc.Subqueryable<PrdMo>()
.LeftJoin<BasMaterial>((aa, bb) => aa.material_id == bb.id)
.LeftJoin<DictionaryTypeEntity>((aa, bb, cc) => cc.EnCode == DictConst.MeasurementUnit)
.LeftJoin<DictionaryDataEntity>((aa, bb, cc, dd) => cc.Id == dd.DictionaryTypeId && aa.unit_id == dd.Id)
.LeftJoin<DictionaryDataEntity>((aa, bb, cc, dd, ee) => aa.mo_status == ee.Id)
.LeftJoin<DictionaryDataEntity>((aa, bb, cc, dd, ee,ff) => aa.mo_type==ff.Id)
.Where(aa=>aa.parent_id==a.id)
.ToList((aa,bb,cc,dd,ee,ff)=>new PrdMoListOuput
{
row.Add("material_name", material.name);
row.Add($"material_attribute", material.attribute);
if (dic.ContainsKey("material_id"))
{
row["material_id"] = material.code + "/" + material.name;
}
}
if (dic.ContainsKey("unit_id"))
{
string unitId = dic["unit_id"]?.ToString() ?? "";
var unit = await db.Queryable<DictionaryDataEntity>().SingleAsync(x => x.Id == unitId);
row["unit_id"] = unit?.FullName ?? "";
}
}
}
}
return data!;
id = aa.id,
mo_type = ff.FullName,
mo_source = aa.mo_source=="1" ? "ERP同步" : "新建/导入",
mo_code = aa.mo_code,
plan_start_date = aa.plan_start_date==null ? "" : aa.plan_start_date.Value.ToString("yyyy-MM-dd"),
plan_end_date = aa.plan_end_date==null ? "" : aa.plan_end_date.Value.ToString("yyyy-MM-dd"),
material_id = bb.code+"/"+bb.name,
material_id_id = bb.id,
plan_qty = aa.plan_qty,
unit_id = dd.FullName,
mo_status = ee.FullName,
remark = aa.remark,
})
}).ToPagedListAsync(input.currentPage, int.MaxValue);
return PageResult<PrdMoListOuput>.SqlSugarPageResult(result);
}
#region Get

View File

@@ -25,6 +25,7 @@ using JNPF.Systems.Entitys.System;
using Newtonsoft.Json;
using Senparc.Weixin.Work.AdvancedAPIs.OaDataOpen;
using Tnb.BasicData;
using Tnb.ProductionMgr.Entities.Dto;
namespace Tnb.ProductionMgr
{
@@ -116,7 +117,8 @@ namespace Tnb.ProductionMgr
.WhereIF(!string.IsNullOrEmpty(moTaskCode), (a, b, c, d) => a.mo_task_code.Contains(moTaskCode))
.WhereIF(!string.IsNullOrEmpty(moTaskStatus), (a, b, c, d) => a.mo_task_status == moTaskStatus)
.Where((a,b,c,d,e,f)=>a.schedule_type==1)
.Select((a, b, c, d,e,f) => new PrdMoTask
.OrderByDescending(a=>a.create_time)
.Select((a, b, c, d,e,f) => new PrdMoTaskIssueListOutput
{
id = a.id,
mo_task_code = a.mo_task_code,
@@ -125,8 +127,9 @@ namespace Tnb.ProductionMgr
mo_task_status = d.FullName,
plan_qty = f.plan_qty,
scheduled_qty = a.scheduled_qty,
create_time = a.create_time==null ? "" :a.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"),
}).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<PrdMoTask>.SqlSugarPageResult(result);
return PageResult<PrdMoTaskIssueListOutput>.SqlSugarPageResult(result);
}
}
}

View File

@@ -303,6 +303,7 @@ namespace Tnb.ProductionMgr
.LeftJoin<ToolMolds>((a, b, c, d) => a.mold_id == d.id)
.LeftJoin<EqpEquipment>((a, b, c, d, e) => a.eqp_id == e.id)
.Where((a, b, c, d, e) => a.mo_id == moId)
.OrderByDescending((a,b,c,d,e)=>a.create_time)
.Select((a, b, c, d, e) => new PrdMoTaskOutput
{
mo_task_code = a.mo_task_code,
@@ -321,6 +322,7 @@ namespace Tnb.ProductionMgr
complete_qty = SqlFunc.IsNull(a.reported_work_qty,0)+SqlFunc.IsNull(a.scrap_qty,0),
process_code = SqlFunc.Subqueryable<BasProcess>().Where(it => it.id == a.process_id).Select(it => it.process_code),
process_name = SqlFunc.Subqueryable<BasProcess>().Where(it => it.id == a.process_id).Select(it => it.process_name),
create_time = a.create_time==null ? "" : a.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"),
})
.Mapper(it =>
{
@@ -335,6 +337,7 @@ namespace Tnb.ProductionMgr
.LeftJoin<OrganizeEntity>((a, b, c, d) => a.workline_id == d.Id)
.LeftJoin<BasProcess>((a,b,c,d,e)=>a.process_id==e.id)
.Where((a, b, c, d) => (b.id == moId || b.parent_id == moId) && SqlFunc.IsNullOrEmpty(a.parent_id))
.OrderByDescending((a,b,c,d,e)=>a.create_time)
.Select((a, b, c, d,e) => new PrdMoTaskOutput
{
mo_task_code = a.mo_task_code,
@@ -350,6 +353,7 @@ namespace Tnb.ProductionMgr
estimated_end_date = a.estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss"),
plan_qty = a.scheduled_qty,
complete_qty = SqlFunc.IsNull(a.reported_work_qty,0)+SqlFunc.IsNull(a.scrap_qty,0),
create_time = a.create_time==null ? "" : a.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"),
})
.Mapper(it =>
{
@@ -375,6 +379,7 @@ namespace Tnb.ProductionMgr
.LeftJoin<BasMbom>((a, b, c, d) => a.bom_id == d.id)
.WhereIF(!string.IsNullOrEmpty(input.mo_task_code), (a, b, c, d) => a.mo_task_code.Contains(input.mo_task_code))
.Where((a, b, c, d) => a.schedule_type == 2 && string.IsNullOrEmpty(a.parent_id))
.OrderByDescending(a=>a.create_time)
.Select((a, b, c, d) => new PackSechelToBeIssueListOutput
{
mo_task_id = a.id,
@@ -1800,19 +1805,21 @@ namespace Tnb.ProductionMgr
worklineIds = await db.Queryable<OrganizeEntity>().Where(x => x.ParentId == eqpId && x.Category==DictConst.RegionCategoryWorklineCode && x.DeleteMark==null).Select(x=>x.Id).ToListAsync();
equipIds = await db.Queryable<EqpEquipment>().Where(x => x.equip_type_id == eqpId).Select(x => x.id).ToListAsync();
}
var result = await db.Queryable<PrdMoTask>()
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
.LeftJoin<DictionaryTypeEntity>((a, b, c) => c.EnCode == DictConst.TaskStatus)
.LeftJoin<DictionaryDataEntity>((a, b, c, d) => c.Id == d.DictionaryTypeId && a.mo_task_status == d.EnCode)
.LeftJoin<ToolMolds>((a,b,c,d,e)=>a.mold_id==e.id)
.LeftJoin<PrdMo>((a,b,c,d,e,f)=>a.mo_id==f.id)
.LeftJoin<OrganizeEntity>((a,b,c,d,e,f,g)=>a.workline_id==g.Id)
.LeftJoin<EqpEquipment>((a,b,c,d,e,f,g,h)=>a.eqp_id==h.id)
.LeftJoin<DictionaryDataEntity>((a, b, c, d) =>
c.Id == d.DictionaryTypeId && a.mo_task_status == d.EnCode)
.LeftJoin<ToolMolds>((a, b, c, d, e) => a.mold_id == e.id)
.LeftJoin<PrdMo>((a, b, c, d, e, f) => a.mo_id == f.id)
.LeftJoin<OrganizeEntity>((a, b, c, d, e, f, g) => a.workline_id == g.Id)
.LeftJoin<EqpEquipment>((a, b, c, d, e, f, g, h) => a.eqp_id == h.id)
.WhereIF(!string.IsNullOrEmpty(moTaskCode), (a, b, c, d) => a.mo_task_code.Contains(moTaskCode))
.WhereIF(!string.IsNullOrEmpty(eqpId) && equipIds.Count<=0 && worklineIds.Count<=0, (a, b, c, d) => a.workline_id==eqpId || a.eqp_id==eqpId)
.WhereIF(worklineIds.Count>0,(a, b, c, d)=>worklineIds.Contains(a.workline_id))
.WhereIF(equipIds.Count>0,(a, b, c, d)=>equipIds.Contains(a.eqp_id))
.WhereIF(!string.IsNullOrEmpty(eqpId) && equipIds.Count <= 0 && worklineIds.Count <= 0,
(a, b, c, d) => a.workline_id == eqpId || a.eqp_id == eqpId)
.WhereIF(worklineIds.Count > 0, (a, b, c, d) => worklineIds.Contains(a.workline_id))
.WhereIF(equipIds.Count > 0, (a, b, c, d) => equipIds.Contains(a.eqp_id))
.Select((a, b, c, d,e,f,g,h) => new WorkOrderAdjustmentListOutput
{
id = a.id,
@@ -1827,7 +1834,8 @@ namespace Tnb.ProductionMgr
estimated_start_date = a.estimated_start_date==null ? "" : a.estimated_start_date.Value.ToString("yyyy-MM-dd"),
estimated_end_date = a.estimated_end_date==null ? "" : a.estimated_end_date.Value.ToString("yyyy-MM-dd"),
eqp_id = a.eqp_id==null ? "" : h.code+"/"+h.name,
}).ToPagedListAsync(input.currentPage, input.pageSize);
create_time = a.create_time==null ? "" :a.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss")
}).OrderByDescending(a => a.create_time).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<WorkOrderAdjustmentListOutput>.SqlSugarPageResult(result);
}

View File

@@ -81,6 +81,7 @@ namespace Tnb.ProductionMgr
// .WhereIF(end, a => a.estimated_end_date != null && endTimes[0] <= a.estimated_end_date && endTimes[1] >= a.estimated_end_date)
.WhereIF(!string.IsNullOrEmpty(input.workline), a => list.Where(p => p.EnCode.Contains(input.workline) || p.FullName.Contains(input.workline)).Select(p => p.Id).ToList().Contains(a.workline_id!))
.Where(a => string.IsNullOrEmpty(a.parent_id) && a.schedule_type == 2 && a.mo_task_status != "ToBeScheduled")
.OrderByDescending(a=>a.create_time)
.Select((a, b, c) => new PrdMoTask
{
id = a.id,
@@ -187,7 +188,7 @@ namespace Tnb.ProductionMgr
process_name = b.process_name,
plan_start_date = a.estimated_start_date,
plan_end_date = a.estimated_end_date,
plan_qty = c.scheduled_qty,
plan_qty = a.scheduled_qty,
//complete_qty = SqlFunc.Subqueryable<PrdReport>().Where(it => it.mo_task_code == a.mo_task_code).Sum(it => it.reported_work_qty),
complete_qty = SqlFunc.IsNull(a.reported_work_qty,0) + SqlFunc.IsNull(a.scrap_qty,0),
mo_task_status = a.mo_task_status,

View File

@@ -155,8 +155,7 @@ namespace Tnb.ProductionMgr
plan_qty = a.scheduled_qty,
complete_qty = a.reported_work_qty,
mo_task_status = a.mo_task_status,
schedule_type = a.schedule_type.ToString()
schedule_type = a.schedule_type.ToString(),
})
.Mapper(x=>x.mo_task_status=dic[x.mo_task_status].ToString())
.ToPagedListAsync(input.currentPage, input.pageSize);