dengjunjie
2025-03-12 f43b7df8400f4fcffc9f19dca0888d61e2b33d5f
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
@@ -1,4 +1,5 @@
using AutoMapper;
using Microsoft.IdentityModel.Tokens;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -72,13 +73,28 @@
                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                #endregion
                List<string> LocationCodes = orderAddDTO.Details
                    .Where(x => !string.IsNullOrEmpty(x.LocationCode))
                    .Select(x => x.LocationCode).ToList();
                Dt_InboundOrder inboundOrder = _mapper.Map<Dt_InboundOrder>(orderAddDTO);
                //inboundOrder.OrderNo = DateTime.Now.ToString("yyMMddHHmmss");
                inboundOrder.OrderStatus = InboundStatusEnum.未开始.ObjToInt();
                bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                Db.Ado.BeginTran();
                if (LocationCodes.Any())
                {
                    content = _basicService.LocationInfoService.UpdateStatus(LocationCodes, LocationStatusEnum.PalletLock.ObjToInt());
                    if (!content.Status)
                        throw new Exception(content.Message);
                }
                BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                Db.Ado.CommitTran();
                content = WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            finally
@@ -88,6 +104,54 @@
            return content;
        }
        public override WebResponseContent UpdateData(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (saveModel.DetailData == null || saveModel.DetailData.Count == 0) throw new Exception($"入库单明细不能为空");
                List<InboundOrderDetailAddDTO> inboundOrderDetail = saveModel.DetailData.DicToIEnumerable<InboundOrderDetailAddDTO>();
                if (inboundOrderDetail.FirstOrDefault(x => x.OrderDetailStatus > 0) != null) throw new Exception($"订单已开始组盘入库");
                var inboundOrderDetails = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>().Where(x => saveModel.DelKeys.Contains(x.Id)).ToList();
                if (inboundOrderDetails.Count > 0)
                {
                    if (inboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt()) != null)
                        throw new Exception($"存在已组盘工单,已先解盘");
                }
                content = base.UpdateData(saveModel);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        public override WebResponseContent DeleteData(object[] keys)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var inboundOrders = BaseDal.QueryData(x => keys.Contains(x.Id));
                if (inboundOrders.FirstOrDefault(x => x.OrderStatus != InboundStatusEnum.未开始.ObjToInt()) != null)
                    throw new Exception($"入库单存在组盘入库信息");
                foreach (var inboundOrder in inboundOrders)
                {
                    var inboundOrderDetails = BaseDal.Db.Queryable<Dt_InboundOrder>().Includes(x => x.Details).First(x => x.OrderNo == inboundOrder.OrderNo).Details;
                    if (inboundOrderDetails != null || inboundOrderDetails.Count > 0)
                    {
                        if (inboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt()) != null)
                            throw new Exception($"入库单【{inboundOrder.OrderNo}】存在组盘入库信息");
                    }
                }
                content = base.DeleteData(keys);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// éªŒè¯å•据添加DTO对象
        /// </summary>