wangxinhui
2 天以前 6d3ea08855337c0cfcc60df2903d3431611c7097
ÏîÄ¿´úÂë/WCSServices/WIDESEAWCS_Server/Controllers/Task/TaskController.cs
@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Text;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseController;
@@ -55,6 +56,7 @@
        {
            return Service.RollbackTaskStatusToLast(taskNum);
        }
        private static object lock_containerFlow = new object();
        /// <summary>
        /// å®¹å™¨æµåŠ¨æŽ¥å£
        /// </summary>
@@ -62,31 +64,77 @@
        [HttpPost, HttpGet, Route("ContainerFlow"), AllowAnonymous]
        public WebResponseContent ContainerFlow([FromBody] ContainerFlowDTO containerFlowDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            lock (lock_containerFlow)
            {
                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x=>x.PickStationCode==containerFlowDTO.SlotCode) ?? throw new Exception($"{containerFlowDTO.SlotCode}拣选位置不存在");
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                if (device == null)
                WebResponseContent content = new WebResponseContent();
                try
                {
                    return WebResponseContent.Instance.Error($"未找到对应设备{stationManger.StationDeviceCode}");
                    Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.PickStationCode == containerFlowDTO.SlotCode) ?? throw new Exception($"{containerFlowDTO.SlotCode}拣选位置不存在");
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                    if (device == null)
                    {
                        return WebResponseContent.Instance.Error($"未找到对应设备{stationManger.StationDeviceCode}");
                    }
                    if (stationManger.StationDeviceCode == "CL1" || stationManger.StationDeviceCode == "CL2")
                    {
                        OtherDevice commonConveyorLine = (OtherDevice)device;
                        byte[] bytesPick = commonConveyorLine.Communicator.Read("2", 5);
                        string PickBarCode = Encoding.UTF8.GetString(bytesPick).Replace("\0", "").Replace("\\0", "");
                        if (containerFlowDTO.ContainerCode != PickBarCode) throw new Exception($"传入料箱码{containerFlowDTO.ContainerCode},输送料箱码{PickBarCode}数据错误");
                        if (containerFlowDTO.Direction == "100")
                        {
                            WebResponseContent responseContent = Service.ContainerFlow(containerFlowDTO, stationManger.StationDeviceCode, stationManger.PickStationCode);
                            if (!responseContent.Status) throw new Exception(responseContent.Message);
                        }
                        commonConveyorLine.Communicator.Write("22", (containerFlowDTO.Direction == "100" ? new byte[] { 1, 0 } : new byte[] { 2, 0 }));
                    }
                    else
                    {
                        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")
                        {
                            WebResponseContent responseContent = Service.ContainerFlow(containerFlowDTO, stationManger.StationDeviceCode, stationManger.PickStationCode);
                            if (!responseContent.Status) throw new Exception(responseContent.Message);
                        }
                        commonConveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)containerFlowDTO.Direction.ObjToInt(), stationManger.StationCode);
                    }
                    content.OK();
                }
                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")
                catch (Exception ex)
                {
                    WebResponseContent responseContent = Service.ContainerFlow(containerFlowDTO, stationManger.StationDeviceCode);
                    if (!responseContent.Status) throw new Exception(responseContent.Message);
                    content.Error(ex.Message);
                }
                commonConveyorLine.SetValue(ConveyorLineDBName.W_PickToHode,(short)containerFlowDTO.Direction.ObjToInt(), stationManger.StationCode);
                content.OK();
                return content;
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// æ’­ç§å¢™åˆå§‹åŒ–
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("InitLight"), AllowAnonymous]
        public WebResponseContent InitLight()
        {
            return Service.InitLight();
        }
        /// <summary>
        /// æ’­ç§å¢™ç»“束作业
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("EndLight"), AllowAnonymous]
        public WebResponseContent EndLight()
        {
            return Service.EndLight();
        }
        /// <summary>
        /// æ’­ç§å¢™äº®ç¯
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("SendLight"), AllowAnonymous]
        public WebResponseContent SendLight([FromBody] TaskSendLight taskSendLight)
        {
            return Service.SendLight(taskSendLight);
        }
        /// <summary>
        /// ç”³è¯·å…¥åº“
@@ -107,10 +155,21 @@
        /// </summary>
        /// <param name="taskNum"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("RecWMSTaskCompleted"), AllowAnonymous]
        public WebResponseContent RecWMSTaskCompleted(int taskNum)
        [HttpPost, HttpGet, Route("RecTaskCompleted"), AllowAnonymous]
        public WebResponseContent RecTaskCompleted(int taskNum)
        {
            return Service.TaskCompleted(taskNum);
        }
        /// <summary>
        /// WMS任务取消同步
        /// </summary>
        /// <param name="taskNum"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("CancelTask"), AllowAnonymous]
        public WebResponseContent CancelTask(List<TaskCancel> taskCancels)
        {
            return WebResponseContent.Instance.Error();
        }
    }
}