From fbc6fae6c793220d0b67ac603ce9bbf22837de79 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 19 六月 2025 17:50:47 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/Base/OutboundOrderService.cs |   79 +++++++++++++++++++++++++++------------
 1 files changed, 54 insertions(+), 25 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/Base/OutboundOrderService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/Base/OutboundOrderService.cs"
index b5ce69c..2eef9c2 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/Base/OutboundOrderService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/Base/OutboundOrderService.cs"
@@ -1,22 +1,26 @@
 锘縰sing AutoMapper;
 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.BaseRepository;
 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_IBasicRepository;
 using WIDESEA_IBasicService;
 using WIDESEA_IOutboundRepository;
 using WIDESEA_IOutboundService;
 using WIDESEA_IStockService;
+using WIDESEA_ITaskInfoRepository;
 using WIDESEA_Model.Models;
 
 namespace WIDESEA_OutboundService
@@ -25,30 +29,43 @@
     {
         private readonly IMapper _mapper;
         private readonly IMaterielInfoService _materielInfoService;
-        private readonly IStockInfoService  _stockService;
+        private readonly IStockInfoService _stockService;
         private readonly IStockInfoDetailService _stockDetailService;
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
+        private readonly IBasicRepository _basicRepository;
+        private readonly ITaskRepository _taskRepository;
+        private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository;
+        private readonly SqlSugarClient _dbBase;
 
         public IOutboundOrderRepository Repository => BaseDal;
 
-        public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IMaterielInfoService materielInfoService, IStockInfoDetailService stockDetailService, IStockInfoService stockInfoService) : base(BaseDal)
+        public OutboundOrderService(IOutboundOrderRepository BaseDal, IBasicRepository basicRepository, IMapper mapper, IMaterielInfoService materielInfoService, IStockInfoDetailService stockDetailService, IStockInfoService stockInfoService, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IOutboundOrderDetailRepository outboundOrderDetailRepository) : base(BaseDal)
         {
             _mapper = mapper;
             _materielInfoService = materielInfoService;
             _stockDetailService = stockDetailService;
-             _stockService = stockInfoService;
+            _basicRepository = basicRepository;
+            _stockService = stockInfoService;
+            _dbBase = unitOfWorkManage.GetDbClient();
+            _taskRepository = taskRepository;
+            _outboundOrderDetailRepository = outboundOrderDetailRepository;
         }
 
         public override WebResponseContent AddData(SaveModel saveModel)
         {
             OutboundOrderAddDTO outboundOrder = saveModel.MainData.DicToModel<OutboundOrderAddDTO>();
             List<OutboundOrderDetailAddDTO> orderDetailAddDTOs = saveModel.DetailData.DicToIEnumerable<OutboundOrderDetailAddDTO>();
-            outboundOrder.Details = orderDetailAddDTOs.GroupBy(x => x.MaterielCode).Select(x => new OutboundOrderDetailAddDTO
-            {
-                BatchNo = x.FirstOrDefault()?.BatchNo ?? "",
-                MaterielCode = x.Key,
-                OrderQuantity = x.Sum(x => x.OrderQuantity),
-                Remark = x.FirstOrDefault(v => !string.IsNullOrEmpty(v.Remark))?.Remark ?? ""
-            }).ToList();
+            #region 鏍规嵁鐗╂枡缂栧彿鍚堝苟鍑哄簱鏁伴噺
+            //outboundOrder.Details = orderDetailAddDTOs.GroupBy(x => x.MaterielCode).Select(x => new OutboundOrderDetailAddDTO
+            //{
+            //    BatchNo = x.FirstOrDefault()?.BatchNo ?? "",
+            //    MaterielCode = x.Key,
+            //    OrderQuantity = x.Sum(x => x.OrderQuantity),
+            //    Remark = x.FirstOrDefault(v => !string.IsNullOrEmpty(v.Remark))?.Remark ?? ""
+            //}).ToList(); 
+            #endregion
+            outboundOrder.Details = new List<OutboundOrderDetailAddDTO>();
+            outboundOrder.Details.AddRange(orderDetailAddDTOs);
             return AddOutboundOrder(outboundOrder);
         }
 
@@ -60,7 +77,7 @@
                 return WebResponseContent.Instance.Error("鐗╂枡閲嶅");
             }
             outboundOrderDetails = outboundOrderDetails.Where(x => (x.Id > 0 && x.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) || x.Id == 0).ToList();
-            
+
             List<Dictionary<string, object>> dics = new List<Dictionary<string, object>>();
             JsonSerializerSettings settings = new JsonSerializerSettings();
             settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
@@ -75,6 +92,31 @@
             return base.UpdateData(saveModel);
         }
 
+        public override WebResponseContent DeleteData(object[] keys)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                List<Dt_OutboundOrder> _OutboundOrders = BaseDal.Db.Queryable<Dt_OutboundOrder>().Includes(x => x.Details).Where(x => keys.Contains(x.Id)).ToList();
+                if (_OutboundOrders.Count < 1) throw new Exception("鏈壘鍒板嚭搴撳崟");
+                List<Dt_OutboundOrderDetail> orderDetails = new List<Dt_OutboundOrderDetail>();
+                foreach (var item in _OutboundOrders)
+                {
+                    if (item.Details.Where(x => x.LockQuantity != x.OverOutQuantity).Any())
+                        throw new Exception("瀛樺湪鏈嚭搴撳畬鎴愭墭鐩�");
+                    orderDetails.AddRange(item.Details);
+                    item.Details = null;
+                }
+                BaseDal.DeleteAndMoveIntoHty(_OutboundOrders, OperateType.浜哄伐鍒犻櫎);
+                content.Status = _outboundOrderDetailRepository.DeleteAndMoveIntoHty(orderDetails, OperateType.浜哄伐鍒犻櫎);
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+
         public WebResponseContent AddOutboundOrder(OutboundOrderAddDTO orderAddDTO)
         {
             WebResponseContent content = new();
@@ -86,6 +128,7 @@
                 #endregion
 
                 Dt_OutboundOrder outboundOrder = _mapper.Map<Dt_OutboundOrder>(orderAddDTO);
+                outboundOrder.OrderNo = DateTime.Now.ToString("yyMMddHHmmss");
                 outboundOrder.OrderStatus = InboundStatusEnum.鏈紑濮�.ObjToInt();
                 bool a = BaseDal.Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
                 content = WebResponseContent.Instance.OK();
@@ -126,20 +169,6 @@
                 return (false, "鍗曟嵁宸插瓨鍦�", outboundOrderAddDTO);
             }
             return (true, "鎴愬姛", outboundOrderAddDTO);
-        }
-
-        public WebResponseContent ReleaseOutOrder(int orderId)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-
-            }
-            catch (Exception ex)
-            {
-
-            }
-            return content;
         }
     }
 }

--
Gitblit v1.9.3