| | |
| | | var startPoint = Settings.ProductionLines.FirstOrDefault(a => a.PointOut == model.StartLoc); |
| | | if (startPoint != null)//起点存在 |
| | | { |
| | | var woInfo = db.Queryable<TN_WorkOrder>().Where(a => a.S_LINE_NO == startPoint.ProductionLine_Name && a.S_B_STATE == "开启").OrderBy(b => b.T_CREATE, OrderByType.Desc).First(); |
| | | |
| | | if (woInfo != null)//当前产线不存在开启的最新的工单 |
| | | var startLoc = db.Queryable<TN_Location>().First(a => a.S_LOCK_STATE == "无" && a.N_LOCK_STATE == 0 && a.S_CODE == model.StartLoc && a.C_ENABLE == "Y"); |
| | | if (startLoc != null)//该产线的起点没锁住 |
| | | { |
| | | var startLoc = db.Queryable<TN_Location>().First(a => a.S_LOCK_STATE == "无" && a.N_LOCK_STATE == 0 && a.S_CODE == model.StartLoc && a.C_ENABLE == "Y"); |
| | | if (startLoc != null)//该产线的起点没锁住 |
| | | var cgInfo = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == model.RfId); |
| | | if (cgInfo != null)//有残留的容器货品明细关系表信息 |
| | | { |
| | | var cgInfo = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == model.RfId); |
| | | if (cgInfo != null)//有残留的容器货品明细关系表信息 |
| | | result.resultCode = 1; |
| | | result.resultMsg = $"该容器{model.RfId}已绑定货品{cgInfo.S_ITEM_CODE},如果要使用,容器先解绑货品"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |
| | | else |
| | | { |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_CNTR_CODE == model.RfId); |
| | | if (locCntrRel != null)//当前容器是否绑定了货位 |
| | | { |
| | | result.resultCode = 1; |
| | | result.resultMsg = $"该容器{model.RfId}已绑定货品{cgInfo.S_ITEM_CODE},如果要使用,容器先解绑货品"; |
| | | result.resultCode = 2; |
| | | result.resultMsg = $"该容器{model.RfId}已绑定货位{locCntrRel.S_LOC_CODE},如果要使用,容器先解绑货位"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |
| | | else |
| | | { |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_CNTR_CODE == model.RfId); |
| | | if (locCntrRel != null)//当前容器是否绑定了货位 |
| | | //新增货位容器关系表 |
| | | locCntrRel = new TN_Loc_Container() |
| | | { |
| | | result.resultCode = 2; |
| | | result.resultMsg = $"该容器{model.RfId}已绑定货位{locCntrRel.S_LOC_CODE},如果要使用,容器先解绑货位"; |
| | | S_LOC_CODE = startPoint.PointOut, |
| | | S_CNTR_CODE = model.RfId, |
| | | }; |
| | | |
| | | var readBytes1 = S7Helper.ReadBytes(startPoint.ProductionLine_IP, 20, 2, 4); |
| | | byte[] rfid = new byte[4] { readBytes1[0], readBytes1[1], readBytes1[2], readBytes1[3] }; |
| | | string rfids16 = BitConverter.ToString(rfid); |
| | | string rfids = (((readBytes1[0]) << 24) + (readBytes1[1] << 16) + (readBytes1[2] << 8) + readBytes1[3]).ToString(); |
| | | LogHelper.Info($"产线容器号:{rfids},其16进制形式:{rfids16}"); |
| | | |
| | | if (rfids != model.RfId) |
| | | { |
| | | result.resultCode = 9; |
| | | result.resultMsg = $"PDA填入的容器号{model.RfId}与S7产线通讯的容器号{rfids}不同"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |
| | | else |
| | | var readBytes2 = S7Helper.ReadBytes(startPoint.ProductionLine_IP, 20, 26, 2); |
| | | var modelWeight = ((readBytes2[0]) << 8) + readBytes2[1]; |
| | | |
| | | var modelCI = db.Queryable<TN_CAR_IN>().First(i => i.S_CAR_CODE == model.CarCode && i.S_CNTR_CODE == model.RfId && i.S_B_STATE == "0");//查询是否有这个对应的且状态正常的容器车号子表 |
| | | |
| | | TN_CG_Detail tN_CG_Detail = new TN_CG_Detail()//新增容器货品明细表 |
| | | { |
| | | //新增货位容器关系表 |
| | | locCntrRel = new TN_Loc_Container() |
| | | S_CNTR_CODE = model.RfId, |
| | | S_ITEM_SPEC = model.Spe, |
| | | S_SPE = model.Spe, |
| | | S_CAR_CODE = model.CarCode, |
| | | N_ITEM_STATE = 1, |
| | | S_ITEM_STATE = "待检", |
| | | F_QTY = modelWeight,//这里的重量要当成数量来使用 |
| | | }; |
| | | |
| | | var endLoc = db.Queryable<TN_Location>(). |
| | | Where(c => c.S_AREA_CODE == Settings.Areas[1] && c.S_LOCK_STATE == "无" && c.N_LOCK_STATE == 0 && c.N_CURRENT_NUM == 0 && c.C_ENABLE == "Y"). |
| | | OrderBy(o => o.T_MODIFY, OrderByType.Asc).First();//查询合适的终点货位,直接判断当前数量为0即可 |
| | | |
| | | if (endLoc != null) |
| | | { |
| | | var task1 = new TN_Task() |
| | | { |
| | | S_LOC_CODE = startPoint.PointOut, |
| | | S_CODE = WCSHelper.GenerateTaskNo(), |
| | | S_START_AREA = startLoc.S_AREA_CODE, |
| | | S_END_AREA = endLoc.S_AREA_CODE, |
| | | S_START_LOC = startLoc.S_CODE, |
| | | S_END_LOC = endLoc.S_CODE, |
| | | S_TYPE = "PDA满托下线入库", |
| | | N_B_STATE = 0, |
| | | S_CNTR_CODE = model.RfId, |
| | | S_SPEC = model.Spe, |
| | | }; |
| | | |
| | | var readBytes1 = S7Helper.ReadBytes(startPoint.ProductionLine_IP, 20, 2, 4); |
| | | byte[] rfid = new byte[4] { readBytes1[0], readBytes1[1], readBytes1[2], readBytes1[3] }; |
| | | string rfids16 = BitConverter.ToString(rfid); |
| | | string rfids = (((readBytes1[0]) << 24) + (readBytes1[1] << 16) + (readBytes1[2] << 8) + readBytes1[3]).ToString(); |
| | | LogHelper.Info($"产线容器号:{rfids},其16进制形式:{rfids16}"); |
| | | startLoc.N_LOCK_STATE = 2; |
| | | startLoc.S_LOCK_STATE = "出库锁"; |
| | | startLoc.N_CURRENT_NUM = 1; |
| | | startLoc.T_MODIFY = DateTime.Now; |
| | | |
| | | if (rfids != model.RfId) |
| | | endLoc.N_LOCK_STATE = 1; |
| | | endLoc.S_LOCK_STATE = "入库锁"; |
| | | startLoc.T_MODIFY = DateTime.Now; |
| | | |
| | | using (var tran = db.Ado.UseTran()) |
| | | { |
| | | result.resultCode = 9; |
| | | result.resultMsg = $"PDA填入的容器号{model.RfId}与S7产线通讯的容器号{rfids}不同"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |
| | | var readBytes2 = S7Helper.ReadBytes(startPoint.ProductionLine_IP, 20, 26, 2); |
| | | var modelWeight = ((readBytes2[0]) << 8) + readBytes2[1]; |
| | | |
| | | var modelCI = db.Queryable<TN_CAR_IN>().First(i => i.S_CAR_CODE == model.CarCode && i.S_CNTR_CODE == model.RfId && i.S_B_STATE == "0");//查询是否有这个对应的且状态正常的容器车号子表 |
| | | |
| | | TN_CG_Detail tN_CG_Detail = new TN_CG_Detail()//新增容器货品明细表 |
| | | { |
| | | S_CNTR_CODE = model.RfId, |
| | | S_ITEM_CODE = woInfo.S_ITEM_CODE, |
| | | S_BATCH_NO = woInfo.S_BATCH_CODE, |
| | | S_ITEM_SPEC = woInfo.S_ITEM_SPEC, |
| | | S_SPE= woInfo.S_ITEM_SPEC, |
| | | S_CAR_CODE = model.CarCode, |
| | | N_ITEM_STATE = 1, |
| | | S_ITEM_STATE = "待检", |
| | | F_QTY = modelWeight,//这里的重量要当成数量来使用 |
| | | }; |
| | | |
| | | var endLoc = db.Queryable<TN_Location>(). |
| | | Where(c => c.S_AREA_CODE == Settings.Areas[1] && c.S_LOCK_STATE == "无" && c.N_LOCK_STATE == 0 && c.N_CURRENT_NUM == 0 && c.C_ENABLE == "Y"). |
| | | OrderBy(o => o.T_MODIFY, OrderByType.Asc).First();//查询合适的终点货位,直接判断当前数量为0即可 |
| | | |
| | | if (endLoc != null) |
| | | { |
| | | var task1 = new TN_Task() |
| | | if (modelCI == null)//容器车号子表不存在 |
| | | { |
| | | S_CODE = WCSHelper.GenerateTaskNo(), |
| | | S_START_AREA = startLoc.S_AREA_CODE, |
| | | S_END_AREA = endLoc.S_AREA_CODE, |
| | | S_START_LOC = startLoc.S_CODE, |
| | | S_END_LOC = endLoc.S_CODE, |
| | | S_TYPE = "PDA满托下线入库", |
| | | N_B_STATE = 0, |
| | | S_CNTR_CODE = model.RfId, |
| | | S_SPEC = model.Spe, |
| | | }; |
| | | |
| | | startLoc.N_LOCK_STATE = 2; |
| | | startLoc.S_LOCK_STATE = "出库锁"; |
| | | startLoc.N_CURRENT_NUM = 1; |
| | | startLoc.T_MODIFY = DateTime.Now; |
| | | |
| | | endLoc.N_LOCK_STATE = 1; |
| | | endLoc.S_LOCK_STATE = "入库锁"; |
| | | startLoc.T_MODIFY = DateTime.Now; |
| | | |
| | | using (var tran = db.Ado.UseTran()) |
| | | { |
| | | if (modelCI == null)//容器车号子表不存在 |
| | | modelCI = new TN_CAR_IN() |
| | | { |
| | | modelCI = new TN_CAR_IN() |
| | | { |
| | | S_CNTR_CODE = model.RfId, |
| | | S_CAR_CODE = model.CarCode, |
| | | S_B_STATE = "0", |
| | | }; |
| | | if (db.Insertable<TN_CAR_IN>(modelCI).ExecuteCommand() <= 0) |
| | | { |
| | | tran.RollbackTran(); |
| | | result.resultCode = 8; |
| | | result.resultMsg = $"新增的TN_CAR_IN表插入失败,容器:{modelCI.S_CNTR_CODE},车号:{modelCI.S_CAR_CODE}"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task1).ExecuteCommand() > 0 && |
| | | db.Updateable<TN_Location>(startLoc).ExecuteCommand() > 0 && |
| | | db.Updateable<TN_Location>(endLoc).ExecuteCommand() > 0 && |
| | | db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() > 0 && |
| | | db.Insertable<TN_CG_Detail>(tN_CG_Detail).ExecuteCommand() > 0)//创建搬送任务,起点终点容器 |
| | | { |
| | | tran.CommitTran(); |
| | | result.resultCode = 0; |
| | | result.resultMsg = "成功"; |
| | | LogHelper.Info($"生成PDA满托下线入库任务成功,容器:{modelCI.S_CNTR_CODE},起点:{startPoint.PointOut},终点:{endLoc.S_CODE}"); |
| | | |
| | | Task task99 = Task.Run(() => |
| | | { |
| | | WMSHelper.InsertOpInfo(model.staff, "PDA满托下线入库", modelCI.S_CNTR_CODE); |
| | | }); |
| | | |
| | | Task task98 = Task.Run(() => |
| | | { |
| | | var target = new TN_EquipProDetail() |
| | | { |
| | | S_ID = tN_CG_Detail.S_ID, |
| | | TASKTYPE = "PDA满托下线入库", |
| | | RFID = model.RfId, |
| | | SPEC = woInfo.S_ITEM_SPEC, |
| | | CARCODE = model.CarCode, |
| | | WEIGHT = modelWeight, |
| | | ITEMSTATE = "待检", |
| | | ITEMCODE = woInfo.S_ITEM_CODE, |
| | | LOGINNAME = model.staff, |
| | | SHIFT = "None", |
| | | STARTLOC = startLoc.S_CODE, |
| | | }; |
| | | SpecHelper.InsertEquipProDetail(target); |
| | | }); |
| | | |
| | | Task task27 = Task.Run(() => |
| | | { |
| | | var target = new TN_InventoryM() |
| | | { |
| | | S_ID = tN_CG_Detail.S_ID, |
| | | RFID = model.RfId, |
| | | SPEC = woInfo.S_ITEM_SPEC, |
| | | WEIGHT = modelWeight, |
| | | ITEMSTATE = "待检", |
| | | ITEMCODE = woInfo.S_ITEM_CODE, |
| | | LOGINNAME = model.staff, |
| | | SHIFT = "None", |
| | | }; |
| | | SpecHelper.InsertInventoryM(target); |
| | | }); |
| | | |
| | | return result; |
| | | } |
| | | else |
| | | S_CNTR_CODE = model.RfId, |
| | | S_CAR_CODE = model.CarCode, |
| | | S_B_STATE = "0", |
| | | }; |
| | | if (db.Insertable<TN_CAR_IN>(modelCI).ExecuteCommand() <= 0) |
| | | { |
| | | tran.RollbackTran(); |
| | | result.resultCode = 7; |
| | | result.resultMsg = $"生成满托下线入库任务失败,容器:{modelCI.S_CNTR_CODE},起点:{startPoint.PointOut},终点:{endLoc.S_CODE}"; |
| | | result.resultCode = 8; |
| | | result.resultMsg = $"新增的TN_CAR_IN表插入失败,容器:{modelCI.S_CNTR_CODE},车号:{modelCI.S_CAR_CODE}"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result.resultCode = 4; |
| | | result.resultMsg = $"未找到合适的终点,容器:{modelCI.S_CNTR_CODE}"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | |
| | | if (db.Insertable<TN_Task>(task1).ExecuteCommand() > 0 && |
| | | db.Updateable<TN_Location>(startLoc).ExecuteCommand() > 0 && |
| | | db.Updateable<TN_Location>(endLoc).ExecuteCommand() > 0 && |
| | | db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() > 0 && |
| | | db.Insertable<TN_CG_Detail>(tN_CG_Detail).ExecuteCommand() > 0)//创建搬送任务,起点终点容器 |
| | | { |
| | | tran.CommitTran(); |
| | | result.resultCode = 0; |
| | | result.resultMsg = "成功"; |
| | | LogHelper.Info($"生成PDA满托下线入库任务成功,容器:{modelCI.S_CNTR_CODE},起点:{startPoint.PointOut},终点:{endLoc.S_CODE}"); |
| | | |
| | | Task task99 = Task.Run(() => |
| | | { |
| | | WMSHelper.InsertOpInfo(model.staff, "PDA满托下线入库", modelCI.S_CNTR_CODE); |
| | | }); |
| | | |
| | | Task task98 = Task.Run(() => |
| | | { |
| | | var target = new TN_EquipProDetail() |
| | | { |
| | | S_ID = tN_CG_Detail.S_ID, |
| | | TASKTYPE = "PDA满托下线入库", |
| | | RFID = model.RfId, |
| | | SPEC = model.Spe, |
| | | CARCODE = model.CarCode, |
| | | WEIGHT = modelWeight, |
| | | ITEMSTATE = "待检", |
| | | LOGINNAME = model.staff, |
| | | SHIFT = "None", |
| | | STARTLOC = startLoc.S_CODE, |
| | | }; |
| | | SpecHelper.InsertEquipProDetail(target); |
| | | }); |
| | | |
| | | Task task27 = Task.Run(() => |
| | | { |
| | | var target = new TN_InventoryM() |
| | | { |
| | | S_ID = tN_CG_Detail.S_ID, |
| | | RFID = model.RfId, |
| | | SPEC = model.Spe, |
| | | WEIGHT = modelWeight, |
| | | ITEMSTATE = "待检", |
| | | LOGINNAME = model.staff, |
| | | SHIFT = "None", |
| | | }; |
| | | SpecHelper.InsertInventoryM(target); |
| | | }); |
| | | |
| | | return result; |
| | | } |
| | | else |
| | | { |
| | | tran.RollbackTran(); |
| | | result.resultCode = 7; |
| | | result.resultMsg = $"生成满托下线入库任务失败,容器:{modelCI.S_CNTR_CODE},起点:{startPoint.PointOut},终点:{endLoc.S_CODE}"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result.resultCode = 4; |
| | | result.resultMsg = $"未找到合适的终点,容器:{modelCI.S_CNTR_CODE}"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result.resultCode = 9; |
| | | result.resultMsg = $"此位置:{startPoint.PointOut}已锁住"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result.resultCode = 10; |
| | | result.resultMsg = $"当前产线{startPoint.ProductionLine_Name}位置{startPoint.PointOut}没有开启的工单"; |
| | | result.resultCode = 9; |
| | | result.resultMsg = $"此位置:{startPoint.PointOut}已锁住"; |
| | | LogHelper.Info(result.resultMsg); |
| | | return result; |
| | | } |