package com.ruoyi.xq.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xq.domain.Feedback;
import com.ruoyi.xq.service.FeedbackService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 留言举报
 *
 * @author 77
 * @date 2024-04-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xq/feedback")
public class FeedbackController extends BaseController {

    private final FeedbackService feedbackService;

    /**
     * 查询留言举报列表
     */
    @SaCheckPermission("xq:feedback:list")
    @GetMapping("/list")
    public TableDataInfo<Feedback> list(Feedback bo, PageQuery pageQuery) {
        Page<Feedback> page = feedbackService.page(pageQuery.build(), Wrappers.lambdaQuery(bo));
        return TableDataInfo.build(page);
    }

    /**
     * 获取留言举报详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xq:feedback:query")
    @GetMapping("/{id}")
    public R<Feedback> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(feedbackService.getById(id));
    }

    /**
     * 修改留言举报
     */
    @SaCheckPermission("xq:feedback:edit")
    @Log(title = "留言举报", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Feedback bo) {
        return toAjax(feedbackService.updateById(bo));
    }

    /**
     * 删除留言举报
     *
     * @param ids 主键串
     */
    @SaCheckPermission("xq:feedback:remove")
    @Log(title = "留言举报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(feedbackService.removeBatchByIds(Arrays.asList(ids), true));
    }
}
