package org.dromara.business.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
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;
import org.dromara.business.domain.vo.CaseFeedbackVo;
import org.dromara.business.domain.bo.CaseFeedbackBo;
import org.dromara.business.service.ICaseFeedbackService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 意见反馈
 *
 * @author wuzhigang
 * @date 2023-12-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/feedback")
public class CaseFeedbackController extends BaseController {

    private final ICaseFeedbackService caseFeedbackService;

    /**
     * 查询意见反馈列表
     */
    @GetMapping("/list")
    public TableDataInfo<CaseFeedbackVo> list(CaseFeedbackBo bo, PageQuery pageQuery) {
        return caseFeedbackService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出意见反馈列表
     */
    @Log(title = "意见反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CaseFeedbackBo bo, HttpServletResponse response) {
        List<CaseFeedbackVo> list = caseFeedbackService.queryList(bo);
        ExcelUtil.exportExcel(list, "意见反馈", CaseFeedbackVo.class, response);
    }

    /**
     * 获取意见反馈详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<CaseFeedbackVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(caseFeedbackService.queryById(id));
    }

    /**
     * 新增意见反馈
     */
    @Log(title = "意见反馈", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CaseFeedbackBo bo) {
        return toAjax(caseFeedbackService.insertByBo(bo));
    }

    /**
     * 修改意见反馈
     */
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CaseFeedbackBo bo) {
        return toAjax(caseFeedbackService.updateByBo(bo));
    }

    /**
     * 删除意见反馈
     *
     * @param ids 主键串
     */
    @Log(title = "意见反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(caseFeedbackService.deleteWithValidByIds(List.of(ids), true));
    }
}
