分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-03-14 73a926018601d9a5a5a3d3f4c051537f45a8eff4
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs
@@ -10,6 +10,7 @@
using WIDESEA_Entity.DomainModels;
using WIDESEA_Comm;
using static System.Collections.Specialized.BitVector32;
using WIDESEA_Comm.TaskNo;
namespace WIDESEA_WCS.JobsPart.Common
{
@@ -17,73 +18,107 @@
    {
        static FreeDB freeDB = new FreeDB();
        /// <summary>
        /// åˆ›å»ºå…¥åº“任务
        /// </summary>
        public static void CreateTask()
        {
            VOLContext context = new VOLContext();
            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
            Idt_WorkinfoRepository workinfoRepository = new dt_WorkinfoRepository(context);
            List<dt_stationinfo> stationinfos = stationinfoRepository.Find(x => x.stationCode.Contains('X'));
            foreach (var item in stationinfos)
            try
            {
                //根据下料口的绑定信息查询对应工单,检测此工单是否已完成  å®Œæˆå³å¯å°†å…¶é€å…¥åº“
                VOLContext context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                Idt_WorkinfoRepository workinfoRepository = new dt_WorkinfoRepository(context);
                dt_mes_head mesinfo = freeDB.Select<dt_mes_head>().Where(x => x.jobID == item.Number).First();
                dt_geometry_data dt_Geometry_Data = freeDB.Select<dt_geometry_data>().Where(x => x.Description == mesinfo.drawingNo).First();
                int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum);
                List<dt_stationinfo> stationinfos = freeDB.Select<dt_stationinfo>().Where(x => x.stationCode.Contains("X") && x.quantity > 0 && !string.IsNullOrEmpty(x.stationType)).ToList();
                //判定任务是否已创建//如已存在
                if (freeDB.Select<dt_agvtask>().Where(x => x.agv_fromaddress == item.stationCode).Count() > 0)
                    continue;
                if (item.quantity == 5 || CompeletedNum == 0)  //循环读取车轮数为5或者订单已完成数量的下料口    â†’工单人工关闭的工单
                foreach (var item in stationinfos)
                {
                    //根据下料口的绑定信息查询对应工单,检测此工单是否已完成  å®Œæˆå³å¯å°†å…¶é€å…¥åº“
                    dt_mes_head mesinfo = freeDB.Select<dt_mes_head>().Where(x => x.jobID == item.Number).First();
                    dt_geometry_data dt_Geometry_Data = freeDB.Select<dt_geometry_data>().Where(x => x.Description == mesinfo.drawingNo).First();
                    int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum);
                    if (mesinfo.quantity <= 50 || item.stationCode.Contains("3"))    //小于50件直接出库
                    //判定任务是否已创建//如已存在
                    if (freeDB.Select<dt_agvtask>().Where(x => x.agv_fromaddress == item.stationCode).Count() > 0)
                        continue;
                    if (item.quantity == 5 || CompeletedNum == 0)  //循环读取车轮数为5或者订单已完成数量的下料口    â†’工单人工关闭的工单
                    {
                        //var station =
                        //todo å¯»æ‰¾å¯æ”¾è´§å¤–协放货台
                        dt_agvtask agvtask = new dt_agvtask()
                        {
                            agv_fromaddress = item.stationCode,
                            agv_id = Guid.NewGuid(),
                            agv_grade = 0,
                            agv_barcode = "",
                            agv_createtime = DateTime.Now,
                            agv_taskstate = TaskStatus.Created.ToString(),
                            //agv_toaddress = ,
                        };
                        freeDB.Add(agvtask);
                    }
                    else
                    {
                        dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item, CompeletedNum, dt_Geometry_Data.e);
                        if (TargetLocation != null)
                        if (mesinfo.quantity <= 50 || item.stationCode.Contains("3"))    //小于50件直接出库
                        {
                            //todo:  è°ƒç”¨WMS接口创建任务
                            dt_agvtask agvtask = new dt_agvtask()
                            dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository);
                            //todo å¯»æ‰¾å¯æ”¾è´§å¤–协放货台
                            if (TargetLocation != null)
                            {
                                agv_fromaddress = item.stationCode,
                                agv_id = Guid.NewGuid(),
                                agv_grade = 0,
                                agv_barcode = "",
                                agv_createtime = DateTime.Now,
                                agv_taskstate = TaskStatus.Created.ToString(),
                                agv_toaddress = TargetLocation.stationCode,
                            };
                                dt_agvtask agvtask = new dt_agvtask()
                                {
                                    agv_fromaddress = item.stationCode,
                                    agv_id = Guid.NewGuid(),
                                    agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                                    agv_grade = 1,
                                    agv_createtime = DateTime.Now,
                                    agv_taskstate = "Create",
                                    agv_materielid = item.stationType,
                                    agv_qty = item.quantity,
                                    agv_tasktype = "TaskType_OutsourceInbound",
                                    agv_toaddress = TargetLocation.stationCode,
                                    agv_userid = "系统",
                                    bindSN = item.bindSN,
                                    agv_worktype = Convert.ToInt32(mesinfo.processCode),
                                    agv_materbarcode = mesinfo.materialCode,
                                    agv_Traytype = item.tray_type,
                                    agv_TrayStatus = item.tray_status
                                };
                            freeDB.Add(agvtask);
                            TargetLocation.location_state = LocationStateEnum.Busy.ToString();
                            freeDB.Update(TargetLocation);
                                freeDB.Add(agvtask);
                                TargetLocation.location_state = LocationStateEnum.Busy.ToString();
                                freeDB.Update(TargetLocation);
                            }
                        }
                        else
                        {
                            dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item, CompeletedNum, dt_Geometry_Data.e);
                            if (TargetLocation != null)
                            {
                                //todo:  è°ƒç”¨WMS接口创建任务
                                dt_agvtask agvtask = new dt_agvtask()
                                {
                                    agv_fromaddress = item.stationCode,
                                    agv_id = Guid.NewGuid(),
                                    agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                                    agv_grade = 1,
                                    agv_createtime = DateTime.Now,
                                    agv_taskstate = "Create",
                                    agv_materielid = item.stationType,
                                    agv_qty = item.quantity,
                                    agv_tasktype = "TaskType_Inbound",
                                    agv_toaddress = TargetLocation.stationCode,
                                    agv_userid = "系统",
                                    bindSN = item.bindSN,
                                    agv_worktype = Convert.ToInt32(mesinfo.processCode),
                                    agv_materbarcode = mesinfo.materialCode,
                                    agv_Traytype = item.tray_type,
                                    agv_TrayStatus = item.tray_status
                                };
                                freeDB.Add(agvtask);
                                TargetLocation.location_state = LocationStateEnum.Busy.ToString();
                                freeDB.Update(TargetLocation);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        /// <summary>
@@ -248,6 +283,22 @@
            return TargetLocation;
        }
        private static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository)
        {
            dt_stationinfo TargetLocation = null;
            List<string> target = new List<string>() { "W01001001", "W01001002", "W01001003" };
            foreach (var item in target)
            {
                TargetLocation = stationinfoRepository.FindFirst(x => x.stationCode == item && x.location_state == LocationStateEnum.Empty.ToString() && x.enable);
                if (TargetLocation != null) continue;
            }
            if (TargetLocation == null)
            {
                throw new Exception("外协入库口已满");
            }
            return TargetLocation;
        }
        /// <summary>
        /// æ ¹æ®è®¢å•数量返回库区(暂时弃用)   //更换为库位类型匹配
        /// </summary>