예제 #1
0
        static List <JdGoodSummayInfoItemClass> getInfoBySukIds(List <string> skids)
        {
            //JdUnion_Goods_PromotionGoodsinfo_Class
            string dsName = "JDUnion_PromotionGoodsinfo";
            List <JdGoodSummayInfoItemClass> ret = new List <JdGoodSummayInfoItemClass>();

            if (skids.Count == 0)
            {
                return(ret);
            }
            List <DataCondition> dcs = new List <DataCondition>();
            DataCondition        dc  = new DataCondition();

            dc.Datapoint = new DataPoint("skuIds");
            dc.value     = string.Join(",", skids);
            dcs.Add(dc);
            string  msg     = null;
            bool    isExtra = false;
            DataSet ds      = DataSource.InitDataSource(dsName, dcs, GlobalShare.UserAppInfos.First().Key, out msg, ref isExtra, false);

            if (msg != null)
            {
                return(ret);
            }
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                DataRow dr = ds.Tables[0].Rows[i];
                JdGoodSummayInfoItemClass jsiic = new JdGoodSummayInfoItemClass();
                jsiic.skuId       = dr["JGD02"].ToString();
                jsiic.skuName     = dr["JGD03"].ToString();
                jsiic.imgageUrl   = dr["JGD08"].ToString();
                jsiic.materialUrl = dr["JGD09"].ToString();
                jsiic.price       = dr["JGD11"].ToString();
                jsiic.discount    = "";
                jsiic.couponLink  = "";
                ret.Add(jsiic);
            }
            return(ret);
        }
예제 #2
0
        public static Dictionary <string, JdGoodSummayInfoItemClass> Query(string name, int defaultReturnCnt = 3)
        {
            Dictionary <string, JdGoodSummayInfoItemClass> ret = new Dictionary <string, JdGoodSummayInfoItemClass>();

            if (!Inited)//先判断有没有初始化完成
            {
                LoadAllcommissionGoods?.Invoke();
            }
            if (AllcommissionGoods == null)
            {
                return(ret);
            }
            List <string> woldKeys = splitTheWords(name, true);
            int           maxWight = 0;

            for (int i = 0; i < woldKeys.Count; i++)
            {
                int weight = (int)Math.Pow(2, i);
                if (woldKeys[i].Length == 1)//单字全重为0
                {
                    weight = 1;
                }
                if (woldKeys[i] == "\r\n")
                {
                    weight = 0;
                }
                maxWight += weight;
            }
            Dictionary <string, int> matchWeights = new Dictionary <string, int>();

            foreach (string key in AllKeys.Keys)
            {
                List <string> keys = AllKeys[key];
                int           sum  = 0;
                for (int k = 0; k < keys.Count; k++)
                {
                    for (int i = 0; i < woldKeys.Count; i++) //关键词匹配次数 权重,前低后高,按2倍增
                    {
                        int weight = (int)Math.Pow(2, i);
                        if (woldKeys[i].Length == 1)//单字全重为0
                        {
                            weight = 1;
                        }
                        if (woldKeys[i] == "\r\n")
                        {
                            weight = 0;
                        }
                        if (keys[k] == woldKeys[i])
                        {
                            sum += weight;
                            break;
                        }
                    }
                }
                matchWeights.Add(key, sum);
            }
            var items = matchWeights.OrderByDescending(a => a.Value);

            if (items.First().Value == maxWight)
            {
                int i = 0;
                foreach (var val in items.Where(a => a.Value == maxWight))
                {
                    JdGoodSummayInfoItemClass item = AllcommissionGoods[val.Key];
                    ret.Add(item.skuId, item);
                    i++;
                    if (i >= defaultReturnCnt)
                    {
                        break;
                    }
                }
                return(ret);
            }
            foreach (var val in items.Where(a => a.Value > 0).Take(defaultReturnCnt))
            {
                JdGoodSummayInfoItemClass item = AllcommissionGoods[val.Key];
                ret.Add(item.skuId, item);
            }
            return(ret);
        }
예제 #3
0
        public static Dictionary <string, JdGoodSummayInfoItemClass> QueryWeb(string keyWord, int defaultReturnCnt = 10)
        {
            //AccessWebServerClass awc = new AccessWebServerClass();
            Dictionary <string, JdGoodSummayInfoItemClass> ret = new Dictionary <string, JdGoodSummayInfoItemClass>();

            try
            {
                string url = "https://union.jd.com/api/goods/search";

                string strJson = JdUnion_GlbObject.getJsonText("jd.union.search.model");
                if (string.IsNullOrEmpty(strJson))
                {
                    return(ret);
                }
                string strPostData = strJson.Replace("{0}", keyWord);
                string retJson     = AccessWebServerClass.PostData(url, strPostData, Encoding.UTF8);
                JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                searchReturnData     returnResult         = javaScriptSerializer.Deserialize <searchReturnData>(retJson);
                if (returnResult.code != 200)
                {
                    return(ret);
                }
                List <string> noMatchedList = new List <string>();
                for (int i = 0; i < returnResult.data.unionGoods.Count; i++)
                {
                    string id = returnResult.data.unionGoods[i][0].skuId;
                    JdGoodSummayInfoItemClass ji = new JdGoodSummayInfoItemClass();
                    if (AllcommissionGoods == null)
                    {
                        AllcommissionGoods = new Dictionary <string, JdGoodSummayInfoItemClass>();
                    }
                    if (AllcommissionGoods.ContainsKey(id))
                    {
                        ji = AllcommissionGoods[id];
                        ret.Add(id, ji);
                    }
                    else
                    {
                        if (noMatchedList.Count < defaultReturnCnt)
                        {
                            noMatchedList.Add(id);
                        }
                    }
                }
                List <JdGoodSummayInfoItemClass> res = null;
                if (LoadPromotionGoodsinfo != null)
                {
                    res = LoadPromotionGoodsinfo(noMatchedList);
                }
                else
                {
                    res = getInfoBySukIds(noMatchedList);
                }
                res.ForEach(a =>
                {
                    if (!ret.ContainsKey(a.skuId))
                    {
                        ret.Add(a.skuId, a);
                    }
                });
                return(ret);
            }
            catch (Exception ce)
            {
            }
            return(ret);
        }