package com.ruoyi.web.controller.info;

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.info.order.domain.vo.OrderReviewsVo;
import com.ruoyi.info.order.domain.bo.OrderReviewsBo;
import com.ruoyi.info.order.service.IOrderReviewsService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 订单评价Controller
 *
 * @author ruoyi
 * @date 2025-09-29
 */
@Validated
@Api(value = "订单评价控制器", tags = {"订单评价管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/order/orderReviews")
public class OrderReviewsController extends BaseController {

    private final IOrderReviewsService iOrderReviewsService;

    /**
     * 分页查询订单评价列表
     */
    @ApiOperation("查询订单评价列表")
    @SaCheckPermission("order:orderReviews:list")
    @GetMapping("/page")
    public TableDataInfo<OrderReviewsVo> page(@Validated(QueryGroup.class) OrderReviewsBo bo, PageQuery pageQuery) {
        return iOrderReviewsService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取订单评价详细信息
     */
    @ApiOperation("获取订单评价详细信息")
    @SaCheckPermission("order:orderReviews:query")
    @GetMapping("/info/{id}")
    public R<OrderReviewsVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iOrderReviewsService.queryById(id));
    }

    /**
     * 新增订单评价
     */
    @ApiOperation("新增订单评价")
    @SaCheckPermission("order:orderReviews:add")
    @Log(title = "订单评价", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OrderReviewsBo bo) {
        return toAjax(iOrderReviewsService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改订单评价
     */
    @ApiOperation("修改订单评价")
    @SaCheckPermission("order:orderReviews:edit")
    @Log(title = "订单评价", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OrderReviewsBo bo) {
        return toAjax(iOrderReviewsService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除订单评价
     */
    @ApiOperation("删除订单评价")
    @SaCheckPermission("order:orderReviews:remove")
    @Log(title = "订单评价", businessType = BusinessType.DELETE)
    @PostMapping("/del/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iOrderReviewsService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 导出订单评价列表
     */
    @ApiOperation("导出订单评价列表")
    @SaCheckPermission("order:orderReviews:export")
    @Log(title = "订单评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated OrderReviewsBo bo, HttpServletResponse response) {
        List<OrderReviewsVo> list = iOrderReviewsService.queryList(bo);
        ExcelUtil.exportExcel(list, "订单评价", OrderReviewsVo.class, response);
    }

}
