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.DbUserCommentVo;
import com.yongqi.xinrenli.domain.bo.DbUserCommentBo;
import com.yongqi.xinrenli.service.IDbUserCommentService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户评论
 *
 * @author zyf
 * @date 2023-03-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xinrenli/userComment")
public class DbUserCommentController extends BaseController {

    private final IDbUserCommentService iDbUserCommentService;

    /**
     * 查询用户评论列表
     */
    @SaCheckPermission("xinrenli:userComment:list")
    @GetMapping("/list")
    public TableDataInfo<DbUserCommentVo> list(DbUserCommentBo bo, PageQuery pageQuery) {
        return iDbUserCommentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户评论列表
     */
    @SaCheckPermission("xinrenli:userComment:export")
    @Log(title = "用户评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DbUserCommentBo bo, HttpServletResponse response) {
        List<DbUserCommentVo> list = iDbUserCommentService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户评论", DbUserCommentVo.class, response);
    }

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

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

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

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