package com.gxwebsoft.hjm.controller;

import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.hjm.service.HjmChoicesService;
import com.gxwebsoft.hjm.entity.HjmChoices;
import com.gxwebsoft.hjm.param.HjmChoicesParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.system.entity.User;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 黄家明_选择题选项控制器
 *
 * @author 科技小王子
 * @since 2025-06-02 12:59:49
 */
@Tag(name = "黄家明_选择题选项管理")
@RestController
@RequestMapping("/api/hjm/hjm-choices")
public class HjmChoicesController extends BaseController {
    @Resource
    private HjmChoicesService hjmChoicesService;

    @Operation(summary = "分页查询黄家明_选择题选项")
    @GetMapping("/page")
    public ApiResult<PageResult<HjmChoices>> page(HjmChoicesParam param) {
        // 使用关联查询
        return success(hjmChoicesService.pageRel(param));
    }

    @PreAuthorize("hasAuthority('hjm:hjmChoices:list')")
    @Operation(summary = "查询全部黄家明_选择题选项")
    @GetMapping()
    public ApiResult<List<HjmChoices>> list(HjmChoicesParam param) {
        // 使用关联查询
        return success(hjmChoicesService.listRel(param));
    }

    @Operation(summary = "根据id查询黄家明_选择题选项")
    @GetMapping("/{id}")
    public ApiResult<HjmChoices> get(@PathVariable("id") Integer id) {
        // 使用关联查询
        return success(hjmChoicesService.getByIdRel(id));
    }

    @PreAuthorize("hasAuthority('hjm:hjmChoices:save')")
    @OperationLog
    @Operation(summary = "添加黄家明_选择题选项")
    @PostMapping()
    public ApiResult<?> save(@RequestBody HjmChoices hjmChoices) {
        if (hjmChoicesService.save(hjmChoices)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmChoices:update')")
    @OperationLog
    @Operation(summary = "修改黄家明_选择题选项")
    @PutMapping()
    public ApiResult<?> update(@RequestBody HjmChoices hjmChoices) {
        if (hjmChoicesService.updateById(hjmChoices)) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmChoices:remove')")
    @OperationLog
    @Operation(summary = "删除黄家明_选择题选项")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (hjmChoicesService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmChoices:save')")
    @OperationLog
    @Operation(summary = "批量添加黄家明_选择题选项")
    @PostMapping("/batch")
    public ApiResult<?> saveBatch(@RequestBody List<HjmChoices> list) {
        if (hjmChoicesService.saveBatch(list)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmChoices:update')")
    @OperationLog
    @Operation(summary = "批量修改黄家明_选择题选项")
    @PutMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody BatchParam<HjmChoices> batchParam) {
        if (batchParam.update(hjmChoicesService, "id")) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmChoices:remove')")
    @OperationLog
    @Operation(summary = "批量删除黄家明_选择题选项")
    @DeleteMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
        if (hjmChoicesService.removeByIds(ids)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

}
