|
|
@@ -1,6 +1,208 @@
|
|
|
package com.tongyu.luck.happywork.ui.mvp.cclient.model;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.tongyu.luck.happywork.AppCacheManager;
|
|
|
+import com.tongyu.luck.happywork.baselibrary.IntentConstant;
|
|
|
+import com.tongyu.luck.happywork.baselibrary.utils.DateUtils;
|
|
|
+import com.tongyu.luck.happywork.baselibrary.utils.SharedPreferencesUtils;
|
|
|
+import com.tongyu.luck.happywork.bean.ClockSettlementBean;
|
|
|
+import com.tongyu.luck.happywork.bean.api.ApiClockSettlementBean;
|
|
|
+import com.tongyu.luck.happywork.bean.api.ApiLoginBean;
|
|
|
+import com.tongyu.luck.happywork.callback.MvpDataCallBack;
|
|
|
+import com.tongyu.luck.happywork.http.ApiObserver;
|
|
|
+import com.tongyu.luck.happywork.http.RetrofitHttpParams;
|
|
|
+import com.tongyu.luck.happywork.http.exception.ApiException;
|
|
|
+import com.tongyu.luck.happywork.http.subscribe.ClockSubscribe;
|
|
|
+import com.tongyu.luck.happywork.http.subscribe.LoginSubscribe;
|
|
|
+import com.tongyu.luck.happywork.ui.activity.cclient.clock.ClockUserStatisticsActivity;
|
|
|
+import com.tongyu.luck.happywork.ui.base.BaseModel;
|
|
|
import com.tongyu.luck.happywork.ui.mvp.cclient.contacts.ClockUserStatisticsContacts;
|
|
|
|
|
|
-public class ClockUserStatisticsModel implements ClockUserStatisticsContacts.IClockUserStatisticsModel {
|
|
|
+public class ClockUserStatisticsModel extends BaseModel implements ClockUserStatisticsContacts.IClockUserStatisticsModel {
|
|
|
+ ClockSettlementBean monthBean;
|
|
|
+ ClockSettlementBean lastMonthBean;
|
|
|
+ ClockSettlementBean weekBean;
|
|
|
+ ClockSettlementBean lastWeekBean;
|
|
|
+
|
|
|
+ boolean isShowLastMonth;
|
|
|
+ boolean isShowLastWeek;
|
|
|
+
|
|
|
+ String monthData;
|
|
|
+
|
|
|
+
|
|
|
+ public ClockUserStatisticsModel(Context mContext) {
|
|
|
+ super(mContext);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取服务端用户数据
|
|
|
+ *
|
|
|
+ * @param callBack
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getHttpUserBean(final MvpDataCallBack<Boolean> callBack) {
|
|
|
+ RetrofitHttpParams params = new RetrofitHttpParams(mContext);
|
|
|
+ if (!SharedPreferencesUtils.isWeChatLogin(mContext))//非微信登录传1
|
|
|
+ params.put("login_type", "1");
|
|
|
+ new LoginSubscribe(mContext).requestUserInfoNew(params.getRequestParams(), new ApiObserver<ApiLoginBean>(mContext) {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(ApiLoginBean data) {
|
|
|
+ if (data != null) {
|
|
|
+ AppCacheManager.getInstance().setLoginModel(data.getHpUser());
|
|
|
+ AppCacheManager.getInstance().setMemberModel(data.getHpMember());
|
|
|
+ callBack.onData(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(ApiLoginBean data, ApiException exception) {
|
|
|
+ super.onError(data, exception);
|
|
|
+ callBack.onError(exception);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFinish() {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取周数据
|
|
|
+ *
|
|
|
+ * @param callBack
|
|
|
+ * @param isLastWeek
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getHttpWeekSettlement(final MvpDataCallBack<ClockSettlementBean> callBack, final boolean isLastWeek, boolean isInit) {
|
|
|
+ RetrofitHttpParams params = new RetrofitHttpParams(mContext);
|
|
|
+ params.put("week_type", isLastWeek ? 2 : 1);
|
|
|
+ new ClockSubscribe(mContext).getWeekSettlement(params.getRequestParams(), new ApiObserver<ApiClockSettlementBean>(mContext, !isInit) {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(ApiClockSettlementBean data) {
|
|
|
+ if (data != null && data.getCurrentSettlement() != null) {
|
|
|
+ if (isLastWeek)
|
|
|
+ lastWeekBean = data.getCurrentSettlement();
|
|
|
+ else
|
|
|
+ weekBean = data.getCurrentSettlement();
|
|
|
+ callBack.onData(data.getCurrentSettlement());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFinish() {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取月数据
|
|
|
+ *
|
|
|
+ * @param callBack
|
|
|
+ * @param isLastMonth
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getHttpMonthSettlement(final MvpDataCallBack<ClockSettlementBean> callBack, final boolean isLastMonth, boolean isInit) {
|
|
|
+ RetrofitHttpParams params = new RetrofitHttpParams(mContext);
|
|
|
+ params.put("month_type", isLastMonth ? 2 : 1);
|
|
|
+ new ClockSubscribe(mContext).getMonthSettlement(params.getRequestParams(), new ApiObserver<ApiClockSettlementBean>(mContext, !isInit) {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(ApiClockSettlementBean data) {
|
|
|
+ if (data != null && data.getCurrentSettlement() != null) {
|
|
|
+ if (isLastMonth)
|
|
|
+ lastMonthBean = data.getCurrentSettlement();
|
|
|
+ else
|
|
|
+ monthBean = data.getCurrentSettlement();
|
|
|
+ callBack.onData(data.getCurrentSettlement());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFinish() {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取本地的周数据
|
|
|
+ *
|
|
|
+ * @param isLastWeek
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ClockSettlementBean getWeekSettlement(boolean isLastWeek) {
|
|
|
+ return isLastWeek ? lastWeekBean : weekBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取本地的月数据
|
|
|
+ *
|
|
|
+ * @param isLastMonth
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ClockSettlementBean getMonthSettlement(boolean isLastMonth) {
|
|
|
+ return isLastMonth ? lastMonthBean : monthBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取周标题显示
|
|
|
+ *
|
|
|
+ * @param isLastWeek
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String getWeekTitle(boolean isLastWeek) {
|
|
|
+ return isLastWeek ? "上周" : "本周";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取月标题显示
|
|
|
+ *
|
|
|
+ * @param isLastMonth
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String getMonthTitle(boolean isLastMonth) {
|
|
|
+ if (TextUtils.isEmpty(monthData)) {
|
|
|
+ monthData = ((ClockUserStatisticsActivity) mContext).getIntent().getStringExtra(IntentConstant.CONTENT);
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(monthData)) {
|
|
|
+ if (isLastMonth) {
|
|
|
+ return DateUtils.getLastMonthStr(monthData);
|
|
|
+ } else {
|
|
|
+ return DateUtils.getFormatYMDStrToStr(monthData, "yyyy-MM");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判斷是否展示上月数据
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean isShowLastMonth() {
|
|
|
+ return isShowLastMonth;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setShowLastMonth(boolean showLastMonth) {
|
|
|
+ isShowLastMonth = showLastMonth;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判斷是否展示上周数据
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean isShowLastWeek() {
|
|
|
+ return isShowLastWeek;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setShowLastWeek(boolean showLastWeek) {
|
|
|
+ isShowLastWeek = showLastWeek;
|
|
|
+ }
|
|
|
}
|