heshaofeng
9 天以前 48710581fbbdd40eb3a743d91fa04e81531ba2ab
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using Autofac.Core;
using MailKit.Search;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SqlSugar;
using System.Net;
using System.Threading.Tasks;
using WIDESEA_BasicService;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_Core.Attributes;
using WIDESEA_Core.BaseController;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.Enums;
using WIDESEA_DTO.Allocate;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Mes;
using WIDESEA_IBasicService;
using WIDESEA_IInboundService;
using WIDESEA_InboundService;
using WIDESEA_IOutboundService;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
using WIDESEA_OutboundService;
 
namespace WIDESEA_WMSServer.Controllers.Inbound
{
    /// <summary>
    /// 入库单
    /// </summary>
    [Route("api/InboundOrder")]
    [ApiController]
    public class InboundOrderController : ApiBaseController<IInboundOrderService, Dt_InboundOrder>
    {
        private readonly WIDESEA_IBasicService.IErpApiService erpApiService;
 
        private readonly WIDESEA_IBasicService.IInvokeMESService _invokeMESService;
        public readonly IInboundService _inboundService;
        private readonly IESSApiService _eSSApiService;
        private readonly ILocationInfoService _locationInfoService;
        private readonly IDailySequenceService _dailySequenceService;
        private readonly IMaterialUnitService _materialUnitService;
        private readonly IOutStockLockInfoService _outStockLockInfoService;
        private readonly IOutboundOrderDetailService _outboundOrderDetailService;
        private readonly IRepository<Dt_Task> _taskRepository;
        private readonly ITask_HtyService _task_HtyService;
        private readonly ILogger<InboundOrderController> _logger;
        public InboundOrderController(IInboundOrderService service, WIDESEA_IBasicService.IErpApiService erpApiService, WIDESEA_IBasicService.IInvokeMESService invokeMESService, IESSApiService eSSApiService, IDailySequenceService dailySequenceService, ILocationInfoService locationInfoService, ILogger<InboundOrderController> logger, IMaterialUnitService materialUnitService, IInboundService inboundService, IOutStockLockInfoService outStockLockInfoService, IOutboundOrderDetailService outboundOrderDetailService, IRepository<Dt_Task> taskRepository, ITask_HtyService task_HtyService) : base(service)
        {
            this.erpApiService = erpApiService;
            _invokeMESService = invokeMESService;
            _eSSApiService = eSSApiService;
            _dailySequenceService = dailySequenceService;
            _locationInfoService = locationInfoService;
            _logger = logger;
            _materialUnitService = materialUnitService;
            _inboundService = inboundService;
            _outStockLockInfoService = outStockLockInfoService;
            _outboundOrderDetailService = outboundOrderDetailService;
            _taskRepository = taskRepository;
            _task_HtyService = task_HtyService;
        }
 
        [HttpPost, Route("Test"), AllowAnonymous, MethodParamsValidate]
        public async Task<WebResponseContent> Test()
        {
 
            var originalTask = _taskRepository.Db.Queryable<Dt_Task>().First();
 
            var result = _task_HtyService.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.人工删除);
            if (result)
            {
                var sddd = "trueee";
            }
            //var originalTask = _taskRepository.Db.Queryable<Dt_Task>().First();
            //_taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.自动完成);
            // Service.Db.Deleteable<Dt_InboundOrder>().Where(x=>x.UpperOrderNo== "12020251100040").ExecuteCommand();
            //_inboundService.InboundOrderDetailService.Db.Deleteable<Dt_InboundOrderDetail>()
            // .Where(p => SqlFunc.Subqueryable<Dt_InboundOrder>().Where(s => s.Id == p.OrderId && s.UpperOrderNo == "12020251100040").Any()).ExecuteCommand();
 
            //var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync("100513-00303", 1);
 
            //var pdddurchaseToStockResult = await _materialUnitService.ConvertFromToStockAsync("100513-00303", "W013", 1);
 
            //var sddd = _locationInfoService.AssignLocation(1);
            //var code = sddd.LocationCode;
            //var ssss=await _dailySequenceService.GetNextSequenceAsync();
            //var  ddddssss = "WSLOT" + DateTime.Now.ToString("yyyyMMddHHmmss") + ssss.ToString().PadLeft(5, '0');
            //erpApiService.GetSuppliersAsync();
 
            //erpApiService.GetMaterialUnitAsync();
            //var sss=await  _invokeMESService.NewMaterielToMes(new WIDESEA_DTO.Basic.MaterielToMesDTO
            //  {
            //      reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
            //      reqCode = Guid.NewGuid().ToString(),
            //      oldmaterialCode = "b001",
            //      newmaterialCode = "Bar01",
            //      unit = "A01",
            //      operationType = 1,
            //      supplyCode = "A0001",
            //      batchNo = "A0002",
            //      materialCode = "FC00001",
            //      warehouseCode = "",
            //      factoryArea = "A01",
            //      qty = "20.0",
            //  });
 
            //await _eSSApiService.MoveContainerAsync(new WIDESEA_DTO.Basic.MoveContainerRequest
            //{
            //    slotCode = "3-5",
            //    containerCode = "A000008009"
            //});
 
            //await erpApiService.GetSuppliersAsync();
            //await erpApiService.GetMaterialUnitAsync();
            //await  erpApiService.GetMaterialInfoAsync(new WIDESEA_DTO.Basic.MaterialRequest());
 
 
            return WebResponseContent.Instance.OK(result?1:0 );
        }
 
        /// <summary>
        /// 接收MES入库单信息 
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("ReceiveInboundOrder"), AllowAnonymous, MethodParamsValidate]
        public async Task<WebResponseContent> ReceiveInboundOrder([FromBody] InboundRequestModel model)
        {
            if (model.inBounds == null || !model.inBounds.Any())
            {
                return WebResponseContent.Instance.Error("入库单不能为空");
            }
 
            _logger.LogInformation("InboundOrderController ReceiveInboundOrder:  " + JsonConvert.SerializeObject(model));
            List<Dt_InboundOrder> inboundOrders = new List<Dt_InboundOrder>();
 
            foreach (var item in model.inBounds)
            {
                Dt_InboundOrder dt_InboundOrder = new Dt_InboundOrder() { Details = new List<Dt_InboundOrderDetail>() };
                foreach (var detailitem in item.details)
                {
 
                    if (detailitem.barcodes != null && detailitem.barcodes.Any())
                    {
                        foreach (var barcode in detailitem.barcodes)
                        {
                            Dt_InboundOrderDetail inboundOrderDetail = new Dt_InboundOrderDetail()
                            {
                                lineNo = detailitem.lineNo,
                                MaterielCode = detailitem.materialCode,
                                SupplyCode = detailitem.supplyCode,
                                BatchNo = detailitem.batchNo,
                                Unit = detailitem.unit,
                                WarehouseCode = detailitem.warehouseCode,
                                Barcode = barcode.barcode,
                                OutBoxbarcodes = barcode.outBoxbarcodes,
                                BarcodeUnit = barcode.unit,
                                BarcodeQty = barcode.qty,
                                OrderQuantity = barcode.qty
                            };
 
                            dt_InboundOrder.Details.Add(inboundOrderDetail);
                        }
 
                    }
                    else
                    {
                        Dt_InboundOrderDetail inboundOrderDetail = new Dt_InboundOrderDetail()
                        {
                            lineNo = detailitem.lineNo,
                            MaterielCode = detailitem.materialCode,
                            SupplyCode = detailitem.supplyCode,
                            BatchNo = detailitem.batchNo,
                            Unit = detailitem.unit,
                            WarehouseCode = detailitem.warehouseCode,
                            OrderQuantity = detailitem.qty,
                            BarcodeUnit = detailitem.unit,
                            BarcodeQty = detailitem.qty,
                        };
                        dt_InboundOrder.Details.Add(inboundOrderDetail);
                    }
 
                }
                dt_InboundOrder.UpperOrderNo = item.orderNo;
                dt_InboundOrder.BusinessType = item.business_type;
                dt_InboundOrder.IsBatch = item.isBatch;
                dt_InboundOrder.FactoryArea = item.factoryArea;
 
                inboundOrders.Add(dt_InboundOrder);
            }
 
            var content = await Service.ReceiveInboundOrder(inboundOrders, model.operationType);
 
            if (content.Status) return WebResponseContent.Instance.OK(200);
            else return WebResponseContent.Instance.Error(content.Message);
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="materielGroupDTO"></param>
        /// <returns></returns>
        [HttpPost, Route("BarcodeMaterielGroup"), AllowAnonymous, MethodParamsValidate]
        public WebResponseContent BarcodeMaterielGroup([FromBody] BarcodeMaterielGroupDTO data)
        {
            var content = Service.BarcodeMaterielGroup(data);
 
            return content;
 
        }
 
        [HttpPost, Route("UndoPalletGroup"), AllowAnonymous, MethodParamsValidate]
        public WebResponseContent UndoPalletGroup(string palletCode)
        {
            return Service.UndoPalletGroup(palletCode);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="materielGroupDTO"></param>
        /// <returns></returns>
        [HttpPost, Route("EmptyMaterielGroup"), AllowAnonymous, MethodParamsValidate]
        public WebResponseContent EmptyMaterielGroup([FromBody] EmptyBarcodeMaterielGroupDTO data)
        {
            var content = Service.EmptyMaterielGroup(data);
 
            return content;
 
        }
 
        [HttpPost, Route("UnPalletQuantity"), AllowAnonymous, MethodParamsValidate]
        public WebResponseContent UnPalletQuantity(string orderNo)
        {
            return Service.UnPalletQuantity(orderNo);
        }
 
        [HttpPost, Route("BatchOrderFeedbackToMes"), AllowAnonymous]
        public async Task<WebResponseContent> BatchOrderFeedbackToMes([FromBody] BatchOrderFeedbackToMesDto request)
        {
            return await _invokeMESService.BatchOrderFeedbackToMes(request.orderNos, request.inout);
        }
 
    }
}