コード例 #1
0
ファイル: GoodsHanlder.cs プロジェクト: jk464479460/target
        //搜索
        public ResultGoodsSearch SearchGoods(QuerySearchGoods query)
        {
            var result = new ResultGoodsSearch {
                Exception = new MyException()
            };

            if (!ValidateInput(query.GoodsName) && !string.IsNullOrEmpty(query.GoodsName))
            {
                result.Exception.Success = false;
                result.Exception.Exmsg   = $"{IndexShow.输入不合法仅允许输入数字字母汉字下划线}";
                return(result);
            }
            try
            {
                var whereStr = string.Empty;
                if (query.StockType != 0)
                {
                    whereStr = $" and StockType={query.StockType}";
                }
                var cacheGoodsResult = _redisOper.GetHash <IList <GoodsDisplayInfo> >("AllGoods");
                if (cacheGoodsResult == null)
                {
                    var allGoodsList = _goodsHandler.GetGoodsInfoByName(whereStr);
                    _redisOper.HSet("AllGoods", allGoodsList);
                }
                var cacheList = _redisOper.GetHash <IList <GoodsDisplayInfo> >("AllGoods");
                var search1   = !string.IsNullOrEmpty(query.GoodsName)?(from p in cacheList where p.GoodsName.Contains(query.GoodsName) select p).ToList():cacheList;
                if (query.StockType == 6)
                {
                    var discountList = _goodsHandler.GetDiscountInfo();
                    search1   = (from p in search1 where discountList.Contains(p.Code) select p).ToList();
                    cacheList = search1;
                }
                var goodsDisplayInfos = search1.ToList();
                result.GoodsList = !string.IsNullOrEmpty(query.GoodsName)
                    ? goodsDisplayInfos.Skip(query.PageNum * (query.PageIndex - 1)).Take(query.PageNum).ToList()
                    : cacheList.Skip(query.PageNum * (query.PageIndex - 1)).Take(query.PageNum).ToList();
                result.PageIndex         = query.PageIndex;
                result.PageTotal         = goodsDisplayInfos.Count / query.PageNum + (goodsDisplayInfos.Count % query.PageNum > 0 ? 1: 0);
                result.Exception.Success = true;
            }
            catch (Exception ex)
            {
                result.Exception.Success = false;
                result.Exception.Exmsg   = $"{ex.Message}";
            }
            return(result);
        }
コード例 #2
0
        public string GoodsSearch([FromBody] QuerySearchGoods goodsStockIn)
        {
            var result = new GoodsHanlder().SearchGoods(goodsStockIn);

            return(JsonConvert.SerializeObject(result));
        }