package com.xhpc.pp.controller;

import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.redis.CacheRateModel;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
public class StationController {

    @PostMapping("station/rateModel/{stationId}/{rateModelId}")
    public Object setStationRateModel(@PathVariable Long stationId, @PathVariable Long rateModelId, @RequestBody CacheRateModel rateModel) {

        String skey = "station:".concat(stationId.toString());
        ChargingStationDto cacheStation = REDIS.getCacheObject(skey);
        if (cacheStation==null) cacheStation = new ChargingStationDto();
        cacheStation.setRateModelId(rateModelId);
        REDIS.setCacheObject(skey, cacheStation);
        String rkey = "rateModel:".concat(rateModelId.toString());
        REDIS.setCacheObject(rkey, rateModel);
        return R.ok();
    }

}
