package com.gyee.generation.controller;

import com.gyee.common.config.R;
import com.gyee.common.util.DateUtils;
import com.gyee.generation.service.AnalysisNewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;

@RestController
@RequestMapping("//analysis")
@Api(value = "底码", tags = "底码")
public class AnalysisNewController {

    @Resource
    private AnalysisNewService analysisNewService;

    //    @Scheduled(cron = "0 15 0 * * ?")
    @GetMapping(value = "/companys")
    @ApiOperation(value = "公司列表", notes = "公司列表")
    public R companys() throws Exception {
        analysisNewService.companys();

        return null;
    }

    //    @Scheduled(cron = "0 30 0 * * ?")
    @GetMapping(value = "/can")
    @ApiOperation(value = "公司列表", notes = "公司列表")
    public R cans() throws Exception {
        // 获取当前日期
        Date currentDate = new Date();

        // 创建 Calendar 对象，并设置为当前日期
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);

        // 将时间设为0点
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        // 设置 beginDate 为前一天的0点
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        Date beginDate = calendar.getTime();

        // 设置 endDate 为当天的0点
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        Date endDate = calendar.getTime();


        //补充数据可将其打开
        //        for (int i = 0; i < 44; i++) {
        //        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //
        //        String beginDateStr = sdf.format(beginDate);
        //        String endDateStr = sdf.format(endDate);


        String yesterday = DateUtils.getYesterdayStr("yyyy-MM-dd");
        analysisNewService.saveWindProject();

        //          beginDate = DateUtils.addDays(beginDate, -1);
        //          calendar.add(Calendar.DAY_OF_MONTH, -1);
        //          endDate = calendar.getTime();
        //        }

        return null;
    }
}
