// POST: api/DeliveryorderConfirm public DeliveryorderConfirmResponse Post([FromBody] DeliveryorderConfirmRequest value, string customerId) { DeliveryorderConfirmResponse response = new DeliveryorderConfirmResponse(); response.Message = "测试通过"; response.Flag = "success"; response.Code = "1"; return(response); }
/// <summary> /// 发货单确认 /// </summary> public bool DeliveryorderConfirm() { log.Info("----------------启用定时任务:发货单确认" + DateTime.Now.Hour + "--------------"); try { dbContext = new SCVDBContainer(); DbSet <SHIPMENT_HEADER> dbset0 = dbContext.Set <SHIPMENT_HEADER>(); DbSet <SHIPMENT_DETAIL> dbset1 = dbContext.Set <SHIPMENT_DETAIL>(); DbSet <SHIPMENT_HEADER_TEMP> dbset_Temp = dbContext.Set <SHIPMENT_HEADER_TEMP>(); IQimenClient client = new DefaultQimenClient(url, appkey, secret); DeliveryorderConfirmRequest req = new DeliveryorderConfirmRequest(); DeliveryorderConfirmResponse rsp = new DeliveryorderConfirmResponse(); DeliveryorderConfirmRequest.DeliveryOrderDomain obj1 = new DeliveryorderConfirmRequest.DeliveryOrderDomain(); DeliveryorderConfirmRequest.PackageDomain package = new DeliveryorderConfirmRequest.PackageDomain(); List <DeliveryorderConfirmRequest.PackageDomain> packageList = new List <DeliveryorderConfirmRequest.PackageDomain>(); DeliveryorderConfirmRequest.ItemDomain itemDomain = new DeliveryorderConfirmRequest.ItemDomain(); List <DeliveryorderConfirmRequest.ItemDomain> itemList = new List <DeliveryorderConfirmRequest.ItemDomain>(); DeliveryorderConfirmRequest.OrderLineDomain orderLine = new DeliveryorderConfirmRequest.OrderLineDomain(); List <DeliveryorderConfirmRequest.OrderLineDomain> orderLineList = new List <DeliveryorderConfirmRequest.OrderLineDomain>(); for (int i = 0; i < customerArr.Length; i++) { var confirmlList = dbset0 .Where(t => t.TRAILING_STS.ToString() == "900" && ( t.SHIPMENT_TYPE == "JYCK" || t.SHIPMENT_TYPE == "HHCK" || t.SHIPMENT_TYPE == "BFCK" || t.SHIPMENT_TYPE == "QTCK") && t.COMPANY == customeId) .OrderByDescending(t => t.INTERNAL_SHIPMENT_NUM) .Take(100).AsNoTracking().ToList(); var confirmTempList = dbset_Temp .Where(t => t.TRAILING_STS.ToString() == "900" && ( t.SHIPMENT_TYPE == "JYCK" || t.SHIPMENT_TYPE == "HHCK" || t.SHIPMENT_TYPE == "BFCK" || t.SHIPMENT_TYPE == "QTCK") && t.COMPANY == customeId) .OrderBy(t => t.INTERNAL_SHIPMENT_NUM) .Take(100).AsNoTracking().ToList(); List <SHIPMENT_DETAIL> detailList = new List <SHIPMENT_DETAIL>(); List <SHIPMENT_HEADER_TEMP> tempList = new List <SHIPMENT_HEADER_TEMP>(); confirmlList = confirmlList .Where(a => !confirmTempList.Exists(t => a.INTERNAL_SHIPMENT_NUM.ToString() == t.INTERNAL_SHIPMENT_NUM.ToString())) .OrderByDescending(t => t.INTERNAL_SHIPMENT_NUM).ToList(); req.CustomerId = customerArr[i].Trim(); req.Version = v; req.Timestamp = DateTime.Now; if (confirmlList.Count == 0) { log.Info("客户:" + req.CustomerId + " " + "需确认的发货单为空,不需要确认!!!"); continue; } foreach (var item in confirmlList) { detailList = dbset1.Where(t => t.INTERNAL_SHIPMENT_NUM == item.INTERNAL_SHIPMENT_NUM).ToList(); obj1.DeliveryOrderCode = item.SHIPMENT_ID; obj1.WarehouseCode = item.WAREHOUSE; obj1.OrderType = item.SHIPMENT_TYPE; //"JYCK" obj1.ConfirmType = 0L; //仅仅确认最终状态的订单 obj1.OutBizCode = Guid.NewGuid().ToString(); req.DeliveryOrder = obj1; foreach (var itemChildren in detailList) { itemDomain.ItemCode = itemChildren.ITEM; itemDomain.Quantity = (long)itemChildren.REQUEST_QTY; itemList.Add(itemDomain); package.ExpressCode = item.SHIPPING_CONTAINER.Where(t => t.PARENT == 0 && t.STATUS == 900).FirstOrDefault().TRACKING_NUMBER; package.LogisticsCode = item.CARRIER;// item.CARRIER; //"SF";随便设置值 package.Items = itemList; packageList.Add(package); orderLine.PlanQty = itemChildren.REQUEST_QTY.ToString(); orderLine.ItemCode = itemChildren.ITEM; orderLine.ActualQty = itemChildren.REQUEST_QTY.ToString(); orderLineList.Add(orderLine); } req.Packages = packageList; req.OrderLines = orderLineList; try { rsp = client.Execute(req); log.Info(" " + "发货单确认--单号:" + item.INTERNAL_SHIPMENT_NUM + " " + "确认:" + rsp.Flag + " " + "消息:" + rsp.Message); } catch (Exception ex) { log.Error("Error", ex); continue; } if (rsp.Flag == "success") { SHIPMENT_HEADER_TEMP headerTemp = new SHIPMENT_HEADER_TEMP() { COMPANY = item.COMPANY, INTERNAL_SHIPMENT_NUM = item.INTERNAL_SHIPMENT_NUM, TRAILING_STS = item.TRAILING_STS, LEADING_STS = item.LEADING_STS, SHIPMENT_ID = item.SHIPMENT_ID, WAREHOUSE = item.WAREHOUSE, SHIPMENT_TYPE = item.SHIPMENT_TYPE, FLAG = rsp.Flag, CODE = rsp.Code, MESSAGE = rsp.Message, DATE_TIME_STAMP = DateTime.Now, }; dbset_Temp.Add(headerTemp); } } dbContext.SaveChanges(); } return(true); } catch (Exception ex) { log.Error("Error", ex); return(false); } }