Ejemplo n.º 1
0
        public void TestAnalyseDataItem_服务器返回错误信息()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
                + "<error_rsp>"
                + "  <args>"
                + "    <arg name=\"api_key\"><![CDATA[12003014]]></arg>"
                + "  </args>"
                + "  <code>551</code>"
                + "  <msg><![CDATA[Item service unavailable:获取单个商品失败]]></msg>"
                + "</error_rsp>"
                + "<!--top50.cm1-->";

            AnalyseData analyser = new AnalyseData(defaultAppKey, defaultAppSecret);
            try
            {
                ItemListItem item = analyser.AnalyseDataItem<ItemListItem>(xml);
            }
            catch (ResponseException ex)
            {
                string errorXml = "<error_rsp>"
                    + "<args>"
                        + "<arg name=\"api_key\"><![CDATA[12003014]]></arg>"
                    + "</args>"
                    + "<code>551</code>"
                    + "<msg><![CDATA[Item service unavailable:获取单个商品失败]]></msg>"
                    + "</error_rsp>";
                Assert.AreEqual(errorXml, ex.ErrorXml);
            }
            catch (Exception ex)
            {
                Assert.Fail("应该抛出服务器返回错误信息的异常,而不是" + ex.GetType().ToString() + "异常");
            }
        }
Ejemplo n.º 2
0
        public void TestAnalyseDataItem_服务器返回错误信息()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
                         + "<error_rsp>"
                         + "  <args>"
                         + "    <arg name=\"api_key\"><![CDATA[12003014]]></arg>"
                         + "  </args>"
                         + "  <code>551</code>"
                         + "  <msg><![CDATA[Item service unavailable:获取单个商品失败]]></msg>"
                         + "</error_rsp>"
                         + "<!--top50.cm1-->";

            AnalyseData analyser = new AnalyseData(defaultAppKey, defaultAppSecret);

            try
            {
                ItemListItem item = analyser.AnalyseDataItem <ItemListItem>(xml);
            }
            catch (ResponseException ex)
            {
                string errorXml = "<error_rsp>"
                                  + "<args>"
                                  + "<arg name=\"api_key\"><![CDATA[12003014]]></arg>"
                                  + "</args>"
                                  + "<code>551</code>"
                                  + "<msg><![CDATA[Item service unavailable:获取单个商品失败]]></msg>"
                                  + "</error_rsp>";
                Assert.AreEqual(errorXml, ex.ErrorXml);
            }
            catch (Exception ex)
            {
                Assert.Fail("应该抛出服务器返回错误信息的异常,而不是" + ex.GetType().ToString() + "异常");
            }
        }
Ejemplo n.º 3
0
        public void TestRequestTOPDataItem_测试请求服务器_卖家不存在()
        {
            string nick = "不存在的卖家";
            string id   = "102a0499bf58d002de05da07f523f3f1";

            AnalyseData analyser          = new AnalyseData(defaultAppKey, defaultAppSecret);
            Dictionary <string, string> q = new Dictionary <string, string>();

            q.Add("nick", nick);
            q.Add("iid", id);
            try
            {
                ItemListItem item = analyser.RequestTOPDataItem <ItemListItem>("taobao.item.get", q);
            }
            catch (ResponseException ex)
            {
                Assert.AreEqual("服务器返回错误响应消息", ex.Message);
                Assert.AreEqual("601", ex.ErrorCode);
                Assert.AreEqual("User not exist:不存在的卖家", ex.ErrorDescription);
            }
            catch (Exception ex)
            {
                Assert.Fail("应该抛出服务器返回错误信息的异常,而不是" + ex.GetType().ToString() + "异常");
            }
        }
Ejemplo n.º 4
0
        public AreaFacade(string appKey, string appSecret, string version)
        {
            currentAppKey = appKey;
            currentAppSecret = appSecret;
            currentVersion = version;

            analyser = new AnalyseData(appKey, appSecret, version);
        }
Ejemplo n.º 5
0
        public void TestRequestTOPDataList_测试请求服务器_正确()
        {
            string nick = "fengxiangxia";

            AnalyseData analyser          = new AnalyseData(defaultAppKey, defaultAppSecret);
            Dictionary <string, string> q = new Dictionary <string, string>();

            q.Add("nicks", nick);
            TOPDataList <ItemListItem> list = analyser.RequestTOPDataList <ItemListItem>("taobao.items.get", q);

            Assert.AreEqual(40, list.Count);
            Assert.IsTrue(list.TotalResultNum > 100);
            Assert.IsFalse(string.IsNullOrEmpty(list[0].Title));
        }
Ejemplo n.º 6
0
        public void TestRequestTOPDataItem_测试请求服务器_正确()
        {
            string nick = "fengxiangxia";
            string id   = "302a0499bf58d002de05da07f523f3f9";

            AnalyseData analyser          = new AnalyseData(defaultAppKey, defaultAppSecret);
            Dictionary <string, string> q = new Dictionary <string, string>();

            q.Add("nick", nick);
            q.Add("iid", id);
            ItemListItem item = analyser.RequestTOPDataItem <ItemListItem>("taobao.item.get", q);

            Assert.AreEqual("302a0499bf58d002de05da07f523f3f9", item.Id);
            Assert.AreEqual("韩国代购THURSDAY ISLAND专柜正品&mdash;TB3TS05AU粉色短袖T恤", item.Title);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 根据企业编号和时间获取总成本,总售价,总利润
        /// </summary>
        /// <param name="eid">企业编号</param>
        /// <param name="time">查询的年月份</param>
        /// <returns>AnalyseDataModel</returns>
        //public AnalyseDataModel GetAnalyseData(int eid, string time)
        //{
        //    AnalyseDataModel analyseDataModel = new AnalyseDataModel(); ;

        //    try
        //    {
        //        List<AnalyseData> analyseDatas= GetListBySearch(eid,time);
        //        if (analyseDatas == null) return null;
        //        foreach(AnalyseData analyseData in analyseDatas)
        //        {

        //            analyseDataModel.TotolIncome += analyseData.Income;
        //            analyseDataModel.TotolCost += analyseData.Cost;
        //            analyseDataModel.TotolProfit += analyseData.Profit;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        XphpTool.CreateErrorLog(ex.ToString());
        //        return null;
        //    }
        //    return analyseDataModel;
        //}

        /// <summary>
        /// 处理AnalyseData集合返回“同一客户,不同部门,同一天”的数据
        /// </summary>
        /// <param name="time">查询的年月份</param>
        /// <returns>AnalyseData集合</returns>
        public List <AnalyseData> DealAnalyseData(string time)
        {
            List <AnalyseData> analyseDatas = GetListBySearch(time);

            if (analyseDatas == null)
            {
                return(null);
            }

            List <AnalyseData> dealAnalyseData = new List <AnalyseData>();
            AnalyseData        aData           = null;
            //string[] dayTime = new string[analyseDatas.Count];
            HashSet <string> dayTime = new HashSet <string>();

            //获取所有订单的日期,无重复
            foreach (AnalyseData data in analyseDatas)
            {
                dayTime.Add(data.OID.Substring(0, 8));
            }

            foreach (string str in dayTime)
            {
                foreach (Enterprise e in new EnterpriseDao().GetEnterpriseList())
                {
                    aData = new AnalyseData();
                    foreach (AnalyseData ad in analyseDatas)
                    {
                        if (ad.OID.Contains(str) && e.EID == ad.EID)
                        {
                            aData.TotalCost += ad.TotalCost;
                            aData.Amount    += ad.Amount;
                            aData.EID        = ad.EID;
                            aData.OID        = ad.OID;
                        }
                    }
                    if (aData.OID != null)
                    {
                        dealAnalyseData.Add(aData);
                    }
                }
            }
            return(dealAnalyseData);
        }
Ejemplo n.º 8
0
        public ActionResult <AnalyseData> Get([FromQuery] string logType = "")
        {
            var ret = new AnalyseData();

            if (logType.Equals("LoginUsers", StringComparison.OrdinalIgnoreCase))
            {
                var loginUsers = LoginHelper.RetrieveAll(null, null, null);
                var temp       = loginUsers.GroupBy(usr => usr.LoginTime.ToString("yyyy-MM-dd"));
                var max        = temp.Any() ? temp.Max(g => g.Count()) : 1;
                ret.Polylines = temp.Select((g, index) =>
                {
                    ret.Datas.Add(new KeyValuePair <string, string>(g.Key, g.Count().ToString()));
                    return($"{index * 2},{Math.Round(g.Count() * 28.0 / max, 2)}");
                });
            }
            if (logType.Equals("trace", StringComparison.OrdinalIgnoreCase))
            {
                var loginUsers = TraceHelper.RetrieveAll(null, null, null);
                var temp       = loginUsers.GroupBy(usr => usr.LogTime.ToString("yyyy-MM-dd"));
                var max        = temp.Any() ? temp.Max(g => g.Count()) : 1;
                ret.Polylines = temp.Select((g, index) =>
                {
                    ret.Datas.Add(new KeyValuePair <string, string>(g.Key, g.Count().ToString()));
                    return($"{index * 5},{Math.Round(g.Count() * 28.0 / max, 2)}");
                });
            }
            if (logType.Equals("log", StringComparison.OrdinalIgnoreCase))
            {
                var loginUsers = LogHelper.RetrieveAll(null, null, null);
                var temp       = loginUsers.GroupBy(usr => usr.LogTime.ToString("yyyy-MM-dd"));
                var max        = temp.Any() ? temp.Max(g => g.Count()) : 1;
                ret.Polylines = temp.Select((g, index) =>
                {
                    ret.Datas.Add(new KeyValuePair <string, string>(g.Key, g.Count().ToString()));
                    return($"{index * 5},{Math.Round(g.Count() * 28.0 / max, 2)}");
                });
            }
            return(ret);
        }
Ejemplo n.º 9
0
        public void TestAnalyseDataItem_解析正确的XML文本()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
                + "<rsp>"
                + "  <item>"
                + "    <iid><![CDATA[302a0499bf58d002de05da07f523f3f9]]></iid>"
                + "    <detail_url><![CDATA[http://item.taobao.com/auction/item_detail.jhtml?item_id=302a0499bf58d002de05da07f523f3f9&x_id=0xid]]></detail_url>"
                + "    <title><![CDATA[韩国代购THURSDAY ISLAND专柜正品&mdash;TB3TS05AU粉色短袖T恤]]></title>"
                + "    <nick><![CDATA[fengxiangxia]]></nick>"
                + "    <type><![CDATA[fixed]]></type>"
                + "    <cid><![CDATA[50011150]]></cid>"
                + "    <desc><![CDATA[商品描述]]></desc>"
                + "    <pic_path><![CDATA[http://img06.taobaocdn.com/bao/uploaded/i6/T1h.ljXoUrvJN81.sV_021900.jpg]]></pic_path>"
                + "    <num>6</num>"
                + "    <approve_status><![CDATA[onsale]]></approve_status>"
                + "  </item>"
                + "</rsp>"
                + "<!--top14.cm3-->";

            AnalyseData analyser = new AnalyseData(defaultAppKey, defaultAppSecret);
            ItemListItem item = analyser.AnalyseDataItem<ItemListItem>(xml);
            Assert.AreEqual("302a0499bf58d002de05da07f523f3f9", item.Id);
        }
Ejemplo n.º 10
0
        public void TestAnalyseDataItem_解析正确的XML文本()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
                         + "<rsp>"
                         + "  <item>"
                         + "    <iid><![CDATA[302a0499bf58d002de05da07f523f3f9]]></iid>"
                         + "    <detail_url><![CDATA[http://item.taobao.com/auction/item_detail.jhtml?item_id=302a0499bf58d002de05da07f523f3f9&x_id=0xid]]></detail_url>"
                         + "    <title><![CDATA[韩国代购THURSDAY ISLAND专柜正品&mdash;TB3TS05AU粉色短袖T恤]]></title>"
                         + "    <nick><![CDATA[fengxiangxia]]></nick>"
                         + "    <type><![CDATA[fixed]]></type>"
                         + "    <cid><![CDATA[50011150]]></cid>"
                         + "    <desc><![CDATA[商品描述]]></desc>"
                         + "    <pic_path><![CDATA[http://img06.taobaocdn.com/bao/uploaded/i6/T1h.ljXoUrvJN81.sV_021900.jpg]]></pic_path>"
                         + "    <num>6</num>"
                         + "    <approve_status><![CDATA[onsale]]></approve_status>"
                         + "  </item>"
                         + "</rsp>"
                         + "<!--top14.cm3-->";

            AnalyseData  analyser = new AnalyseData(defaultAppKey, defaultAppSecret);
            ItemListItem item     = analyser.AnalyseDataItem <ItemListItem>(xml);

            Assert.AreEqual("302a0499bf58d002de05da07f523f3f9", item.Id);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 根据年月份获取总成本,总售价,总利润
        /// </summary>
        /// <param name="time">查询的年月份</param>
        /// <returns>AnalyseDataModel</returns>
        public AnalyseDataModel GetAnalyseDataModel(string time)
        {
            AnalyseDataModel   adModel      = null;
            List <AnalyseData> analyseDatas = analyseDataDao.DealAnalyseData(time);

            if (analyseDatas != null)
            {
                adModel           = new AnalyseDataModel();
                adModel.MonthData = new List <AnalyseData>();
                adModel.DayData   = new List <AnalyseData>();

                adModel.Enterpreses  = enterpriseService.GetEnterpriseList();
                adModel.AnalyseDatas = analyseDatas;
                AnalyseData monthData = null;
                AnalyseData dayData   = null;
                //计算所有客户当月的总成本和总售价
                foreach (AnalyseData ad in analyseDatas)
                {
                    adModel.TotolIncome += ad.Amount;
                    adModel.TotolCost   += ad.TotalCost;
                }
                //计算各个客户当月的总成本,总售价
                foreach (Enterprise e in enterpriseService.GetEnterpriseList())
                {
                    monthData = new AnalyseData();
                    foreach (AnalyseData ad in analyseDatas)
                    {
                        if (ad.EID == e.EID)
                        {
                            monthData.TotalCost += ad.TotalCost;
                            monthData.Amount    += ad.Amount;
                            monthData.EID        = ad.EID;
                            monthData.OID        = ad.OID;
                        }
                    }
                    adModel.MonthData.Add(monthData);
                }
                //获取所有订单的日期,无重复
                HashSet <string> dayTime = new HashSet <string>();
                foreach (AnalyseData data in analyseDatas)
                {
                    dayTime.Add(data.OID.Substring(0, 8));
                }

                //计算当月所有客户同一天的总售价和总成本
                foreach (string str in dayTime)
                {
                    dayData = new AnalyseData();

                    foreach (AnalyseData ad in analyseDatas)
                    {
                        if (ad.OID.Contains(str))
                        {
                            dayData.TotalCost += ad.TotalCost;
                            dayData.Amount    += ad.Amount;
                            dayData.EID        = ad.EID;
                            dayData.OID        = ad.OID;
                        }
                    }

                    adModel.DayData.Add(dayData);
                }

                adModel.TotolProfit = adModel.TotolIncome - adModel.TotolCost;
            }
            else
            {
                msg = "没有该月的订单信息,请重新查询!";
            }

            if (adModel.AnalyseDatas.Count == 0)
            {
                msg = "没有该月的订单信息,请重新查询!";
            }

            return(adModel);
        }
Ejemplo n.º 12
0
        public void TestRequestTOPDataItem_测试请求服务器_卖家不存在()
        {
            string nick = "不存在的卖家";
            string id = "102a0499bf58d002de05da07f523f3f1";

            AnalyseData analyser = new AnalyseData(defaultAppKey, defaultAppSecret);
            Dictionary<string, string> q = new Dictionary<string, string>();
            q.Add("nick", nick);
            q.Add("iid", id);
            try
            {
                ItemListItem item = analyser.RequestTOPDataItem<ItemListItem>("taobao.item.get", q);
            }
            catch (ResponseException ex)
            {
                Assert.AreEqual("服务器返回错误响应消息", ex.Message);
                Assert.AreEqual("601", ex.ErrorCode);
                Assert.AreEqual("User not exist:不存在的卖家", ex.ErrorDescription);
            }
            catch (Exception ex)
            {
                Assert.Fail("应该抛出服务器返回错误信息的异常,而不是" + ex.GetType().ToString() + "异常");
            }
        }
Ejemplo n.º 13
0
        public void TestRequestTOPDataList_测试请求服务器_正确()
        {
            string nick = "fengxiangxia";

            AnalyseData analyser = new AnalyseData(defaultAppKey, defaultAppSecret);
            Dictionary<string, string> q = new Dictionary<string, string>();
            q.Add("nicks", nick);
            TOPDataList<ItemListItem> list = analyser.RequestTOPDataList<ItemListItem>("taobao.items.get", q);
            Assert.AreEqual(40, list.Count);
            Assert.IsTrue(list.TotalResultNum > 100);
            Assert.IsFalse(string.IsNullOrEmpty(list[0].Title));
        }
Ejemplo n.º 14
0
        public void TestRequestTOPDataItem_测试请求服务器_正确()
        {
            string nick = "fengxiangxia";
            string id = "302a0499bf58d002de05da07f523f3f9";

            AnalyseData analyser = new AnalyseData(defaultAppKey, defaultAppSecret);
            Dictionary<string, string> q = new Dictionary<string, string>();
            q.Add("nick", nick);
            q.Add("iid", id);
            ItemListItem item = analyser.RequestTOPDataItem<ItemListItem>("taobao.item.get", q);
            Assert.AreEqual("302a0499bf58d002de05da07f523f3f9", item.Id);
            Assert.AreEqual("韩国代购THURSDAY ISLAND专柜正品&mdash;TB3TS05AU粉色短袖T恤", item.Title);
        }