package org.dromara.controller.complaintSuggestion;

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.complaintSuggestion.bo.ComplaintSuggestionBo;
import org.dromara.domain.complaintSuggestion.vo.ComplaintSuggestionVo;
import org.dromara.service.IComplaintSuggestionService;
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/suggestion")
public class ComplaintSuggestionController extends BaseController {

    private final IComplaintSuggestionService complaintSuggestionService;

    /**
     * 查询投诉建议列表
     */
    @SaCheckPermission("wuYe:suggestion:list")
    @GetMapping("/list")
    public TableDataInfo<ComplaintSuggestionVo> list(ComplaintSuggestionBo bo, PageQuery pageQuery) {
        return complaintSuggestionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出投诉建议列表
     */
    @SaCheckPermission("wuYe:suggestion:export")
    @Log(title = "投诉建议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ComplaintSuggestionBo bo, HttpServletResponse response) {
        List<ComplaintSuggestionVo> list = complaintSuggestionService.queryList(bo);
        ExcelUtil.exportExcel(list, "投诉建议", ComplaintSuggestionVo.class, response);
    }

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

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

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

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