Пример #1
0
        /// <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);
            }
        }
Пример #2
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("EntryorderConfirmJob 开始执行... " + 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);
                            EntryorderConfirmRequest req    = new EntryorderConfirmRequest();

                            //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 == "EntryorderCreate" &&
                                                            (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 == "EntryorderCreate").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)
                            {
                                EntryorderConfirmRequest.EntryOrderDomain entryOrder = new EntryorderConfirmRequest.EntryOrderDomain();
                                entryOrder.EntryOrderCode = itemHeader.RECEIPT_ID;
                                entryOrder.OwnerCode      = itemHeader.COMPANY;
                                entryOrder.WarehouseCode  = itemHeader.WAREHOUSE;
                                entryOrder.OutBizCode     = itemHeader.INTERNAL_RECEIPT_NUM.ToString();
                                //if (itemHeader.RECEIPT_ID == "RK1708240001")
                                //{
                                //    entryOrder.OutBizCode = "xxx1231";
                                //}
                                entryOrder.Status          = "FULFILLED";//item.TRAILING_STS.ToString();
                                entryOrder.ConfirmType     = 0L;
                                entryOrder.EntryOrderType  = itemHeader.RECEIPT_TYPE;
                                entryOrder.TotalOrderLines = (long)itemHeader.TOTAL_LINES;//======
                                entryOrder.EntryOrderId    = itemHeader.INTERNAL_RECEIPT_NUM.ToString();
                                req.EntryOrder             = entryOrder;

                                List <EntryorderConfirmRequest.OrderLineDomain> orderLineList = new List <EntryorderConfirmRequest.OrderLineDomain>();

                                foreach (var itemDetail in itemHeader.RECEIPT_DETAIL)
                                {
                                    EntryorderConfirmRequest.OrderLineDomain orderLine = new EntryorderConfirmRequest.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 = (long)(itemDetail.TOTAL_QTY - itemDetail.OPEN_QTY);
                                    //if (itemDetail.TOTAL_QTY != itemDetail.OPEN_QTY)
                                    //{
                                    //    entryOrder.Status = "PARTFULFILLED";
                                    //}
                                    orderLine.OutBizCode = itemDetail.INTERNAL_RECEIPT_LINE_NUM.ToString();
                                    //if (itemHeader.RECEIPT_ID == "RK1708240001")
                                    //{
                                    //    orderLine.OutBizCode = itemDetail.INTERNAL_RECEIPT_LINE_NUM.ToString() + "x";
                                    //    orderLine.ActualQty = 0;
                                    //}

                                    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 (rsp.Message.Length > 50)
                                    //{
                                    //    pushFlag = false;
                                    //}
                                    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();
                                        }
                                    }
                                    _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("EntryorderConfirmJob 执行完成... " + DateTime.Now + "");
            }
            catch (Exception ex)
            {
                _logger.Error("EntryorderConfirmJob 异常..." + DateTime.Now + " " + ex.Message);
            }
        }
Пример #3
0
        public static EntryorderConfirmResponse 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);
            EntryorderConfirmRequest req        = new EntryorderConfirmRequest();

            req.CustomerId = customerId;
            req.Version    = "2.0";
            EntryorderConfirmRequest.EntryOrderDomain entryOrder = new EntryorderConfirmRequest.EntryOrderDomain();
            entryOrder.EntryOrderCode = "RK1706300003";
            entryOrder.OwnerCode      = "ZK";
            entryOrder.WarehouseCode  = "LK01";
            entryOrder.OutBizCode     = Guid.NewGuid().ToString("N");
            entryOrder.Status         = "FULFILLED";
            req.EntryOrder            = entryOrder;

            List <EntryorderConfirmRequest.OrderLineDomain> orderLines = new List <EntryorderConfirmRequest.OrderLineDomain>();

            EntryorderConfirmRequest.OrderLineDomain orderLine = new EntryorderConfirmRequest.OrderLineDomain();
            orderLine.OwnerCode = "ZK";
            orderLine.ItemCode  = "1006-1003";
            orderLine.PlanQty   = 20;
            orderLine.ActualQty = 20;
            orderLines.Add(orderLine);

            EntryorderConfirmRequest.OrderLineDomain orderLine1 = new EntryorderConfirmRequest.OrderLineDomain();
            orderLine1.OwnerCode = "ZK";
            orderLine1.ItemCode  = "1006-1002";
            orderLine1.PlanQty   = 20;
            orderLine1.ActualQty = 20;
            orderLines.Add(orderLine1);

            EntryorderConfirmRequest.OrderLineDomain orderLine2 = new EntryorderConfirmRequest.OrderLineDomain();
            orderLine2.OwnerCode = "ZK";
            orderLine2.ItemCode  = "1001-1001";
            orderLine2.PlanQty   = 10;
            orderLine2.ActualQty = 10;
            orderLines.Add(orderLine2);

            EntryorderConfirmRequest.OrderLineDomain orderLine3 = new EntryorderConfirmRequest.OrderLineDomain();
            orderLine3.OwnerCode = "ZK";
            orderLine3.ItemCode  = "1001-1000";
            orderLine3.PlanQty   = 10;
            orderLine3.ActualQty = 10;
            orderLines.Add(orderLine3);

            EntryorderConfirmRequest.OrderLineDomain orderLine4 = new EntryorderConfirmRequest.OrderLineDomain();
            orderLine4.OwnerCode = "ZK";
            orderLine4.ItemCode  = "1000-0";
            orderLine4.PlanQty   = 10;
            orderLine4.ActualQty = 10;
            orderLines.Add(orderLine4);

            req.OrderLines = orderLines;

            return(client.Execute(req));
            //EntryorderConfirmResponse rsp = client.Execute(req);
            //Console.WriteLine(rsp.Body);
        }