package com.zcxk.controller;

import com.zcxk.entity.DayReportEntity;
import com.zcxk.service.TestDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @description
 * @auto wangli
 * @data 2020/12/14 11:29
 */
@RestController
@RequestMapping("/TestDataController")
@Api(tags = "数据测试")
public class TestDataController {
    @Autowired
    private TestDataService testDataService;

    @RequestMapping(value="createDataByDay" , method = RequestMethod.GET)
    @ApiOperation(value = "生成日、月、年数据")
    public void createDataByDay(
            @ApiParam("设备id") @RequestParam List<Long> ids,
             @ApiParam("开始时间，yyyy-MM-dd") @RequestParam String beginDate,
            @ApiParam("结束时间，yyyy-MM-dd")@RequestParam String endDate){
        LocalDate localDate1 =LocalDate.now();
        LocalDate localDate2 =LocalDate.now();
        if(null != beginDate){
            localDate1 = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            localDate2 = LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }
        for(Long id:ids){
            List<DayReportEntity> dayReportEntity = testDataService.selectDeviceInfo(id);
            testDataService.createDataByDay(dayReportEntity,localDate1,localDate2.plusDays(1));

            testDataService.createDataByMonth(id,localDate1,localDate2.plusDays(1));
            testDataService.createDataByYear(id,localDate1,localDate2.plusDays(1));
        }
//        testDataService.createAlarmByDay(id.intValue(),localDate1,localDate2.plusDays(1),100);
    }

    @RequestMapping(value="createAlarmDataByDay" , method = RequestMethod.GET)
    @ApiOperation(value = "生成报警数据")
    public void createAlarmDataByDay(
            @ApiParam("设备id") @RequestParam List<Long> ids,
            @ApiParam("报警信息条数") @RequestParam Integer number,
            @ApiParam("开始时间，yyyy-MM-dd") @RequestParam String beginDate,
            @ApiParam("结束时间，yyyy-MM-dd")@RequestParam String endDate) {
        LocalDate localDate1 = LocalDate.now();
        LocalDate localDate2 = LocalDate.now();
        if (null != beginDate) {
            localDate1 = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            localDate2 = LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }
        for(Long id:ids){
            testDataService.createAlarmByDay(id.intValue(),localDate1,localDate2.plusDays(1),number);
        }
    }
}
