// 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);
        }
Esempio n. 2
0
        public static DeliveryorderConfirmResponse InitRequest()
        {
            string url    = "http://qimenapi.tbsandbox.com/router/qimen/service";
            string appkey = "1023883919";
            string secret = "sandboxff0b11ecc626508c171a5b2a2";
            //string customerId = "c1498112555030";
            string       customerId         = "c1498448349079";
            IQimenClient client             = new DefaultQimenClient(url, appkey, secret);
            DeliveryorderConfirmRequest req = new DeliveryorderConfirmRequest();

            req.CustomerId = customerId;
            req.Version    = "2.0";

            DeliveryorderConfirmRequest.DeliveryOrderDomain    deliveryOrder = new DeliveryorderConfirmRequest.DeliveryOrderDomain();
            DeliveryorderConfirmRequest.OrderLineDomain        orderLine     = new DeliveryorderConfirmRequest.OrderLineDomain();
            List <DeliveryorderConfirmRequest.OrderLineDomain> orderLines    = new List <DeliveryorderConfirmRequest.OrderLineDomain>();

            DeliveryorderConfirmRequest.PackageDomain        package  = new DeliveryorderConfirmRequest.PackageDomain();
            List <DeliveryorderConfirmRequest.PackageDomain> packages = new List <DeliveryorderConfirmRequest.PackageDomain>();

            deliveryOrder.OutBizCode = Guid.NewGuid().ToString("N");
            package.LogisticsCode    = "SF";
            package.ExpressCode      = "974701803690";
            packages.Add(package);
            req.Packages = packages;
            deliveryOrder.DeliveryOrderCode = "JY1707040014";
            deliveryOrder.WarehouseCode     = "LK01";
            deliveryOrder.OrderType         = "JYCK";

            req.DeliveryOrder   = deliveryOrder;
            orderLine.ItemCode  = "1006-1003";
            orderLine.ActualQty = "1";

            orderLines.Add(orderLine);
            req.OrderLines = orderLines;

            return(client.Execute(req));
        }
Esempio n. 3
0
        /// <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);
            }
        }
Esempio n. 4
0
        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);
            }
        }