package com.cf.imes.module.executor.controller.admin.funds.bill;


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.excel.core.util.ExcelUtils;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import com.cf.imes.module.executor.controller.admin.funds.balancedetails.vo.BalanceDetailsPageReqVO;
import com.cf.imes.module.executor.controller.admin.funds.bill.vo.BillDetailsRespVO;
import com.cf.imes.module.executor.service.funds.bill.BillService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
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 jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
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("/executor/bill")
@Validated
public class BillController {


    @Resource
    private BillService billService;



    @GetMapping("")
    @Operation(summary = "获取组织账单明细")
    public CommonResult<PageResult<BillDetailsRespVO>> getBillDetailsPage(@Valid BalanceDetailsPageReqVO pageReqVO) {

        return success(billService.getBillDetailsPage(pageReqVO));

    }




    @GetMapping("/export")
    @Operation(summary = "组织账单明细下载")
    @OperateLog(type = EXPORT)
    public void billDetailsExport(@Valid BalanceDetailsPageReqVO pageReqVO,
                                  HttpServletResponse response) throws IOException {

        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<BillDetailsRespVO> list = billService.getBillDetailsPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "余额明细表.xls", "数据", BillDetailsRespVO.class,list);

    }



}
