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,
|
||||
|
||||
/**
|
||||
* 初始化索引
|
||||
*/
|
||||
INIT_INDEX_PROCESS,
|
||||
|
||||
/**
|
||||
* 初始化索引标示
|
||||
*/
|
||||
INIT_INDEX_FLAG,
|
||||
|
||||
/**
|
||||
* 店铺分类
|
||||
*/
|
||||
|
@ -439,8 +439,8 @@ public enum ResultCode {
|
||||
CUSTOM_WORDS_EXIST_ERROR(90000, "当前自定义分词已存在!"),
|
||||
CUSTOM_WORDS_NOT_EXIST_ERROR(90001, "当前自定义分词不存在!"),
|
||||
CUSTOM_WORDS_SECRET_KEY_ERROR(90002, "秘钥验证失败!"),
|
||||
CONNECT_NOT_EXIST(90000, "登录方式不存在"),
|
||||
|
||||
CONNECT_NOT_EXIST(90000, "登录方式不存在!"),
|
||||
ELASTICSEARCH_INDEX_INIT_ERROR(90003, "索引初始化失败!"),
|
||||
;
|
||||
|
||||
private final Integer code;
|
||||
|
@ -253,6 +253,9 @@ public abstract class BaseElasticsearchService {
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"recommend\": {\n" +
|
||||
" \"type\": \"boolean\"\n" +
|
||||
" },\n" +
|
||||
" \"selfOperated\": {\n" +
|
||||
" \"type\": \"boolean\"\n" +
|
||||
" },\n" +
|
||||
|
@ -1,6 +1,5 @@
|
||||
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.MemberPointsHistory;
|
||||
import cn.lili.modules.member.entity.enums.PointTypeEnum;
|
||||
@ -45,11 +44,16 @@ public class PointLogInterceptor {
|
||||
if (obj[1] != null) {
|
||||
type = obj[1].toString();
|
||||
}
|
||||
//会员ID
|
||||
// 会员ID
|
||||
String memberId = "";
|
||||
if (obj[2] != null) {
|
||||
memberId = obj[2].toString();
|
||||
}
|
||||
// 变动积分为0,则直接返回
|
||||
if (point == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//根据会员id查询会员信息
|
||||
Member member = memberService.getById(memberId);
|
||||
if (member != null) {
|
||||
|
@ -17,8 +17,6 @@ import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -50,7 +48,7 @@ public class MemberPointsHistory {
|
||||
|
||||
@CreatedDate
|
||||
@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)
|
||||
@ApiModelProperty(value = "创建时间", hidden = true)
|
||||
private Date createTime;
|
||||
|
@ -23,6 +23,9 @@ public class EsGoodsSearchDTO {
|
||||
@ApiModelProperty(value = "品牌,可以多选 品牌Id@品牌Id@品牌Id")
|
||||
private String brandId;
|
||||
|
||||
@ApiModelProperty("是否为推荐商品")
|
||||
private Boolean recommend;
|
||||
|
||||
@ApiModelProperty(value = "价格", example = "10_30")
|
||||
private String price;
|
||||
|
||||
|
@ -6,18 +6,20 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.EsSuffix;
|
||||
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.GoodsWords;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
||||
import cn.lili.modules.goods.entity.enums.GoodsWordsTypeEnum;
|
||||
import cn.lili.modules.goods.service.GoodsWordsService;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.dto.BasePromotion;
|
||||
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.search.entity.dos.EsGoodsAttribute;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
@ -36,7 +38,6 @@ import org.elasticsearch.search.SearchHit;
|
||||
import org.mybatis.spring.MyBatisSystemException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@ -65,7 +66,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
@Autowired
|
||||
private PromotionService promotionService;
|
||||
@Autowired
|
||||
private ElasticsearchRestTemplate elasticsearchRestTemplate;
|
||||
private Cache<Object> cache;
|
||||
|
||||
@Override
|
||||
public void addIndex(EsGoodsIndex goods) {
|
||||
@ -152,6 +153,9 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
|
||||
@Override
|
||||
public void initIndex(List<EsGoodsIndex> goodsIndexList) {
|
||||
if (goodsIndexList == null || goodsIndexList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
//索引名称拼接
|
||||
String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
|
||||
|
||||
@ -165,12 +169,32 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
|
||||
//如果索引不存在,则创建索引
|
||||
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();
|
||||
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
|
||||
@ -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("@");
|
||||
filterBuilder.must(QueryBuilders.termsQuery("brandId", brands));
|
||||
}
|
||||
if (searchDTO.getRecommend() != null) {
|
||||
filterBuilder.filter(QueryBuilders.termQuery("storeId", searchDTO.getRecommend()));
|
||||
}
|
||||
//规格项判定
|
||||
if (searchDTO.getNameIds() != null && !searchDTO.getNameIds().isEmpty()) {
|
||||
filterBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.termsQuery("attrList.nameId", searchDTO.getNameIds()), ScoreMode.None));
|
||||
|
@ -1,6 +1,12 @@
|
||||
package cn.lili.controller.other;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
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.GoodsSku;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -50,20 +57,28 @@ public class ElasticsearchController {
|
||||
@Autowired
|
||||
private PromotionService promotionService;
|
||||
|
||||
@GetMapping
|
||||
public void init() {
|
||||
//查询商品信息
|
||||
LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(GoodsSku::getIsAuth, GoodsAuthEnum.PASS.name());
|
||||
queryWrapper.eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name());
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
|
||||
List<GoodsSku> list = goodsSkuService.list(queryWrapper);
|
||||
List<EsGoodsIndex> esGoodsIndices = new ArrayList<>();
|
||||
String goodsId = null;
|
||||
//库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量
|
||||
for (GoodsSku goodsSku : list) {
|
||||
goodsId = goodsSku.getGoodsId();
|
||||
Goods goods = goodsService.getById(goodsId);
|
||||
@GetMapping
|
||||
public ResultMessage<String> init() {
|
||||
|
||||
Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix());
|
||||
if (Boolean.TRUE.equals(flag)) {
|
||||
return ResultUtil.error(100000, "当前有任务在执行");
|
||||
}
|
||||
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);
|
||||
if (goods.getParams() != null && !goods.getParams().isEmpty()) {
|
||||
List<GoodsParamsDTO> goodsParamDTOS = JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class);
|
||||
@ -73,9 +88,18 @@ public class ElasticsearchController {
|
||||
index.setPromotionMap(goodsCurrentPromotionMap);
|
||||
esGoodsIndices.add(index);
|
||||
stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString());
|
||||
}
|
||||
//初始化商品索引
|
||||
esGoodsIndexService.initIndex(esGoodsIndices);
|
||||
});
|
||||
return ResultUtil.success();
|
||||
}
|
||||
|
||||
}
|
||||
//初始化商品索引
|
||||
esGoodsIndexService.initIndex(esGoodsIndices);
|
||||
@GetMapping("/progress")
|
||||
public ResultMessage<Map<String, Integer>> getProgress() {
|
||||
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