1
xiazhengtongxue
2026-01-28 b45155e1a5d76ca95d138025ab458fe2f3689748
1
已添加2个文件
已修改4个文件
223 ■■■■■ 文件已修改
项目代码/WCSServices/WIDESEAWCS_Server/Controllers/Task/TaskController.cs 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCSServices/WIDESEAWCS_Server/Log/容器入库创建任务/2026-01-27/任务信息260127.txt 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCSServices/WIDESEAWCS_TaskInfoService/InvokeAGVService.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCSServices/WIDESEAWCS_TaskInfoService/WriteLog.cs 182 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WCSServices/WIDESEAWCS_Tasks/二期线体/ConveyorLineJob2.cs 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ÏîÄ¿´úÂë/WCSServices/WIDESEAWCS_Server/Controllers/Task/TaskController.cs
@@ -13,6 +13,7 @@
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_TaskInfoService;
using WIDESEAWCS_Tasks;
using WIDESEAWCS_Tasks.DBNames;
@@ -91,14 +92,18 @@
                    }
                    else
                    {
                        Thread.Sleep(500);
                        CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                        string PickBarCode = commonConveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_PickBarCode, stationManger.StationCode).Trim();
                        if (containerFlowDTO.ContainerCode != PickBarCode) throw new Exception($"传入料箱码{containerFlowDTO.ContainerCode},输送料箱码{PickBarCode}数据错误");
                        if (containerFlowDTO.Direction == "100")
                        int W_PickToHode = commonConveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.W_PickToHode, stationManger.StationDeviceCode);
                        if (containerFlowDTO.Direction == "100" && W_PickToHode == 300)
                        {
                            WebResponseContent responseContent = Service.ContainerFlow(containerFlowDTO, stationManger.StationDeviceCode, stationManger.PickStationCode);
                            if (!responseContent.Status) throw new Exception(responseContent.Message);
                        }
                        WriteLog.Write_Log($"容器流动{stationManger.StationCode}", $"输送线信息", "开始入库", $"状态{containerFlowDTO.Direction},料箱码{containerFlowDTO.ContainerCode}");
                        commonConveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)containerFlowDTO.Direction.ObjToInt(), stationManger.StationCode);
                    }
                    content.OK();
ÏîÄ¿´úÂë/WCSServices/WIDESEAWCS_Server/Log/ÈÝÆ÷Èë¿â´´½¨ÈÎÎñ/2026-01-27/ÈÎÎñÐÅÏ¢260127.txt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,5 @@
2026/1/27 11:36:07.534
开始入库
"托盘号string"
-------------------------------
ÏîÄ¿´úÂë/WCSServices/WIDESEAWCS_TaskInfoService/InvokeAGVService.cs
@@ -113,7 +113,7 @@
        /// <summary>
        /// AGV状态查询调用及WMS故障上报
        /// </summary>
        public void AgvSearchStatus() // 1原来和2更新任务
        public void AgvSearchStatus()
        {
            try
            {
ÏîÄ¿´úÂë/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -200,6 +200,7 @@
            WebResponseContent content = new WebResponseContent();
            try
            {
                WriteLog.Write_Log("容器入库创建任务", $"输送线信息", "开始入库", $"托盘号{containerFlowDTO.ContainerCode},设备{deviceCode}");
                List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData();
                Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == containerFlowDTO.ContainerCode);
                if (locationInfo != null) throw new Exception($"库位料箱号{containerFlowDTO.ContainerCode}已存在");
@@ -221,13 +222,14 @@
                    _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { taskOld.TaskNum }, $"{oldSlotCode}换至{containerFlowDTO.SlotCode}入库");
                    return content.OK();
                }
                else if(taskOld != null)
                else if (taskOld != null)
                {
                    throw new Exception($"料箱号{containerFlowDTO.ContainerCode}" + (taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "入库AGV执行中": "出库AGV执行中"));
                    throw new Exception($"料箱号{containerFlowDTO.ContainerCode}" + (taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "入库AGV执行中" : "出库AGV执行中"));
                }
                Dt_LocationInfo? noInLocation = locationInfos.FirstOrDefault(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt());
                if (noInLocation == null) throw new Exception($"可用货位不足!");
                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode);
                WriteLog.Write_Log("容器入库创建任务", $"站台信息", "查询站台", $"站台号{stationManger.StationCode},设备{stationManger.StationDeviceCode}");
                //创建任务
                Dt_Task task = new Dt_Task();
                task.PalletCode = containerFlowDTO.ContainerCode;
@@ -242,7 +244,8 @@
                task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt();
                
                //添加任务
                BaseDal.AddData(task);
                int taskId = BaseDal.AddData(task);
                WriteLog.Write_Log("容器入库创建任务", $"任务信息", "创建入库", $"任务号:{taskId},托盘编号:{task.PalletCode}");
                if (type > 0)
                {
                    _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "手动按钮入库");
@@ -255,6 +258,7 @@
            }
            catch (Exception ex)
            {
                WriteLog.Write_Log("容器入库创建任务", $"任务", "创建入库", $"失败:{ex.Message}");
                content.Error($"错误信息:{ex.Message}");
            }
            return content;
ÏîÄ¿´úÂë/WCSServices/WIDESEAWCS_TaskInfoService/WriteLog.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,182 @@
using Newtonsoft.Json;
namespace WIDESEAWCS_TaskInfoService
{
    public class WriteLog
    {
        private int fileSize;
        private string logFileName;
        public static WriteLog log;
        static string EquipName;
        public static WriteLog GetLog(string equipName)
        {
            EquipName = equipName;
            //if (log == null)
            log = new WriteLog(equipName);
            log.FileLogPath = AppContext.BaseDirectory + "\\log\\" + DateTime.Now.ToString("yyyyMMdd") /*+ "\\" + EquipName + "_" + DateTime.Now.ToString("yyyyMMdd")*/ + "\\";
            return log;
        }
        public static WriteLog Info(string equipName)
        {
            EquipName = equipName;
            //if (log == null)
            log = new WriteLog("Info" + equipName);
            log.FileLogPath = AppContext.BaseDirectory + "\\log\\Info\\" + DateTime.Now.ToString("yyyyMMdd") /*+ "\\" + EquipName + "_" + DateTime.Now.ToString("yyyyMMdd")*/ + "\\";
            return log;
        }
        public static WriteLog Error(string equipName)
        {
            EquipName = equipName;
            //if (log == null)
            log = new WriteLog("Error" + equipName);
            log.FileLogPath = AppContext.BaseDirectory + "\\log\\Error\\" + DateTime.Now.ToString("yyyyMMdd") /*+ "\\" + EquipName + "_" + DateTime.Now.ToString("yyyyMMdd")*/ + "\\";
            return log;
        }
        private WriteLog(string equipName)
        {
            //初始化大于399M日志文件将自动删除;
            this.fileSize = 2048 * 1024 * 200;//50M   2048 * 1024 * 200= 419430000字节(b)=399.9996185兆字节(mb)
            //默认路径
            //this.FileLogPath = AppContext.BaseDirectory + "\\log\\" + EquipName + "\\";
            EquipName = equipName;
            if (!string.IsNullOrEmpty(equipName))
                this.logFileName = equipName + "_log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
            else
                this.logFileName = "log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
            //this.logFileName = EquipName + "_log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
        }
        public int FileSize
        {
            set
            {
                fileSize = value;
            }
            get
            {
                return fileSize;
            }
        }
        public string FileLogPath { set; get; } //= AppContext.BaseDirectory + "\\log\\" + EquipName + "\\";
        public string LogFileName
        {
            set
            {
                this.logFileName = value;
            }
            get
            {
                return this.logFileName;
            }
        }
        object flag = new object();
        public void Write(string Message, string equipName)
        {
            lock (flag)
            {
                if (!string.IsNullOrEmpty(equipName))
                    this.logFileName = equipName + "_log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
                else
                    this.logFileName = "log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
                this.Write(this.logFileName, Message, equipName);
            }
        }
        public void Write(string LogFileName, string Message, string equipName)
        {
            //DirectoryInfo path=new DirectoryInfo(LogFileName);
            //如果日志文件目录不存在,则创建
            if (!Directory.Exists(this.FileLogPath))
            {
                Directory.CreateDirectory(this.FileLogPath);
            }
            FileInfo finfo = new FileInfo(this.FileLogPath + LogFileName);
            if (finfo.Exists && finfo.Length > fileSize)
            {
                finfo.Delete();
            }
            try
            {
                FileStream fs = new FileStream(this.FileLogPath + LogFileName, FileMode.Append);
                StreamWriter strwriter = new StreamWriter(fs);
                try
                {
                    DateTime d = DateTime.Now;
                    strwriter.WriteLine("时间:" + d.ToString());
                    strwriter.WriteLine(Message);
                    //strwriter.WriteLine();
                    strwriter.Flush();
                }
                catch (Exception ee)
                {
                    //Console.WriteLine("日志文件写入失败信息:" + ee.ToString());
                }
                finally
                {
                    strwriter.Close();
                    strwriter = null;
                    fs.Close();
                    fs = null;
                }
            }
            catch (Exception ee)
            {
                //Console.WriteLine("日志文件没有打开,详细信息如下:");
            }
        }
        /// <summary>
        /// å†™å…¥æ—¥å¿—(不要多线程操作同一文件,一个设备一个文件夹)
        /// </summary>
        /// <param name="groupName">日志组</param>
        /// <param name="logName">日志名称</param>
        /// <param name="content">内容</param>
        /// <param name="data">数据</param>
        public static void Write_Log(string groupName, string logName, string content, object data = null)
        {
            DateTime nowTime = DateTime.Now;
            string basePath = System.Environment.CurrentDirectory + "/Log/" + $"/{groupName}/{nowTime.ToString("yyyy-MM-dd")}";
            //如果日志文件目录不存在,则创建
            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }
            try
            {
                FileStream fs = new FileStream(basePath + "/" + logName + $"{nowTime.ToString("yyMMdd")}.txt", FileMode.Append);
                StreamWriter strwriter = new StreamWriter(fs);
                try
                {
                    strwriter.WriteLine(nowTime.ToString() + "." + nowTime.Millisecond);
                    strwriter.WriteLine(content);
                    if (data != null)
                    {
                        strwriter.WriteLine(JsonConvert.SerializeObject(data));
                    }
                    strwriter.WriteLine("-------------------------------");
                    strwriter.WriteLine();
                    strwriter.Flush();
                }
                catch { }
                finally
                {
                    strwriter.Close();
                    fs.Close();
                }
            }
            catch { }
        }
    }
}
ÏîÄ¿´úÂë/WCSServices/WIDESEAWCS_Tasks/¶þÆÚÏßÌå/ConveyorLineJob2.cs
@@ -18,6 +18,7 @@
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_TaskInfoService;
namespace WIDESEAWCS_Tasks
{
@@ -72,6 +73,7 @@
                                        WriteError(conveyorLine.DeviceCode, $"{station.PickStationCode}拣选申请上报WMS错误{PickBarCode},信息{content.Message}");
                                    }
                                    //写入拣选确认
                                    WriteLog.Write_Log("二期输送线拣选写入", $"{station.StationCode}", "二期输送线拣选写入", $"W_PickToHode写入PLC信号:300");
                                    conveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)300, station.StationCode);
                                }
                                else
@@ -81,9 +83,11 @@
                            }
                            //按钮申请
                            bool DownRequest = conveyorLine.GetValue<ConveyorLineDBName, bool>(ConveyorLineDBName.R_DownRequest, station.StationCode);
                            if (DownRequest)
                            int W_PickToHode = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.W_PickToHode, station.StationCode);
                            if (DownRequest && W_PickToHode == 300)
                            {
                                string PickBarCode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_PickBarCode, station.StationCode).Trim();
                                WriteInfo(conveyorLine.DeviceCode, $"申请入库{PickBarCode},站台:{station.StationCode}");
                                //上报WMS料箱到达
                                if (PickBarCode.IsNotEmptyOrNull())
                                {
@@ -93,9 +97,12 @@
                                        ContainerCode = PickBarCode,
                                        Direction="100"
                                    };
                                    WriteInfo(conveyorLine.DeviceCode, $"任务构建完成SlotCode: {containerFlowDTO.SlotCode}, ContainerCode: {containerFlowDTO.ContainerCode}");
                                    WebResponseContent responseContent = _taskService.ContainerFlow(containerFlowDTO, station.StationDeviceCode, station.PickStationCode,1);
                                    if (responseContent.Status)
                                    {
                                        WriteLog.Write_Log("二期输送线拣选写入", $"{station.StationCode}", "二期输送线拣选写入", $"W_PickToHode写入PLC信号:{containerFlowDTO.Direction}");
                                        WriteInfo(conveyorLine.DeviceCode, $"写入PLC信号W_PickToHode: {containerFlowDTO.Direction},站台:{station.StationCode}");
                                        conveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)containerFlowDTO.Direction.ObjToInt(), station.StationCode);
                                    }
                                    else
@@ -107,7 +114,6 @@
                                {
                                    WriteError(conveyorLine.DeviceCode, $"{station.PickStationCode}按钮申请为{DownRequest}条码为空值");
                                }
                            }
                        }
@@ -120,6 +126,8 @@
                            if (InRequest && !InResponse && InWeight>0)
                            {
                                string InBarCode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_InBarCode, station.StationCode).Trim();
                                WriteInfo(conveyorLine.DeviceCode, $"站台{station.StationCode}料箱{InBarCode}申请入库成功");
                                WriteLog.Write_Log("二期输送线拣选写入", $"{station.StationCode}", $"站台{station.StationCode}", $"料箱{InBarCode}申请入库成功");
                                //料箱到达
                                if (InBarCode.IsNotEmptyOrNull())
                                {
@@ -127,9 +135,8 @@
                                    WebResponseContent content =_taskService.RequestInTask(station.StationCode,InBarCode);
                                    if (content.Status)
                                    {
                                        //写入入库确认
                                        conveyorLine.SetValue(ConveyorLineDBName.W_InResponse, true, station.StationCode);
                                        WriteInfo(conveyorLine.DeviceCode, $"站台{station.StationCode}料箱{InBarCode}申请入库成功");
                                        WriteLog.Write_Log("二期输送线拣选写入", $"{station.StationCode}", $"写入确定{ConveyorLineDBName.W_InResponse}", $"料箱{InBarCode}");
                                        conveyorLine.SetValue(ConveyorLineDBName.W_InResponse, true, station.StationCode);
                                    }
                                    else
                                    {