package com.cy.guoyan.admin.module.guoyan.controller.admin.stateownedreformbestpracticecategory;

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

import com.cy.guoyan.admin.framework.excel.core.util.ExcelUtils;

import com.cy.guoyan.admin.framework.apilog.core.annotation.ApiAccessLog;
import static com.cy.guoyan.admin.framework.apilog.core.enums.OperateTypeEnum.*;

import com.cy.guoyan.admin.module.guoyan.controller.admin.stateownedreformbestpracticecategory.vo.*;
import com.cy.guoyan.admin.module.guoyan.dal.dataobject.stateownedreformbestpracticecategory.StateOwnedReformBestPracticeCategoryDO;
import com.cy.guoyan.admin.module.guoyan.service.stateownedreformbestpracticecategory.StateOwnedReformBestPracticeCategoryService;

@Tag(name = "管理后台 - 国资改革最佳实践主题分类")
@RestController
@RequestMapping("/guoyan/state-owned-reform-best-practice-category")
@Validated
public class StateOwnedReformBestPracticeCategoryController {

    @Resource
    private StateOwnedReformBestPracticeCategoryService stateOwnedReformBestPracticeCategoryService;

    @PostMapping("/create")
    @Operation(summary = "创建国资改革最佳实践主题分类")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-category:create')")
    public CommonResult<Long> createStateOwnedReformBestPracticeCategory(@Valid @RequestBody StateOwnedReformBestPracticeCategorySaveReqVO createReqVO) {
        return success(stateOwnedReformBestPracticeCategoryService.createStateOwnedReformBestPracticeCategory(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新国资改革最佳实践主题分类")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-category:update')")
    public CommonResult<Boolean> updateStateOwnedReformBestPracticeCategory(@Valid @RequestBody StateOwnedReformBestPracticeCategorySaveReqVO updateReqVO) {
        stateOwnedReformBestPracticeCategoryService.updateStateOwnedReformBestPracticeCategory(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除国资改革最佳实践主题分类")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-category:delete')")
    public CommonResult<Boolean> deleteStateOwnedReformBestPracticeCategory(@RequestParam("id") Long id) {
        stateOwnedReformBestPracticeCategoryService.deleteStateOwnedReformBestPracticeCategory(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除国资改革最佳实践主题分类")
                @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-category:delete')")
    public CommonResult<Boolean> deleteStateOwnedReformBestPracticeCategoryList(@RequestParam("ids") List<Long> ids) {
        stateOwnedReformBestPracticeCategoryService.deleteStateOwnedReformBestPracticeCategoryListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得国资改革最佳实践主题分类")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-category:query')")
    public CommonResult<StateOwnedReformBestPracticeCategoryRespVO> getStateOwnedReformBestPracticeCategory(@RequestParam("id") Long id) {
        StateOwnedReformBestPracticeCategoryDO stateOwnedReformBestPracticeCategory = stateOwnedReformBestPracticeCategoryService.getStateOwnedReformBestPracticeCategory(id);
        return success(BeanUtils.toBean(stateOwnedReformBestPracticeCategory, StateOwnedReformBestPracticeCategoryRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得国资改革最佳实践主题分类分页")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-category:query')")
    public CommonResult<PageResult<StateOwnedReformBestPracticeCategoryRespVO>> getStateOwnedReformBestPracticeCategoryPage(@Valid StateOwnedReformBestPracticeCategoryPageReqVO pageReqVO) {
        PageResult<StateOwnedReformBestPracticeCategoryDO> pageResult = stateOwnedReformBestPracticeCategoryService.getStateOwnedReformBestPracticeCategoryPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, StateOwnedReformBestPracticeCategoryRespVO.class));
    }

    @GetMapping("/tree")
    @Operation(summary = "获得国资改革最佳实践主题分类树")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-category:query')")
    public CommonResult<List<StateOwnedReformBestPracticeCategoryTreeVO>> getStateOwnedReformBestPracticeCategoryTree(@Valid StateOwnedReformBestPracticeCategoryPageReqVO pageReqVO) {
        List<StateOwnedReformBestPracticeCategoryDO> pageResult = stateOwnedReformBestPracticeCategoryService.getStateOwnedReformBestPracticeCategoryTree(pageReqVO);
        return success(BeanUtils.toBean(pageResult, StateOwnedReformBestPracticeCategoryTreeVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出国资改革最佳实践主题分类 Excel")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-category:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportStateOwnedReformBestPracticeCategoryExcel(@Valid StateOwnedReformBestPracticeCategoryPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<StateOwnedReformBestPracticeCategoryDO> list = stateOwnedReformBestPracticeCategoryService.getStateOwnedReformBestPracticeCategoryPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "国资改革最佳实践主题分类.xls", "数据", StateOwnedReformBestPracticeCategoryRespVO.class,
                        BeanUtils.toBean(list, StateOwnedReformBestPracticeCategoryRespVO.class));
    }

}