wangxinhui
2024-09-23 a3eb67538c4716aef9967f1e6301720cce095e3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using Microsoft.EntityFrameworkCore;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Common.LoctionEnum;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_WCS.JobsPart.Public;
using WIDESEA_WCS.WCSClient;
using static FreeSql.Internal.GlobalFilter;
 
namespace WIDESEA_WCS.SchedulerExecute.AGV
{  
    public partial class AGVSchedulerExecute
    {
        /// <summary>
        /// 辊分下料缓存架良品料自动搬运极库
        /// </summary>
        public static async void AgvAndEquiWorkZJ()
        {   
            WebResponseContent content = new WebResponseContent();
            VOLContext Context = new VOLContext();
            Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
            Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
            Ibase_ware_locationRepository ibase_Ware_Location = new base_ware_locationRepository(Context);
 
            List<base_ware_location> ware_Locatiolist = ibase_Ware_Location.Find(d => d.upper_code.Contains("GFHCJ")&&d.logic_col==1&&d.task==2 && d.status == 1&& d.geartype != "暂无").ToList();
 
            //if (ware_Locatio == null)
            //{
            //    return ;
            //}
            foreach (var listloction in ware_Locatiolist)
            {
            List<base_ware_location> gfloction = new List<base_ware_location>();
            List<base_routing_table> routing_table = routingRepository.Find(v => v.route_began == listloction.upper_code).ToList();
            if (routing_table.Count > 0)
            {
                foreach (var item in routing_table)
                {
                    base_ware_location ware_Location = ibase_Ware_Location.FindFirst(d => d.upper_code == item.route_end && d.location_state == LoctionStateEnum.LocationState_Empty.ToString() && d.logic_col == 0 && d.tpgd == 0 && d.status == 1 && d.task == 2 && d.geartype== "暂无");
                    if (ware_Location != null)
                    {
                        gfloction.Add(ware_Location);
                    }
                }
                if (gfloction.Count > 0)
                {
                    base_ware_location ware_Locatio = ibase_Ware_Location.FindFirst(d => d.upper_code == listloction.upper_code);
                        if (ware_Locatio == null) { continue; }
                    base_ware_location lotion = gfloction.OrderBy(d => d.order_num).FirstOrDefault();
                    dt_agvtask agvtask = new dt_agvtask
                    {
                        agv_id = Guid.NewGuid(),
                        agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
                        agv_fromaddress = ware_Locatio.upper_code,
                        agv_toaddress = lotion.upper_code,
                        agv_code = "组装AGV调度",
                        agv_remark = "辊分下料呼叫",
                        agv_taskstate = AGVTaskStateEnum.Create.ToString(),
                        agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
                        agv_worktype = 1,//工作类型
                        agv_materielid = "",
                        agv_qty = 1,
                        agv_createtime = DateTime.Now,
                        agv_grade = 0,//任务优先级
                        agv_userid = "WCS",
                        agv_barcode = ""
                    };
                    listloction.update_time = DateTime.Now;
                    ware_Locatio.logic_col = 1;//设置良品物料
                    ware_Locatio.task = 1;//设置任务生成1
                    ware_Locatio.light_color = "无";
                    var entrys = ibase_Ware_Location.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                    if (entrys != null)
                    {
                        entrys.State = EntityState.Detached;
                    }
                  int begin=  ibase_Ware_Location.Update(ware_Locatio, d => new { d.logic_col, d.task, d.update_time, d.light_color }, true);
 
                    lotion.update_time = DateTime.Now;
                    lotion.logic_col = 1;
                    lotion.task = 1;
                    lotion.geartype = ware_Locatio.geartype;
                    var entry = ibase_Ware_Location.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                    if (entry != null)
                    {
                        entry.State = EntityState.Detached;
                    }
                  int end= ibase_Ware_Location.Update(lotion, d => new { d.logic_col, d.task, d.update_time, d.geartype }, true);
                    if (begin==1&&end==1)
                    {
                        agvRepository.Add(agvtask, true);//任务生成
                        WriteDBLog.Info($"辊分到极库任务生成").Write($"生成任务:{agvtask.agv_tasknum}", $"辊分到极库任务生成");
                        WriteDBLog.Info($"辊分到极库任务生成").Write($"起点货位【{ware_Locatio.upper_code}】状态:托盘光电检测:{ware_Locatio.tpgd},-1光电:{ware_Locatio.gd2},-2光电:{ware_Locatio.gd1},-3光电:{ware_Locatio.gd4},-4光电:{ware_Locatio.gd3},状态:{ware_Locatio.location_state},更新时间:{ware_Locatio.wireless_time}", $"辊分到极库任务生成");
                        WriteDBLog.Info($"辊分到极库任务生成").Write($"终点货位【{lotion.upper_code}】状态:托盘光电检测:{lotion.tpgd},状态:{lotion.location_state},更新时间:{lotion.wireless_time}", $"辊分到极库任务生成");
                        WriteDBLog.Info($"辊分到极库任务生成").Write($"----------------任务生成成功  {DateTime.Now} -------------- {Environment.NewLine}", $"辊分到极库任务生成");
                        return;
                    }
                }
            }
            }
        }
    }
}