记得上下班打卡 | git大法好,push需谨慎

Commit c46d59f9 authored by jiangxiulong's avatar jiangxiulong

app 商品列表与详情

parent f3ac304c
...@@ -122,6 +122,7 @@ public class GoblinRedisConst { ...@@ -122,6 +122,7 @@ public class GoblinRedisConst {
public static final String REDIS_GOBLIN_NFT_ORDER_INFO = PREFIX.concat("nftOrder:");// nft订单详情 public static final String REDIS_GOBLIN_NFT_ORDER_INFO = PREFIX.concat("nftOrder:");// nft订单详情
public static final String REDIS_GOBLIN_NFT_ORDER_USER_ID_LIST = PREFIX.concat("nftOrder:idList:user:");// nft用户订单id列表 public static final String REDIS_GOBLIN_NFT_ORDER_USER_ID_LIST = PREFIX.concat("nftOrder:idList:user:");// nft用户订单id列表
public static final String REDIS_GOBLIN_NFT_ORDER_REFUND_INFO = PREFIX.concat("nftOrder:refund:");// nft退款订单详情 public static final String REDIS_GOBLIN_NFT_ORDER_REFUND_INFO = PREFIX.concat("nftOrder:refund:");// nft退款订单详情
public static final String REDIS_GOBLIN_GOODS_LIST = PREFIX.concat("nftGoodsList");// nft商品列表
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
......
package com.liquidnet.service.goblin.service;
import com.github.pagehelper.PageInfo;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.*;
public interface IGoblinNftGoodsAppService {
ResponseDto<PageInfo<GoblinGoodsInfoVo>> goodsList(int pag);
GoblinGoodsInfoVo goodsDetail(String spuId, String skuId);
}
package com.liquidnet.service.goblin.controller;
import com.github.pagehelper.PageInfo;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.service.IGoblinNftGoodsAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@Api(tags = "NFT商品-App")
@RestController
@RequestMapping("/nftGoods")
public class GoblinNftGoodsAppController {
@Autowired
IGoblinNftGoodsAppService goblinNftGoodsAppService;
@GetMapping("list")
@ApiOperation("获得NFT商品列表")
@ApiImplicitParams({
@ApiImplicitParam(type = "query", dataType = "String", name = "page", value = "页码", example = "1"),
})
public ResponseDto<PageInfo<GoblinGoodsInfoVo>> getGoodsList(
@RequestParam(name = "page", defaultValue = "1") Integer page
) {
return goblinNftGoodsAppService.goodsList(page);
}
@GetMapping("detail")
@ApiOperation("获得商品详情")
@ApiImplicitParams({
@ApiImplicitParam(type = "query", required = true, dataType = "String", name = "spuId", value = "spuId", example = "1"),
@ApiImplicitParam(type = "query", required = true, dataType = "String", name = "skuId", value = "skuId", example = "1"),
})
public ResponseDto<GoblinGoodsInfoVo> getGoodsDetail(
@RequestParam("spuId") String spuId,
@RequestParam("skuId") String skuId
) {
GoblinGoodsInfoVo vo = goblinNftGoodsAppService.goodsDetail(spuId, skuId);
if (vo == null) {
return ResponseDto.failure("商品不存在");
}
return ResponseDto.success(vo);
}
}
package com.liquidnet.service.goblin.service.impl;
import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo;
import com.liquidnet.service.goblin.service.GoblinCouponService;
import com.liquidnet.service.goblin.service.IGoblinNftGoodsAppService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
@Slf4j
public class GoblinNftGoodsAppServiceImpl implements IGoblinNftGoodsAppService {
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
MongoTemplate mongoTemplate;
@Autowired
QueueUtils queueUtils;
@Autowired
GoblinMongoUtils mongoUtils;
@Autowired
GoblinCouponService goblinCouponService;
@Override
public ResponseDto<PageInfo<GoblinGoodsInfoVo>> goodsList(int page) {
int size = 20;
//条件
Query query = Query.query(
Criteria.where("spuType").is(1)
);
long count = mongoTemplate.count(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
List<GoblinGoodsInfoVo> spuList = goblinRedisUtils.getGoblinGoodsInfoVoList();
if (null == spuList || page > 1) {
// 排序 分页
Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdAt"));
query.with(pageable);
spuList = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
for (GoblinGoodsInfoVo info : spuList) {
List<String> skuIdList = info.getSkuIdList();
List<GoblinGoodsSkuInfoVo> spuSkuVoList = new ArrayList<>();
for (String skuId : skuIdList) {
GoblinGoodsSkuInfoVo skuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
spuSkuVoList.add(skuInfoVo);
}
info.setGoblinOrderSkuVos(spuSkuVoList);
}
if (page <= 1) {
goblinRedisUtils.setGoblinGoodsInfoVoList(spuList);
}
}
PageInfo<GoblinGoodsInfoVo> pageInfo = new PageInfo(spuList);
pageInfo.setTotal(count);
return ResponseDto.success(pageInfo);
}
@Override
public GoblinGoodsInfoVo goodsDetail(String spuId, String skuId) {
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(spuId);
if (null != goodsInfoVo) {
Integer buyCount = 0;
String userId = CurrentUtil.getCurrentUid();
if (StringUtils.isNotBlank(userId)) {
buyCount = goblinRedisUtils.getSkuCountByUid(userId, skuId);
}
GoblinGoodsSkuInfoVo goodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if (null != goodsSkuInfoVo && goodsSkuInfoVo.getDelFlg().equals("0") && goodsSkuInfoVo.getShelvesStatus().equals("3")) {
//获取 sku 库存数量
int stock = goblinRedisUtils.getSkuStock(null, skuId);
log.info("skuId:{}, 库存数量:{}", skuId, stock);
if (0 != goodsSkuInfoVo.getBuyLimit()) {
buyCount = 0;
// TODO: jxl 2022/3/25 新vo处理
// goodsSkuInfoVo.setCanBuy(goodsSkuInfoVo.getBuyLimit() - buyCount);
} else {
// goodsSkuInfoVo.setCanBuy(-9999);
}
if (stock <= 0) {
// goodsSkuInfoVo.setStockLess(true);
} else {
// goodsSkuInfoVo.setStockLess(false);
}
List<GoblinGoodsSkuInfoVo> spuSkuVoList = new ArrayList<>();
spuSkuVoList.add(goodsSkuInfoVo);
goodsInfoVo.setGoblinOrderSkuVos(spuSkuVoList);
} else {
return null;
}
} else {
return null;
}
return goodsInfoVo;
}
}
...@@ -1350,5 +1350,19 @@ public class GoblinRedisUtils { ...@@ -1350,5 +1350,19 @@ public class GoblinRedisUtils {
} }
} }
public List<GoblinGoodsInfoVo> getGoblinGoodsInfoVoList() {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_GOODS_LIST;
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (List<GoblinGoodsInfoVo>) obj;
}
}
public void setGoblinGoodsInfoVoList(List<GoblinGoodsInfoVo> spuList) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_GOODS_LIST;
redisUtil.set(redisKey, spuList);
}
/* ---------------------------------------- ---------------------------------------- */ /* ---------------------------------------- ---------------------------------------- */
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment