package ${package.Controller};

import ${package.Entity}.${entity}DO;
import ${package.Service}.${table.serviceName};
import cn.meowrain.aioj.backend.framework.result.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ${table.comment!} 控制器
 *
 * @author ${author}
 * @since ${date}
 */
@Tag(name = "${table.comment!}管理")
@RestController
@RequestMapping("/v1/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@RequiredArgsConstructor
public class ${table.controllerName} {

    private final ${table.serviceName} ${table.entityPath}Service;

    /**
     * 分页查询${table.comment!}列表
     */
    @Operation(summary = "分页查询${table.comment!}列表")
    @GetMapping("/page")
    public Result<Page<${entity}DO>> page(
            @Parameter(description = "当前页码") @RequestParam(defaultValue = "1") Integer current,
            @Parameter(description = "每页数量") @RequestParam(defaultValue = "10") Integer size) {
        Page<${entity}DO> page = new Page<>(current, size);
        return Result.success(${table.entityPath}Service.page(page));
    }

    /**
     * 查询所有${table.comment!}列表
     */
    @Operation(summary = "查询所有${table.comment!}列表")
    @GetMapping("/list")
    public Result<List<${entity}DO>> list() {
        return Result.success(${table.entityPath}Service.list());
    }

    /**
     * 根据ID查询${table.comment!}详情
     */
    @Operation(summary = "根据ID查询${table.comment!}详情")
    @GetMapping("/{id}")
    public Result<${entity}DO> getById(
            @Parameter(description = "${table.comment!}ID") @PathVariable Long id) {
        return Result.success(${table.entityPath}Service.getById(id));
    }

    /**
     * 新增${table.comment!}
     */
    @Operation(summary = "新增${table.comment!}")
    @PostMapping
    public Result<Boolean> save(@RequestBody ${entity}DO entity) {
        return Result.success(${table.entityPath}Service.save(entity));
    }

    /**
     * 修改${table.comment!}
     */
    @Operation(summary = "修改${table.comment!}")
    @PutMapping
    public Result<Boolean> update(@RequestBody ${entity}DO entity) {
        return Result.success(${table.entityPath}Service.updateById(entity));
    }

    /**
     * 删除${table.comment!}
     */
    @Operation(summary = "删除${table.comment!}")
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(
            @Parameter(description = "${table.comment!}ID") @PathVariable Long id) {
        return Result.success(${table.entityPath}Service.removeById(id));
    }

    /**
     * 批量删除${table.comment!}
     */
    @Operation(summary = "批量删除${table.comment!}")
    @DeleteMapping("/batch")
    public Result<Boolean> deleteBatch(@RequestBody List<Long> ids) {
        return Result.success(${table.entityPath}Service.removeByIds(ids));
    }
}
