package com.yongqi.xinrenli.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.yongqi.xinrenli.domain.vo.DbUserFeedbackVo;
import com.yongqi.xinrenli.domain.bo.DbUserFeedbackBo;
import com.yongqi.xinrenli.service.IDbUserFeedbackService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户反馈
 *
 * @author zyf
 * @date 2023-03-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xinrenli/userFeedback")
public class DbUserFeedbackController extends BaseController {

    private final IDbUserFeedbackService iDbUserFeedbackService;

    /**
     * 查询用户反馈列表
     */
    @SaCheckPermission("xinrenli:userFeedback:list")
    @GetMapping("/list")
    public TableDataInfo<DbUserFeedbackVo> list(DbUserFeedbackBo bo, PageQuery pageQuery) {
        return iDbUserFeedbackService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户反馈列表
     */
    @SaCheckPermission("xinrenli:userFeedback:export")
    @Log(title = "用户反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DbUserFeedbackBo bo, HttpServletResponse response) {
        List<DbUserFeedbackVo> list = iDbUserFeedbackService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户反馈", DbUserFeedbackVo.class, response);
    }

    /**
     * 获取用户反馈详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xinrenli:userFeedback:query")
    @GetMapping("/{id}")
    public R<DbUserFeedbackVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long id) {
        return R.ok(iDbUserFeedbackService.queryById(id));
    }

    /**
     * 新增用户反馈
     */
    @SaCheckPermission("xinrenli:userFeedback:add")
    @Log(title = "用户反馈", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DbUserFeedbackBo bo) {
        return toAjax(iDbUserFeedbackService.insertByBo(bo));
    }

    /**
     * 修改用户反馈
     */
    @SaCheckPermission("xinrenli:userFeedback:edit")
    @Log(title = "用户反馈", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DbUserFeedbackBo bo) {
        return toAjax(iDbUserFeedbackService.updateByBo(bo));
    }

    /**
     * 删除用户反馈
     *
     * @param ids 主键串
     */
    @SaCheckPermission("xinrenli:userFeedback:remove")
    @Log(title = "用户反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iDbUserFeedbackService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
