package com.xhpc.charging.station.controller;

import com.xhpc.charging.station.service.IXhpcTimingChargingPowerService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.domain.XhpcTimingChargingPowerModel;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/timingChargingPower")
public class XhpcTimingChargingPowerController extends BaseController {


    @Resource
    private IXhpcTimingChargingPowerService xhpcTimingChargingPowerService;


    @GetMapping("/list")
    public TableDataInfo list(HttpServletRequest request, String tenantId, Long operatorId, String reason, Integer status, String startTime, String endTime, Long chargingStationId, String endSatrtTime, String endEndTime,Integer type) {
        startPage();
        List<Map<String, Object>> list = xhpcTimingChargingPowerService.list(request,tenantId,operatorId,reason, status, startTime,endTime, chargingStationId,endSatrtTime,endEndTime,type);
        return getDataTable(list);
    }


    /**
     * 添加定时功率调整
     * @param xhpcTimingChargingPowerModel
     * @return
     */
    @Log(title = "添加定时功率调整", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addXhpcTimingChargingPowerModel")
    public R addXhpcTimingChargingModel(HttpServletRequest request, @RequestBody XhpcTimingChargingPowerModel xhpcTimingChargingPowerModel) {
        return xhpcTimingChargingPowerService.addXhpcTimingChargingPowerModel(request,xhpcTimingChargingPowerModel);
    }

    /**
     * 删除
     */
    @Log(title = "删除", businessType = BusinessType.UPDATE)
    @DeleteMapping("/{timingChargingPowerId}")
    public R updateXhpcTimingChargingModel(@PathVariable Long timingChargingPowerId) {
        return xhpcTimingChargingPowerService.updateXhpcTimingChargingPowerModel(timingChargingPowerId);
    }

    /**
     * 详情
     *
     * @return
     */
    @GetMapping(value = "/getXhpcTimingChargingPowerModelMessage")
    public R getXhpcTimingChargingPowerModelMessage(Long timingChargingPowerId) {
        return xhpcTimingChargingPowerService.getXhpcTimingChargingPowerModelMessage(timingChargingPowerId);
    }


    /**
     * 编辑定时计费模型
     * @param xhpcTimingChargingPowerModel
     * @return
     */
    @Log(title = "编辑定时功率调整", businessType = BusinessType.INSERT)
    @PostMapping(value = "/updateXhpcTimingChargingPowerModel")
    public R updateXhpcTimingChargingPowerModel(HttpServletRequest request, @RequestBody XhpcTimingChargingPowerModel xhpcTimingChargingPowerModel) {
        return xhpcTimingChargingPowerService.addXhpcTimingChargingPowerModel(request,xhpcTimingChargingPowerModel);
    }

    /**
     * 每30秒执行一次
     */
    @Scheduled(cron = "0/30 * * * * ?")
    @PostMapping(value = "/getXhpcTimingChargingPowerModelCron")
    public void getXhpcTimingChargingPowerModelCron(){
        xhpcTimingChargingPowerService.getXhpcTimingChargingPowerModelCron();
    }

}
