dengjunjie
2025-03-12 f43b7df8400f4fcffc9f19dca0888d61e2b33d5f
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
using AutoMapper;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core.Utilities;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Outbound;
using WIDESEA_DTO.Stock;
using WIDESEA_DTO.WCSInfo;
using WIDESEA_IBasicService;
using WIDESEA_IOutboundRepository;
using WIDESEA_IOutboundService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
using WIDESEAWCS_DTO.WCSInfo;
 
namespace WIDESEA_OutboundService
{
    public partial class OutboundOrderService : ServiceBase<Dt_OutboundOrder, IOutboundOrderRepository>, IOutboundOrderService
    {
        /// <summary>
        /// 空托出库
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent PdaOutEmpty()
        {
            try
            {
                ISugarQueryable<Dt_StockInfo> sugarQueryable1 = _dbBase.Queryable<Dt_StockInfo>();
                ISugarQueryable<Dt_StockInfoDetail> sugarQueryable2 = _dbBase.Queryable<Dt_StockInfoDetail>();
                List<StockViewDTO1> list = sugarQueryable1.InnerJoin(sugarQueryable2, (a, b) => a.Id == b.StockId && b.MaterielName.Contains("空托") && a.StockStatus == StockStatusEmun.已入库.ObjToInt()).Select((a, b) => new StockViewDTO1
                {
                    LocationCode = a.LocationCode,
                    PalletCode = a.PalletCode,
                    MaterielCode = b.MaterielCode,
                    MaterielName = b.MaterielName,
                    InDate = a.InDate,
                    StockId = a.Id
                }).ToList();
                StockViewDTO1? stockViewDTO = list.OrderByDescending(x => x.InDate).FirstOrDefault();
                if (stockViewDTO == null) throw new Exception("未找到可出库空托");
                Dt_LocationInfo locationInfo = _dbBase.Queryable<Dt_LocationInfo>().Where(x => x.LocationCode == stockViewDTO.LocationCode).First();
                if (locationInfo == null) throw new Exception($"未找到货位【{stockViewDTO.LocationCode}】信息");
                Dt_StockInfo stockInfo = sugarQueryable1.Where(x => x.Id == stockViewDTO.StockId).Includes(x => x.Details).First();
                if (stockInfo == null) throw new Exception($"未找到空托库存信息");
                stockInfo.StockStatus = StockStatusEmun.出库中.ObjToInt();
                stockInfo.Details.ForEach(x =>
                {
                    x.Status = StockStatusEmun.出库中.ObjToInt();
                });
                locationInfo.CurrentQty--;
                Dt_Task _Task = new Dt_Task()
                {
                    CurrentAddress = locationInfo.LocationCode,
                    NextAddress = "SC01",
                    SourceAddress = locationInfo.LocationCode,
                    TargetAddress = "SC01",
                    CreateDate = DateTime.Now,
                    Creater = "System",
                    PalletCode = stockViewDTO.PalletCode,
                    Roadway = locationInfo.RoadwayNo,
                    OrderNo = "",
                    TaskNum = _taskRepository.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    TaskState = OutTaskStatusEnum.OutNew.ObjToInt(),
                    TaskType = TaskTypeEnum.PalletOutbound.ObjToInt(),
                    Dispatchertime = DateTime.Now,
                };
                List<WMSTaskDTO> wMSTaskDTOs = _mapper.Map<List<WMSTaskDTO>>(_Task);
                Db.Ado.BeginTran();
                _dbBase.Updateable(locationInfo);
                _stockService.UpdateData(stockInfo);
                _stockDetailService.UpdateData(stockInfo.Details);
                _taskRepository.AddData(_Task);
                var ResultData = HttpHelper.PostAsync(WCSInterfaceAddress.ReceiveTask, wMSTaskDTOs.ToJson(), headers: new Dictionary<string, string>());
                if (ResultData.Result == null) throw new Exception($"向WCS下发空托出库任务超时");
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result);
                if (content == null) throw new Exception($"下发空托出库任务WCS无响应");
                if (!content.Status) throw new Exception(content.Message);
                Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
    }
}