package com.ruoyi.web.controller.system;

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.common.utils.poi.ExcelUtil;
import com.ruoyi.ss.transfer.domain.TransferQuery;
import com.ruoyi.ss.transfer.domain.TransferVO;
import com.ruoyi.ss.transfer.service.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 转账Controller
 *
 * @author ruoyi
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/ss/transfer")
public class TransferController extends BaseController
{
    @Autowired
    private TransferService transferService;

    /**
     * 查询转账列表
     */
    @PreAuthorize("@ss.hasPermi('ss:transfer:list')")
    @GetMapping("/list")
    public TableDataInfo list(TransferQuery query)
    {
        startPage();
        startOrderBy();
        List<TransferVO> list = transferService.selectTransferList(query);
        return getDataTable(list);
    }

    /**
     * 导出转账列表
     */
    @PreAuthorize("@ss.hasPermi('ss:transfer:export')")
    @Log(title = "转账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TransferQuery query)
    {
        List<TransferVO> list = transferService.selectTransferList(query);
        ExcelUtil<TransferVO> util = new ExcelUtil<TransferVO>(TransferVO.class);
        util.exportExcel(response, list, "转账数据");
    }

    /**
     * 获取转账详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:transfer:query')")
    @GetMapping(value = "/{batchId}")
    public AjaxResult getInfo(@PathVariable("batchId") Long batchId)
    {
        return success(transferService.selectTransferByBatchId(batchId));
    }

    /**
     * 刷新转账结果
     */
    @PreAuthorize("@ss.hasPermi('ss:transfer:refresh')")
    @PutMapping(value = "/{batchId}/refresh")
    public AjaxResult refreshStatus(@PathVariable("batchId") Long batchId)
    {
        return toAjax(transferService.refreshTransferStatus(batchId));
    }

}
