package com.rongwei.bsserver.sys.controller;

import com.rongwei.bscommon.sys.service.EquEnergyRecordService;
import com.rongwei.rwcommon.base.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 表具管理
 * 2024-07-12
 * huangpeng
 */
@RestController
@RequestMapping("/equEnergyRecord")
public class EquEnergyRecordController {

    private static final Logger logger = LoggerFactory.getLogger(EquEnergyRecordController.class);
    @Autowired
    EquEnergyRecordService equEnergyRecordService;


    /**
     * 计算能源用量
     * @param
     * @return
     */
    @Scheduled(cron = "0 0 6/2 1/1 * ? ")
    @RequestMapping("/calEnergyUsage")
    public R calEnergyUsage() {
        try {
            logger.info("计算能源用量开始：{}"+new Date());
            return equEnergyRecordService.calEnergyUsage();
        } catch (Exception e) {
            logger.error("计算能源用量失败：{}" + e.getMessage());
            return R.error();
        }
    }


    /**
     * 手动入参 补充数据
     * @param endTime
     * @return
     */
    @RequestMapping("/calEnergyUsageByStartTime/{endTime}")
    public R calEnergyUsageByStartTime(@PathVariable("endTime") String endTime) {
        try {
            logger.info("手动调用计算能源用量开始：{}"+new Date());
            return equEnergyRecordService.calEnergyUsageByStartTime(endTime);
        } catch (Exception e) {
            logger.error("计算能源用量失败：{}" + e.getMessage());
            return R.error();
        }
    }
}
