IPC-610
2024-10-21 f040136ab8029cc207a8111d21c78bbf315a6dbd
Admin.NET/WCS.Application/Util/HttpService.cs
@@ -1,7 +1,10 @@
using Furion.Logging;
using DocumentFormat.OpenXml.EMMA;
using Elastic.Clients.Elasticsearch;
using Furion.Logging;
using Furion.RemoteRequest.Extensions;
using Newtonsoft.Json;
using System.Text;
using WCS.Application.Entity;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ComponentTCBBatchCreateContainerServiceVersionResponse.Types;
namespace WCS.Application;
@@ -46,15 +49,18 @@
            string url = Urls.WMSAddress + ":" + Urls.WMSPort;
            var result =  (url + "/api/DownAPi/RequestRoadWay").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasks>().Result;
            Log.Information("调用WMS接口反馈任务接口" + result.ToJson());
            if (result.StatusCode == "0")
            if (result.Success == 0)
            {
                                
                var taskAdd = new WcsTask()
                {
                    TaskType = TaskTypeEnum.In,
                    Status = TaskStatusEnum.Wait,
                    Origin = "WMS",
                    StartLocate = startLocat,
                    PalletNo = palletNo,
                    TaskNo = result.TaskList.TaskNo,
                    Levels = 999,
                    EndLocate = result.TaskList.EndLocate,
                    EndRoadway = result.TaskList.EndRoadway
                };
@@ -80,155 +86,72 @@
        endLocat = PLCCommon.RoadwayToStationNum(endLocat, ceng);
        return returnStr;
        // 确定目标工位//需添加层数确认
        //switch (endLocat)
        //{
        //    case "R01":
        //        if (ceng == "1")
        //        {
        //            endLocat = "145";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "252";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "101";
        //        }
        //        break;
        //    case "R02":
        //        if (ceng == "1")
        //        {
        //            endLocat = "137";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "260";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "405";
        //        }
        //        break;
        //    case "R03":
        //        if (ceng == "1")
        //        {
        //            endLocat = "127";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "270";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "409";
        //        }
        //        break;
        //    case "R04":
        //        if (ceng == "1")
        //        {
        //            endLocat = "119";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "278";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "413";
        //        }
        //        break;
        //    case "R05":
        //        if (ceng == "1")
        //        {
        //            endLocat = "109";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "288";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "417";
        //        }
        //        break;
        //    case "R06":
        //        if (ceng == "1")
        //        {
        //            endLocat = "101";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "301";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "421";
        //        }
        //        break;
        //    case "R07":
        //        if (ceng == "1")
        //        {
        //            endLocat = "091";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "307";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "425";
        //        }
        //        break;
        //    case "R08":
        //        if (ceng == "1")
        //        {
        //            endLocat = "083";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "315";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "429";
        //        }
        //        break;
        //    case "R09":
        //        if (ceng == "1")
        //        {
        //            endLocat = "073";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "325";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "433";
        //        }
        //        break;
        //    case "R10":
        //        if (ceng == "1")
        //        {
        //            endLocat = "065";
        //        }
        //        else if (ceng == "2")
        //        {
        //            endLocat = "337";
        //        }
        //        else if (ceng == "3")
        //        {
        //            endLocat = "437";
        //        }
        //        break;
        //}
    }
    /// <summary>
    /// 调用WMS接口自动码垛绑定信息返回巷道口
    /// </summary>
    /// <returns></returns>
    public string BindRequestRoadWay(string orderNo, string palletNo,decimal qty ,string type,string skuNo, string lotNo, string lotText, string supplierLot, List<WcsBoxInfo> detail,
        string startLocat, string taskModel, string ceng, ref string endLocat, ref string taskNo)
    {
        string returnStr = "";
        var task = _db.Queryable<WcsTask>().First(m => m.IsDelete == false && (m.Status == TaskStatusEnum.Wait || m.Status == TaskStatusEnum.Doing) && m.TaskType == TaskTypeEnum.In && m.PalletNo == palletNo);
        if (task == null)
        {
            var model = new BoxPalletBindVm()
            {
                OrderCode= "",//暂无上游系统编号
                AsnNo= orderNo,
                AsnDetailNo=0,//暂无入库单明细编号,WMS根据物料批次查找
                PalletNo=palletNo,
                Qty= qty,
                Type=type,
                SkuNo=skuNo,
                LotNo= lotNo,
                LotText= lotText,
                SupplierLot= supplierLot,
                Detail=detail
            };
            string url = Urls.WMSAddress + ":" + Urls.WMSPort;
            var result = (url + "/api/DownAPi/BindRequestRoadWay").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasks>().Result;
            Log.Information("调用WMS接口反馈任务接口" + result.ToJson());
            if (result.Success == 0)
            {
                var taskAdd = new WcsTask()
                {
                    TaskType = TaskTypeEnum.In,
                    Status = TaskStatusEnum.Wait,
                    Origin = "WMS",
                    StartLocate = startLocat,
                    PalletNo = palletNo,
                    TaskNo = result.TaskList.TaskNo,
                    EndLocate = result.TaskList.EndLocate,
                    EndRoadway = result.TaskList.EndRoadway
                };
                _db.Insertable(taskAdd).ExecuteCommand();
                endLocat = result.TaskList.EndRoadway;
                returnStr = result.TaskList.EndLocate;
            }
            else
            {
                returnStr = "-1:" + result.Message;
                return returnStr;
            }
        }
        else
        {
            returnStr = task.EndLocate;
            endLocat = task.EndRoadway;
            taskNo = task.TaskNo;
        }
        endLocat = PLCCommon.RoadwayToStationNum(endLocat, ceng);
        return returnStr;
    }
    /// <summary>
    /// 调用WMS接口申请储位接口
    /// </summary>
@@ -243,7 +166,9 @@
        string returnStr = "";
        var task = _db.Queryable<WcsTask>().First(m => m.IsDelete == false && (m.Status == TaskStatusEnum.Wait || m.Status == TaskStatusEnum.Doing) && m.TaskType == TaskTypeEnum.In && m.PalletNo == palletNo && string.IsNullOrWhiteSpace(m.EndLocate));
        var task = _db.Queryable<WcsTask>().First(m => m.IsDelete == false
        && (m.Status == TaskStatusEnum.Wait || m.Status == TaskStatusEnum.Doing)
        && m.TaskType == TaskTypeEnum.In && m.PalletNo == palletNo && !string.IsNullOrWhiteSpace(m.EndLocate));
        if (task == null)
        {
@@ -258,20 +183,35 @@
            string url = Urls.WMSAddress + ":" + Urls.WMSPort;
            var result = (url + "/api/DownAPi/RequestLocation").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasks>().Result;
            Log.Information("调用WMS申请储位接口反馈任务接口" + result.ToJson());
            if (result.StatusCode == "0")
            if (result.Success == 0)
            {
                var taskAdd = new WcsTask()
                var taskUp = _db.Queryable<WcsTask>().First(m => m.IsDelete == false && m.TaskNo == result.TaskList.TaskNo);
                if (taskUp == null)
                {
                    TaskType = TaskTypeEnum.In,
                    Origin = "WMS",
                    StartLocate = startLocat,
                    TaskNo = result.TaskList.TaskNo,
                    EndLocate = result.TaskList.EndLocate,
                    EndRoadway = result.TaskList.EndRoadway
                };
                    var taskAdd = new WcsTask()
                    {
                        TaskNo = result.TaskList.TaskNo,
                        TaskType = TaskTypeEnum.In,
                        Status = TaskStatusEnum.Wait,
                        //IsSuccess =TaskSuccessEnum.Success,
                        Origin = "WMS",
                        StartLocate = startLocat,
                        PalletNo = palletNo,
                        EndLocate = result.TaskList.EndLocate,
                        EndRoadway = result.TaskList.EndRoadway
                    };
                    _db.Insertable(taskAdd).ExecuteCommand();
                    HubUtil.PublicTask(taskAdd.Adapt<WcsTaskOutput>());
                }
                else
                {
                    taskUp.EndRoadway = result.TaskList.EndRoadway;
                    taskUp.EndLocate = result.TaskList.EndLocate;
                    _db.Updateable(taskUp).ExecuteCommand();
                    HubUtil.PublicTask(taskUp.Adapt<WcsTaskOutput>());
                }
                _db.Updateable(taskAdd).ExecuteCommand();
                returnStr = result.TaskList.EndLocate;
                taskNo = result.TaskList.TaskNo;
            }
@@ -288,7 +228,6 @@
        }
        return returnStr;
    }
@@ -297,10 +236,10 @@
    /// </summary>
    /// <param name="model">任务完成状态</param>
    /// <returns></returns>
    public async Task<ResponseTasks> RequestTask(TaskRequest model)
    public async Task<ResponseModel> RequestTask(TaskRequestWMS model)
    {
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = await (url + "/api/DownAPi/ReceiveWcsSignal").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasks>();
        var result = await (url + "/api/DownAPi/ReceiveWcsSignal").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseModel>();
        Log.Information("调用WMS接口反馈任务接口" + result.ToJson());
        return result;
    }
@@ -330,4 +269,63 @@
        Log.Information("调用WMS接口反馈满取异常接口" + result.ToJson());
        return result;
    }
    /// <summary>
    /// 调用WMS接口申请空托跺出库
    /// </summary>
    /// <param name="Num"></param>
    /// <param name="OutMode"></param>
    /// <returns></returns>
    public string IssuePlnOutHouseWcs(string Num,string OutMode)
    {
        string returnStr = "";
        var model = new OutPalletModel()
        {
            Num = Num,//出库跺数
            OutMode = OutMode//出库口
        };
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = (url + "/api/DownAPi/IssuePlnOutHouseWcs").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseOutPallet>().Result;
        Log.Information("调用WMS接口反馈任务接口" + result.ToJson());
        if (result.Success == 0)
        {
            foreach (var item in result.TaskList)
            {
                var taskUp = _db.Queryable<WcsTask>().First(m => m.IsDelete == false && m.TaskNo == item.TaskNo);
                if (taskUp == null)
                {
                    var taskAdd = new WcsTask()
                    {
                        TaskNo = item.TaskNo,
                        TaskType = (TaskTypeEnum)(int.Parse(item.TaskType)),
                        Status = TaskStatusEnum.Wait,
                        //IsSuccess =TaskSuccessEnum.Success,
                        Origin = "WMS",
                        StartLocate = item.StartLocate,
                        StartRoadway=item.StartRoadway,
                        PalletNo = item.PalletNo,
                        EndLocate = item.EndLocate,
                        EndRoadway = item.EndRoadway
                    };
                    _db.Insertable(taskAdd).ExecuteCommand();
                    HubUtil.PublicTask(taskAdd.Adapt<WcsTaskOutput>());
                }
                else
                {
                    taskUp.EndRoadway = item.EndRoadway;
                    taskUp.EndLocate = item.EndLocate;
                    _db.Updateable(taskUp).ExecuteCommand();
                    HubUtil.PublicTask(taskUp.Adapt<WcsTaskOutput>());
                }
            }
        }
        else
        {
            returnStr = "-1:" + result.Message;
            return returnStr;
        }
        return returnStr;
    }
}