分支自 SuZhouGuanHong/TaiYuanTaiZhong

huanghongfeng
2024-05-20 cb62fe00ff0c80bce983b0aa7a2b320fdc26f85f
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Comm.TaskNo;
using WIDESEA_Comm;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
 
namespace WIDESEA_WCS.JobsPart.Common
{
    public class EmptyTray
    {
        /// <summary>
        /// 空托叠盘入库
        /// </summary>
        public static void EmptyTrayIn()
        {
            try
            {
                VOLContext Context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 5 && x.enable).ToList();
                foreach (var EmptyStation in EmptyStations)
                {
                    CreateEmptyTrayIn(stationinfoRepository, EmptyStation);
                }
            }
            catch (Exception ex)
            {
                WriteDBLog.Success("创建叠盘位空托入库任务", $"错误信息:{ex.Message}", "PCS");
            }
        }
        /// <summary>
        /// 获取可入空托货位
        /// </summary>
        public static dt_stationinfo GetEmptyTrayStation(Idt_stationinfoRepository stationinfoRepository,dt_agvtask agv_task)
        {
            dt_stationinfo EmptyStation = null;
            #region 检测上料的空托叠盘
            if (agv_task.agv_fromaddress.Contains("S"))
            {
                var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.quantity < 5 && x.enable).ToList();
                EmptyStation = EmptyStations.Where(x => x.tray_type == agv_task.agv_Traytype && x.quantity < 5 && x.location_state == LocationStateEnum.Stroge.ToString()).FirstOrDefault();
                if (EmptyStation == null)
                    EmptyStation = EmptyStations.Where(x => x.location_state == LocationStateEnum.Empty.ToString() && x.quantity == 0).FirstOrDefault();
                if (EmptyStation == null)
                {
                    var EmptyD = EmptyStations.Where(x => x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderByDescending(x => x.quantity).FirstOrDefault();
                    if (EmptyD != null) CreateEmptyTrayIn(stationinfoRepository, EmptyD);
                }
            }
            #endregion
            else
            {
                EmptyStation = GetStation.EmptyPalletStation1(agv_task.agv_Traytype == "SmallTray" ? "11" : "10");
            }
            return EmptyStation;
        }
        /// <summary>
        /// 创建空托叠盘入库任务
        /// </summary>
        /// <param name="stationinfoRepository"></param>
        /// <param name="EmptyStation"></param>
        public static void CreateEmptyTrayIn(Idt_stationinfoRepository stationinfoRepository, dt_stationinfo EmptyStation)
        {
            VOLContext Context = new VOLContext();
            Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
            try
            {
                if (agvtaskRepository.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any()) return;
                var area = EmptyStation.tray_type == "SmallTray" ? "11" : "10";
                var toEmptyStation = GetStation.EmptyPalletStation1(area);
                if (toEmptyStation != null)
                {
                    #region 同一个空托位只能同时生成一个空托任务
                    if (agvtaskRepository.Find(x => x.agv_fromaddress == toEmptyStation.stationCode || x.agv_toaddress == toEmptyStation.stationCode).Any()) return;
                    #endregion
 
                    dt_agvtask agvtask = new dt_agvtask()
                    {
                        agv_fromaddress = EmptyStation.stationCode,
                        agv_id = Guid.NewGuid(),
                        agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                        agv_grade = 3,
                        agv_createtime = DateTime.Now,
                        agv_taskstate = "Create",
                        //agv_materielid = station.stationType,
                        agv_qty = EmptyStation.quantity - toEmptyStation.quantity,
                        StarQuantity = toEmptyStation.quantity,
                        EndQuantity = toEmptyStation.quantity,
                        agv_tasktype = "TaskType_EmptyPallet",
                        agv_toaddress = toEmptyStation.stationCode,
                        agv_userid = "系统",
                        agv_TrayStatus = "EmptyTray",//station.tray_status,
                        agv_Traytype = EmptyStation.tray_type,
                    };
                    agvtaskRepository.Add(agvtask, true);
                    EmptyStation.location_state = LocationStateEnum.Busy.ToString();
                    stationinfoRepository.Update(EmptyStation, true);
                    toEmptyStation.location_state = LocationStateEnum.Busy.ToString();
                    stationinfoRepository.Update(toEmptyStation, true);
                    WriteDBLog.Success("创建叠盘位空托入库任务", $"任务编号:{agvtask.agv_tasknum}", "PCS");
                }
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("创建叠盘位空托入库任务", $"错误信息:{ex.Message}", "PCS");
            }
        }
    }
}