package com.cooleshow.teacher.presenter.income;

import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.bean.AccountTotalBean;
import com.cooleshow.teacher.contract.EarningStatisticsContract;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 创建日期：2022/6/1 18:00
 *
 * @author Ryan
 * 类说明：
 */
public class EarningStatisticsPresenter extends BasePresenter<EarningStatisticsContract.EarningStatisticsView> implements EarningStatisticsContract.Presenter {

    public void accountTotal(String dateTime,String timeType) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("dateTime", dateTime);
            jsonObject.putOpt("timeType", timeType);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).accountTotal(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<AccountTotalBean>(getView()) {
            @Override
            protected void onSuccess(AccountTotalBean data) {
                if (getView() != null) {
                    getView().accountTotalSuccess(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);

            }
        });
    }

}
