package cn.iocoder.yudao.module.system.job;

import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.system.enums.device.SleepthingApiConstants;
import cn.iocoder.yudao.module.system.service.biz.SleepthingService;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

@Component
public class SleepDeviceJob implements JobHandler {

    private final static Logger logger = LoggerFactory.getLogger(SleepDeviceJob.class);

    @Resource
    private SleepthingService sleepthingService;

    @Override
    @TenantJob
    public String execute(String param) {

        logger.info("设置睡小宝事件通知地址:{}", SleepthingApiConstants.IP);
        HashMap<String, Object> paramMap1 = Maps.newHashMap();

        paramMap1.put("reportNotifyUrl", SleepthingApiConstants.IP + "/api/sleep/reportIsReady");
        sleepthingService.setReportNotifyUrl(paramMap1);

        HashMap<String, Object> paramMap2 = Maps.newHashMap();
        paramMap2.put("alarmNotifyUrl", SleepthingApiConstants.IP +"/api/sleep/alarmNotify");
        sleepthingService.setAlarmNotifyUrl(paramMap2);

        HashMap<String, Object> paramMap3 = Maps.newHashMap();
        paramMap3.put("eventNotifyUrl", SleepthingApiConstants.IP +"/api/sleep/eventNotify");
        sleepthingService.setEventNotifyUrl(paramMap3);
        return "";
    }

}
