/**
 * Copyright
 * All right reserved.
 * 项目名称:
 * 创建日期:2022/5/22
 */
package org.springblade.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.baseinfo.rtu.entity.RtuInfoEntity;
import org.springblade.modules.baseinfo.rtu.service.IRtuBaseInfoService;
import org.springblade.modules.business.warning.service.IRtuWarningService;

import java.util.List;
import java.util.concurrent.Callable;

/***
 * Date:2022/5/22
 * Title: 预警处理任务
 * Description：
 * @author swp
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@Slf4j
public class WarningCheckTask implements Callable<Integer> {

	private IRtuBaseInfoService rtuBaseInfoService;
	private IRtuWarningService rtuWarningService;


	public WarningCheckTask(IRtuBaseInfoService rtuBaseInfoService, IRtuWarningService rtuWarningService) {
		this.rtuBaseInfoService = rtuBaseInfoService;
		this.rtuWarningService = rtuWarningService;
	}

	@Override
	public Integer call() {
		try {
			log.info("预警检测任务开始执行*********************");
			//检测离线
			LambdaQueryWrapper<RtuInfoEntity> dataWrapper = Wrappers.<RtuInfoEntity>query().lambda();
			dataWrapper.eq(RtuInfoEntity::getIsDeleted, 0);
			dataWrapper.orderByAsc(RtuInfoEntity::getRtuCode);
			List<RtuInfoEntity> list = rtuBaseInfoService.list(dataWrapper);
			if (null != list && list.size() > 0) {
				for (RtuInfoEntity entity : list) {
					//检测测站时钟状态
					rtuWarningService.checkRtuClockStatus(entity);
					//疑似异常值
					rtuWarningService.checkRtuOutlierValueStatus(entity);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error("数据统计任务异常 {}", e.getMessage());
		}
		return 0;
	}
}
