Skip to content

Commit

Permalink
Merge branch 'hotwords'
Browse files Browse the repository at this point in the history
热词功能,管理端权限存在的问题处理
# 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
  • Loading branch information
chopper711 committed Apr 25, 2022
2 parents 2b21c3c + 8dc86e0 commit a6d734b
Show file tree
Hide file tree
Showing 26 changed files with 714 additions and 140 deletions.
16 changes: 15 additions & 1 deletion DB/version4.2.4toMASTER.sql
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -117,7 +121,7 @@ public ResultMessage<EsGoodsRelatedInfo> getGoodsRelatedByPageFromEs(EsGoodsSear
@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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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());
}
}
}

}
8 changes: 8 additions & 0 deletions framework/src/main/java/cn/lili/common/utils/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
* 当天的开始时间
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,6 @@ public AdminUser findByUsername(String username) {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<MenuVO> findUserTree() {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ public List<RoleMenu> findByRoleId(String roleId) {

@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);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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);

}
Loading

0 comments on commit a6d734b

Please sign in to comment.