package com.bbitcn.silk.ui.activity;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.bbitcn.silk.base.BasePresenter;
import com.bbitcn.silk.model.net.Statistics;
import com.bbitcn.silk.utils.global.Global;
import com.bbitcn.silk.utils.log.MyLog;
import com.bbitcn.silk.utils.network.Url;
import com.bbitcn.silk.utils.network.XHttpManager;
import com.bbitcn.silk.utils.network.XHttpShorthand;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * @Author DuanKaiji
 * @CreateTime 2024年3月28日 10:06:01
 */
public class TotalActivityPresenter extends BasePresenter {
    private MutableLiveData<Statistics.DataDTO> queryListLiveData = new MutableLiveData<>();

    public MutableLiveData<Statistics.DataDTO> getQueryListLiveData() {
        return queryListLiveData;
    }



    public TotalActivityPresenter(@NonNull Application application) {
        super(application);
    }

    public void query( String startDate, String endDate) {
        showLoadingDialog("正在查询");
        RequestParams params = XHttpManager.getInstance().getRequestParams(Url.queryStatistics);
        params.addParameter("dtstart", startDate);
        params.addParameter("dtend", endDate);
        params.addParameter("depsysid", Global.getDepSysId() );
        x.http().post(params, new XHttpShorthand<Statistics>() {
            @Override
            public void success(Statistics model) {
                if (model.getResult()) {
                    MyLog.app("查询成功");
                    queryListLiveData.setValue(model.getData());
                } else {
                    MyLog.appError("查询失败");
                }
            }

            @Override
            public void error(Throwable e) {
                MyLog.appError("查询失败");
            }

            @Override
            public void myFinish() {
                super.myFinish();
                hideLoadingDialog();
            }
        });
    }
}
