package com.rongwei.bsserver.sys.controller;

import com.rongwei.bscommon.sys.service.impl.EquGdyRecordServiceImpl;
import com.rongwei.bsentity.domain.EquGdyRecordDo;
import com.rongwei.rwcommon.base.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * EquGdyRecordController class
 *
 * @author XH
 * @date 2024/11/05
 */
@RestController
@RequestMapping("/equ-gdy-record")
public class EquGdyRecordController {
    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
    @Autowired
    private EquGdyRecordServiceImpl equGdyRecordService;


    @Scheduled(cron = "1 0 0 * * ? ")
    @PostMapping("/write")
    public R generateDailyRecords() {
        return equGdyRecordService.generateDailyRecords();
    }

    @PostMapping("/save")
    public R saveData(@RequestBody EquGdyRecordDo equGdyRecordDo) {
        return equGdyRecordService.saveData(equGdyRecordDo);
    }

    @PostMapping("/generate-by-date")
    public R generateByDate(@RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                            @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        return equGdyRecordService.generateByDate(startDate, endDate);
    }
}
