package ${package}.controller;

import ${package}.model.dto.${classUppercaseName}Dto;
import ${package}.model.entity.${classUppercaseName}Entity;
import ${package}.model.vo.${classUppercaseName}Vo;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import ${package}.service.${classUppercaseName}Service;
import com.auth.common.model.common.result.PageResult;
import com.auth.common.model.common.result.Result;
import com.auth.common.model.common.result.ResultCodeEnum;

import java.util.List;

/**
 * <p>
 * ${comment} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Tag(name = "${comment}", description = "${comment}相关接口")
@RestController
@RequestMapping("${requestMapping}/${lowerHyphenName}")
@RequiredArgsConstructor
public class ${classUppercaseName}Controller {

    private final ${classUppercaseName}Service ${classLowercaseName}Service;

    @PreAuthorize("auth.decide('${classLowercaseName}:query')")
    @Operation(summary = "分页查询${comment}", description = "分页查询${comment}")
    @GetMapping()
    public Result<PageResult<${classUppercaseName}Vo>> get${classUppercaseName}Page(${classUppercaseName}Dto dto) {
        Page<${classUppercaseName}Entity> pageParams = new Page<>(dto.getPageIndex(), dto.getPageSize());
        PageResult<${classUppercaseName}Vo> pageResult = ${classLowercaseName}Service.get${classUppercaseName}Page(pageParams, dto);
        return Result.success(pageResult);
    }

    @PreAuthorize("auth.decide('${classLowercaseName}:query')")
    @Operation(summary = "根据id查询${comment}详情", description = "根据id查询${comment}详情")
    @GetMapping("{id}")
    public Result<${classUppercaseName}Vo> getById(@PathVariable("id") Long id) {
        ${classUppercaseName}Vo ${classLowercaseName}Vo = ${classLowercaseName}Service.getById(id);

        return Result.success(${classLowercaseName}Vo);
    }

    @PreAuthorize("auth.decide('${classLowercaseName}:create')")
    @Operation(summary = "添加${comment}", description = "添加${comment}")
    @PostMapping()
    public Result<String> create(@Valid @RequestBody ${classUppercaseName}Dto dto) {
            ${classLowercaseName}Service.create(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @PreAuthorize("auth.decide('${classLowercaseName}:update')")
    @Operation(summary = "更新${comment}", description = "更新${comment}")
    @PutMapping()
    public Result<String> update(@Valid @RequestBody ${classUppercaseName}Dto dto) {
            ${classLowercaseName}Service.update(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @PreAuthorize("auth.decide('${classLowercaseName}:delete')")
    @Operation(summary = "删除${comment}", description = "删除${comment}")
    @DeleteMapping()
    public Result<String> batchDelete(@RequestBody List<Long> ids) {
            ${classLowercaseName}Service.batchDelete(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}