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.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.category.support.SellerShopContext;
import com.ruoyi.web.modules.finance.service.IShopFundService;
import com.ruoyi.web.modules.store.constant.ShopConstants;

/**
 * 商家端资金概览
 */
@RestController
@RequestMapping("/agri/seller/finance/overview")
public class SellerFundOverviewController extends BaseController
{
    @Autowired
    private IShopFundService shopFundService;

    @PreAuthorize("@ss.hasPermi('agri:seller:finance:overview:query')")
    @GetMapping("/summary")
    public AjaxResult summary()
    {
        return success(shopFundService.getOverviewSummary(requireShopId(), getUsername()));
    }

    @PreAuthorize("@ss.hasPermi('agri:seller:finance:overview:query')")
    @GetMapping("/logs")
    public TableDataInfo logs()
    {
        startPage();
        return getDataTable(shopFundService.listFundLogs(requireShopId()));
    }

    private Long requireShopId()
    {
        Long shopId = SellerShopContext.getShopId();
        if (shopId == null || shopId <= 0)
        {
            throw new ServiceException(ShopConstants.MSG_SHOP_CONTEXT_REQUIRED);
        }
        return shopId;
    }
}
