From c020f31a67fc5aa5644511bddff075f7ecc85234 Mon Sep 17 00:00:00 2001 From: qinchulong <qinchulong@hnkhzn.com> Date: 星期二, 27 五月 2025 15:35:27 +0800 Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/HuaYiZhongHeng/ZhongHeLiTiKu --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 173 insertions(+), 0 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs" new file mode 100644 index 0000000..3005140 --- /dev/null +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs" @@ -0,0 +1,173 @@ +锘縰sing AutoMapper; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection.Metadata; +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; +using WIDESEA_DTO.Inbound; +using WIDESEA_IBasicService; +using WIDESEA_IInboundRepository; +using WIDESEA_IInboundService; +using WIDESEA_IStockService; +using WIDESEA_ITaskInfoRepository; +using WIDESEA_Model.Models; + +namespace WIDESEA_InboundService +{ + public partial class InboundOrderService : ServiceBase<Dt_InboundOrder, IInboundOrderRepository>, IInboundOrderService + { + private readonly IMapper _mapper; + private readonly IUnitOfWorkManage _unitOfWorkManage; + private readonly ITaskRepository _taskRepository; + + private IBasicService _basicService; + private IStockService _stockService; + private IInboundOrderDetailService _inboundOrderDetailService; + + public IInboundOrderRepository Repository => BaseDal; + + public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IBasicService basicService, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService) : base(BaseDal) + { + _mapper = mapper; + _unitOfWorkManage = unitOfWorkManage; + _taskRepository = taskRepository; + _basicService = basicService; + _stockService = stockService; + _inboundOrderDetailService = inboundOrderDetailService; + } + + /// <summary> + /// 娣诲姞鍗曟嵁 + /// </summary> + /// <param name="saveModel"></param> + /// <returns></returns> + public override WebResponseContent AddData(SaveModel saveModel) + { + InboundOrderAddDTO orderAddDTO = saveModel.MainData.DicToModel<InboundOrderAddDTO>(); + orderAddDTO.Details = saveModel.DetailData.DicToIEnumerable<InboundOrderDetailAddDTO>(); + return AddInboundOrder(orderAddDTO); + } + + /// <summary> + /// 娣诲姞鍗曟嵁 + /// </summary> + /// <param name="orderAddDTO">鍗曟嵁娣诲姞DTO</param> + /// <returns></returns> + public WebResponseContent AddInboundOrder(InboundOrderAddDTO orderAddDTO) + { + WebResponseContent content = new(); + try + { + #region 楠岃瘉鏁版嵁 + (bool, string, object?) result = CheckInboundOrderAddData(orderAddDTO); + if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); + #endregion + + Dt_InboundOrder inboundOrder = _mapper.Map<Dt_InboundOrder>(orderAddDTO); + inboundOrder.OrderStatus = InboundStatusEnum.鏈紑濮�.ObjToInt(); + bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); + content = WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + content = WebResponseContent.Instance.Error(ex.Message); + } + finally + { + + } + return content; + } + + /// <summary> + /// 楠岃瘉鍗曟嵁娣诲姞DTO瀵硅薄 + /// </summary> + /// <param name="inboundOrderAddDTO">鍗曟嵁娣诲姞DTO</param> + /// <returns></returns> + private (bool, string, object?) CheckInboundOrderAddData(InboundOrderAddDTO inboundOrderAddDTO) + { + (bool, string, object?) result1 = ModelValidate.ValidateModelData(inboundOrderAddDTO); + if (!result1.Item1) return result1; + + (bool, string, object?) result2 = ModelValidate.ValidateModelData(inboundOrderAddDTO.Details); + if (!result2.Item1) return result2; + + IEnumerable<int> inOrderTypes = Enum.GetValues<InOrderTypeEnum>().Cast<int>(); + if (!inOrderTypes.Contains(inboundOrderAddDTO.OrderType)) + { + return (false, "鏈壘鍒拌鍗曟嵁绫诲瀷", inboundOrderAddDTO); + } + + List<string> materielCodes = inboundOrderAddDTO.Details.Select(x => x.MaterielCode).ToList(); + if (!_basicService.MaterielInfoService.ExsitMateriels(materielCodes)) + { + return (false, "鏈夌墿鏂欎俊鎭湭褰曞叆锛岃褰曞叆鐗╂枡淇℃伅", inboundOrderAddDTO); + } + + if (BaseDal.QueryFirst(x => x.UpperOrderNo == inboundOrderAddDTO.UpperOrderNo && !string.IsNullOrEmpty(x.UpperOrderNo)) != null) + { + return (false, "鍗曟嵁宸插瓨鍦�", inboundOrderAddDTO); + } + return (true, "鎴愬姛", inboundOrderAddDTO); + } + + public WebResponseContent GetInboundOrder(InboundOrderGetDTO inboundOrderGetDTO) + { + WebResponseContent content = new WebResponseContent(); + try + { + Expression<Func<Dt_InboundOrder, bool>> expressionOrder = x => true; + if (!string.IsNullOrEmpty(inboundOrderGetDTO.OrderNo)) + { + expressionOrder = x => x.OrderNo.Contains(inboundOrderGetDTO.OrderNo); + } + int count = BaseDal.QueryData(x => x.OrderStatus == InboundStatusEnum.鏈紑濮�.ObjToInt()).ToList().Count(); + int maxPage = Convert.ToInt32(Math.Ceiling(count / 10.0)); + if (inboundOrderGetDTO.pageNo <= maxPage) + { + var inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(expressionOrder).OrderByDescending(x => x.CreateDate).Skip((inboundOrderGetDTO.pageNo - 1) * 10).Take(10).Select(x => new Dt_InboundOrder { OrderNo = x.OrderNo, Id = x.Id, CreateDate = x.CreateDate,Creater=x.Creater }).ToList(); + + content = WebResponseContent.Instance.OK(data: inboundOrder); + } + else + { + content = WebResponseContent.Instance.OK(data: null, message: "宸插埌鏈�鍚庝竴椤�"); + } + } + catch (Exception ex) + { + content = WebResponseContent.Instance.Error($"鏌ヨ鍏ュ簱鍗曟嵁閿欒,閿欒淇℃伅:{ex.Message}"); + } + + return content; + } + + public WebResponseContent GetInboundOrderDetail(string OrderNo) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_InboundOrder inboundOrder = BaseDal.QueryFirst(x => x.OrderNo==OrderNo); + + var inboundOrderDetail = BaseDal.Db.Queryable<Dt_InboundOrderDetail>().Where(x=>x.OrderId==inboundOrder.Id).Take(10).Select(x => new Dt_InboundOrderDetail { MaterielCode = x.MaterielCode, MaterielName = x.MaterielName, OrderQuantity = x.OrderQuantity, ReceiptQuantity = x.ReceiptQuantity, OverInQuantity=x.OverInQuantity }).ToList(); + + content = WebResponseContent.Instance.OK(data: inboundOrderDetail); + } + catch (Exception ex) + { + content = WebResponseContent.Instance.Error($"鏌ヨ鍏ュ簱鍗曟嵁鏄庣粏閿欒,閿欒淇℃伅:{ex.Message}"); + } + return content; + } + } +} -- Gitblit v1.9.3