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

Commit e0ea79d5 authored by wangyifan's avatar wangyifan

goblin 改成从mongodb查询商品

parent bdae082e
......@@ -27,8 +27,6 @@ import com.liquidnet.service.goblin.dto.vo.GoblinArtistAuthApplyVo;
import com.liquidnet.service.goblin.dto.vo.GoblinArtistTopicVo;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreInfoVo;
import com.liquidnet.service.goblin.entity.GoblinGoods;
import com.liquidnet.service.goblin.mapper.GoblinGoodsMapper;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtArtistService;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.QueueUtils;
......@@ -72,8 +70,6 @@ public class GoblinStoreMgtArtistServiceImpl implements IGoblinStoreMgtArtistSer
@Autowired
private QueueUtils queueUtils;
@Autowired
private GoblinGoodsMapper goodsMapper;
@Autowired
private KylinArtistMapper kylinArtistMapper;
private ResponseDto<GoblinStoreInfoVo> requireStore() {
......@@ -396,14 +392,14 @@ public class GoblinStoreMgtArtistServiceImpl implements IGoblinStoreMgtArtistSer
.map(GoblinArtistTopicVo.GoodsItem::getSpuId)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toSet());
Map<String, GoblinGoods> goodsMap = loadGoodsMapBySpuIds(spuIds);
Map<String, GoblinGoodsInfoVo> goodsMap = loadGoodsMapBySpuIds(spuIds);
for (GoblinArtistTopicVo.GoodsItem goods : topic.getGoods()) {
GoblinStoreMgtArtistTopicDetailVo.GoodsItem item = new GoblinStoreMgtArtistTopicDetailVo.GoodsItem();
item.setSpuId(goods.getSpuId());
item.setSort(goods.getSort());
item.setName(goods.getName());
item.setCoverPic(goods.getCoverPic());
GoblinGoods dbGoods = goodsMap.get(goods.getSpuId());
GoblinGoodsInfoVo dbGoods = goodsMap.get(goods.getSpuId());
if (dbGoods != null) {
item.setName(dbGoods.getName());
item.setCoverPic(dbGoods.getCoverPic());
......@@ -470,7 +466,7 @@ public class GoblinStoreMgtArtistServiceImpl implements IGoblinStoreMgtArtistSer
topicVo.setCreatedAt(now);
topicVo.setUpdatedAt(now);
Map<String, GoblinGoods> goodsMap = loadGoodsMap(params.getGoods());
Map<String, GoblinGoodsInfoVo> goodsMap = loadGoodsMap(params.getGoods());
List<GoblinArtistTopicVo.GoodsItem> goodsItems = buildGoodsItems(params.getGoods(), goodsMap);
ResponseDto<Void> goodsCheck = checkGoodsBelong(storeId, goodsMap, params.getGoods());
if (!goodsCheck.isSuccess()) {
......@@ -523,7 +519,7 @@ public class GoblinStoreMgtArtistServiceImpl implements IGoblinStoreMgtArtistSer
}
LocalDateTime now = LocalDateTime.now();
Map<String, GoblinGoods> goodsMap = loadGoodsMap(params.getGoods());
Map<String, GoblinGoodsInfoVo> goodsMap = loadGoodsMap(params.getGoods());
ResponseDto<Void> goodsCheck = checkGoodsBelong(storeId, goodsMap, params.getGoods());
if (!goodsCheck.isSuccess()) {
return ResponseDto.failure(goodsCheck.getMessage());
......@@ -681,14 +677,14 @@ public class GoblinStoreMgtArtistServiceImpl implements IGoblinStoreMgtArtistSer
return StringUtils.trimToNull(customAvatarUrl);
}
private ResponseDto<Void> checkGoodsBelong(String storeId, Map<String, GoblinGoods> goodsMap,
private ResponseDto<Void> checkGoodsBelong(String storeId, Map<String, GoblinGoodsInfoVo> goodsMap,
List<GoblinStoreMgtArtistTopicGoodsItemParams> paramsGoods) {
if (CollectionUtils.isEmpty(paramsGoods)) {
return ResponseDto.success(null);
}
for (GoblinStoreMgtArtistTopicGoodsItemParams item : paramsGoods) {
if (StringUtils.isBlank(item.getSpuId())) continue;
GoblinGoods goods = goodsMap.get(item.getSpuId());
GoblinGoodsInfoVo goods = goodsMap.get(item.getSpuId());
if (goods == null || !Objects.equals(goods.getStoreId(), storeId)
|| !Objects.equals(goods.getDelFlg(), "0")) {
return ResponseDto.failure("存在非本店或已删除商品");
......@@ -735,7 +731,7 @@ public class GoblinStoreMgtArtistServiceImpl implements IGoblinStoreMgtArtistSer
// ======================== 私有:商品 / 艺人 Map ========================
private Map<String, GoblinGoods> loadGoodsMap(List<GoblinStoreMgtArtistTopicGoodsItemParams> goods) {
private Map<String, GoblinGoodsInfoVo> loadGoodsMap(List<GoblinStoreMgtArtistTopicGoodsItemParams> goods) {
if (CollectionUtils.isEmpty(goods)) {
return Collections.emptyMap();
}
......@@ -744,22 +740,27 @@ public class GoblinStoreMgtArtistServiceImpl implements IGoblinStoreMgtArtistSer
return loadGoodsMapBySpuIds(spuIds);
}
private Map<String, GoblinGoods> loadGoodsMapBySpuIds(Set<String> spuIds) {
private Map<String, GoblinGoodsInfoVo> loadGoodsMapBySpuIds(Set<String> spuIds) {
if (CollectionUtils.isEmpty(spuIds)) {
return Collections.emptyMap();
}
List<GoblinGoods> list = goodsMapper.selectList(new LambdaQueryWrapper<GoblinGoods>()
.in(GoblinGoods::getSpuId, spuIds));
Map<String, GoblinGoods> map = new HashMap<>();
for (GoblinGoods g : list) {
List<GoblinGoodsInfoVo> list = mongoTemplate.find(
new Query(Criteria.where("spuId").in(spuIds)),
GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
Map<String, GoblinGoodsInfoVo> map = new HashMap<>();
if (list != null) {
for (GoblinGoodsInfoVo g : list) {
if (g != null && StringUtils.isNotBlank(g.getSpuId())) {
map.put(g.getSpuId(), g);
}
}
}
return map;
}
private List<GoblinArtistTopicVo.GoodsItem> buildGoodsItems(
List<GoblinStoreMgtArtistTopicGoodsItemParams> paramsGoods,
Map<String, GoblinGoods> goodsMap) {
Map<String, GoblinGoodsInfoVo> goodsMap) {
List<GoblinArtistTopicVo.GoodsItem> items = new ArrayList<>();
if (CollectionUtils.isEmpty(paramsGoods)) {
return items;
......@@ -770,7 +771,7 @@ public class GoblinStoreMgtArtistServiceImpl implements IGoblinStoreMgtArtistSer
GoblinArtistTopicVo.GoodsItem item = new GoblinArtistTopicVo.GoodsItem();
item.setSpuId(p.getSpuId());
item.setSort(p.getSort() == null ? index : p.getSort());
GoblinGoods goods = goodsMap.get(p.getSpuId());
GoblinGoodsInfoVo goods = goodsMap.get(p.getSpuId());
if (goods != null) {
item.setName(goods.getName());
item.setCoverPic(goods.getCoverPic());
......
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