| | |
| | | public partial class OutboundOrderService : ServiceBase<Dt_OutboundOrder, IOutboundOrderRepository>, IOutboundOrderService |
| | | { |
| | | private readonly IMapper _mapper; |
| | | private readonly IMaterielInfoService _materielInfoService; |
| | | private readonly IStockInfoService _stockService; |
| | | private readonly IStockInfoDetailService _stockDetailService; |
| | | |
| | | public IOutboundOrderRepository Repository => BaseDal; |
| | | |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IMaterielInfoService materielInfoService, IStockInfoDetailService stockDetailService, IStockInfoService stockInfoService) : base(BaseDal) |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _materielInfoService = materielInfoService; |
| | | _stockDetailService = stockDetailService; |
| | | _stockService = stockInfoService; |
| | | } |
| | | |
| | | 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), |
| | | MaterielName= x.FirstOrDefault()?.MaterielName ?? "", |
| | | Remark = x.FirstOrDefault(v => !string.IsNullOrEmpty(v.Remark))?.Remark ?? "" |
| | | }).ToList(); |
| | | return AddOutboundOrder(outboundOrder); |
| | | } |
| | | |
| | | public override WebResponseContent UpdateData(SaveModel saveModel) |
| | | { |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = saveModel.DetailData.DicToIEnumerable<Dt_OutboundOrderDetail>(); |
| | | if (outboundOrderDetails.GroupBy(x => x.MaterielCode).Select(x => x.Count()).Any(x => x > 1)) |
| | | { |
| | | 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(); |
| | | foreach (var item in outboundOrderDetails) |
| | | { |
| | | string str = JsonConvert.SerializeObject(item, settings); |
| | | Dictionary<string, object>? dic = JsonConvert.DeserializeObject<Dictionary<string, object>>(str); |
| | | if (dic != null) |
| | | dics.Add(dic); |
| | | } |
| | | saveModel.DetailData = dics; |
| | | return base.UpdateData(saveModel); |
| | | } |
| | | |
| | | public WebResponseContent AddOutboundOrder(OutboundOrderAddDTO orderAddDTO) |
| | | { |
| | | WebResponseContent content = new(); |
| | | try |
| | | { |
| | | #region éªè¯æ°æ® |
| | | (bool, string, object?) result = CheckOutboundOrderAddData(orderAddDTO); |
| | | if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); |
| | | #endregion |
| | | |
| | | Dt_OutboundOrder outboundOrder = _mapper.Map<Dt_OutboundOrder>(orderAddDTO); |
| | | outboundOrder.OrderStatus = OutOrderStatusEnum.æªå¼å§.ObjToInt(); |
| | | bool a = BaseDal.Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | finally |
| | | { |
| | | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | private (bool, string, object?) CheckOutboundOrderAddData(OutboundOrderAddDTO outboundOrderAddDTO) |
| | | { |
| | | (bool, string, object?) result1 = ModelValidate.ValidateModelData(outboundOrderAddDTO); |
| | | if (!result1.Item1) return result1; |
| | | |
| | | (bool, string, object?) result2 = ModelValidate.ValidateModelData(outboundOrderAddDTO.Details); |
| | | if (!result2.Item1) return result2; |
| | | |
| | | IEnumerable<int> inOrderTypes = Enum.GetValues<OutOrderTypeEnum>().Cast<int>(); |
| | | if (!inOrderTypes.Contains(outboundOrderAddDTO.OrderType)) |
| | | { |
| | | return (false, "æªæ¾å°è¯¥åæ®ç±»å", outboundOrderAddDTO); |
| | | } |
| | | |
| | | List<string> materielCodes = outboundOrderAddDTO.Details.Select(x => x.MaterielCode).ToList(); |
| | | if (!_materielInfoService.ExsitMateriels(materielCodes)) |
| | | { |
| | | return (false, "æç©æä¿¡æ¯æªå½å
¥ï¼è¯·å½å
¥ç©æä¿¡æ¯", outboundOrderAddDTO); |
| | | } |
| | | |
| | | if (BaseDal.QueryFirst(x => x.UpperOrderNo == outboundOrderAddDTO.UpperOrderNo && !string.IsNullOrEmpty(x.UpperOrderNo)) != null) |
| | | { |
| | | return (false, "忮已åå¨", outboundOrderAddDTO); |
| | | } |
| | | return (true, "æå", outboundOrderAddDTO); |
| | | } |
| | | |
| | | public WebResponseContent ReleaseOutOrder(int orderId) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public WebResponseContent GetOutboundOrder(OutboundOrderGetDTO outboundOrderGetDTO) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Expression<Func<Dt_OutboundOrder, bool>> expressionOrder = x => true; |
| | | if (!string.IsNullOrEmpty(outboundOrderGetDTO.OrderNo)) |
| | | { |
| | | expressionOrder = x => x.OrderNo.Contains(outboundOrderGetDTO.OrderNo); |
| | | } |
| | | int count = BaseDal.QueryData(x => x.OrderStatus == OutOrderStatusEnum.æªå¼å§.ObjToInt()).ToList().Count(); |
| | | int maxPage = Convert.ToInt32(Math.Ceiling(count / 10.0)); |
| | | if (outboundOrderGetDTO.pageNo <= maxPage) |
| | | { |
| | | var outboundOrder = BaseDal.Db.Queryable<Dt_OutboundOrder>().Where(expressionOrder).OrderByDescending(x => x.CreateDate).Skip((outboundOrderGetDTO.pageNo - 1) * 10).Take(10).Select(x => new Dt_OutboundOrder { OrderNo = x.OrderNo, Id = x.Id, CreateDate = x.CreateDate, Creater = x.Creater }).ToList(); |
| | | |
| | | content = WebResponseContent.Instance.OK(data: outboundOrder); |
| | | } |
| | | else |
| | | { |
| | | content = WebResponseContent.Instance.OK(data: null, message: "已尿åä¸é¡µ"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"æ¥è¯¢åºåºåæ®é误,é误信æ¯:{ex.Message}"); |
| | | } |
| | | |
| | | return content; |
| | | } |
| | | |
| | | public WebResponseContent GetOutboundOrderDetail(string OrderNo) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_OutboundOrder outboundOrder = BaseDal.QueryFirst(x => x.OrderNo == OrderNo); |
| | | |
| | | var outboundOrderDetail = BaseDal.Db.Queryable<Dt_OutboundOrderDetail>().Where(x => x.OrderId == outboundOrder.Id).Take(10).Select(x => new Dt_OutboundOrderDetail {Id=x.Id, MaterielCode = x.MaterielCode, MaterielName = x.MaterielName, OrderQuantity = x.OrderQuantity, OverOutQuantity = x.OverOutQuantity, LockQuantity = x.LockQuantity }).ToList(); |
| | | |
| | | content = WebResponseContent.Instance.OK(data: outboundOrderDetail); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"æ¥è¯¢åºåºåæ®æç»é误,é误信æ¯:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |