package com.jiayue.passback.job;
import com.jiayue.passback.entity.ElectricField;
import com.jiayue.passback.service.*;
import com.jiayue.passback.util.DateMomentUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Component
@RequiredArgsConstructor
@Slf4j
public class job extends GenerateService {

    private final List<GenerateDataService> generateDataServiceList;

//    private final List<GenerateDataLlKyService> generateDataLlKyServiceList;

    private final ElectricFieldService electricFieldService;

    @Scheduled(cron = "${job.cdqjob}")
    @Override
    public void GenerateData() {
        try {

            Date date = new Date(DateMomentUtil.getMomentTime(new Date().getTime(), 1, 15 * 60 * 1000L));
            Map<String,Object> map = new HashMap();
            ElectricField electricField = electricFieldService.list().get(0);

            map.put("elType",electricField.getElectricFieldTypeEnum().name());
            log.info("====开始启动数据生成业务，时间：{}====",DateFormatUtils.format(date,"yyyy-MM-dd HH:mm:ss"));
            generateDataServiceList.forEach(g -> {

                map.putAll(g.GenerateData(date));
            });

            log.info("====数据生成业务结束====");
            generateFile(map,date);
        } catch (Exception e) {
            log.info("数据生成业务发生错误  /(ㄒoㄒ)/~~",e);
            e.printStackTrace();
        }

    }

//    /**
//     *  内网回传理论可用功率数据
//     */
//    @Scheduled(cron = "${job.llKyjob}")
////    @Scheduled(fixedDelay = 1000*60)
//    @Override
//    public void GenerateLlKyData() {
//        try {
//
//            Date date = new Date(DateMomentUtil.getMomentTime(new Date().getTime(), 1, 5 * 60 * 1000L));
//            Map<String,Object> map = new HashMap();
//            ElectricField electricField = electricFieldService.list().get(0);
//
//            map.put("elType",electricField.getElectricFieldTypeEnum().name());
//            log.info("====开始启动数据生成业务，时间：{}====",DateFormatUtils.format(date,"yyyy-MM-dd HH:mm:ss"));
//            generateDataLlKyServiceList.forEach(g -> {
//
//                map.putAll(g.GenerateDataLlKy(date));
//            });
//
//            log.info("====数据生成业务结束====");
//            generateLlKyFile(map,date);
//        } catch (Exception e) {
//            log.info("数据生成业务发生错误  /(ㄒoㄒ)/~~");
//            e.printStackTrace();
//        }

//    }




}
