package com.ruoyi.web.work.api;

import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.web.work.api.config.BaseController;
import com.ruoyi.web.work.domain.Pay;
import com.ruoyi.web.work.domain.Platform;
import com.ruoyi.web.work.domain.dto.PayCashOutDto;
import com.ruoyi.web.work.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.rmi.ServerException;
import java.util.List;

/**
 * 微信在线充值记录
 *
 * @author lsw
 * @date 2024-07-01
 */
@RestController
@RequestMapping("/app/pay")
public class Api_PayController extends BaseController {
    @Autowired
    private IPayService payService;

    @Autowired
    private RedisCache redisCache;

    @GetMapping("/list")
    public TableDataInfo list(Pay pay) {
        pay.setUserId(getUser().getId());
        startPage();
        List<Pay> list = payService.selectList(pay);
        return getDataTable(list);
    }

    @GetMapping("/getPlatform")
    public AjaxResult getPlatform() {
        Platform platform = redisCache.getCacheObject(CacheConstants.APP_PLATFORM);
        return AjaxResult.success(platform);
    }

    @PostMapping("/cashOut")
    public AjaxResult cashOut(@Validated @RequestBody PayCashOutDto dto) throws ServerException {
        return payService.cashOut(dto);
    }

    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id) {
        return AjaxResult.success(payService.getById(id));
    }

}
