package com.xhpc.charging.station.api;

import com.xhpc.charging.station.service.IXhpcChargingStationService;
import com.xhpc.charging.station.service.IXhpcTerminalService;
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 org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
import java.util.Map;

import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;

@RestController
@RequestMapping("/api/station")
public class XhpcChargingStationApiController extends BaseController {

    @Autowired
    private IXhpcChargingStationService xhpcChargingStationService;
    @Autowired
    private IXhpcTerminalService xhpcTerminalService;
    @Autowired
    private RedisService redisService;
    /**
     * 微信小程序电站列表
     *
     * @param name              电站名称
     * @param serviceFacilities 标签（服务设施）
     * @param code              城市id
     * @param longitude         经度
     * @param latitude          维度
     * @return
     */
    //@PreAuthorize(hasPermi = "system:station:list")
    @GetMapping("/getWXList")
    public TableDataInfo getWXList(String name, String serviceFacilities, Integer code, String longitude, String latitude,String tenantId) {
        startPage();
        List<Map<String, Object>> list = xhpcChargingStationService.getWXList(name, serviceFacilities, code, longitude, latitude,tenantId);
        return getDataTable(list);
    }

    /**
     * 电站详情+站点详情(微信)
     *
     * @param chargingStationId 站点id
     * @param longitude         经度
     * @param latitude          维度
     * @return
     */
    @GetMapping(value = "/getWXXhpcChargingStationMessage")
    public AjaxResult getWXXhpcChargingStationMessage(@RequestParam(value = "chargingStationId") Long chargingStationId, @RequestParam(value = "longitude") String longitude, @RequestParam(value = "latitude") String latitude) {

        return AjaxResult.success(xhpcChargingStationService.getWXXhpcChargingStationMessage(chargingStationId, longitude, latitude));
    }

    /**
     * 电站详情---价格详情
     *
     * @param chargingStationId 站点id
     * @return
     */
    @GetMapping(value = "/getWXXhpcRateTimeMassage")
    public AjaxResult getXhpcRateTimeMassage(@RequestParam Long chargingStationId) {

        return AjaxResult.success(xhpcChargingStationService.getWXXhpcRateTimeMassage(chargingStationId));
    }

    /**
     * 电站详情---终端列表（微信）
     *
     * @param chargingStationId 站点id
     * @return
     */
    @GetMapping(value = "/getWXXhpcTerminalMassage")
    public AjaxResult getWXXhpcTerminalMassage(@RequestParam Long chargingStationId) {

        return AjaxResult.success(xhpcChargingStationService.getWXXhpcTerminalMassage(chargingStationId));
    }

    /**
     * 通过终端编号进入小程序开始充电页面
     */
    @GetMapping(value = "/getWXpNumMessage")
    public AjaxResult getWXpNumMessage(@RequestParam(value = "pNum") String pNum) {
        return xhpcTerminalService.getWXpNumMessage(pNum);
    }


    @GetMapping(value = "/getPlaceholderTimeMassage")
    public AjaxResult getPlaceholderTimeMassage(@RequestParam Long chargingStationId) {

        return AjaxResult.success(xhpcChargingStationService.getPlaceholderTimeMassage(chargingStationId));
    }


    @GetMapping(value = "/getReis")
    public AjaxResult getReis(String serialNumber,Integer voltageUpperLimits,Integer currentLimit) {
        Map<String, Object> pileDataModel = redisService.getCacheMap("pile:" + serialNumber);
        pileDataModel.put("voltageUpperLimits",voltageUpperLimits);
        pileDataModel.put("currentLimit",currentLimit);
        redisService.setCacheMap("pile:" + serialNumber,pileDataModel);
        return AjaxResult.success();
    }
}
