|
@@ -22,6 +22,7 @@ import com.sxtvs.open.api.news.entity.YoumeiOffset;
|
|
|
import com.sxtvs.open.api.news.mapper.YoumeiDataMapper;
|
|
|
import com.sxtvs.open.api.news.service.IYoumeiDataService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.sxtvs.open.core.sls.AliyunLogger;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.util.TextUtils;
|
|
@@ -37,7 +38,7 @@ import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author syj
|
|
@@ -53,10 +54,10 @@ public class YoumeiDataServiceImpl extends ServiceImpl<YoumeiDataMapper, YoumeiD
|
|
|
private YoumeiOffsetServiceImpl youmeiOffsetService;
|
|
|
|
|
|
@Resource
|
|
|
- private ObjectMapper objectMapper;
|
|
|
+ private AliyunLogger logger;
|
|
|
|
|
|
|
|
|
- public Page<YoumeiEsData> search(DataRequestDTO dataRequestDTO){
|
|
|
+ public Page<YoumeiEsData> search(DataRequestDTO dataRequestDTO) {
|
|
|
|
|
|
SearchResponse<YoumeiEsData> response = null;
|
|
|
Page<YoumeiEsData> page = new Page<>(dataRequestDTO.getPage(), dataRequestDTO.getPageSize());
|
|
@@ -68,25 +69,25 @@ public class YoumeiDataServiceImpl extends ServiceImpl<YoumeiDataMapper, YoumeiD
|
|
|
builder.index("news_data").from(offset).size((int) page.getSize());
|
|
|
|
|
|
// 日期
|
|
|
- if(dataRequestDTO.getStart() != null){
|
|
|
+ if (dataRequestDTO.getStart() != null) {
|
|
|
String start = dataRequestDTO.getStart().format(dateTimeFormatter);
|
|
|
String end = dataRequestDTO.getEnd().format(dateTimeFormatter);
|
|
|
- builder.query(Query.of(x->x.range(y -> y.field("publishTime").gte(JsonData.of(start)).lte(JsonData.of(end)))));
|
|
|
+ builder.query(Query.of(x -> x.range(y -> y.field("publishTime").gte(JsonData.of(start)).lte(JsonData.of(end)))));
|
|
|
}
|
|
|
|
|
|
// 关键词
|
|
|
- if(TextUtils.isEmpty(dataRequestDTO.getKeywords())){
|
|
|
+ if (TextUtils.isEmpty(dataRequestDTO.getKeywords())) {
|
|
|
builder.sort(SortOptions.of(
|
|
|
- so -> so.field(fs->fs.field("offset").order(SortOrder.Desc))
|
|
|
+ so -> so.field(fs -> fs.field("offset").order(SortOrder.Desc))
|
|
|
));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
builder.query(
|
|
|
Query.of(y -> y.multiMatch(MultiMatchQuery.of(z -> z.fields(Arrays.asList("title", "content")).query(dataRequestDTO.getKeywords()))))
|
|
|
).minScore(10D);
|
|
|
}
|
|
|
|
|
|
// 类型
|
|
|
- if(!TextUtils.isEmpty(dataRequestDTO.getCategory())){
|
|
|
+ if (!TextUtils.isEmpty(dataRequestDTO.getCategory())) {
|
|
|
builder.query(
|
|
|
Query.of(x -> x.term(y -> y.field("category").value(dataRequestDTO.getCategory())))
|
|
|
);
|
|
@@ -115,22 +116,22 @@ public class YoumeiDataServiceImpl extends ServiceImpl<YoumeiDataMapper, YoumeiD
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
- public void putDataRun(){
|
|
|
+ public void putDataRun() {
|
|
|
(new Thread(this::putData)).start();
|
|
|
}
|
|
|
|
|
|
- public void putData() {
|
|
|
+ public void putData() {
|
|
|
log.info("ES 入数据开始");
|
|
|
YoumeiOffset youmeiOffset = youmeiOffsetService.getById(4);
|
|
|
long offset = youmeiOffset.getOffset() + 1L;
|
|
|
long max = 0L;
|
|
|
- while (true){
|
|
|
+ while (true) {
|
|
|
List<CategoryData> youmeiDataList = baseMapper.getCategoryList(offset, 1000);
|
|
|
- log.info("本次数据{}条,offset从{}开始",youmeiDataList.size(), offset);
|
|
|
- if (youmeiDataList.size() == 0){
|
|
|
+ log.info("本次数据{}条,offset从{}开始", youmeiDataList.size(), offset);
|
|
|
+ if (youmeiDataList.size() == 0) {
|
|
|
break;
|
|
|
}
|
|
|
- max = youmeiDataList.get(youmeiDataList.size()-1).getOffset();
|
|
|
+ max = youmeiDataList.get(youmeiDataList.size() - 1).getOffset();
|
|
|
List<BulkOperation> bulkOperations = new ArrayList<>();
|
|
|
|
|
|
youmeiDataList.forEach(a -> {
|
|
@@ -139,18 +140,18 @@ public class YoumeiDataServiceImpl extends ServiceImpl<YoumeiDataMapper, YoumeiD
|
|
|
});
|
|
|
|
|
|
try {
|
|
|
- elasticsearchClient.bulk(BulkRequest.of(x ->x.index("news_data").operations(bulkOperations)));
|
|
|
+ elasticsearchClient.bulk(BulkRequest.of(x -> x.index("news_data").operations(bulkOperations)));
|
|
|
} catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ logger.error("error", e);
|
|
|
}
|
|
|
|
|
|
- if (youmeiDataList.size() < 1000){
|
|
|
+ if (youmeiDataList.size() < 1000) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
offset += 1000;
|
|
|
}
|
|
|
- if(max > 0L){
|
|
|
+ if (max > 0L) {
|
|
|
youmeiOffset.setOffset(max);
|
|
|
youmeiOffsetService.updateById(youmeiOffset);
|
|
|
}
|