package com.mortals.xhx.daemon.task;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.alarm.model.AlarmSmsSendEntity;
import com.mortals.xhx.module.alarm.model.AlarmSmsSendQuery;
import com.mortals.xhx.module.alarm.service.AlarmSmsSendService;
import com.mortals.xhx.module.device.model.*;
import com.mortals.xhx.module.device.service.*;
import com.mortals.xhx.module.platform.service.PlatformService;
import com.mortals.xhx.module.product.service.ProductService;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static java.math.BigDecimal.ROUND_HALF_DOWN;
import static java.util.stream.Collectors.counting;

/**
 * 设备统计任务，生成当天统计数据
 *
 * @author: zxfei
 * @date: 2022/3/9 15:19
 */
@CommonsLog
@Service("DeviceTotalStatTask")
public class DeviceTotalStatTaskImpl implements ITaskExcuteService {

    @Autowired
    private DeviceService deviceService;
    @Autowired
    private ISiteFeign siteFeign;

    @Override
    public void excuteTask(ITask task) throws AppException {
        //统计所有站点
        SitePdu sitePdu = new SitePdu();
        sitePdu.setSize(-1);
        siteFeign.list(sitePdu).getData().getData().parallelStream().forEach(item -> {
            deviceService.deviceStat(item.getId(), null);
        });
    }

    @Override
    public void stopTask(ITask task) throws AppException {

    }

    public static void main(String[] args) {

        System.out.println(DateUtil.month(new Date()));

        System.out.println(DateUtil.year(new Date()));

        System.out.println(DateUtil.dayOfMonth(new Date()));


    }


}
