public SCVBaseRepository() { //关闭 EF容器的 为空检查 db.Configuration.ValidateOnSaveEnabled = false; //在构造函数中 实例化 dbSet //2.通过EF容器对象 获取 一个 DbSet<T> 用来操作 和 TEntity实体类 对应的数据表 dbSet = db.Set <T>(); }
// POST: api/EntryorderQuery public EntryOrderQueryResponseModel Post([FromBody] EntryOrderQueryRequestModel model) { EntryOrderQueryResponseModel response = new EntryOrderQueryResponseModel(); using (SCVDBContainer dbContext = new SCVDBContainer()) { DbSet <RECEIPT_HEADER> dbSet0 = dbContext.Set <RECEIPT_HEADER>(); DbSet <RECEIPT_DETAIL> dbSet1 = dbContext.Set <RECEIPT_DETAIL>(); RECEIPT_HEADER header = dbSet0.FirstOrDefault(h => h.RECEIPT_ID == model.EntryOrderCode && h.COMPANY == model.OwnerCode); if (header == null) { response.Flag = "failure"; response.Code = "-1"; response.Message = "无此入库单"; response.TotalLines = 0; return(response); } EntryOrder entryOrder = new EntryOrder(); entryOrder.EntryOrderCode = model.EntryOrderCode; entryOrder.OwnerCode = header.COMPANY; entryOrder.WarehouseCode = "LK01"; entryOrder.EntryOrderId = header.INTERNAL_RECEIPT_NUM.ToString(); entryOrder.EntryOrderType = header.RECEIPT_TYPE; entryOrder.Status = header.TRAILING_STS.ToString(); List <OrderLine> orderLines = new List <OrderLine>(); foreach (var item in header.RECEIPT_DETAIL) { OrderLine orderLine = new OrderLine(); orderLine.OrderLineNo = item.INTERNAL_RECEIPT_LINE_NUM.ToString(); orderLine.ItemCode = item.ITEM; orderLine.ItemId = item.INTERNAL_RECEIPT_NUM.ToString(); orderLine.ItemName = item.ITEM_DESC; orderLine.PlanQty = Convert.ToInt32(item.TOTAL_QTY); orderLine.ActualQty = Convert.ToInt32(item.OPEN_QTY); orderLines.Add(orderLine); } response.Flag = "success"; response.Code = "1"; response.Message = "查询成功"; response.TotalLines = header.RECEIPT_DETAIL.Count(); response.EntryOrder = entryOrder; response.OrderLines = orderLines; } return(response); }
// POST: api/DeliveryorderQuery public DeliveryorderQueryResponseModel Post([FromBody] DeliveryorderQueryRequestModel model) { DeliveryorderQueryResponseModel response = new DeliveryorderQueryResponseModel(); using (SCVDBContainer dbContext = new SCVDBContainer()) { DbSet <SHIPMENT_HEADER> dbSet0 = dbContext.Set <SHIPMENT_HEADER>(); DbSet <SHIPMENT_DETAIL> dbSet1 = dbContext.Set <SHIPMENT_DETAIL>(); SHIPMENT_HEADER header = dbSet0.FirstOrDefault(h => h.SHIPMENT_ID == model.OrderCode && h.COMPANY == model.OwnerCode); if (header == null) { response.Flag = "failure"; response.Code = "-1"; response.Message = "无此出库单"; response.TotalLines = 0; return(response); } int page = (int)model.Page; int pageSize = (int)model.PageSize; response.Flag = "success"; response.Code = "1"; response.Message = "查询成功"; response.TotalLines = header.SHIPMENT_DETAIL.Count(); DeliveryorderQueryResponseModel.DeliveryOrderDomain deliveryOrder = new DeliveryorderQueryResponseModel.DeliveryOrderDomain(); DeliveryorderQueryResponseModel.PackageDomain package = new DeliveryorderQueryResponseModel.PackageDomain(); List <DeliveryorderQueryResponseModel.PackageDomain> packages = new List <DeliveryorderQueryResponseModel.PackageDomain>(); DeliveryorderQueryResponseModel.OrderLineDomain orderLine = new DeliveryorderQueryResponseModel.OrderLineDomain(); List <DeliveryorderQueryResponseModel.OrderLineDomain> orderLines = new List <DeliveryorderQueryResponseModel.OrderLineDomain>(); deliveryOrder.DeliveryOrderCode = header.SHIPMENT_ID; deliveryOrder.DeliveryOrderId = header.INTERNAL_SHIPMENT_NUM.ToString(); deliveryOrder.WarehouseCode = header.WAREHOUSE; deliveryOrder.OrderType = header.SHIPMENT_TYPE; if (header.LEADING_STS == 900 && header.TRAILING_STS == 900) { deliveryOrder.Status = DeliveryorderQueryStatusEnum.DELIVERED.ToString(); } } return(response); }
// POST: api/SingleitemSynchronize public SingleitemSynchronizeResponseModel Post([FromBody] SingleitemSynchronizeRequestModel model, string customerId) { //测试相关 //if (customerId == "c1515046170643") //{ // customerId = "HPH"; //} //--------------------------------- if (customerId == "CH1") { customerId = "CH"; } SingleitemSynchronizeResponseModel response = new SingleitemSynchronizeResponseModel(); using (DBContainer context = new DBContainer()) { QiMen_RequestLog log = new QiMen_RequestLog(); HttpContextBase ctx = (HttpContextBase)Request.Properties["MS_HttpContext"]; string body = ApiUtils.GetStreamAsString(ctx.Request.InputStream, new UTF8Encoding(false)); string ip = ctx.Request.UserHostAddress; log.Interface = "SingleitemSynchronize"; log.Url = Request.RequestUri.AbsoluteUri; log.Ip = ip; log.CustomerId = customerId; log.RequestBody = body; context.QiMen_RequestLog.Add(log); context.SaveChanges(); } using (SCVDBContainer dbContext = new SCVDBContainer()) { DbSet <ITEM> dbSet = dbContext.Set <ITEM>(); DbSet <ITEM_UNIT_OF_MEASURE> dbSet1 = dbContext.Set <ITEM_UNIT_OF_MEASURE>(); Apps.Models.ITEM scvItem = null; if (model.ActionType == "update") { scvItem = dbSet.FirstOrDefault(i => i.ITEM1 == model.Item.ItemCode && i.COMPANY == customerId); if (scvItem != null) { scvItem.COMPANY = model.OwnerCode; scvItem.ITEM1 = model.Item.ItemCode; scvItem.ITEM_DESC = model.Item.ItemName; scvItem.STORAGE_TEMPLATE = "三层模板"; scvItem.ACTIVE = "Y"; scvItem.DATE_TIME_STAMP = DateTime.Now; scvItem.ATTRIBUTE_TRACK = "N"; scvItem.ITEM_SIZE = model.Item.SkuProperty; scvItem.ITEM_COLOR = model.Item.Color; scvItem.ITEM_STYLE = model.Item.GoodsCode; } } if (model.ActionType == "add") { scvItem = new Apps.Models.ITEM(); scvItem.COMPANY = model.OwnerCode; scvItem.ITEM1 = model.Item.ItemCode; scvItem.ITEM_DESC = model.Item.ItemName; scvItem.STORAGE_TEMPLATE = "三层模板"; scvItem.ACTIVE = "Y"; scvItem.DATE_TIME_STAMP = DateTime.Now; scvItem.ATTRIBUTE_TRACK = "N"; scvItem.ITEM_SIZE = model.Item.SkuProperty; scvItem.ITEM_COLOR = model.Item.Color; scvItem.ITEM_STYLE = model.Item.GoodsCode; var scvItemUnit = dbSet1.FirstOrDefault(u => u.ITEM == model.Item.ItemCode && u.COMPANY == customerId); if (scvItemUnit == null) { scvItemUnit = new Apps.Models.ITEM_UNIT_OF_MEASURE(); scvItemUnit.ITEM = model.Item.ItemCode; scvItemUnit.COMPANY = customerId; scvItemUnit.SEQUENCE = 1; scvItemUnit.QUANTITY_UM = "EA"; scvItemUnit.CONVERSION_QTY = 1; scvItemUnit.LENGTH = model.Item.Length; scvItemUnit.WIDTH = model.Item.Width; scvItemUnit.HEIGHT = model.Item.Height; scvItemUnit.DIMENSION_UM = "CM"; scvItemUnit.WEIGHT = model.Item.GrossWeight; scvItemUnit.WEIGHT_UM = "KG"; scvItemUnit.USER_STAMP = "Interface"; scvItemUnit.DATE_TIME_STAMP = DateTime.Now; scvItemUnit.TREAT_FULL_PCT = 100; scvItemUnit.TREAT_AS_LOOSE = "Y"; scvItemUnit.GROUP_DURING_CHECKIN = "Y"; scvItemUnit.USER_DEF7 = "0"; scvItemUnit.USER_DEF8 = "0"; dbSet1.Add(scvItemUnit); } dbSet.Add(scvItem); } if (dbContext.SaveChanges() >= 0) { response.Code = "0"; response.Flag = "success"; response.Message = "商品同步成功"; response.ItemId = scvItem.INTERNAL_ITEM_NUM.ToString(); } else { response.Code = "-1"; response.Flag = "failure"; response.Message = "商品同步失败,请重试"; } } return(response); }
public void Execute(IJobExecutionContext context) { string url = ConfigurationManager.AppSettings["URL"].ToString(); string appkey = ConfigurationManager.AppSettings["APPKEY"].ToString(); //"1023883919"; 23883919 string secret = ConfigurationManager.AppSettings["SECRET"].ToString(); //"sandboxff0b11ecc626508c171a5b2a2"; string customeId = ConfigurationManager.AppSettings["CUSTOMEID"].ToString(); string v = ConfigurationManager.AppSettings["v"].ToString(); string[] customerArr = customeId.Split(','); try { _logger.Info("ReturnorderConfirm 开始执行... " + DateTime.Now + ""); foreach (var cId in customerArr) { using (SCVDBContainer dbContext0 = new SCVDBContainer()) using (DBContainer dbContext1 = new DBContainer()) { DbSet <RECEIPT_HEADER> header = dbContext0.Set <RECEIPT_HEADER>(); DbSet <RECEIPT_DETAIL> detail = dbContext0.Set <RECEIPT_DETAIL>(); //DbSet<QiMen_PushTimeStatus> dbSet0 = dbContext1.Set<QiMen_PushTimeStatus>(); DbSet <QiMen_PushLog> dbSet1 = dbContext1.Set <QiMen_PushLog>(); IQimenClient client = new DefaultQimenClient(url, appkey, secret); ReturnorderConfirmRequest req = new ReturnorderConfirmRequest(); //DateTime lastTime; //QiMen_PushTimeStatus qmt = dbSet0.Where(q => q.CustomerId == cId && q.OrderType == RECEIPT && q.Interface == INTERFACE).FirstOrDefault(); //if (qmt == null) //{ // qmt = new QiMen_PushTimeStatus() { CustomerId = cId, ActualArriveTime = DateTime.Now, OrderType = RECEIPT, Interface = INTERFACE }; // dbSet0.Add(qmt); // lastTime = DateTime.Now.AddMinutes(-1); //} //else //{ // lastTime = ((DateTime)qmt.ActualArriveTime).AddMinutes(-1); //} //var confirmlList = header.Where(h => h.COMPANY == cId && h.TRAILING_STS == 900 && (h.RECEIPT_TYPE).Equals("THRK",StringComparison.OrdinalIgnoreCase) && h.CLOSE_DATE >= lastTime).Include(r => r.RECEIPT_DETAIL).OrderByDescending(h => h.CLOSE_DATE).ToList(); var confirmlList = header.Where(h => h.COMPANY == cId && h.CREATE_USER == "ReturnorderCreate" && (h.USER_DEF8 == null || h.USER_DEF8 == QimenPushStatus.Failure.ToString() || h.USER_DEF8 == "1" || h.USER_DEF8 == "2" || h.USER_DEF8 == "3" || h.USER_DEF8 == "4" || h.USER_DEF8 == "5") && (h.TRAILING_STS == 800 || h.TRAILING_STS == 850 || h.TRAILING_STS == 900) && h.RECEIPT_TYPE.Equals("THRK", StringComparison.OrdinalIgnoreCase) ).Include(s => s.RECEIPT_DETAIL).ToList(); if (cId == "XGQQG") { confirmlList.Clear(); } //if (cId == "CQHGE") //{ // confirmlList = confirmlList.Where(l => l.CREATE_USER == "ReturnorderCreate").ToList(); //} if (cId == "CH") { req.CustomerId = "CH1"; } else { req.CustomerId = cId; } req.Version = v; req.Timestamp = DateTime.Now; //bool pushFlag = true; foreach (var itemHeader in confirmlList) { ReturnorderConfirmRequest.ReturnOrderDomain returnOrder = new ReturnorderConfirmRequest.ReturnOrderDomain(); returnOrder.ReturnOrderCode = itemHeader.RECEIPT_ID; //"R1234";//item.ERP_ORDER_ID; returnOrder.WarehouseCode = itemHeader.WAREHOUSE; returnOrder.LogisticsCode = ""; //"SF";//item.CARRER; returnOrder.OutBizCode = itemHeader.INTERNAL_RECEIPT_NUM.ToString(); returnOrder.OrderType = itemHeader.RECEIPT_TYPE; ReturnorderConfirmRequest.SenderInfoDomain senderInfo = new ReturnorderConfirmRequest.SenderInfoDomain(); senderInfo.Name = itemHeader.SHIP_FROM_NAME; //"老王";// senderInfo.Mobile = itemHeader.SHIP_FROM_PHONE_NUM; //"13214567869";// senderInfo.Province = itemHeader.SHIP_FROM_COUNTRY; //"浙江省";// senderInfo.City = itemHeader.SHIP_FROM_CITY; //"杭州"; // senderInfo.DetailAddress = itemHeader.SHIP_FROM_ADDRESS1 != null ? itemHeader.SHIP_FROM_ADDRESS1 : itemHeader.SHIP_FROM_ADDRESS2; //"杭州市余杭区989号";// returnOrder.SenderInfo = senderInfo; req.ReturnOrder = returnOrder; List <ReturnorderConfirmRequest.OrderLineDomain> orderLineList = new List <ReturnorderConfirmRequest.OrderLineDomain>(); foreach (var itemDetail in itemHeader.RECEIPT_DETAIL) { ReturnorderConfirmRequest.OrderLineDomain orderLine = new ReturnorderConfirmRequest.OrderLineDomain(); orderLine.ItemId = itemDetail.INTERNAL_RECEIPT_LINE_NUM.ToString(); orderLine.ItemName = itemDetail.ITEM_DESC; orderLine.OwnerCode = itemDetail.COMPANY; orderLine.ItemCode = itemDetail.ITEM; orderLine.PlanQty = (long)itemDetail.TOTAL_QTY; orderLine.ActualQty = (itemDetail.TOTAL_QTY - itemDetail.OPEN_QTY).ToString(); orderLine.OutBizCode = itemDetail.INTERNAL_RECEIPT_LINE_NUM.ToString(); orderLineList.Add(orderLine); } req.OrderLines = orderLineList; var rsp = client.Execute(req); QiMen_PushLog log = new QiMen_PushLog(); log.InternalOrderID = itemHeader.INTERNAL_RECEIPT_NUM; log.OrderType = INTERFACE; log.CustomerId = cId; log.Flag = rsp.Flag; log.Message = rsp.Message; log.CreateTime = DateTime.Now; dbSet1.Add(log); if (rsp.Flag == "success") { itemHeader.USER_DEF8 = QimenPushStatus.Success.ToString(); _logger.Info("入库单:" + itemHeader.RECEIPT_ID + "确认成功----" + DateTime.Now); } else { if (string.IsNullOrEmpty(itemHeader.USER_DEF8)) { itemHeader.USER_DEF8 = "1"; } else { int parseResult; if (int.TryParse(itemHeader.USER_DEF8, out parseResult)) { itemHeader.USER_DEF8 = (parseResult + 1).ToString(); } } //if (rsp.Message.Length > 50) //{ // pushFlag = false; //} _logger.Info("入库单:" + itemHeader.RECEIPT_ID + "确认失败:-" + rsp.Message + DateTime.Now); } } //if (confirmlList.Count > 0 && pushFlag) //{ // qmt.ActualArriveTime = (DateTime)confirmlList.First().CLOSE_DATE; //} dbContext0.SaveChanges(); dbContext1.SaveChanges(); } } _logger.Info("ReturnorderConfirm 执行完成... " + DateTime.Now + ""); } catch (Exception ex) { _logger.Error("ReturnorderConfirm 异常..." + DateTime.Now + " " + ex.Message); } }
// POST: api/DeliveryorderCreate public DeliveryorderCreateResponseModel Post([FromBody] DeliveryorderCreateRequestModel model, string customerId) { DeliveryorderCreateResponseModel response = new DeliveryorderCreateResponseModel(); if (customerId == "CH1") { customerId = "CH"; } using (DBContainer context = new DBContainer()) { QiMen_RequestLog log = new QiMen_RequestLog(); HttpContextBase ctx = (HttpContextBase)Request.Properties["MS_HttpContext"]; string body = ApiUtils.GetStreamAsString(ctx.Request.InputStream, new UTF8Encoding(false)); string ip = ctx.Request.UserHostAddress; log.Interface = "DeliveryorderCreate"; log.Url = Request.RequestUri.AbsoluteUri; log.Ip = ip; log.CustomerId = customerId; log.RequestBody = body; context.QiMen_RequestLog.Add(log); context.SaveChanges(); } using (SCVDBContainer dbContext = new SCVDBContainer()) { //DbSet<SHIPMENT_HEADER> dbSet0 = dbContext.Set<SHIPMENT_HEADER>(); //DbSet<SHIPMENT_DETAIL> dbSet1 = dbContext.Set<SHIPMENT_DETAIL>(); DbSet <ITEM> dbSetItem = dbContext.Set <ITEM>(); if (dbContext.SHIPMENT_HEADER.Where(h => h.SHIPMENT_ID == model.DeliveryOrder.DeliveryOrderCode && h.COMPANY == customerId).Any()) { response.Flag = "success"; response.Code = "0"; response.Message = model.DeliveryOrder.DeliveryOrderCode + ":单号重复"; response.DeliveryOrderId = ""; return(response); } SHIPMENT_HEADER header = new SHIPMENT_HEADER(); header.WAREHOUSE = "LK01"; header.COMPANY = customerId; header.USER_DEF2 = model.DeliveryOrder.ShopNick; header.SHIPMENT_NOTE = model.DeliveryOrder.SellerMessage; header.SHIPMENT_TYPE = model.DeliveryOrder.OrderType; header.SHIPMENT_ID = model.DeliveryOrder.DeliveryOrderCode; DateTime time; if (DateTime.TryParse(model.DeliveryOrder.CreateTime, out time)) { header.CREATE_DATE_TIME = time; } header.LEADING_STS = 100; header.TRAILING_STS = 100; header.SHIP_TO_NAME = model.DeliveryOrder.ReceiverInfo.Name; header.SHIP_TO_MOBILE = model.DeliveryOrder.ReceiverInfo.Mobile; header.SHIP_TO_DISTRICT = model.DeliveryOrder.ReceiverInfo.Area; header.SHIP_TO_CITY = model.DeliveryOrder.ReceiverInfo.City; header.SHIP_TO_STATE = model.DeliveryOrder.ReceiverInfo.Province; //header.SHIPMENT_NOTE = model.DeliveryOrder.ReceiverInfo.Remark; header.SHIP_TO_ADDRESS1 = model.DeliveryOrder.ReceiverInfo.DetailAddress; header.PROCESS_TYPE = "NORMAL"; header.CARRIER = model.DeliveryOrder.LogisticsCode; header.CREATE_USER = "******"; header.TOTAL_LINES = model.OrderLines.Count(); int totalQty = 0; foreach (var item in model.OrderLines) { SHIPMENT_DETAIL detail = new SHIPMENT_DETAIL(); detail.WAREHOUSE = "LK01"; detail.COMPANY = item.OwnerCode; detail.SHIPMENT_ID = model.DeliveryOrder.DeliveryOrderCode; detail.ITEM = item.ItemCode; ITEM sItem = dbSetItem.Where(t => t.ITEM1 == item.ItemCode).FirstOrDefault(); if (sItem != null) { detail.ITEM_DESC = sItem.ITEM_DESC; } //detail.ITEM_DESC = item.ItemName; detail.REQUEST_QTY = Convert.ToInt32(item.PlanQty); detail.QUANTITY_UM = "EA"; detail.DATE_TIME_STAMP = time; if (item.InventoryType == null) { detail.INVENTORY_STS = "合格"; } else { if (string.Equals("ZP", item.InventoryType, StringComparison.CurrentCultureIgnoreCase)) { detail.INVENTORY_STS = "合格"; } else { detail.INVENTORY_STS = "不合格"; } } //detail.INVENTORY_STS = item.InventoryType; detail.STATUS = 100; totalQty += Convert.ToInt32(item.PlanQty); header.SHIPMENT_DETAIL.Add(detail); } header.TOTAL_QTY = totalQty; dbContext.SHIPMENT_HEADER.Add(header); if (dbContext.SaveChanges() > 0) { response.Flag = "success"; response.Code = "1"; response.Message = model.DeliveryOrder.DeliveryOrderCode + ":创建成功"; response.DeliveryOrderId = header.INTERNAL_SHIPMENT_NUM.ToString(); } else { response.Flag = "failure"; response.Code = "-1"; response.Message = model.DeliveryOrder.DeliveryOrderCode + ":创建失败"; response.DeliveryOrderId = ""; } } return(response); }
/// <summary> /// 出库单确认 /// </summary> public bool StockoutConfirm() { 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_TEMP1> dbset_Temp = dbContext.Set <SHIPMENT_HEADER_TEMP1>(); IQimenClient client = new DefaultQimenClient(url, appkey, secret); StockoutConfirmRequest req = new StockoutConfirmRequest(); StockoutConfirmResponse rsp = new StockoutConfirmResponse(); StockoutConfirmRequest.DeliveryOrderDomain obj1 = new StockoutConfirmRequest.DeliveryOrderDomain(); StockoutConfirmRequest.PackageDomain package = new StockoutConfirmRequest.PackageDomain(); List <StockoutConfirmRequest.PackageDomain> packageList = new List <StockoutConfirmRequest.PackageDomain>(); StockoutConfirmRequest.ItemDomain itemDomain = new StockoutConfirmRequest.ItemDomain(); List <StockoutConfirmRequest.ItemDomain> itemDomainList = new List <StockoutConfirmRequest.ItemDomain>(); StockoutConfirmRequest.OrderLineDomain orderLine = new StockoutConfirmRequest.OrderLineDomain(); List <StockoutConfirmRequest.OrderLineDomain> orderLineList = new List <StockoutConfirmRequest.OrderLineDomain>(); for (int i = 0; i < customerArr.Length; i++) { var confirmlList = dbset0 .Where(t => t.TRAILING_STS.ToString() == "900" && 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.COMPANY == customeId) .OrderByDescending(t => t.INTERNAL_SHIPMENT_NUM) .Take(100).AsNoTracking().ToList(); List <SHIPMENT_DETAIL> detailList = new List <SHIPMENT_DETAIL>(); confirmlList = confirmlList .Where(a => !confirmTempList.Exists(t => a.INTERNAL_SHIPMENT_NUM == t.INTERNAL_SHIPMENT_NUM)) .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.DeliveryOrderId = item.SHIPMENT_ID.ToString(); obj1.OutBizCode = Guid.NewGuid().ToString(); obj1.DeliveryOrderCode = item.SHIPMENT_ID; obj1.WarehouseCode = item.WAREHOUSE; obj1.OrderType = item.SHIPMENT_TYPE; req.DeliveryOrder = obj1; foreach (var itemChildren in detailList) { itemDomain.ItemCode = itemChildren.ITEM; itemDomain.Quantity = (long)itemChildren.REQUEST_QTY; itemDomainList.Add(itemDomain); package.ExpressCode = item.SHIPPING_CONTAINER .Where(t => t.PARENT == 0 && t.STATUS == 900) .FirstOrDefault().TRACKING_NUMBER; package.Items = itemDomainList; package.LogisticsCode = item.CARRIER; packageList.Add(package); orderLine.ItemCode = itemChildren.ITEM; orderLine.ActualQty = (long)itemChildren.REQUEST_QTY; orderLineList.Add(orderLine); } req.OrderLines = orderLineList; req.Packages = packageList; 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_TEMP1 headerTemp = new SHIPMENT_HEADER_TEMP1() { LEADING_STS = item.LEADING_STS, DATE_TIME_STAMP = DateTime.Now, TRAILING_STS = item.TRAILING_STS, TOTAL_QTY = item.TOTAL_QTY, INTERNAL_SHIPMENT_NUM = item.INTERNAL_SHIPMENT_NUM, SHIPMENT_ID = item.SHIPMENT_ID, WAREHOUSE = item.WAREHOUSE, COMPANY = item.COMPANY, SHIPMENT_TYPE = item.SHIPMENT_TYPE, FLAG = rsp.Flag, CODE = rsp.Code, MESSAGE = rsp.Message }; dbset_Temp.Add(headerTemp); } } dbContext.SaveChanges(); } return(true); } catch (Exception ex) { log.Error("Error", ex); return(false); } }
/// <summary> /// 退货入库单确认 /// </summary> public bool ReturnorderConfirm() { log.Info("----------------启用定时任务:退货入库单确认" + DateTime.Now.Hour + "--------------"); try { dbContext = new SCVDBContainer(); DbSet <RECEIPT_HEADER> dbset0 = dbContext.Set <RECEIPT_HEADER>(); DbSet <RECEIPT_DETAIL> dbset1 = dbContext.Set <RECEIPT_DETAIL>(); DbSet <RECEIPT_HEADER_TEMP> dbset_Temp = dbContext.Set <RECEIPT_HEADER_TEMP>(); IQimenClient client = new DefaultQimenClient(url, appkey, secret); ReturnorderConfirmRequest req = new ReturnorderConfirmRequest(); ReturnorderConfirmResponse rsp = new ReturnorderConfirmResponse(); //退货单信息 ReturnorderConfirmRequest.ReturnOrderDomain obj1 = new ReturnorderConfirmRequest.ReturnOrderDomain(); //发件人信息 ReturnorderConfirmRequest.SenderInfoDomain send = new ReturnorderConfirmRequest.SenderInfoDomain(); //订单信息 ReturnorderConfirmRequest.OrderLineDomain orderLine = new ReturnorderConfirmRequest.OrderLineDomain(); List <ReturnorderConfirmRequest.OrderLineDomain> orderLineList = new List <ReturnorderConfirmRequest.OrderLineDomain>(); for (int i = 0; i < customerArr.Length; i++) { var confirmlList = dbset0 .Where(t => t.TRAILING_STS.ToString() == "900" && ( t.RECEIPT_TYPE.Contains("THRK") || t.RECEIPT_TYPE.Contains("HHRK") ) && t.COMPANY == customeId) .OrderByDescending(t => t.INTERNAL_RECEIPT_NUM) .Take(100).AsNoTracking().ToList(); var confirmTempList = dbset_Temp .Where(t => t.TRAILING_STS.ToString() == "900" && ( t.RECEIPT_TYPE.Contains("THRK") || t.RECEIPT_TYPE.Contains("HHRK") ) && t.COMPANY == customeId) .OrderByDescending(t => t.INTERNAL_RECEIPT_NUM) .Take(100).AsNoTracking().ToList(); List <RECEIPT_HEADER_TEMP> tempList = new List <RECEIPT_HEADER_TEMP>(); List <RECEIPT_DETAIL> detailList = new List <RECEIPT_DETAIL>(); //排除已确认的数据,并且一次性只处理100个订单 confirmlList = confirmlList .Where(a => !confirmTempList.Exists(t => a.INTERNAL_RECEIPT_NUM == t.INTERNAL_RECEIPT_NUM)) .OrderByDescending(t => t.INTERNAL_RECEIPT_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_RECEIPT_NUM == item.INTERNAL_RECEIPT_NUM).ToList(); obj1.ReturnOrderCode = item.RECEIPT_ID; //"R1234";//item.ERP_ORDER_ID; obj1.WarehouseCode = item.WAREHOUSE; obj1.LogisticsCode = "SF"; //"SF";//item.CARRER; obj1.OutBizCode = Guid.NewGuid().ToString(); send.Name = item.SHIP_FROM_NAME; //"老王";// send.Mobile = item.SHIP_FROM_PHONE_NUM; //"13214567869";// send.Province = item.SHIP_FROM_COUNTRY; //"浙江省";// send.City = item.SHIP_FROM_CITY; //"杭州"; // send.DetailAddress = item.SHIP_FROM_ADDRESS1 != null ? item.SHIP_FROM_ADDRESS1 : item.SHIP_FROM_ADDRESS2; //"杭州市余杭区989号";// obj1.SenderInfo = send; foreach (var itemChildren in detailList) { orderLine.OwnerCode = itemChildren.COMPANY; orderLine.ItemCode = itemChildren.ITEM; orderLine.PlanQty = (long)itemChildren.OPEN_QTY;//12L;// orderLine.ActualQty = itemChildren.TOTAL_QTY.ToString(); orderLineList.Add(orderLine); } req.ReturnOrder = obj1; req.OrderLines = orderLineList; try { rsp = client.Execute(req); log.Info(" " + "退货入库确认--订单号:" + item.INTERNAL_RECEIPT_NUM + " " + "确认结果:" + rsp.Flag + " " + "消息:" + rsp.Message); } catch (Exception ex) { log.Error("Error", ex); continue; } if (rsp.Flag == "success") { DbSet <RECEIPT_HEADER_TEMP> header = dbContext.Set <RECEIPT_HEADER_TEMP>(); RECEIPT_HEADER_TEMP headerTemp = new RECEIPT_HEADER_TEMP() { INTERNAL_RECEIPT_NUM = item.INTERNAL_RECEIPT_NUM, DATE_TIME_STAMP = DateTime.Now, RECEIPT_ID = item.RECEIPT_ID, WAREHOUSE = item.WAREHOUSE, RECEIPT_TYPE = item.RECEIPT_TYPE, TRAILING_STS = item.TRAILING_STS, LEADING_STS = item.LEADING_STS, FLAG = rsp.Flag, CODE = rsp.Code, MESSAGE = rsp.Message }; header.Add(headerTemp); } } dbContext.SaveChanges(); } return(true); } catch (Exception ex) { log.Error("Error", ex); return(false); } }
/// <summary> /// 入库单确认 /// </summary> public bool EntryorderConfirm() { log.Info("----------------启用定时任务:入库单确认" + DateTime.Now.Hour + "--------------"); try { dbContext = new SCVDBContainer(); DbSet <RECEIPT_HEADER> dbset0 = dbContext.Set <RECEIPT_HEADER>(); DbSet <RECEIPT_DETAIL> dbset1 = dbContext.Set <RECEIPT_DETAIL>(); DbSet <RECEIPT_HEADER_TEMP> dbset_Temp = dbContext.Set <RECEIPT_HEADER_TEMP>(); IQimenClient client = new DefaultQimenClient(url, appkey, secret); EntryorderConfirmRequest req = new EntryorderConfirmRequest(); EntryorderConfirmResponse rsp = new EntryorderConfirmResponse(); EntryorderConfirmRequest.EntryOrderDomain obj1 = new EntryorderConfirmRequest.EntryOrderDomain(); EntryorderConfirmRequest.OrderLineDomain orderLine = new EntryorderConfirmRequest.OrderLineDomain(); List <EntryorderConfirmRequest.OrderLineDomain> orderLineList = new List <EntryorderConfirmRequest.OrderLineDomain>(); for (int i = 0; i < customerArr.Length; i++) { var confirmlList = dbset0 .Where(t => t.TRAILING_STS.ToString() == "900" && (t.RECEIPT_TYPE.Contains("SCRK") || t.RECEIPT_TYPE.Contains("LYRK") || t.RECEIPT_TYPE.Contains("CCRK") || t.RECEIPT_TYPE.Contains("CGRK") || t.RECEIPT_TYPE.Contains("DBRK") || t.RECEIPT_TYPE.Contains("QTRK") || t.RECEIPT_TYPE.Contains("B2BRK") && t.COMPANY == customeId) ).OrderByDescending(t => t.INTERNAL_RECEIPT_NUM) .Take(100).AsNoTracking().ToList(); var confirmTempList = dbset_Temp.Where(t => t.TRAILING_STS.ToString() == "900" && (t.RECEIPT_TYPE.Contains("SCRK") || t.RECEIPT_TYPE.Contains("LYRK") || t.RECEIPT_TYPE.Contains("CCRK") || t.RECEIPT_TYPE.Contains("CGRK") || t.RECEIPT_TYPE.Contains("DBRK") || t.RECEIPT_TYPE.Contains("QTRK") || t.RECEIPT_TYPE.Contains("B2BRK") && t.COMPANY == customeId) ).OrderByDescending(t => t.INTERNAL_RECEIPT_NUM) .Take(100).AsNoTracking().ToList(); List <RECEIPT_DETAIL> tempList = new List <RECEIPT_DETAIL>(); //过滤已确认的数据 confirmlList = confirmlList .Where(a => !confirmTempList.Exists(t => a.INTERNAL_RECEIPT_NUM == t.INTERNAL_RECEIPT_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) { tempList = dbset1.Where(t => t.INTERNAL_RECEIPT_NUM == item.INTERNAL_RECEIPT_NUM).ToList(); obj1.EntryOrderCode = item.RECEIPT_ID; obj1.OwnerCode = item.COMPANY; obj1.WarehouseCode = item.WAREHOUSE; obj1.OutBizCode = Guid.NewGuid().ToString(); obj1.Status = "FULFILLED";//item.TRAILING_STS.ToString(); obj1.ConfirmType = 0L; obj1.TotalOrderLines = (long)item.TOTAL_LINES; obj1.EntryOrderId = item.RECEIPT_ID; req.EntryOrder = obj1; foreach (var itemChildren in tempList) { orderLine.ItemId = itemChildren.ITEM; orderLine.OwnerCode = itemChildren.COMPANY; orderLine.ItemCode = itemChildren.ITEM; orderLine.PlanQty = (long)itemChildren.OPEN_QTY; orderLine.ActualQty = (long)itemChildren.TOTAL_QTY; orderLineList.Add(orderLine); } req.OrderLines = orderLineList; try { rsp = client.Execute(req); log.Info(" " + "入库确认--订单号:" + item.INTERNAL_RECEIPT_NUM + " " + "确认结果:" + rsp.Flag + " " + "消息:" + rsp.Message); } catch (Exception ex) { log.Error("Error", ex); continue; } if (rsp.Flag == "success") { DbSet <RECEIPT_HEADER_TEMP> header = dbContext.Set <RECEIPT_HEADER_TEMP>(); RECEIPT_HEADER_TEMP headerTemp = new RECEIPT_HEADER_TEMP() { COMPANY = item.COMPANY, ACTUAL_ARRIVE_DATE = DateTime.Now, TRAILING_STS = item.TRAILING_STS, INTERNAL_RECEIPT_NUM = item.INTERNAL_RECEIPT_NUM, DATE_TIME_STAMP = DateTime.Now, RECEIPT_ID = item.RECEIPT_ID, WAREHOUSE = item.WAREHOUSE, RECEIPT_TYPE = item.RECEIPT_TYPE, FLAG = rsp.Flag, CODE = rsp.Code, MESSAGE = rsp.Message }; header.Add(headerTemp); } } dbContext.SaveChanges(); } return(true); } catch (Exception ex) { log.Error("Error", ex); return(false); } }
public void Execute(IJobExecutionContext context) { string url = ConfigurationManager.AppSettings["URL"].ToString(); string appkey = ConfigurationManager.AppSettings["APPKEY"].ToString(); //"1023883919"; 23883919 string secret = ConfigurationManager.AppSettings["SECRET"].ToString(); //"sandboxff0b11ecc626508c171a5b2a2"; string customeId = ConfigurationManager.AppSettings["CUSTOMEID"].ToString(); string v = ConfigurationManager.AppSettings["v"].ToString(); string[] customerArr = customeId.Split(','); try { _logger.Info("StockoutConfirmJob 开始执行... " + DateTime.Now + ""); foreach (var cId in customerArr) { using (SCVDBContainer dbContext = new SCVDBContainer()) using (DBContainer dbContext1 = new DBContainer()) { DbSet <SHIPMENT_HEADER> header = dbContext.Set <SHIPMENT_HEADER>(); DbSet <SHIPMENT_DETAIL> detail = dbContext.Set <SHIPMENT_DETAIL>(); //DbSet<QiMen_PushTimeStatus> dbSet0 = dbContext1.Set<QiMen_PushTimeStatus>(); DbSet <QiMen_PushLog> dbSet1 = dbContext1.Set <QiMen_PushLog>(); IQimenClient client; if (cId == "RB") { string rbUrl = ""; client = new DefaultQimenClient(rbUrl, appkey, secret, true); } else { client = new DefaultQimenClient(url, appkey, secret); } StockoutConfirmRequest req = new StockoutConfirmRequest(); //DateTime lastTime; //QiMen_PushTimeStatus qmt = dbSet0.Where(q => q.CustomerId == cId && q.OrderType == SHIPMENT && q.Interface == INTERFACE).FirstOrDefault(); //if (qmt == null) //{ // qmt = new QiMen_PushTimeStatus() { CustomerId = cId, ActualShipTime = DateTime.Now, OrderType = SHIPMENT, Interface = INTERFACE }; // dbSet0.Add(qmt); // lastTime = DateTime.Now.AddMinutes(-1); //} //else //{ // lastTime = ((DateTime)qmt.ActualShipTime).AddMinutes(-1); //} //&& (h.SHIPMENT_TYPE.Equals("LKCK", StringComparison.OrdinalIgnoreCase)) //var confirmlList = header.Where(h => h.COMPANY == cId && h.TRAILING_STS == 900 && h.ACTUAL_SHIP_DATE_TIME >= lastTime).OrderByDescending(h => h.ACTUAL_SHIP_DATE_TIME).Include(s => s.SHIPMENT_DETAIL).Include(s => s.SHIPPING_CONTAINER).AsNoTracking().ToList(); var confirmlList = new List <SHIPMENT_HEADER>(); if (cId == "XGQQG") { confirmlList = header.Where(h => h.COMPANY == cId && (h.SHIPMENT_CATEGORY6 == null || h.SHIPMENT_CATEGORY6 == QimenPushStatus.Failure.ToString() || h.SHIPMENT_CATEGORY6 == "1" || h.SHIPMENT_CATEGORY6 == "2" || h.SHIPMENT_CATEGORY6 == "3" || h.SHIPMENT_CATEGORY6 == "4" || h.SHIPMENT_CATEGORY6 == "5") && (h.TRAILING_STS == 800 || h.TRAILING_STS == 850 || h.TRAILING_STS == 900) && (h.PROCESS_TYPE == "NORMAL") ).Include(s => s.SHIPMENT_DETAIL).Include(s => s.SHIPPING_CONTAINER).ToList(); } else { confirmlList = header.Where(h => h.COMPANY == cId && h.CREATE_USER == "StockOutCreate" && (h.SHIPMENT_CATEGORY6 == null || h.SHIPMENT_CATEGORY6 == QimenPushStatus.Failure.ToString() || h.SHIPMENT_CATEGORY6 == "1" || h.SHIPMENT_CATEGORY6 == "2" || h.SHIPMENT_CATEGORY6 == "3" || h.SHIPMENT_CATEGORY6 == "4" || h.SHIPMENT_CATEGORY6 == "5") && (h.TRAILING_STS == 800 || h.TRAILING_STS == 850 || h.TRAILING_STS == 900) && (h.PROCESS_TYPE == "NORMAL") ).Include(s => s.SHIPMENT_DETAIL).Include(s => s.SHIPPING_CONTAINER).ToList(); } //if (cId == "CQHGE") //{ // confirmlList = confirmlList.Where(l => l.CREATE_USER == "StockOutCreate").ToList(); //} if (cId == "XGQQG") { CustomHttpClient.Request.YSJsonDeliveryorderConfirmRequest ysReq = new CustomHttpClient.Request.YSJsonDeliveryorderConfirmRequest(); string ysUrl = ysReq.GetApiName(); CustomHttpClient.ICustomClient customClient = new CustomHttpClient.DefaultCustomClient(ysUrl, null, null); ysReq.Db = "shop01"; ysReq.Function = "sp_mobile"; ysReq.Intype = "qrcode_out"; foreach (var itemHeader in confirmlList) { var snList = dbContext.SERIAL_NUMBER.Where(s => s.INTERNAL_SHIPMENT_NUM == itemHeader.INTERNAL_SHIPMENT_NUM).ToList(); if (!snList.Any()) { itemHeader.SHIPMENT_CATEGORY6 = "Skip"; } int successCount = 0; foreach (var sn in snList) { ysReq.Inpara = itemHeader.SHIPMENT_ID + "," + sn.SERIAL_NUMBER1; //ysReq.Inpara = "20170416591020," + "MAI2800000009001"; CustomHttpClient.Response.YSJsonDeliveryorderConfirmResponse ysRsp = customClient.Execute(ysReq); QiMen_PushLog log = new QiMen_PushLog(); log.InternalOrderID = itemHeader.INTERNAL_SHIPMENT_NUM; log.OrderType = INTERFACE; log.CustomerId = cId; log.Flag = ysRsp.Success ? "success" : "failure"; log.Message = ysRsp.Err + ":" + ysRsp.OutContext; log.CreateTime = DateTime.Now; dbSet1.Add(log); if (ysRsp.Success) { successCount++; if (successCount == snList.Count()) { itemHeader.SHIPMENT_CATEGORY6 = QimenPushStatus.Success.ToString(); _logger.Info("出库单:" + itemHeader.SHIPMENT_ID + "确认成功----" + DateTime.Now); } } else { if (string.IsNullOrEmpty(itemHeader.SHIPMENT_CATEGORY6)) { itemHeader.SHIPMENT_CATEGORY6 = "1"; } else { int parseResult; if (int.TryParse(itemHeader.SHIPMENT_CATEGORY6, out parseResult)) { itemHeader.SHIPMENT_CATEGORY6 = (parseResult + 1).ToString(); } } _logger.Info("出库单:" + itemHeader.SHIPMENT_ID + "确认失败:-" + ysRsp.OutContext + DateTime.Now); } } } dbContext.SaveChanges(); dbContext1.SaveChanges(); continue; } if (cId == "CH") { req.CustomerId = "CH1"; } else { req.CustomerId = cId; } req.Version = v; req.Timestamp = DateTime.Now; //bool pushFlag = true; foreach (var itemHeader in confirmlList) { StockoutConfirmRequest.DeliveryOrderDomain deliveryOrder = new StockoutConfirmRequest.DeliveryOrderDomain(); deliveryOrder.DeliveryOrderCode = itemHeader.SHIPMENT_ID; deliveryOrder.WarehouseCode = itemHeader.WAREHOUSE; deliveryOrder.OrderType = itemHeader.SHIPMENT_TYPE; deliveryOrder.ConfirmType = 0L; deliveryOrder.DeliveryOrderId = itemHeader.INTERNAL_SHIPMENT_NUM.ToString(); deliveryOrder.OutBizCode = itemHeader.INTERNAL_SHIPMENT_NUM.ToString(); deliveryOrder.TotalOrderLines = (long)itemHeader.TOTAL_LINES; deliveryOrder.Status = "DELIVERED"; req.DeliveryOrder = deliveryOrder; List <StockoutConfirmRequest.PackageDomain> packageList = new List <StockoutConfirmRequest.PackageDomain>(); List <StockoutConfirmRequest.OrderLineDomain> orderLineList = new List <StockoutConfirmRequest.OrderLineDomain>(); foreach (var container in itemHeader.SHIPPING_CONTAINER.Where(t => t.PARENT == 0)) { var childContainer = itemHeader.SHIPPING_CONTAINER.Where(c => c.PARENT == container.INTERNAL_CONTAINER_NUM); List <StockoutConfirmRequest.ItemDomain> itemList = new List <StockoutConfirmRequest.ItemDomain>(); StockoutConfirmRequest.PackageDomain package = new StockoutConfirmRequest.PackageDomain(); foreach (var child in childContainer) { StockoutConfirmRequest.ItemDomain itemDomain = new StockoutConfirmRequest.ItemDomain(); itemDomain.ItemCode = child.ITEM; itemDomain.Quantity = (int)child.QUANTITY; itemList.Add(itemDomain); } if (string.IsNullOrEmpty(deliveryOrder.ExpressCode) || string.IsNullOrEmpty(deliveryOrder.LogisticsCode)) { deliveryOrder.ExpressCode = container.TRACKING_NUMBER; deliveryOrder.LogisticsCode = itemHeader.CARRIER; } package.ExpressCode = container.TRACKING_NUMBER; package.LogisticsCode = itemHeader.CARRIER; package.Items = itemList; packageList.Add(package); } //---------------package add test data //if (!packageList.Any()) //{ // for (int i = 0; i < 1; i++) // { // List<StockoutConfirmRequest.ItemDomain> itemList = new List<StockoutConfirmRequest.ItemDomain>(); // StockoutConfirmRequest.PackageDomain package = new StockoutConfirmRequest.PackageDomain(); // StockoutConfirmRequest.ItemDomain itemDomain = new StockoutConfirmRequest.ItemDomain(); // itemDomain.ItemCode = "1000000000203"; // itemDomain.Quantity = 30; // itemList.Add(itemDomain); // package.ExpressCode = "012345678905" + i; // package.LogisticsCode = "SF"; // package.Items = itemList; // packageList.Add(package); // } //} //---------------package add test data foreach (var itemDetail in itemHeader.SHIPMENT_DETAIL) { StockoutConfirmRequest.OrderLineDomain orderLine = new StockoutConfirmRequest.OrderLineDomain(); orderLine.PlanQty = (int)itemDetail.REQUEST_QTY; orderLine.ItemCode = itemDetail.ITEM; orderLine.ActualQty = (int)itemDetail.REQUEST_QTY; orderLine.OutBizCode = itemDetail.INTERNAL_SHIPMENT_LINE_NUM.ToString(); orderLine.InventoryType = itemDetail.INVENTORY_STS == "合格" ? "ZP" : "CC"; orderLineList.Add(orderLine); } req.Packages = packageList; req.OrderLines = orderLineList; var rsp = client.Execute(req); QiMen_PushLog log = new QiMen_PushLog(); log.InternalOrderID = itemHeader.INTERNAL_SHIPMENT_NUM; log.OrderType = INTERFACE; log.CustomerId = cId; log.Flag = rsp.Flag; log.Message = rsp.Message; log.CreateTime = DateTime.Now; dbSet1.Add(log); if (rsp.Flag == "success") { itemHeader.SHIPMENT_CATEGORY6 = QimenPushStatus.Success.ToString(); _logger.Info("出库单:" + itemHeader.SHIPMENT_ID + "确认成功----" + DateTime.Now); } else { if (string.IsNullOrEmpty(itemHeader.SHIPMENT_CATEGORY6)) { itemHeader.SHIPMENT_CATEGORY6 = "1"; } else { int parseResult; if (int.TryParse(itemHeader.SHIPMENT_CATEGORY6, out parseResult)) { itemHeader.SHIPMENT_CATEGORY6 = (parseResult + 1).ToString(); } } //if (rsp.Message.Length > 50) //{ // pushFlag = false; //} _logger.Info("出库单:" + itemHeader.SHIPMENT_ID + "确认失败:-" + rsp.Message + DateTime.Now); } } // if (confirmlList.Count > 0 && pushFlag) { //if (confirmlList.Count > 0 && pushFlag) //{ // qmt.ActualShipTime = (DateTime)confirmlList.First().ACTUAL_SHIP_DATE_TIME; //} dbContext.SaveChanges(); dbContext1.SaveChanges(); } } _logger.Info("StockoutConfirmJob 执行完成... " + DateTime.Now + ""); } catch (Exception ex) { _logger.Error("StockoutConfirmJob 异常..." + DateTime.Now + " " + ex.Message); } }
// POST: api/ReturnorderCreate public ReturnorderCreateResponseModel Post([FromBody] ReturnorderCreateRequestModel model, [FromUri] string customerId) { if (customerId == "CH1") { customerId = "CH"; } ReturnorderCreateResponseModel response = new ReturnorderCreateResponseModel(); using (DBContainer context = new DBContainer()) { QiMen_RequestLog log = new QiMen_RequestLog(); HttpContextBase ctx = (HttpContextBase)Request.Properties["MS_HttpContext"]; string body = ApiUtils.GetStreamAsString(ctx.Request.InputStream, new UTF8Encoding(false)); string ip = ctx.Request.UserHostAddress; log.Interface = "ReturnorderCreate"; log.Url = Request.RequestUri.AbsoluteUri; log.Ip = ip; log.CustomerId = customerId; log.RequestBody = body; context.QiMen_RequestLog.Add(log); context.SaveChanges(); } using (SCVDBContainer dbContext = new SCVDBContainer()) { //DbSet<RECEIPT_HEADER> dbSet0 = dbContext.Set<RECEIPT_HEADER>(); //DbSet<RECEIPT_DETAIL> dbSet1 = dbContext.Set<RECEIPT_DETAIL>(); DbSet <ITEM> dbSetItem = dbContext.Set <ITEM>(); if (dbContext.RECEIPT_HEADER.Where(h => h.RECEIPT_ID == model.ReturnOrder.ReturnOrderCode && h.COMPANY == customerId).Any()) { response.Flag = "success"; response.Code = "0"; response.Message = model.ReturnOrder.ReturnOrderCode + ":单号重复"; response.ReturnOrderId = ""; return(response); } RECEIPT_HEADER header = new RECEIPT_HEADER(); header.COMPANY = customerId; header.RECEIPT_ID = model.ReturnOrder.ReturnOrderCode; header.WAREHOUSE = "LK01"; header.LEADING_STS = 100; header.TRAILING_STS = 100; header.RECEIPT_TYPE = model.ReturnOrder.OrderType; header.CREATE_USER = "******"; if (!string.IsNullOrEmpty(model.ReturnOrder.ExpressCode)) { header.ERP_ORDER_ID = model.ReturnOrder.ExpressCode; } if (!string.IsNullOrEmpty(model.ReturnOrder.SenderInfo.DetailAddress)) { header.SHIP_FROM_ADDRESS1 = model.ReturnOrder.SenderInfo.DetailAddress; } if (!string.IsNullOrEmpty(model.ReturnOrder.SenderInfo.City)) { header.SHIP_FROM_CITY = model.ReturnOrder.SenderInfo.City; } if (!string.IsNullOrEmpty(model.ReturnOrder.SenderInfo.Province)) { header.SHIP_FROM_STATE = model.ReturnOrder.SenderInfo.Province; } if (!string.IsNullOrEmpty(model.ReturnOrder.SenderInfo.ZipCode)) { header.SHIP_FROM_POSTAL_CODE = model.ReturnOrder.SenderInfo.ZipCode; } if (!string.IsNullOrEmpty(model.ReturnOrder.SenderInfo.Name)) { header.SHIP_FROM = model.ReturnOrder.SenderInfo.Name; header.SHIP_FROM_NAME = model.ReturnOrder.SenderInfo.Name; header.SHIP_FROM_ATTENTION_TO = model.ReturnOrder.SenderInfo.Name; } if (!string.IsNullOrEmpty(model.ReturnOrder.SenderInfo.Mobile)) { header.SHIP_FROM_FAX_NUM = model.ReturnOrder.SenderInfo.Mobile; } header.USER_STAMP = "Interface"; header.SHIP_FROM_COUNTRY = "CN"; //DateTime orderCreateTime; //if (DateTime.TryParse(model.ReturnOrder.OrderCreateTime, out orderCreateTime)) //{ header.CREATE_DATE = DateTime.Now; //} //int totalLines = Convert.ToInt32(model.EntryOrder.TotalOrderLines); int totalLines = model.OrderLines.Count(); int totalQty = 0; header.TOTAL_LINES = totalLines; foreach (var item in model.OrderLines) { RECEIPT_DETAIL detail = new RECEIPT_DETAIL(); detail.RECEIPT_ID = model.ReturnOrder.ReturnOrderCode; detail.WAREHOUSE = "LK01"; detail.COMPANY = item.OwnerCode; detail.ITEM = item.ItemCode; ITEM sItem = dbSetItem.Where(t => t.ITEM1 == item.ItemCode).FirstOrDefault(); if (sItem != null) { detail.ITEM_DESC = sItem.ITEM_DESC; } detail.TOTAL_QTY = item.PlanQty; detail.OPEN_QTY = item.PlanQty; detail.QUANTITY_UM = "EA"; totalQty += Convert.ToInt32(item.PlanQty); header.RECEIPT_DETAIL.Add(detail); //if (string.Equals("ZP", item.InventoryType, StringComparison.CurrentCultureIgnoreCase)) //{ // detail.INVENTORY_STS = "合格"; //} //else //{ // detail.INVENTORY_STS = "不合格"; //} if (item.InventoryType == null) { detail.INVENTORY_STS = "合格"; } else { if (string.Equals("ZP", item.InventoryType, StringComparison.CurrentCultureIgnoreCase)) { detail.INVENTORY_STS = "合格"; } else { detail.INVENTORY_STS = "不合格"; } } } header.TOTAL_QTY = totalQty; dbContext.RECEIPT_HEADER.Add(header); if (dbContext.SaveChanges() > 0) { response.Flag = "success"; response.Code = "1"; response.Message = "入库单:" + model.ReturnOrder.ReturnOrderCode + ":创建成功"; response.ReturnOrderId = header.INTERNAL_RECEIPT_NUM.ToString(); } else { response.Flag = "failure"; response.Code = "-1"; response.Message = "入库单:" + model.ReturnOrder.ReturnOrderCode + ":创建失败"; response.ReturnOrderId = ""; } } return(response); }
public void Execute(IJobExecutionContext context) { string url = ConfigurationManager.AppSettings["URL"].ToString(); string appkey = ConfigurationManager.AppSettings["APPKEY"].ToString(); //"1023883919"; 23883919 string secret = ConfigurationManager.AppSettings["SECRET"].ToString(); //"sandboxff0b11ecc626508c171a5b2a2"; string customeId = ConfigurationManager.AppSettings["CUSTOMEID"].ToString(); string v = ConfigurationManager.AppSettings["v"].ToString(); string[] customerArr = customeId.Split(','); try { _logger.Info("DeliveryorderConfirmJob 开始执行... " + DateTime.Now + ""); //_logger.Info(1,"Reicept","123", "Success","开始执行"); //for (int i = 0; i < 5; i++) //{ // _logger.Info("SimpleQuartzJob start... " + i + " " + DateTime.Now + ""); // Console.WriteLine("SimpleQuartzJob running..." + i); //} foreach (var cId in customerArr) { using (SCVDBContainer dbContext = new SCVDBContainer()) using (DBContainer dbContext1 = new DBContainer()) { DbSet <SHIPMENT_HEADER> header = dbContext.Set <SHIPMENT_HEADER>(); DbSet <SHIPMENT_DETAIL> detail = dbContext.Set <SHIPMENT_DETAIL>(); //DbSet<SHIPMENT_HEADER_TEMP> headerTemp = dbContext.Set<SHIPMENT_HEADER_TEMP>(); //DbSet<QiMen_PushTimeStatus> dbSet0 = dbContext1.Set<QiMen_PushTimeStatus>(); DbSet <QiMen_PushLog> dbSet1 = dbContext1.Set <QiMen_PushLog>(); //Spm_LastTime sl = dbSet0.Find("1"); //DateTime lastTime = ((DateTime)sl.ActualShipDateTime).AddMinutes(-1); IQimenClient client = new DefaultQimenClient(url, appkey, secret); DeliveryorderConfirmRequest req = new DeliveryorderConfirmRequest(); //DateTime lastTime; //QiMen_PushTimeStatus qmt = dbSet0.Where(q => q.CustomerId == cId && q.OrderType == SHIPMENT && q.Interface == INTERFACE).FirstOrDefault(); //if (qmt == null) //{ // qmt = new QiMen_PushTimeStatus() { CustomerId = cId, ActualShipTime = DateTime.Now, OrderType = SHIPMENT, Interface = INTERFACE }; // dbSet0.Add(qmt); // lastTime = DateTime.Now.AddMinutes(-1); //} //else //{ // lastTime = ((DateTime)qmt.ActualShipTime).AddMinutes(-1); //} //DateTime lastTime = dbSet0.Where() //&& !(h.SHIPMENT_TYPE.Equals("LKCK", StringComparison.OrdinalIgnoreCase)) //var confirmlList = header.Where(h => h.COMPANY == cId && h.TRAILING_STS == 900 && h.ACTUAL_SHIP_DATE_TIME >= lastTime).OrderByDescending(h => h.ACTUAL_SHIP_DATE_TIME).Include(s => s.SHIPMENT_DETAIL).Include(s => s.SHIPPING_CONTAINER).AsNoTracking().ToList(); var confirmlList = header.Where(h => h.COMPANY == cId && h.CREATE_USER == "DeliveryorderCreate" && (h.SHIPMENT_CATEGORY6 == null || h.SHIPMENT_CATEGORY6 == QimenPushStatus.Failure.ToString() || h.SHIPMENT_CATEGORY6 == "1" || h.SHIPMENT_CATEGORY6 == "2" || h.SHIPMENT_CATEGORY6 == "3" || h.SHIPMENT_CATEGORY6 == "4" || h.SHIPMENT_CATEGORY6 == "5") && (h.TRAILING_STS == 800 || h.TRAILING_STS == 850 || h.TRAILING_STS == 900) && (h.PROCESS_TYPE == "NORMAL") ).Include(s => s.SHIPMENT_DETAIL).Include(s => s.SHIPPING_CONTAINER).ToList(); if (cId == "XGQQG") { confirmlList.Clear(); } //if (cId == "CQHGE") //{ // confirmlList = confirmlList.Where(l => l.CREATE_USER == "DeliveryorderCreate").ToList(); //} if (cId == "CH") { req.CustomerId = "CH1"; } else { req.CustomerId = cId; } req.Version = v; req.Timestamp = DateTime.Now; //bool pushFlag = true; foreach (var itemHeader in confirmlList) { DeliveryorderConfirmRequest.DeliveryOrderDomain deliveryOrder = new DeliveryorderConfirmRequest.DeliveryOrderDomain(); deliveryOrder.DeliveryOrderCode = itemHeader.SHIPMENT_ID; deliveryOrder.WarehouseCode = itemHeader.WAREHOUSE; deliveryOrder.OrderType = itemHeader.SHIPMENT_TYPE; //"JYCK" deliveryOrder.ConfirmType = 0L; //仅仅确认最终状态的订单 deliveryOrder.OutBizCode = itemHeader.INTERNAL_SHIPMENT_NUM.ToString(); deliveryOrder.DeliveryOrderId = itemHeader.INTERNAL_SHIPMENT_NUM.ToString(); req.DeliveryOrder = deliveryOrder; List <DeliveryorderConfirmRequest.PackageDomain> packageList = new List <DeliveryorderConfirmRequest.PackageDomain>(); List <DeliveryorderConfirmRequest.OrderLineDomain> orderLineList = new List <DeliveryorderConfirmRequest.OrderLineDomain>(); foreach (var container in itemHeader.SHIPPING_CONTAINER.Where(t => t.PARENT == 0)) { var childContainer = itemHeader.SHIPPING_CONTAINER.Where(c => c.PARENT == container.INTERNAL_CONTAINER_NUM); List <DeliveryorderConfirmRequest.ItemDomain> itemList = new List <DeliveryorderConfirmRequest.ItemDomain>(); DeliveryorderConfirmRequest.PackageDomain package = new DeliveryorderConfirmRequest.PackageDomain(); foreach (var child in childContainer) { DeliveryorderConfirmRequest.ItemDomain itemDomain = new DeliveryorderConfirmRequest.ItemDomain(); itemDomain.ItemCode = child.ITEM; itemDomain.Quantity = (int)child.QUANTITY; itemList.Add(itemDomain); } package.ExpressCode = container.TRACKING_NUMBER; package.LogisticsCode = itemHeader.CARRIER; package.Items = itemList; packageList.Add(package); } //---------------package add test data //if (!packageList.Any()) //{ // for (int i = 0; i < 1; i++) // { // List<DeliveryorderConfirmRequest.ItemDomain> itemList = new List<DeliveryorderConfirmRequest.ItemDomain>(); // DeliveryorderConfirmRequest.PackageDomain package = new DeliveryorderConfirmRequest.PackageDomain(); // DeliveryorderConfirmRequest.ItemDomain itemDomain = new DeliveryorderConfirmRequest.ItemDomain(); // itemDomain.ItemCode = "1000000000203"; // itemDomain.Quantity = 30; // itemList.Add(itemDomain); // package.ExpressCode = "000123456780" + i; // package.LogisticsCode = "FAST"; // package.Items = itemList; // packageList.Add(package); // } //} //---------------package add test data foreach (var itemDetail in itemHeader.SHIPMENT_DETAIL) { DeliveryorderConfirmRequest.OrderLineDomain orderLine = new DeliveryorderConfirmRequest.OrderLineDomain(); orderLine.PlanQty = itemDetail.REQUEST_QTY.ToString(); orderLine.ItemCode = itemDetail.ITEM; orderLine.ActualQty = itemDetail.REQUEST_QTY.ToString(); orderLine.OutBizCode = itemDetail.INTERNAL_SHIPMENT_LINE_NUM.ToString(); orderLineList.Add(orderLine); } req.Packages = packageList; req.OrderLines = orderLineList; var rsp = client.Execute(req); QiMen_PushLog log = new QiMen_PushLog(); log.InternalOrderID = itemHeader.INTERNAL_SHIPMENT_NUM; log.OrderType = INTERFACE; log.CustomerId = cId; log.Flag = rsp.Flag; log.Message = rsp.Message; log.CreateTime = DateTime.Now; dbSet1.Add(log); if (rsp.Flag == "success") { itemHeader.SHIPMENT_CATEGORY6 = QimenPushStatus.Success.ToString(); _logger.Info("发货单:" + itemHeader.SHIPMENT_ID + "确认成功----" + DateTime.Now); } else { if (string.IsNullOrEmpty(itemHeader.SHIPMENT_CATEGORY6)) { itemHeader.SHIPMENT_CATEGORY6 = "1"; } else { int parseResult; if (int.TryParse(itemHeader.SHIPMENT_CATEGORY6, out parseResult)) { itemHeader.SHIPMENT_CATEGORY6 = (parseResult + 1).ToString(); } } //if (rsp.Message.Length > 50) //{ // pushFlag = false; //} _logger.Info("发货单:" + itemHeader.SHIPMENT_ID + "确认失败:-" + rsp.Message + DateTime.Now); } } //if (confirmlList.Count > 0 && pushFlag) //{ // qmt.ActualShipTime = (DateTime)confirmlList.First().ACTUAL_SHIP_DATE_TIME; //} dbContext.SaveChanges(); dbContext1.SaveChanges(); } } _logger.Info("DeliveryorderConfirmJob 执行完成... " + DateTime.Now + ""); } catch (Exception ex) { _logger.Error("DeliveryorderConfirmJob 异常..." + DateTime.Now + " " + ex.Message); } }