Commit 7ea33d57 authored by suhuiguang's avatar suhuiguang

1.修改初始化

parent 4c163d7b
......@@ -11,6 +11,7 @@ import com.yeejoin.amos.boot.module.elevator.api.entity.ESAlertCalled;
import com.yeejoin.amos.boot.module.elevator.api.enums.AlertStatusEnum;
import com.yeejoin.amos.boot.module.elevator.biz.dao.ESAlertCalledRepository;
import com.yeejoin.amos.boot.module.elevator.biz.utils.BeanDtoVoUtils;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -23,7 +24,6 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
......@@ -38,6 +38,7 @@ import java.util.List;
* @version $Id: ESAlertCalledService.java, v 0.1 2021年6月19日 下午5:12:01 gwb Exp $
*/
@Service
@Slf4j
public class ESAlertCalledService {
@Autowired
......@@ -51,27 +52,23 @@ public class ESAlertCalledService {
@Value("${alertcall.es.synchrony.time}")
private Long time;
@PostConstruct
public void init() throws Exception
{
//初始化ES,重建索引
initEs();
}
/**
* 重建索引
*/
public Boolean initEs() throws Exception {
esAlertCalledRepository.deleteAll();
/**
* 同步历史48小时以内的警情处置记录
*/
public Boolean initEs() {
try {
esAlertCalledRepository.deleteAll();
} catch (Exception e) {
log.error("索引不存在:{}",e.getMessage());
}
// 同步历史48小时以内的警情处置记录
QueryWrapper<AlertCalled> wrapper = new QueryWrapper<>();
long currentTime = System.currentTimeMillis() ;
if (ValidationUtil.isEmpty(time)) //默认为同步48小时
//默认为同步48小时
if (ValidationUtil.isEmpty(time))
{
currentTime = currentTime - 48*60*60*1000;
}else
......@@ -102,8 +99,7 @@ public class ESAlertCalledService {
*
* @param alertCalled 警情信息列表
*/
public ESAlertCalled saveAlertCalledToES(AlertCalled alertCalled) throws Exception
{
public ESAlertCalled saveAlertCalledToES(AlertCalled alertCalled) {
ESAlertCalled esAlertCalled = new ESAlertCalled();
esAlertCalled.setSequenceNbr(alertCalled.getSequenceNbr());
esAlertCalled.setAlarmType(alertCalled.getAlarmType());
......
......@@ -20,11 +20,18 @@ public class ElevatorAppRunner implements ApplicationRunner {
@Autowired
ElevatorServiceImpl elevatorServiceImpl;
@Autowired
ESAlertCalledService esAlertCalledService;
@Override
public void run(ApplicationArguments args) {
// 缓存电梯数据
List<ElevatorDto> list = elevatorServiceImpl.selectExportData(null);
redisUtil.set(BizCommonConstant.OLD_ELEVATOR_REDIS_KEY, JSONObject.toJSONString(list));
// 电梯es数据缓存
esAlertCalledService.initEs();
}
}
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