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.Systems.Entitys.Permission; using JNPF.Systems.Entitys.System; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; using JNPF.VisualDev.Entitys.Dto.VisualDevModelData; using JNPF.VisualDev.Interfaces; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using SqlSugar; using Tnb.BasicData; using Tnb.BasicData.Entities; using Tnb.EquipMgr.Entities; using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Entities.Dto.PrdManage; using Tnb.ProductionMgr.Interfaces; namespace Tnb.ProductionMgr { [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)] [Route("api/[area]/[controller]/[action]")] [OverideVisualDev(ModuleId)] public class PrdTaskManageService : IPrdTaskManageService, IOverideVisualDevService, IDynamicApiController, ITransient { public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); private const string ModuleId = "25617945906709"; private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; private readonly IDictionaryDataService _dictionaryDataService; private readonly IRunService _runService; private readonly IVisualDevService _visualDevService; public PrdTaskManageService( ISqlSugarRepository repository, IUserManager userManager, IDictionaryDataService dictionaryDataService, IRunService runService, IVisualDevService visualDevService ) { _repository = repository; _userManager = userManager; _dictionaryDataService = dictionaryDataService; _runService = runService; _visualDevService = visualDevService; OverideFuncs.GetListAsync = GetList; } // private async Task 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) // { // var statusField = "mo_task_status"; // var scheduledTypeField = nameof(PrdMoTask.schedule_type); // data.list = data.list.Where(it => it.ContainsKey(statusField) && // it[statusField].IsNotEmptyOrNull() && it[statusField].ToString() != "待下发" && // it[scheduledTypeField].IsNotEmptyOrNull() && it[scheduledTypeField].ParseToInt() == 1 // ).ToList(); // foreach (var row in data.list) // { // var dic = row.ToDictionary(x => x.Key, x => x.Value); // var pkName = "material_id"; // if (dic.ContainsKey(pkName)) // { // var materialId = dic[pkName]?.ToString(); // var material = await db.Queryable().FirstAsync(it => it.id == materialId); // if (material != null) // { // row[pkName] = $"{material.code}/{material.name}"; // } // } // //模具 // if (dic.ContainsKey("mold_id")) // { // var moldId = dic["mold_id"]?.ToString(); // var mold = await db.Queryable().FirstAsync(it => it.id == moldId); // if (mold != null) // { // row["mold_id"] = $"{mold.mold_code}/{mold.mold_name}"; // } // } // //设备 // if (dic.ContainsKey("eqp_id")) // { // var eqpId = dic["eqp_id"]?.ToString(); // var eqp = await db.Queryable().FirstAsync(it => it.id == eqpId); // if (eqp != null) // { // row["eqp_id"] = $"{eqp.code}/{eqp.name}"; // } // } // // } // } // return data!; // } private async Task GetList(VisualDevModelListQueryInput input) { ISqlSugarClient db = _repository.AsSugarClient(); Dictionary? queryJson = !string.IsNullOrEmpty(input.queryJson) ? JsonConvert.DeserializeObject>(input.queryJson) : new Dictionary(); string? moTaskCode = queryJson != null && queryJson.ContainsKey("mo_task_code") ? queryJson["mo_task_code"].ToString() : ""; string? stationId = queryJson != null && queryJson.ContainsKey("stationId") ? queryJson["stationId"].ToString() : ""; if (string.IsNullOrEmpty(stationId)) { return new { pagination = new PageResult(), list = Array.Empty() }; } Dictionary dic = await _dictionaryDataService.GetDicByKey(DictConst.TaskStatus); DateTime[]? planStartDateArr = null; DateTime[]? planEndDateArr = null; if (queryJson.TryGetValue("plan_start_date", out object? value1)) { planStartDateArr = value1.ToObject().Select(x => x.TimeStampToDateTime()).ToArray(); } if (queryJson.TryGetValue("plan_end_date", out object? value2)) { planEndDateArr = value2.ToObject().Select(x => x.TimeStampToDateTime()).ToArray(); } SqlSugarPagedList result = await db.Queryable() .LeftJoin((a, b) => a.eqp_id == b.id) .LeftJoin((a, b, c) => a.material_id == c.id) .LeftJoin((a, b, c, d) => a.mold_id == d.id) .Where((a, b, c, d) => a.mo_task_status == DictConst.ToBeStartedEnCode || a.mo_task_status == DictConst.InProgressEnCode || a.mo_task_status == DictConst.MoStatusExceptionCode || a.mo_task_status == DictConst.MoStatusPauseCode || a.mo_task_status == DictConst.ComplatedEnCode) .Where((a, b, c, d) => a.schedule_type == 1) .WhereIF(!string.IsNullOrEmpty(moTaskCode), (a, b, c, d) => a.mo_task_code.Contains(moTaskCode)) .WhereIF(planStartDateArr != null, (a, b, c, d) => a.estimated_start_date >= planStartDateArr[0] && a.estimated_start_date <= planStartDateArr[1]) .WhereIF(planEndDateArr != null, (a, b, c, d) => a.estimated_end_date >= planEndDateArr[0] && a.estimated_end_date <= planEndDateArr[1]) .Where((a, b, c, d) => a.workstation_id == stationId) .OrderByDescending((a, b, c, d) => a.create_time) .Select((a, b, c, d) => new PrdTaskManageListOutput() { id = a.id, mo_task_code = a.mo_task_code, material_id = c.code + "/" + c.name, mold_id = d.mold_code + "/" + d.mold_name, eqp_id = b.code + "/" + b.name, plan_start_date = a.estimated_start_date == null ? "" : a.estimated_start_date.Value.ToString("yyyy-MM-dd"), plan_end_date = a.estimated_end_date == null ? "" : a.estimated_end_date.Value.ToString("yyyy-MM-dd"), plan_qty = a.scheduled_qty, complete_qty = a.reported_work_qty, mo_task_status = a.mo_task_status, schedule_type = a.schedule_type.ToString(), }) .Mapper(x => x.mo_task_status = dic[x.mo_task_status].ToString()) .ToPagedListAsync(input.currentPage, input.pageSize); return PageResult.SqlSugarPageResult(result); } // /// // /// 根据任务单号获取提报记录明细 // /// // /// 任务单号 // /// // /// returns: // ///
{ // ///
icmo_qty:任务计划数量 // ///
reported_work_qty:已报工数量 // ///
reported_qty:报工数量 // ///
prd_qty:生产数量 // ///
} // ///
// [HttpGet] // public async Task GetPrdReportByIcmoCode([FromRoute] string mo_task_code) // { // var db = _repository.AsSugarClient(); // var prdTask = await db.Queryable().FirstAsync(it => it.mo_task_code == mo_task_code); // var eqpCode = ""; // var moldCode = ""; // var materialCode = ""; // var materialName = ""; // var materialProp = ""; // if (prdTask != null) // { // var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); // var eqp = await db.Queryable().FirstAsync(it => it.id == prdTask.eqp_id); // var mold = await db.Queryable().FirstAsync(it => it.id == prdTask.mold_id); // var material = await db.Queryable().FirstAsync(it => it.id == prdTask.material_id); // eqpCode = eqp != null ? eqp.code : ""; // moldCode = mold != null ? mold.mold_code : ""; // materialCode = material != null ? material.code : ""; // materialName = material != null ? material.name : ""; // materialProp = material != null ? material.material_property : ""; // prdTask.workline_code = (await db.Queryable().Where(it => it.Id == prdTask.workline_id && it.Category == "workline").FirstAsync())?.EnCode; // prdTask.process_code = (await db.Queryable().Where(it => it.id == prdTask.process_id).FirstAsync())?.process_code; // if (dic.ContainsKey(prdTask.mo_task_status)) // { // prdTask.mo_task_status = dic[prdTask.mo_task_status]?.ToString(); // } // // } // var res = await db.Queryable().Where(it => it.mo_task_code == mo_task_code) // .Select(it => new PrdReportOutput // { // icmo_qty = it.icmo_qty, // reported_work_qty = it.reported_work_qty, // reported_qty = it.reported_qty, // prd_qty = it.prd_qty, // scrap_qty = SqlFunc.Subqueryable().Where(pmtd => pmtd.mo_task_id == it.mo_task_id).Select(pmtd => pmtd.scrap_qty), // }) // .Mapper(it => // { // it.icmo_qty = it.icmo_qty ?? ( // db.Queryable().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty < 1 ? 0 : // (it.icmo_qty ?? db.Queryable().First(it => it.mo_task_code == mo_task_code)?.scheduled_qty ?? 0)); // it.reported_work_qty = it.reported_work_qty ?? 0; // it.reported_qty = it.reported_qty ?? 0; // it.prd_qty = it.prd_qty ?? 0; // it.scrap_qty = it.scrap_qty ?? 0; // }) // .FirstAsync(); // prdTask.eqp_code = eqpCode; // prdTask.mold_code = moldCode; // prdTask.material_code = materialCode; // prdTask.material_name = materialName; // prdTask.icmo_qty = res?.icmo_qty; // prdTask.reported_work_qty = res?.reported_work_qty ?? 0; // prdTask.reported_qty = res?.reported_qty ?? 0; // prdTask.prd_qty = res?.prd_qty ?? 0; // prdTask.scrap_qty = res?.scrap_qty ?? 0; // // return prdTask; // } /// /// 根据任务单号获取提报记录明细 /// /// /// returns: ///
{ ///
icmo_qty:任务计划数量 ///
reported_work_qty:已报工数量 ///
reported_qty:报工数量 ///
prd_qty:生产数量 ///
} ///
[HttpGet] public async Task GetPrdReportByIcmoCode([FromRoute] string mo_task_code) { ISqlSugarClient db = _repository.AsSugarClient(); Dictionary dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); var prdTask = await db.Queryable() .LeftJoin((a, b) => a.material_id == b.id) .LeftJoin((a, b, c) => a.mold_id == c.id) .LeftJoin((a, b, c, d) => a.eqp_id == d.id) .LeftJoin((a, b, c, d, e) => e.DictionaryTypeId == DictConst.PrdTaskStatusTypeId && a.mo_task_status == e.EnCode) .LeftJoin((a, b, c, d, e, f) => a.workline_id == f.Id) .LeftJoin((a, b, c, d, e, f, g) => a.process_id == g.id) .Where((a, b) => a.mo_task_code == mo_task_code) .Select((a, b, c, d, e, f, g) => new { a.id, a.mo_task_code, a.mo_id, a.material_id, material_code = b.code, material_name = b.name, b.material_property, mo_task_status = e.FullName, a.plan_qty, a.scheduled_qty, complete_qty = a.reported_work_qty + a.scrap_qty, a.scrap_qty, c.mold_code, // icmo_qty = a.icmo_qty, a.reported_work_qty, // reported_qty = a.reported_qty, // prd_qty = a.prd_qty, eqp_code = d.code, a.mbom_process_id, workline_name = f.FullName, g.process_name, a.process_id }).FirstAsync(); return prdTask; } //public async Task GetPrdMoTaskList() //{ // var db= _repository.AsSugarClient(); //} } }