package org.dromara.biz.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.biz.domain.vo.BizTaskFeedbackVo;
import org.dromara.biz.domain.bo.BizTaskFeedbackBo;
import org.dromara.biz.service.IBizTaskFeedbackService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 任务反馈信息
 *
 * @author chenle
 * @date 2025-05-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/biz/taskFeedback")
public class BizTaskFeedbackController extends BaseController {

    private final IBizTaskFeedbackService bizTaskFeedbackService;

    /**
     * 查询任务反馈信息列表
     */
    @SaCheckPermission("biz:taskFeedback:list")
    @GetMapping("/list")
    public TableDataInfo<BizTaskFeedbackVo> list(BizTaskFeedbackBo bo, PageQuery pageQuery) {
        return bizTaskFeedbackService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出任务反馈信息列表
     */
    @SaCheckPermission("biz:taskFeedback:export")
    @Log(title = "任务反馈信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BizTaskFeedbackBo bo, HttpServletResponse response) {
        List<BizTaskFeedbackVo> list = bizTaskFeedbackService.queryList(bo);
        ExcelUtil.exportExcel(list, "任务反馈信息", BizTaskFeedbackVo.class, response);
    }

    /**
     * 获取任务反馈信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("biz:taskFeedback:query")
    @GetMapping("/{id}")
    public R<BizTaskFeedbackVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(bizTaskFeedbackService.queryById(id));
    }

    /**
     * 新增任务反馈信息
     */
    @SaCheckPermission("biz:taskFeedback:add")
    @Log(title = "任务反馈信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BizTaskFeedbackBo bo) {
        return toAjax(bizTaskFeedbackService.insertByBo(bo));
    }

    /**
     * 修改任务反馈信息
     */
    @SaCheckPermission("biz:taskFeedback:edit")
    @Log(title = "任务反馈信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BizTaskFeedbackBo bo) {
        return toAjax(bizTaskFeedbackService.updateByBo(bo));
    }

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