package cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual;

import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessTaskDimensionPageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessTaskDimensionRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.modelassesstaskmanual.vo.ModelAssessTaskDimensionSaveReqVO;
import cn.iocoder.yudao.module.llm.dal.dataobject.modelassesstaskmanual.ModelAssessTaskDimensionDO;
import cn.iocoder.yudao.module.llm.service.modelassesstaskmanual.ModelAssessTaskDimensionService;
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 cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

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

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



//@Tag(name = "管理后台 - 人工打分 评估维度")
//@RestController
//@RequestMapping("/llm/model-assess-task-dimension")
@Validated
public class ModelAssessTaskDimensionController {

    @Resource
    private ModelAssessTaskDimensionService modelAssessTaskDimensionService;

    @PostMapping("/create")
    @Operation(summary = "创建人工打分 评估维度")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-dimension:create')")
    public CommonResult<Long> createModelAssessTaskDimension(@Valid @RequestBody ModelAssessTaskDimensionSaveReqVO createReqVO) {
        return success(modelAssessTaskDimensionService.createModelAssessTaskDimension(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新人工打分 评估维度")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-dimension:update')")
    public CommonResult<Boolean> updateModelAssessTaskDimension(@Valid @RequestBody ModelAssessTaskDimensionSaveReqVO updateReqVO) {
        modelAssessTaskDimensionService.updateModelAssessTaskDimension(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除人工打分 评估维度")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-dimension:delete')")
    public CommonResult<Boolean> deleteModelAssessTaskDimension(@RequestParam("id") Long id) {
        modelAssessTaskDimensionService.deleteModelAssessTaskDimension(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得人工打分 评估维度")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-dimension:query')")
    public CommonResult<ModelAssessTaskDimensionRespVO> getModelAssessTaskDimension(@RequestParam("id") Long id) {
        ModelAssessTaskDimensionDO modelAssessTaskDimension = modelAssessTaskDimensionService.getModelAssessTaskDimension(id);
        return success(BeanUtils.toBean(modelAssessTaskDimension, ModelAssessTaskDimensionRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得人工打分 评估维度分页")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-dimension:query')")
    public CommonResult<PageResult<ModelAssessTaskDimensionRespVO>> getModelAssessTaskDimensionPage(@Valid ModelAssessTaskDimensionPageReqVO pageReqVO) {
        PageResult<ModelAssessTaskDimensionDO> pageResult = modelAssessTaskDimensionService.getModelAssessTaskDimensionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ModelAssessTaskDimensionRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出人工打分 评估维度 Excel")
    @PreAuthorize("@ss.hasPermission('llm:model-assess-task-dimension:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportModelAssessTaskDimensionExcel(@Valid ModelAssessTaskDimensionPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ModelAssessTaskDimensionDO> list = modelAssessTaskDimensionService.getModelAssessTaskDimensionPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "人工打分 评估维度.xls", "数据", ModelAssessTaskDimensionRespVO.class,
                        BeanUtils.toBean(list, ModelAssessTaskDimensionRespVO.class));
    }

}