分支自 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Common;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.FreeDB;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
 
namespace WIDESEA_WMS.Common
{
    public class HandleTask
    {
        public static FreeDB freeDB = new FreeDB();
        /// <summary>
        /// 添加历史任务
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="operatetype">操作类型</param>
        public static void AddHtyTask(dt_agvtask task, string operatetype = "Complete", string compeletor = "AGV")
        {
            VOLContext context = new VOLContext();
            Idt_agvtask_htyRepository htyRepository = new dt_agvtask_htyRepository(context);
            Idt_agvtaskRepository repository = new dt_agvtaskRepository(context);
            dt_agvtask_hty agvtask_Hty = new dt_agvtask_hty()
            {
                hty_pkid = Guid.NewGuid(),
                agv_id = task.agv_id,
                agv_tasknum = task.agv_tasknum,
                agv_materielid = task.agv_materielid,
                agv_qty = task.agv_qty,
                agv_createtime = task.agv_createtime,
                agv_realesstime = task.agv_realesstime,
                agv_executingBeginTime = task.agv_executingBeginTime,
                agv_executingEndTime = task.agv_executingEndTime,
                agv_completeBeginTime = task.agv_completeBeginTime,
                agv_finishedtime = task.agv_finishedtime,
                agv_taskstate = task.agv_taskstate,
                agv_tasktype = task.agv_tasktype,
                agv_fromaddress = task.agv_fromaddress,
                agv_toaddress = task.agv_toaddress,
                agv_operatetype = operatetype,
                agv_compeletor = compeletor,
                agv_completedate = DateTime.Now,
                agv_grade = task.agv_grade,
                agv_userid = task.agv_userid,
                agv_Traytype = task.agv_Traytype,
                agv_TrayStatus = task.agv_TrayStatus,
                agv_worktype = task.agv_worktype,
                agv_remark = task.agv_remark,
                bindSN = task.bindSN,
                agv_materbarcode = task.agv_materbarcode,
            };
            htyRepository.Add(agvtask_Hty, true);
            repository.Delete(task, true);
        }
        /// <summary>
        /// 库存处理
        /// </summary>
        /// <param name="task"></param>
        public static void Updateinventory(dt_agvtask task)
        {
            string[] bindSNs = task.bindSN.Split(",");
            int count = 0;
            if (bindSNs.Length > 0)
            {
                if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Outbound.ToString() || task.agv_tasktype == AGVTaskTypeEnum.TaskType_OutsourceCarry.ToString())
                {
                    foreach (var bindSN in bindSNs)
                    {
                        //List<dt_inventory> inventorys = new List<dt_inventory>();
                        var inventory = freeDB.Select<dt_inventory>().Where(x => x.SN == bindSN).First();
                        //inventorys.Add(inventory);
                        count = freeDB.Remove(inventory);
                        if (count < 1)
                            throw new Exception("库存清除失败!SN号:" + bindSN);
                    }
 
                }
                else if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Inbound.ToString())
                {
                    List<dt_inventory> inventorys = new List<dt_inventory>();
                    foreach (string bindSN in bindSNs)
                    {
                        var mes_detail = freeDB.Select<dt_mes_detail>().Where(x => x.SN == bindSN).First();
                        var mes_head = freeDB.Select<dt_mes_head>().Where(x => x.jobID == mes_detail.jobID).First();
                        var station = freeDB.Select<dt_stationinfo>().Where(x => x.stationCode == task.agv_toaddress).First();
                        dt_inventory inventory = new dt_inventory()
                        {
                            SN = bindSN,
                            Name = mes_head.productName,
                            FigureNumber = mes_head.drawingNo,
                            //HearthNumber = "",
                            HeatNumber = mes_detail.heatID,
                            BilletNumber = mes_detail.billetID,
                            OnlineTime = task.agv_finishedtime,
                            Operator = "admin",
                            stationCode = task.agv_toaddress,
                            area = station.area,
                            jobID = mes_detail.jobID,
                            ID = Guid.NewGuid()
                        };
                        inventorys.Add(inventory);
                    }
                    count = freeDB.AddRange(inventorys);
                    if (count < 1)
                        throw new Exception("库存添加失败!库位号:" + task.agv_toaddress);
                }
 
                //var Materiel = QueryData.QueryMateriel(task.agv_materielid);
                //List<dt_inventory> inventorys = new List<dt_inventory>();
                //foreach (string bindSN in bindSNs)
                //{
                //    dt_inventory inventory = new dt_inventory()
                //    {
                //        SN = bindSN,//待完善
                //        Name = "",
                //        FigureNumber = "",
                //        //HearthNumber = "",
                //        HeatNumber = "",
                //        //BilletNumber=,
                //        OnlineTime = task.agv_finishedtime,
                //        Operator = "admin",
                //        stationCode = task.agv_toaddress,
                //        area = "",
                //        jobID = "",
                //    };
                //    inventorys.Add(inventory);
                //}
                //if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Inbound.ToString() || task.agv_tasktype == AGVTaskTypeEnum.TaskType_OutsourceInbound.ToString())
                //    freeDB.AddRange(inventorys);
                //else if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Outbound.ToString() || task.agv_tasktype == AGVTaskTypeEnum.TaskType_OutsourceOutbound.ToString())
                //    freeDB.Remove(inventorys);
            }
        }
 
        /// <summary>
        /// 自动更新缓存架状态
        /// </summary>
        /// <param name="task"></param>
        public static void AutoUpdateHCJState(dt_agvtask task)
        {
            VOLContext context = new VOLContext();
            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
            var station1 = stationinfoRepository.FindFirst(t => t.stationCode == task.agv_fromaddress);
            var station2 = stationinfoRepository.FindFirst(t => t.stationCode == task.agv_toaddress);
 
            station2.quantity = station1.quantity;
            station2.bindSN = station1.bindSN;
            station2.location_state = LocationStateEnum.Stroge.ToString();
            station2.Number = task.jobID;
            station2.heatNumber = station1.heatNumber;
            station2.stationType = station1.stationType;
            station2.tray_status = station1.tray_status;//横放/竖放
            stationinfoRepository.Update(station2, true);
 
            station1.quantity = 0;
            station1.bindSN = string.Empty;
            station1.location_state = LocationStateEnum.Empty.ToString();
            station1.Number = string.Empty;
            station1.heatNumber = string.Empty;
            station1.stationType = string.Empty;
            station1.tray_status = LocationStateEnum.Empty.ToString();
            stationinfoRepository.Update(station1, true);
        }
    }
}