huanghongfeng
16 小时以前 bce2cc310d462ffbe56ee3d9f3d9368abf481aad
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
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;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WIDESEA_Common.OtherEnum;
using WIDESEA_Core.Const;
using WIDESEA_DTO.ToMes;
using System.DirectoryServices.Protocols;
using System.Net;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
        
        /// <summary>
        /// 下发出库接口
        /// </summary>
        /// <param name="outbound"></param>
        /// <returns></returns>
        public ApiResponse<object> sendExTask(InOutboundTaskReceived outbound)
        {
 
            List<Dt_StockInfo> Adddtstockt = new List<Dt_StockInfo>();
            List<Dt_LocationInfo> Addlocations = new List<Dt_LocationInfo>();
            List<Dt_Task> Addtaskdt = new List<Dt_Task>();
 
            if ( outbound != null )
            {
                if (outbound.PalletCodeList.Count > 0)
                {
                    List<Dt_StockInfo> StockData = _stockRepository.QueryData();
                    List<Dt_LocationInfo> LocationData=_locationInfoRepository.QueryData(x=>x.LocationStatus== (int)LocationStatusEnum.InStock);
                    List<Dt_Task> taskData = BaseDal.QueryData();
 
                    foreach (string Pallet in outbound.PalletCodeList)
                    {
                        //查找库存信息
                        Dt_StockInfo dt_StockInfo = StockData.Find(x => x.PalletCode == Pallet);
                        if(dt_StockInfo==null) return MESresponse($"接收到的托盘条码:{Pallet},未在系统中找到库存信息!", false);
                        //查找库位信息
                        Dt_LocationInfo locationInfo = LocationData.Find(x => x.LocationCode == dt_StockInfo.LocationCode);
                        if (locationInfo == null) return MESresponse($"接收到的托盘条码:{Pallet},未在系统中找到库位信息!", false);
 
                        //判断当前货位是否有任务
                        Dt_Task _Task = taskData.Find(x => x.SourceAddress == locationInfo.LocationCode || x.TargetAddress == locationInfo.LocationCode);
                        if (_Task != null) return MESresponse($"接收到的托盘条码:{Pallet},当前托盘对应的库位信息已有任务,不可出库!", false);
 
                        dt_StockInfo.StockStatus = (int)StockStatusEmun.出库锁定;
                        locationInfo.LocationStatus = (int)LocationStatusEnum.InStockLock;
 
 
 
                        string TaregtAddres = "";
                        if (outbound.NodeCode != "2011" && outbound.NodeCode != "2009")
                        {
                            int nextTaregt = int.Parse(outbound.NodeCode);
                            //确认目标站台(固定)
                            TaregtAddres = (nextTaregt - 1).ToString();
                        }
                        else
                        {
                            TaregtAddres = locationInfo.RoadwayNo == "SC01" ? "2021" : "2020";
                        }
 
                        //生成移动任务
                        Dt_Task dt_Task = new()
                        {
                            PalletCode = dt_StockInfo.PalletCode,
                            TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                            Roadway = locationInfo.RoadwayNo,
                            TaskType = TaskOutboundTypeEnum.Outbound.ObjToInt(),
                            TaskStatus = TaskOutStatusEnum.OutNew.ObjToInt(),
                            SourceAddress = locationInfo.LocationCode,
                            TargetAddress = outbound.NodeCode,
                            CurrentAddress = locationInfo.LocationCode,
                            NextAddress = outbound.NodeCode,
                            Grade = 1,
                            Creater = "MES",
                            Depth = locationInfo.Depth,
                            CreateDate = DateTime.Now,
                            MEStaskId = outbound.TaskId,
                            MESbusinessId = outbound.BusinessId,
                            MESsubPalletCode = dt_StockInfo.MESsubPalletCode,
                            OutboundPlatform = outbound.NodeCode
                        };
                        Adddtstockt.Add(dt_StockInfo);
                        Addlocations.Add(locationInfo);
                        Addtaskdt.Add(dt_Task);
                    }
                    if (Adddtstockt.Count > 0 && Addlocations.Count > 0 && Addtaskdt.Count > 0)
                    {
                        _unitOfWorkManage.BeginTran();
 
 
                        _stockRepository.UpdateData(Adddtstockt);
                        _locationInfoRepository.UpdateData(Addlocations);
                        BaseDal.AddData(Addtaskdt);
 
                        var respon = PushTasksToWCS(Addtaskdt,"");
                        if (respon.Status)
                        {
                            _unitOfWorkManage.CommitTran();  //提交事务
                            return MESresponse("", true);
                        }
                        else
                        {
                            _unitOfWorkManage.RollbackTran();  //回滚事务
                            return MESresponse($"下发出库失败,原因:{respon.Message}!", false);
                        }
 
                    }
                    else
                    {
                        return MESresponse("任务生成失败!", false);
                    }
 
                }
                else
                {
                    return MESresponse("接收到MES托盘编码列表无数据!", false);
                }
            }
            else
            {
                return MESresponse("接收到MES下发的任务为空!", false);
            }
        }
 
        
    }
}