using AutoMapper; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; 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, 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; } /// /// 添加单据 /// /// /// public override WebResponseContent AddData(SaveModel saveModel) { InboundOrderAddDTO orderAddDTO = saveModel.MainData.DicToModel(); orderAddDTO.Details = saveModel.DetailData.DicToIEnumerable(); return AddInboundOrder(orderAddDTO); } /// /// 添加单据 /// /// 单据添加DTO /// 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(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; } /// /// 验证单据添加DTO对象 /// /// 单据添加DTO /// 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 inOrderTypes = Enum.GetValues().Cast(); if (!inOrderTypes.Contains(inboundOrderAddDTO.OrderType)) { return (false, "未找到该单据类型", inboundOrderAddDTO); } List 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); } } }