huanghongfeng
4 天以前 1d8897348d578648421b024d0dc5ff3d626e05f9
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -41,6 +41,7 @@
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_Core.Utilities;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoRepository;
@@ -48,6 +49,7 @@
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using static Microsoft.IO.RecyclableMemoryStreamManager;
namespace WIDESEAWCS_TaskInfoService
{
@@ -83,10 +85,10 @@
        public string urlWMSTask = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlWMSTask"];
        public string urlTaskCompleted = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlTaskCompleted"];
        public string urlWMSMovelibraryTask = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlWMSMovelibraryTask"];
        public string urlRelocationTaskCompleted = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlRelocationTaskCompleted"];
        public string urlQueryinventory = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlQueryinventory"];
        public string urlEmptyOutbound = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlEmptyOutbound"];
        public string urlRawmaterialout = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlRawmaterialout"];
        public string urlPalletQueryinventory = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlPalletQueryinventory"];
        /// <summary>
        /// æŽ¥æ”¶WMS任务信息
        /// </summary>
@@ -107,10 +109,12 @@
                    Dt_Task task = _mapper.Map<Dt_Task>(item);
                    task.TaskState = (int)TaskOutStatusEnum.OutNew;
                    task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
                    task.CreateDate = DateTime.Now;
                    tasks.Add(task);
                }
                BaseDal.AddData(tasks);
                _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "接收WMS任务");
                content = WebResponseContent.Instance.OK("成功");
            }
            catch (Exception ex)
@@ -154,6 +158,7 @@
                    PalletCode = palletCode
                };
                content = HttpHelper.Post<WebResponseContent>($"{urlWMSTask}", generate);
                WriteLog.GetLog("入库任务接收").Write(JsonConvert.SerializeObject(content), "入库任务接收");
                Dt_Task task = new Dt_Task();
                if (content != null)
                {
@@ -163,9 +168,11 @@
                        task.TaskState = (int)TaskInStatusEnum.Line_InFinish;
                        task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
                        BaseDal.AddData(task);
                        return content = WebResponseContent.Instance.Error();
                        return content;
                    }
                }
                return content = WebResponseContent.Instance.Error();
            }
            catch (Exception ex)
@@ -196,23 +203,9 @@
                throw;
            }
            /*WebResponseContent content = new WebResponseContent();
            GenerateInv generate = new GenerateInv()
            {
                SourceAddress = "",
                PalletCode = palletCode
            };
            content = HttpHelper.Post<WebResponseContent>($"{urlQueryinventory}", generate);
            if (content != null)
            {
                if (content.Status)
                {
                    return content;
                }
            }
            return content = WebResponseContent.Instance.Error();*/
        }
        /// <summary>
        /// æ ¹æ®æ‰˜ç›˜å·ã€èµ·å§‹åœ°å€å‘WMS请求任务
@@ -242,6 +235,10 @@
                        task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
                        BaseDal.AddData(task);
                        return content = WebResponseContent.Instance.OK();
                    }
                    else
                    {
                        WriteLog.GetLog("PLC日志出库日志").Write($"空托出库失败,详情:{content.Message}", "需要空托");
                    }
                }
                return content = WebResponseContent.Instance.Error();
@@ -295,6 +292,20 @@
            }
        }
        public WebResponseContent RequestWMSTask4()
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                return content = HttpHelper.Get<WebResponseContent>($"{urlPalletQueryinventory}");
            }
            catch (Exception ex)
            {
                return content = WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// æ ¹æ®æ·±åº“位向wms申请判断浅库位是否有货,是否需要进行移库操作
        /// </summary>
@@ -315,7 +326,7 @@
                        task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToString());
                        if (task.TaskNum != _Task.TaskNum)
                        {
                            WriteLog.GetLog("接收任务").Write("移库任务:"+JsonConvert.SerializeObject(task), "接收任务");
                            task.TaskState = (int)TaskRelocationTypeEnum.Relocation;
                            task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
                            task.TaskNum = task.TaskNum;
@@ -325,6 +336,49 @@
                            return task;
                        }
                    }
                }
                else
                {
                    WriteLog.GetLog("PLC日志").Write($"失败信息:{content.Message}", "移库信息");
                    return null;
                }
            }
            return _Task;
        }
        public Dt_Task RequestWMSTaskMovelibrary2(Dt_Task _Task)
        {
            WebResponseContent content = new WebResponseContent();
            content = HttpHelper.Get<WebResponseContent>($"{urlWMSMovelibraryTask}?TaskNum={_Task.TaskNum}&SourceAddress={_Task.TargetAddress}");
            Dt_Task task = new Dt_Task();
            if (content != null)
            {
                if (content.Status)
                {
                    if (content.Data != null)
                    {
                        task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToString());
                        if (task.TaskNum != _Task.TaskNum)
                        {
                            WriteLog.GetLog("接收任务").Write("移库任务:" + JsonConvert.SerializeObject(task), "接收任务");
                            task.TaskState = (int)TaskRelocationTypeEnum.Relocation;
                            task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
                            task.TaskNum = task.TaskNum;
                            task.Grade = 3;
                            task.TaskType = (int)TaskRelocationTypeEnum.Relocation;
                            BaseDal.AddData(task);
                            return task;
                        }
                    }
                }
                else
                {
                    WriteLog.GetLog("PLC日志").Write($"失败信息:{content.Message}", "移库信息");
                    return null;
                }
            }
@@ -394,6 +448,18 @@
            else
                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy);
        }
        public List<Dt_Task> CraneTaskList(string deviceNo)
        {
            return BaseDal.QueryData(x => x.Roadway == deviceNo && (x.TaskState == (int)TaskInStatusEnum.Line_InFinish || x.TaskState == (int)TaskOutStatusEnum.OutNew),TaskOrderBy);
        }
        public Dt_Task CutStackerCraneTask(string deviceNo)
        {
            Dt_Task dt_Task = BaseDal.QueryFirst(x => x.Roadway == deviceNo && (x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting || x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish || x.TaskState == (int)TaskInStatusEnum.SC_InExecuting || x.TaskState == (int)TaskInStatusEnum.SC_InFinish));
            return dt_Task;
        }
        public Dt_Task IngStackerCraneTask(string deviceNo)
        {
            //string deviceNot = deviceNo == "SC01" ? "1" : "2";
@@ -403,7 +469,15 @@
        public Dt_Task IngStackerCraneTask2(string deviceNo)
        {
            //string deviceNot = deviceNo == "SC01" ? "1" : "2";
            return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting);
            try
            {
                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        /// <summary>
@@ -454,6 +528,11 @@
        public List<Dt_Task> QueryStationIsOccupiedOutTasks(string deviceNo, string SourceAddress)
        {
            return BaseDal.QueryData(x => x.Roadway == deviceNo && SourceAddress.Contains(x.SourceAddress), TaskOrderBy);
        }
        public List<Dt_Task> QueryStationIsOccupiedOutTasks2(string deviceNo, string TargetAddress)
        {
            return BaseDal.QueryData(x => x.Roadway == deviceNo && TargetAddress.Contains(x.SourceAddress), TaskOrderBy);
        }
        /// <summary>
@@ -671,9 +750,14 @@
                {
                    /*List<Dt_Router> routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress);
                    if (!routers.Any()) return WebResponseContent.Instance.Error($"未找到设备路由信息");*/
                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}");
                    task.TaskState = (int)TaskOutStatusEnum.OutFinish;
                    BaseDal.UpdateData(task);
                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}&HowWorks=2");
                    wcs_PLCto09("出库任务",$"条码:{task.PalletCode},任务号:{task.TaskNum}",$"调取wms任务反馈:{JsonConvert.SerializeObject(content)}");
                    task.ModifyDate = DateTime.Now;
                    BaseDal.DeleteData(task);
                    _task_HtyService.AddTaskHty(task);
@@ -684,10 +768,14 @@
                }
                else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting)
                {
                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}");
                    task.TaskState = (int)TaskInStatusEnum.InFinish;
                    BaseDal.UpdateData(task);
                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}&HowWorks=2");
                    wcs_PLCto09("入库任务", $"条码:{task.PalletCode},任务号:{task.TaskNum}", $"调取wms任务反馈:{JsonConvert.SerializeObject(content)}");
                    //todo 
                    //int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
                    task.TaskState = (int)TaskInStatusEnum.InFinish;
                    task.ModifyDate = DateTime.Now;
                    task.Modifier = "System";
                    BaseDal.DeleteData(task);
@@ -697,15 +785,13 @@
                }
                else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation)
                {
                    GenerateInv2 generate = new GenerateInv2()
                    {
                        PalletCode = task.PalletCode,
                        SourceAddress = task.SourceAddress,
                        TargetAddress = task.TargetAddress
                    task.TaskState = (int)TaskOutStatusEnum.OutRest;
                    BaseDal.UpdateData(task);
                    };
                    content = HttpHelper.Post<WebResponseContent>($"{urlRelocationTaskCompleted}", generate);
                    task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish;
                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}&HowWorks=2");
                    wcs_PLCto09("入库任务", $"条码:{task.PalletCode},任务号:{task.TaskNum}", $"调取wms任务反馈:{JsonConvert.SerializeObject(content)}");
                    task.ModifyDate = DateTime.Now;
                    BaseDal.DeleteData(task);
                    _task_HtyService.AddTaskHty(task);
@@ -723,7 +809,7 @@
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error($"任务完成异常,任务号:【{taskNum}】");
                content = WebResponseContent.Instance.Error($"任务完成异常,任务号:【{taskNum}】,原因:{ex.Message}");
            }
            return content;
        }
@@ -818,5 +904,92 @@
            }
            return content;
        }
        /// <summary>
        /// åˆ é™¤æ•°æ®
        /// </summary>
        /// <param name="keys">主键数组</param>
        /// <returns></returns>
        public virtual WebResponseContent DeleteData(object[] keys)
        {
            try
            {
                List<Dt_Task> tasks = BaseDal.QureyDataByIds(keys);
                foreach (Dt_Task task in tasks)
                {
                    _task_HtyService.AddTaskHty(task);
                }
                if (typeof(Dt_Task).GetNavigatePro() == null)
                    return BaseDal.DeleteDataByIds(keys) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error();
                else
                {
                    if (keys != null)
                    {
                        Type detailType = typeof(Dt_Task).GetDetailType();
                        string name = typeof(Dt_Task).GetMainIdByDetail();
                        List<object> dynamicDelKeys = new List<object>();
                        for (int i = 0; i < keys.Length; i++)
                        {
                            dynamicDelKeys.Add(keys[i]);
                        }
                        ((SqlSugarClient)BaseDal.Db).BeginTran();
                        if (dynamicDelKeys.Count > 0)
                            BaseDal.Db.Deleteable<object>().AS(detailType.Name).Where($"{name} in (@id)", new { id = dynamicDelKeys.ToArray() }).ExecuteCommandHasChange();
                        BaseDal.DeleteDataByIds(keys);
                        ((SqlSugarClient)BaseDal.Db).CommitTran();
                        return WebResponseContent.Instance.OK();
                    }
                    else
                    {
                        return WebResponseContent.Instance.Error("参数错误");
                    }
                }
            }
            catch (Exception ex)
            {
                ((SqlSugarClient)BaseDal.Db).RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        public WebResponseContent ReceiveWCSTask(int tasknum)
        {
            Dt_Task tasks = BaseDal.QueryFirst(x => x.TaskNum == tasknum);
            if(tasks == null)
            {
                return WebResponseContent.Instance.Error();
            }
            else
            {
                try
                {
                    _task_HtyService.AddTaskHty(tasks);
                    BaseDal.DeleteData(tasks);
                    WriteLog.Write_Log("WMS手动删除任务", "删除成功", $"申请删除的条码:{tasks.TaskNum},托盘条码:{tasks.PalletCode}", new { ä¿¡æ¯ = "删除成功" });
                    return WebResponseContent.Instance.OK();
                }
                catch (Exception ex)
                {
                    WriteLog.Write_Log("WMS手动删除任务", "删除失败", $"申请删除的条码:{tasks.TaskNum},托盘条码:{tasks.PalletCode}", new { ä¿¡æ¯ = ex.Message });
                    return WebResponseContent.Instance.Error();
                }
            }
        }
        public void wcs_PLCto09(string SCLLinStack, string Logtype, string Magessadd)
        {
            WriteLog.Write_Log("任务完成交互", SCLLinStack, Logtype, new { ä¿¡æ¯ = Magessadd });
        }
    }
}