| | |
| | | using System; |
| | | using Microsoft.IdentityModel.Protocols; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using Utility.Tools; |
| | | using WMS.Entity.BllAsnEntity; |
| | | using WMS.Entity.Context; |
| | | using WMS.Entity.DataEntity; |
| | | using WMS.Entity.SysEntity; |
| | | using static Model.InterFaceModel.RCSModel; |
| | | |
| | | namespace WMS.BLL.BllTransServer |
| | | { |
| | | class RcsServer |
| | | public class RcsServer |
| | | { |
| | | private static readonly SqlSugarScope Db = DataContext.Db; |
| | | /// <summary> |
| | | /// RCS叫桶(净桶和脏桶) |
| | | /// </summary> |
| | | /// <param name="warehouseno">库区</param> |
| | | /// <param name="type">叫料类型</param> |
| | | /// <returns></returns> |
| | | public void GetPalletNo(string warehouseno, string type, out string palletno, out string locatno) |
| | | { |
| | | var sql = "select LocatNo,palletno from SysStorageLocat where status = '1'"; |
| | | SysStorageLocat pallet = new SysStorageLocat(); |
| | | try |
| | | { |
| | | switch (type) |
| | | { |
| | | case "0"://叫净桶 |
| | | sql += $"and WareHouseNo = 'A01' and WareHouseNo = '{warehouseno}' order by updatetime desc"; |
| | | pallet = Db.Ado.SqlQuery<SysStorageLocat>(sql).FirstOrDefault(); |
| | | if (pallet == null) |
| | | { |
| | | throw new Exception("暂无净桶可分配"); |
| | | } |
| | | break; |
| | | case "3"://叫脏桶 |
| | | sql += $"and WareHouseNo = 'A04' and WareHouseNo = '{warehouseno}' order by updatetime desc"; |
| | | pallet = Db.Ado.SqlQuery<SysStorageLocat>(sql).FirstOrDefault(); |
| | | if (pallet == null) |
| | | { |
| | | throw new Exception("暂无脏桶可分配"); |
| | | } |
| | | break; |
| | | } |
| | | palletno = pallet.PalletNo; |
| | | locatno = pallet.LocatNo; |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// RCS叫桶(混料桶和下料桶) |
| | | /// </summary> |
| | | /// <param name="warehouseno">库区</param> |
| | | /// <param name="type">叫料类型</param> |
| | | /// <param name="lotno">叫料批次</param> |
| | | /// <returns></returns> |
| | | public void GetPalletNo(string warehouseno, string type, string lotno, out string palletno, out string locatno) |
| | | { |
| | | var sql = ""; |
| | | var pallet = ""; |
| | | DataStockDetail SoMes = new DataStockDetail(); |
| | | try |
| | | { |
| | | switch (type) |
| | | { |
| | | case "1"://叫料桶(混料) |
| | | BllArrivalNoticeDetail ArriveMes = new BllArrivalNoticeDetail(); |
| | | //判断该批次是否有对应入库单 |
| | | sql += $"select * from BllArrivalNoticeDetail where LotNo = '{lotno}' order by CreateTime desc"; |
| | | ArriveMes = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(sql).FirstOrDefault(); |
| | | if (ArriveMes == null) |
| | | { |
| | | throw new Exception("该批次没有对应的入库单"); |
| | | } |
| | | //查找库存中是否有可用的此批次的混料桶 |
| | | sql = $"select LocatNo,palletno from DataStockDetail " + |
| | | $"left join SysStorageLocat b on a.LocatNo = b.LocatNo " + |
| | | $"where a.LotNo = '{lotno}'and a.WareHouseNo = '{warehouseno}' and b.status = '1' " + |
| | | $"order by CompleteTime desc"; |
| | | SoMes = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); |
| | | if (pallet == null) |
| | | { |
| | | throw new Exception("暂无混料桶可分配"); |
| | | } |
| | | break; |
| | | case "2"://叫料桶(下料) |
| | | //查找库存中是否有此批次的下料桶 |
| | | sql = $"select LocatNo,palletno from DataStockDetail" + |
| | | $"left join SysStorageLocat b on a.LocatNo = b.LocatNo " + |
| | | $"where a.LotNo = '{lotno}'and a.WareHouseNo = '{warehouseno}' and b.status = '1'" + |
| | | $" order by CompleteTime desc"; |
| | | SoMes = Db.Ado.SqlQuery<DataStockDetail>(sql).FirstOrDefault(); |
| | | if (pallet == null) |
| | | { |
| | | throw new Exception("暂无下料桶可分配"); |
| | | } |
| | | |
| | | break; |
| | | } |
| | | palletno = SoMes.PalletNo; |
| | | locatno = SoMes.LocatNo; |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 申请储位 |
| | | /// </summary> |
| | | /// <param name="PalletNo"></param> |
| | | /// <returns></returns> |
| | | public void ApplyLocatNo(string palletno, string type, out string locatno) |
| | | { |
| | | var sql = $"select LocatNo from SysStorageLocat where status = '0'"; |
| | | SysStorageLocat loction = new SysStorageLocat(); |
| | | try |
| | | { |
| | | switch (type) |
| | | { |
| | | case "0"://净桶申请储位 |
| | | sql += $"and WareHouseNo = 'A01'"; |
| | | loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); |
| | | if (loction == null) |
| | | { |
| | | throw new Exception("库内暂无空余净桶储位"); |
| | | } |
| | | break; |
| | | case "1"://混料桶申请储位 |
| | | sql += $"and WareHouseNo = 'A02'"; |
| | | loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); |
| | | if (loction == null) |
| | | { |
| | | throw new Exception("库内暂无空余混料桶储位"); |
| | | } |
| | | break; |
| | | case "2"://半成品桶申请储位 |
| | | sql += $"and WareHouseNo = 'A03'"; |
| | | loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); |
| | | if (loction == null) |
| | | { |
| | | throw new Exception("库内暂无空余半成品桶储位"); |
| | | } |
| | | break; |
| | | case "3"://脏桶申请储位 |
| | | sql += $"and WareHouseNo = 'A04'"; |
| | | loction = Db.Ado.SqlQuery<SysStorageLocat>(sql).OrderByDescending(a => a.CreateTime).FirstOrDefault(); |
| | | if (loction == null) |
| | | { |
| | | throw new Exception("库内暂无空余脏桶储位"); |
| | | } |
| | | break; |
| | | } |
| | | locatno = loction.PalletNo; |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// RCS生成任务 |
| | | /// </summary> |
| | | /// <param name="taskCode"></param> |
| | | /// <param name="taskType"></param> |
| | | /// <param name="startPos">起始位置</param> |
| | | /// <param name="endPos">目的位置</param> |
| | | /// <param name="agvCode"></param> |
| | | /// <param name="url">RCS地址</param> |
| | | /// <returns></returns> |
| | | public string genAgvSchedulingTask(string taskCode, string taskType, string startPos, string endPos, string agvCode,string url, ref genAgvSchedulingTaskRep cbrep) |
| | | { |
| | | try |
| | | { |
| | | PositionCodePath pcd1 = new PositionCodePath() |
| | | { |
| | | positionCode = startPos.ToString(), |
| | | type = "00", |
| | | }; |
| | | PositionCodePath pcd2 = new PositionCodePath() |
| | | { |
| | | positionCode = endPos.ToString(), |
| | | type = "00", |
| | | }; |
| | | List<PositionCodePath> lst = new List<PositionCodePath>(); |
| | | lst.Add(pcd1); |
| | | lst.Add(pcd2); |
| | | genAgvSchedulingTaskReq cbreq = new genAgvSchedulingTaskReq() |
| | | { |
| | | reqCode = taskCode.ToString(), |
| | | taskCode = taskCode.ToString(), |
| | | taskTyp = taskType, |
| | | positionCodePath = lst, |
| | | podCode = "", |
| | | agvCode = agvCode, |
| | | ctnrTyp = "1", |
| | | //ctnrCode="2", |
| | | |
| | | }; |
| | | if (startPos == "50") |
| | | { |
| | | cbreq.ctnrTyp = "4"; |
| | | } |
| | | cbrep = genAgvSchedulingTask(cbreq,url); |
| | | |
| | | |
| | | return cbrep.code; |
| | | } |
| | | catch (Exception ex) { throw ex; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 生成任务单 |
| | | /// </summary> |
| | | /// <param name="req"></param> |
| | | /// <returns></returns> |
| | | private genAgvSchedulingTaskRep genAgvSchedulingTask(genAgvSchedulingTaskReq req,string url) |
| | | { |
| | | genAgvSchedulingTaskRep rep = new genAgvSchedulingTaskRep() |
| | | { |
| | | code = "-1", |
| | | message = "生产任务单失败" |
| | | }; |
| | | if (req == null) |
| | | { |
| | | return rep; |
| | | } |
| | | try |
| | | { |
| | | string jsonReq = JsonConvert.SerializeObject(req); |
| | | |
| | | string jsonRep = HttpHelper.DoPost(url + "/genAgvSchedulingTask", jsonReq,"小车任务下发","RCS"); |
| | | jsonRep = jsonRep.TrimStart('\"'); |
| | | jsonRep = jsonRep.TrimEnd('\"'); |
| | | jsonRep = jsonRep.Replace("\\", ""); |
| | | rep = JsonConvert.DeserializeObject<genAgvSchedulingTaskRep>(jsonRep); |
| | | return rep; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 生成任务单到LogTask |
| | | /// </summary> |
| | | /// <param name="req"></param> |
| | | /// <returns></returns> |
| | | public void CreateLotTask(string startport,string endport,string type,string tasktype) |
| | | { |
| | | try |
| | | { |
| | | |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |