dengjunjie
2025-02-17 2bdad959bc30a7c24bf08ca81fb52fff63e79f52
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ProductionLineJob/ProductionLineExtend/ProductionLineExtend.cs
@@ -1,9 +1,16 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.WMSInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_Tasks.ProductionLineJob;
namespace WIDESEAWCS_Tasks
@@ -11,17 +18,198 @@
    public partial class CommonProductionLineJob
    {
        /// <summary>
        /// äº§çº¿
        /// å…¥åº“产线
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <returns></returns>
        public List<Task> ProductionLineExtend(OtherDevice ProductionLine)
        public void ProductionLineIn(OtherDevice ProductionLine)
        {
            foreach (var item in ProductionLine.DeviceProDTOs.GroupBy(x => x.DeviceChildCode))
            {
                var request = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.request, item.Key);
                if (request == 1)
                {
                    var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType, item.Key);
                    var content = Request(ProductionLine, traytype, item.Key);
            var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType);
            ProductionLine.SetValue(ProductionLineDBName.trayType, traytype);
            List<Task> tasks = new List<Task>();
            return tasks;
                    if (content.Status) ProductionLine.SetValue(ProductionLineDBName.Wrequest, 1, item.Key);
                }
            }
        }
        /// <summary>
        /// å‡ºåº“产线
        /// </summary>
        /// <param name="ProductionLine"></param>
        public void ProductionLineOut(OtherDevice ProductionLine)
        {
            foreach (var item in ProductionLine.DeviceProDTOs.GroupBy(x => x.DeviceChildCode))
            {
                var request = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.request, item.Key);
                if (request == 1)
                {
                    bool ok = false;
                    var traytype = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.trayType, item.Key);
                    if (traytype == 2 || traytype == 4 || traytype == 6)
                        ok = Request(ProductionLine, traytype, item.Key).Status;
                    else
                    {
                        var task = _taskService.QuertOutProductionLineTask(true);
                        if (task != null)
                        {
                            //if (task.Remark.ObjToInt() == traytype)
                            if (!string.IsNullOrEmpty(task.Remark) && traytype == 5)
                            {
                                task.TargetAddress = item.Key;
                                task.NextAddress = item.Key;
                                ok = _taskService.UpdateData(task).Status;
                            }
                        }
                    }
                    if (ok) ProductionLine.SetValue(ProductionLineDBName.Wrequest, 1, item.Key);
                }
            }
        }
        /// <summary>
        /// ç”³è¯·
        /// </summary>
        /// <param name="ProductionLine">产线</param>
        /// <param name="traytype">托盘类型</param>
        /// <param name="station">站台号</param>
        /// <returns></returns>
        public WebResponseContent Request(OtherDevice ProductionLine, short traytype, string station)
        {
            WebResponseContent response = new WebResponseContent();
            ProductionLineDTO MaterielGroupDTO = new ProductionLineDTO();
            try
            {
                switch (traytype)
                {
                    case 1://放空托
                    case 3://放空盒
                           //case 5://放满盒
                        {
                            MaterielGroupDTO.stationCode = station;
                            MaterielGroupDTO.traytype = traytype;
                        }
                        break;
                    case 2://取空托
                    case 4://取满盒
                    case 6://取空盒
                        {
                            MaterielGroupDTO.Barcode = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.trayBarcode, station);
                            MaterielGroupDTO.stationCode = station;
                            MaterielGroupDTO.traytype = traytype;
                            if (traytype == 4)
                            {
                                #region è¯»å–数量
                                //var productQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.productQty.ToString() && x.DeviceChildCode == station);
                                //var productQty = ProductionLine.Communicator.Read<short>(productQtyadd.DeviceProAddress, (ushort)productQtyadd.DeviceProDataLength);
                                //#endregion
                                //#region å†™å…¥æ•°é‡
                                //var WproductQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.WproductQty.ToString() && x.DeviceChildCode == station);
                                //ProductionLine.Communicator.Write(WproductQtyadd.DeviceProAddress, productQty);
                                #endregion
                                MaterielGroupDTO.batchNo = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.batchNo, station);
                                //MaterielGroupDTO.productQty = string.Join(",", productQty);
                            }
                        }
                        break;
                    #region MyRegion
                    //case 3://放空盒
                    //    {
                    //        MaterielGroupDTO.stationCode = station;
                    //        MaterielGroupDTO.traytype = traytype;
                    //    }
                    //    break;
                    //case 4://取满盒
                    //    {
                    //        //var productQty = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.productQty, station);
                    //        #region è¯»å–数量
                    //        var productQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.productQty.ToString() && x.DeviceChildCode == station);
                    //        var productQty = ProductionLine.Communicator.Read<short>(productQtyadd.DeviceProAddress, (ushort)productQtyadd.DeviceProDataLength);
                    //        #endregion
                    //        #region å†™å…¥æ•°é‡
                    //        var WproductQtyadd = ProductionLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ProductionLineDBName.WproductQty.ToString() && x.DeviceChildCode == station);
                    //        ProductionLine.Communicator.Write(WproductQtyadd.DeviceProAddress, productQty);
                    //        #endregion
                    //        var batchNo = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.batchNo, station);
                    //        var trayBarcode = ProductionLine.GetValue<ProductionLineDBName, string>(ProductionLineDBName.trayBarcode, station);
                    //        MaterielGroupDTO.batchNo = batchNo;
                    //        MaterielGroupDTO.Barcode = trayBarcode;
                    //        MaterielGroupDTO.stationCode = station;
                    //        MaterielGroupDTO.traytype = traytype;
                    //        MaterielGroupDTO.productQty = string.Join(",", productQty);
                    //    }
                    //    break;
                    //case 5://放满盒
                    //    {
                    //        MaterielGroupDTO.stationCode = station;
                    //        MaterielGroupDTO.traytype = traytype;
                    //    }
                    //    break;
                    //case 6://取空盒
                    //    {
                    //    }
                    //    break;
                    #endregion
                    default:
                        throw new Exception("未定义托盘类型");
                }
                response = ProductionLineToWMSRequest(MaterielGroupDTO);
            }
            catch (Exception ex)
            {
                response.Error(ex.Message);
            }
            return response;
        }
        public WebResponseContent ProductionLineToWMSRequest(ProductionLineDTO MaterielGroupDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var ResultData = HttpHelper.PostAsync(WMSInterfaceAddress.ProductionlineRequest, MaterielGroupDTO.ToJson(), headers: new Dictionary<string, string>());
                if (ResultData.Result == null) throw new Exception($"产线向WMS请求超时");
                content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result);
                #region äº§çº¿ç”³è¯·å…¥åº“任务
                if (content != null && content.Status)//任务转换
                {
                    var task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToJson());
                    if (task != null)
                    {
                        List<int> TaskNums = new List<int>();
                        List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.TargetAddress);
                        if (routers.Count > 0)
                        {
                            task.NextAddress = routers.FirstOrDefault().ChildPosi;
                        }
                        task.WMSId = task.TaskId;
                        task.Creater = "WMS";
                        task.Dispatchertime = null;
                        task.CreateDate = DateTime.Now;
                        content = _taskService.AddData(task);
                        TaskNums.Add(task.TaskNum);
                        _taskExecuteDetailService.AddTaskExecuteDetail(TaskNums, "接收WMS任务");
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
    }
}