package cn.iocoder.yudao.module.system.controller.admin.sys;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.sys.vo.EvaluationProcessPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.SysEvaluationProcessDO;
import cn.iocoder.yudao.module.system.service.biz.SysEvaluationProcessService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.Objects;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 评估表")
@RestController
@RequestMapping("/evaluationProcess")
public class SysEvaluationProcessController {

    @Resource
    private SysEvaluationProcessService sysEvaluationProcessService;


    @GetMapping("/queryPage")
    @Operation(summary = "评估表列表分页")
    //@PreAuthorize("@ss.hasPermission('evaluationProcess:query')")
    @TenantIgnore
    public CommonResult<PageResult<SysEvaluationProcessDO>> queryPage(@Valid EvaluationProcessPageReqVO pageVO) {
        pageVO.setTenantIds(Objects.isNull(pageVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageVO.getTenantIds());
        PageResult<SysEvaluationProcessDO> pageResult = sysEvaluationProcessService.queryPage(pageVO);
        return success(BeanUtils.toBean(pageResult, SysEvaluationProcessDO.class));
    }


    @GetMapping("/findOneById")
    @Operation(summary = "评估表详情")
    @Parameter(name = "evaluationProcessId", description = "评估表ID", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<SysEvaluationProcessDO> findOneById(@RequestParam("evaluationProcessId") Long evaluationProcessId) {
        return success(sysEvaluationProcessService.findOneById(evaluationProcessId));
    }


    @PostMapping("/addEvaluationProcess")
    @Operation(summary = "评估表新增")
    @TenantIgnore
    public CommonResult<Boolean> addEvaluationProcess(@RequestBody SysEvaluationProcessDO processDO) {
        processDO.setTenantId(processDO.getTenantId() == null ? TenantContextHolder.getTenantId() : processDO.getTenantId());
        sysEvaluationProcessService.addEvaluationProcess(processDO);
        return success(true);
    }


    @PostMapping("/edit")
    @Operation(summary = "评估表编辑")
    @TenantIgnore
    public CommonResult<Boolean> edit(@RequestBody SysEvaluationProcessDO processDO) {
        sysEvaluationProcessService.edit(processDO);
        return success(true);
    }


    @DeleteMapping("/delete")
    @Operation(summary = "评估表删除")
    @Parameter(name = "id", description = "评估表ID", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<Boolean> delete(@RequestParam("evaluationProcessId") Long evaluationProcessId) {
        sysEvaluationProcessService.delete(evaluationProcessId);
        return success(true);
    }
}
