package com.younike.merchant;

import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.common.enums.BusinessType;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.system.domain.OrderRefund;
import com.younike.system.service.IMerchantOrderRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单--退款处理Controller
 *
 * @author jubs
 * @date 2022-01-10
 */
@Api("订单--退款处理接口")
@RestController
@RequestMapping("/system/refund")
public class MerchantOrderRefundController extends BaseController {
    @Autowired
    private IMerchantOrderRefundService orderRefundService;

    /**
     * 查询订单--退款处理列表
     */
    @ApiOperation("查询订单--退款处理列表")
    @PreAuthorize("@ss.hasAnyRoles({'merchant','operation'})")
    @GetMapping("/list")
    public TableDataInfo list(OrderRefund orderRefund) {
        startPage();
        List<OrderRefund> list = orderRefundService.selectOrderRefundList(orderRefund);
        return getDataTable(list);
    }

    /**
     * 导出订单--退款处理列表
     */
    @ApiOperation("导出订单--退款处理列表")
    @PreAuthorize("@ss.hasRole('merchant')")
    @Log(title = "订单--退款处理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderRefund orderRefund) {
        List<OrderRefund> list = orderRefundService.selectOrderRefundList(orderRefund);
        ExcelUtil<OrderRefund> util = new ExcelUtil<OrderRefund>(OrderRefund.class);
        return util.exportExcel(list, "订单--退款处理数据");
    }

    /**
     * 获取订单--退款处理详细信息
     */
    @ApiOperation("获取订单--退款处理详细信息")
    @PreAuthorize("@ss.hasRole('merchant')")
    @GetMapping(value = "/{orderRefundId}")
    public AjaxResult getInfo(@PathVariable("orderRefundId") Long orderRefundId) {
        return AjaxResult.success(orderRefundService.selectOrderRefundByOrderRefundId(orderRefundId));
    }

    /**
     * 新增订单--退款处理
     */
    @ApiOperation("新增订单--退款处理")
    @PreAuthorize("@ss.hasRole('merchant')")
    @Log(title = "订单--退款处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderRefund orderRefund) {
        return toAjax(orderRefundService.insertOrderRefund(orderRefund));
    }

    /**
     * 修改订单--退款处理
     */
    @ApiOperation("修改订单--退款处理")
    @PreAuthorize("@ss.hasRole('merchant')")
    @Log(title = "订单--退款处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderRefund orderRefund) {
        return toAjax(orderRefundService.updateOrderRefund(orderRefund));
    }

    /**
     * 删除订单--退款处理
     */
    @ApiOperation("删除订单--退款处理")
    @PreAuthorize("@ss.hasRole('merchant')")
    @Log(title = "订单--退款处理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderRefundIds}")
    public AjaxResult remove(@PathVariable Long[] orderRefundIds) {
        return toAjax(orderRefundService.deleteOrderRefundByOrderRefundIds(orderRefundIds));
    }

}
