|
|
|
@ -18,6 +18,7 @@ package cc.hiver.mall.controller; |
|
|
|
import cc.hiver.core.common.constant.ShopConstant; |
|
|
|
import cc.hiver.core.common.constant.ShopUserConstant; |
|
|
|
import cc.hiver.core.common.constant.UserConstant; |
|
|
|
import cc.hiver.core.common.redis.RedisTemplateHelper; |
|
|
|
import cc.hiver.core.common.utils.PageUtil; |
|
|
|
import cc.hiver.core.common.utils.ResultUtil; |
|
|
|
import cc.hiver.core.common.utils.SecurityUtil; |
|
|
|
@ -28,27 +29,28 @@ import cc.hiver.core.entity.User; |
|
|
|
import cc.hiver.core.service.UserService; |
|
|
|
import cc.hiver.mall.entity.Shop; |
|
|
|
import cc.hiver.mall.entity.ShopArea; |
|
|
|
import cc.hiver.mall.entity.ShopTakeaway; |
|
|
|
import cc.hiver.mall.entity.ShopUser; |
|
|
|
import cc.hiver.mall.invitelog.service.InviteLogService; |
|
|
|
import cc.hiver.mall.pojo.dto.ShopCacheDTO; |
|
|
|
import cc.hiver.mall.pojo.dto.ShopRevenue; |
|
|
|
import cc.hiver.mall.pojo.query.ProductPageQuery; |
|
|
|
import cc.hiver.mall.pojo.vo.ProductPageVO; |
|
|
|
import cc.hiver.mall.pojo.vo.QueryShopRevenueVO; |
|
|
|
import cc.hiver.mall.service.ShopAreaService; |
|
|
|
import cc.hiver.mall.service.ShopService; |
|
|
|
import cc.hiver.mall.service.ShopTakeawayService; |
|
|
|
import cc.hiver.mall.service.ShopUserService; |
|
|
|
import cn.hutool.core.text.CharSequenceUtil; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import cc.hiver.core.common.redis.RedisTemplateHelper; |
|
|
|
import cc.hiver.mall.pojo.dto.ShopCacheDTO; |
|
|
|
import org.springframework.data.domain.PageImpl; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.domain.Page; |
|
|
|
import org.springframework.data.domain.PageImpl; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
@ -87,6 +89,9 @@ public class ShopController { |
|
|
|
@Autowired |
|
|
|
private RedisTemplateHelper redisTemplateHelper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ShopTakeawayService shopTakeawayService; |
|
|
|
|
|
|
|
@RequestMapping(value = "/getAll", method = RequestMethod.GET) |
|
|
|
@ApiOperation("获取全部数据") |
|
|
|
public Result<List<Shop>> getAll() { |
|
|
|
@ -230,11 +235,43 @@ public class ShopController { |
|
|
|
ShopCacheDTO dto = JSONUtil.toBean(v.toString(), ShopCacheDTO.class); |
|
|
|
Shop s = dto.getShop(); |
|
|
|
s.setProducts(dto.getProducts()); |
|
|
|
s.setShopTakeaway(dto.getShopTakeaway()); |
|
|
|
if (CharSequenceUtil.isNotBlank(shop.getShopArea())) { |
|
|
|
if (!shop.getShopArea().equals(s.getShopArea())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if(s.getStatus() != 1){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (CharSequenceUtil.isNotBlank(shop.getShopType())) { |
|
|
|
if (!shop.getShopType().equals(s.getShopType())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (CharSequenceUtil.isNotBlank(shop.getKeyWord())) { |
|
|
|
String kw = shop.getKeyWord(); |
|
|
|
boolean match = false; |
|
|
|
if (s.getShopName() != null && s.getShopName().contains(kw)) { |
|
|
|
match = true; |
|
|
|
} else { |
|
|
|
String productsJson = redisTemplateHelper.get("SHOP_PRODUCTS:" + s.getId()); |
|
|
|
if (CharSequenceUtil.isNotBlank(productsJson)) { |
|
|
|
List<ProductPageVO> products = JSONUtil.toList(productsJson, ProductPageVO.class); |
|
|
|
if (products != null) { |
|
|
|
for (ProductPageVO p : products) { |
|
|
|
if (p.getDelFlag() == 1 && p.getProductName() != null && p.getProductName().contains(kw)) { |
|
|
|
match = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!match) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
allShops.add(s); |
|
|
|
} |
|
|
|
|
|
|
|
@ -253,6 +290,10 @@ public class ShopController { |
|
|
|
BigDecimal score1 = s1.getShopScore() == null ? BigDecimal.ZERO : s1.getShopScore(); |
|
|
|
BigDecimal score2 = s2.getShopScore() == null ? BigDecimal.ZERO : s2.getShopScore(); |
|
|
|
compareResult = score1.compareTo(score2); |
|
|
|
} else if ("shoprank".equals(sort)) { |
|
|
|
Integer shoprank1 = s1.getShoprank() == null ? 0 : s1.getShoprank(); |
|
|
|
Integer shoprank2 = s2.getShoprank() == null ? 0 : s2.getShoprank(); |
|
|
|
compareResult = shoprank1.compareTo(shoprank2); |
|
|
|
} |
|
|
|
if ("desc".equalsIgnoreCase(order)) { |
|
|
|
return -compareResult; |
|
|
|
@ -261,8 +302,8 @@ public class ShopController { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
int pageNumber = pageVo.getPageNumber() == null ? 1 : pageVo.getPageNumber(); |
|
|
|
int pageSize = pageVo.getPageSize() == null ? 10 : pageVo.getPageSize(); |
|
|
|
int pageNumber = pageVo.getPageNumber() > 0 ? pageVo.getPageNumber() : 1; |
|
|
|
int pageSize = pageVo.getPageSize() > 0 ? pageVo.getPageSize() : 10; |
|
|
|
int fromIndex = (pageNumber - 1) * pageSize; |
|
|
|
int toIndex = Math.min(fromIndex + pageSize, allShops.size()); |
|
|
|
List<Shop> pageList; |
|
|
|
@ -272,6 +313,40 @@ public class ShopController { |
|
|
|
pageList = allShops.subList(fromIndex, toIndex); |
|
|
|
} |
|
|
|
|
|
|
|
// --- 核心优化:获取当前页的商品数据(二层缓存架构的核心拼装) ---
|
|
|
|
if (!pageList.isEmpty()) { |
|
|
|
List<String> productKeys = new ArrayList<>(); |
|
|
|
for (Shop s : pageList) { |
|
|
|
productKeys.add("SHOP_PRODUCTS:" + s.getId()); |
|
|
|
} |
|
|
|
List<String> productsJsonList = redisTemplateHelper.multiGet(productKeys); |
|
|
|
if (productsJsonList != null && productsJsonList.size() == pageList.size()) { |
|
|
|
for (int i = 0; i < pageList.size(); i++) { |
|
|
|
String productsJson = productsJsonList.get(i); |
|
|
|
if (CharSequenceUtil.isNotBlank(productsJson)) { |
|
|
|
List<ProductPageVO> productsReturn = new ArrayList<>(); |
|
|
|
List<ProductPageVO> products = JSONUtil.toList(productsJson, ProductPageVO.class); |
|
|
|
if (CharSequenceUtil.isNotBlank(shop.getKeyWord())) { |
|
|
|
for (ProductPageVO p : products) { |
|
|
|
if (p.getDelFlag() == 1 && p.getProductName() != null && p.getProductName().contains(shop.getKeyWord())) { |
|
|
|
productsReturn.add(p); |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
for (ProductPageVO p : products) { |
|
|
|
if (p.getDelFlag() == 1 && p.getIsPush() == 1) { |
|
|
|
productsReturn.add(p); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
pageList.get(i).setProducts(productsReturn); |
|
|
|
} else { |
|
|
|
pageList.get(i).setProducts(new ArrayList<>()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Page<Shop> pageResult = new PageImpl<>(pageList, PageUtil.initPage(pageVo), allShops.size()); |
|
|
|
return new ResultUtil<Page<Shop>>().setData(pageResult); |
|
|
|
} |
|
|
|
@ -283,27 +358,39 @@ public class ShopController { |
|
|
|
page.getContent().forEach(e -> { |
|
|
|
shopIdList.add(e.getId()); |
|
|
|
}); |
|
|
|
//查询推荐商品
|
|
|
|
final ProductPageQuery productPageQuery = new ProductPageQuery(); |
|
|
|
productPageQuery.setShopIdList(shopIdList); |
|
|
|
productPageQuery.setIsPush(ShopUserConstant.SHOP_ADMIN_COST[1]); |
|
|
|
IPage<ProductPageVO> productList = shopService.getShareList(productPageQuery); |
|
|
|
|
|
|
|
page.getContent().forEach(e -> { |
|
|
|
final List<ProductPageVO> products = new ArrayList<>(); |
|
|
|
if(productList.getRecords() != null && productList.getRecords().size() > 0){ |
|
|
|
productList.getRecords().forEach(productPageVO -> { |
|
|
|
if (e.getId().equals(productPageVO.getShopId())) { |
|
|
|
products.add(productPageVO); |
|
|
|
} |
|
|
|
}); |
|
|
|
if(shopIdList.size() > 0){ |
|
|
|
//查询业务信息
|
|
|
|
List<ShopTakeaway> shopTakeaways = shopTakeawayService.selectListByshopId(shopIdList); |
|
|
|
//查询推荐商品
|
|
|
|
final ProductPageQuery productPageQuery = new ProductPageQuery(); |
|
|
|
productPageQuery.setPageNum(1); |
|
|
|
productPageQuery.setPageSize(100); |
|
|
|
productPageQuery.setShopIdList(shopIdList); |
|
|
|
productPageQuery.setDelFlag(1); |
|
|
|
if(CharSequenceUtil.isBlank(shop.getKeyWord())){ |
|
|
|
productPageQuery.setIsPush(ShopUserConstant.SHOP_ADMIN_COST[1]); |
|
|
|
}else{ |
|
|
|
productPageQuery.setProductName(shop.getKeyWord()); |
|
|
|
} |
|
|
|
|
|
|
|
e.setProducts(products); |
|
|
|
if (CharSequenceUtil.isNotBlank(regionId)) { |
|
|
|
shopService.refreshShopCache(e.getId(), regionId); |
|
|
|
} |
|
|
|
}); |
|
|
|
IPage<ProductPageVO> productList = shopService.getShareList(productPageQuery); |
|
|
|
|
|
|
|
page.getContent().forEach(e -> { |
|
|
|
final List<ProductPageVO> products = new ArrayList<>(); |
|
|
|
if(productList.getRecords().size() > 0){ |
|
|
|
productList.getRecords().forEach(productPageVO -> { |
|
|
|
if (e.getId().equals(productPageVO.getShopId())) { |
|
|
|
products.add(productPageVO); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
e.setProducts(products); |
|
|
|
for(ShopTakeaway shopTakeawa : shopTakeaways) { |
|
|
|
if (e.getId().equals(shopTakeawa.getShopId())) { |
|
|
|
e.setShopTakeaway(shopTakeawa); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
return new ResultUtil<Page<Shop>>().setData(page); |
|
|
|
} |
|
|
|
|
|
|
|
|