分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-03-06 5662395113163ac87425f23aa0bff8853be92462
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
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.EFDbContext;
using WIDESEA_Core.FreeDB;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Repositories;
using static FreeSql.Internal.GlobalFilter;
using static System.Collections.Specialized.BitVector32;
 
namespace WIDESEA_WCS.JobsPart.Common
{
    public class OutboundTask
    {
        static FreeDB freeDB = new FreeDB();
        /// <summary>
        /// 创建出库任务
        /// </summary>
        public static void CreateOutboundTask()
        {
            try
            {
                VOLContext context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                var mes_heads = freeDB.Select<dt_mes_head>().Where(x => x.processCode == "28").OrderBy(x => x.expectedStartTime).ToList();
                foreach (var mes_head in mes_heads)
                {
                    //var inventorys = freeDB.Select<dt_inventory>().Where(x => x.FigureNumber == mes_head.drawingNo).OrderBy.ToList();
                    var station = stationinfoRepository.Find(x => x.stationType == mes_head.drawingNo && x.line != x.line).OrderBy(x => x.line).ThenByDescending(x => x.column).FirstOrDefault();
                    bool ok = false;
                    List<string> list = new List<string>();
                    if (station != null && station.location_state == LocationStateEnum.Stroge.ToString() && station.enable)
                    {
                        var SNS = station.bindSN.Split(",");
                        foreach (var SN in SNS)
                        {
                            if (!string.IsNullOrEmpty(SN))
                                list.Add(SN);
                        }
                    }
                    foreach (var SN in list)
                    {
                        if (ok = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mes_head.jobID && x.SN == SN).Any()) continue;
                    }
                    if (ok)
                    {
                        dt_agvtask agvtask = new dt_agvtask()
                        {
                            agv_fromaddress = station.stationCode,
                            agv_id = Guid.NewGuid(),
                            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                            agv_grade = 1,
                            agv_createtime = DateTime.Now,
                            agv_taskstate = "Queue",
                            agv_materielid = station.stationType,
                            agv_qty = station.quantity,
                            agv_tasktype = "TaskType_Outbound",
                            agv_toaddress = "",
                            agv_userid = "系统",
                            bindSN = station.bindSN,
                            agv_worktype = Convert.ToInt32(mes_head.processCode),
                            agv_materbarcode = mes_head.materialCode,
                            agv_barcode = station.tray_type
                        };
                        dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository);
                        if (TargetLocation != null)
                        {
                            agvtask.agv_taskstate = "Create";
                            agvtask.agv_toaddress = TargetLocation.stationCode;
                            TargetLocation.location_state = LocationStateEnum.Busy.ToString();
                            freeDB.Update(TargetLocation);
                        }
                        freeDB.Add(agvtask);
                    }
                }
            }
            catch (Exception)
            {
 
                throw;
            }
        }
        private static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository)
        {
            dt_stationinfo TargetLocation = null;
            var stations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001"));
            foreach (var station in stations)
            {
                TargetLocation = stationinfoRepository.FindFirst(x => x.stationCode == station.stationCode && x.location_state == LocationStateEnum.Empty.ToString() && x.enable);
                if (TargetLocation != null) continue;
            }
 
            if (TargetLocation == null)
            {
                throw new Exception("检测线上料位已满");
            }
            return TargetLocation;
        }
    }
}