package com.zanxiang.game.module.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.GameRemitLogListParam;
import com.zanxiang.game.module.manage.pojo.params.OrderParam;
import com.zanxiang.game.module.manage.pojo.params.PayCallCpLogParam;
import com.zanxiang.game.module.manage.pojo.vo.GameRemitLogVO;
import com.zanxiang.game.module.manage.pojo.vo.LogPayCpVO;
import com.zanxiang.game.module.manage.pojo.vo.OrderListVO;
import com.zanxiang.game.module.manage.service.IGameRemitLogService;
import com.zanxiang.game.module.manage.service.ILogPayCpService;
import com.zanxiang.game.module.manage.service.IOrderService;
import com.zanxiang.module.util.pojo.ResultVO;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author : lingfeng
 * @time : 2022-11-07
 * @description : 订单
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @Autowired
    private ILogPayCpService logPayCpService;

    @Autowired
    private IGameRemitLogService gameRemitLogService;

    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:order:orderList")
    public ResultVO<OrderListVO> orderList(@Validated @RequestBody OrderParam param) {
        return ResultVO.ok(orderService.orderList(param));
    }

    @PostMapping(value = "/cp/call/list")
    @PreAuthorize(permissionKey = "manage:order:callCpList")
    public ResultVO<IPage<LogPayCpVO>> callCpList(@Validated @RequestBody PayCallCpLogParam param) {
        return ResultVO.ok(logPayCpService.callCpList(param));
    }

    @PostMapping(value = "/list/excel")
    @PreAuthorize(permissionKey = "manage:order:orderExcel")
    public void getOrderExcel(@Validated @RequestBody OrderParam param, HttpServletResponse response) {
        orderService.getOrderExcel(param, response);
    }

    @PostMapping(value = "/remit/Log")
    @PreAuthorize(permissionKey = "manage:order:remitLog")
    public ResultVO<IPage<GameRemitLogVO>> listOfPage(@Validated @RequestBody GameRemitLogListParam param) {
        return ResultVO.ok(gameRemitLogService.listOfPage(param));
    }

    @GetMapping(value = "/call/cp")
    @PreAuthorize(permissionKey = "manage:order:callCp")
    public ResultVO<Boolean> callCp(@RequestParam String orderId, String payKey) {
        return ResultVO.ok(orderService.callCp(orderId, payKey));
    }
}
