陈勇
2026-04-06 9de6c7c6d835ba5161d64114d154bfc7676244a1
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
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_DTO;
using WIDESEA_Model.Models;
using WIDESEA_Repository;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEA_StoragIntegrationServices
{
    public partial class WCSService
    {
        /// <summary>
        /// 请求入库巷道号
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public WebResponseContent RequestInboundRoadWayNo(RequestTaskDto json)
        {
            WebResponseContent response = new WebResponseContent();
            try
            {
                //如任务已存在则 返回此任务
                var checkTask = _taskRepository.QueryFirst(x => x.PalletCode == json.PalletCode && x.PVI == json.PVI);
                if (checkTask != null)
                {
                    return response.OK("申请入库成功", data: checkTask);
                }
 
                var carInfo = _carBodyInfoRepository.QueryFirst(x => x.RFID == json.PVI && x.PalletCode == json.PalletCode);
                if (carInfo == null) throw new Exception("未知车身信息,无法入库");
 
                //屏蔽MES
                if (json.Position == "EL01RB")
                {
                    //焊装提升机
                    HZPassTZ(json);
                }
                else
                {
                    ///涂装提升机
                    TZPassZZ(json);
                }
 
           
                //{
                //    Dt_CarBodyInfo _CarBodyInfo = new Dt_CarBodyInfo  //测试
                //    {
                //        PVI = "J25000660",
                //        RFID = json.PVI,
                //        BodyStatus = 0,
                //        CarType = 1,
                //    };
                //}
 
                List<Dt_RoadWay> roadWays = new List<Dt_RoadWay>();
                if (carInfo.CarType == 1)
                {
                    roadWays = _roadWayRepository.QueryData(x => x.WirteCar == 1);
                }
                else if (carInfo.CarType == 2)
                {
                    roadWays = _roadWayRepository.QueryData(x => x.WirteCar == 2);
                }
 
                //var locations = _locationRepository.QueryData(x => (x.LocationType == carInfo.CarType || x.LocationType == 3) && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == (int)EnableEnum.Enable);
 
                var maxGroup = _locationRepository.QueryData(x => x.LocationType == carInfo.CarType && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == (int)EnableEnum.Enable)
                                .GroupBy(x => x.RoadwayNo)
                                .OrderByDescending(g => g.Count()) // 根据每个组的元素数量排序
                                .ToList(); // 取出数量最多的组
 
                if (maxGroup.Count == 0)
                {
                    maxGroup = _locationRepository.QueryData(x => x.LocationType == (int)BodyType.Empty && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == (int)EnableEnum.Enable)
                   .GroupBy(x => x.RoadwayNo)
                   .OrderByDescending(g => g.Count()) // 根据每个组的元素数量排序
                   .ToList(); // 取出数量最多的组
                }
 
                if (maxGroup.Count == 0) return response.Error(12, "无可用库位");
 
                Dictionary<string, int> result = new Dictionary<string, int>();
                foreach (var item in maxGroup)
                {
                    var number = _taskRepository.QueryData(x => x.RoadwayNo == item.Key && x.CarType == carInfo.CarType && (x.TaskType == (int)TaskInboundTypeEnum.Inbound || x.TaskType == (int)TaskInboundTypeEnum.InTray)).Count();
                    if (item.Count() - number <= 0)
                    {
                        continue;
                    }
                    result.Add(item.Key, item.Count() - number);
                }
 
                string maxRoadwayNo = result.OrderByDescending(x => x.Value).FirstOrDefault().Key; // 数量最多的组的Key
 
                var stationList = _stationManagerRepository.QueryData(x => x.RoadwayNo == maxRoadwayNo && x.stationArea == json.area && x.stationType == 1 && x.stationStatus == "1");
 
                Dt_StationManager station = null;
 
                if (stationList.Count > 1)
                {
                    var task = _taskRepository.QueryData(x => x.Roadway == stationList.FirstOrDefault().Roadway && x.TaskType == (int)TaskInboundTypeEnum.Inbound).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                    if (task != null) station = stationList.Where(x => x.stationChildCode != task.NextAddress && x.stationChildCode != task.CurrentAddress).FirstOrDefault();
                    else station = stationList.FirstOrDefault();
                }
                else
                {
                    station = stationList.FirstOrDefault();
                }
 
                //var location = _taskService.RequestLocation(station.RoadwayNo, carInfo.CarType);
                //if (location == null)
                //{
                //    return response.Error("无法获取货位信息或库位已满");
                //}
 
                var newtask = new Dt_Task
                {
                    CurrentAddress = json.Position,
                    Grade = 1,
                    Roadway = station.Roadway,
                    TargetAddress = station.Roadway,
                    //Dispatchertime = DateTime.Now,
                    NextAddress = station.stationChildCode,
                    OrderNo = null,
                    PalletCode = json.PalletCode,
                    SourceAddress = json.Position,
                    TaskState = (int)TaskInStatusEnum.InNew,
                    TaskType = (int)TaskInboundTypeEnum.Inbound,
                    TaskNum = _taskRepository.GetTaskNo().Result,
                    Creater = "Systeam",
                    PVI = json.PVI,
                    CarType = carInfo.CarType,
                    RoadwayNo = station.RoadwayNo
                };
                _unitOfWorkManage.BeginTran();
 
                _taskRepository.AddData(newtask);
                //location.LocationStatus = (int)LocationEnum.InStockDisable;
                //_locationRepository.UpdateData(location);
                _unitOfWorkManage.CommitTran();
 
                response.OK("申请入库成功", data: newtask);
 
                //response.OK(data: maxRoadwayNo);
            }
            catch (Exception ex)
            {
                response.Error($"请求巷道号失败:{ex.Message}");
            }
            return response;
        }
    }
}