package com.jiayue.ipfcst.console.controller;


import cn.hutool.core.date.DateUtil;
import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.entity.PowerPlanSD;
import com.jiayue.ipfcst.console.service.PowerPlanSDService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 用户信息restful接口
 *
 * @author bizy
 * @version 3.0
 * @since 2020/6/28 10:12
 */
@RestController
@Slf4j
public class PowerPlanSDController {

    private final PowerPlanSDService powerPlanSDService;

    @Autowired
    public PowerPlanSDController(PowerPlanSDService powerPlanSDService) {
        this.powerPlanSDService = powerPlanSDService;
    }

    /**
     * 根据条件查询
     * @param startTimeStr 开始时间
     * @param endTimeStr 结束时间
     * @return map
     */
    @GetMapping(value = "/pwoerPlanSD/{startTimeStr}/{endTimeStr}")
    public ResponseVO getPowerPlan(@PathVariable final String startTimeStr,
                                   @PathVariable final String endTimeStr) {
        List<PowerPlanSD> list = powerPlanSDService.getPowerPlan(startTimeStr,endTimeStr);
        for (PowerPlanSD powerPlanSD : list) {
            powerPlanSD.setBackupA(DateUtil.format(new Date(powerPlanSD.getPlanTime()),"yyyy-MM-dd HH:mm:ss"));
        }
        return ResponseVO.success(list);
    }

    /**
     *根据条件查询
     * @param startTimeStr 开始时间
     * @param endTimeStr 结束时间
     * @return map
     */
    @PostMapping("powerPlanSD/getPowerPlanDrawing/{startTimeStr}/{endTimeStr}")
    public ResponseVO getPowerPlanDrawing(
            @PathVariable final String startTimeStr,
            @PathVariable final String endTimeStr) {
        List<PowerPlanSD> list = powerPlanSDService.getPowerPlanDrawing(startTimeStr,endTimeStr);
        return ResponseVO.success(list);
    }
}
