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

import com.cy.guoyan.admin.module.guoyan.controller.admin.researchtopicinfo.vo.ResearchTopicInfoSaveReqVO;
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.stateownedreformbestpracticeinfo.vo.*;
import com.cy.guoyan.admin.module.guoyan.dal.dataobject.stateownedreformbestpracticeinfo.StateOwnedReformBestPracticeInfoDO;
import com.cy.guoyan.admin.module.guoyan.service.stateownedreformbestpracticeinfo.StateOwnedReformBestPracticeInfoService;

@Tag(name = "管理后台 - 国资改革最佳实践数据信息")
@RestController
@RequestMapping("/guoyan/state-owned-reform-best-practice-info")
@Validated
public class StateOwnedReformBestPracticeInfoController {

    @Resource
    private StateOwnedReformBestPracticeInfoService stateOwnedReformBestPracticeInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建国资改革最佳实践数据信息")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-info:create')")
    public CommonResult<Long> createStateOwnedReformBestPracticeInfo(@Valid @RequestBody StateOwnedReformBestPracticeInfoSaveReqVO createReqVO) {
        return success(stateOwnedReformBestPracticeInfoService.createStateOwnedReformBestPracticeInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新国资改革最佳实践数据信息")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-info:update')")
    public CommonResult<Boolean> updateStateOwnedReformBestPracticeInfo(@Valid @RequestBody StateOwnedReformBestPracticeInfoSaveReqVO updateReqVO) {
        stateOwnedReformBestPracticeInfoService.updateStateOwnedReformBestPracticeInfo(updateReqVO);
        return success(true);
    }

    @PutMapping("/audit")
    @Operation(summary = "审核国资改革最佳实践数据信息")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-info:update')")
    public CommonResult<Boolean> auditStateOwnedReformBestPracticeInfo(@RequestBody StateOwnedReformBestPracticeInfoSaveReqVO updateReqVO) {
        stateOwnedReformBestPracticeInfoService.auditStateOwnedReformBestPracticeInfo(updateReqVO.getId(), updateReqVO.getAuditStatus());
        return success(true);
    }

    @PutMapping("/void")
    @Operation(summary = "作废国资改革最佳实践数据信息")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-info:update')")
    public CommonResult<Boolean> voidStateOwnedReformBestPracticeInfo(@RequestBody StateOwnedReformBestPracticeInfoSaveReqVO updateReqVO) {
        stateOwnedReformBestPracticeInfoService.voidStateOwnedReformBestPracticeInfo(updateReqVO.getId(), updateReqVO.getStatus());
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除国资改革最佳实践数据信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-info:delete')")
    public CommonResult<Boolean> deleteStateOwnedReformBestPracticeInfo(@RequestParam("id") Long id) {
        stateOwnedReformBestPracticeInfoService.deleteStateOwnedReformBestPracticeInfo(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除国资改革最佳实践数据信息")
                @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-info:delete')")
    public CommonResult<Boolean> deleteStateOwnedReformBestPracticeInfoList(@RequestParam("ids") List<Long> ids) {
        stateOwnedReformBestPracticeInfoService.deleteStateOwnedReformBestPracticeInfoListByIds(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-info:query')")
    public CommonResult<StateOwnedReformBestPracticeInfoRespVO> getStateOwnedReformBestPracticeInfo(@RequestParam("id") Long id) {
        StateOwnedReformBestPracticeInfoRespVO stateOwnedReformBestPracticeInfo = stateOwnedReformBestPracticeInfoService.getStateOwnedReformBestPracticeInfo(id);
        return success(stateOwnedReformBestPracticeInfo);
    }

    @GetMapping("/page")
    @Operation(summary = "获得国资改革最佳实践数据信息分页")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-info:query')")
    public CommonResult<PageResult<StateOwnedReformBestPracticeInfoRespVO>> getStateOwnedReformBestPracticeInfoPage(@Valid StateOwnedReformBestPracticeInfoPageReqVO pageReqVO) {
        PageResult<StateOwnedReformBestPracticeInfoDO> pageResult = stateOwnedReformBestPracticeInfoService.getStateOwnedReformBestPracticeInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, StateOwnedReformBestPracticeInfoRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出国资改革最佳实践数据信息 Excel")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-best-practice-info:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportStateOwnedReformBestPracticeInfoExcel(@Valid StateOwnedReformBestPracticeInfoPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<StateOwnedReformBestPracticeInfoDO> list = stateOwnedReformBestPracticeInfoService.getStateOwnedReformBestPracticeInfoPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "国资改革最佳实践数据信息.xls", "数据", StateOwnedReformBestPracticeInfoRespVO.class,
                        BeanUtils.toBean(list, StateOwnedReformBestPracticeInfoRespVO.class));
    }

}