package com.cmvr.web.controller.system;

import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.core.page.TableDataInfo;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.system.domain.SysVehOperConfig;
import com.cmvr.system.service.ISysVehOperConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 车机操作配置
 *
 * @author cmvr-iot
 */
@Api(tags = "车机操作配置")
@RestController
@RequestMapping("/system/vehOper")
@RequiredArgsConstructor
public class SysVehOperConfigController extends BaseController {

    private final ISysVehOperConfigService sysVehOperConfigService;

    @ApiOperation("获取车机操作配置列表")
    @PreAuthorize("@ss.hasPermi('system:vehOper:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVehOperConfig config) {
        startPage();
        List<SysVehOperConfig> list = sysVehOperConfigService.selectSysVehOperConfigList(config);
        return getDataTable(list);
    }

    @ApiOperation("根据参数编号获取详细信息")
    @PreAuthorize("@ss.hasPermi('system:vehOper:query')")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable Long configId) {
        return success(sysVehOperConfigService.selectSysVehOperConfigById(configId));
    }

    @ApiOperation("新增参数配置")
    @PreAuthorize("@ss.hasPermi('system:vehOper:add')")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysVehOperConfig config) {
        return toAjax(sysVehOperConfigService.insertVehOperConfig(config));
    }

    @ApiOperation("修改参数配置")
    @PreAuthorize("@ss.hasPermi('system:vehOper:edit')")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysVehOperConfig config) {
        return toAjax(sysVehOperConfigService.updateVehOperConfig(config));
    }

    @ApiOperation("删除参数配置")
    @PreAuthorize("@ss.hasPermi('system:vehOper:remove')")
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds) {
        return success(sysVehOperConfigService.deleteVehOperConfigByIds(configIds));
    }
}
