| | |
| | | [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(); |
| | | //} |
| | | |
| | | var agvTaskState = new AgvTaskState() { |
| | | task_no = model.TaskID, |
| | | forklift_no = model.ForkliftNo, |
| | |
| | | //typeof(TN_Container_Item), |
| | | }; |
| | | |
| | | //var areaNameList = new List<string>(); |
| | | //foreach (var area in Settings.Areas) { |
| | | // areaNameList.AddRange(area.Codes); |
| | | //} |
| | | |
| | | //var locationList = new List<TN_Location>(); |
| | | //foreach (var area in areaNameList) { |
| | | // int i = 0; |
| | | // int j = 0; |
| | | // int k = 0; |
| | | |
| | | // if (area == "KXHJQ" || area == "MTHJQ" || area == "MXHJQ") { |
| | | // for (i = 1; i <= 4; i++) { |
| | | // for (j = 1; j <= 5; j++) { |
| | | // for (k = 1; k <= 3; k++) { |
| | | // locationList.Add(new TN_Location() { |
| | | // N_ROW = i, |
| | | // N_COL = j, |
| | | // N_LAYER = k, |
| | | // S_AREA_CODE = area, |
| | | // S_CODE = $"{area}-{i.ToString().PadLeft(2, '0')}-{j.ToString().PadLeft(2, '0')}" + |
| | | // $"-{k.ToString().PadLeft(2, '0')}" |
| | | // }); |
| | | // } |
| | | // } |
| | | // } |
| | | // continue; |
| | | // } |
| | | |
| | | // if (area == "BZQ") { |
| | | // for (i = 1; i <= 2; i++) { |
| | | // for (j = 1; j <= 2; j++) { |
| | | // locationList.Add(new TN_Location() { |
| | | // N_ROW = i, |
| | | // N_COL = j, |
| | | // S_AREA_CODE = area, |
| | | // S_CODE = $"{area}-{i.ToString().PadLeft(2, '0')}-{j.ToString().PadLeft(2, '0')}" |
| | | // }); |
| | | // } |
| | | // } |
| | | // continue; |
| | | // } |
| | | |
| | | // i = 1; |
| | | // for (j = 1; j <= 5; j++) { |
| | | // locationList.Add(new TN_Location() { |
| | | // N_ROW = i, |
| | | // N_COL = j, |
| | | // S_AREA_CODE = area, |
| | | // S_CODE = $"{area}-{i.ToString().PadLeft(2, '0')}-{j.ToString().PadLeft(2, '0')}" |
| | | // }); |
| | | // } |
| | | |
| | | |
| | | //} |
| | | |
| | | |
| | | |
| | | //using (var tran = db.Ado.UseTran()) { |
| | | // //db.CodeFirst.InitTables(entityTypes); |
| | | // if (db.Insertable<TN_Location>(locationList).ExecuteCommand() <= 0) { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// DEBUG:插入货位、容器、货品信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [Route("InsertLocCntrCg")] |
| | | public string InsertLocCntrCg(LocCntrCg locCntrCg) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | |
| | | try { |
| | | |
| | | using (var tran = db.UseTran()) { |
| | | LogHelper.Info("LogCntrCg:" + JsonConvert.SerializeObject(locCntrCg)); |
| | | if (string.IsNullOrEmpty(locCntrCg.LocCode)) return ""; |
| | | |
| | | var loc = db.Queryable<TN_Location>().First(a => a.S_CODE == locCntrCg.LocCode); |
| | | if (loc == null) { |
| | | var newLoc = new TN_Location { |
| | | S_CODE = locCntrCg.LocCode, |
| | | S_AREA_CODE = locCntrCg.LocArea ?? "" |
| | | }; |
| | | |
| | | if (db.Insertable<TN_Location>(newLoc).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info($"插入位置{locCntrCg.LocCode}失败"); |
| | | return "插入失败"; |
| | | } |
| | | |
| | | loc = newLoc; |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(locCntrCg.CntrCode)) { |
| | | LogHelper.Info("容器号为空,不再读取后面的数据"); |
| | | return ""; |
| | | } |
| | | |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_LOC_CODE == locCntrCg.LocCode |
| | | && a.S_CNTR_CODE == locCntrCg.CntrCode); |
| | | |
| | | if (locCntrRel == null) { |
| | | var newLocCntrRel = new TN_Loc_Container { |
| | | S_LOC_CODE = locCntrCg.LocCode, |
| | | S_CNTR_CODE = locCntrCg.CntrCode, |
| | | S_CNTR_TYPE = locCntrCg.CntrType ?? "" |
| | | }; |
| | | |
| | | loc.N_CURRENT_NUM = 1; |
| | | |
| | | if (db.Insertable<TN_Loc_Container>(newLocCntrRel).ExecuteCommand() <= 0 |
| | | && db.Updateable<TN_Location>(loc).UpdateColumns(c => c.N_CURRENT_NUM).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info($"插入位置托盘关系{locCntrCg.LocCode}-{locCntrCg.CntrCode}失败"); |
| | | return "插入失败"; |
| | | } |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(locCntrCg.ItemCode)) { |
| | | LogHelper.Info("物料号为空,不再读取后面的数据"); |
| | | return ""; |
| | | } |
| | | |
| | | var cgDetail = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == locCntrCg.CntrCode |
| | | && a.S_ITEM_CODE == locCntrCg.ItemCode); |
| | | if (cgDetail == null) { |
| | | var locList = new List<TN_CG_Detail>(); |
| | | locList.Add(new TN_CG_Detail { S_CNTR_CODE = locCntrCg.CntrCode, S_ITEM_CODE = locCntrCg.ItemCode, S_BATCH_NO = locCntrCg.BatchNo ?? "" }); |
| | | if (db.Insertable<TN_CG_Detail>(locList).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info($"插入托盘物料关系{locCntrCg.CntrCode}-{locCntrCg}失败"); |
| | | return "插入失败"; |
| | | } |
| | | } |
| | | tran.CommitTran(); |
| | | } |
| | | |
| | | return "插入数据成功"; |
| | | |
| | | } |
| | | catch (Exception ex) { |
| | | return $"Error reading CSV file: {ex.Message}"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// DEBUG:根据容器物料信息表,插入容器物料登记信息表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [Route("InsertContainerItemByCgDetail")] |
| | | public string InsertContainerItemByCgDetail(FalseOk _) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | try { |
| | | var cgDetailList = db.Queryable<TN_CG_Detail>().ToList(); |
| | | var cntrItemList = new List<TN_Container_ItemType>(); |
| | | foreach (var cgDetail in cgDetailList) { |
| | | if (db.Queryable<TN_Container_ItemType>().Where(i => i.S_CNTR_CODE == cgDetail.S_CNTR_CODE).Any()) { |
| | | continue; |
| | | } |
| | | |
| | | cntrItemList.Add(new TN_Container_ItemType { |
| | | S_CNTR_CODE = cgDetail.S_CNTR_CODE, |
| | | S_ITEM_CODE = cgDetail.S_ITEM_CODE, |
| | | }); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Container_ItemType>(cntrItemList).ExecuteCommand() <= 0) { |
| | | return "插入失败"; |
| | | } |
| | | |
| | | return "插入成功"; |
| | | } |
| | | catch (Exception ex) { |
| | | |
| | | LogHelper.InfoEx(ex); |
| | | return ex.Message; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// DEBUG:根据容器物料信息表,插入容器物料登记信息表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [Route("InsertContainerItem")] |
| | | public string InsertContainerItem(InsertCntrItemInfo cgDetail) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | try { |
| | | var cntrItem = new TN_Container_ItemType { |
| | | S_CNTR_CODE = cgDetail.Cntr, |
| | | S_ITEM_CODE = cgDetail.Item, |
| | | }; |
| | | |
| | | if (db.Insertable<TN_Container_ItemType>(cntrItem).ExecuteCommand() <= 0) { |
| | | return "插入失败"; |
| | | } |
| | | |
| | | return "插入成功"; |
| | | } |
| | | catch (Exception ex) { |
| | | |
| | | LogHelper.InfoEx(ex); |
| | | return ex.Message; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// DEBUG:模拟输送线产线满托盘下线流程 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var info = ""; |
| | | |
| | | var taskName = TaskName.T托盘_满托下线入库; |
| | | var startAreaName = AreaName.B包装区; |
| | | 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 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 cgDetail = new TN_CG_Detail { |
| | | // S_ITEM_CODE = itemCode, |
| | | // S_BATCH_NO = batchNo, |
| | | // S_CNTR_CODE = cntrCode, |
| | | //}; |
| | | |
| | | // BEG 每次轮询都检查对应容器是否已登记,登记保持不变,未登记则插入 |
| | | // TODO 可能会采用每次上线都更新的逻辑,后面再看 |
| | | var cntrItemRel = db.Queryable<TN_Container_ItemType>() |
| | | .Where(i => i.S_CNTR_CODE == cntrCode).First(); |
| | | //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}"); |
| | | |
| | | var insertTable = cntrItemRel == null; |
| | | // 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}不符,直接覆盖结果"); |
| | | |
| | | if (insertTable) { |
| | | // 暂定在满托下线入库的时候,登记托盘容器-物料号关系(后面可能会改成系统维护) |
| | | cntrItemRel = new TN_Container_ItemType { |
| | | S_ITEM_CODE = itemCode, |
| | | S_CNTR_CODE = cntrCode, |
| | | S_CNTR_TYPE = "托盘", |
| | | }; |
| | | } |
| | | // END |
| | | // cntr.S_SPEC = itemCode; |
| | | // cntr.S_SOURCE = taskName; |
| | | // } |
| | | //} |
| | | |
| | | var startLoc = db.Queryable<TN_Location>() |
| | | .Where(l => l.S_CODE == startLocCode) // 指定:起点货位号 |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) |
| | | .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE)) // 起点货区符合任务要求 |
| | | .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(); |
| | | |
| | | if (startLoc == null) { |
| | | info = $"起点位置 '{startLocCode}' 不存在或不具备取货要求"; |
| | | info = $"在'{startAreaName}'中没有找到起点货位'{startLocCode}',或不满足要求:未上锁、当前容器数量=0"; |
| | | LogHelper.Info(info); |
| | | return info; |
| | | } |
| | | |
| | | 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 = cgDetail.S_CNTR_CODE, |
| | | S_CNTR_TYPE = "托盘", |
| | | S_CNTR_CODE = cntrCode, |
| | | S_CNTR_TYPE = cntrType, |
| | | }; |
| | | |
| | | startLoc.N_CURRENT_NUM = 1; // 绑定后 |
| | | |
| | | var endLoc = db.Queryable<TN_Location>() |
| | | .Where(a => Settings.AreaMap[AreaName.K空托存放区].Contains(a.S_AREA_CODE)) |
| | | .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(); |
| | | |
| | | if (endLoc == null) { |
| | | info = "空托入库暂时没有合适的货位可以入库"; |
| | | info = $"在终点货区'{endAreaName}'中,没有找到合适的【终点货位】,需要满足要求:未上锁、当前容器数量=0"; |
| | | LogHelper.Info(info); |
| | | return info; |
| | | } |
| | |
| | | LocationHelper.LockEndLoc(ref endLoc); // 终点入库锁 |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | 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; |
| | | } |
| | | |
| | | // BEG 插入或更新容器与物料类型的绑定表 |
| | | if (insertTable) { |
| | | if (db.Insertable<TN_Container_ItemType>(cntrItemRel).ExecuteCommand() <= 0) { |
| | | 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 = $"登记容器物料类型绑定表失败:物料编码{cntrItemRel.S_ITEM_CODE},容器编码{cntrItemRel.S_CNTR_CODE}"; |
| | | info = $"删除旧货位容器关系表失败:货位编码{locCntrRelOld.S_LOC_CODE},容器编码{locCntrRelOld.S_CNTR_CODE}"; |
| | | LogHelper.Info(info); |
| | | return info; |
| | | } |
| | | } |
| | | //else { |
| | | // if (db.Updateable<TN_Container_ItemType>(cntrItemRel).ExecuteCommand() <= 0) { |
| | | //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(); |
| | | // info = $"登记容器物料类型绑定表失败:物料编码{cntrItemRel.S_ITEM_CODE},容器编码{cntrItemRel.S_CNTR_CODE}"; |
| | | // LogHelper.Info(info); |
| | | // return info; |
| | | // } |
| | | //} |
| | | // END |
| | | //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) { |
| | | tran.RollbackTran(); |
| | |
| | | return info; |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | 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); |
| | |
| | | |
| | | public class AddInboundTaskInfo { |
| | | /// <summary> |
| | | /// 物料编码 |
| | | /// 物料编码(暂时没用) |
| | | /// </summary> |
| | | public string ItemCode { get; set; } |
| | | /// <summary> |
| | | /// 批次号 |
| | | /// 批次号(暂时没用) |
| | | /// </summary> |
| | | public string BatchNo { get; set; } |
| | | /// <summary> |
| | |
| | | /// AGV 小车号 |
| | | /// </summary> |
| | | public string ForkliftNo { set; get; } |
| | | /// <summary> |
| | | /// AGV 下一个状态 |
| | | /// </summary> |
| | | public int NextState { set; get; } |
| | | ///// <summary> |
| | | ///// AGV 下一个状态 |
| | | ///// </summary> |
| | | //public int NextState { set; get; } |
| | | } |
| | | |
| | | public class FalseOk { |