package com.xhpc.charging.station.controller;

import com.xhpc.charging.station.service.IXhpcBarrierGateService;
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.XhpcBarrierGate;
import com.xhpc.common.domain.XhpcEquipmentAccident;
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("/barrierGate")
public class XhpcBarrierGateController extends BaseController {

    @Resource
    private IXhpcBarrierGateService xhpcBarrierGateService;

    @GetMapping("/getBarrierGateList")
    public R getBarrierGateList(){
        return xhpcBarrierGateService.getBarrierGateList();
    }

    @GetMapping("/list")
    public TableDataInfo list(String barrierGateCompany, String chargingStationNumber) {
        List<Map<String, Object>> list = xhpcBarrierGateService.getLsit(barrierGateCompany,chargingStationNumber);
        return getDataTable(list);
    }

    @PostMapping(value = "/addBarrierGate")
    public R addXhpcEquipmentAccident(@RequestBody XhpcBarrierGate xhpcBarrierGate) {
        return xhpcBarrierGateService.insertBarrierGate(xhpcBarrierGate);
    }

    @PostMapping(value = "/updateBarrierGate")
    public R updateBarrierGate(@RequestBody XhpcBarrierGate xhpcBarrierGate) {
        return xhpcBarrierGateService.updateBarrierGate(xhpcBarrierGate);
    }

    @Log(title = "删除道闸", businessType = BusinessType.DELETE)
    @GetMapping("/deleteBarrierGateById")
    public R deleteBarrierGateById(Long barrierGateId) {
        return xhpcBarrierGateService.deleteBarrierGateById(barrierGateId);
    }

    @GetMapping("/getXhpcBarrierGateById")
    public R getXhpcBarrierGateById(Long barrierGateId) {
        Map<String, Object> map = xhpcBarrierGateService.getXhpcBarrierGateById(barrierGateId);
        return R.ok(map);
    }

    /**
     * 定时任务时间
     */
    @Scheduled(cron = "0 0 12 * * ? ")
    @GetMapping("/getEndTimeExpire")
    public void getEndTimeExpire(){
        xhpcBarrierGateService.getEndTimeExpire();
    }
}
