package cn.iocoder.byzs.module.bjdx.controller.admin.reportmanage;

import cn.iocoder.byzs.module.bjdx.controller.admin.reportmanage.vo.ReportManagePageReqVO;
import cn.iocoder.byzs.module.bjdx.controller.admin.reportmanage.vo.ReportManageRespVO;
import cn.iocoder.byzs.module.bjdx.controller.admin.reportmanage.vo.ReportManageSaveReqVO;
import org.springframework.web.bind.annotation.*;
import jakarta.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 jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.byzs.framework.common.pojo.PageParam;
import cn.iocoder.byzs.framework.common.pojo.PageResult;
import cn.iocoder.byzs.framework.common.pojo.CommonResult;
import cn.iocoder.byzs.framework.common.util.object.BeanUtils;
import static cn.iocoder.byzs.framework.common.pojo.CommonResult.success;

import cn.iocoder.byzs.framework.excel.core.util.ExcelUtils;

import cn.iocoder.byzs.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.byzs.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.byzs.module.bjdx.dal.dataobject.reportmanage.ReportManageDO;
import cn.iocoder.byzs.module.bjdx.service.reportmanage.ReportManageService;

@Tag(name = "管理后台 - 评估报告-评语")
@RestController
@RequestMapping("/bjdxReport/manage")
@Validated
public class ReportManageController {

    @Resource
    private ReportManageService manageService;

    @PostMapping("/create")
    @Operation(summary = "创建评估报告-评语")
    @PreAuthorize("@ss.hasPermission('report:manage:create')")
    public CommonResult<Long> createManage(@Valid @RequestBody ReportManageSaveReqVO createReqVO) {
        return success(manageService.createManage(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新评估报告-评语")
    @PreAuthorize("@ss.hasPermission('report:manage:update')")
    public CommonResult<Boolean> updateManage(@Valid @RequestBody ReportManageSaveReqVO updateReqVO) {
        manageService.updateManage(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除评估报告-评语")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('report:manage:delete')")
    public CommonResult<Boolean> deleteManage(@RequestParam("id") Long id) {
        manageService.deleteManage(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除评估报告-评语")
                @PreAuthorize("@ss.hasPermission('report:manage:delete')")
    public CommonResult<Boolean> deleteManageList(@RequestParam("ids") List<Long> ids) {
        manageService.deleteManageListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得评估报告-评语")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('report:manage:query')")
    public CommonResult<ReportManageRespVO> getManage(@RequestParam("id") Long id) {
        ReportManageDO manage = manageService.getManage(id);
        return success(BeanUtils.toBean(manage, ReportManageRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得评估报告-评语分页")
    @PreAuthorize("@ss.hasPermission('report:manage:query')")
    public CommonResult<PageResult<ReportManageRespVO>> getManagePage(@Valid ReportManagePageReqVO pageReqVO) {
        PageResult<ReportManageDO> pageResult = manageService.getManagePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ReportManageRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出评估报告-评语 Excel")
    @PreAuthorize("@ss.hasPermission('report:manage:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportManageExcel(@Valid ReportManagePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ReportManageDO> list = manageService.getManagePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "评估报告-评语.xls", "数据", ReportManageRespVO.class,
                        BeanUtils.toBean(list, ReportManageRespVO.class));
    }

}