1
This commit is contained in:
159
ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs
Normal file
159
ProductionMgr/Tnb.ProductionMgr/PrdPackReportService.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aspose.Cells.Drawing;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Filter;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.Systems.Entitys.Permission;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.CodeAnalysis.Operations;
|
||||
using NPOI.POIFS.Properties;
|
||||
using Spire.Pdf.Widget;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.ProductionMgr.Entities;
|
||||
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
||||
using Tnb.ProductionMgr.Interfaces;
|
||||
|
||||
namespace Tnb.ProductionMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 组装、包装生产提报服务
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
|
||||
public class PrdPackReportService : IPrdPackReportService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IDictionaryDataService _dictionaryDataService;
|
||||
private static Dictionary<string, Tuple<string,string>> _dicWorkLine = new Dictionary<string, Tuple<string, string>>();
|
||||
public PrdPackReportService(ISqlSugarRepository<PrdMoTask> repository, IDictionaryDataService dictionaryDataService)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_dictionaryDataService = dictionaryDataService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取组装包装生产任务记录,树形结构
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<dynamic> GetList(PrdPackReportQueryInput input)
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException("input");
|
||||
List<PackReportTreeOutput> trees = new();
|
||||
var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId);
|
||||
if (_dicWorkLine.Count < 1)
|
||||
{
|
||||
var list = await _db.Queryable<OrganizeEntity>().Where(it => it.Category == "workline").ToListAsync();
|
||||
_dicWorkLine = list.ToDictionary(x => x.Id, x => Tuple.Create<string, string>(x.EnCode, x.FullName));
|
||||
}
|
||||
|
||||
var items = await _db.Queryable<PrdMoTask>().LeftJoin<BasProcess>((a, b) => a.process_id == b.id).LeftJoin<PrdMo>((a, b, c) => a.mo_id == c.id)
|
||||
.WhereIF(!string.IsNullOrEmpty(input.mo_task_code), a => a.mo_task_code == input.mo_task_code)
|
||||
.Where(a => string.IsNullOrEmpty(a.parent_id) && a.schedule_type == 2 && a.mo_task_status != "ToBeScheduled")
|
||||
.Select((a, b, c) => new PrdMoTask
|
||||
{
|
||||
id = a.id,
|
||||
mo_task_code = a.mo_task_code,
|
||||
workline_id = a.workline_id,
|
||||
process_id = a.process_id,
|
||||
plan_start_date = a.estimated_start_date,
|
||||
plan_end_date = a.estimated_end_date,
|
||||
plan_qty = c.plan_qty,
|
||||
complete_qty = SqlFunc.Subqueryable<PrdReport>().Where(it => it.mo_task_code == a.mo_task_code).Sum(it => it.reported_work_qty),
|
||||
mo_task_status = a.mo_task_status,
|
||||
|
||||
})
|
||||
.ToPagedListAsync(input.currentPage, input.pageSize);
|
||||
_db.ThenMapper(items.list, it =>
|
||||
{
|
||||
it.mo_task_status = it.mo_task_status.IsNotEmptyOrNull() && dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "";
|
||||
});
|
||||
|
||||
if (items != null && items.list != null && items.list.Any())
|
||||
{
|
||||
foreach (var item in items.list)
|
||||
{
|
||||
var node = item.Adapt<PackReportTreeOutput>();
|
||||
node.parentId = "0";
|
||||
if (item.workline_id.IsNotEmptyOrNull())
|
||||
{
|
||||
var workLine = _dicWorkLine.ContainsKey(item.workline_id) ? (Tuple<string, string>)_dicWorkLine[item.workline_id] : null;
|
||||
if (workLine != null)
|
||||
{
|
||||
node.workline_id = $"{workLine.Item1}/{workLine.Item2}";
|
||||
}
|
||||
}
|
||||
node.plan_start_date = item.estimated_start_date.HasValue ? item.estimated_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
|
||||
node.plan_end_date = item.estimated_end_date.HasValue ? item.estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
|
||||
await GetChild(item.id, trees, dic);
|
||||
trees.Add(node);
|
||||
}
|
||||
}
|
||||
var treeList = trees.ToTree();
|
||||
SqlSugarPagedList<PackReportTreeOutput> pagedList = new()
|
||||
{
|
||||
list = treeList,
|
||||
pagination = new Pagination
|
||||
{
|
||||
CurrentPage = input.currentPage,
|
||||
PageSize = input.pageSize,
|
||||
Total = treeList.Count
|
||||
}
|
||||
};
|
||||
return PageResult<PackReportTreeOutput>.SqlSugarPageResult(pagedList);
|
||||
}
|
||||
|
||||
private async Task GetChild(string parentId, List<PackReportTreeOutput> nodes, Dictionary<string, object> dic)
|
||||
{
|
||||
var items = await _db.Queryable<PrdMoTask>().LeftJoin<BasProcess>((a, b) => a.process_id == b.id).LeftJoin<PrdMo>((a, b, c) => a.mo_id == c.id)
|
||||
.Where(a => a.parent_id == parentId && a.mo_task_status != "ToBeScheduled")
|
||||
.Select((a, b, c) => new PrdMoTask
|
||||
{
|
||||
id = a.id,
|
||||
mo_task_code = a.mo_task_code,
|
||||
workline_id = a.workline_id,
|
||||
process_id = a.process_id,
|
||||
process_code =b.process_code,
|
||||
process_name = b.process_name,
|
||||
plan_start_date = a.estimated_start_date,
|
||||
plan_end_date = a.estimated_end_date,
|
||||
plan_qty = c.plan_qty,
|
||||
complete_qty = SqlFunc.Subqueryable<PrdReport>().Where(it => it.mo_task_code == a.mo_task_code).Sum(it => it.reported_work_qty),
|
||||
mo_task_status = a.mo_task_status,
|
||||
|
||||
}).ToListAsync();
|
||||
_db.ThenMapper(items, it =>
|
||||
{
|
||||
it.mo_task_status = it.mo_task_status.IsNotEmptyOrNull() && dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "";
|
||||
});
|
||||
|
||||
if (items?.Count > 0)
|
||||
{
|
||||
var nsChild = items.Adapt<List<PackReportTreeOutput>>();
|
||||
for (int i = 0; i < nsChild.Count; i++)
|
||||
{
|
||||
nsChild[i].parentId = parentId;
|
||||
nsChild[i].process_id = $"{items[i].process_code}/{items[i].process_name}";
|
||||
nsChild[i].plan_start_date = items[i].estimated_start_date.HasValue ? items[i].estimated_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
|
||||
nsChild[i].plan_end_date = items[i].estimated_end_date.HasValue ? items[i].estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
|
||||
}
|
||||
|
||||
nodes.AddRange(nsChild);
|
||||
foreach (var item in items)
|
||||
{
|
||||
await GetChild(item.id, nodes, dic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user