package com.yc.ship.module.resource.controller.admin.routelight;

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 com.yc.ship.framework.common.pojo.PageParam;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.framework.common.util.object.BeanUtils;
import static com.yc.ship.framework.common.pojo.CommonResult.success;

import com.yc.ship.framework.excel.core.util.ExcelUtils;

import com.yc.ship.framework.apilog.core.annotation.ApiAccessLog;
import static com.yc.ship.framework.apilog.core.enums.OperateTypeEnum.*;

import com.yc.ship.module.resource.controller.admin.routelight.vo.*;
import com.yc.ship.module.resource.dal.dataobject.routelight.ResourceRouteLightDO;
import com.yc.ship.module.resource.service.routelight.ResourceRouteLightService;

@Tag(name = "管理后台 - 航线管理-行程亮点")
@RestController
@RequestMapping("/resource/route-light")
@Validated
public class ResourceRouteLightController {

    @Resource
    private ResourceRouteLightService routeLightService;

    @PostMapping("/create")
    @Operation(summary = "创建航线管理-行程亮点")
    @PreAuthorize("@ss.hasPermission('resource:route-light:create')")
    public CommonResult<Long> createRouteLight(@Valid @RequestBody ResourceRouteLightSaveReqVO createReqVO) {
        return success(routeLightService.createRouteLight(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新航线管理-行程亮点")
    @PreAuthorize("@ss.hasPermission('resource:route-light:update')")
    public CommonResult<Boolean> updateRouteLight(@Valid @RequestBody ResourceRouteLightSaveReqVO updateReqVO) {
        routeLightService.updateRouteLight(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除航线管理-行程亮点")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('resource:route-light:delete')")
    public CommonResult<Boolean> deleteRouteLight(@RequestParam("id") Long id) {
        routeLightService.deleteRouteLight(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得航线管理-行程亮点")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('resource:route-light:query')")
    public CommonResult<ResourceRouteLightRespVO> getRouteLight(@RequestParam("id") Long id) {
        ResourceRouteLightDO routeLight = routeLightService.getRouteLight(id);
        return success(BeanUtils.toBean(routeLight, ResourceRouteLightRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得航线管理-行程亮点分页")
    @PreAuthorize("@ss.hasPermission('resource:route-light:query')")
    public CommonResult<PageResult<ResourceRouteLightRespVO>> getRouteLightPage(@Valid ResourceRouteLightPageReqVO pageReqVO) {
        PageResult<ResourceRouteLightDO> pageResult = routeLightService.getRouteLightPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ResourceRouteLightRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出航线管理-行程亮点 Excel")
    @PreAuthorize("@ss.hasPermission('resource:route-light:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportRouteLightExcel(@Valid ResourceRouteLightPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ResourceRouteLightDO> list = routeLightService.getRouteLightPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "航线管理-行程亮点.xls", "数据", ResourceRouteLightRespVO.class,
                        BeanUtils.toBean(list, ResourceRouteLightRespVO.class));
    }

}