package com.ruoyi.web.work.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.domain.Pay;
import com.ruoyi.web.work.domain.User;
import com.ruoyi.web.work.domain.dto.PayAuditDto;
import com.ruoyi.web.work.service.IPayService;
import com.ruoyi.web.work.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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("/work/pay")
public class PayController extends BaseController {
    @Autowired
    private IPayService payService;

    @Autowired
    private IUserService userService;

    @PreAuthorize("@ss.hasPermi('work:pay:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pay pay) {
        startPage();
        List<Pay> list = payService.selectList(pay);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('work:pay:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id) {
        Pay pay = payService.getById(id);
        User user = userService.getById(pay.getUserId());
        return AjaxResult.success(new AjaxResult().put("pay", pay).put("user", user));
    }

    @PreAuthorize("@ss.hasPermi('work:pay:audit')")
    @Log(title = "余额提现", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@Validated @RequestBody PayAuditDto dto) throws ServerException {
        return payService.audit(dto);
    }

}
