package com.cf.imes.module.system.controller.admin.funds.balancedetails;


import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.excel.core.util.ExcelUtils;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;

import com.cf.imes.module.system.controller.admin.funds.balancedetails.vo.BalanceDetailsPageReqVO;
import com.cf.imes.module.system.controller.admin.funds.balancedetails.vo.BalanceDetailsRespVO;
import com.cf.imes.module.system.service.funds.incomeandexpense.IncomeExpenseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

import static com.cf.imes.framework.common.pojo.CommonResult.success;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

/**
 * @author 组织余额明细
 */
@Tag(name = "管理后台 - 组织余额明细")
@RestController
@RequestMapping("/system/balance")
@Validated
public class BalanceDetailsController {


    @Resource
    private IncomeExpenseService incomeExpenseService;

    @GetMapping("")
    @Operation(summary = "查询组织余额明细分页")
    public CommonResult<PageResult<BalanceDetailsRespVO>> getBalanceDetailsPage(@Valid BalanceDetailsPageReqVO pageReqVO) {
        return success(incomeExpenseService.getBalanceDetailsPage(pageReqVO));
    }




    @GetMapping("/export")
    @Operation(summary = "组织余额明细导出")
    @OperateLog(type = EXPORT)
    public void balanceDetailsExport(@Valid BalanceDetailsPageReqVO pageReqVO,
                                     HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<BalanceDetailsRespVO> list = incomeExpenseService.getBalanceDetailsPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "余额明细表.xls", "数据", BalanceDetailsRespVO.class,
                BeanUtils.toBean(list, BalanceDetailsRespVO.class));
    }
}
