package org.dromara.system.controller.opinion;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.opinion.bo.XiaoyuanOpinionBo;
import org.dromara.system.domain.opinion.vo.XiaoyuanOpinionVo;
import org.dromara.system.service.opinion.IXiaoyuanOpinionService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;

/**
 * 校园建议ID
 *
 * @author boman
 * @date 2023-09-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/opinion")
public class XiaoyuanOpinionController extends BaseController {

    private final IXiaoyuanOpinionService xiaoyuanOpinionService;

    /**
     * 查询校园建议ID列表
     */
    @SaCheckPermission("system:opinion:list")
    @GetMapping("/list")
    public TableDataInfo<XiaoyuanOpinionVo> list(XiaoyuanOpinionBo bo, PageQuery pageQuery) {
        return xiaoyuanOpinionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出校园建议ID列表
     */
    @SaCheckPermission("system:opinion:export")
    @Log(title = "校园建议ID", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XiaoyuanOpinionBo bo, HttpServletResponse response) {
        List<XiaoyuanOpinionVo> list = xiaoyuanOpinionService.queryList(bo);
        ExcelUtil.exportExcel(list, "校园建议ID", XiaoyuanOpinionVo.class, response);
    }

    /**
     * 获取校园建议ID详细信息
     *
     * @param opinionId 主键
     */
    @SaCheckPermission("system:opinion:query")
    @GetMapping("/{opinionId}")
    public R<XiaoyuanOpinionVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long opinionId) {
        return R.ok(xiaoyuanOpinionService.queryById(opinionId));
    }

    /**
     * 新增校园建议ID
     */
    @SaCheckPermission("system:opinion:add")
    @Log(title = "校园建议ID", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XiaoyuanOpinionBo bo) {
        return toAjax(xiaoyuanOpinionService.insertByBo(bo));
    }

    /**
     * 修改校园建议ID
     */
    @SaCheckPermission("system:opinion:edit")
    @Log(title = "校园建议ID", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XiaoyuanOpinionBo bo) {
        return toAjax(xiaoyuanOpinionService.updateByBo(bo));
    }

    /**
     * 删除校园建议ID
     *
     * @param opinionIds 主键串
     */
    @SaCheckPermission("system:opinion:remove")
    @Log(title = "校园建议ID", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{opinionIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] opinionIds) {
        return toAjax(xiaoyuanOpinionService.deleteWithValidByIds(List.of(opinionIds), true));
    }
}
