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

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.stateownedreformlawinfo.vo.*;
import com.cy.guoyan.admin.module.guoyan.dal.dataobject.stateownedreformlawinfo.StateOwnedReformLawInfoDO;
import com.cy.guoyan.admin.module.guoyan.service.stateownedreformlawinfo.StateOwnedReformLawInfoService;

@Tag(name = "管理后台 - 国企改革法规信息")
@RestController
@RequestMapping("/guoyan/state-owned-reform-law-info")
@Validated
public class StateOwnedReformLawInfoController {

    @Resource
    private StateOwnedReformLawInfoService stateOwnedReformLawInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建国企改革法规信息")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:create')")
    public CommonResult<Long> createStateOwnedReformLawInfo(@Valid @RequestBody StateOwnedReformLawInfoSaveReqVO createReqVO) {
        return success(stateOwnedReformLawInfoService.createStateOwnedReformLawInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新国企改革法规信息")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:update')")
    public CommonResult<Boolean> updateStateOwnedReformLawInfo(@Valid @RequestBody StateOwnedReformLawInfoSaveReqVO updateReqVO) {
        stateOwnedReformLawInfoService.updateStateOwnedReformLawInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除国企改革法规信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:delete')")
    public CommonResult<Boolean> deleteStateOwnedReformLawInfo(@RequestParam("id") Long id) {
        stateOwnedReformLawInfoService.deleteStateOwnedReformLawInfo(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除国企改革法规信息")
                @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:delete')")
    public CommonResult<Boolean> deleteStateOwnedReformLawInfoList(@RequestParam("ids") List<Long> ids) {
        stateOwnedReformLawInfoService.deleteStateOwnedReformLawInfoListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得国企改革法规信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:query')")
    public CommonResult<StateOwnedReformLawInfoRespVO> getStateOwnedReformLawInfo(@RequestParam("id") Long id) {
        StateOwnedReformLawInfoRespVO stateOwnedReformLawInfo = stateOwnedReformLawInfoService.getStateOwnedReformLawInfo(id);
        return success(stateOwnedReformLawInfo);
    }

    @GetMapping("/page")
    @Operation(summary = "获得国企改革法规信息分页")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:query')")
    public CommonResult<PageResult<StateOwnedReformLawInfoRespVO>> getStateOwnedReformLawInfoPage(@Valid StateOwnedReformLawInfoPageReqVO pageReqVO) {
        PageResult<StateOwnedReformLawInfoDO> pageResult = stateOwnedReformLawInfoService.getStateOwnedReformLawInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, StateOwnedReformLawInfoRespVO.class));
    }

//    @GetMapping("/list")
//    @Operation(summary = "获得国企改革法规信息列表")
//    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:query')")
//    public CommonResult<List<StateOwnedReformLawInfoRespVO>> getStateOwnedReformLawInfoList(@Valid StateOwnedReformLawInfoPageReqVO pageReqVO) {
//        List<StateOwnedReformLawInfoDO> pageResult = stateOwnedReformLawInfoService.getStateOwnedReformLawInfoList(pageReqVO);
//        return success(BeanUtils.toBean(pageResult, StateOwnedReformLawInfoRespVO.class));
//    }

    @PutMapping("/audit")
    @Operation(summary = "审核国企改革法规信息")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:update')")
    public CommonResult<Boolean> auditResearchTopicInfo(@RequestBody StateOwnedReformLawInfoSaveReqVO updateReqVO) {
        stateOwnedReformLawInfoService.auditStateOwnedReformLawInfo(updateReqVO.getId(), updateReqVO.getAuditStatus());
        return success(true);
    }

    @PutMapping("/void")
    @Operation(summary = "作废国企改革法规信息")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:update')")
    public CommonResult<Boolean> voidResearchTopicInfo(@RequestBody StateOwnedReformLawInfoSaveReqVO updateReqVO) {
        stateOwnedReformLawInfoService.voidStateOwnedReformLawInfo(updateReqVO.getId(), updateReqVO.getStatus());
        return success(true);
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出国企改革法规信息 Excel")
    @PreAuthorize("@ss.hasPermission('guoyan:state-owned-reform-law-info:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportStateOwnedReformLawInfoExcel(@Valid StateOwnedReformLawInfoPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<StateOwnedReformLawInfoDO> list = stateOwnedReformLawInfoService.getStateOwnedReformLawInfoPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "国企改革法规信息.xls", "数据", StateOwnedReformLawInfoRespVO.class,
                        BeanUtils.toBean(list, StateOwnedReformLawInfoRespVO.class));
    }

}