package com.xhpc.order.controller;

import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.order.service.IXhpcChargingStationPowerService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yuyang
 * @date 2023-06-28 14:11
 */
@EnableScheduling
@RestController
@RequestMapping("/chargingStationPower")
public class XhpcChargingStationPowerController extends BaseController {

    @Resource
    private IXhpcChargingStationPowerService xhpcChargingStationPowerService;
    @Autowired
    private RedisService redisService;

    @GetMapping("/test1")
    @Scheduled(cron = "0 0/3 0/1 * * ? ")
    public void test1(){
        xhpcChargingStationPowerService.addChargingStationPower();
    }

    //列表
    @GetMapping("/getListPage")
    public TableDataInfo getListPage(
                                    @RequestParam(required = false)String tenantId,
                                    @RequestParam(required = false)Long chargingStationId,
                                     @RequestParam(required = false)Long chargingPileId,
                                     @RequestParam(required = false)Long terminalId,
                                     @RequestParam(required = false)Long operatorId,
                                     @RequestParam(required = true)String startTime,
                                     @RequestParam(required = true)String endTime
                                     ) {
        Map<String, Object> params = new HashMap<>();
        params.put("tenantId",tenantId);
        params.put("chargingStationId",chargingStationId);
        params.put("chargingPileId",chargingPileId);
        params.put("terminalId",terminalId);
        params.put("operatorId",operatorId);
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        List<Map<String, Object>> listPage = xhpcChargingStationPowerService.getListPage(params);
        return getDataTable(listPage);
    }


    //获取所有场站
    @GetMapping("/getChargingStationList")
    public R getChargingStationList(){
        return R.ok(xhpcChargingStationPowerService.getChargingStationList());
    }


    //获取订单最大功率统计列表
    @GetMapping("/getMaxPowerList")
    public TableDataInfo getMaxPowerList(
            @RequestParam(required = false)String tenantId,
            @RequestParam(required = false)String startTime,
            @RequestParam(required = false)String endTime,
            @RequestParam(required = false)Long chargingStationId,
            @RequestParam(required = false)Long chargingPileId,
            @RequestParam(required = false)Long terminalId,
            @RequestParam(required = false)Long operatorId,
            @RequestParam String pileStart,
            @RequestParam String pileEnd,
            @RequestParam String bmsStart,
            @RequestParam String bmsEnd,
            @RequestParam String pileVoltageStart,
            @RequestParam String pileVoltageEnd,
            @RequestParam String bmsVoltageStart,
            @RequestParam String bmsVoltageEnd,
            @RequestParam String pileCurrentStart,
            @RequestParam String pileCurrentEnd,
            @RequestParam String bmsCurrentStart,
            @RequestParam String bmsCurrentEnd
    ) {
        Map<String, Object> params = new HashMap<>();
        params.put("tenantId",tenantId);
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("chargingStationId",chargingStationId);
        params.put("chargingPileId",chargingPileId);
        params.put("terminalId",terminalId);
        params.put("operatorId",operatorId);
        params.put("pileStart",pileStart);
        params.put("pileEnd",pileEnd);
        params.put("bmsStart",bmsStart);
        params.put("bmsEnd",bmsEnd);
        params.put("pileVoltageStart",pileVoltageStart);
        params.put("pileVoltageEnd",pileVoltageEnd);
        params.put("bmsVoltageStart",bmsVoltageStart);
        params.put("bmsVoltageEnd",bmsVoltageEnd);
        params.put("pileCurrentStart",pileCurrentStart);
        params.put("pileCurrentEnd",pileCurrentEnd);
        params.put("bmsCurrentStart",bmsCurrentStart);
        params.put("bmsCurrentEnd",bmsCurrentEnd);
        List<Map<String, Object>> listPage = xhpcChargingStationPowerService.getMaxPowerList(params);
        return getDataTable(listPage);
    }




}
