分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-03-14 73a926018601d9a5a5a3d3f4c051537f45a8eff4
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
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Comm.TaskNo;
using WIDESEA_Core.FreeDB;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.JobsPart.Common.存储过程;
using static FreeSql.Internal.GlobalFilter;
using static System.Collections.Specialized.BitVector32;
 
namespace WIDESEA_WCS.JobsPart.Common
{
    public class ReplaceTray
    {
        static FreeDB freeDB = new FreeDB();
 
        public static void a()
        {
            var mes_Detail = freeDB.Select<dt_mes_detail>().Where(x => x.SN == "1202956016").First();
            var mes_Head = freeDB.Select<dt_mes_head>().Where(x => x.jobID == mes_Detail.jobID).First();
 
            dt_inventory inventory = new dt_inventory()
            {
                SN = mes_Detail.SN,
                Name = mes_Head.productName,
                FigureNumber = mes_Head.drawingNo,
                area = "2",
                HeatNumber = mes_Detail.heatID,
                BilletNumber = mes_Detail.billetID,
                OnlineTime = DateTime.Now,
                Operator = "AGV",
                stationCode = "B01001001",
                jobID = mes_Detail.jobID,
                ID = Guid.NewGuid(),
                remark=""
            };
            StoredProcedure.EXEC( inventory,"");
        }
        /// <summary>
        /// 创建更换托盘任务
        /// </summary>
        public static void ReplaceTrayTask()
        {
            try
            {
                var stations = freeDB.Select<dt_stationinfo>().Where(x => x.stationCode.Contains("X") && x.location_state == LocationStateEnum.Abnormal.ToString() && (x.tray_type == "SmallTray/LargeTray" || x.tray_type == "LargeTray/SmallTray")).ToList();
                foreach (var station in stations)
                {
                    var types = station.tray_type.Split('/');
                    var area = types[0] == "SmallTray" ? "11" : "10";
                    //找1库区的空托位
 
                    var EmptyStation = freeDB.Select<dt_stationinfo>().Where(x => x.area == area && x.stationCode.Contains("A") && x.location_state == "Empty" && x.enable)
                        .OrderBy(x => x.column).OrderByDescending(x => x.line).First();
                    if (EmptyStation == null)
                        EmptyStation = freeDB.Select<dt_stationinfo>().Where(x => x.area == area && x.stationCode.Contains("C") && x.location_state == "Empty" && x.enable)
                        .OrderBy(x => x.line).OrderBy(x => x.column).First();
                    if (EmptyStation != null)
                    {
                        dt_agvtask agvtask = new dt_agvtask()
                        {
                            agv_fromaddress = station.stationCode,
                            agv_id = Guid.NewGuid(),
                            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                            agv_grade = 2,
                            agv_createtime = DateTime.Now,
                            agv_taskstate = "Create",
                            //agv_materielid = station.stationType,
                            agv_qty = 1,
                            agv_tasktype = "TaskType_EmptyPallet",
                            agv_toaddress = EmptyStation.stationCode,
                            agv_userid = "系统",
                            agv_TrayStatus = station.tray_status,
                            //bindSN = station.bindSN,
                            //agv_worktype = Convert.ToInt32(mesinfo.processCode),
                            //agv_materbarcode = mesinfo.materialCode,
                            agv_Traytype = types[0]
                        };
                        freeDB.Add(agvtask);
                        CreatePartQueue(agvtask, types[1]);
                    }
                }
            }
            catch (Exception ex)
            {
 
                throw;
            }
        }
        /// <summary>
        /// 创建完整的补空托任务
        /// </summary>
        /// <param name="agvtask"></param>
        public static void CreatePartQueue(dt_agvtask agvtask, string type = "")
        {
            if (agvtask.agv_fromaddress.Contains("X"))
            {
                dt_agvtask taskPart = new dt_agvtask()
                {
                    agv_fromaddress = "",
                    agv_id = Guid.NewGuid(),
                    agv_tasknum = agvtask.agv_tasknum + "_1",
                    agv_grade = 2,
                    agv_createtime = DateTime.Now,
                    agv_taskstate = "Queue",
                    agv_qty = 1,
                    agv_tasktype = "TaskType_EmptyPallet",
                    agv_toaddress = agvtask.agv_fromaddress,
                    agv_userid = "系统",
                    agv_TrayStatus = agvtask.agv_TrayStatus,
                    agv_Traytype = type
                };
                freeDB.Add(taskPart);
            }
        }
    }
}