package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
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.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.vo.OaFeedbackVo;
import com.ruoyi.oa.domain.bo.OaFeedbackBo;
import com.ruoyi.oa.service.IOaFeedbackService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题反馈
 *
 * @author ruoyi
 * @date 2025-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/feedback")
public class OaFeedbackController extends BaseController {

    private final IOaFeedbackService iOaFeedbackService;

    /**
     * 查询问题反馈列表
     */
    @GetMapping("/list")
    public TableDataInfo<OaFeedbackVo> list(OaFeedbackBo bo, PageQuery pageQuery) {
        return iOaFeedbackService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询问题反馈列表
     */
    @GetMapping("/index-list")
    public TableDataInfo<OaFeedbackVo> indexList(OaFeedbackBo bo, PageQuery pageQuery) {
        return iOaFeedbackService.indexQueryList(bo, pageQuery);
    }

    /**
     * 导出问题反馈列表
     */
    @PostMapping("/export")
    public void export(OaFeedbackBo bo, HttpServletResponse response) {
        List<OaFeedbackVo> list = iOaFeedbackService.queryList(bo);
        ExcelUtil.exportExcel(list, "问题反馈", OaFeedbackVo.class, response);
    }

    /**
     * 获取问题反馈详细信息
     *
     * @param feedbackId 主键
     */
    @GetMapping("/{feedbackId}")
    public R<OaFeedbackVo> getInfo(@NotNull(message = "主键不能为空")
                                   @PathVariable Long feedbackId) {
        return R.ok(iOaFeedbackService.queryById(feedbackId));
    }

    /**
     * 新增问题反馈
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OaFeedbackBo bo) {
        return toAjax(iOaFeedbackService.insertByBo(bo));
    }

    /**
     * 修改问题反馈
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OaFeedbackBo bo) {
        return toAjax(iOaFeedbackService.updateByBo(bo));
    }

    /**
     * 删除问题反馈
     *
     * @param feedbackIds 主键串
     */
    @DeleteMapping("/{feedbackIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] feedbackIds) {
        return toAjax(iOaFeedbackService.deleteWithValidByIds(Arrays.asList(feedbackIds), true));
    }
    /**
     * 删除问题反馈
     *
     * @param feedbackId 主键
     */
    @DeleteMapping("/remove/{feedbackId}")
    public R<Void> removeItem(@PathVariable("feedbackId") Long feedbackId) {
        return toAjax(iOaFeedbackService.delItem(feedbackId));
    }


    /**
     * 修改问题反馈
     */
    @RepeatSubmit()
    @PutMapping("/toRead")
    public R<Void> toRead(@Validated(EditGroup.class) @RequestBody OaFeedbackBo bo) {
        return toAjax(iOaFeedbackService.updateToRead(bo));
    }

}
