package com.ag.test;

import com.ag.entity.fee.face.IFeeBase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by yangxh on 2019/8/21.
 */
//@Service
public class MainModuleCall {
    private Log log = LogFactory.getLog(MainModuleCall.class);

    @Autowired
    private ApplicationContext ioc;

    private final String feeBeanName = "feeController";
    private final String mainParams = "mainParams";

    /**
     * 返回费用明细list
     * @return List<com.ag.entity.account.FeeDetail>
     */
    public String execute(JSONObject object, HttpServletResponse response, HttpServletRequest request){
        IFeeBase feeBase = (IFeeBase) ioc.getBean(feeBeanName);
        String source = object.getString(mainParams);
        log.error("callback source value============");
        log.error(source);
        String result = feeBase.callback(source);
        log.error("callback result value============");
        log.error(result);
        return result;
    }

    /**
     * 返回请求的数据源+费用明细list
     * @return List<com.ag.entity.fee.vo.SourceAndFeeDetail>
     *     SourceProperty + FeeDetail
     */
    public String callbackSource(JSONObject object, HttpServletResponse response, HttpServletRequest request){
        IFeeBase feeBase = (IFeeBase) ioc.getBean(feeBeanName);
        String source = object.getString(mainParams);
        log.error("callbackSource source value============");
        log.error(source);
        String result = feeBase.callbackSource(source);
        log.error("callbackSource result value============");
        log.error(result);
        return result;
    }
}
