|
|
|
@ -3,6 +3,7 @@ package com.wayn.admin.api.controller.shop;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.wayn.admin.framework.manager.elastic.service.BaseElasticService;
|
|
|
|
|
import com.wayn.admin.framework.redis.RedisCache;
|
|
|
|
|
import com.wayn.common.base.BaseController;
|
|
|
|
|
import com.wayn.common.base.ElasticEntity;
|
|
|
|
|
import com.wayn.common.constant.SysConstants;
|
|
|
|
@ -15,10 +16,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
@ -32,11 +35,14 @@ import java.util.Map;
|
|
|
|
|
@RequestMapping("/shop/goods")
|
|
|
|
|
public class GoodsController extends BaseController {
|
|
|
|
|
|
|
|
|
|
private static final String GOODS_INDEX = "goods";
|
|
|
|
|
private static final String REDIS_GOODS_INDEX = "es_goods";
|
|
|
|
|
@Autowired
|
|
|
|
|
private IGoodsService iGoodsService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BaseElasticService baseElasticService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
public R list(Goods goods) {
|
|
|
|
@ -66,8 +72,14 @@ public class GoodsController extends BaseController {
|
|
|
|
|
|
|
|
|
|
@PostMapping("syncEs")
|
|
|
|
|
public R syncEs() {
|
|
|
|
|
baseElasticService.deleteIndex("goods");
|
|
|
|
|
baseElasticService.createIndex("goos", FileUtils.getContent(this.getClass().getResourceAsStream(SysConstants.ES_INDEX_GOODS_FILENAME)));
|
|
|
|
|
if (redisCache.getCacheObject(REDIS_GOODS_INDEX) != null) {
|
|
|
|
|
return R.error("正在同步,请稍等");
|
|
|
|
|
}
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
redisCache.setCacheObject(REDIS_GOODS_INDEX, true, 3, TimeUnit.MINUTES);
|
|
|
|
|
baseElasticService.deleteIndex(GOODS_INDEX);
|
|
|
|
|
InputStream inputStream = this.getClass().getResourceAsStream(SysConstants.ES_INDEX_GOODS_FILENAME);
|
|
|
|
|
if (baseElasticService.createIndex(GOODS_INDEX, FileUtils.getContent(inputStream))) {
|
|
|
|
|
List<Goods> list = iGoodsService.list();
|
|
|
|
|
List<ElasticEntity> entities = new ArrayList<>();
|
|
|
|
|
for (Goods goods : list) {
|
|
|
|
@ -83,6 +95,9 @@ public class GoodsController extends BaseController {
|
|
|
|
|
elasticEntity.setData(map);
|
|
|
|
|
entities.add(elasticEntity);
|
|
|
|
|
}
|
|
|
|
|
return R.result(baseElasticService.insertBatch("goods", entities));
|
|
|
|
|
flag = baseElasticService.insertBatch("goods", entities);
|
|
|
|
|
redisCache.deleteObject(REDIS_GOODS_INDEX);
|
|
|
|
|
}
|
|
|
|
|
return R.result(flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|