zhaowc
2024-06-20 c3d7843cd9508afbeca86df38e2d7322be227a00
小车叫桶接口,任务下发接口编写,小车任务model添加
1个文件已添加
2个文件已修改
407 ■■■■■ 已修改文件
Wms/Model/InterFaceModel/RCSModel.cs 118 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/WMS.BLL/BllTransServer/QualityServer.cs 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/WMS.BLL/BllTransServer/RcsServer.cs 277 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/Model/InterFaceModel/RCSModel.cs
New file
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Model.InterFaceModel
{
    public class RCSModel
    {
        /// <summary>
        /// 生成RCS任务单 任务下发接口信息
        /// </summary>
        public class genAgvSchedulingTaskReq
        {
            /// <summary>
            /// 请求编号,每个请求都要一个唯一编号,同一个请求重复提交,使用同一编号
            /// 必填
            /// </summary>
            public string reqCode { get; set; }
            /// <summary>
            /// 请求时间 yyyy-MM-dd HH:mm:ss CMS系统生成
            /// </summary>
            public string reqTime { get; set; }
            /// <summary>
            /// 客户端编号
            /// </summary>
            public string clientCode { get; set; }
            /// <summary>
            /// 令牌号
            /// </summary>
            public string tokenCode { get; set; }
            /// <summary>
            /// 任务类型,根据配置的任务模板号填写
            /// 必填
            /// </summary>
            public string taskTyp { get; set; }
            public string scenetTyp { get; set; }
            /// <summary>
            /// 容器类型
            /// </summary>
            public string ctnrTyp { get; set; }
            /// <summary>
            /// 容器编号
            /// </summary>
            public string ctnrCode { get; set; }
            /// <summary>
            /// 工作位
            /// </summary>
            public string wbCode { get; set; }
            /// <summary>
            /// 位置路径 途经点--起点和终点
            /// 必须
            /// </summary>
            public List<PositionCodePath> positionCodePath { get; set; }
            /// <summary>
            /// 货架编号
            /// </summary>
            public string podCode { get; set; }
            /// <summary>
            /// 货架方向
            /// </summary>
            public string podDir { get; set; }
            /// <summary>
            /// 货架类型
            /// </summary>
            public string podTyp { get; set; }
            /// <summary>
            /// 物料批次或货架上的物料唯一编码
            /// </summary>
            public string materialLot { get; set; }
            /// <summary>
            /// 优先级
            /// </summary>
            public string priorit { get; set; }
            /// <summary>
            /// 任务单号
            /// </summary>
            public string taskCode { get; set; }
            /// <summary>
            /// AGV编号
            /// </summary>
            public string agvCode { get; set; }
            /// <summary>
            /// 自定义字段
            /// </summary>
            public List<data> data { get; set; }
        }
        public class PositionCodePath
        {
            public string positionCode { get; set; }
            public string type { get; set; }
        }
        public class data
        {
            public string materialLot { get; set; }
            public string materialCode { get; set; }
        }
        /// <summary>
        /// RCS任务返回
        /// </summary>
        public class genAgvSchedulingTaskRep
        {
            /// <summary>
            /// 返回码
            /// 0:成功
            /// 1~N:失败
            /// </summary>
            public string code { get; set; }
            public string message { get; set; }
            public string reqCode { get; set; }
            public string data { get; set; }
        }
    }
}
Wms/WMS.BLL/BllTransServer/QualityServer.cs
@@ -1,10 +1,18 @@
using System;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMS.Entity.BllAsnEntity;
using WMS.Entity.Context;
using WMS.Entity.DataEntity;
using WMS.Entity.SysEntity;
namespace WMS.BLL.BllTransServer
{
    class QualityServer
    public class QualityServer
    {
    }
}
Wms/WMS.BLL/BllTransServer/RcsServer.cs
@@ -1,10 +1,283 @@
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;
            }
        }
    }
}