package com.yingpai.miniapp.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yingpai.miniapp.domain.bo.PaymentOrderBo;
import com.yingpai.miniapp.domain.vo.PaymentOrderVo;
import com.yingpai.miniapp.service.IPaymentOrderService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单管理
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/miniapp/order")
public class PaymentOrderController extends BaseController {

    private final IPaymentOrderService orderService;

    /**
     * 查询订单列表
     */
    @SaCheckPermission("miniapp:order:list")
    @GetMapping("/list")
    public TableDataInfo<PaymentOrderVo> list(PaymentOrderBo bo, PageQuery pageQuery) {
        return orderService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出订单列表
     */
    @SaCheckPermission("miniapp:order:export")
    @Log(title = "订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PaymentOrderBo bo, HttpServletResponse response) {
        List<PaymentOrderVo> list = orderService.queryList(bo);
        ExcelUtil.exportExcel(list, "订单数据", PaymentOrderVo.class, response);
    }

    /**
     * 获取订单详情
     */
    @SaCheckPermission("miniapp:order:query")
    @GetMapping("/{id}")
    public R<PaymentOrderVo> getInfo(@PathVariable Long id) {
        return R.ok(orderService.queryById(id));
    }

    /**
     * 删除订单
     */
    @SaCheckPermission("miniapp:order:remove")
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> remove(@PathVariable Long id) {
        return toAjax(orderService.deleteById(id));
    }
}
