wankeda
3 天以前 2a32dfbf5fe3b484d1ef6849cd8e322faa70ce14
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.Enums;
using WIDESEA_Core;
using WIDESEA_Model.Models;
using WIDESEA_Core.Helper;
using Microsoft.Extensions.Logging;
using MailKit.Search;
using System.Reflection.Metadata;
using static WIDESEA_ITaskInfoService.ITaskService;
using WIDESEA_Common;
using WIDESEA_Core.LogHelper;
using WIDESEA_DTO.Task;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.LocationEnum;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
 
        /// <summary>
        /// 仅申请任务,让WCS根据路由确定下一地址
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="palletCode"></param>
        /// <returns></returns>
        public WebResponseContent DeviceRequestInboundTaskSimple(string stationCode, string palletCode)
        {
            try
            {
                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
                if (task != null)
                {
                    PushTasksToWCS(new List<Dt_Task> { task });
                    return WebResponseContent.Instance.OK($"该托盘已生成任务", _mapper.Map<WMSTaskDTO>(task));
                }
                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
                {
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
                //Dt_StockInfo stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
 
                //if (stockInfo == null)
                //{
                //    return WebResponseContent.Instance.Error($"未找到组盘信息");
                //}
                //var details = stockInfo.Details.FirstOrDefault();
                //if (!string.IsNullOrEmpty(stockInfo.LocationCode))
                //{
                //    return WebResponseContent.Instance.Error($"该托盘已绑定货位");
                //}
                Dt_RoadwayInfo roadwayInfo = _roadwayInforepository.QueryFirst(x => x.InStationCode == stationCode);
                if (roadwayInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到刚入库站台地址");
                }
                Dt_Warehouse warehouse = _warehouseRepository.QueryFirst(x => x.WarehouseCode == roadwayInfo.RoadwayNo);
                if (warehouse == null)
                {
                    return WebResponseContent.Instance.Error("未找到改仓库");
                }
                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayInfo.RoadwayNo, warehouse.WarehouseId, "");//
                if (locationInfo == null)
                {
                    return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位");
                }
                var dt_Stock = new Dt_StockInfo
                {
                    PalletCode = palletCode,
                    PalletType = 1,
                    LocationCode = locationInfo.LocationCode,
                    StockStatus = (int)StockStatusEmun.组盘暂存,
                    Creater = "WMS",
                    CreateDate = DateTime.Now,
                    WarehouseId = warehouse.WarehouseId,
                };
                Dt_Task newTask = new Dt_Task()
                {
                    CurrentAddress = stationCode,
                    Grade = 0,
                    NextAddress = stationCode,//堆垛机
                    PalletCode = palletCode,
                    OrderNo = "1",
                    Roadway = "1",
                    SourceAddress = "",
                    TargetAddress = locationInfo.LocationCode,
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = 1,
                    //PalletType = GetPalletType(warehouse, palletCode),//GetPalletType(warehouse, palletCode)
                    Creater = "WCS",
                    CreateDate = DateTime.Now
                };
 
                _unitOfWorkManage.BeginTran();
                locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                int taskId = BaseDal.AddData(newTask);
                newTask.TaskId = taskId;
                _stockRepository.AddData(dt_Stock);
                //_stockRepository.UpdateData(stockInfo);
                _locationInfoRepository.UpdateData(locationInfo);
                _unitOfWorkManage.CommitTran();
                WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
 
                PushTasksToWCS(new List<Dt_Task> { newTask });
                return WebResponseContent.Instance.OK(data: wMSTaskDTO);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
    }
}