wankeda
2025-05-26 0864509e1eb593c3dedb66196ec19fe51437922b
´úÂë¹ÜÀí/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskCZService.cs
@@ -26,18 +26,26 @@
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ISystemRepository;
using WIDESEA_Common;
using WIDESEA_Core.Enums;
using SqlSugar.Extensions;
namespace WIDESEAWCS_TaskInfoService
{
    public class TaskCZService : ServiceBase<DtCZTask, ITaskCZRepository>, ITaskCZService
    {
        private readonly ITaskRepository _taskRepository;
        private readonly ITaskService _taskService;
        private readonly ITaskCZDetailsRepository _detailsRepository;
        private readonly IDt_StationinfoRepository _stationinfoRepository;
        public TaskCZService(ITaskCZRepository BaseDal, ITaskRepository taskRepository, ITaskCZDetailsRepository detailsRepository) : base(BaseDal)
        public TaskCZService(ITaskCZRepository BaseDal, IDt_StationinfoRepository stationinfoRepository, ITaskService taskService, ITaskRepository taskRepository, ITaskCZDetailsRepository detailsRepository) : base(BaseDal)
        {
            _taskRepository = taskRepository;
            _detailsRepository = detailsRepository;
            _taskService = taskService;
            _stationinfoRepository = stationinfoRepository;
        }
        public Task<WebResponseContent> AddTaskCZAsync(CZTaskDto dto)
@@ -165,7 +173,7 @@
        }
        /// <summary>
        /// è¾“送线回流
        /// ç©ºæ‰˜å›žæµ
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
@@ -174,23 +182,196 @@
            WebResponseContent webResponseContent = new WebResponseContent();
            try
            {
                //通过站点表判断缓存架是那个区域去那条输送线回流口。。。。。。。。。。。
                string Saddress = saveModel.MainData["sourceAddress"].ToString();
                string Taddress = saveModel.MainData["targetAddress"].ToString();
                string Exception = saveModel.MainData["Exception"].ToString();
                Dt_Task task = _taskRepository.QueryFirst(x => x.SourceAddress == Saddress && x.TaskState == (int)TaskInStatusEnum.InPending && x.TargetAddress == "WaitBind");
                if (task == null)
                Dt_Task task = _taskRepository.QueryFirst(x => x.SourceAddress == Saddress);
                if (task != null)
                {
                    webResponseContent.Error("任务不存在!");
                    webResponseContent.Error("此缓存架已存在任务!");
                    return Task.FromResult(webResponseContent);
                }
                task.TargetAddress = Taddress;
                task.ExceptionMessage = Exception;
                task.TaskState = (int)TaskInStatusEnum.InNew;
                var isTrue = _taskRepository.UpdateData(task);
                if (isTrue)
                Dt_Stationinfo Stationinfo = _stationinfoRepository.QueryFirst(x => x.StationCode == Saddress);
                Dt_Task dt_Task = new Dt_Task();
                dt_Task.TaskNum = _taskService.GetTaskNum();
                dt_Task.CreateDate = DateTime.Now;
                dt_Task.Creater = "system";
                dt_Task.CurrentAddress = Saddress;
                dt_Task.SourceAddress = Saddress;
                dt_Task.TaskState = (int)TaskInStatusEnum.InNew;
                dt_Task.TaskType = (int)TaskOutboundTypeEnum.Outbound;
                dt_Task.Grade = 1;
                dt_Task.PalletCode = "";
                if (Stationinfo.Area == "正极")
                {
                    webResponseContent.OK("任务下发成功!");
                    dt_Task.TargetAddress = "正极回流输送线入口";
                }
                else
                {
                    dt_Task.TargetAddress = "负极回流输送线入口";
                }
                dt_Task.NextAddress = dt_Task.TargetAddress;
                dt_Task.Barcode = "";
                dt_Task.Roadway = "AGV";
                dt_Task.WMSId = 0;
                dt_Task.Remark = "空托回流";
                Dt_Task dt_Tasks = new Dt_Task();
                dt_Tasks.TaskNum = _taskService.GetTaskNum();
                dt_Tasks.CreateDate = DateTime.Now;
                dt_Tasks.Creater = "system";
                if (Stationinfo.Area == "正极")
                {
                    dt_Task.CurrentAddress = "正极回流输送线出口";
                }
                else
                {
                    dt_Task.CurrentAddress = "负极回流输送线出口";
                }
                dt_Tasks.SourceAddress = dt_Task.CurrentAddress;
                dt_Tasks.TaskState = (int)TaskInStatusEnum.InPending;
                dt_Tasks.TaskType = (int)TaskOutboundTypeEnum.Outbound;
                dt_Tasks.Grade = 1;
                dt_Tasks.PalletCode = "";
                dt_Tasks.TargetAddress = Taddress;
                dt_Tasks.NextAddress = Taddress;
                dt_Tasks.Barcode = "";
                dt_Tasks.Roadway = "AGV";
                dt_Tasks.WMSId = 0;
                dt_Tasks.Remark = "空托回流";
                var isTrue = _taskRepository.AddData(dt_Task);
                var isTrue1 = _taskRepository.AddData(dt_Tasks);
                webResponseContent.OK("任务下发成功!");
            }
            catch (Exception ex)
            {
                webResponseContent.Error(ex.Message);
            }
            return Task.FromResult(webResponseContent);
        }
        /// <summary>
        /// çƒ˜çƒ¤å‡ºæ–™
        /// </summary>
        /// <param name="sourceAddress"></param>
        /// <returns></returns>
        public Task<WebResponseContent> OutBoundTask(string sourceAddress)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            try
            {
                Dt_Task task = _taskRepository.QueryFirst(x => x.SourceAddress == sourceAddress);
                if (task != null)
                {
                    webResponseContent.Error("起点已存在任务!");
                    return Task.FromResult(webResponseContent);
                }
                Dt_Stationinfo stationinfo = _stationinfoRepository.QueryFirst(x => x.Location_state == LocationStatusEnum.Free.ObjToInt());
                if (stationinfo == null)
                {
                    webResponseContent.Error("未找到空缓存架放置!");
                    return Task.FromResult(webResponseContent);
                }
                Dt_Task tasks = _taskRepository.QueryFirst(x => x.SourceAddress == stationinfo.StationCode || x.TargetAddress == stationinfo.StationCode);
                if (tasks != null)
                {
                    webResponseContent.Error("未找到可用缓存架");
                    return Task.FromResult(webResponseContent);
                }
                Dt_Task dt_Task = new Dt_Task()
                {
                    TaskNum = _taskService.GetTaskNum(),
                    CreateDate = DateTime.Now,
                    Creater = "system",
                    CurrentAddress = sourceAddress,
                    SourceAddress = sourceAddress,
                    TaskState = (int)TaskInStatusEnum.InNew,
                    TaskType = (int)TaskOutboundTypeEnum.Outbound,
                    Grade = 1,
                    PalletCode = "",
                    TargetAddress = stationinfo.StationCode,
                    NextAddress = stationinfo.StationCode,
                    Barcode = "",
                    Roadway = "AGV",
                    WMSId = 0,
                    Remark = "空托回流"
                };
                var isTrue = _taskRepository.AddData(dt_Task);
                webResponseContent.OK("任务下发成功!");
            }
            catch (Exception ex)
            {
                webResponseContent.Error(ex.Message);
            }
            return Task.FromResult(webResponseContent);
        }
        /// <summary>
        /// çƒ˜çƒ¤å›žç‚‰
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public Task<WebResponseContent> OutBoundTasks(SaveModel saveModel)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            try
            {
                //通过站点表判断缓存架是那个区域去那条输送线回流口。。。。。。。。。。。
                string Saddress = saveModel.MainData["sourceAddress"].ToString();
                string Taddress = saveModel.MainData["targetAddress"].ToString();
                Dt_Stationinfo Stationinfo = _stationinfoRepository.QueryFirst(x => x.StationCode == Saddress);
                Dt_Task dt_Task = new Dt_Task();
                dt_Task.TaskNum = _taskService.GetTaskNum();
                dt_Task.CreateDate = DateTime.Now;
                dt_Task.Creater = "system";
                dt_Task.CurrentAddress = Saddress;
                dt_Task.SourceAddress = Saddress;
                dt_Task.TaskState = (int)TaskInStatusEnum.InNew;
                dt_Task.TaskType = (int)TaskOutboundTypeEnum.Outbound;
                dt_Task.Grade = 1;
                dt_Task.PalletCode = "";
                if (Stationinfo.Area == "正极")
                {
                    dt_Task.TargetAddress = "正极回流输送线入口";
                }
                else
                {
                    dt_Task.TargetAddress = "负极回流输送线入口";
                }
                dt_Task.NextAddress = dt_Task.TargetAddress;
                dt_Task.Barcode = "";
                dt_Task.Roadway = "AGV";
                dt_Task.WMSId = 0;
                dt_Task.Remark = "烘烤回炉";
                Dt_Task dt_Tasks = new Dt_Task();
                dt_Tasks.TaskNum = _taskService.GetTaskNum();
                dt_Tasks.CreateDate = DateTime.Now;
                dt_Tasks.Creater = "system";
                if (Stationinfo.Area == "正极")
                {
                    dt_Task.CurrentAddress = "正极回流输送线出口";
                }
                else
                {
                    dt_Task.CurrentAddress = "负极回流输送线出口";
                }
                dt_Tasks.SourceAddress = dt_Task.CurrentAddress;
                dt_Tasks.TaskState = (int)TaskInStatusEnum.InPending;
                dt_Tasks.TaskType = (int)TaskOutboundTypeEnum.Outbound;
                dt_Tasks.Grade = 1;
                dt_Tasks.PalletCode = "";
                dt_Tasks.TargetAddress = Taddress;
                dt_Tasks.NextAddress = Taddress;
                dt_Tasks.Barcode = "";
                dt_Tasks.Roadway = "AGV";
                dt_Tasks.WMSId = 0;
                dt_Tasks.Remark = "烘烤回炉";
                var isTrue = _taskRepository.AddData(dt_Task);
                var isTrue1 = _taskRepository.AddData(dt_Tasks);
                webResponseContent.OK("任务下发成功!");
            }
            catch (Exception ex)
            {