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

import cn.iocoder.yudao.module.system.controller.admin.wait.vo.MoveToWaitPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.wait.vo.MoveToWaitRespVO;
import cn.iocoder.yudao.module.system.controller.admin.wait.vo.MoveToWaitSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.wait.MoveToWaitDO;
import cn.iocoder.yudao.module.system.service.wait.MoveToWaitService;
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.constraints.*;
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("/wait/move-to-wait")
@Validated
public class MoveToWaitController {

    @Resource
    private MoveToWaitService moveToWaitService;

    @PostMapping("/create")
    @Operation(summary = "创建车辆前往等待点记录")
    @PreAuthorize("@ss.hasPermission('wait:move-to-wait:create')")
    public CommonResult<Long> createMoveToWait(@Valid @RequestBody MoveToWaitSaveReqVO createReqVO) {
        return success(moveToWaitService.createMoveToWait(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新车辆前往等待点记录")
    @PreAuthorize("@ss.hasPermission('wait:move-to-wait:update')")
    public CommonResult<Boolean> updateMoveToWait(@Valid @RequestBody MoveToWaitSaveReqVO updateReqVO) {
        moveToWaitService.updateMoveToWait(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除车辆前往等待点记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wait:move-to-wait:delete')")
    public CommonResult<Boolean> deleteMoveToWait(@RequestParam("id") Long id) {
        moveToWaitService.deleteMoveToWait(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得车辆前往等待点记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wait:move-to-wait:query')")
    public CommonResult<MoveToWaitRespVO> getMoveToWait(@RequestParam("id") Long id) {
        MoveToWaitDO moveToWait = moveToWaitService.getMoveToWait(id);
        return success(BeanUtils.toBean(moveToWait, MoveToWaitRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得车辆前往等待点记录分页")
    @PreAuthorize("@ss.hasPermission('wait:move-to-wait:query')")
    public CommonResult<PageResult<MoveToWaitRespVO>> getMoveToWaitPage(@Valid MoveToWaitPageReqVO pageReqVO) {
        PageResult<MoveToWaitDO> pageResult = moveToWaitService.getMoveToWaitPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MoveToWaitRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出车辆前往等待点记录 Excel")
    @PreAuthorize("@ss.hasPermission('wait:move-to-wait:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportMoveToWaitExcel(@Valid MoveToWaitPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<MoveToWaitDO> list = moveToWaitService.getMoveToWaitPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "车辆前往等待点记录.xls", "数据", MoveToWaitRespVO.class,
                        BeanUtils.toBean(list, MoveToWaitRespVO.class));
    }

}