分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-06-07 fdf6494705b9bcddb2e16b933b231262497fc227
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
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.LogInfo;
using WIDESEA_Comm.TaskNo;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Extensions;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Repositories;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
using static FreeSql.Internal.GlobalFilter;
using static System.Collections.Specialized.BitVector32;
 
namespace WIDESEA_WMS.Common
{
    public class OutboundTask
    {
        /// <summary>
        /// 创建出库队列任务
        /// </summary>
        public static void CreateOutboundTask()
        {
            try
            {
                VOLContext context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(context);
                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
                IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context);
 
                var Mes_Works = workinfoRepository.Find(x => x.processCode == "28").OrderByDescending(x => x.CreateTime).ToList();
                foreach (var Mes_Work in Mes_Works)
                {
                    var inventory = inventoryRepository.Find(x => x.SN == Mes_Work.SN).FirstOrDefault();
                    if (inventory != null)
                    {
                        var Station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();//查找库存货位
                        if (Station != null)
                        {
 
                            #region 
 
                            dt_stationinfo stationinfo = null;
                            //查找当前货位同行是否存在入库任务
                            if (GetStation.InBusyStation(Station.stationCode)) continue;
 
                            stationinfo = stationinfoRepository.Find(x => x.line == Station.line && x.area == Station.area && x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderByDescending(x => x.column).FirstOrDefault();
                            if (stationinfo != null)
                            {
                                if (agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).Any()) continue;
 
                                if (stationinfoRepository.Find(x => x.line == stationinfo.line && x.area == stationinfo.area && x.column > stationinfo.column && !x.enable).Any())
                                    continue;
                                if (string.IsNullOrEmpty(stationinfo.bindSN))
                                {
                                    stationinfo.remark = "车轮SN号信息异常";
                                    stationinfo.location_state = "Abnormal";
                                    stationinfoRepository.Update(stationinfo, true);
                                    continue;
                                }
 
                                if (agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).Any()) continue;
 
                                List<string> lists = new List<string>();
                                var SNS = stationinfo.bindSN.Split(",");
                                foreach (var SN in SNS)
                                {
                                    if (!string.IsNullOrEmpty(SN))
                                        lists.Add(SN);
                                }
 
                                #region 货位车轮全部包含在工单内则下发任务
                                var count = 0;
                                foreach (var SN in lists)
                                {
                                    if (workinfoRepository.Find(x => x.processCode == "28" && x.SN == SN).Any()) count++;
                                    //if (workinfoRepository.Find(x => x.processCode == "28" && x.SN.Contains(SN)).Any()) count++;
 
                                }
                                if (count != lists.Count) continue;
                                dt_agvtask agvtask = new dt_agvtask()
                                {
                                    agv_fromaddress = stationinfo.stationCode,
                                    agv_id = Guid.NewGuid(),
                                    agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                                    agv_grade = 2,
                                    agv_createtime = DateTime.Now,
                                    agv_taskstate = "Queue",
                                    agv_materielid = stationinfo.stationType,
                                    agv_qty = stationinfo.quantity,
                                    agv_tasktype = "TaskType_Outbound",
                                    agv_toaddress = "",
                                    agv_userid = "系统",
                                    bindSN = stationinfo.bindSN,
                                    jobID = Mes_Work.workOrder,
                                    agv_worktype = Convert.ToInt32(Mes_Work.processCode),
                                    agv_materbarcode = Mes_Work.materialCode,
                                    agv_Traytype = stationinfo.tray_type,
                                    agv_TrayStatus = stationinfo.tray_status
                                };
                                stationinfo.location_state = LocationStateEnum.OutBusy.ToString();
                                stationinfoRepository.Update(stationinfo, true);
                                agvtaskRepository.Add(agvtask, true);
                                WriteDBLog.Success("创建出库任务", $"任务编号:{agvtask.agv_tasknum}", "PCS");
                                continue;
 
                                #endregion
                            }
                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("创建出库任务", $"错误信息:{ex.Message}", "PCS");
            }
        }
    }
}