| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Runtime.ConstrainedExecution; |
| | | using System.Web.Http; |
| | | |
| | |
| | | |
| | | 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 { |
| | |
| | | } |
| | | |
| | | /// <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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// AGV状态一键回报134 |
| | | /// </summary> |
| | | /// <param name="model">容器号</param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [Route("AGVSeriesReports14")] |
| | | public ReturnResults AGVSeriesReports14(UpdateTaskState model) { |
| | | var agvTaskState = new AgvTaskState() { |
| | | task_no = model.TaskID, |
| | | forklift_no = model.ForkliftNo, |
| | | state = 1 |
| | | }; |
| | | ReturnResults returnResult = new ReturnResults(); |
| | | returnResult.ResultList = new List<ReturnResult>(); |
| | | |
| | | var temp1 = WCSCore.OperateAgvTaskStatus(agvTaskState); |
| | | returnResult.ResultList.Add(temp1); |
| | | |
| | | agvTaskState.state = 3; |
| | | var temp3 = WCSCore.OperateAgvTaskStatus(agvTaskState); |
| | | returnResult.ResultList.Add(temp3); |
| | | |
| | | agvTaskState.state = 4; |
| | | var temp4 = WCSCore.OperateAgvTaskStatus(agvTaskState); |
| | | returnResult.ResultList.Add(temp4); |
| | | |
| | | return returnResult; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// AGV状态一键回报562 |
| | | /// </summary> |
| | | /// <param name="model">容器号</param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [Route("AGVSeriesReports62")] |
| | | public ReturnResults AGVSeriesReports62(UpdateTaskState model) { |
| | | var agvTaskState = new AgvTaskState() { |
| | | task_no = model.TaskID, |
| | | forklift_no = model.ForkliftNo, |
| | | state = 5 |
| | | }; |
| | | ReturnResults returnResult = new ReturnResults(); |
| | | returnResult.ResultList = new List<ReturnResult>(); |
| | | |
| | | var temp5 = WCSCore.OperateAgvTaskStatus(agvTaskState); |
| | | returnResult.ResultList.Add(temp5); |
| | | |
| | | agvTaskState.state = 6; |
| | | var temp6 = WCSCore.OperateAgvTaskStatus(agvTaskState); |
| | | returnResult.ResultList.Add(temp6); |
| | | |
| | | agvTaskState.state = 2; |
| | | var temp2 = WCSCore.OperateAgvTaskStatus(agvTaskState); |
| | | returnResult.ResultList.Add(temp2); |
| | | |
| | | return returnResult; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化数据库 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 模拟Erp下发出库计划单 |
| | | /// DEBUG:模拟人工将料箱搬运到产线上线口(直接修改数据库) |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [Route("GoodpackToProdLine")] |
| | | public string GoodpackToProdLine(GoodpackToProdLineInfo model) { |
| | | |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | try { |
| | | // 查询起点货位:数量=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) { |
| | | return $"没有找到起点货位'{model.StartLoc}'!要求:锁状态='无',当前容器数量=1"; |
| | | } |
| | | |
| | | // 查询终点货位 |
| | | // 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) { |
| | | return $"没有找到合适的终点货位!要求:锁状态='无',当前容器数量=0"; |
| | | } |
| | | |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().Where(c => c.S_CNTR_CODE == model.CntrCode).First() ; |
| | | if (locCntrRel == null) { |
| | | return $"该容器不存在绑定的货位!"; |
| | | } |
| | | |
| | | locCntrRel.S_LOC_CODE = model.StartLoc; |
| | | startLoc.N_CURRENT_NUM = 0; |
| | | endLoc.N_CURRENT_NUM = 1; |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Updateable(startLoc).ExecuteCommand() <= 0 && |
| | | db.Updateable(endLoc).ExecuteCommand() <= 0 && |
| | | db.Updateable(locCntrRel).ExecuteCommand() <= 0) { |
| | | |
| | | tran.RollbackTran(); |
| | | return "数据库操作失败!"; |
| | | } |
| | | |
| | | tran.CommitTran() ; |
| | | return "数据库操作成功"; |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | |
| | | return ex.Message; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// DEBUG:模拟Erp下发出库计划单 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | |
| | | } |
| | | } |
| | | |
| | | public class GoodpackToProdLineInfo { |
| | | public string CntrCode { get; set; } |
| | | public string StartLoc { get; set; } |
| | | public string EndLoc { get; set; } |
| | | } |
| | | |
| | | public class TestErpSendOutboundPlanInfo { |
| | | /// <summary> |
| | | /// 出库计划单号(计划单号 jhdh) |
| | |
| | | /// AGV 小车号 |
| | | /// </summary> |
| | | public string ForkliftNo { set; get; } |
| | | ///// <summary> |
| | | ///// AGV 下一个状态 |
| | | ///// </summary> |
| | | //public int NextState { set; get; } |
| | | } |
| | | |
| | | public class AgvReportsInfo { |
| | |
| | | public int NextState { set; get; } = 0; |
| | | } |
| | | |
| | | public class FalseOk { |
| | | public bool JumpOut { set; get; } = true; |
| | | } |
| | | |
| | | public class InsertCntrItemInfo { |
| | | public string Cntr { set; get; } |
| | | public string Item { set; get; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | |
| | | 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; } |
| | | } |
| | | } |