pan
2025-11-24 6b4e3935dceb3a4b158c0005468a5c803df509be
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_AllocateService/AllocateService.cs
@@ -1,10 +1,14 @@
using SqlSugar;
using MailKit.Search;
using Microsoft.Extensions.Logging;
using SqlSugar;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.AllocateEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
@@ -28,32 +32,36 @@
        public readonly IOutboundService _outboundService;
        public readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository;
        public readonly IRepository<Dt_AllocateOrderDetail> _allocateOrderDetailRepository;
        private readonly ILogger<AllocateService> _logger;
        public AllocateService(IRepository<Dt_AllocateOrder> BaseDal,
            IUnitOfWorkManage unitOfWorkManage,
            IInboundService inboundService,
            IOutboundService outboundService,
            IRepository<Dt_AllocateOrder> allocateOrderRepository,
            IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository) : base(BaseDal)
            IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository,
            ILogger<AllocateService> logger) : base(BaseDal)
        {
            _unitOfWorkManage = unitOfWorkManage;
            _inboundService = inboundService;
            _outboundService = outboundService;
            _allocateOrderRepository = allocateOrderRepository;
            _allocateOrderDetailRepository = allocateOrderDetailRepository;
            _logger = logger;
        }
        public IRepository<Dt_AllocateOrder> Repository => BaseDal;
        public WebResponseContent ReceiveAllocateOrder(Dt_AllocateOrder allocateOrder, int operateType)
        public async Task<WebResponseContent> ReceiveAllocateOrder(Dt_AllocateOrder allocateOrder, int operateType)
        {
            try
            {
                return operateType switch
                {
                    1 => AddInboundOrder(allocateOrder),
                    2 => UpdateInboundOrder(allocateOrder),
                    3 => DeleteInboundOrder(allocateOrder),
                    1 => await AddAllocateOrder(allocateOrder),
                    2 => await UpdateAllocateOrder(allocateOrder),
                    3 => DeleteAllocateOrder(allocateOrder),
                    _ => WebResponseContent.Instance.OK(),
                };
@@ -64,7 +72,7 @@
            }
        }
        public WebResponseContent AddInboundOrder(Dt_AllocateOrder allocateOrder)
        public async Task<WebResponseContent> AddAllocateOrder(Dt_AllocateOrder allocateOrder)
        {
            try
            {
@@ -76,15 +84,24 @@
                Db.InsertNav(allocateOrder).Include(x => x.Details).ExecuteCommand();
                if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType))
                {
                    if (businessType == BusinessTypeEnum.外部仓库调智仓)
                    if (businessType == BusinessTypeEnum.智仓调外部仓库)
                    {
                        var inboundOrders = ConvertToInboundOrders(allocateOrder);
                        _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1);
                        await _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1);
                    }
                    else if (businessType == BusinessTypeEnum.智仓调外部仓库)
                    else if (businessType == BusinessTypeEnum.外部仓库调智仓 || businessType == BusinessTypeEnum.智仓调智仓)
                    {
                        if (businessType == BusinessTypeEnum.外部仓库调智仓)
                        {
                            allocateOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt();
                        }
                        else if (businessType == BusinessTypeEnum.智仓调智仓)
                        {
                            allocateOrder.OrderType = InOrderTypeEnum.InternalAllocat.ObjToInt();
                        }
                        var outboundOrders = ConvertToOutboundOrders(allocateOrder);
                        _outboundService.OutboundOrderService.ReceiveOutboundOrder(outboundOrders, 1);
                        await _outboundService.OutboundOrderService.ReceiveOutboundOrder(outboundOrders, 1);
                    }
                    else
                    {
@@ -96,10 +113,11 @@
            }
            catch (Exception ex)
            {
                _logger.LogInformation("AllocateService AddAllocateOrder  err:  " + ex.Message);
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        public WebResponseContent UpdateInboundOrder(Dt_AllocateOrder model)
        public async Task<WebResponseContent> UpdateAllocateOrder(Dt_AllocateOrder model)
        {
            try
            {
@@ -170,7 +188,8 @@
                _unitOfWorkManage.BeginTran();
                foreach (var item in deletePurchaseOrderDetails)
                {
                    _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.自动删除);
                    // _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.自动删除);
                    _allocateOrderDetailRepository.DeleteData(item);
                }
                _allocateOrderDetailRepository.UpdateData(updateAllocateOrderDetails);
@@ -185,11 +204,12 @@
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                _logger.LogInformation("AllocateService UpdateAllocateOrder  err:  " + ex.Message);
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        public WebResponseContent DeleteInboundOrder(Dt_AllocateOrder model)
        public WebResponseContent DeleteAllocateOrder(Dt_AllocateOrder model)
        {
            try
            {
@@ -202,7 +222,7 @@
                {
                    return WebResponseContent.Instance.Error($"未找到调拨单明细信息");
                }
                //Db.DeleteNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                //Db.DeleteNav(Allocate).Include(x => x.Details).ExecuteCommand();
                _unitOfWorkManage.BeginTran();
                // BaseDal.DeleteAndMoveIntoHty(allocateOrder, OperateTypeEnum.自动删除);
                foreach (var item in allocateOrder.Details)
@@ -217,6 +237,7 @@
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                _logger.LogInformation("AllocateService DeleteAllocateOrder  err:  " + ex.Message);
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
@@ -230,7 +251,7 @@
                   InboundOrderNo=allocateOrder.OrderNo,
                   UpperOrderNo=allocateOrder.UpperOrderNo,
                   SupplierId=allocateOrder.SupplierId,
                   OrderType=allocateOrder.OrderType,
                   OrderType= allocateOrder.OrderType ,
                   OrderStatus=allocateOrder.OrderStatus,
                   CreateType=allocateOrder.CreateType,
                   BusinessType=allocateOrder.BusinessType,
@@ -249,7 +270,7 @@
                       OrderDetailStatus=detail.OrderDetailStatus,
                       Unit=detail.Unit,
                       RowNo=0,
                       SupplyCode="",
                       SupplyCode=detail.SupplyCode,
                       WarehouseCode=detail.WarehouseCode,
                       Barcode=detail.Barcode,
                       OutBoxbarcodes="",
@@ -267,7 +288,7 @@
                WarehouseId = allocateOrder.WarehouseId,
                OrderNo = allocateOrder.OrderNo,
                UpperOrderNo = allocateOrder.UpperOrderNo,
                OrderType = allocateOrder.OrderType,
                OrderType = OutOrderTypeEnum.Allocate.ObjToInt(),
                OrderStatus = allocateOrder.OrderStatus,
                CreateType = allocateOrder.CreateType,
                BusinessType = allocateOrder.BusinessType,
@@ -288,7 +309,7 @@
                    OrderDetailStatus = detail.OrderDetailStatus,
                    Unit = detail.Unit,
                    RowNo = 0,
                    SupplyCode = "",
                    SupplyCode = detail.SupplyCode,
                    WarehouseCode = detail.WarehouseCode,
                }).ToList()