| | |
| | | |
| | | public static void HandleClientRequest(System.Net.Sockets.TcpClient client) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var (ok, msg) = (false, string.Empty); |
| | | |
| | | using (client) |
| | | using (NetworkStream stream = client.GetStream()) { |
| | | try { |
| | |
| | | // B. 如果是每条产线各一个客户端,更简单,直接根据IP地址确定终点货位 |
| | | // TODO 具体逻辑待后续确定时补完 |
| | | |
| | | var success = CreateInboundTask(startLocCode, message.CntrCode).Value; |
| | | (ok, msg) = CreateInboundTask(startLocCode, message.CntrCode); |
| | | LogHelper.Info(msg); |
| | | |
| | | // 发送响应 |
| | | string response = success ? "ACK: 机器人已调度" : "NAK: 调度失败"; |
| | | string response = ok ? "ACK: 机器人已调度" : "NAK: 调度失败"; |
| | | byte[] responseData = Encoding.UTF8.GetBytes(response); |
| | | stream.Write(responseData, 0, responseData.Length); |
| | | } |
| | |
| | | /// <param name="startLocCode"></param> |
| | | /// <param name="cntrCode"></param> |
| | | /// <returns></returns> |
| | | public static Result<bool> CreateInboundTask(string startLocCode, string cntrCode) { |
| | | public static (bool, string) CreateInboundTask(string startLocCode, string cntrCode) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | |
| | | var taskInfo = Settings.GetTaskInfo(ETask.M满托下线入库); |
| | |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") |
| | | //.Where(l => l.N_CURRENT_NUM == 0) // 绑定前 |
| | | .First(); |
| | | |
| | | |
| | | if (startLoc == null) { |
| | | return NewResult(false, $"没有找到起点货位'{startLocCode}',或不满足要求:未上锁,当前容器数量=0"); |
| | | return (false, $"没有找到起点货位'{startLocCode}'!!要求:未上锁,当前容器数量=0"); |
| | | } |
| | | |
| | | var locCntrRelOld = db.Queryable<TN_Loc_Container>() |
| | |
| | | .Where(a => a.N_CURRENT_NUM == 0) // 筛选:空货位 |
| | | .OrderBy(l => l.N_LAYER) |
| | | .First(); |
| | | |
| | | |
| | | if (endLoc == null) { |
| | | return NewResult(false, $"没有找到合适的【终点货位】,需要满足要求:未上锁,当前容器数量=0"); |
| | | return (false, $"没有找到合适的[终点货位]!!要求:未上锁,当前容器数量=0"); |
| | | } |
| | | |
| | | var cntId = locCntrRel.S_CNTR_CODE; |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); |
| | | |
| | | WCSHelper.LockStartLoc(startLoc); // 起点出库锁 |
| | | WCSHelper.LockEndLoc(endLoc); // 终点入库锁 |
| | | var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, cntId, taskName); |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (locCntrRelOld != null) { |
| | | if (db.Deleteable(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(); |
| | | return NewResult(false, $"删除旧货位容器关系表失败:货位编码{locCntrRelOld.S_LOC_CODE},容器编码{locCntrRelOld.S_CNTR_CODE}"); |
| | | return (false, $"删除旧货位容器关系表失败:货位编码{locCntrRelOld.S_LOC_CODE},容器编码{locCntrRelOld.S_CNTR_CODE}"); |
| | | } |
| | | } |
| | | |
| | | if (db.Insertable(locCntrRel).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewResult(false, $"插入货位容器关系表失败:货位编码{locCntrRel.S_LOC_CODE},容器编码{locCntrRel.S_CNTR_CODE}"); |
| | | return (false, $"插入货位容器关系表失败:货位编码{locCntrRel.S_LOC_CODE},容器编码{locCntrRel.S_CNTR_CODE}"); |
| | | } |
| | | |
| | | if (db.Updateable(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(); |
| | | return NewResult(false, $"生成任务'{taskName}'失败:更新起点货位{startLoc.S_CODE}锁状态失败"); |
| | | return (false, $"生成任务'{taskName}'失败:更新起点货位{startLoc.S_CODE}锁状态失败"); |
| | | } |
| | | |
| | | if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewResult(false, $"生成任务'{taskName}'失败:更新终点货位{endLoc.S_CODE}锁状态失败"); |
| | | return (false, $"生成任务'{taskName}'失败:更新终点货位{endLoc.S_CODE}锁状态失败"); |
| | | } |
| | | |
| | | if (db.Insertable(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewResult(false, $"生成任务'{taskName}'失败,任务号={task.S_CODE},容器号={cntId},起点={startLoc.S_CODE},终点={endLoc.S_CODE}"); |
| | | return (false, $"生成任务'{taskName}'失败,任务号={task.S_CODE},容器号={cntId},起点={startLoc.S_CODE},终点={endLoc.S_CODE}"); |
| | | } |
| | | |
| | | tran.CommitTran(); |
| | | return NewResult(true, $"生成任务'{taskName}'成功,任务号={task.S_CODE},容器号={cntId},起点={startLoc.S_CODE},终点={endLoc.S_CODE}"); |
| | | return (true, $"生成任务'{taskName}'成功,任务号={task.S_CODE},容器号={cntId},起点={startLoc.S_CODE},终点={endLoc.S_CODE}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | return NewResult(false, ex.Message); |
| | | return (false, ex.Message); |
| | | } |
| | | } |
| | | |
| | | private static Result<bool> NewResult(bool res, string msg, bool log = true) { |
| | | if (log) { LogHelper.Info(msg); } |
| | | return new Result<bool>(res, msg); |
| | | } |
| | | |
| | | } |
| | |
| | | //public string ItemCode { get; set; } |
| | | //public string BatchNo { get; set; } |
| | | public string CntrCode { get; set; } |
| | | } |
| | | |
| | | public class Result<T> { |
| | | public T Value { get; set; } |
| | | public string Content { get; set; } |
| | | |
| | | public Result(T value, string content) { |
| | | Value = value; |
| | | Content = content; |
| | | } |
| | | } |
| | | } |