Commit 3558e93f authored by Quxl's avatar Quxl

x

parent 56674fac
package com.egolm.search.schedules.house; package com.egolm.search.schedules.house;
import java.io.InputStream;
import java.util.Date; import java.util.Date;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -33,6 +32,27 @@ public class HouseCollectTask extends AbstractSolrApi{ ...@@ -33,6 +32,27 @@ public class HouseCollectTask extends AbstractSolrApi{
@Value("${solr.house.offset-minute-for-minute}") @Value("${solr.house.offset-minute-for-minute}")
private Long offsetMinuteForMinute; private Long offsetMinuteForMinute;
@Value("${sql.house.create-index-query}")
private String createIndexQueryFilePath;
@Value("${sql.house.delete-index-query}")
private String deleteIndexQueryFilePath;
@Value("${sql.house.update-index-query}")
private String updateIndexQueryFilePath;
private String createIndexQuerySql;
private String updateIndexQuerySql;
private String deleteIndexQuerySql;
@PostConstruct
public void init() {
createIndexQuerySql = FileUtil.fileToString(createIndexQueryFilePath);
updateIndexQuerySql = FileUtil.fileToString(deleteIndexQueryFilePath);
deleteIndexQuerySql = FileUtil.fileToString(updateIndexQueryFilePath);
}
@Scheduled(cron="${solr.house.cron-for-day}") @Scheduled(cron="${solr.house.cron-for-day}")
public void dayExecute() { public void dayExecute() {
Date date = new Date(System.currentTimeMillis() - (offsetMinuteForDay*60L*1000L)); Date date = new Date(System.currentTimeMillis() - (offsetMinuteForDay*60L*1000L));
...@@ -59,25 +79,5 @@ public class HouseCollectTask extends AbstractSolrApi{ ...@@ -59,25 +79,5 @@ public class HouseCollectTask extends AbstractSolrApi{
public HttpSolrClient getSolrClient() { public HttpSolrClient getSolrClient() {
return solrClient; return solrClient;
} }
static {
try {
Resource createIndexQuerySqlResource = new ClassPathResource("sql/house/create-index-query.sql");
Resource updateIndexQuerySqlResource = new ClassPathResource("sql/house/update-index-query.sql");
Resource deleteIndexQuerySqlResource = new ClassPathResource("sql/house/delete-index-query.sql");
InputStream createIndexQuerySqlStream = createIndexQuerySqlResource.getInputStream();
InputStream updateIndexQuerySqlStream = updateIndexQuerySqlResource.getInputStream();
InputStream deleteIndexQuerySqlStream = deleteIndexQuerySqlResource.getInputStream();
createIndexQuerySql = new String(FileUtil.streamToBytes(createIndexQuerySqlStream));
updateIndexQuerySql = new String(FileUtil.streamToBytes(updateIndexQuerySqlStream));
deleteIndexQuerySql = new String(FileUtil.streamToBytes(deleteIndexQuerySqlStream));
} catch (Throwable e) {
throw new RuntimeException("索引更新查询[SQL]加载错误", e);
}
}
private static final String createIndexQuerySql;
private static final String updateIndexQuerySql;
private static final String deleteIndexQuerySql;
} }
...@@ -2,4 +2,10 @@ server: ...@@ -2,4 +2,10 @@ server:
port: 9090 port: 9090
spring: spring:
profiles: profiles:
active: dev active: dev
\ No newline at end of file sql.house:
create-index-query: sql/house/create-index-query.sql
delete-index-query: sql/house/delete-index-query.sql
update-index-query: sql/house/update-index-query.sql
\ No newline at end of file
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