package com.ruoyi.web.modules.finance.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.web.modules.finance.dto.PlatformFundLogQuery;
import com.ruoyi.web.modules.finance.dto.PlatformShopFundRankQuery;
import com.ruoyi.web.modules.finance.service.IShopFundService;

/**
 * 平台端资金概览
 */
@RestController
@RequestMapping("/agri/finance/fundOverview")
public class PlatformFundOverviewController extends BaseController
{
    @Autowired
    private IShopFundService shopFundService;

    @PreAuthorize("@ss.hasPermi('agri:finance:fundOverview:summary')")
    @GetMapping("/summary")
    public AjaxResult summary()
    {
        return success(shopFundService.getPlatformOverviewSummary());
    }

    @PreAuthorize("@ss.hasPermi('agri:finance:fundOverview:ranking')")
    @GetMapping("/shops")
    public TableDataInfo shops(PlatformShopFundRankQuery query)
    {
        // 排序由 BizShopWalletMapper 内自定义 ORDER BY 处理；勿交给 PageHelper（会转成 snake_case 列名导致报错）
        PageDomain pageDomain = TableSupport.buildPageRequest();
        PageHelper.startPage(pageDomain.getPageNum(), pageDomain.getPageSize())
                .setReasonable(pageDomain.getReasonable());
        return getDataTable(shopFundService.listPlatformShopRanks(query));
    }

    @PreAuthorize("@ss.hasPermi('agri:finance:fundOverview:log')")
    @GetMapping("/logs")
    public TableDataInfo logs(PlatformFundLogQuery query)
    {
        startPage();
        return getDataTable(shopFundService.listPlatformFundLogs(query));
    }
}
