コード例 #1
0
  @Override
  public List<SkuStockInMemVo> getStocksBySkuIdList(List<Long> skuIdList) {
    if (skuIdList == null || skuIdList.size() <= 0) {
      logger.error("skuIdList is null or no elements");
      return null;
    }

    List<SkuStockInMemVo> skuStockInMemVoList = new ArrayList<SkuStockInMemVo>();
    for (Long skuId : skuIdList) {
      ResponseResult<Integer> result =
          dataStore.getValueByKeyAndField(CartConstant.SKU_STOCK_NAMESPACE, String.valueOf(skuId));

      if (result.getCode() == CodeInfoClass.COMMON_FAIL
          || result.getCode() == CodeInfoClass.NOT_EXIST) {
        logger.error(
            "system err or no stockCount found in mem,skuId:"
                + skuId
                + ",code:"
                + result.getCode());
        continue;
      }
      SkuStockInMemVo vo = new SkuStockInMemVo();
      vo.setSkuId(skuId);
      vo.setStockCount(result.getResult());
      skuStockInMemVoList.add(vo);
    }
    return skuStockInMemVoList;
  }
コード例 #2
0
  @Override
  public boolean insert(SkuStockInMemVo vo) {
    if (vo == null || vo.getSkuId() == null || vo.getStockCount() < 0) {
      logger.error("vo or stockCount is null,skuId:" + vo.getSkuId());
      return false;
    }

    ResponseResult<Integer> result =
        dataStore.putToHashNotExist(
            CartConstant.SKU_STOCK_NAMESPACE, String.valueOf(vo.getSkuId()), vo.getStockCount());

    return result.getCode() == CodeInfoClass.SUCCESS;
  }