Commit b73c4f2e authored by shiyu's avatar shiyu

type->kind

parent 95513f3e
...@@ -5,11 +5,13 @@ import com.wwdz.ch.core.consts.CommConsts; ...@@ -5,11 +5,13 @@ import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.consts.CommonEnum; import com.wwdz.ch.core.consts.CommonEnum;
import com.wwdz.ch.core.consts.MediaTypeEnum; import com.wwdz.ch.core.consts.MediaTypeEnum;
import com.wwdz.ch.core.storage.QiniuStorage; import com.wwdz.ch.core.storage.QiniuStorage;
import com.wwdz.ch.db.bean.ItemOfEs;
import com.wwdz.ch.db.dao.CoinsDao; import com.wwdz.ch.db.dao.CoinsDao;
import com.wwdz.ch.db.dao.ItemDao; import com.wwdz.ch.db.dao.ItemDao;
import com.wwdz.ch.db.domain.Coins; import com.wwdz.ch.db.domain.Coins;
import com.wwdz.ch.db.domain.Item; import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.db.dto.request.CoinRequestDto; import com.wwdz.ch.db.dto.request.CoinRequestDto;
import com.wwdz.ch.db.es.ItemEsDao;
import com.xxdxxs.utils.CommonUtils; import com.xxdxxs.utils.CommonUtils;
import com.xxdxxs.utils.StringUtils; import com.xxdxxs.utils.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -28,6 +30,8 @@ import java.net.URL; ...@@ -28,6 +30,8 @@ import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@Component @Component
...@@ -44,6 +48,8 @@ public class SynCoinJob { ...@@ -44,6 +48,8 @@ public class SynCoinJob {
@Autowired @Autowired
QiniuStorage qiniuStorage; QiniuStorage qiniuStorage;
@Autowired
ItemEsDao itemEsDao;
public void execute() { public void execute() {
...@@ -52,7 +58,7 @@ public class SynCoinJob { ...@@ -52,7 +58,7 @@ public class SynCoinJob {
CoinRequestDto coinRequestDto = new CoinRequestDto(); CoinRequestDto coinRequestDto = new CoinRequestDto();
coinRequestDto.setPage(1); coinRequestDto.setPage(1);
coinRequestDto.setLimit(100); coinRequestDto.setLimit(100);
PageInfo<Item> pageInfo = itemDao.findByPage(coinRequestDto); PageInfo<Item> pageInfo = itemDao.findPageExcludeFilter(coinRequestDto);
int totalPageNum = pageInfo.getPages(); int totalPageNum = pageInfo.getPages();
logger.info("total page : {}, total : {}", totalPageNum, pageInfo.getTotal()); logger.info("total page : {}, total : {}", totalPageNum, pageInfo.getTotal());
IntStream.rangeClosed(1, totalPageNum).parallel().forEach(i -> { IntStream.rangeClosed(1, totalPageNum).parallel().forEach(i -> {
...@@ -102,7 +108,7 @@ public class SynCoinJob { ...@@ -102,7 +108,7 @@ public class SynCoinJob {
CoinRequestDto coinRequestDto = new CoinRequestDto(); CoinRequestDto coinRequestDto = new CoinRequestDto();
coinRequestDto.setPage(1); coinRequestDto.setPage(1);
coinRequestDto.setLimit(100); coinRequestDto.setLimit(100);
PageInfo<Item> pageInfo = itemDao.findByPage(coinRequestDto); PageInfo<Item> pageInfo = itemDao.findPageExcludeFilter(coinRequestDto);
int totalPageNum = pageInfo.getPages(); int totalPageNum = pageInfo.getPages();
logger.info("total page : {}, total : {}", totalPageNum, pageInfo.getTotal()); logger.info("total page : {}, total : {}", totalPageNum, pageInfo.getTotal());
IntStream.rangeClosed(1, totalPageNum).parallel().forEach(i -> { IntStream.rangeClosed(1, totalPageNum).parallel().forEach(i -> {
...@@ -168,4 +174,33 @@ public class SynCoinJob { ...@@ -168,4 +174,33 @@ public class SynCoinJob {
return null; return null;
} }
public void synItemToEs() {
try {
CoinRequestDto coinRequestDto = new CoinRequestDto();
coinRequestDto.setPage(1);
coinRequestDto.setLimit(100);
PageInfo<Item> pageInfo = itemDao.findPageExcludeFilter(coinRequestDto);
int totalPageNum = pageInfo.getPages();
logger.info("total page : {}, total : {}", totalPageNum, pageInfo.getTotal());
IntStream.rangeClosed(1, totalPageNum).parallel().forEach(i -> {
logger.info(">>>>>>>>>>>>>>>>> 当前同步数据的页码: {} 更新开始 <<<<<<<<<<<<<<<<<", i);
CoinRequestDto dto = new CoinRequestDto();
dto.setPage(i);
dto.setLimit(100);
List<Item> itemList = itemDao.findListByPage(dto);
itemEsDao.create(itemList);
logger.info(">>>>>>>>>>>>>>>>> 页码 = {}, 同步es 成功 ! <<<<<<<<<<<<<<<<<", i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
logger.info(">>>>>>>>>>>>>>>>>数据同步es 完成 SUCCESS!!!!! <<<<<<<<<<<<<<<<<");
} catch (Exception e) {
logger.error("同步数据到es error {}", e);
}
}
} }
package com.wwdz.ch.admin.impl; package com.wwdz.ch.admin.impl;
import com.wwdz.ch.admin.job.SynCoinJob;
import com.wwdz.ch.core.entity.EsSearchParam; import com.wwdz.ch.core.entity.EsSearchParam;
import com.wwdz.ch.core.util.ElasticsearchUtil; import com.wwdz.ch.core.util.ElasticsearchUtil;
import com.wwdz.ch.db.bean.EsPageInfo;
import com.wwdz.ch.db.bean.ItemOfEs;
import com.wwdz.ch.db.dto.request.EsSearchRequestDto;
import com.wwdz.ch.db.es.ItemEsDao;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
...@@ -16,13 +23,30 @@ import java.util.List; ...@@ -16,13 +23,30 @@ import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
public class ElasticsearchUtilTest { public class ElasticsearchUtilTest {
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchUtilTest.class);
@Autowired @Autowired
ElasticsearchUtil elasticsearchUtil; ElasticsearchUtil elasticsearchUtil;
@Autowired
ItemEsDao itemEsDao;
@Test @Test
public void findDocument() { public void findDocument() {
EsSearchParam esSearchParam = EsSearchParam.of("清代"); EsSearchParam esSearchParam = EsSearchParam.of("清代");
esSearchParam.setContent("清代"); esSearchParam.setContent("清代");
List list = elasticsearchUtil.findDocument(esSearchParam); List list = elasticsearchUtil.findDocument(esSearchParam);
} }
@Test
public void find() {
EsSearchRequestDto esSearchRequestDto = new EsSearchRequestDto();
esSearchRequestDto.setContent("清代");
esSearchRequestDto.setPage(1);
esSearchRequestDto.setSize(20);
EsPageInfo esPageInfo = itemEsDao.findList(esSearchRequestDto);
logger.info("esPageInfo = {}", esPageInfo);
}
} }
\ No newline at end of file
package com.wwdz.ch.admin.impl; package com.wwdz.ch.admin.impl;
import com.wwdz.ch.admin.job.SynCoinJob; import com.wwdz.ch.admin.job.SynCoinJob;
import com.wwdz.ch.db.es.ItemEsDao;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -15,8 +16,29 @@ public class SynCoinJobTest { ...@@ -15,8 +16,29 @@ public class SynCoinJobTest {
@Autowired @Autowired
SynCoinJob synCoinJob; SynCoinJob synCoinJob;
@Autowired
ItemEsDao itemEsDao;
@Test @Test
public void execute() { public void execute() {
synCoinJob.execute(); synCoinJob.execute();
} }
@Test
public void updateImage() throws Exception {
synCoinJob.updateImageUrlOfsSize();
}
@Test
public void createIndex() throws Exception {
itemEsDao.createIndex();
}
@Test
public void synToEs() throws Exception {
synCoinJob.synItemToEs();
}
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ package com.wwdz.ch.core.consts; ...@@ -3,7 +3,7 @@ package com.wwdz.ch.core.consts;
/** /**
* 商品种类 * 商品种类
*/ */
public enum ItemTypeEnum { public enum ItemKindEnum {
COIN(1, "钱币"), COIN(1, "钱币"),
NEPHRITE(2, "和田玉"), NEPHRITE(2, "和田玉"),
...@@ -12,15 +12,15 @@ public enum ItemTypeEnum { ...@@ -12,15 +12,15 @@ public enum ItemTypeEnum {
private int code; private int code;
private String des; private String des;
ItemTypeEnum(int code, String des) { ItemKindEnum(int code, String des) {
this.code = code; this.code = code;
this.des = des; this.des = des;
} }
public static String getNameByCode(int code) { public static String getNameByCode(int code) {
for (ItemTypeEnum itemTypeEnum :ItemTypeEnum.values()) { for (ItemKindEnum itemKindEnum : ItemKindEnum.values()) {
if (code == itemTypeEnum.getCode()) { if (code == itemKindEnum.getCode()) {
return itemTypeEnum.getDes(); return itemKindEnum.getDes();
} }
} }
return null; return null;
......
...@@ -73,4 +73,7 @@ public class ElasticsearchUtil { ...@@ -73,4 +73,7 @@ public class ElasticsearchUtil {
} }
return Collections.emptyList(); return Collections.emptyList();
} }
} }
...@@ -17,6 +17,8 @@ public interface ItemDao { ...@@ -17,6 +17,8 @@ public interface ItemDao {
PageInfo<Item> findByPage(CoinRequestDto coinRequestDto); PageInfo<Item> findByPage(CoinRequestDto coinRequestDto);
PageInfo<Item> findPageExcludeFilter(CoinRequestDto coinRequestDto);
Item findDetails(Long id); Item findDetails(Long id);
boolean setCoin(Item item); boolean setCoin(Item item);
...@@ -35,6 +37,8 @@ public interface ItemDao { ...@@ -35,6 +37,8 @@ public interface ItemDao {
int update(Item item); int update(Item item);
PageInfo<Item> findByRandomPage(CoinRequestDto coinRequestDto);
/** /**
* 获取分类下的商品 * 获取分类下的商品
......
...@@ -10,7 +10,7 @@ import lombok.Data; ...@@ -10,7 +10,7 @@ import lombok.Data;
/** /**
* @author shiyu * @author shiyu
* @date 2023/08/16 * @date 2023/08/17
*/ */
@Data @Data
public class Item implements Entity { public class Item implements Entity {
...@@ -104,7 +104,7 @@ public class Item implements Entity { ...@@ -104,7 +104,7 @@ public class Item implements Entity {
/** /**
* 商品种类1钱币 * 商品种类1钱币
*/ */
private Integer type; private Integer kind;
/** /**
* 商品额外信息 * 商品额外信息
...@@ -157,7 +157,7 @@ public class Item implements Entity { ...@@ -157,7 +157,7 @@ public class Item implements Entity {
sb.append(", isSetted=").append(isSetted); sb.append(", isSetted=").append(isSetted);
sb.append(", originalSourceUrl=").append(originalSourceUrl); sb.append(", originalSourceUrl=").append(originalSourceUrl);
sb.append(", source=").append(source); sb.append(", source=").append(source);
sb.append(", type=").append(type); sb.append(", kind=").append(kind);
sb.append(", extra=").append(extra); sb.append(", extra=").append(extra);
sb.append(", images=").append(images); sb.append(", images=").append(images);
sb.append(", videos=").append(videos); sb.append(", videos=").append(videos);
...@@ -198,7 +198,7 @@ public class Item implements Entity { ...@@ -198,7 +198,7 @@ public class Item implements Entity {
&& (this.getIsSetted() == null ? other.getIsSetted() == null : this.getIsSetted().equals(other.getIsSetted())) && (this.getIsSetted() == null ? other.getIsSetted() == null : this.getIsSetted().equals(other.getIsSetted()))
&& (this.getOriginalSourceUrl() == null ? other.getOriginalSourceUrl() == null : this.getOriginalSourceUrl().equals(other.getOriginalSourceUrl())) && (this.getOriginalSourceUrl() == null ? other.getOriginalSourceUrl() == null : this.getOriginalSourceUrl().equals(other.getOriginalSourceUrl()))
&& (this.getSource() == null ? other.getSource() == null : this.getSource().equals(other.getSource())) && (this.getSource() == null ? other.getSource() == null : this.getSource().equals(other.getSource()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType())) && (this.getKind() == null ? other.getKind() == null : this.getKind().equals(other.getKind()))
&& (this.getExtra() == null ? other.getExtra() == null : this.getExtra().equals(other.getExtra())) && (this.getExtra() == null ? other.getExtra() == null : this.getExtra().equals(other.getExtra()))
&& (this.getImages() == null ? other.getImages() == null : this.getImages().equals(other.getImages())) && (this.getImages() == null ? other.getImages() == null : this.getImages().equals(other.getImages()))
&& (this.getVideos() == null ? other.getVideos() == null : this.getVideos().equals(other.getVideos())) && (this.getVideos() == null ? other.getVideos() == null : this.getVideos().equals(other.getVideos()))
...@@ -228,7 +228,7 @@ public class Item implements Entity { ...@@ -228,7 +228,7 @@ public class Item implements Entity {
result = prime * result + ((getIsSetted() == null) ? 0 : getIsSetted().hashCode()); result = prime * result + ((getIsSetted() == null) ? 0 : getIsSetted().hashCode());
result = prime * result + ((getOriginalSourceUrl() == null) ? 0 : getOriginalSourceUrl().hashCode()); result = prime * result + ((getOriginalSourceUrl() == null) ? 0 : getOriginalSourceUrl().hashCode());
result = prime * result + ((getSource() == null) ? 0 : getSource().hashCode()); result = prime * result + ((getSource() == null) ? 0 : getSource().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); result = prime * result + ((getKind() == null) ? 0 : getKind().hashCode());
result = prime * result + ((getExtra() == null) ? 0 : getExtra().hashCode()); result = prime * result + ((getExtra() == null) ? 0 : getExtra().hashCode());
result = prime * result + ((getImages() == null) ? 0 : getImages().hashCode()); result = prime * result + ((getImages() == null) ? 0 : getImages().hashCode());
result = prime * result + ((getVideos() == null) ? 0 : getVideos().hashCode()); result = prime * result + ((getVideos() == null) ? 0 : getVideos().hashCode());
...@@ -263,7 +263,7 @@ public class Item implements Entity { ...@@ -263,7 +263,7 @@ public class Item implements Entity {
isSetted("is_setted", "isSetted", "INTEGER", false), isSetted("is_setted", "isSetted", "INTEGER", false),
originalSourceUrl("original_source_url", "originalSourceUrl", "VARCHAR", false), originalSourceUrl("original_source_url", "originalSourceUrl", "VARCHAR", false),
source("source", "source", "INTEGER", true), source("source", "source", "INTEGER", true),
type("type", "type", "INTEGER", true), kind("kind", "kind", "INTEGER", false),
extra("extra", "extra", "LONGVARCHAR", false), extra("extra", "extra", "LONGVARCHAR", false),
images("images", "images", "LONGVARCHAR", false), images("images", "images", "LONGVARCHAR", false),
videos("videos", "videos", "LONGVARCHAR", false), videos("videos", "videos", "LONGVARCHAR", false),
......
...@@ -2584,18 +2584,18 @@ public class ItemExample { ...@@ -2584,18 +2584,18 @@ public class ItemExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeIsNull() { public Criteria andKindIsNull() {
addCriterion("`type` is null"); addCriterion("kind is null");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeIsNotNull() { public Criteria andKindIsNotNull() {
addCriterion("`type` is not null"); addCriterion("kind is not null");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeEqualTo(Integer value) { public Criteria andKindEqualTo(Integer value) {
addCriterion("`type` =", value, "type"); addCriterion("kind =", value, "kind");
return (Criteria) this; return (Criteria) this;
} }
...@@ -2606,13 +2606,13 @@ public class ItemExample { ...@@ -2606,13 +2606,13 @@ public class ItemExample {
* @mbg.generated * @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin * @project https://github.com/itfsw/mybatis-generator-plugin
*/ */
public Criteria andTypeEqualToColumn(Item.Column column) { public Criteria andKindEqualToColumn(Item.Column column) {
addCriterion(new StringBuilder("`type` = ").append(column.getEscapedColumnName()).toString()); addCriterion(new StringBuilder("kind = ").append(column.getEscapedColumnName()).toString());
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeNotEqualTo(Integer value) { public Criteria andKindNotEqualTo(Integer value) {
addCriterion("`type` <>", value, "type"); addCriterion("kind <>", value, "kind");
return (Criteria) this; return (Criteria) this;
} }
...@@ -2623,13 +2623,13 @@ public class ItemExample { ...@@ -2623,13 +2623,13 @@ public class ItemExample {
* @mbg.generated * @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin * @project https://github.com/itfsw/mybatis-generator-plugin
*/ */
public Criteria andTypeNotEqualToColumn(Item.Column column) { public Criteria andKindNotEqualToColumn(Item.Column column) {
addCriterion(new StringBuilder("`type` <> ").append(column.getEscapedColumnName()).toString()); addCriterion(new StringBuilder("kind <> ").append(column.getEscapedColumnName()).toString());
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeGreaterThan(Integer value) { public Criteria andKindGreaterThan(Integer value) {
addCriterion("`type` >", value, "type"); addCriterion("kind >", value, "kind");
return (Criteria) this; return (Criteria) this;
} }
...@@ -2640,13 +2640,13 @@ public class ItemExample { ...@@ -2640,13 +2640,13 @@ public class ItemExample {
* @mbg.generated * @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin * @project https://github.com/itfsw/mybatis-generator-plugin
*/ */
public Criteria andTypeGreaterThanColumn(Item.Column column) { public Criteria andKindGreaterThanColumn(Item.Column column) {
addCriterion(new StringBuilder("`type` > ").append(column.getEscapedColumnName()).toString()); addCriterion(new StringBuilder("kind > ").append(column.getEscapedColumnName()).toString());
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeGreaterThanOrEqualTo(Integer value) { public Criteria andKindGreaterThanOrEqualTo(Integer value) {
addCriterion("`type` >=", value, "type"); addCriterion("kind >=", value, "kind");
return (Criteria) this; return (Criteria) this;
} }
...@@ -2657,13 +2657,13 @@ public class ItemExample { ...@@ -2657,13 +2657,13 @@ public class ItemExample {
* @mbg.generated * @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin * @project https://github.com/itfsw/mybatis-generator-plugin
*/ */
public Criteria andTypeGreaterThanOrEqualToColumn(Item.Column column) { public Criteria andKindGreaterThanOrEqualToColumn(Item.Column column) {
addCriterion(new StringBuilder("`type` >= ").append(column.getEscapedColumnName()).toString()); addCriterion(new StringBuilder("kind >= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeLessThan(Integer value) { public Criteria andKindLessThan(Integer value) {
addCriterion("`type` <", value, "type"); addCriterion("kind <", value, "kind");
return (Criteria) this; return (Criteria) this;
} }
...@@ -2674,13 +2674,13 @@ public class ItemExample { ...@@ -2674,13 +2674,13 @@ public class ItemExample {
* @mbg.generated * @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin * @project https://github.com/itfsw/mybatis-generator-plugin
*/ */
public Criteria andTypeLessThanColumn(Item.Column column) { public Criteria andKindLessThanColumn(Item.Column column) {
addCriterion(new StringBuilder("`type` < ").append(column.getEscapedColumnName()).toString()); addCriterion(new StringBuilder("kind < ").append(column.getEscapedColumnName()).toString());
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeLessThanOrEqualTo(Integer value) { public Criteria andKindLessThanOrEqualTo(Integer value) {
addCriterion("`type` <=", value, "type"); addCriterion("kind <=", value, "kind");
return (Criteria) this; return (Criteria) this;
} }
...@@ -2691,28 +2691,28 @@ public class ItemExample { ...@@ -2691,28 +2691,28 @@ public class ItemExample {
* @mbg.generated * @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin * @project https://github.com/itfsw/mybatis-generator-plugin
*/ */
public Criteria andTypeLessThanOrEqualToColumn(Item.Column column) { public Criteria andKindLessThanOrEqualToColumn(Item.Column column) {
addCriterion(new StringBuilder("`type` <= ").append(column.getEscapedColumnName()).toString()); addCriterion(new StringBuilder("kind <= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeIn(List<Integer> values) { public Criteria andKindIn(List<Integer> values) {
addCriterion("`type` in", values, "type"); addCriterion("kind in", values, "kind");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeNotIn(List<Integer> values) { public Criteria andKindNotIn(List<Integer> values) {
addCriterion("`type` not in", values, "type"); addCriterion("kind not in", values, "kind");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeBetween(Integer value1, Integer value2) { public Criteria andKindBetween(Integer value1, Integer value2) {
addCriterion("`type` between", value1, value2, "type"); addCriterion("kind between", value1, value2, "kind");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeNotBetween(Integer value1, Integer value2) { public Criteria andKindNotBetween(Integer value1, Integer value2) {
addCriterion("`type` not between", value1, value2, "type"); addCriterion("kind not between", value1, value2, "kind");
return (Criteria) this; return (Criteria) this;
} }
} }
......
...@@ -81,7 +81,7 @@ public class CoinRequestDto extends BaseRequestDto implements Entity { ...@@ -81,7 +81,7 @@ public class CoinRequestDto extends BaseRequestDto implements Entity {
/** /**
* 商品种类1钱币 * 商品种类1钱币
*/ */
private Integer type; private Integer kind;
/** /**
* 商品视频, 分号分隔 * 商品视频, 分号分隔
......
...@@ -4,16 +4,21 @@ import co.elastic.clients.elasticsearch.ElasticsearchClient; ...@@ -4,16 +4,21 @@ import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.SortOrder; import co.elastic.clients.elasticsearch._types.SortOrder;
import co.elastic.clients.elasticsearch._types.query_dsl.MatchQuery; import co.elastic.clients.elasticsearch._types.query_dsl.MatchQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.Query; import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch.core.SearchRequest; import co.elastic.clients.elasticsearch.core.*;
import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.core.bulk.BulkOperation;
import co.elastic.clients.elasticsearch.core.bulk.CreateOperation;
import co.elastic.clients.elasticsearch.core.search.Hit; import co.elastic.clients.elasticsearch.core.search.Hit;
import co.elastic.clients.elasticsearch.indices.CreateIndexResponse;
import co.elastic.clients.elasticsearch.indices.DeleteIndexResponse;
import com.wwdz.ch.db.bean.EsPageInfo; import com.wwdz.ch.db.bean.EsPageInfo;
import com.wwdz.ch.db.bean.ItemOfEs; import com.wwdz.ch.db.bean.ItemOfEs;
import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.db.dto.request.EsSearchRequestDto; import com.wwdz.ch.db.dto.request.EsSearchRequestDto;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -22,11 +27,40 @@ public class ItemEsDao { ...@@ -22,11 +27,40 @@ public class ItemEsDao {
private static final Logger logger = LoggerFactory.getLogger(ItemEsDao.class); private static final Logger logger = LoggerFactory.getLogger(ItemEsDao.class);
private final static String INDEX = "quanku_new"; private final static String INDEX = "quanku_temp";
@Resource(name="clientByPasswd") @Resource(name="clientByPasswd")
ElasticsearchClient elasticsearchClient; ElasticsearchClient elasticsearchClient;
public void createIndex() {
boolean flag = false;
try {
flag = elasticsearchClient.exists(req -> req.index(INDEX)).value();
if (flag){
logger.info("索引 {} 已经存在!", INDEX);
} else {
CreateResponse createResponse = elasticsearchClient.create(req -> req.index(INDEX));
logger.info("创建索引的响应结果:{}", createResponse);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void deleteIndex() {
boolean flag = false;
try {
flag = elasticsearchClient.exists(req -> req.index(INDEX)).value();
if (flag){
DeleteResponse deleteResponse = elasticsearchClient.delete(req -> req.index(INDEX));
logger.info("索引 {} 删除结果 :{} ", INDEX, deleteResponse);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public EsPageInfo findList(EsSearchRequestDto esSearchRequestDto) { public EsPageInfo findList(EsSearchRequestDto esSearchRequestDto) {
EsPageInfo esPageInfo = null; EsPageInfo esPageInfo = null;
...@@ -65,4 +99,33 @@ public class ItemEsDao { ...@@ -65,4 +99,33 @@ public class ItemEsDao {
return esPageInfo; return esPageInfo;
} }
public void create(List<Item> itemList) {
// 批量添加数据
List<BulkOperation> opts = new ArrayList<>();
for (Item item : itemList) {
CreateOperation<Item> optObj = new CreateOperation.Builder<Item>()
.index(INDEX)
.id(String.valueOf(item.getId()))
.document(item)
.build();
BulkOperation opt = new BulkOperation.Builder()
.create(optObj)
.build();
opts.add(opt);
}
BulkRequest bulkRequest = new BulkRequest.Builder()
.operations(opts)
.build();
try {
BulkResponse bulk = elasticsearchClient.bulk(bulkRequest);
logger.info("ES批量新增数据 : {}, 数量:{}" , bulk);
} catch (IOException e) {
logger.info("ES批量新增数据 error" , e);
}
}
} }
...@@ -17,6 +17,7 @@ import org.springframework.util.StringUtils; ...@@ -17,6 +17,7 @@ import org.springframework.util.StringUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.IntStream;
@Repository @Repository
public class ItemDaoImpl implements ItemDao { public class ItemDaoImpl implements ItemDao {
...@@ -84,6 +85,15 @@ public class ItemDaoImpl implements ItemDao { ...@@ -84,6 +85,15 @@ public class ItemDaoImpl implements ItemDao {
} }
@Override
public PageInfo<Item> findPageExcludeFilter(CoinRequestDto coinRequestDto) {
ItemExample example = new ItemExample();
PageHelper.startPage(coinRequestDto.getPage(), coinRequestDto.getLimit());
List<Item> list = itemMapper.selectByExampleWithBLOBs(example);
return new PageInfo<>(list);
}
@Override @Override
public Item findDetails(Long id) { public Item findDetails(Long id) {
ItemExample example = new ItemExample(); ItemExample example = new ItemExample();
...@@ -168,7 +178,11 @@ public class ItemDaoImpl implements ItemDao { ...@@ -168,7 +178,11 @@ public class ItemDaoImpl implements ItemDao {
return itemMapper.updateByPrimaryKeySelective(item); return itemMapper.updateByPrimaryKeySelective(item);
} }
@Override
public PageInfo<Item> findByRandomPage(CoinRequestDto coinRequestDto) {
IntStream.range(0, 767372).parallel().boxed().findAny().get();
return null;
}
//-------------------------初始代码--------------------------// //-------------------------初始代码--------------------------//
......
...@@ -68,7 +68,6 @@ public interface ItemMapper { ...@@ -68,7 +68,6 @@ public interface ItemMapper {
*/ */
Item selectByPrimaryKeySelective(@Param("id") Long id, @Param("selective") Item.Column ... selective); Item selectByPrimaryKeySelective(@Param("id") Long id, @Param("selective") Item.Column ... selective);
Item selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") Item record, @Param("example") ItemExample example); int updateByExampleSelective(@Param("record") Item record, @Param("example") ItemExample example);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<result column="is_setted" jdbcType="INTEGER" property="isSetted" /> <result column="is_setted" jdbcType="INTEGER" property="isSetted" />
<result column="original_source_url" jdbcType="VARCHAR" property="originalSourceUrl" /> <result column="original_source_url" jdbcType="VARCHAR" property="originalSourceUrl" />
<result column="source" jdbcType="INTEGER" property="source" /> <result column="source" jdbcType="INTEGER" property="source" />
<result column="type" jdbcType="INTEGER" property="type" /> <result column="kind" jdbcType="INTEGER" property="kind" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.wwdz.ch.db.domain.Item"> <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.wwdz.ch.db.domain.Item">
<result column="extra" jdbcType="LONGVARCHAR" property="extra" /> <result column="extra" jdbcType="LONGVARCHAR" property="extra" />
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time, id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time,
source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url, source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url,
`source`, `type` `source`, kind
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
extra, images, videos, detail, original_extra extra, images, videos, detail, original_extra
...@@ -149,7 +149,7 @@ ...@@ -149,7 +149,7 @@
<otherwise> <otherwise>
id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time, id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time,
source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url, source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url,
`source`, `type`, extra, images, videos, detail, original_extra `source`, kind, extra, images, videos, detail, original_extra
</otherwise> </otherwise>
</choose> </choose>
from item from item
...@@ -184,7 +184,7 @@ ...@@ -184,7 +184,7 @@
<otherwise> <otherwise>
id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time, id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time,
source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url, source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url,
`source`, `type`, extra, images, videos, detail, original_extra `source`, kind, extra, images, videos, detail, original_extra
</otherwise> </otherwise>
</choose> </choose>
from item from item
...@@ -209,7 +209,7 @@ ...@@ -209,7 +209,7 @@
top_image, price, create_time, top_image, price, create_time,
source_type, update_time, is_deleted, source_type, update_time, is_deleted,
bid_time, remark, is_setted, bid_time, remark, is_setted,
original_source_url, `source`, `type`, original_source_url, `source`, kind,
extra, images, videos, extra, images, videos,
detail, original_extra) detail, original_extra)
values (#{name,jdbcType=VARCHAR}, #{cid,jdbcType=INTEGER}, #{isOnSale,jdbcType=BIT}, values (#{name,jdbcType=VARCHAR}, #{cid,jdbcType=INTEGER}, #{isOnSale,jdbcType=BIT},
...@@ -217,7 +217,7 @@ ...@@ -217,7 +217,7 @@
#{topImage,jdbcType=VARCHAR}, #{price,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{topImage,jdbcType=VARCHAR}, #{price,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP},
#{sourceType,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP}, #{isDeleted,jdbcType=BIT}, #{sourceType,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP}, #{isDeleted,jdbcType=BIT},
#{bidTime,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{isSetted,jdbcType=INTEGER}, #{bidTime,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{isSetted,jdbcType=INTEGER},
#{originalSourceUrl,jdbcType=VARCHAR}, #{source,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{originalSourceUrl,jdbcType=VARCHAR}, #{source,jdbcType=INTEGER}, #{kind,jdbcType=INTEGER},
#{extra,jdbcType=LONGVARCHAR}, #{images,jdbcType=LONGVARCHAR}, #{videos,jdbcType=LONGVARCHAR}, #{extra,jdbcType=LONGVARCHAR}, #{images,jdbcType=LONGVARCHAR}, #{videos,jdbcType=LONGVARCHAR},
#{detail,jdbcType=LONGVARCHAR}, #{originalExtra,jdbcType=LONGVARCHAR}) #{detail,jdbcType=LONGVARCHAR}, #{originalExtra,jdbcType=LONGVARCHAR})
</insert> </insert>
...@@ -278,8 +278,8 @@ ...@@ -278,8 +278,8 @@
<if test="source != null"> <if test="source != null">
`source`, `source`,
</if> </if>
<if test="type != null"> <if test="kind != null">
`type`, kind,
</if> </if>
<if test="extra != null"> <if test="extra != null">
extra, extra,
...@@ -349,8 +349,8 @@ ...@@ -349,8 +349,8 @@
<if test="source != null"> <if test="source != null">
#{source,jdbcType=INTEGER}, #{source,jdbcType=INTEGER},
</if> </if>
<if test="type != null"> <if test="kind != null">
#{type,jdbcType=INTEGER}, #{kind,jdbcType=INTEGER},
</if> </if>
<if test="extra != null"> <if test="extra != null">
#{extra,jdbcType=LONGVARCHAR}, #{extra,jdbcType=LONGVARCHAR},
...@@ -432,8 +432,8 @@ ...@@ -432,8 +432,8 @@
<if test="record.source != null"> <if test="record.source != null">
`source` = #{record.source,jdbcType=INTEGER}, `source` = #{record.source,jdbcType=INTEGER},
</if> </if>
<if test="record.type != null"> <if test="record.kind != null">
`type` = #{record.type,jdbcType=INTEGER}, kind = #{record.kind,jdbcType=INTEGER},
</if> </if>
<if test="record.extra != null"> <if test="record.extra != null">
extra = #{record.extra,jdbcType=LONGVARCHAR}, extra = #{record.extra,jdbcType=LONGVARCHAR},
...@@ -475,7 +475,7 @@ ...@@ -475,7 +475,7 @@
is_setted = #{record.isSetted,jdbcType=INTEGER}, is_setted = #{record.isSetted,jdbcType=INTEGER},
original_source_url = #{record.originalSourceUrl,jdbcType=VARCHAR}, original_source_url = #{record.originalSourceUrl,jdbcType=VARCHAR},
`source` = #{record.source,jdbcType=INTEGER}, `source` = #{record.source,jdbcType=INTEGER},
`type` = #{record.type,jdbcType=INTEGER}, kind = #{record.kind,jdbcType=INTEGER},
extra = #{record.extra,jdbcType=LONGVARCHAR}, extra = #{record.extra,jdbcType=LONGVARCHAR},
images = #{record.images,jdbcType=LONGVARCHAR}, images = #{record.images,jdbcType=LONGVARCHAR},
videos = #{record.videos,jdbcType=LONGVARCHAR}, videos = #{record.videos,jdbcType=LONGVARCHAR},
...@@ -505,7 +505,7 @@ ...@@ -505,7 +505,7 @@
is_setted = #{record.isSetted,jdbcType=INTEGER}, is_setted = #{record.isSetted,jdbcType=INTEGER},
original_source_url = #{record.originalSourceUrl,jdbcType=VARCHAR}, original_source_url = #{record.originalSourceUrl,jdbcType=VARCHAR},
`source` = #{record.source,jdbcType=INTEGER}, `source` = #{record.source,jdbcType=INTEGER},
`type` = #{record.type,jdbcType=INTEGER} kind = #{record.kind,jdbcType=INTEGER}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
...@@ -564,8 +564,8 @@ ...@@ -564,8 +564,8 @@
<if test="source != null"> <if test="source != null">
`source` = #{source,jdbcType=INTEGER}, `source` = #{source,jdbcType=INTEGER},
</if> </if>
<if test="type != null"> <if test="kind != null">
`type` = #{type,jdbcType=INTEGER}, kind = #{kind,jdbcType=INTEGER},
</if> </if>
<if test="extra != null"> <if test="extra != null">
extra = #{extra,jdbcType=LONGVARCHAR}, extra = #{extra,jdbcType=LONGVARCHAR},
...@@ -604,7 +604,7 @@ ...@@ -604,7 +604,7 @@
is_setted = #{isSetted,jdbcType=INTEGER}, is_setted = #{isSetted,jdbcType=INTEGER},
original_source_url = #{originalSourceUrl,jdbcType=VARCHAR}, original_source_url = #{originalSourceUrl,jdbcType=VARCHAR},
`source` = #{source,jdbcType=INTEGER}, `source` = #{source,jdbcType=INTEGER},
`type` = #{type,jdbcType=INTEGER}, kind = #{kind,jdbcType=INTEGER},
extra = #{extra,jdbcType=LONGVARCHAR}, extra = #{extra,jdbcType=LONGVARCHAR},
images = #{images,jdbcType=LONGVARCHAR}, images = #{images,jdbcType=LONGVARCHAR},
videos = #{videos,jdbcType=LONGVARCHAR}, videos = #{videos,jdbcType=LONGVARCHAR},
...@@ -631,7 +631,7 @@ ...@@ -631,7 +631,7 @@
is_setted = #{isSetted,jdbcType=INTEGER}, is_setted = #{isSetted,jdbcType=INTEGER},
original_source_url = #{originalSourceUrl,jdbcType=VARCHAR}, original_source_url = #{originalSourceUrl,jdbcType=VARCHAR},
`source` = #{source,jdbcType=INTEGER}, `source` = #{source,jdbcType=INTEGER},
`type` = #{type,jdbcType=INTEGER} kind = #{kind,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
<select id="selectOneByExample" parameterType="com.wwdz.ch.db.domain.ItemExample" resultMap="BaseResultMap"> <select id="selectOneByExample" parameterType="com.wwdz.ch.db.domain.ItemExample" resultMap="BaseResultMap">
...@@ -689,7 +689,7 @@ ...@@ -689,7 +689,7 @@
<otherwise> <otherwise>
id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time, id, `name`, cid, is_on_sale, is_std, sort, share_image, top_image, price, create_time,
source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url, source_type, update_time, is_deleted, bid_time, remark, is_setted, original_source_url,
`source`, `type`, extra, images, videos, detail, original_extra `source`, kind, extra, images, videos, detail, original_extra
</otherwise> </otherwise>
</choose> </choose>
from item from item
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment