package org.dromara.controller.suggestionFj;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
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.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.domain.suggestionFj.bo.SuggestionFjBo;
import org.dromara.domain.suggestionFj.vo.SuggestionFjVo;
import org.dromara.service.ISuggestionFjService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 投诉建议_附件
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/suggestionFj")
public class SuggestionFjController extends BaseController {

    private final ISuggestionFjService suggestionFjService;

    /**
     * 查询投诉建议_附件列表
     */
    @SaCheckPermission("wuYe:suggestionFj:list")
    @GetMapping("/list")
    public TableDataInfo<SuggestionFjVo> list(SuggestionFjBo bo, PageQuery pageQuery) {
        return suggestionFjService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出投诉建议_附件列表
     */
    @SaCheckPermission("wuYe:suggestionFj:export")
    @Log(title = "投诉建议_附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SuggestionFjBo bo, HttpServletResponse response) {
        List<SuggestionFjVo> list = suggestionFjService.queryList(bo);
        ExcelUtil.exportExcel(list, "投诉建议_附件", SuggestionFjVo.class, response);
    }

    /**
     * 获取投诉建议_附件详细信息
     *
     * @param suggestionFjId 主键
     */
    @SaCheckPermission("wuYe:suggestionFj:query")
    @GetMapping("/{suggestionFjId}")
    public R<SuggestionFjVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long suggestionFjId) {
        return R.ok(suggestionFjService.queryById(suggestionFjId));
    }

    /**
     * 新增投诉建议_附件
     */
    @SaCheckPermission("wuYe:suggestionFj:add")
    @Log(title = "投诉建议_附件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SuggestionFjBo bo) {
        return toAjax(suggestionFjService.insertByBo(bo));
    }

    /**
     * 修改投诉建议_附件
     */
    @SaCheckPermission("wuYe:suggestionFj:edit")
    @Log(title = "投诉建议_附件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SuggestionFjBo bo) {
        return toAjax(suggestionFjService.updateByBo(bo));
    }

    /**
     * 删除投诉建议_附件
     *
     * @param suggestionFjIds 主键串
     */
    @SaCheckPermission("wuYe:suggestionFj:remove")
    @Log(title = "投诉建议_附件", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{suggestionFjIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] suggestionFjIds) {
        return toAjax(suggestionFjService.deleteWithValidByIds(List.of(suggestionFjIds), true));
    }
}
