118 lines
5.3 KiB
C#
118 lines
5.3 KiB
C#
using System.Dynamic;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.ProductionMgr.Entities;
|
|
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
|
using Tnb.ProductionMgr.Entities.Entity;
|
|
using Tnb.ProductionMgr.Interfaces;
|
|
|
|
namespace Tnb.ProductionMgr
|
|
{
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class AndonService : IAndonService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
public AndonService(ISqlSugarRepository<AndonRecords> repository, IUserManager userManager)
|
|
{
|
|
_userManager = userManager;
|
|
_db = repository.AsSugarClient();
|
|
}
|
|
[HttpGet]
|
|
public async Task<dynamic> GetPrdTask(string stationId)
|
|
{
|
|
Dictionary<string, string> dic = new()
|
|
{
|
|
{ "ToBeStarted", "待开工" },
|
|
{ "InProgress", "进行中" },
|
|
{ "Closed", "关闭" },
|
|
{ "Complated", "完工" },
|
|
{ "ToBeScheduled", "待下发" },
|
|
{ "Pause", "暂停" },
|
|
{ "Exception", "异常" },
|
|
{ "Revoke", "撤销" }
|
|
};
|
|
List<dynamic> result = new();
|
|
List<PrdMoTask> List = await _db.Queryable<PrdMoTask>()
|
|
.WhereIF(!string.IsNullOrEmpty(stationId), p => p.workstation_id == stationId)
|
|
.ToListAsync();
|
|
List<BasMaterial> materials = await _db.Queryable<BasMaterial>().ToListAsync();
|
|
foreach (PrdMoTask data in List)
|
|
{
|
|
dynamic info = new ExpandoObject();
|
|
info.id = data.id;
|
|
info.material_id = materials.Where(p => p.id == data.material_id).Any() ? materials.Where(p => p.id == data.material_id).First().name : "";
|
|
info.material_id_id = data.material_id;
|
|
info.status = dic.Where(p => p.Key == data.mo_task_status).Any() ? dic.Where(p => p.Key == data.mo_task_status).First().Value : "";
|
|
info.mo_code = data.mo_task_code;
|
|
info.mo_type = data.schedule_type == 1 ? "注塑工单" : "组装工单";
|
|
info.plan_gty = data.plan_qty;
|
|
info.plan_start_date = data.estimated_start_date == null ? "" : ((DateTime)data.estimated_start_date!).ToString("yyyy-MM-dd");
|
|
info.plan_end_date = data.estimated_end_date == null ? "" : ((DateTime)data.estimated_end_date!).ToString("yyyy-MM-dd");
|
|
result.Add(info);
|
|
}
|
|
_ = result.OrderByDescending(p => p.plan_start_date);
|
|
return result;
|
|
}
|
|
[HttpPost]
|
|
public async Task SaveData(AndonRecordInput AndonRecordInput)
|
|
{
|
|
List<AndonBreakDown> list = _db.Queryable<AndonBreakDown>().ToList();
|
|
AndonRecords andonRecord = new()
|
|
{
|
|
mo_id = AndonRecordInput.mo_id,
|
|
breakdown_type = list.Where(p => p.id == AndonRecordInput.breakdown).Any() ? list.Where(p => p.id == AndonRecordInput.breakdown).First().type_id : "",
|
|
breakdown = AndonRecordInput.breakdown,
|
|
create_time = DateTime.Now,
|
|
create_id = _userManager.UserId
|
|
};
|
|
_ = await _db.Insertable(andonRecord).ExecuteCommandAsync();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetAndonCascaderOptions()
|
|
{
|
|
Dictionary<string, object> result = new();
|
|
List<AndonType> andonTypes = await _db.Queryable<AndonType>().ToListAsync();
|
|
List<AndonInfo> andonInfos = await _db.Queryable<AndonInfo>().ToListAsync();
|
|
List<AndonBreakDown> andonBreakDowns = await _db.Queryable<AndonBreakDown>().ToListAsync();
|
|
List<AndonCascaderOptionsOuput> options = new();
|
|
foreach (AndonType andonType in andonTypes)
|
|
{
|
|
options.Add(new AndonCascaderOptionsOuput()
|
|
{
|
|
label = andonType.name,
|
|
value = andonType.id,
|
|
children = andonInfos.Where(x => x.andon_type == andonType.id).Select(x => new AndonCascaderOptionsOuput()
|
|
{
|
|
label = x.name,
|
|
value = x.id,
|
|
children = andonBreakDowns.Where(y => x.breakdown_id.Contains(y.id)).Select(y => new AndonCascaderOptionsOuput()
|
|
{
|
|
label = y.name,
|
|
value = y.id
|
|
}).ToList()
|
|
}).ToList()
|
|
});
|
|
}
|
|
|
|
string defaultValue = "";
|
|
if (!string.IsNullOrEmpty(andonInfos.FirstOrDefault()?.breakdown_id))
|
|
{
|
|
string[] breakdownIdArr = JsonConvert.DeserializeObject<string[]>(andonInfos.FirstOrDefault()?.breakdown_id);
|
|
defaultValue = breakdownIdArr[0];
|
|
}
|
|
|
|
result.Add("options", options);
|
|
result.Add("defaultValue", defaultValue);
|
|
return result;
|
|
}
|
|
}
|
|
}
|