From e79700d34620c495667b7b8e7b852f23ed7d7e4e Mon Sep 17 00:00:00 2001 From: kazelee <1847801760@qq.com> Date: 星期三, 16 七月 2025 17:30:42 +0800 Subject: [PATCH] 简化增删改表达式,避免类型匹配出错 --- api/DebugController.cs | 437 ++++++++++++++++++++++++++--------------------------- 1 files changed, 215 insertions(+), 222 deletions(-) diff --git a/api/DebugController.cs b/api/DebugController.cs index 836c7d7..6934fdb 100644 --- a/api/DebugController.cs +++ b/api/DebugController.cs @@ -11,7 +11,11 @@ using Newtonsoft.Json; +using SqlSugar; + using static HH.WCS.Mobox3.DSZSH.api.ApiModel; +using static HH.WCS.Mobox3.DSZSH.api.OtherModel; +using static HH.WCS.Mobox3.DSZSH.Config; using static HH.WCS.Mobox3.DSZSH.core.Monitor; namespace HH.WCS.Mobox3.DSZSH.api { @@ -19,8 +23,7 @@ /// 娴嬭瘯鐢細濡傛灉椤圭洰涓鍜岃澶囧鎺ワ紝鍓嶆湡璁惧鏃犳硶娴嬭瘯锛岀敤鎺ュ彛妯℃嫙 /// </summary> [RoutePrefix("api")] - public class DebugController : ApiController - { + public class DebugController : ApiController { /// <summary> /// AGV鐘舵�涓�敭鍥炴姤134562 /// </summary> @@ -29,22 +32,15 @@ [HttpPost] [Route("AGVSeriesReports")] public ReturnResults AGVSeriesReports(UpdateTaskState model) { - //var db = new SqlHelper<object>().GetInstance(); - - //var task = db.Queryable<TN_Task>().Where(t => t.S_CODE == model.TaskID).First(); - //if (task == null) return new ReturnResults(); - //if (task.S_B_STATE == "瀹屾垚" && task.N_B_STATE == 3 || task.S_B_STATE == "閿欒" && task.N_B_STATE == 4) { - // return new ReturnResults(); - //} + ReturnResults returnResult = new ReturnResults(); + returnResult.ResultList = new List<ReturnResult>(); var agvTaskState = new AgvTaskState() { task_no = model.TaskID, forklift_no = model.ForkliftNo, - state = 1 }; - ReturnResults returnResult = new ReturnResults(); - returnResult.ResultList = new List<ReturnResult>(); + agvTaskState.state = 1; var temp1 = WCSCore.OperateAgvTaskStatus(agvTaskState); returnResult.ResultList.Add(temp1); @@ -67,6 +63,73 @@ agvTaskState.state = 2; var temp2 = WCSCore.OperateAgvTaskStatus(agvTaskState); returnResult.ResultList.Add(temp2); + + return returnResult; + } + + /// <summary> + /// 妯℃嫙AGV鍥炴姤浠诲姟鐘舵�锛堟寚瀹氫笅涓�釜鐘舵�锛岀敤浜庨渶瑕佸垎娈垫祴璇曠殑鍦烘櫙锛�br/> + /// 鎬ц兘鐩稿杈冨樊锛屼粎鐢ㄤ簬娴嬭瘯锛屼竴鑸笉浣跨敤 + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [HttpPost] + [Route("AgvReports")] + public ReturnResults AgvReports(AgvReportsInfo model) { + var db = new SqlHelper<object>().GetInstance(); + ReturnResults returnResult = new ReturnResults(); + returnResult.ResultList = new List<ReturnResult>(); + var agvTaskState = new AgvTaskState() { + task_no = model.TaskId, + forklift_no = model.ForkliftNo, + }; + + var taskAction = db.Queryable<TN_Task_Action>() + .Where(t => t.S_TASK_CODE == model.TaskId) + .OrderBy(t => new { create = SqlFunc.Desc(t.T_CREATE) }).First(); // 鏈�悗涓�釜Action鐘舵� + + var lastState = taskAction?.N_ACTION_CODE ?? 0; + + if (model.NextState <= 0 || model.NextState >= 7) { + LogHelper.Info("灏忚溅鍥炴姤鐘舵�涓嶅湪134562鐨勮寖鍥村唴"); + } + + // 0 ==> 1,3,4,5,6,2 + if (lastState == 0 && model.NextState >= 1) { + agvTaskState.state = 1; + var temp = WCSCore.OperateAgvTaskStatus(agvTaskState); + returnResult.ResultList.Add(temp); + } + // 0,1 ==> 3,4,5,6,2 + if (lastState < 2 && model.NextState >= 2) { + agvTaskState.state = 3; + var temp = WCSCore.OperateAgvTaskStatus(agvTaskState); + returnResult.ResultList.Add(temp); + } + // 0,1,3 ==> 4,5,6,2 + if (lastState < 4 && lastState != 2 && (model.NextState >= 3 || model.NextState == 2)) { + agvTaskState.state = 4; + var temp = WCSCore.OperateAgvTaskStatus(agvTaskState); + returnResult.ResultList.Add(temp); + } + // 0,1,3,4 ==> 5,6,2 + if (lastState < 5 && lastState != 2 && (model.NextState >= 4 || model.NextState == 2)) { + agvTaskState.state = 5; + var temp = WCSCore.OperateAgvTaskStatus(agvTaskState); + returnResult.ResultList.Add(temp); + } + // 0,1,3,4,5 ==> 6,2 + if (lastState < 6 && lastState != 2 && (model.NextState >= 5 || model.NextState == 2)) { + agvTaskState.state = 6; + var temp = WCSCore.OperateAgvTaskStatus(agvTaskState); + returnResult.ResultList.Add(temp); + } + // 0,1,3,4,5,6 ==> 2 + if (lastState != 2 && model.NextState == 2) { + agvTaskState.state = 2; + var temp = WCSCore.OperateAgvTaskStatus(agvTaskState); + returnResult.ResultList.Add(temp); + } return returnResult; } @@ -137,47 +200,13 @@ /// <returns></returns> [HttpPost] [Route("CreateDatabase")] - public string CreateDatabase(FalseOk model) { + public string CreateDatabase() { try { - if (model.JumpOut) { - return "璺冲嚭"; - } var db = new SqlHelper<object>().GetInstance(); - var entityTypes = new Type[] { - //typeof(TN_CAR_IN), - //typeof(TN_CG_Detail), - //typeof(TN_Container), - //typeof(TN_Loc_Container), - //typeof(TN_Location), - //typeof(TN_Task), - //typeof(TN_Task_Action), - //typeof(SysHelper.OI_SYS_MAXID), + var entityTypes = new Type[] { }; - //typeof(TN_Inbound_Order), - //typeof(TN_Check_Detail), - //typeof(TN_Check_Order), - //typeof(TN_CNTR_ITEM), - //typeof(TN_Outbound_Detail), - //typeof(TN_Outbound_Order), - //typeof(TN_Shift_Order), - //typeof(TN_Shift_Detail) - - //typeof(TN_Container_Item), - }; - - //using (var tran = db.Ado.UseTran()) { - // //db.CodeFirst.InitTables(entityTypes); - // if (db.Insertable<TN_Location>(locationList).ExecuteCommand() <= 0) { - // tran.RollbackTran(); - // return "澶辫触"; - // } - - // tran.CommitTran(); - - - //} - + //db.CodeFirst.InitTables(entityTypes); } catch (Exception ex) { LogHelper.Info($"鍙戠敓浜嗗紓甯�); @@ -194,178 +223,150 @@ [HttpPost] [Route("AddInboundTask")] public string AddInboundTask(AddInboundTaskInfo model) { + return WCSCore.CreateInboundTask(model.StartLoc, model.CntrCode).Content; + } + + /// <summary> + /// DEBUG锛氭ā鎷熶汉宸ュ皢鏂欑鎼繍鍒颁骇绾夸笂绾垮彛锛堢洿鎺ヤ慨鏀规暟鎹簱锛�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [HttpPost] + [Route("GoodpackToProdLine")] + public string GoodpackToProdLine(GoodpackToProdLineInfo model) { + var db = new SqlHelper<object>().GetInstance(); - var info = ""; - - const string taskName = TaskName.T鎵樼洏_婊℃墭涓嬬嚎鍏ュ簱; - const string startAreaName = AreaName.B鍖呰鍖� - const string endAreaName = AreaName.M婊℃墭璐ф灦鍖� - const string cntrType = "鎵樼洏"; - try { - //var itemCode = model.ItemCode; - //var batchNo = model.BatchNo; - var cntrCode = model.CntrCode; - var startLocCode = model.StartLoc; - - //var cgDetail = new TN_CG_Detail { - // S_ITEM_CODE = itemCode, - // S_BATCH_NO = batchNo, - // S_CNTR_CODE = cntrCode, - //}; - - //var needInsertContainer = false; - //var needUpdateContainer = false; - // 鏌ュ鍣ㄤ俊鎭〃鏄惁宸茬粡鏈夎繖涓鍣�- //var cntr = db.Queryable<TN_Container>() - // .Where(c => c.S_CODE == cntrCode).First(); - // 濡傛灉鎵句笉鍒拌瀹瑰櫒锛岄渶瑕佹坊鍔狅紝骞朵笖灏嗗鍣ㄦ潵婧愯缃负浠诲姟鍚嶇О - //if (cntr == null) { - // needInsertContainer = true; - // LogHelper.Info($"杞锛歿taskName}锛氬鍣細{cntrCode}锛屽湪瀹瑰櫒琛ㄤ腑娌℃湁鐧昏锛岀櫥璁板苟璁剧疆瀹瑰櫒鏉ユ簮涓猴細{taskName}"); - - // cntr = new TN_Container { - // S_CODE = cntrCode, - // S_TYPE = "鎵樼洏", - // S_SPEC = itemCode, - // S_SOURCE = taskName, - // }; - //} - //else { - // // 濡傛灉鎵惧埌璇ュ鍣紝浣嗗鍣ㄧ墿鏂欑被鍨嬩笌涓嬬嚎鐗╂枡涓嶇锛岃褰曞苟鐩存帴瑕嗙洊锛堝緟瀹氾級 - // if (!string.IsNullOrEmpty(cntr.S_SPEC) && cntr.S_SPEC != itemCode) { - // needUpdateContainer = true; - // LogHelper.Info($"杞锛歿taskName}锛氬鍣ㄨ〃涓鍣▄cntrCode}瀵瑰簲鐨勭墿鏂欎俊鎭細{cntr.S_SPEC}锛� + - // $"涓庢墍闇�鐨勭墿鏂欎俊鎭瘂itemCode}涓嶇锛岀洿鎺ヨ鐩栫粨鏋�); - - // cntr.S_SPEC = itemCode; - // cntr.S_SOURCE = taskName; - // } - //} - - var startLoc = db.Queryable<TN_Location>() - .Where(l => l.S_CODE == startLocCode) - .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE)) - .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "鏃� && l.C_ENABLE == "Y") - .Where(l => l.N_CURRENT_NUM == 0) // 缁戝畾鍓�- .First(); - + // 鏌ヨ璧风偣璐т綅锛氭暟閲�0 + var startLoc = db.Queryable<TN_Location>().LeftJoin<TN_Loc_Container>((l, c) => l.S_CODE == c.S_LOC_CODE) + .Where((l,c) => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "鏃� && l.C_ENABLE == "Y" && l.S_CODE == model.StartLoc && l.N_CURRENT_NUM == 1 && c.S_CNTR_CODE == model.CntrCode).First(); if (startLoc == null) { - info = $"鍦�{startAreaName}'涓病鏈夋壘鍒拌捣鐐硅揣浣�{startLocCode}'锛屾垨涓嶆弧瓒宠姹傦細鏈笂閿併�褰撳墠瀹瑰櫒鏁伴噺=0"; - LogHelper.Info(info); - return info; + return $"娌℃湁鎵惧埌璧风偣璐т綅'{model.StartLoc}'锛佽姹傦細閿佺姸鎬�'鏃�锛屽綋鍓嶅鍣ㄦ暟閲�1"; } - var locCntrRelOld = db.Queryable<TN_Loc_Container>() - .Where(c => c.S_CNTR_CODE == cntrCode).First(); - - // 缁戝畾璐т綅鍜屽鍣ㄥ彿 - var locCntrRel = new TN_Loc_Container { - S_LOC_CODE = startLocCode, - S_CNTR_CODE = cntrCode, - S_CNTR_TYPE = cntrType, - }; - - startLoc.N_CURRENT_NUM = 1; // 缁戝畾鍚�- - var endLoc = db.Queryable<TN_Location>() - .Where(a => Settings.AreaMap[endAreaName].Contains(a.S_AREA_CODE)) - .Where(a => a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "鏃� && a.C_ENABLE == "Y") // 绛涢�锛氭湭涓婇攣 - .Where(a => a.N_CURRENT_NUM == 0) // 绛涢�锛氱┖璐т綅 - .OrderBy(l => l.N_LAYER) - .First(); - + // 鏌ヨ缁堢偣璐т綅 + // Order锛氭寜璐т綅灞傛暟锛屼粠灏忓埌澶ф帓鍒�+ var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "鏃� && l.C_ENABLE == "Y" && l.N_CURRENT_NUM == 0).First(); if (endLoc == null) { - info = $"鍦ㄧ粓鐐硅揣鍖�{endAreaName}'涓紝娌℃湁鎵惧埌鍚堥�鐨勩�缁堢偣璐т綅銆戯紝闇�婊¤冻瑕佹眰锛氭湭涓婇攣銆佸綋鍓嶅鍣ㄦ暟閲�0"; - LogHelper.Info(info); - return info; + return $"娌℃湁鎵惧埌鍚堥�鐨勭粓鐐硅揣浣嶏紒瑕佹眰锛氶攣鐘舵�='鏃�锛屽綋鍓嶅鍣ㄦ暟閲�0"; } - var cntId = locCntrRel.S_CNTR_CODE; - var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); + var locCntrRel = db.Queryable<TN_Loc_Container>().Where(c => c.S_CNTR_CODE == model.CntrCode).First() ; + if (locCntrRel == null) { + return $"璇ュ鍣ㄤ笉瀛樺湪缁戝畾鐨勮揣浣嶏紒"; + } - LocationHelper.LockStartLoc(ref startLoc); // 璧风偣鍑哄簱閿�- LocationHelper.LockEndLoc(ref endLoc); // 缁堢偣鍏ュ簱閿�+ locCntrRel.S_LOC_CODE = model.StartLoc; + startLoc.N_CURRENT_NUM = 0; + endLoc.N_CURRENT_NUM = 1; using (var tran = db.Ado.UseTran()) { - if (locCntrRelOld != null) { - if (db.Deleteable<TN_Loc_Container>(locCntrRelOld).ExecuteCommand() <= 0 && - db.Updateable<TN_Location>().SetColumns(l => l.N_CURRENT_NUM == 0).Where(l => l.S_CODE == locCntrRelOld.S_LOC_CODE).ExecuteCommand() <= 0) { - tran.RollbackTran(); - info = $"鍒犻櫎鏃ц揣浣嶅鍣ㄥ叧绯昏〃澶辫触锛氳揣浣嶇紪鐮亄locCntrRelOld.S_LOC_CODE}锛屽鍣ㄧ紪鐮亄locCntrRelOld.S_CNTR_CODE}"; - LogHelper.Info(info); - return info; - } - } - //if (db.Insertable<TN_CG_Detail>(cgDetail).ExecuteCommand() <= 0) { - // tran.RollbackTran(); - // info = $"鎻掑叆瀹瑰櫒璐у搧淇℃伅琛ㄥけ璐ワ細鐗╂枡缂栫爜{cgDetail.S_ITEM_CODE}锛屽鍣ㄧ紪鐮亄cgDetail.S_CNTR_CODE}"; - // LogHelper.Info(info); - // return info; - //} - - //if (needInsertContainer) { - // if (db.Insertable<TN_Container>(cntr).ExecuteCommand() <= 0) { - // info = $"鎻掑叆瀹瑰櫒琛ㄥけ璐ワ細" + JsonConvert.SerializeObject(cntr); - // tran.RollbackTran(); - // LogHelper.Info(info); - // return info; - // } - //} - //else if (needUpdateContainer) { - // if (db.Updateable<TN_Container>(cntr).ExecuteCommand() <= 0) { - // info = $"鏇存柊瀹瑰櫒琛ㄥけ璐ワ細" + JsonConvert.SerializeObject(cntr); - // tran.RollbackTran(); - // LogHelper.Info(info); - // return info; - // } - //} - - if (db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) { + if (db.Updateable(startLoc).ExecuteCommand() <= 0 && + db.Updateable(endLoc).ExecuteCommand() <= 0 && + db.Updateable(locCntrRel).ExecuteCommand() <= 0) { + tran.RollbackTran(); - info = $"鎻掑叆璐т綅瀹瑰櫒鍏崇郴琛ㄥけ璐ワ細璐т綅缂栫爜{locCntrRel.S_LOC_CODE}锛屽鍣ㄧ紪鐮亄locCntrRel.S_CNTR_CODE}"; - LogHelper.Info(info); - return info; + return "鏁版嵁搴撴搷浣滃け璐ワ紒"; } - if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM }).ExecuteCommand() <= 0) { - tran.RollbackTran(); - info = $"鐢熸垚浠诲姟'{taskName}'澶辫触锛氭洿鏂拌捣鐐硅揣浣峽startLoc.S_CODE}閿佺姸鎬佸け璐�; - LogHelper.Info(info); - return info; - } - - if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { - it.N_LOCK_STATE, - it.S_LOCK_STATE, - it.S_LOCK_OP, - it.T_MODIFY - }).ExecuteCommand() <= 0) { - tran.RollbackTran(); - info = $"鐢熸垚浠诲姟'{taskName}'澶辫触锛氭洿鏂扮粓鐐硅揣浣峽endLoc.S_CODE}閿佺姸鎬佸け璐�; - LogHelper.Info(info); - return info; - } - - if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { - tran.RollbackTran(); - info = $"鐢熸垚浠诲姟'{taskName}'澶辫触锛屽鍣ㄥ彿{cntId}锛岃捣鐐箋startLoc.S_CODE}锛岀粓鐐硅揣鏋秢endLoc.S_CODE}"; - LogHelper.Info(info); - return info; - } - - tran.CommitTran(); - info = $"鐢熸垚浠诲姟'{taskName}'鎴愬姛锛屽鍣ㄥ彿{cntId}锛岃捣鐐箋startLoc.S_CODE}锛岀粓鐐硅揣鏋秢endLoc.S_CODE}"; - LogHelper.Info(info); - return info; + tran.CommitTran() ; + return "鏁版嵁搴撴搷浣滄垚鍔�; } - } catch (Exception ex) { - LogHelper.InfoEx(ex); + return ex.Message; } } + + /// <summary> + /// DEBUG锛氭ā鎷烢rp涓嬪彂鍑哄簱璁″垝鍗�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [HttpPost] + [Route("TestErpSendOutboundPlan")] + public ErpResult TestErpSendOutboundPlan(TestErpSendOutboundPlanInfo model) { + var apiName = "ERP涓嬪彂鍑哄簱璁″垝鍗�; + //LogHelper.InfoApi(apiName, model); + + var erpModel = new ErpSendOutboundPlanInfo(); + erpModel.jhdh = model.PlanNo; + erpModel.cpdm = model.ItemCode; + erpModel.pzjs = model.ItemNum; + + LogHelper.InfoApi(apiName, erpModel); + + return ApiHelper.ErpSendOutboundPlan(erpModel); + } + + /// <summary> + /// 锛堝唴閮ㄦ柟娉曡鍕胯皟鐢級妯℃嫙鍙栬揣瀹屾垚鍙嶉Erp鍥炴姤缁撴灉锛堥粯璁や负success锛�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [HttpPost] + [Route("PickUpReturn")] + public TestErpResult PickUpReturn(PickUpReturnErpInfo model) { + if (model.sfjs == 0) { + return new TestErpResult { + code = 1, + message = "瀹炲彂浠舵暟鏈‘瀹� + }; + } + + return new TestErpResult { + code = 0, + message = "success" + }; + } + + /// <summary> + /// 锛堝唴閮ㄦ柟娉曡鍕胯皟鐢級妯℃嫙浠诲姟鍒涘缓瀹屾垚鍙嶉Erp鍥炴姤缁撴灉锛堥粯璁や负success锛�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [HttpPost] + [Route("CreateTaskReturn")] + public TestErpResult CreateTaskReturn(CreateTaskReturnErpInfo model) { + if (model.hw == "") { + return new TestErpResult { + code = 1, + message = "璐т綅淇℃伅鏈彁渚� + }; + } + + return new TestErpResult { + code = 0, + message = "success" + }; + } + } + + public class GoodpackToProdLineInfo { + public string CntrCode { get; set; } + public string StartLoc { get; set; } + public string EndLoc { get; set; } + } + + public class TestErpSendOutboundPlanInfo { + /// <summary> + /// 鍑哄簱璁″垝鍗曞彿锛堣鍒掑崟鍙�jhdh锛�+ /// </summary> + public string PlanNo { get; set; } = string.Empty; + /// <summary> + /// 鐗╂枡缂栫爜锛堜骇鍝佷唬鐮�cpdm锛�+ /// </summary> + public string ItemCode { get; set; } = string.Empty; + /// <summary> + /// 鐗╂枡鏁伴噺锛堟淳瑁呬欢鏁�pzjs锛�+ /// </summary> + public float ItemNum { get; set; } = 0; + } + + public class TestErpResult { + public int code { get; set; } + public string message { get; set; } } public class AddInboundTaskInfo { @@ -399,19 +400,21 @@ /// AGV 灏忚溅鍙� /// </summary> public string ForkliftNo { set; get; } - ///// <summary> - ///// AGV 涓嬩竴涓姸鎬�- ///// </summary> - //public int NextState { set; get; } } - public class FalseOk { - public bool JumpOut { set; get; } = true; - } - - public class InsertCntrItemInfo { - public string Cntr { set; get; } - public string Item { set; get; } + public class AgvReportsInfo { + /// <summary> + /// 浠诲姟鍙�+ /// </summary> + public string TaskId { set; get; } + /// <summary> + /// AGV 灏忚溅鍙�+ /// </summary> + public string ForkliftNo { get; set; } + /// <summary> + /// AGV 涓嬩竴鐘舵�锛堜换鍔″洖鎶ュ彿锛�+ /// </summary> + public int NextState { set; get; } = 0; } /// <summary> @@ -421,14 +424,4 @@ public List<ReturnResult> ResultList { set; get; } } - public class LocCntrCg { - public string Note { get; set; } // 浠呯敤浜庡娉�- - public string LocCode { get; set; } - public string LocArea { get; set; } - public string CntrCode { get; set; } - public string CntrType { get; set; } - public string ItemCode { get; set; } - public string BatchNo { get; set; } - } } -- Gitblit v1.9.1