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.OrderRefundVo;
import com.ruoyi.info.order.domain.bo.OrderRefundBo;
import com.ruoyi.info.order.service.IOrderRefundService;
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/orderRefund")
public class OrderRefundController extends BaseController {

    private final IOrderRefundService iOrderRefundService;

    /**
     * 分页查询售后订单列表
     */
    @ApiOperation("查询售后订单列表")
    @SaCheckPermission("order:orderRefund:list")
    @GetMapping("/page")
    public TableDataInfo<OrderRefundVo> page(@Validated(QueryGroup.class) OrderRefundBo bo, PageQuery pageQuery) {
        return iOrderRefundService.queryPageList(bo, pageQuery);
    }

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

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

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

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

    /**
     * 导出售后订单列表
     */
    @ApiOperation("导出售后订单列表")
    @SaCheckPermission("order:orderRefund:export")
    @Log(title = "售后订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated OrderRefundBo bo, HttpServletResponse response) {
        List<OrderRefundVo> list = iOrderRefundService.queryList(bo);
        ExcelUtil.exportExcel(list, "售后订单", OrderRefundVo.class, response);
    }

}
