From 006c12987d7dc7c2081fbf6715ebea98b93fdca0 Mon Sep 17 00:00:00 2001 From: Rodney Chen <rodney.chen@hotmail.com> Date: 星期日, 08 十二月 2024 17:04:32 +0800 Subject: [PATCH] 增加工单批次缓存,不良代码缓存,岗位缓存 --- Tiger.Controllers.MES/Controllers/CacheController.MesPosition.cs | 58 ++++++++ Tiger.Controllers.MES/Controllers/CacheController.cs | 20 ++ Tiger.Api/DbCache/DbCacheBus.cs | 4 Tiger.Controllers.MES/Controllers/CacheController.WorkBatch.cs | 96 +++++++++++++ Tiger.Controllers.MES/Controllers/CacheController.MesDefect.cs | 55 +++++++ Tiger.IBusiness.MES/Core/IWoContext.cs | 48 ++++++ Tiger.Business.MES/Transaction/Position.cs | 3 Tiger.Business.MES/Common/WorkBatch.cs | 6 Tiger.IBusiness.MES/Core/IMESContext.cs | 0 Tiger.Business.MES/Common/WoContext.cs | 84 ++++++++++-- Tiger.IBusiness.MES/Core/IWorkBatch.cs | 5 11 files changed, 362 insertions(+), 17 deletions(-) diff --git a/Tiger.Api/DbCache/DbCacheBus.cs b/Tiger.Api/DbCache/DbCacheBus.cs index 316a0d8..83488ec 100644 --- a/Tiger.Api/DbCache/DbCacheBus.cs +++ b/Tiger.Api/DbCache/DbCacheBus.cs @@ -27,6 +27,10 @@ /// 鑾峰彇宀椾綅缂撳瓨 /// </summary> public static IMesPositionCache MesPosition => DI.Resolve<IMesPositionCache>(); + /// <summary> + /// 鑾峰彇宸ュ崟姹犵紦瀛� + /// </summary> + public static IWoContext WorkBatch => DI.Resolve<IWoContext>(); }//endClass /// <summary> diff --git a/Tiger.Business.MES/Common/WoContext.cs b/Tiger.Business.MES/Common/WoContext.cs index be617d9..4592e38 100644 --- a/Tiger.Business.MES/Common/WoContext.cs +++ b/Tiger.Business.MES/Common/WoContext.cs @@ -10,20 +10,20 @@ using Tiger.IBusiness; using Tiger.Model; using Tiger.Model.Entitys.MES.Position; -using static Tiger.Business.Biz; namespace Tiger.Business { /// <summary> /// 宸ュ崟 涓婁笅鏂� /// </summary> - public class WoContext + public class WoContext : IWoContext { #region 宸ュ崟绠$悊 /// <summary> - /// + /// 宸ュ崟鎵规缂撳瓨瀛楀吀 /// </summary> public static Dictionary<string, WorkBatch> WoBatchDic { get; set; } = new Dictionary<string, WorkBatch>(); + public Dictionary<string, IWorkBatch> GetWoBatchDic() => WoBatchDic.ToDictionary(k => k.Key, v => v.Value as IWorkBatch); /// <summary> /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鑾峰彇涓�涓伐鍗曟壒娆″璞� @@ -35,7 +35,7 @@ { if (ExistsBatch(workorder, lineCode, batchNo)) { - return WoBatchDic.WhereIF(canDoWork, q => q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() || q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue()) + return WoBatchDic.WhereIF(canDoWork, q => q.Value.Batch?.STATUS == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() || q.Value.Batch?.STATUS == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue()) .FirstOrDefault(q => !q.Value.Batch.IsNullOrEmpty() && q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch.BATCH_NO == batchNo)).Value; } return null; @@ -52,15 +52,56 @@ public static bool ExistsBatch(string workorder, string lineCode, string batchNo = "", bool canDoWork = false) { return WoBatchDic.WhereIF(canDoWork, q => !q.Value.Batch.IsNullOrEmpty() && (q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() || q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue())) - .Any(q => q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch.BATCH_NO == batchNo)); + .Any(q => q.Value.Batch?.ORDER_NO == workorder && q.Value.Batch?.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch?.BATCH_NO == batchNo)); } - /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� + /// 鏍规嵁宸ュ崟鍙凤紝澧炲姞涓�涓伐鍗曞璞″埌宸ュ崟鎵规瀛楀吀涓� /// </summary> - /// <param name="batchNo"></param> + /// <param name="workorder"></param> + /// <returns></returns> + public static WorkBatch Add(string workorder) + { + var wb = new WorkBatch(workorder).Init(""); + WoBatchDic.Add(workorder, wb); + return wb; + } + + /// 鏍规嵁宸ュ崟鍙峰拰浜х嚎锛屽鍔犱竴涓伐鍗曟壒娆″璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="workorder"></param> /// <param name="lineCode"></param> /// <returns></returns> - public static bool RemoveWo(string workorder) + public static WorkBatch Add(string workorder, string linecode) + { + var wb = new WorkBatch(workorder).Init(linecode); + WoBatchDic.Add(wb.Batch.BATCH_NO, wb); + return wb; + } + + /// 鏍规嵁宸ュ崟鍙凤紝澧炲姞涓�涓伐鍗曞璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="workorder"></param> + /// <returns></returns> + public IWorkBatch AddWo(string workorder) + { + return Add(workorder); + } + + /// 鏍规嵁宸ュ崟鍙峰拰浜х嚎锛屽鍔犱竴涓伐鍗曟壒娆″璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="workorder"></param> + /// <param name="lineCode"></param> + /// <returns></returns> + public IWorkBatch AddBatch(string workorder, string linecode) + { + return Add(workorder, linecode); + } + + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曠殑鎵�鏈夋壒娆″璞� + /// </summary> + /// <param name="workorder"></param> + /// <returns></returns> + public static bool RemoveAll(string workorder) { try { @@ -78,12 +119,20 @@ } } + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曠殑鎵�鏈夋壒娆″璞� + /// </summary> + /// <param name="workorder"></param> + /// <returns></returns> + public bool RemoveWo(string workorder) + { + return RemoveAll(workorder); + } + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� /// </summary> /// <param name="batchNo"></param> - /// <param name="lineCode"></param> /// <returns></returns> - public static bool RemoveBatch(string batchNo) + public static bool Remove(string batchNo) { try { @@ -98,6 +147,15 @@ Logger.Default.Fatal(ex, $"浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆{batchNo}]瀵硅薄寮傚父"); return false; } + } + + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� + /// </summary> + /// <param name="batchNo"></param> + /// <returns></returns> + public bool RemoveBatch(string batchNo) + { + return Remove(batchNo); } /// <summary> @@ -148,8 +206,7 @@ { if (!WoBatchDic.Any(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER)) { - var wb = new WorkBatch(wipSNs.First().WORK_ORDER).Init(""); - WoBatchDic.Add(wb.Batch.BATCH_NO, wb); + Add(wipSNs.First().WORK_ORDER); } var wo = WoBatchDic.FirstOrDefault(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER).Value; action.Data = wo.GetNextNodes(wipSNs.First()); @@ -209,8 +266,7 @@ { if (!WoBatchDic.Any(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER)) { - var wb = new WorkBatch(wipSNs.First().WORK_ORDER).Init(""); - WoBatchDic.Add(wipSNs.First().BATCH_NO, wb); + Add(wipSNs.First().WORK_ORDER); } var wo = WoBatchDic.FirstOrDefault(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER).Value; action.Data = new() diff --git a/Tiger.Business.MES/Common/WorkBatch.cs b/Tiger.Business.MES/Common/WorkBatch.cs index 0259371..7d5fdaa 100644 --- a/Tiger.Business.MES/Common/WorkBatch.cs +++ b/Tiger.Business.MES/Common/WorkBatch.cs @@ -50,7 +50,7 @@ #region Functions /// <summary> - /// 鍒濆鍖栧伐鍗曡祫鏂� + /// 鍒濆鍖栧伐鍗曟壒娆¤祫鏂� /// </summary> /// <returns></returns> public WorkBatch Init(string lineCode) @@ -63,6 +63,10 @@ return this; } + /// <summary> + /// 鏇存柊宸ュ崟鎵规璧勬枡 + /// </summary> + /// <param name="updateAll"></param> public void Update(bool updateAll = false) { var strat = DateTime.Now; diff --git a/Tiger.Business.MES/Transaction/Position.cs b/Tiger.Business.MES/Transaction/Position.cs index 7003188..5e71779 100644 --- a/Tiger.Business.MES/Transaction/Position.cs +++ b/Tiger.Business.MES/Transaction/Position.cs @@ -144,8 +144,7 @@ action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.BatchStatusException", input.OrderNo, batch.BATCH_NO, batch.STATUS.GetEnumDesc<BIZ_MES_WO_BATCH.STATUSs>()); return action; } - var wb = new WorkBatch(input.OrderNo).Init(CurLine.LINE_CODE); - WoContext.WoBatchDic.Add(wb.Batch.BATCH_NO, wb); + var wb = WoContext.Add(input.OrderNo, CurLine.LINE_CODE); batchNo = wb.Batch.BATCH_NO; } CurBatch = WoContext.GetBatch(input.OrderNo, CurLine.LINE_CODE, batchNo); diff --git a/Tiger.Controllers.MES/Controllers/CacheController.MesDefect.cs b/Tiger.Controllers.MES/Controllers/CacheController.MesDefect.cs new file mode 100644 index 0000000..781eb1a --- /dev/null +++ b/Tiger.Controllers.MES/Controllers/CacheController.MesDefect.cs @@ -0,0 +1,55 @@ +锘縰sing Rhea.Common; +using Microsoft.AspNetCore.Mvc; +using System; +using Tiger.IBusiness; +using System.Linq; +using System.Threading.Tasks; +using Tiger.Api.DbCache; + +namespace Tiger.Api.Controllers.Base +{ + public partial class CacheController : ControllerBase + { + /// <summary> + /// GetMesDefect(ApiAction(Data:PARAM_CODE)) + /// 鏍规嵁涓嶈壇浠g爜杩斿洖涓嶈壇浠g爜瀵硅薄 + /// </summary> + /// <param name="action"></param> + /// <returns></returns> + [HttpPost("[action]")] + public async Task<IActionResult> GetMesDefect([FromBody] ApiAction action) + { + ApiAction response; + try + { + response = action.GetResponse(Cache.MesDefect[action.Data?.ToString() ?? ""]); + } + catch (System.Exception ex) + { + response = action.GetResponse().CatchExceptionWithLog(ex); + } + return Ok(response); + } + + /// <summary> + /// GetMesDefectGroup(ApiAction(Data:DFTG_CODE)) + /// 鏍规嵁涓嶈壇浠g爜缁勪唬鐮佽繑鍥炰笉鑹唬鐮佺粍瀵硅薄 + /// </summary> + /// <param name="action"></param> + /// <returns></returns> + [HttpPost("[action]")] + public async Task<IActionResult> GetMesDefectGroup([FromBody] ApiAction action) + { + ApiAction response; + try + { + response = action.GetResponse(Cache.MesDefect.Groups.FirstOrDefault(q => q.DFTG_CODE == (action.Data?.ToString() ?? ""))); + } + catch (Exception ex) + { + response = action.GetResponse().CatchExceptionWithLog(ex); + } + return Ok(response); + } + } +} diff --git a/Tiger.Controllers.MES/Controllers/CacheController.MesPosition.cs b/Tiger.Controllers.MES/Controllers/CacheController.MesPosition.cs new file mode 100644 index 0000000..a9b07c6 --- /dev/null +++ b/Tiger.Controllers.MES/Controllers/CacheController.MesPosition.cs @@ -0,0 +1,58 @@ +锘縰sing Rhea.Common; +using Microsoft.AspNetCore.Mvc; +using System; +using Tiger.IBusiness; +using System.Linq; +using System.Threading.Tasks; +using Tiger.Model; +using System.Linq.Expressions; +using Tiger.Api.DbCache; + +namespace Tiger.Api.Controllers.Base +{ + public partial class CacheController : ControllerBase + { + /// <summary> + /// GetMesPosition(ApiAction(Data:POST_CODE)) + /// 鏍规嵁宀椾綅浠g爜杩斿洖宀椾綅瀵硅薄 + /// </summary> + /// <param name="action"></param> + /// <returns></returns> + [HttpPost("[action]")] + public async Task<IActionResult> GetMesPosition([FromBody] ApiAction action) + { + ApiAction response; + try + { + response = action.GetResponse(Cache.MesPosition[action.Data?.ToString() ?? ""]); + } + catch (System.Exception ex) + { + response = action.GetResponse().CatchExceptionWithLog(ex); + } + return Ok(response); + } + + /// <summary> + /// GetMesPositionByOper(ApiAction(Data:OPER_CODE)) + /// 鏍规嵁宸ュ簭缂栫爜杩斿洖宀椾綅瀵硅薄鍒楄〃 + /// </summary> + /// <param name="action"></param> + /// <returns></returns> + [HttpPost("[action]")] + public async Task<IActionResult> GetMesPositionByOper([FromBody] ApiAction action) + { + ApiAction response; + try + { + response = action.GetResponse(Cache.MesPosition.Positions.Where(q => q.OPER_CODE == (action.Data?.ToString() ?? "")).ToList()); + } + catch (Exception ex) + { + response = action.GetResponse().CatchExceptionWithLog(ex); + } + return Ok(response); + } + + } +} \ No newline at end of file diff --git a/Tiger.Controllers.MES/Controllers/CacheController.WorkBatch.cs b/Tiger.Controllers.MES/Controllers/CacheController.WorkBatch.cs new file mode 100644 index 0000000..f613ca5 --- /dev/null +++ b/Tiger.Controllers.MES/Controllers/CacheController.WorkBatch.cs @@ -0,0 +1,96 @@ +锘縰sing Rhea.Common; +using Microsoft.AspNetCore.Mvc; +using System; +using Tiger.IBusiness; +using System.Linq; +using System.Threading.Tasks; +using Tiger.Api.DbCache; + +namespace Tiger.Api.Controllers.Base +{ + public partial class CacheController : ControllerBase + { + /// <summary> + /// GetWorkBatch(OrderOrBatch) + /// 鏍规嵁宸ュ崟鍙锋垨鑰呭伐鍗曟壒娆″彿杩斿洖宸ュ崟鎵规缂撳瓨瀵硅薄鍒楄〃 + /// </summary> + /// <param name="OrderOrBatch"></param> + /// <returns></returns> + [HttpGet("WorkBatch/Get")] + public async Task<IActionResult> GetWorkBatch(string? OrderOrBatch) + { + var wbs = Cache.WorkBatch.GetWoBatchDic().Where(q => OrderOrBatch.IsNullOrEmpty() || q.Value.WO?.ORDER_NO == OrderOrBatch || q.Value.Batch?.BATCH_NO == OrderOrBatch).Select(q => q.Value).ToList(); + return Ok(wbs); + } + + /// <summary> + /// AddWo(WorkOrder) + /// 鏍规嵁宸ュ崟鍙凤紝澧炲姞涓�涓伐鍗曞璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="WorkOrder"></param> + /// <returns></returns> + [HttpGet("WorkBatch/AddWo")] + public async Task<IActionResult> AddWo(string WorkOrder) + { + var wb = Cache.WorkBatch.AddWo(WorkOrder); + return Ok(wb); + } + + /// <summary> + /// AddBatch(WorkOrder, LineCode) + /// 鏍规嵁宸ュ崟鍙峰拰浜х嚎锛屽鍔犱竴涓伐鍗曟壒娆″璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="WorkOrder"></param> + /// <param name="LineCode"></param> + /// <returns></returns> + [HttpGet("WorkBatch/AddBatch")] + public async Task<IActionResult> AddBatch(string? WorkOrder, string? LineCode) + { + var wb = Cache.WorkBatch.AddBatch(WorkOrder, LineCode); + return Ok(wb); + } + + /// <summary> + /// RemoveWo(WorkOrder) + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曠殑鎵�鏈夋壒娆″璞� + /// </summary> + /// <param name="WorkOrder"></param> + /// <returns></returns> + [HttpGet("WorkBatch/RemoveWo")] + public async Task<IActionResult> RemoveWo(string? WorkOrder) + { + var result = Cache.WorkBatch.RemoveWo(WorkOrder); + return Ok(result); + } + + /// <summary> + /// RemoveBatch(BatchNo) + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� + /// </summary> + /// <param name="BatchNo"></param> + /// <returns></returns> + [HttpGet("WorkBatch/RemoveBatch")] + public async Task<IActionResult> RemoveBatch(string? BatchNo) + { + var result = Cache.WorkBatch.RemoveBatch(BatchNo); + return Ok(result); + } + + /// <summary> + /// Update(BatchNo) + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� + /// </summary> + /// <param name="BatchNo"></param> + /// <returns></returns> + [HttpGet("WorkBatch/Update")] + public async Task<IActionResult> UpdateWorkBatch(string? BatchNo) + { + var wb = Cache.WorkBatch.GetWoBatchDic().Where(q => q.Value.Batch?.BATCH_NO == (BatchNo ?? "")).FirstOrDefault().Value; + if (!wb.IsNullOrEmpty()) + { + wb.Update(true); + } + return Ok(wb); + } + } +} diff --git a/Tiger.Controllers.MES/Controllers/CacheController.cs b/Tiger.Controllers.MES/Controllers/CacheController.cs new file mode 100644 index 0000000..b574a40 --- /dev/null +++ b/Tiger.Controllers.MES/Controllers/CacheController.cs @@ -0,0 +1,20 @@ +锘縰sing Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Tiger.Api.Controllers.Base +{ + /// <summary> + /// CacheController + /// </summary> + [Route("api/[controller]/")] + [EnableCors("Any")] + [ApiController] + public partial class CacheController : ControllerBase + { + } +} diff --git a/Tiger.IBusiness.MES/IMESContext.cs b/Tiger.IBusiness.MES/Core/IMESContext.cs similarity index 100% rename from Tiger.IBusiness.MES/IMESContext.cs rename to Tiger.IBusiness.MES/Core/IMESContext.cs diff --git a/Tiger.IBusiness.MES/Core/IWoContext.cs b/Tiger.IBusiness.MES/Core/IWoContext.cs new file mode 100644 index 0000000..b41d107 --- /dev/null +++ b/Tiger.IBusiness.MES/Core/IWoContext.cs @@ -0,0 +1,48 @@ +锘縰sing Microsoft.AspNetCore.Http; +using Rhea.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Tiger.Model; + +namespace Tiger.IBusiness +{ + public interface IWoContext + { + /// <summary> + /// 宸ュ崟鎵规缂撳瓨瀛楀吀 + /// </summary> + /// <returns></returns> + public Dictionary<string, IWorkBatch> GetWoBatchDic(); + + /// 鏍规嵁宸ュ崟鍙峰拰浜х嚎锛屽鍔犱竴涓伐鍗曞璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="workorder"></param> + /// <returns></returns> + public IWorkBatch AddWo(string workorder); + + /// 鏍规嵁宸ュ崟鍙峰拰浜х嚎锛屽鍔犱竴涓伐鍗曟壒娆″璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="workorder"></param> + /// <param name="lineCode"></param> + /// <returns></returns> + public IWorkBatch AddBatch(string workorder, string linecode); + + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� + /// </summary> + /// <param name="batchNo"></param> + /// <param name="lineCode"></param> + /// <returns></returns> + public bool RemoveWo(string workorder); + + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� + /// </summary> + /// <param name="batchNo"></param> + /// <param name="lineCode"></param> + /// <returns></returns> + public bool RemoveBatch(string batchNo); + } +} diff --git a/Tiger.IBusiness.MES/Core/IWorkBatch.cs b/Tiger.IBusiness.MES/Core/IWorkBatch.cs index f8519a7..e09b73f 100644 --- a/Tiger.IBusiness.MES/Core/IWorkBatch.cs +++ b/Tiger.IBusiness.MES/Core/IWorkBatch.cs @@ -29,6 +29,11 @@ public List<BAS_DEFECT> Defects { get; } /// <summary> + /// 鏇存柊宸ュ崟鎵规璧勬枡 + /// </summary> + /// <param name="updateAll"></param> + public void Update(bool updateAll = false); + /// <summary> /// 宸ュ崟寮�宸� /// </summary> /// <param name="user"></param> -- Gitblit v1.9.3