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

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.routetripdetail.vo.*;
import com.yc.ship.module.resource.dal.dataobject.routetripdetail.ResourceRouteTripDetailDO;
import com.yc.ship.module.resource.service.routetripdetail.ResourceRouteTripDetailService;

@Tag(name = "管理后台 - 资源管理-航线行程详细")
@RestController
@RequestMapping("/resource/route-trip-detail")
@Validated
public class ResourceRouteTripDetailController {

    @Resource
    private ResourceRouteTripDetailService routeTripDetailService;

    @PostMapping("/create")
    @Operation(summary = "创建资源管理-航线行程详细")
    @PreAuthorize("@ss.hasPermission('resource:route-trip-detail:create')")
    public CommonResult<Long> createRouteTripDetail(@Valid @RequestBody ResourceRouteTripDetailSaveReqVO createReqVO) {
        return success(routeTripDetailService.createRouteTripDetail(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新资源管理-航线行程详细")
    @PreAuthorize("@ss.hasPermission('resource:route-trip-detail:update')")
    public CommonResult<Boolean> updateRouteTripDetail(@Valid @RequestBody ResourceRouteTripDetailSaveReqVO updateReqVO) {
        routeTripDetailService.updateRouteTripDetail(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除资源管理-航线行程详细")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('resource:route-trip-detail:delete')")
    public CommonResult<Boolean> deleteRouteTripDetail(@RequestParam("id") Long id) {
        routeTripDetailService.deleteRouteTripDetail(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得资源管理-航线行程详细")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('resource:route-trip-detail:query')")
    public CommonResult<ResourceRouteTripDetailRespVO> getRouteTripDetail(@RequestParam("id") Long id) {
        ResourceRouteTripDetailDO routeTripDetail = routeTripDetailService.getRouteTripDetail(id);
        return success(BeanUtils.toBean(routeTripDetail, ResourceRouteTripDetailRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得资源管理-航线行程详细分页")
    @PreAuthorize("@ss.hasPermission('resource:route-trip-detail:query')")
    public CommonResult<PageResult<ResourceRouteTripDetailRespVO>> getRouteTripDetailPage(@Valid ResourceRouteTripDetailPageReqVO pageReqVO) {
        PageResult<ResourceRouteTripDetailDO> pageResult = routeTripDetailService.getRouteTripDetailPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ResourceRouteTripDetailRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出资源管理-航线行程详细 Excel")
    @PreAuthorize("@ss.hasPermission('resource:route-trip-detail:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportRouteTripDetailExcel(@Valid ResourceRouteTripDetailPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ResourceRouteTripDetailDO> list = routeTripDetailService.getRouteTripDetailPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "资源管理-航线行程详细.xls", "数据", ResourceRouteTripDetailRespVO.class,
                        BeanUtils.toBean(list, ResourceRouteTripDetailRespVO.class));
    }

}