Merge branch 'hotwords'
热词功能,管理端权限存在的问题处理 # Conflicts: # framework/src/main/java/cn/lili/modules/order/order/serviceimpl/StoreFlowServiceImpl.java # framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java # manager-api/src/main/java/cn/lili/controller/hotwords/HotWordsManagerController.java
This commit is contained in:
commit
a6d734bacf
@ -1,4 +1,18 @@
|
||||
/** 增加签到日期 **/
|
||||
ALTER TABLE li_member_sign ADD day int DEFAULT NULL COMMENT '签到日 ';
|
||||
ALTER TABLE li_member_sign DROP INDEX uk_member_day;
|
||||
ALTER TABLE li_member_sign add unique uk_member_day (member_id, day) COMMENT 'uk_member_day';
|
||||
ALTER TABLE li_member_sign add unique uk_member_day (member_id, day) COMMENT 'uk_member_day';
|
||||
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for li_hot_words_history
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `li_hot_words_history`;
|
||||
CREATE TABLE `li_hot_words_history` (
|
||||
`id` bigint NOT NULL COMMENT 'ID',
|
||||
`create_time` datetime(6) DEFAULT NULL COMMENT '创建时间',
|
||||
`keywords` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '热词',
|
||||
`score` int DEFAULT NULL COMMENT '热词分数',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;
|
||||
|
@ -14,6 +14,7 @@ import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsRelatedInfo;
|
||||
import cn.lili.modules.search.entity.dto.EsGoodsSearchDTO;
|
||||
import cn.lili.modules.search.service.EsGoodsSearchService;
|
||||
import cn.lili.modules.search.service.HotWordsService;
|
||||
import cn.lili.modules.statistics.aop.PageViewPoint;
|
||||
import cn.lili.modules.statistics.aop.enums.PageViewEnum;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -62,6 +63,9 @@ public class GoodsBuyerController {
|
||||
@Autowired
|
||||
private EsGoodsSearchService goodsSearchService;
|
||||
|
||||
@Autowired
|
||||
private HotWordsService hotWordsService;
|
||||
|
||||
@ApiOperation(value = "通过id获取商品信息")
|
||||
@ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "path", dataType = "Long")
|
||||
@GetMapping(value = "/get/{goodsId}")
|
||||
@ -117,7 +121,7 @@ public class GoodsBuyerController {
|
||||
@ApiOperation(value = "获取搜索热词")
|
||||
@GetMapping("/hot-words")
|
||||
public ResultMessage<List<String>> getGoodsHotWords(Integer count) {
|
||||
List<String> hotWords = goodsSearchService.getHotWords(count);
|
||||
List<String> hotWords = hotWordsService.getHotWords(count);
|
||||
return ResultUtil.data(hotWords);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,24 @@
|
||||
package cn.lili.timetask.handler.impl.hotwords;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.cache.Cache;
|
||||
import cn.lili.cache.CachePrefix;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.modules.search.entity.dos.HotWordsHistory;
|
||||
import cn.lili.modules.search.service.HotWordsHistoryService;
|
||||
import cn.lili.modules.system.entity.dos.Setting;
|
||||
import cn.lili.modules.system.entity.dto.HotWordsSetting;
|
||||
import cn.lili.modules.system.entity.dto.HotWordsSettingItem;
|
||||
import cn.lili.modules.system.entity.enums.SettingEnum;
|
||||
import cn.lili.modules.system.service.SettingService;
|
||||
import cn.lili.timetask.handler.EveryDayExecute;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.DefaultTypedTuple;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author paulG
|
||||
@ -18,13 +31,54 @@ public class HotWordsEveryDayTaskExecute implements EveryDayExecute {
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
|
||||
@Autowired
|
||||
private HotWordsHistoryService hotWordsHistoryService;
|
||||
@Autowired
|
||||
private SettingService settingService;
|
||||
|
||||
/**
|
||||
* 执行每日任务
|
||||
*/
|
||||
@Override
|
||||
public void execute() {
|
||||
//获取大于0分的热词
|
||||
Set<DefaultTypedTuple> tuples = cache.zRangeByScore(CachePrefix.HOT_WORD.getPrefix(), 1, Integer.MAX_VALUE);
|
||||
//如果任务不为空
|
||||
if (!CollectionUtils.isEmpty(tuples)) {
|
||||
|
||||
//因为是第二天统计第一天的数据,所以这里获取昨天凌晨的时间
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - 1);
|
||||
|
||||
//批量保存热词
|
||||
List<HotWordsHistory> hotWordsHistories = new ArrayList<>();
|
||||
for (DefaultTypedTuple tuple : tuples) {
|
||||
String keywords = (String) tuple.getValue();
|
||||
Double score = tuple.getScore();
|
||||
hotWordsHistories.add(new HotWordsHistory(keywords, score.intValue(), calendar.getTime()));
|
||||
}
|
||||
|
||||
hotWordsHistoryService.saveBatch(hotWordsHistories);
|
||||
}
|
||||
//移除昨日的热搜词
|
||||
cache.remove(CachePrefix.HOT_WORD.getPrefix());
|
||||
|
||||
//设置今日默认热词
|
||||
Setting setting = settingService.get(SettingEnum.HOT_WORDS.name());
|
||||
if (setting == null) {
|
||||
return;
|
||||
}
|
||||
HotWordsSetting hotWordsSetting = JSONUtil.toBean(setting.getSettingValue(), HotWordsSetting.class);
|
||||
List<HotWordsSettingItem> hotWordsSettingItems = hotWordsSetting.getHotWordsSettingItems();
|
||||
if (hotWordsSettingItems != null && !hotWordsSettingItems.isEmpty()) {
|
||||
for (HotWordsSettingItem hotWordsSettingItem : hotWordsSettingItems) {
|
||||
cache.zAdd(CachePrefix.HOT_WORD.getPrefix(), hotWordsSettingItem.getScore(), hotWordsSettingItem.getKeywords());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,14 @@ public class DateUtil {
|
||||
public static Long getDayOfStart() {
|
||||
return DateUtil.getDateline()/(60*24*60);
|
||||
}
|
||||
/**
|
||||
* 指定日的开始时间
|
||||
*
|
||||
* @return 指定日时间
|
||||
*/
|
||||
public static Long getDayOfStart(Date date) {
|
||||
return date.getTime()/(60*24*60);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当天的开始时间
|
||||
|
@ -24,7 +24,7 @@ public interface MenuMapper extends BaseMapper<Menu> {
|
||||
@Select("SELECT menu.* FROM li_menu AS menu WHERE menu.id IN (" +
|
||||
"SELECT rm.menu_id FROM li_role_menu AS rm WHERE rm.role_id IN (" +
|
||||
"SELECT ur.role_id FROM li_user_role AS ur WHERE ur.user_id=#{userId}) OR rm.role_id IN (" +
|
||||
"SELECT dr.role_id FROM li_department_role AS dr WHERE dr.id=(" +
|
||||
"SELECT dr.role_id FROM li_department_role AS dr WHERE dr.department_id =(" +
|
||||
"SELECT department_id FROM li_admin_user AS au WHERE au.id = #{userId})))")
|
||||
List<Menu> findByUserId(String userId);
|
||||
|
||||
|
@ -141,15 +141,6 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
AdminUserVO adminUserVO = new AdminUserVO(user);
|
||||
//关联部门
|
||||
if (user.getDepartmentId() != null) {
|
||||
Department department = departmentService.getById(user.getDepartmentId());
|
||||
if (department != null) {
|
||||
adminUserVO.setDepartmentTitle(department.getTitle());
|
||||
}
|
||||
}
|
||||
adminUserVO.setMenus(menuService.findUserList(user.getId()));
|
||||
return user;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
||||
if (Boolean.TRUE.equals(authUser.getIsSuper())) {
|
||||
return this.tree();
|
||||
}
|
||||
List<Menu> userMenus = this.baseMapper.findByUserId(authUser.getId());
|
||||
List<Menu> userMenus = this.findUserList(authUser.getId());
|
||||
return this.tree(userMenus);
|
||||
}
|
||||
|
||||
|
@ -47,13 +47,7 @@ public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> i
|
||||
|
||||
@Override
|
||||
public List<UserMenuVO> findAllMenu(String userId) {
|
||||
String cacheKey = CachePrefix.USER_MENU.getPrefix() + userId;
|
||||
List<UserMenuVO> menuList = (List<UserMenuVO>) cache.get(cacheKey);
|
||||
if (menuList == null) {
|
||||
menuList = menuMapper.getUserRoleMenu(userId);
|
||||
cache.put(cacheKey, menuList);
|
||||
}
|
||||
return menuList;
|
||||
return menuMapper.getUserRoleMenu(userId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,52 @@
|
||||
package cn.lili.modules.search.entity.dos;
|
||||
|
||||
import cn.lili.mybatis.BaseIdEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* HotWordsHistory
|
||||
*
|
||||
* @author Chopper
|
||||
* @version v1.0
|
||||
* 2022-04-14 09:39
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("li_hot_words_history")
|
||||
public class HotWordsHistory extends BaseIdEntity implements Comparable<HotWordsHistory>, Serializable {
|
||||
|
||||
/**
|
||||
* 词
|
||||
*/
|
||||
private String keywords;
|
||||
|
||||
/**
|
||||
* 分数
|
||||
*/
|
||||
private Integer score;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
public HotWordsHistory(String keywords, Integer score) {
|
||||
this.keywords = keywords;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(HotWordsHistory hotWordsHistory) {
|
||||
return hotWordsHistory.getScore() - this.score;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package cn.lili.modules.search.entity.dto;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
|
||||
import cn.lili.modules.statistics.entity.dto.StatisticsQueryParam;
|
||||
import cn.lili.modules.statistics.util.StatisticsDateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品查询条件
|
||||
*
|
||||
* @author pikachu
|
||||
* @since 2020-02-24 19:27:20
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class HotWordsSearchParams extends PageVO {
|
||||
|
||||
private static final long serialVersionUID = 2544015852728566887L;
|
||||
|
||||
@NotNull(message = "搜索热词不能为空")
|
||||
@ApiModelProperty(value = "热词")
|
||||
private String keywords;
|
||||
|
||||
@ApiModelProperty(value = "快捷搜索", allowableValues = "TODAY, YESTERDAY, LAST_SEVEN, LAST_THIRTY")
|
||||
private String searchType;
|
||||
|
||||
@ApiModelProperty(value = "类型:年(YEAR)、月(MONTH)")
|
||||
private String timeType;
|
||||
|
||||
@ApiModelProperty(value = "年份")
|
||||
private Integer year;
|
||||
|
||||
@ApiModelProperty(value = "月份")
|
||||
private Integer month;
|
||||
|
||||
|
||||
//临时参数 不作为前端传递
|
||||
private Date startTIme;
|
||||
|
||||
private Date endTime;
|
||||
|
||||
//搜索热词数量
|
||||
private Integer top = 50;
|
||||
|
||||
public <T> QueryWrapper<T> queryWrapper() {
|
||||
//组织查询时间
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||
StatisticsQueryParam statisticsQueryParam = new StatisticsQueryParam();
|
||||
BeanUtils.copyProperties(this, statisticsQueryParam);
|
||||
Date[] dates = StatisticsDateUtil.getDateArray(statisticsQueryParam);
|
||||
|
||||
//获取当前时间
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
|
||||
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
if (StringUtils.isNotEmpty(keywords)) {
|
||||
queryWrapper.like("keywords", keywords);
|
||||
}
|
||||
queryWrapper.between("create_time", dates[0], dates[1]);
|
||||
|
||||
startTIme = dates[0];
|
||||
endTime = dates[1];
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cn.lili.modules.search.entity.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 在线会员
|
||||
*
|
||||
* @author Chopper
|
||||
* @since 2021-02-21 09:59
|
||||
*/
|
||||
@Data
|
||||
public class HotWordsHistoryVO {
|
||||
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 词
|
||||
*/
|
||||
private String keywords;
|
||||
|
||||
/**
|
||||
* 分数
|
||||
*/
|
||||
private Integer score;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package cn.lili.modules.search.mapper;
|
||||
|
||||
import cn.lili.modules.search.entity.dos.CustomWords;
|
||||
import cn.lili.modules.search.entity.dos.HotWordsHistory;
|
||||
import cn.lili.modules.search.entity.vo.HotWordsHistoryVO;
|
||||
import cn.lili.modules.statistics.entity.vo.OrderStatisticsDataVO;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 搜索热词历史记录数据处理层
|
||||
*
|
||||
* @author paulG
|
||||
* @since 2020/10/15
|
||||
**/
|
||||
public interface HotWordsHistoryMapper extends BaseMapper<HotWordsHistory> {
|
||||
|
||||
/**
|
||||
* 获取订单统计数据
|
||||
*
|
||||
* @param queryWrapper 查询条件
|
||||
* @return 订单统计列表
|
||||
*/
|
||||
@Select("SELECT sum(score) as score,keywords FROM li_hot_words_history " +" ${ew.customSqlSegment}")
|
||||
List<HotWordsHistory> statistics(@Param(Constants.WRAPPER) Wrapper queryWrapper);
|
||||
|
||||
}
|
@ -26,28 +26,6 @@ public interface EsGoodsSearchService {
|
||||
*/
|
||||
SearchPage<EsGoodsIndex> searchGoods(EsGoodsSearchDTO searchDTO, PageVO pageVo);
|
||||
|
||||
/**
|
||||
* 获取热门关键词
|
||||
*
|
||||
* @param count 热词数量
|
||||
* @return 热词集合
|
||||
*/
|
||||
List<String> getHotWords(Integer count);
|
||||
|
||||
/**
|
||||
* 设置热门关键词
|
||||
*
|
||||
* @param hotWords 热词分数
|
||||
*/
|
||||
void setHotWords(HotWordsDTO hotWords);
|
||||
|
||||
/**
|
||||
* 删除热门关键词
|
||||
*
|
||||
* @param keywords 热词
|
||||
*/
|
||||
void deleteHotWords(String keywords);
|
||||
|
||||
/**
|
||||
* 获取筛选器
|
||||
*
|
||||
|
@ -0,0 +1,41 @@
|
||||
package cn.lili.modules.search.service;
|
||||
|
||||
import cn.lili.modules.search.entity.dos.CustomWords;
|
||||
import cn.lili.modules.search.entity.dos.HotWordsHistory;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsDTO;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsSearchParams;
|
||||
import cn.lili.modules.search.entity.vo.HotWordsHistoryVO;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* HotWordsService
|
||||
*
|
||||
* @author Chopper
|
||||
* @version v1.0
|
||||
* 2022-04-14 09:35
|
||||
*/
|
||||
public interface HotWordsHistoryService extends IService<HotWordsHistory> {
|
||||
|
||||
/**
|
||||
* 热词统计
|
||||
*
|
||||
* @param hotWordsSearchParams
|
||||
* @return
|
||||
*/
|
||||
List<HotWordsHistory> statistics(HotWordsSearchParams hotWordsSearchParams);
|
||||
|
||||
/**
|
||||
* 根据时间查询
|
||||
*
|
||||
* @param queryTime 查询时间
|
||||
* @return
|
||||
*/
|
||||
List<HotWordsHistory> queryByDay(Date queryTime);
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package cn.lili.modules.search.service;
|
||||
|
||||
import cn.lili.modules.search.entity.dos.HotWordsHistory;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* HotWordsService
|
||||
*
|
||||
* @author Chopper
|
||||
* @version v1.0
|
||||
* 2022-04-14 09:35
|
||||
*/
|
||||
public interface HotWordsService {
|
||||
|
||||
/**
|
||||
* 获取热门关键词
|
||||
*
|
||||
* @param count 热词数量
|
||||
* @return 热词集合
|
||||
*/
|
||||
List<String> getHotWords(Integer count);
|
||||
|
||||
/**
|
||||
* 获取热门关键词
|
||||
*
|
||||
* @param count 热词数量
|
||||
* @return 热词集合
|
||||
*/
|
||||
List<HotWordsHistory> getHotWordsVO(Integer count);
|
||||
|
||||
/**
|
||||
* 设置热门关键词
|
||||
*
|
||||
* @param hotWords 热词分数
|
||||
*/
|
||||
void setHotWords(HotWordsDTO hotWords);
|
||||
|
||||
/**
|
||||
* 删除热门关键词
|
||||
*
|
||||
* @param keywords 热词
|
||||
*/
|
||||
void deleteHotWords(String keywords);
|
||||
|
||||
}
|
@ -36,9 +36,10 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.SearchHitSupport;
|
||||
import org.springframework.data.elasticsearch.core.SearchHits;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
@ -72,7 +73,8 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
* ES
|
||||
*/
|
||||
@Autowired
|
||||
private ElasticsearchOperations restTemplate;
|
||||
@Qualifier("elasticsearchRestTemplate")
|
||||
private ElasticsearchRestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private EsGoodsIndexService esGoodsIndexService;
|
||||
@ -98,42 +100,6 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
return SearchHitSupport.searchPageFor(search, searchQuery.getPageable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHotWords(Integer count) {
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
List<String> hotWords = new ArrayList<>();
|
||||
// redis 排序中,下标从0开始,所以这里需要 -1 处理
|
||||
count = count - 1;
|
||||
Set<ZSetOperations.TypedTuple<Object>> set = cache.reverseRangeWithScores(CachePrefix.HOT_WORD.getPrefix(), count);
|
||||
if (set == null || set.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
for (ZSetOperations.TypedTuple<Object> defaultTypedTuple : set) {
|
||||
hotWords.add(Objects.requireNonNull(defaultTypedTuple.getValue()).toString());
|
||||
}
|
||||
return hotWords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHotWords(HotWordsDTO hotWords) {
|
||||
cache.incrementScore(CachePrefix.HOT_WORD.getPrefix(), hotWords.getKeywords(), hotWords.getPoint());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除热门关键词
|
||||
*
|
||||
* @param keywords 热词
|
||||
*/
|
||||
@Override
|
||||
public void deleteHotWords(String keywords) {
|
||||
if (CharSequenceUtil.isEmpty(keywords)) {
|
||||
cache.vagueDel(CachePrefix.HOT_WORD.getPrefix());
|
||||
} else {
|
||||
cache.zRemove(CachePrefix.HOT_WORD.getPrefix(), keywords);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EsGoodsRelatedInfo getSelector(EsGoodsSearchDTO goodsSearch, PageVO pageVo) {
|
||||
@ -179,6 +145,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
||||
return this.restTemplate.get(id, EsGoodsIndex.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 转换搜索结果为聚合商品展示信息
|
||||
*
|
||||
|
@ -0,0 +1,53 @@
|
||||
package cn.lili.modules.search.serviceimpl;
|
||||
|
||||
import cn.lili.common.utils.DateUtil;
|
||||
import cn.lili.modules.search.entity.dos.HotWordsHistory;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsSearchParams;
|
||||
import cn.lili.modules.search.mapper.HotWordsHistoryMapper;
|
||||
import cn.lili.modules.search.service.HotWordsHistoryService;
|
||||
import cn.lili.modules.search.service.HotWordsService;
|
||||
import cn.lili.modules.statistics.entity.enums.SearchTypeEnum;
|
||||
import cn.lili.modules.statistics.util.StatisticsDateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 历史热词
|
||||
*
|
||||
* @author paulG
|
||||
* @since 2020/10/15
|
||||
**/
|
||||
@Service
|
||||
public class HotWordsHistoryServiceImpl extends ServiceImpl<HotWordsHistoryMapper, HotWordsHistory> implements HotWordsHistoryService {
|
||||
|
||||
@Autowired
|
||||
private HotWordsService hotWordsService;
|
||||
|
||||
@Override
|
||||
public List<HotWordsHistory> statistics(HotWordsSearchParams hotWordsSearchParams) {
|
||||
if (hotWordsSearchParams.getSearchType().equals(SearchTypeEnum.TODAY.name())) {
|
||||
return hotWordsService.getHotWordsVO(hotWordsSearchParams.getTop());
|
||||
}
|
||||
QueryWrapper queryWrapper = hotWordsSearchParams.queryWrapper();
|
||||
|
||||
queryWrapper.groupBy("keywords");
|
||||
queryWrapper.orderByDesc("score");
|
||||
queryWrapper.last("limit " + hotWordsSearchParams.getTop());
|
||||
List<HotWordsHistory> list = baseMapper.statistics(queryWrapper);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HotWordsHistory> queryByDay(Date queryTime) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
|
||||
Date[] dates = StatisticsDateUtil.getDateArray(queryTime);
|
||||
queryWrapper.between("create_time", dates[0], dates[1]);
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package cn.lili.modules.search.serviceimpl;
|
||||
|
||||
import cn.lili.cache.Cache;
|
||||
import cn.lili.cache.CachePrefix;
|
||||
import cn.lili.modules.search.entity.dos.HotWordsHistory;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsDTO;
|
||||
import cn.lili.modules.search.mapper.HotWordsHistoryMapper;
|
||||
import cn.lili.modules.search.service.HotWordsService;
|
||||
import cn.lili.modules.system.entity.dos.Setting;
|
||||
import cn.lili.modules.system.entity.enums.SettingEnum;
|
||||
import cn.lili.modules.system.service.SettingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* HotWordsServiceImpl
|
||||
*
|
||||
* @author Chopper
|
||||
* @version v1.0
|
||||
* 2022-04-14 09:35
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class HotWordsServiceImpl implements HotWordsService {
|
||||
|
||||
/**
|
||||
* 缓存
|
||||
*/
|
||||
@Autowired
|
||||
private Cache<Object> cache;
|
||||
|
||||
@Override
|
||||
public List<String> getHotWords(Integer count) {
|
||||
if (count == null) {
|
||||
count = 0;
|
||||
}
|
||||
List<String> hotWords = new ArrayList<>();
|
||||
// redis 排序中,下标从0开始,所以这里需要 -1 处理
|
||||
count = count - 1;
|
||||
Set<ZSetOperations.TypedTuple<Object>> set = cache.reverseRangeWithScores(CachePrefix.HOT_WORD.getPrefix(), count);
|
||||
if (set == null || set.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
for (ZSetOperations.TypedTuple<Object> defaultTypedTuple : set) {
|
||||
hotWords.add(Objects.requireNonNull(defaultTypedTuple.getValue()).toString());
|
||||
}
|
||||
return hotWords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HotWordsHistory> getHotWordsVO(Integer count) {
|
||||
if (count == null) {
|
||||
count = 50;
|
||||
}
|
||||
List<HotWordsHistory> hotWords = new ArrayList<>();
|
||||
// redis 排序中,下标从0开始,所以这里需要 -1 处理
|
||||
count = count - 1;
|
||||
Set<ZSetOperations.TypedTuple<Object>> set = cache.reverseRangeWithScores(CachePrefix.HOT_WORD.getPrefix(), count);
|
||||
if (set == null || set.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
for (ZSetOperations.TypedTuple<Object> defaultTypedTuple : set) {
|
||||
try {
|
||||
hotWords.add(new HotWordsHistory(defaultTypedTuple.getValue().toString(),
|
||||
defaultTypedTuple.getScore().intValue()));
|
||||
} catch (Exception e) {
|
||||
log.error("读取热词错误", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(hotWords);
|
||||
return hotWords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHotWords(HotWordsDTO hotWords) {
|
||||
cache.incrementScore(CachePrefix.HOT_WORD.getPrefix(), hotWords.getKeywords(), hotWords.getPoint());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除热门关键词
|
||||
*
|
||||
* @param keywords 热词
|
||||
*/
|
||||
@Override
|
||||
public void deleteHotWords(String keywords) {
|
||||
cache.zRemove(CachePrefix.HOT_WORD.getPrefix(), keywords);
|
||||
}
|
||||
|
||||
}
|
@ -121,4 +121,30 @@ public class StatisticsDateUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据一个日期,获取这一天的开始时间和结束时间
|
||||
*
|
||||
* @param queryDate
|
||||
* @return
|
||||
*/
|
||||
public static Date[] getDateArray(Date queryDate) {
|
||||
|
||||
Date[] dateArray = new Date[2];
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(queryDate);
|
||||
//时间归到今天凌晨0点
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
dateArray[0] = calendar.getTime();
|
||||
|
||||
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1);
|
||||
calendar.set(Calendar.SECOND, calendar.get(Calendar.SECOND) - 1);
|
||||
|
||||
dateArray[1] = calendar.getTime();
|
||||
return dateArray;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package cn.lili.modules.system.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 搜索热词
|
||||
*
|
||||
* @author Bulbasaur
|
||||
* @since 2021/5/16 11:10 下午
|
||||
*/
|
||||
@Data
|
||||
public class HotWordsSetting implements Serializable {
|
||||
|
||||
//热词1-5,默认分数1-5
|
||||
|
||||
@ApiModelProperty(value = "热词默认配置")
|
||||
private List<HotWordsSettingItem> hotWordsSettingItems = new ArrayList<>();
|
||||
|
||||
|
||||
@ApiModelProperty("每日保存数量")
|
||||
private Integer saveNum;
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package cn.lili.modules.system.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 积分签到设置
|
||||
*
|
||||
* @author Chopper
|
||||
* @since 2021-02-26 11:48
|
||||
*/
|
||||
@Data
|
||||
public class HotWordsSettingItem implements Comparable<HotWordsSettingItem>, Serializable {
|
||||
|
||||
|
||||
@ApiModelProperty(value = "热词")
|
||||
private String keywords;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "默认分数")
|
||||
private Integer score;
|
||||
|
||||
|
||||
public Integer getScore() {
|
||||
if (score == null || score < 0) {
|
||||
return 0;
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(Integer score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(HotWordsSettingItem pointSettingItem) {
|
||||
return pointSettingItem.getScore();
|
||||
}
|
||||
}
|
@ -44,5 +44,7 @@ public enum SettingEnum {
|
||||
//支付宝支付设置
|
||||
ALIPAY_PAYMENT,
|
||||
//微信支付设置
|
||||
WECHAT_PAYMENT;
|
||||
WECHAT_PAYMENT,
|
||||
//热词设置
|
||||
HOT_WORDS
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
package cn.lili.controller.hotwords;
|
||||
|
||||
import cn.lili.common.enums.ResultUtil;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsDTO;
|
||||
import cn.lili.modules.search.service.EsGoodsSearchService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 管理端,app版本控制器
|
||||
*
|
||||
* @author Chopper
|
||||
* @since 2018-07-04 21:50:52
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "管理端,系统设置扩展接口")
|
||||
@RequestMapping("/manager/hotwords/hotwords")
|
||||
public class HotWordsManagerController {
|
||||
|
||||
@Autowired
|
||||
private EsGoodsSearchService esGoodsSearchService;
|
||||
|
||||
@ApiOperation(value = "获取热词")
|
||||
@GetMapping
|
||||
public ResultMessage<Object> getHotWords() {
|
||||
return ResultUtil.data(esGoodsSearchService.getHotWords(100));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "设置热词")
|
||||
@PostMapping
|
||||
public ResultMessage<Object> paymentForm(@Validated HotWordsDTO hotWords) {
|
||||
esGoodsSearchService.setHotWords(hotWords);
|
||||
return ResultUtil.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除热词")
|
||||
@DeleteMapping("/{words}")
|
||||
public ResultMessage<Object> deleteWords(@PathVariable String words) {
|
||||
esGoodsSearchService.deleteHotWords(words);
|
||||
return ResultUtil.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除全部热词")
|
||||
@DeleteMapping("")
|
||||
public ResultMessage<Object> deleteWordsAll() {
|
||||
esGoodsSearchService.deleteHotWords(null);
|
||||
return ResultUtil.success();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package cn.lili.controller.other;
|
||||
|
||||
import cn.lili.common.enums.ResultUtil;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.search.entity.dos.HotWordsHistory;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsDTO;
|
||||
import cn.lili.modules.search.entity.dto.HotWordsSearchParams;
|
||||
import cn.lili.modules.search.service.HotWordsHistoryService;
|
||||
import cn.lili.modules.search.service.HotWordsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 管理端,热词管理
|
||||
*
|
||||
* @author Chopper
|
||||
* @since 2018-07-04 21:50:52
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "管理端,热词管理")
|
||||
@RequestMapping("/manager/hotwords/hotwords")
|
||||
public class HotWordsManagerController {
|
||||
|
||||
@Autowired
|
||||
private HotWordsService hotWordsService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private HotWordsHistoryService hotWordsHistoryService;
|
||||
|
||||
@ApiOperation(value = "获取热词")
|
||||
@GetMapping
|
||||
public ResultMessage<Object> getHotWords() {
|
||||
return ResultUtil.data(hotWordsService.getHotWords(100));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "设置热词")
|
||||
@PostMapping
|
||||
public ResultMessage<Object> setHotWords(@Validated HotWordsDTO hotWords) {
|
||||
hotWordsService.setHotWords(hotWords);
|
||||
return ResultUtil.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除热词")
|
||||
@DeleteMapping
|
||||
public ResultMessage<Object> deleteWords(String words) {
|
||||
hotWordsService.deleteHotWords(words);
|
||||
return ResultUtil.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "历史热词")
|
||||
@GetMapping("/history")
|
||||
public ResultMessage<Object> deleteWords(HistorySearchParams historySearchParams) {
|
||||
List<HotWordsHistory> hotWordsHistoryList = hotWordsHistoryService.queryByDay(historySearchParams.getDate());
|
||||
Collections.sort(hotWordsHistoryList);
|
||||
return ResultUtil.data(hotWordsHistoryList);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "热词统计")
|
||||
@GetMapping("/statistics")
|
||||
public ResultMessage<Object> deleteWords(HotWordsSearchParams hotWordsSearchParams) {
|
||||
return ResultUtil.data(hotWordsHistoryService.statistics(hotWordsSearchParams));
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
class HistorySearchParams {
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@NotNull(message = "查询日期不能为空")
|
||||
private Date date;
|
||||
|
||||
}
|
@ -88,13 +88,10 @@ public class AdminUserManagerController {
|
||||
|
||||
@GetMapping(value = "/info")
|
||||
@ApiOperation(value = "获取当前登录用户接口")
|
||||
public ResultMessage<AdminUserVO> getUserInfo() {
|
||||
public ResultMessage<AdminUser> getUserInfo() {
|
||||
AuthUser tokenUser = UserContext.getCurrentUser();
|
||||
if (tokenUser != null) {
|
||||
AdminUserVO adminUser = new AdminUserVO(adminUserService.findByUsername(tokenUser.getUsername()));
|
||||
if (StringUtils.isNotEmpty(adminUser.getDepartmentId())) {
|
||||
adminUser.setDepartmentTitle(departmentService.getById(adminUser.getDepartmentId()).getTitle());
|
||||
}
|
||||
AdminUser adminUser = adminUserService.findByUsername(tokenUser.getUsername());
|
||||
adminUser.setPassword(null);
|
||||
return ResultUtil.data(adminUser);
|
||||
}
|
||||
|
@ -185,6 +185,10 @@ public class SettingManagerController {
|
||||
return setting == null ?
|
||||
ResultUtil.data(new ImSetting()) :
|
||||
ResultUtil.data(JSONUtil.toBean(setting.getSettingValue(), ImSetting.class));
|
||||
case HOT_WORDS:
|
||||
return setting == null ?
|
||||
ResultUtil.data(new HotWordsSetting()) :
|
||||
ResultUtil.data(JSONUtil.toBean(setting.getSettingValue(), HotWordsSetting.class));
|
||||
default:
|
||||
throw new ServiceException(ResultCode.SETTING_NOT_TO_SET);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user