Merge branch 'master' of https://gitee.com/beijing_hongye_huicheng/lilishop
This commit is contained in:
commit
6c95679ad2
@ -455,6 +455,16 @@ public enum CachePrefix {
|
|||||||
*/
|
*/
|
||||||
ARTICLE_CACHE,
|
ARTICLE_CACHE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化索引
|
||||||
|
*/
|
||||||
|
INIT_INDEX_PROCESS,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化索引标示
|
||||||
|
*/
|
||||||
|
INIT_INDEX_FLAG,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺分类
|
* 店铺分类
|
||||||
*/
|
*/
|
||||||
|
@ -439,8 +439,8 @@ public enum ResultCode {
|
|||||||
CUSTOM_WORDS_EXIST_ERROR(90000, "当前自定义分词已存在!"),
|
CUSTOM_WORDS_EXIST_ERROR(90000, "当前自定义分词已存在!"),
|
||||||
CUSTOM_WORDS_NOT_EXIST_ERROR(90001, "当前自定义分词不存在!"),
|
CUSTOM_WORDS_NOT_EXIST_ERROR(90001, "当前自定义分词不存在!"),
|
||||||
CUSTOM_WORDS_SECRET_KEY_ERROR(90002, "秘钥验证失败!"),
|
CUSTOM_WORDS_SECRET_KEY_ERROR(90002, "秘钥验证失败!"),
|
||||||
CONNECT_NOT_EXIST(90000, "登录方式不存在"),
|
CONNECT_NOT_EXIST(90000, "登录方式不存在!"),
|
||||||
|
ELASTICSEARCH_INDEX_INIT_ERROR(90003, "索引初始化失败!"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Integer code;
|
private final Integer code;
|
||||||
|
@ -253,6 +253,9 @@ public abstract class BaseElasticsearchService {
|
|||||||
" }\n" +
|
" }\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
|
" \"recommend\": {\n" +
|
||||||
|
" \"type\": \"boolean\"\n" +
|
||||||
|
" },\n" +
|
||||||
" \"selfOperated\": {\n" +
|
" \"selfOperated\": {\n" +
|
||||||
" \"type\": \"boolean\"\n" +
|
" \"type\": \"boolean\"\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cn.lili.modules.member.entity.aop.interceptor;
|
package cn.lili.modules.member.entity.aop.interceptor;
|
||||||
|
|
||||||
import cn.lili.common.utils.CurrencyUtil;
|
|
||||||
import cn.lili.modules.member.entity.dos.Member;
|
import cn.lili.modules.member.entity.dos.Member;
|
||||||
import cn.lili.modules.member.entity.dos.MemberPointsHistory;
|
import cn.lili.modules.member.entity.dos.MemberPointsHistory;
|
||||||
import cn.lili.modules.member.entity.enums.PointTypeEnum;
|
import cn.lili.modules.member.entity.enums.PointTypeEnum;
|
||||||
@ -45,11 +44,16 @@ public class PointLogInterceptor {
|
|||||||
if (obj[1] != null) {
|
if (obj[1] != null) {
|
||||||
type = obj[1].toString();
|
type = obj[1].toString();
|
||||||
}
|
}
|
||||||
//会员ID
|
// 会员ID
|
||||||
String memberId = "";
|
String memberId = "";
|
||||||
if (obj[2] != null) {
|
if (obj[2] != null) {
|
||||||
memberId = obj[2].toString();
|
memberId = obj[2].toString();
|
||||||
}
|
}
|
||||||
|
// 变动积分为0,则直接返回
|
||||||
|
if (point == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//根据会员id查询会员信息
|
//根据会员id查询会员信息
|
||||||
Member member = memberService.getById(memberId);
|
Member member = memberService.getById(memberId);
|
||||||
if (member != null) {
|
if (member != null) {
|
||||||
|
@ -17,8 +17,6 @@ import javax.persistence.Column;
|
|||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.Max;
|
|
||||||
import javax.validation.constraints.Min;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +48,7 @@ public class MemberPointsHistory {
|
|||||||
|
|
||||||
@CreatedDate
|
@CreatedDate
|
||||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
@TableField(fill = FieldFill.INSERT)
|
@TableField(fill = FieldFill.INSERT)
|
||||||
@ApiModelProperty(value = "创建时间", hidden = true)
|
@ApiModelProperty(value = "创建时间", hidden = true)
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
@ -23,6 +23,9 @@ public class EsGoodsSearchDTO {
|
|||||||
@ApiModelProperty(value = "品牌,可以多选 品牌Id@品牌Id@品牌Id")
|
@ApiModelProperty(value = "品牌,可以多选 品牌Id@品牌Id@品牌Id")
|
||||||
private String brandId;
|
private String brandId;
|
||||||
|
|
||||||
|
@ApiModelProperty("是否为推荐商品")
|
||||||
|
private Boolean recommend;
|
||||||
|
|
||||||
@ApiModelProperty(value = "价格", example = "10_30")
|
@ApiModelProperty(value = "价格", example = "10_30")
|
||||||
private String price;
|
private String price;
|
||||||
|
|
||||||
|
@ -6,18 +6,20 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
import cn.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.pinyin.PinyinUtil;
|
import cn.hutool.extra.pinyin.PinyinUtil;
|
||||||
|
import cn.lili.cache.Cache;
|
||||||
|
import cn.lili.cache.CachePrefix;
|
||||||
|
import cn.lili.common.enums.PromotionTypeEnum;
|
||||||
import cn.lili.elasticsearch.BaseElasticsearchService;
|
import cn.lili.elasticsearch.BaseElasticsearchService;
|
||||||
import cn.lili.elasticsearch.EsSuffix;
|
import cn.lili.elasticsearch.EsSuffix;
|
||||||
import cn.lili.elasticsearch.config.ElasticsearchProperties;
|
import cn.lili.elasticsearch.config.ElasticsearchProperties;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsWords;
|
import cn.lili.modules.goods.entity.dos.GoodsWords;
|
||||||
|
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
||||||
import cn.lili.modules.goods.entity.enums.GoodsWordsTypeEnum;
|
import cn.lili.modules.goods.entity.enums.GoodsWordsTypeEnum;
|
||||||
import cn.lili.modules.goods.service.GoodsWordsService;
|
import cn.lili.modules.goods.service.GoodsWordsService;
|
||||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||||
import cn.lili.modules.promotion.entity.dto.BasePromotion;
|
import cn.lili.modules.promotion.entity.dto.BasePromotion;
|
||||||
import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum;
|
import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum;
|
||||||
import cn.lili.common.enums.PromotionTypeEnum;
|
|
||||||
import cn.lili.modules.promotion.service.PromotionService;
|
import cn.lili.modules.promotion.service.PromotionService;
|
||||||
import cn.lili.modules.search.entity.dos.EsGoodsAttribute;
|
import cn.lili.modules.search.entity.dos.EsGoodsAttribute;
|
||||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||||
@ -36,7 +38,6 @@ import org.elasticsearch.search.SearchHit;
|
|||||||
import org.mybatis.spring.MyBatisSystemException;
|
import org.mybatis.spring.MyBatisSystemException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PromotionService promotionService;
|
private PromotionService promotionService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ElasticsearchRestTemplate elasticsearchRestTemplate;
|
private Cache<Object> cache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addIndex(EsGoodsIndex goods) {
|
public void addIndex(EsGoodsIndex goods) {
|
||||||
@ -152,6 +153,9 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initIndex(List<EsGoodsIndex> goodsIndexList) {
|
public void initIndex(List<EsGoodsIndex> goodsIndexList) {
|
||||||
|
if (goodsIndexList == null || goodsIndexList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
//索引名称拼接
|
//索引名称拼接
|
||||||
String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
|
String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
|
||||||
|
|
||||||
@ -165,12 +169,32 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
|
|
||||||
//如果索引不存在,则创建索引
|
//如果索引不存在,则创建索引
|
||||||
createIndexRequest(indexName);
|
createIndexRequest(indexName);
|
||||||
if (goodsIndexList != null && !goodsIndexList.isEmpty()) {
|
Map<String, Integer> resultMap = new HashMap<>();
|
||||||
|
final String KEY_SUCCESS = "success";
|
||||||
|
final String KEY_FAIL = "fail";
|
||||||
|
final String KEY_PROCESSED = "processed";
|
||||||
|
resultMap.put("total", goodsIndexList.size());
|
||||||
|
resultMap.put(KEY_SUCCESS, 0);
|
||||||
|
resultMap.put(KEY_FAIL, 0);
|
||||||
|
resultMap.put(KEY_PROCESSED, 0);
|
||||||
|
cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix() + "", resultMap);
|
||||||
|
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true);
|
||||||
|
if (!goodsIndexList.isEmpty()) {
|
||||||
goodsIndexRepository.deleteAll();
|
goodsIndexRepository.deleteAll();
|
||||||
for (EsGoodsIndex goodsIndex : goodsIndexList) {
|
for (EsGoodsIndex goodsIndex : goodsIndexList) {
|
||||||
addIndex(goodsIndex);
|
try {
|
||||||
|
addIndex(goodsIndex);
|
||||||
|
resultMap.put(KEY_SUCCESS, resultMap.get(KEY_SUCCESS) + 1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("商品{}生成索引错误!", goodsIndex);
|
||||||
|
resultMap.put(KEY_FAIL, resultMap.get(KEY_FAIL) + 1);
|
||||||
|
}
|
||||||
|
resultMap.put(KEY_PROCESSED, resultMap.get(KEY_PROCESSED) + 1);
|
||||||
|
cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), resultMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), resultMap);
|
||||||
|
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -440,7 +464,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//移除促销信息
|
//移除促销信息
|
||||||
promotionMap.keySet().removeAll(removeKeys);
|
removeKeys.forEach(promotionMap.keySet()::remove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,6 +342,9 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
|||||||
String[] brands = searchDTO.getBrandId().split("@");
|
String[] brands = searchDTO.getBrandId().split("@");
|
||||||
filterBuilder.must(QueryBuilders.termsQuery("brandId", brands));
|
filterBuilder.must(QueryBuilders.termsQuery("brandId", brands));
|
||||||
}
|
}
|
||||||
|
if (searchDTO.getRecommend() != null) {
|
||||||
|
filterBuilder.filter(QueryBuilders.termQuery("storeId", searchDTO.getRecommend()));
|
||||||
|
}
|
||||||
//规格项判定
|
//规格项判定
|
||||||
if (searchDTO.getNameIds() != null && !searchDTO.getNameIds().isEmpty()) {
|
if (searchDTO.getNameIds() != null && !searchDTO.getNameIds().isEmpty()) {
|
||||||
filterBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.termsQuery("attrList.nameId", searchDTO.getNameIds()), ScoreMode.None));
|
filterBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.termsQuery("attrList.nameId", searchDTO.getNameIds()), ScoreMode.None));
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
package cn.lili.controller.other;
|
package cn.lili.controller.other;
|
||||||
|
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import cn.lili.cache.Cache;
|
||||||
|
import cn.lili.cache.CachePrefix;
|
||||||
|
import cn.lili.common.enums.ResultCode;
|
||||||
|
import cn.lili.common.enums.ResultUtil;
|
||||||
|
import cn.lili.common.vo.ResultMessage;
|
||||||
import cn.lili.modules.goods.entity.dos.Goods;
|
import cn.lili.modules.goods.entity.dos.Goods;
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
||||||
@ -15,6 +21,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.security.core.parameters.P;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@ -50,20 +57,28 @@ public class ElasticsearchController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PromotionService promotionService;
|
private PromotionService promotionService;
|
||||||
|
|
||||||
@GetMapping
|
@Autowired
|
||||||
public void init() {
|
private Cache cache;
|
||||||
//查询商品信息
|
|
||||||
LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
queryWrapper.eq(GoodsSku::getIsAuth, GoodsAuthEnum.PASS.name());
|
|
||||||
queryWrapper.eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name());
|
|
||||||
|
|
||||||
List<GoodsSku> list = goodsSkuService.list(queryWrapper);
|
@GetMapping
|
||||||
List<EsGoodsIndex> esGoodsIndices = new ArrayList<>();
|
public ResultMessage<String> init() {
|
||||||
String goodsId = null;
|
|
||||||
//库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量
|
Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix());
|
||||||
for (GoodsSku goodsSku : list) {
|
if (Boolean.TRUE.equals(flag)) {
|
||||||
goodsId = goodsSku.getGoodsId();
|
return ResultUtil.error(100000, "当前有任务在执行");
|
||||||
Goods goods = goodsService.getById(goodsId);
|
}
|
||||||
|
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false);
|
||||||
|
ThreadUtil.execAsync(() -> {
|
||||||
|
//查询商品信息
|
||||||
|
LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(GoodsSku::getIsAuth, GoodsAuthEnum.PASS.name());
|
||||||
|
queryWrapper.eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name());
|
||||||
|
|
||||||
|
List<GoodsSku> list = goodsSkuService.list(queryWrapper);
|
||||||
|
List<EsGoodsIndex> esGoodsIndices = new ArrayList<>();
|
||||||
|
//库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量
|
||||||
|
for (GoodsSku goodsSku : list) {
|
||||||
|
Goods goods = goodsService.getById(goodsSku.getGoodsId());
|
||||||
EsGoodsIndex index = new EsGoodsIndex(goodsSku);
|
EsGoodsIndex index = new EsGoodsIndex(goodsSku);
|
||||||
if (goods.getParams() != null && !goods.getParams().isEmpty()) {
|
if (goods.getParams() != null && !goods.getParams().isEmpty()) {
|
||||||
List<GoodsParamsDTO> goodsParamDTOS = JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class);
|
List<GoodsParamsDTO> goodsParamDTOS = JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class);
|
||||||
@ -73,9 +88,18 @@ public class ElasticsearchController {
|
|||||||
index.setPromotionMap(goodsCurrentPromotionMap);
|
index.setPromotionMap(goodsCurrentPromotionMap);
|
||||||
esGoodsIndices.add(index);
|
esGoodsIndices.add(index);
|
||||||
stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString());
|
stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString());
|
||||||
|
}
|
||||||
|
//初始化商品索引
|
||||||
|
esGoodsIndexService.initIndex(esGoodsIndices);
|
||||||
|
});
|
||||||
|
return ResultUtil.success();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
@GetMapping("/progress")
|
||||||
//初始化商品索引
|
public ResultMessage<Map<String, Integer>> getProgress() {
|
||||||
esGoodsIndexService.initIndex(esGoodsIndices);
|
Map<String, Integer> map = (Map<String, Integer>) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix());
|
||||||
|
Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix());
|
||||||
|
map.put("flag", Boolean.TRUE.equals(flag) ? 1 : 0);
|
||||||
|
return ResultUtil.data(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user