diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/RedisKeyConstant.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/RedisKeyConstant.java index b17e8ab..903e961 100644 --- a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/RedisKeyConstant.java +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/RedisKeyConstant.java @@ -131,4 +131,14 @@ public class RedisKeyConstant { * 特约邀请码键 */ public static final String SPECIAL_INVITE_CODE_KEY = "bnyer.img.invite.status"; + + /** + * 热搜词 + */ + public static final String HOT_KEY_WORD_KEY = "bnyer.hotkeyword"; + + /** + * 热搜词存入时间 + */ + public static final String HOT_KEY_WORD_TIME_KEY = "bnyer.hotkeywordtime"; } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java index 2e89129..7d4d0a0 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java @@ -79,6 +79,9 @@ public class FhMiniController extends BaseController { @Autowired private FollowService followService; + @Autowired + private HotSearchKeywordService hotSearchKeywordService; + @ApiOperation(value="查询banner列表") @GetMapping(value = "/listBanner") public AjaxResult listBanner(){ @@ -351,4 +354,24 @@ public class FhMiniController extends BaseController { List creatorFollowVos = followService.queryFollowCreatorList(dto.getUserId(), "1"); return getDataTable(creatorFollowVos); } + + @ApiOperation(value="获取近一个月热度最高的前10条热搜词") + @GetMapping(value = "/getHotKeywordList") + public AjaxResult getHotKeywordList(){ + return AjaxResult.success(hotSearchKeywordService.getHotKeywordList()); + } + + @ApiOperation(value="点击增长热搜词热度次数") + @GetMapping(value = "/incrementHotKeywordScore/{keyword}") + public AjaxResult incrementHotKeywordScore(@PathVariable @ApiParam("热搜词") String keyword){ + hotSearchKeywordService.incrementHotKeywordScore(keyword); + return AjaxResult.success(); + } + + @ApiOperation(value="添加热搜词") + @GetMapping(value = "/insertHotKeyword/{keyword}") + public AjaxResult insertHotKeyword(@PathVariable @ApiParam("热搜词") String keyword){ + hotSearchKeywordService.insertHotKeyword(keyword); + return AjaxResult.success(); + } } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java index da2802a..83e573f 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java @@ -6,7 +6,6 @@ import com.bnyer.common.core.constant.TiktokConstant; import com.bnyer.common.core.domain.Feedback; import com.bnyer.common.core.domain.R; import com.bnyer.common.core.dto.*; -import com.bnyer.common.core.exception.ServiceException; import com.bnyer.common.core.web.controller.BaseController; import com.bnyer.common.core.web.domain.AjaxResult; import com.bnyer.common.core.web.page.TableDataInfo; @@ -22,6 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -76,6 +77,9 @@ public class TiktokMiniController extends BaseController { @Autowired private FollowService followService; + @Autowired + private HotSearchKeywordService hotSearchKeywordService; + @ApiOperation(value="查询banner列表") @GetMapping(value = "/listBanner") public AjaxResult listBanner(){ @@ -283,13 +287,15 @@ public class TiktokMiniController extends BaseController { @ApiOperation(value="根据标签名称查询图片分页") @PostMapping(value = "/querySignImgBySignName") - public TableDataInfo querySignImgBySignName(@RequestBody @ApiParam("分页对象") SignImgNamePageDto dto){ + public TableDataInfo querySignImgBySignName(@RequestBody @ApiParam("分页对象") SignImgNamePageDto dto) { PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); - List tiktokImgs = tiktokImgService.queryImgPageBySignName(dto.getSignName()); - if(tiktokImgs.size() <= 0){ - throw new ServiceException("该标签名称不存在!"); + List tiktokImgVos = tiktokImgService.queryImgPageBySignName(dto.getSignName()); + if(tiktokImgVos != null){ + return getDataTable(tiktokImgVos); + }else{ + return getDataTable(new ArrayList<>()); } - return getDataTable(tiktokImgs); + } @@ -370,4 +376,24 @@ public class TiktokMiniController extends BaseController { List creatorFollowVos = followService.queryFollowCreatorList(dto.getUserId(), "0"); return getDataTable(creatorFollowVos); } + + @ApiOperation(value="获取近一个月热度最高的前10条热搜词") + @GetMapping(value = "/getHotKeywordList") + public AjaxResult getHotKeywordList(){ + return AjaxResult.success(hotSearchKeywordService.getHotKeywordList()); + } + + @ApiOperation(value="点击增长热搜词热度次数") + @GetMapping(value = "/incrementHotKeywordScore/{keyword}") + public AjaxResult incrementHotKeywordScore(@PathVariable @ApiParam("热搜词") String keyword){ + hotSearchKeywordService.incrementHotKeywordScore(keyword); + return AjaxResult.success(); + } + + @ApiOperation(value="添加热搜词") + @GetMapping(value = "/insertHotKeyword/{keyword}") + public AjaxResult insertHotKeyword(@PathVariable @ApiParam("热搜词") String keyword){ + hotSearchKeywordService.insertHotKeyword(keyword); + return AjaxResult.success(); + } } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java index 610a52f..309b967 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java @@ -79,6 +79,9 @@ public class WxMiniController extends BaseController { @Autowired private FollowService followService; + @Autowired + private HotSearchKeywordService hotSearchKeywordService; + @ApiOperation(value="查询banner列表") @GetMapping(value = "/listBanner") @@ -381,4 +384,24 @@ public class WxMiniController extends BaseController { List creatorFollowVos = followService.queryFollowCreatorList(dto.getUserId(), "2"); return getDataTable(creatorFollowVos); } + + @ApiOperation(value="获取近一个月热度最高的前10条热搜词") + @GetMapping(value = "/getHotKeywordList") + public AjaxResult getHotKeywordList(){ + return AjaxResult.success(hotSearchKeywordService.getHotKeywordList()); + } + + @ApiOperation(value="点击增长热搜词热度次数") + @GetMapping(value = "/incrementHotKeywordScore/{keyword}") + public AjaxResult incrementHotKeywordScore(@PathVariable @ApiParam("热搜词") String keyword){ + hotSearchKeywordService.incrementHotKeywordScore(keyword); + return AjaxResult.success(); + } + + @ApiOperation(value="添加热搜词") + @GetMapping(value = "/insertHotKeyword/{keyword}") + public AjaxResult insertHotKeyword(@PathVariable @ApiParam("热搜词") String keyword){ + hotSearchKeywordService.insertHotKeyword(keyword); + return AjaxResult.success(); + } } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/HotSearchKeywordService.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/HotSearchKeywordService.java new file mode 100644 index 0000000..a11a855 --- /dev/null +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/HotSearchKeywordService.java @@ -0,0 +1,25 @@ +package com.bnyer.img.service; + +import java.util.List; + +public interface HotSearchKeywordService { + + /** + * 获取最近一个月搜索次数最多的前10条记录 + * @return - + */ + List getHotKeywordList(); + + /** + * 点击增长热搜词热度次数 + * @param keyword 热搜词 + * @return - + */ + void incrementHotKeywordScore(String keyword); + + /** + * 新增热搜词 + * @param keyword 热搜词 + */ + void insertHotKeyword(String keyword); +} diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/HotSearchKeywordServiceImpl.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/HotSearchKeywordServiceImpl.java new file mode 100644 index 0000000..d148308 --- /dev/null +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/HotSearchKeywordServiceImpl.java @@ -0,0 +1,65 @@ +package com.bnyer.img.service.impl; + +import com.bnyer.common.core.constant.RedisKeyConstant; +import com.bnyer.common.redis.service.RedisService; +import com.bnyer.img.service.HotSearchKeywordService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.data.redis.core.ZSetOperations; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +@Service +@Slf4j +public class HotSearchKeywordServiceImpl implements HotSearchKeywordService { + + @Autowired + private RedisService redisService; + + + + @Override + public List getHotKeywordList() { + Long now = System.currentTimeMillis(); + List result = new ArrayList<>(); + ZSetOperations zSetOperations = redisService.redisTemplate.opsForZSet(); + HashOperations hashOperations = redisService.redisTemplate.opsForHash(); + Set value = zSetOperations.reverseRangeByScore(RedisKeyConstant.HOT_KEY_WORD_KEY, 0, Double.MAX_VALUE); + //key不为空的时候 推荐相关的最热前十名 + for (String val : value) { + if (result.size() > 9) {//只返回最热的前十名 + break; + } + Long time = Long.valueOf((String) hashOperations.get(RedisKeyConstant.HOT_KEY_WORD_TIME_KEY, val)); + if ((now - time) < 2592000000L) {//返回最近一个月的数据 + result.add(val); + } else {//时间超过一个月没搜索就把这个词热度归0 + zSetOperations.add(RedisKeyConstant.HOT_KEY_WORD_KEY, val, 0); + } + } + return result; + } + + @Override + public void incrementHotKeywordScore(String keyword) { + Long now = System.currentTimeMillis(); + ZSetOperations zSetOperations = redisService.redisTemplate.opsForZSet(); + HashOperations hashOperations = redisService.redisTemplate.opsForHash(); + zSetOperations.incrementScore(RedisKeyConstant.HOT_KEY_WORD_KEY, keyword, 1); + hashOperations.put(RedisKeyConstant.HOT_KEY_WORD_TIME_KEY,keyword,String.valueOf(now)); + } + + @Override + public void insertHotKeyword(String keyword) { + Long now = System.currentTimeMillis(); + ZSetOperations zSetOperations = redisService.redisTemplate.opsForZSet(); + HashOperations hashOperations = redisService.redisTemplate.opsForHash(); + zSetOperations.incrementScore(RedisKeyConstant.HOT_KEY_WORD_KEY, keyword, 1); + hashOperations.put(RedisKeyConstant.HOT_KEY_WORD_TIME_KEY,keyword,String.valueOf(now)); + } +} diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/TiktokImgServiceImpl.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/TiktokImgServiceImpl.java index 40185a5..96399d1 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/TiktokImgServiceImpl.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/TiktokImgServiceImpl.java @@ -8,12 +8,14 @@ import com.bnyer.common.core.domain.TiktokImg; import com.bnyer.common.core.domain.TiktokLike; import com.bnyer.common.core.dto.StatusDto; import com.bnyer.common.core.dto.TiktokImgMiniDto; +import com.bnyer.common.core.utils.StringUtils; import com.bnyer.common.redis.service.RedisService; import com.bnyer.img.constants.StatusImgConstant; import com.bnyer.img.mapper.ImgSignRelationMapper; import com.bnyer.img.mapper.TiktokCollectionMapper; import com.bnyer.img.mapper.TiktokImgMapper; import com.bnyer.img.mapper.TiktokLikeMapper; +import com.bnyer.img.service.HotSearchKeywordService; import com.bnyer.img.service.TiktokImgService; import com.bnyer.img.vo.*; import lombok.extern.slf4j.Slf4j; @@ -23,6 +25,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -45,6 +48,9 @@ public class TiktokImgServiceImpl implements TiktokImgService { @Autowired private ImgSignRelationMapper imgSignRelationMapper; + @Autowired + private HotSearchKeywordService hotSearchKeywordService; + @Override @Transactional(rollbackFor = Exception.class) public void insert(TiktokImgMiniDto dto) { @@ -210,7 +216,17 @@ public class TiktokImgServiceImpl implements TiktokImgService { @Override public List queryImgPageBySignName(String signName) { - return tiktokImgMapper.queryImgPageBySignName(signName); + if(StringUtils.isNotBlank(signName)){ + List tiktokImgVos = tiktokImgMapper.queryImgPageBySignName(signName); + if(tiktokImgVos.size() > 0){ + return tiktokImgVos; + }else{ + return null; + } + }else{ + //返回Null,则让前端界面判断,使其引导用户去用AI绘画 + return null; + } } @Override