//package org.springblade.modules.nh.factory.ginlong;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springblade.modules.nh.factory.ginlong.dto.alarmlist.GetAlarmListR;
//import org.springblade.modules.nh.factory.ginlong.dto.alarmlist.GetAlarmListReq;
//import org.springblade.modules.nh.factory.ginlong.dto.collectorlist.GetCollectorListResp;
//import org.springblade.modules.nh.factory.ginlong.dto.inverterday.GetInverterDayR;
//import org.springblade.modules.nh.factory.ginlong.dto.inverterday.GetInverterDayReq;
//import org.springblade.modules.nh.factory.ginlong.dto.inverterdetaillist.GetInverterDetailListReq;
//import org.springblade.modules.nh.factory.ginlong.dto.inverterdetaillist.GetInverterDetailR;
//import org.springblade.modules.nh.factory.ginlong.dto.inverterlist.GetInverterListReq;
//import org.springblade.modules.nh.factory.ginlong.dto.inverterlist.GetInverterListResp;
//import org.springblade.modules.nh.factory.ginlong.dto.inverterlist.GetInverterR;
//import org.springblade.modules.nh.factory.ginlong.dto.invertermonth.GetInverterMonthR;
//import org.springblade.modules.nh.factory.ginlong.dto.invertermonth.GetInverterMonthReq;
//import org.springblade.modules.nh.factory.ginlong.dto.stationday.GetStationDayR;
//import org.springblade.modules.nh.factory.ginlong.dto.stationday.GetStationDayReq;
//import org.springblade.modules.nh.factory.ginlong.dto.stationdayenergylist.GetStationDayEnergyListR;
//import org.springblade.modules.nh.factory.ginlong.dto.stationdayenergylist.GetStationDayEnergyListReq;
//import org.springblade.modules.nh.factory.ginlong.dto.stationmonth.GetStationMonthR;
//import org.springblade.modules.nh.factory.ginlong.dto.stationmonth.GetStationMonthReq;
//import org.springblade.modules.nh.factory.ginlong.dto.stationyear.GetStationYearR;
//import org.springblade.modules.nh.factory.ginlong.dto.stationyear.GetStationYearReq;
//import org.springblade.modules.nh.factory.ginlong.dto.userstationlist.GetStationListReq;
//import org.springblade.modules.nh.factory.ginlong.dto.userstationlist.GetStationListResp;
//import org.springblade.modules.nh.factory.ginlong.dto.userstationlist.GetStationR;
//import org.springblade.modules.nh.factory.ginlong.scheduler.GinlongInverterDayEachRunner;
//import org.springblade.modules.nh.factory.ginlong.scheduler.GinlongStationMonthEachRunner;
//import org.springblade.modules.nh.factory.ginlong.scheduler.GinlongStationYearEachRunner;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.IOException;
//import java.util.*;
//
//@RestController
//@RequestMapping("/gin")
//@Slf4j
//public class GinlongApiTestController {
//
//    @Autowired
//    GinlongApi ginlongApi;
//    @Autowired
//    GinlongStationMonthEachRunner ginlongStationMonthEachRunner;
//    @Autowired
//    MonitorAlarmInfoServiceImpl monitorAlarmInfoService;
//    @Autowired
//    GinlongInverterDayEachRunner ginlongInverterDayEachRunner;
//    @Autowired
//    MonitorInverterStatServiceImpl monitorInverterStatService;
//    @Autowired
//    GinlongStationYearEachRunner ginlongStationYearEachRunner;
//    @Autowired
//    MonitorEntryStatServiceImpl monitorEntryStatService;
//
//    @GetMapping(value = "userStationList")
//    public Object userStationList(@RequestParam(value = "pageNo", required = false) Integer pageNo,
//                                  @RequestParam(value = "pageSize", required = false) Integer pageSize) throws IOException {
//        GetStationListReq req = new GetStationListReq();
//        req.setPageSize(pageSize == null ? 300 : pageSize);
//        req.setPageNo(pageNo == null ? 1 : pageNo);
//        req.setNmiCode(null);
//        IRet<GetStationListResp> getStationListRespResult = ginlongApi.userStationList(req);
//        GetStationListResp data = getStationListRespResult.getData();
//        List<GetStationR> records = data.getPage().getRecords();
//        for (GetStationR record : records) {
//            int state = record.getState();
//            if (state == 1) {
//                log.info("station, id: {}, nmiCode: {}", record.getId(), record.getNmiCode());
//                break;
//            }
//        }
//        return getStationListRespResult;
//    }
//
//    @GetMapping(value = "inverterDetailList")
//    public Object inverterDetailList() throws IOException {
//        GetInverterDetailListReq req = new GetInverterDetailListReq();
//        req.setPageSize(100);
//        req.setPageNo(1);
//        IRet<Page<GetInverterDetailR>> ret = ginlongApi.inverterDetailList(req);
//        monitorInverterStatService.syncInverterDetails(ret.getData().getRecords(), Constants.SYS_TYPE_GINLONG, new HashSet<>());
//        log.info("ret.code: {}", ret.getCode());
//        return ret;
//    }
//
//    @GetMapping(value = "inverterList")
//    public Object inverterList() throws IOException {
//        GetInverterListReq req = new GetInverterListReq();
//        req.setPageSize(100);
//        req.setPageNo(1);
////        req.setStationId("1299184320438796693");
//        req.setNmiCode(null);
//        IRet<GetInverterListResp> ret = ginlongApi.inverterList(req);
//        GetInverterListResp data = ret.getData();
//        if (data != null && data.getPage() != null && data.getPage().getRecords() != null) {
//            List<GetInverterR> records = data.getPage().getRecords();
//            Double sum = records.stream().reduce(0d, (a, b) -> a + b.getEtoday(), Double::sum);
//            log.info("total sum is: {}", sum);
//        }
//
//        log.info("ret.code: {}", ret.getCode());
//        return ret;
//    }
//
//    @GetMapping(value = "inverterDay")
//    public Object inverterDay() throws IOException {
//        GetInverterDayReq req = new GetInverterDayReq();
//        // 对应电站id:  1299184320438796693
////        req.setId("1299184088035530778");
//        req.setId("1299184088035530844"); // sn: 2016010233070199, inverterId: 1299184088035530844
//        req.setMoney("CNY");
//        req.setTime("2024-02-18");
//        req.setTimeZone(8);
//        IRet<List<GetInverterDayR>> ret = ginlongApi.inverterDay(req);
//        log.info("ret.code: {}", ret.getCode());
//        Map<String, Object> ctx = new HashMap<>();
//        ctx.put("baseDate", DateUtils.formatDate(new Date(), "yyyy-MM-dd"));
//        ginlongInverterDayEachRunner.handle("1299184088035530844", ctx);
//        return ret;
//    }
//
//    @GetMapping(value = "stationDay")
//    public Object stationDay() throws IOException {
//        GetStationDayReq req = new GetStationDayReq();
//        // 对应电站id:  1299184320438796693
//        // entry id: 4028819b8bf9e458018c14ccfd500012
//        req.setId("1299184320438796693");
//        req.setMoney("CNY");
//        req.setTime("2024-01-30");
//        req.setTimeZone(8);
//        IRet<List<GetStationDayR>> ret = ginlongApi.stationDay(req);
//        log.info("ret.code: {}", ret.getCode());
//        return ret;
//    }
//
//    @GetMapping(value = "stationMonth")
//    public Object stationMonth() throws IOException {
//        GetStationMonthReq req = new GetStationMonthReq();
//        // 对应电站id:  1299184320438796693
//        req.setId("1299184320438796693");
//        req.setMoney("CNY");
//        req.setMonth("2024-04");
//        req.setTimeZone(8);
//        IRet<List<GetStationMonthR>> ret = ginlongApi.stationMonth(req);
//        log.info("ret.code: {}", ret.getCode());
//        return ret;
//    }
//
//    @GetMapping(value = "stationYear")
//    public Object stationYear() throws IOException {
//        GetStationYearReq req = new GetStationYearReq();
//        // 对应电站id:  1299184320438796693
//        req.setId("1299184320438796693");
//        req.setMoney("CNY");
//        req.setYear("2023");
//        req.setTimeZone(8);
//        IRet<List<GetStationYearR>> ret = ginlongApi.stationYear(req);
//        log.info("ret.code: {}", ret.getCode());
//        return ret;
//    }
//
//    @GetMapping(value = "syncStationYear")
//    public Object syncStationYear() throws IOException {
//        List<String> stationIds = monitorEntryStatService.getStationIds("0");
//        ginlongStationYearEachRunner.start(stationIds, "获取单个电站某年的月数据", 1L, null);
//        return "ok";
//    }
//
//    @GetMapping(value = "collectorList")
//    public Object collectorList() throws IOException {
//        GetInverterDetailListReq req = new GetInverterDetailListReq();
//        req.setPageNo(1);
//        req.setPageSize(100);
//        IRet<GetCollectorListResp> ret = ginlongApi.collectorList(req);
//        log.info("ret.code: {}", ret.getCode());
//        return ret;
//    }
//
//    @GetMapping(value = "inverterMonth")
//    public Object inverterMonth() throws IOException {
//        GetInverterMonthReq req = new GetInverterMonthReq();
//        // 对应 station id:  1299184320438796693
//        // 对应 inverter id:  1299184088035530844
//        req.setId("1299184088035530844");
//        req.setMoney("CNY");
//        req.setMonth("2024-02");
//        IRet<List<GetInverterMonthR>> ret = ginlongApi.inverterMonth(req);
//
//        log.info("ret.code: {}", ret.getCode());
//        return ret;
//    }
//
//    @GetMapping(value = "stationDayEnergyList")
//    public Object stationDayEnergyList() throws IOException {
//        GetStationDayEnergyListReq req = new GetStationDayEnergyListReq();
//        // 对应电站id:  1299184320438796693
//        req.setPageNo(1);
//        req.setPageSize(10);
//        req.setStationIds("1299184320438796693");
//        req.setTime("2024-01-31");
//        IRet<Page<GetStationDayEnergyListR>> ret = ginlongApi.stationDayEnergyList(req);
//        log.info("ret.code: {}", ret.getCode());
//        return ret;
//    }
//
//    @GetMapping(value = "alarmList")
//    public Object alarmList() throws IOException {
//        GetAlarmListReq req = new GetAlarmListReq();
//        // 对应电站id:  1299184320438796693
//        req.setPageNo(1);
//        req.setPageSize(100);
//        req.setAlarmBeginTime("2024-01-31");
//        IRet<Page<GetAlarmListR>> ret = ginlongApi.alarmList(req);
//        monitorAlarmInfoService.syncAlarmInfo(ret.getData().getRecords(), Constants.SYS_TYPE_GINLONG);
//        log.info("ret.code: {}", ret.getCode());
//        return ret;
//    }
//
//}
