package com.tmerclub.cloud.order.controller.platform;

import com.tmerclub.cloud.api.user.dto.FinanceDetailDTO;
import com.tmerclub.cloud.api.user.vo.FinanceDetailExcelVO;
import com.tmerclub.cloud.api.user.vo.FinanceDetailVO;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.ExcelUtil;
import com.tmerclub.cloud.order.service.OrderFinanceService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 财务明细
 *
 * @author TRACK
 */
@RestController("platformOrderFinanceController")
@RequestMapping("/p/finance")
public class OrderFinanceController {

    @Autowired
    private OrderFinanceService orderFinanceService;

    @GetMapping("/get_finance_detail")
    @Operation(summary = "获取财务明细", description = "分页获取财务明细")
    public ServerResponseEntity<PageVO<FinanceDetailVO>> getFinanceDetail(@Valid PageDTO pageDTO, FinanceDetailDTO financeDetailDTO) {
        PageVO<FinanceDetailVO> pageFinanceDetail = orderFinanceService.pageFinanceDetail(pageDTO, financeDetailDTO);
        return ServerResponseEntity.success(pageFinanceDetail);
    }

    @GetMapping("/finance_detail_export")
    @Operation(summary = "导出excel", description = "导出财务明细")
    public ServerResponseEntity<Void> financeDetailExport(HttpServletResponse response, FinanceDetailDTO financeDetailDTO) {
        List<FinanceDetailExcelVO> list = orderFinanceService.listExcelFinanceDetail(financeDetailDTO);
        ExcelUtil.soleExcel(response, list, FinanceDetailExcelVO.EXCEL_NAME, FinanceDetailExcelVO.MERGE_ROW_INDEX, FinanceDetailExcelVO.MERGE_COLUMN_INDEX, FinanceDetailExcelVO.class);
        return ServerResponseEntity.success();
    }
}
