128 lines
5.6 KiB
C#
128 lines
5.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Dynamic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using System.Reactive.Joins;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aop.Api.Domain;
|
|
using Aspose.Cells.Drawing;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Message.Service;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.TaskScheduler;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.EquipMgr.Interfaces;
|
|
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 Dictionary<string, string>();
|
|
dic.Add("ToBeStarted", "待开工");
|
|
dic.Add("InProgress", "进行中");
|
|
dic.Add("Closed", "关闭");
|
|
dic.Add("Complated", "完工");
|
|
dic.Add("ToBeScheduled", "待下发");
|
|
dic.Add("Pause", "暂停");
|
|
dic.Add("Exception", "异常");
|
|
dic.Add("Revoke", "撤销");
|
|
List<dynamic> result = new();
|
|
var List = await _db.Queryable<PrdMoTask>()
|
|
.WhereIF(!string.IsNullOrEmpty(stationId), p => p.workstation_id == stationId)
|
|
.ToListAsync();
|
|
var materials = await _db.Queryable<BasMaterial>().ToListAsync();
|
|
foreach (var 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)
|
|
{
|
|
var list = _db.Queryable<AndonBreakDown>().ToList();
|
|
AndonRecords andonRecord = new AndonRecords();
|
|
andonRecord.mo_id = AndonRecordInput.mo_id;
|
|
andonRecord.breakdown_type = list.Where(p => p.id == AndonRecordInput.breakdown).Any() ? list.Where(p => p.id == AndonRecordInput.breakdown).First().type_id : "";
|
|
andonRecord.breakdown = AndonRecordInput.breakdown;
|
|
andonRecord.create_time = DateTime.Now;
|
|
andonRecord.create_id = _userManager.UserId;
|
|
await _db.Insertable(andonRecord).ExecuteCommandAsync();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetAndonCascaderOptions()
|
|
{
|
|
Dictionary<string, object> result = new Dictionary<string, object>();
|
|
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 List<AndonCascaderOptionsOuput>();
|
|
foreach (var 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;
|
|
}
|
|
}
|
|
}
|