Browse Source

feature-img-1.0:新增热点词记忆

feature-1.0-img
Penny 3 years ago
parent
commit
df3473c242
  1. 10
      bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/RedisKeyConstant.java
  2. 23
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java
  3. 38
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java
  4. 23
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java
  5. 25
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/HotSearchKeywordService.java
  6. 65
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/HotSearchKeywordServiceImpl.java
  7. 18
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/TiktokImgServiceImpl.java

10
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 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";
} }

23
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java

@ -79,6 +79,9 @@ public class FhMiniController extends BaseController {
@Autowired @Autowired
private FollowService followService; private FollowService followService;
@Autowired
private HotSearchKeywordService hotSearchKeywordService;
@ApiOperation(value="查询banner列表") @ApiOperation(value="查询banner列表")
@GetMapping(value = "/listBanner") @GetMapping(value = "/listBanner")
public AjaxResult listBanner(){ public AjaxResult listBanner(){
@ -351,4 +354,24 @@ public class FhMiniController extends BaseController {
List<CreatorFollowVo> creatorFollowVos = followService.queryFollowCreatorList(dto.getUserId(), "1"); List<CreatorFollowVo> creatorFollowVos = followService.queryFollowCreatorList(dto.getUserId(), "1");
return getDataTable(creatorFollowVos); 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();
}
} }

38
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.Feedback;
import com.bnyer.common.core.domain.R; import com.bnyer.common.core.domain.R;
import com.bnyer.common.core.dto.*; 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.controller.BaseController;
import com.bnyer.common.core.web.domain.AjaxResult; import com.bnyer.common.core.web.domain.AjaxResult;
import com.bnyer.common.core.web.page.TableDataInfo; 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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -76,6 +77,9 @@ public class TiktokMiniController extends BaseController {
@Autowired @Autowired
private FollowService followService; private FollowService followService;
@Autowired
private HotSearchKeywordService hotSearchKeywordService;
@ApiOperation(value="查询banner列表") @ApiOperation(value="查询banner列表")
@GetMapping(value = "/listBanner") @GetMapping(value = "/listBanner")
public AjaxResult listBanner(){ public AjaxResult listBanner(){
@ -283,13 +287,15 @@ public class TiktokMiniController extends BaseController {
@ApiOperation(value="根据标签名称查询图片分页") @ApiOperation(value="根据标签名称查询图片分页")
@PostMapping(value = "/querySignImgBySignName") @PostMapping(value = "/querySignImgBySignName")
public TableDataInfo querySignImgBySignName(@RequestBody @ApiParam("分页对象") SignImgNamePageDto dto){ public TableDataInfo querySignImgBySignName(@RequestBody @ApiParam("分页对象") SignImgNamePageDto dto) {
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
List<TiktokImgVo> tiktokImgs = tiktokImgService.queryImgPageBySignName(dto.getSignName()); List<TiktokImgVo> tiktokImgVos = tiktokImgService.queryImgPageBySignName(dto.getSignName());
if(tiktokImgs.size() <= 0){ if(tiktokImgVos != null){
throw new ServiceException("该标签名称不存在!"); return getDataTable(tiktokImgVos);
}else{
return getDataTable(new ArrayList<>());
} }
return getDataTable(tiktokImgs);
} }
@ -370,4 +376,24 @@ public class TiktokMiniController extends BaseController {
List<CreatorFollowVo> creatorFollowVos = followService.queryFollowCreatorList(dto.getUserId(), "0"); List<CreatorFollowVo> creatorFollowVos = followService.queryFollowCreatorList(dto.getUserId(), "0");
return getDataTable(creatorFollowVos); 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();
}
} }

23
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java

@ -79,6 +79,9 @@ public class WxMiniController extends BaseController {
@Autowired @Autowired
private FollowService followService; private FollowService followService;
@Autowired
private HotSearchKeywordService hotSearchKeywordService;
@ApiOperation(value="查询banner列表") @ApiOperation(value="查询banner列表")
@GetMapping(value = "/listBanner") @GetMapping(value = "/listBanner")
@ -381,4 +384,24 @@ public class WxMiniController extends BaseController {
List<CreatorFollowVo> creatorFollowVos = followService.queryFollowCreatorList(dto.getUserId(), "2"); List<CreatorFollowVo> creatorFollowVos = followService.queryFollowCreatorList(dto.getUserId(), "2");
return getDataTable(creatorFollowVos); 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();
}
} }

25
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<String> getHotKeywordList();
/**
* 点击增长热搜词热度次数
* @param keyword 热搜词
* @return -
*/
void incrementHotKeywordScore(String keyword);
/**
* 新增热搜词
* @param keyword 热搜词
*/
void insertHotKeyword(String keyword);
}

65
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<String> getHotKeywordList() {
Long now = System.currentTimeMillis();
List<String> result = new ArrayList<>();
ZSetOperations zSetOperations = redisService.redisTemplate.opsForZSet();
HashOperations hashOperations = redisService.redisTemplate.opsForHash();
Set<String> 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));
}
}

18
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.domain.TiktokLike;
import com.bnyer.common.core.dto.StatusDto; import com.bnyer.common.core.dto.StatusDto;
import com.bnyer.common.core.dto.TiktokImgMiniDto; import com.bnyer.common.core.dto.TiktokImgMiniDto;
import com.bnyer.common.core.utils.StringUtils;
import com.bnyer.common.redis.service.RedisService; import com.bnyer.common.redis.service.RedisService;
import com.bnyer.img.constants.StatusImgConstant; import com.bnyer.img.constants.StatusImgConstant;
import com.bnyer.img.mapper.ImgSignRelationMapper; import com.bnyer.img.mapper.ImgSignRelationMapper;
import com.bnyer.img.mapper.TiktokCollectionMapper; import com.bnyer.img.mapper.TiktokCollectionMapper;
import com.bnyer.img.mapper.TiktokImgMapper; import com.bnyer.img.mapper.TiktokImgMapper;
import com.bnyer.img.mapper.TiktokLikeMapper; import com.bnyer.img.mapper.TiktokLikeMapper;
import com.bnyer.img.service.HotSearchKeywordService;
import com.bnyer.img.service.TiktokImgService; import com.bnyer.img.service.TiktokImgService;
import com.bnyer.img.vo.*; import com.bnyer.img.vo.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -23,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -45,6 +48,9 @@ public class TiktokImgServiceImpl implements TiktokImgService {
@Autowired @Autowired
private ImgSignRelationMapper imgSignRelationMapper; private ImgSignRelationMapper imgSignRelationMapper;
@Autowired
private HotSearchKeywordService hotSearchKeywordService;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void insert(TiktokImgMiniDto dto) { public void insert(TiktokImgMiniDto dto) {
@ -210,7 +216,17 @@ public class TiktokImgServiceImpl implements TiktokImgService {
@Override @Override
public List<TiktokImgVo> queryImgPageBySignName(String signName) { public List<TiktokImgVo> queryImgPageBySignName(String signName) {
return tiktokImgMapper.queryImgPageBySignName(signName); if(StringUtils.isNotBlank(signName)){
List<TiktokImgVo> tiktokImgVos = tiktokImgMapper.queryImgPageBySignName(signName);
if(tiktokImgVos.size() > 0){
return tiktokImgVos;
}else{
return null;
}
}else{
//返回Null,则让前端界面判断,使其引导用户去用AI绘画
return null;
}
} }
@Override @Override

Loading…
Cancel
Save