package com.jwipc.finance.controller.rest;


import com.alibaba.fastjson2.JSON;
import com.jwipc.finance.logic.PaymentPlanSummaryLogic;
import com.jwipc.finance.model.query.PaymentPlanQuery;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

import static com.jwipc.finance.constant.ModuleConst.MODULE_ROOT;

/**
 * <p>
 *     对账模块-付款计划汇总 前端控制器
 * </p>
 *
 * @author 邓京术
 * @since 2025-07-22
 */
@RestController
@RequestMapping(MODULE_ROOT + "/payment/plan/summary/rest")
@RequiredArgsConstructor
public class PaymentPlanSummaryRestController {
    private final PaymentPlanSummaryLogic paymentPlanSummaryLogic;

    /**
     * 查询付款计划单汇总列表
     *
     * @param query 查询条件
     * @return 结果
     */
    @PostMapping("/list")
    public PageView list(PaymentPlanQuery query){
        if (LoginUtil.isSupplier()){
        //超级管理员排除
        } else if (LoginUtil.getName().equals("admin")){

        } else {
            query.setUserId(LoginUtil.getUserId());
        }
        return paymentPlanSummaryLogic.findByPage(query);
    }

    /**
     * 导出
     * @param exportFiled 导出的列信息
     * @param queryStr 查询条件
     */
    @PostMapping("/summaryExport")
    public void summaryExport(HttpServletResponse response, String exportFiled, String queryStr) throws
    IOException
    {
        PaymentPlanQuery basicPlanQuery = JSON.parseObject(queryStr, PaymentPlanQuery.class);
        paymentPlanSummaryLogic.exportPaymentPlanSumData(response,exportFiled,basicPlanQuery);
    }
}
