| | |
| | | } |
| | | |
| | | /// <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> |
| | |
| | | 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; |
| | | |
| | | if (insertTable) { |
| | | // 暂定在满托下线入库的时候,登记托盘容器-物料号关系(后面可能会改成系统维护) |
| | | cntrItemRel = new TN_Container_ItemType { |
| | | S_ITEM_CODE = itemCode, |
| | | S_CNTR_CODE = cntrCode, |
| | | S_CNTR_TYPE = "托盘", |
| | | cntr = new TN_Container { |
| | | S_CODE = cntrCode, |
| | | S_TYPE = "托盘", |
| | | S_SPEC = itemCode, |
| | | S_SOURCE = taskName, |
| | | }; |
| | | } |
| | | // END |
| | | 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) // 指定:起点货位号 |
| | |
| | | return info; |
| | | } |
| | | |
| | | // BEG 插入或更新容器与物料类型的绑定表 |
| | | if (insertTable) { |
| | | if (db.Insertable<TN_Container_ItemType>(cntrItemRel).ExecuteCommand() <= 0) { |
| | | 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; |
| | | } |
| | | } |
| | | //else { |
| | | // if (db.Updateable<TN_Container_ItemType>(cntrItemRel).ExecuteCommand() <= 0) { |
| | | // 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(); |