热词统计,热词功能改版

This commit is contained in:
Chopper
2022-04-19 09:28:26 +08:00
parent 6ae9692358
commit 947a82eac5
22 changed files with 653 additions and 109 deletions

View File

@@ -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);
}
/**
* 当天的开始时间

View File

@@ -149,13 +149,13 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
.eq(StoreFlow::getFlowType, FlowTypeEnum.PAY));
storeFlow.setNum(afterSale.getNum());
storeFlow.setCategoryId(payStoreFlow.getCategoryId());
//佣金
//佣金 = (佣金/订单商品数量)* 售后商品数量
storeFlow.setCommissionPrice(CurrencyUtil.mul(CurrencyUtil.div(payStoreFlow.getCommissionPrice(), payStoreFlow.getNum()), afterSale.getNum()));
//分销佣金
//分销佣金 =(分校佣金/订单商品数量)* 售后商品数量
storeFlow.setDistributionRebate(CurrencyUtil.mul(CurrencyUtil.div(payStoreFlow.getDistributionRebate(), payStoreFlow.getNum()), afterSale.getNum()));
//流水金额
//流水金额 = 实际退款金额
storeFlow.setFinalPrice(afterSale.getActualRefundPrice());
//最终结算金额
//最终结算金额 =
storeFlow.setBillPrice(CurrencyUtil.add(storeFlow.getFinalPrice(), storeFlow.getDistributionRebate(), storeFlow.getCommissionPrice()));
//获取第三方支付流水号
RefundLog refundLog = refundLogService.queryByAfterSaleSn(afterSale.getSn());

View File

@@ -0,0 +1,47 @@
package cn.lili.modules.search.entity.dos;
import cn.lili.mybatis.BaseEntity;
import cn.lili.mybatis.BaseIdEntity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
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.data.annotation.CreatedDate;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.format.annotation.DateTimeFormat;
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 {
/**
* 词
*/
private String keywords;
/**
* 分数
*/
private Integer score;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date createTime;
}

View File

@@ -0,0 +1,80 @@
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;
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;
}
}

View File

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

View File

@@ -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 score,keywords,DATE_FORMAT(create_time,'%Y-%m-%d') AS create_time FROM li_hot_words_history " +" ${ew.customSqlSegment}")
List<HotWordsHistory> statistics(@Param(Constants.WRAPPER) Wrapper queryWrapper);
}

View File

@@ -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);
/**
* 获取筛选器
*

View File

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

View File

@@ -0,0 +1,38 @@
package cn.lili.modules.search.service;
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 hotWords 热词分数
*/
void setHotWords(HotWordsDTO hotWords);
/**
* 删除热门关键词
*
* @param keywords 热词
*/
void deleteHotWords(String keywords);
}

View File

@@ -100,38 +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) {
cache.zRemove(CachePrefix.HOT_WORD.getPrefix(), keywords);
}
@Override
public EsGoodsRelatedInfo getSelector(EsGoodsSearchDTO goodsSearch, PageVO pageVo) {
@@ -177,6 +145,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
return this.restTemplate.get(id, EsGoodsIndex.class);
}
/**
* 转换搜索结果为聚合商品展示信息
*

View File

@@ -0,0 +1,73 @@
package cn.lili.modules.search.serviceimpl;
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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* 历史热词
*
* @author paulG
* @since 2020/10/15
**/
@Service
public class HotWordsHistoryServiceImpl extends ServiceImpl<HotWordsHistoryMapper, HotWordsHistory> implements HotWordsHistoryService {
@Override
public List<HotWordsHistory> statistics(HotWordsSearchParams hotWordsSearchParams) {
QueryWrapper queryWrapper = hotWordsSearchParams.queryWrapper();
List<HotWordsHistory> list = baseMapper.statistics(queryWrapper);
return initData(list, hotWordsSearchParams);
}
@Override
public List<HotWordsHistory> queryByDay(Date queryTime) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("create_time", queryTime);
return list(queryWrapper);
}
/**
* 历史统计查询
*
* @param source
* @return
*/
private List<HotWordsHistory> initData(List<HotWordsHistory> source, HotWordsSearchParams hotWordsSearchParams) {
//结果集
List<HotWordsHistory> onlineMemberVOS = new ArrayList<>();
//时间初始化
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT-8:00"));
calendar.setTime(hotWordsSearchParams.getStartTIme());
//判定是否超出时间 如果结束时间在循环时间之后,则跳出循环
while (hotWordsSearchParams.getEndTime().after(calendar.getTime())) {
// //筛选时间相等的查询结果
Optional<HotWordsHistory> first = source.stream().filter(item -> item.getCreateTime().equals(calendar.getTime())).findFirst();
if (first.isPresent()) {
onlineMemberVOS.add(first.get());
} else {
onlineMemberVOS.add(new HotWordsHistory(hotWordsSearchParams.getKeywords(), 0, calendar.getTime()));
}
// for (HotWordsHistory hotWordsHistory : source) {
// System.out.println(hotWordsHistory.getCreateTime().getTime() + "-" + calendar.getTime().getTime());
// if (hotWordsHistory.getCreateTime().equals(calendar.getTime())) {
// onlineMemberVOS.add(hotWordsHistory);
// } else {
// onlineMemberVOS.add(new HotWordsHistory(hotWordsSearchParams.getKeywords(), 0, calendar.getTime()));
// }
// }
calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1);
}
return onlineMemberVOS;
}
}

View File

@@ -0,0 +1,68 @@
package cn.lili.modules.search.serviceimpl;
import cn.lili.cache.Cache;
import cn.lili.cache.CachePrefix;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
/**
* HotWordsServiceImpl
*
* @author Chopper
* @version v1.0
* 2022-04-14 09:35
*/
@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 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);
}
}

View File

@@ -70,7 +70,7 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
//结算基础信息
bill.setStartTime(startTime);
bill.setEndTime(DateUtil.yesterday());
bill.setEndTime(endTime);
bill.setBillStatus(BillStatusEnum.OUT.name());
bill.setStoreId(storeId);
bill.setStoreName(store.getStoreName());

View File

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

View File

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

View File

@@ -44,5 +44,7 @@ public enum SettingEnum {
//支付宝支付设置
ALIPAY_PAYMENT,
//微信支付设置
WECHAT_PAYMENT;
WECHAT_PAYMENT,
//热词设置
HOT_WORDS
}