分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-01-31 50fd5cc9cfad08714c4daa6d481c5293ff2ae6b1
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
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 = Guid.Empty,
                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 = DateTime.Now,
                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_barcode = task.agv_barcode,
                agv_code = task.agv_code,
                agv_worktype = task.agv_worktype,
                agv_remark = task.agv_remark
            };
            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(",");
            if (bindSNs.Length > 0)
            {
                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,//待完善
                    };
                    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.tray_status = station1.tray_status;
            stationinfoRepository.Update(station2, true);
 
            station1.quantity = 0;
            station1.bindSN = string.Empty;
            station1.location_state = LocationStateEnum.Empty.ToString();
            station1.tray_status = string.Empty;
            stationinfoRepository.Update(station1, true);
        }
    }
}