package cn.iocoder.yudao.module.system.controller.admin.remote;

import cn.iocoder.yudao.module.system.controller.admin.remote.vo.RobotMaxSpeedPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.remote.vo.RobotMaxSpeedRespVO;
import cn.iocoder.yudao.module.system.controller.admin.remote.vo.RobotMaxSpeedSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.remote.RobotMaxSpeedDO;
import cn.iocoder.yudao.module.system.service.remote.RobotMaxSpeedService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - 远遥车辆最大速度")
@RestController
@RequestMapping("/system/remote/robot-max-speed")
@Validated
public class RobotMaxSpeedController {

    @Resource
    private RobotMaxSpeedService robotMaxSpeedService;

    @PostMapping("/create")
    @Operation(summary = "创建远遥车辆最大速度")
    @PreAuthorize("@ss.hasPermission('remote:robot-max-speed:create')")
    public CommonResult<Long> createRobotMaxSpeed(@Valid @RequestBody RobotMaxSpeedSaveReqVO createReqVO) {
        return success(robotMaxSpeedService.createRobotMaxSpeed(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新远遥车辆最大速度")
    @PreAuthorize("@ss.hasPermission('remote:robot-max-speed:update')")
    public CommonResult<Boolean> updateRobotMaxSpeed(@Valid @RequestBody RobotMaxSpeedSaveReqVO updateReqVO) {
        robotMaxSpeedService.updateRobotMaxSpeed(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除远遥车辆最大速度")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('remote:robot-max-speed:delete')")
    public CommonResult<Boolean> deleteRobotMaxSpeed(@RequestParam("id") Long id) {
        robotMaxSpeedService.deleteRobotMaxSpeed(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得远遥车辆最大速度")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('remote:robot-max-speed:query')")
    public CommonResult<RobotMaxSpeedRespVO> getRobotMaxSpeed(@RequestParam("id") Long id) {
        RobotMaxSpeedDO robotMaxSpeed = robotMaxSpeedService.getRobotMaxSpeed(id);
        return success(BeanUtils.toBean(robotMaxSpeed, RobotMaxSpeedRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得远遥车辆最大速度分页")
    @PreAuthorize("@ss.hasPermission('remote:robot-max-speed:query')")
    public CommonResult<PageResult<RobotMaxSpeedRespVO>> getRobotMaxSpeedPage(@Valid RobotMaxSpeedPageReqVO pageReqVO) {
        PageResult<RobotMaxSpeedDO> pageResult = robotMaxSpeedService.getRobotMaxSpeedPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, RobotMaxSpeedRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出远遥车辆最大速度 Excel")
    @PreAuthorize("@ss.hasPermission('remote:robot-max-speed:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportRobotMaxSpeedExcel(@Valid RobotMaxSpeedPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<RobotMaxSpeedDO> list = robotMaxSpeedService.getRobotMaxSpeedPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "远遥车辆最大速度.xls", "数据", RobotMaxSpeedRespVO.class,
                        BeanUtils.toBean(list, RobotMaxSpeedRespVO.class));
    }

}