1
yangpeixing
4 天以前 30470e6a44e05993bd1c63610af4fec3f0fda960
WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -24,25 +24,35 @@
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Org.BouncyCastle.Asn1.Tsp;
using Spire.Pdf;
using Spire.Pdf;
using SqlSugar;
using System;
using System;
using System;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing.Printing;
using System.Drawing.Printing;
using System.IO;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using System.Threading.Tasks;
using WIDESEA_BasicRepository;
using WIDESEA_Common;
using WIDESEA_Common.Log;
using WIDESEA_Common.Log;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.TaskEnum;
@@ -54,6 +64,7 @@
using WIDESEA_Core.TaskEnum;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.ERP;
using WIDESEA_DTO.ERP;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Stock;
using WIDESEA_DTO.Task;
@@ -62,6 +73,7 @@
using WIDESEA_IInboundRepository;
using WIDESEA_IInboundService;
using WIDESEA_InboundRepository;
using WIDESEA_InboundRepository;
using WIDESEA_IOutboundRepository;
using WIDESEA_IOutboundService;
using WIDESEA_IRecordService;
@@ -69,8 +81,10 @@
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoRepository;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.Inbound;
using WIDESEA_OutboundRepository;
using WIDESEA_OutboundRepository;
using WIDESEA_StockRepository;
using WIDESEA_TaskInfoRepository;
@@ -78,26 +92,13 @@
using static WIDESEA_Common.HouseBackboundPassBack;
using static WIDESEA_Common.HouseInboundPassBack;
using static WIDESEA_Common.HouseInboundPassBack.data.data1;
using static WIDESEA_Common.HouseInboundPassBack.data.data1;
using static WIDESEA_Common.HouseoutboundPassBack;
using static WIDESEA_Common.InventoryAllocate;
using static WIDESEA_Common.NewHouseInboundPassBack;
using static WIDESEA_Common.NewHouseInboundPassBack.Parame.Syncretism;
using static WIDESEA_ITaskInfoService.ITaskService;
using Parameter = WIDESEA_Common.Parameter;
using WIDESEA_DTO.ERP;
using WIDESEA_OutboundRepository;
using System.ComponentModel.DataAnnotations;
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Spire.Pdf;
using WIDESEA_InboundRepository;
using System.Drawing.Printing;
using System;
using WIDESEA_Common.Log;
using static WIDESEA_Common.HouseInboundPassBack.data.data1;
using System.Diagnostics;
namespace WIDESEA_TaskInfoService
{
@@ -131,9 +132,11 @@
        private readonly IInboundRepository _inboundRepository;
        private readonly ITakeStockOrderCPRepository _takeStockOrderCPRepository;
        private readonly ITakeStockOrderDetailCPRepository _takeStockOrderDetailCPRepository;
        private readonly IHubContext<WMSNoticeHub> _hubContext;
        public ITaskRepository Repository => BaseDal;
        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IMaterielInfoService materielInfoService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IInboundOrder_HtyService inboundOrder_HtyService, IStockRepository stockRepository, IInboundOrderDetailService inboundOrderDetailService, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IBasicRepository basicRepository, IStockInfoDetailRepository stockInfoDetailRepository, IPalletTypeInfoRepository palletTypeInfoRepository, IReturnOrderRepository returnOrderRepository, IProductionRepository productionRepository, IInboundRepository inboundRepository, INewOutboundOrderDetailRepository newOutboundOrderDetailRepository, ITakeStockOrderCPRepository takeStockOrderCPRepository, ITakeStockOrderDetailCPRepository takeStockOrderDetailCPRepository, IStockInfoDetailCPRepository stockInfoDetailCPRepository) : base(BaseDal)
        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IMaterielInfoService materielInfoService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IInboundOrder_HtyService inboundOrder_HtyService, IStockRepository stockRepository, IInboundOrderDetailService inboundOrderDetailService, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IBasicRepository basicRepository, IStockInfoDetailRepository stockInfoDetailRepository, IPalletTypeInfoRepository palletTypeInfoRepository, IReturnOrderRepository returnOrderRepository, IProductionRepository productionRepository, IInboundRepository inboundRepository, INewOutboundOrderDetailRepository newOutboundOrderDetailRepository, ITakeStockOrderCPRepository takeStockOrderCPRepository, ITakeStockOrderDetailCPRepository takeStockOrderDetailCPRepository, IStockInfoDetailCPRepository stockInfoDetailCPRepository,
          IHubContext<WMSNoticeHub> hubContext) : base(BaseDal)
        {
            _mapper = mapper;
            _stockRepository = stockRepository;
@@ -162,6 +165,7 @@
            _takeStockOrderCPRepository = takeStockOrderCPRepository;
            _takeStockOrderDetailCPRepository = takeStockOrderDetailCPRepository;
            _stockInfoDetailCPRepository = stockInfoDetailCPRepository;
            _hubContext = hubContext;
        }
        public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"];
@@ -2866,89 +2870,102 @@
        private void AddRetrueOrder(Dt_Task task,Dt_StockInfo stockInfo, Dt_OutboundOrder outboundOrder)
        {
            Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
           .Where(x => x.StockId == stockInfo.Id).First();
            if (stockInfoDetail == null)
            List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
           .Where(x => x.StockId == stockInfo.Id).ToList();
            if (stockInfoDetails == null || stockInfoDetails.Count == 0)
            {
                throw new Exception("建立回库单时,未找到该库存信息");
            }
            if (outboundOrder.OrderType == OrderTypeEnum.反拣出库单.ObjToInt())
            Dt_ReturnOrder? lastReturnOrder = null;
            foreach (var stockInfoDetail in stockInfoDetails)
            {
                Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == stockInfo.PalletCode && x.LocationCode == stockInfo.LocationCode && x.OrderStatus == InOrderStatusEnum.未开始.ObjToInt());
                if (returnOrder == null)
                if (outboundOrder.OrderType == OrderTypeEnum.反拣出库单.ObjToInt())
                {
                    throw new Exception("反拣出库后,未找到对应反拣回库单信息");
                }
                stockInfo.LocationCode = "";
                stockInfo.StockStatus = StockStatusEmun.反拣入库.ObjToInt();
                stockInfo.Remark = "反拣入库";
                stockInfoDetail.OutboundQuantity = 0;
                stockInfoDetail.StockQuantity += returnOrder.OrderQuantity;
                stockInfoDetail.OrderNo = returnOrder.OrderNo;
            }
            else
            {
                WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文 = 1 });
                var postData = new
                {
                    DeviceCode = task.NextAddress,    // 屏幕编号
                    MaterialCode = stockInfoDetail.MaterielCode,//物料类型
                    SendNum = stockInfoDetail.OutboundQuantity,//发料数
                    BackNum = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity//回库数
                };
                WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文2 = postData });
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData);
                WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文3 = json });
                using (var client = new HttpClient())
                {
                    var content = new StringContent(json, Encoding.UTF8, "application/json");
                    var response = client.PostAsync(LEDAPI, content).Result;
                    string result = response.Content.ReadAsStringAsync().Result;
                    WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文 = response, 接收报文 = result });
                }
                WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文 = 4 });
                decimal returnQuantity = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity;
                if (returnQuantity > 0)
                {
                    Dt_ReturnOrder returnOrder = new Dt_ReturnOrder
                    Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == stockInfo.PalletCode && x.LocationCode == stockInfo.LocationCode && x.OrderStatus == InOrderStatusEnum.未开始.ObjToInt());
                    if (returnOrder == null)
                    {
                        MaterielCode = stockInfoDetail.MaterielCode,
                        MaterielName = stockInfoDetail.MaterielName,
                        BatchNo = stockInfoDetail.BatchNo,
                        OrderQuantity = returnQuantity,
                        ReceiptQuantity = returnQuantity,
                        OrderStatus = InOrderStatusEnum.未开始.ObjToInt(),
                        LinId = stockInfoDetail.LinId,
                        LPNNo = stockInfo.PalletCode,
                        Creater = "LK",
                        CreateDate = DateTime.Now,
                        OrderType = OrderTypeEnum.余料回库单.ObjToInt(),
                        System = "WMS"
                    };
                    if (outboundOrder.System == "SMOM" && stockInfo.LocationCode != null)
                    {
                        returnOrder.LocationCode = stockInfo.LocationCode;
                        throw new Exception("反拣出库后,未找到对应反拣回库单信息");
                    }
                    _unitOfWorkManage.BeginTran();
                    _returnOrderRepository.AddData(returnOrder);
                    stockInfo.LocationCode = "";
                    stockInfo.StockStatus = StockStatusEmun.余料退库.ObjToInt();
                    stockInfo.Remark = "余料退库";
                    stockInfo.StockStatus = StockStatusEmun.反拣入库.ObjToInt();
                    stockInfo.Remark = "反拣入库";
                    stockInfoDetail.OutboundQuantity = 0;
                    stockInfoDetail.StockQuantity = returnQuantity;
                    stockInfoDetail.StockQuantity += returnOrder.OrderQuantity;
                    stockInfoDetail.OrderNo = returnOrder.OrderNo;
                    _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                    _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                    _unitOfWorkManage.CommitTran();
                }
                else
                {
                    DeleteAndMoveIntoHtStockStatus(stockInfo);
                    WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文 = 1 });
                    var postData = new
                    {
                        DeviceCode = task.NextAddress,    // 屏幕编号
                        MaterialCode = stockInfoDetail.MaterielCode,//物料类型
                        SendNum = stockInfoDetail.OutboundQuantity,//发料数
                        BackNum = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity//回库数
                    };
                    WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文2 = postData });
                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData);
                    WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文3 = json });
                    using (var client = new HttpClient())
                    {
                        var content = new StringContent(json, Encoding.UTF8, "application/json");
                        var response = client.PostAsync(LEDAPI, content).Result;
                        string result = response.Content.ReadAsStringAsync().Result;
                        WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文 = response, 接收报文 = result });
                    }
                    WriteLog.Write_Log("API", "出库—请求LED", "请求成功", new { 请求报文 = 4 });
                    bool allowCompeted = stockInfo.Details.All(x => x.StockQuantity == x.OutboundQuantity);
                    if (allowCompeted)
                    {
                        DeleteAndMoveIntoHtStockStatus(stockInfo);
                    }
                    else
                    {
                        decimal returnQuantity = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity;
                        Dt_ReturnOrder returnOrder = new Dt_ReturnOrder
                        {
                            MaterielCode = stockInfoDetail.MaterielCode,
                            MaterielName = stockInfoDetail.MaterielName,
                            BatchNo = stockInfoDetail.BatchNo,
                            OrderQuantity = returnQuantity,
                            ReceiptQuantity = returnQuantity,
                            OrderStatus = InOrderStatusEnum.未开始.ObjToInt(),
                            LinId = stockInfoDetail.LinId,
                            LPNNo = stockInfo.PalletCode,
                            Creater = "LK",
                            CreateDate = DateTime.Now,
                            OrderType = OrderTypeEnum.余料回库单.ObjToInt(),
                            System = "WMS"
                        };
                        if(lastReturnOrder != null)
                        {
                            lastReturnOrder.Remark = lastReturnOrder.Remark + $",{returnOrder.BatchNo}";
                            _returnOrderRepository.UpdateData(lastReturnOrder);
                        }
                        if (outboundOrder.System == "SMOM" && stockInfo.LocationCode != null)
                        {
                            returnOrder.LocationCode = stockInfo.LocationCode;
                        }
                        _unitOfWorkManage.BeginTran();
                        if(lastReturnOrder == null)
                        {
                            _returnOrderRepository.AddData(returnOrder);
                            lastReturnOrder = returnOrder;
                        }
                        stockInfo.LocationCode = "";
                        stockInfo.StockStatus = StockStatusEmun.余料退库.ObjToInt();
                        stockInfo.Remark = "余料退库";
                        stockInfoDetail.OutboundQuantity = 0;
                        stockInfoDetail.StockQuantity = returnQuantity;
                        stockInfoDetail.OrderNo = lastReturnOrder.OrderNo;
                        _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                        _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                        _unitOfWorkManage.CommitTran();
                    }
                }
            }
        }
        //低温、药水回库单