| | |
| | | 锘縰sing AutoMapper; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | |
| | | private readonly IStockInfoService _stockInfoService; |
| | | private readonly IStockInfoDetailService _stockDetailService; |
| | | |
| | | public IOutboundOrderRepository Repository => BaseDal; |
| | | |
| | | public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IMaterielInfoService materielInfoService, IStockInfoDetailService stockDetailService, IStockInfoService stockInfoService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | |
| | | public override WebResponseContent AddData(SaveModel saveModel) |
| | | { |
| | | OutboundOrderAddDTO outboundOrder = saveModel.MainData.DicToModel<OutboundOrderAddDTO>(); |
| | | outboundOrder.Details = saveModel.DetailData.DicToIEnumerable<OutboundOrderDetailAddDTO>(); |
| | | 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(); |
| | | 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) |
| | |
| | | { |
| | | |
| | | } |
| | | catch(Exception ex) |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | |
| | | } |
| | | } |