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

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.constraints.*;
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.controller.admin.questionnaireresultdetails.vo.*;
import cn.iocoder.byzs.module.bjdx.dal.dataobject.questionnaireresultdetails.QuestionnaireResultDetailsDO;
import cn.iocoder.byzs.module.bjdx.service.questionnaireresultdetails.QuestionnaireResultDetailsService;

@Tag(name = "管理后台 - 北京大学-问卷结果-详情")
@RestController
@RequestMapping("/bjdxResult/questionnaire-result-details")
@Validated
public class QuestionnaireResultDetailsController {

    @Resource
    private QuestionnaireResultDetailsService questionnaireResultDetailsService;

    @PostMapping("/create")
    @Operation(summary = "创建北京大学-问卷结果-详情")
    @PreAuthorize("@ss.hasPermission('bjdxResult:questionnaire-result-details:create')")
    public CommonResult<Long> createQuestionnaireResultDetails(@Valid @RequestBody QuestionnaireResultDetailsSaveReqVO createReqVO) {
        return success(questionnaireResultDetailsService.createQuestionnaireResultDetails(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新北京大学-问卷结果-详情")
    @PreAuthorize("@ss.hasPermission('bjdxResult:questionnaire-result-details:update')")
    public CommonResult<Boolean> updateQuestionnaireResultDetails(@Valid @RequestBody QuestionnaireResultDetailsSaveReqVO updateReqVO) {
        questionnaireResultDetailsService.updateQuestionnaireResultDetails(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除北京大学-问卷结果-详情")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('bjdxResult:questionnaire-result-details:delete')")
    public CommonResult<Boolean> deleteQuestionnaireResultDetails(@RequestParam("id") Long id) {
        questionnaireResultDetailsService.deleteQuestionnaireResultDetails(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除北京大学-问卷结果-详情")
                @PreAuthorize("@ss.hasPermission('bjdxResult:questionnaire-result-details:delete')")
    public CommonResult<Boolean> deleteQuestionnaireResultDetailsList(@RequestParam("ids") List<Long> ids) {
        questionnaireResultDetailsService.deleteQuestionnaireResultDetailsListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得北京大学-问卷结果-详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('bjdxResult:questionnaire-result-details:query')")
    public CommonResult<QuestionnaireResultDetailsRespVO> getQuestionnaireResultDetails(@RequestParam("id") Long id) {
        QuestionnaireResultDetailsDO questionnaireResultDetails = questionnaireResultDetailsService.getQuestionnaireResultDetails(id);
        return success(BeanUtils.toBean(questionnaireResultDetails, QuestionnaireResultDetailsRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得北京大学-问卷结果-详情分页")
    @PreAuthorize("@ss.hasPermission('bjdxResult:questionnaire-result-details:query')")
    public CommonResult<PageResult<QuestionnaireResultDetailsRespVO>> getQuestionnaireResultDetailsPage(@Valid QuestionnaireResultDetailsPageReqVO pageReqVO) {
        PageResult<QuestionnaireResultDetailsDO> pageResult = questionnaireResultDetailsService.getQuestionnaireResultDetailsPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, QuestionnaireResultDetailsRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出北京大学-问卷结果-详情 Excel")
    @PreAuthorize("@ss.hasPermission('bjdxResult:questionnaire-result-details:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportQuestionnaireResultDetailsExcel(@Valid QuestionnaireResultDetailsPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<QuestionnaireResultDetailsDO> list = questionnaireResultDetailsService.getQuestionnaireResultDetailsPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "北京大学-问卷结果-详情.xls", "数据", QuestionnaireResultDetailsRespVO.class,
                        BeanUtils.toBean(list, QuestionnaireResultDetailsRespVO.class));
    }

}