package com.zt.plat.module.qms.iot.tcpserver.listener;

import com.zt.plat.module.qms.iot.tcpserver.core.EventConstant;
import com.zt.plat.module.qms.iot.tcpserver.event.HygrothermographEvent;
import com.zt.plat.module.qms.iot.tcpserver.pojo.Hygrothermograph;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * <b>HygrothermographListener</b>
 * <p>更新历史：</p>
 * <pre> 版本         更新时间            更新者        更新内容
 * V1.0      2021-10-18          王兴荣         Add</pre>
 * <b>Copyright (C)  云南志者竟成科技有限公司</b> 
 * @author 王兴荣 &lt;xingrong_wang@will-way.cn&gt;
 * @version V1.0 
 * @since 2021-10-18
 */
@Slf4j
@Component
@AllArgsConstructor
public class HygrothermographListener {

//    private final ITimeSeriesDataService timeSeriesDataService;

    @Async
    @Order
    @EventListener(HygrothermographEvent.class)
    @SuppressWarnings("unchecked")
    public void saveHygrothermograph(HygrothermographEvent event) {
        try {
            Map<String, Object> source = (Map<String, Object>) event.getSource();
            Hygrothermograph hygrothermograph = (Hygrothermograph) source.get(EventConstant.EVENT_HYGROTHERMOGRAPH);
//            timeSeriesDataService.saveHygrothermograph(hygrothermograph);
        } catch (Exception e) {
            log.error("保存温湿度数据出错！", e);
        }
        
    }
}
