From 82e57df230ecb744af6c8865f80870ba03c86d89 Mon Sep 17 00:00:00 2001
From: Linjiajia <319408893@qq.com>
Date: 星期二, 25 七月 2023 22:18:27 +0800
Subject: [PATCH] 基本功能完成

---
 app/src/main/java/com/application/zhangshi_app_android/ui/function/AnnualHealthStatusActivityViewModel.java |  326 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 308 insertions(+), 18 deletions(-)

diff --git a/app/src/main/java/com/application/zhangshi_app_android/ui/function/AnnualHealthStatusActivityViewModel.java b/app/src/main/java/com/application/zhangshi_app_android/ui/function/AnnualHealthStatusActivityViewModel.java
index e47e190..858180e 100644
--- a/app/src/main/java/com/application/zhangshi_app_android/ui/function/AnnualHealthStatusActivityViewModel.java
+++ b/app/src/main/java/com/application/zhangshi_app_android/ui/function/AnnualHealthStatusActivityViewModel.java
@@ -1,17 +1,33 @@
 package com.application.zhangshi_app_android.ui.function;
 
+import static com.android.app_base.base.BaseConfig.CODE_SUCCESS;
+
 import android.app.Application;
+import android.text.TextUtils;
 
 import androidx.annotation.NonNull;
+import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
 
+import com.android.app_base.base.StateViewEnum;
 import com.android.app_base.base.viewmodel.BaseViewModel;
+import com.android.app_base.http.ResultData;
+import com.android.app_base.utils.RxUtils;
+import com.android.app_base.utils.Utils;
 import com.application.zhangshi_app_android.bean.AnnualHealthStatusBean;
-import com.application.zhangshi_app_android.bean.CleanStorageBean;
+import com.application.zhangshi_app_android.bean.AnnualHealthStatusRequestBean;
+import com.application.zhangshi_app_android.bean.PageResponseBean;
+import com.application.zhangshi_app_android.bean.AnnualHealthStatusBean;
+import com.application.zhangshi_app_android.bean.AnnualHealthStatusRequestBean;
 import com.application.zhangshi_app_android.data.DataRepository;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
+
+import io.reactivex.Observer;
+import io.reactivex.disposables.Disposable;
+import io.reactivex.functions.Action;
 
 /**
  * @author Ljj
@@ -20,7 +36,12 @@
  */
 public class AnnualHealthStatusActivityViewModel extends BaseViewModel<DataRepository> {
     private MutableLiveData<List<AnnualHealthStatusBean>> dataListLiveData;
+    private MutableLiveData<List<AnnualHealthStatusBean>> checkListLiveData;//閫変腑鐨勬暟鎹�
+    private MutableLiveData<List<AnnualHealthStatusBean>> moreListLiveData;//涓嬫媺鍔犺浇鏁版嵁
+    private MutableLiveData<AnnualHealthStatusRequestBean> requestBeanLiveData;//璇锋眰鍙傛暟
+    private MutableLiveData<List<AnnualHealthStatusBean>> finishDeleteListLiveData;//宸茬粡瀹屾垚鍒犻櫎鐨勬暟鎹紝鐢ㄤ簬adapter鐨剅emove鎿嶄綔
 
+    private MutableLiveData<Integer> operateTypeLiveData;//鎿嶄綔绫诲瀷 0 閫夋嫨鎿嶄綔 1.瀹屾垚 2.鍒犻櫎
     public AnnualHealthStatusActivityViewModel(@NonNull Application application) {
         super(application);
     }
@@ -30,8 +51,207 @@
         return DataRepository.getInstance();
     }
 
+    /**
+     *  鑾峰彇骞村害鍋ュ悍鎯呭喌
+     */
+    public void getAnnualHealthStatus() {
+        if (getRequestBeanLiveData().getValue() == null){
+            getRequestBeanLiveData().setValue(new AnnualHealthStatusRequestBean());
+        }
+        getRequestBeanLiveData().getValue().setPageNum(1);
+        model.getAnnualHealthStatus(getRequestBeanLiveData().getValue().toMap())
+                .compose(RxUtils.schedulersTransformer())
+                .subscribe(new Observer<ResultData<PageResponseBean<AnnualHealthStatusBean>>>() {
+                    @Override
+                    public void onSubscribe(Disposable d) {
+                        addSubscribe(d);
+                    }
+
+                    @Override
+                    public void onNext(ResultData<PageResponseBean<AnnualHealthStatusBean>> data) {
+                        if (data.getCode() == CODE_SUCCESS){
+                            if (data.getData().getData().isEmpty()){
+                                changeStateView(StateViewEnum.DATA_NULL);
+                            }else {
+                                changeStateView(StateViewEnum.HIDE);
+                                dataListLiveData.postValue(data.getData().getData());
+                            }
+                        }else {
+                            messageLiveData.postValue(data.getMsg());
+                        }
+                    }
+
+                    @Override
+                    public void onError(Throwable e) {
+                        messageLiveData.postValue(e.getMessage());
+                    }
+
+                    @Override
+                    public void onComplete() {
+
+                    }
+                });
+    }
+    /**
+     * 鍔犺浇鏇村
+     */
+    public void getMoreAnnualHealthStatus() {
+        if (true){
+            changeStateView(StateViewEnum.DATA_NULL);
+            return;
+        }
+        if (getRequestBeanLiveData().getValue() == null){
+            getRequestBeanLiveData().setValue(new AnnualHealthStatusRequestBean());
+        }
+        getRequestBeanLiveData().getValue().setPageNum(getRequestBeanLiveData().getValue().getPageNum() + 1);
+        model.getAnnualHealthStatus(getRequestBeanLiveData().getValue().toMap())
+                .compose(RxUtils.schedulersTransformer())
+                .doFinally(new Action() {
+                    @Override
+                    public void run() throws Exception {
+                        changeStateView(StateViewEnum.DATA_FINISH);
+                    }
+                })
+                .subscribe(new Observer<ResultData<PageResponseBean<AnnualHealthStatusBean>>>() {
+                    @Override
+                    public void onSubscribe(Disposable d) {
+                        addSubscribe(d);
+                    }
+
+                    @Override
+                    public void onNext(ResultData<PageResponseBean<AnnualHealthStatusBean>> data) {
+                        if (data.getCode() == CODE_SUCCESS){
+                            if (data.getData().getData().isEmpty()){
+                                messageLiveData.postValue("娌℃湁鏇村鏁版嵁浜�");
+                            }else {
+                                changeStateView(StateViewEnum.HIDE);
+                                moreListLiveData.postValue(data.getData().getData());
+                            }
+                        }else {
+                            messageLiveData.postValue(data.getMsg());
+                        }
+                    }
+
+                    @Override
+                    public void onError(Throwable e) {
+                        messageLiveData.postValue(e.getMessage());
+                    }
+
+                    @Override
+                    public void onComplete() {
+
+                    }
+                });
+    }
+    /**
+     * 鍒犻櫎澶氶�夐�変腑鐨勬暟鎹�
+     */
+    public void deleteCheckList() {
+        List<AnnualHealthStatusBean> deleteList = getCheckListLiveData().getValue();
+        if (deleteList == null){
+            return;
+        }
+        StringBuffer sb = new StringBuffer();
+        deleteList.forEach(AnnualHealthStatusBean -> sb.append(AnnualHealthStatusBean.getId()).append(","));
+        sb.deleteCharAt(sb.length()-1);
+        model.deleteAnnualHealthStatus(sb.toString())
+                .compose(RxUtils.schedulersTransformer())
+                .subscribe(new Observer<ResultData<String>>() {
+                    @Override
+                    public void onSubscribe(Disposable d) {
+                        addSubscribe(d);
+                    }
+
+                    @Override
+                    public void onNext(ResultData<String> stringResultData) {
+                        if (stringResultData.getCode() == CODE_SUCCESS){
+                            finishDeleteListLiveData.postValue(checkListLiveData.getValue());
+                            messageLiveData.postValue("鍒犻櫎鎴愬姛");
+                            getCheckListLiveData().postValue(new ArrayList<>());
+                        }else {
+                            messageLiveData.postValue(stringResultData.getMsg());
+                        }
+                    }
+
+                    @Override
+                    public void onError(Throwable e) {
+                        messageLiveData.postValue(e.getMessage());
+                    }
+
+                    @Override
+                    public void onComplete() {
+
+                    }
+                });
+    }
+    /**
+     * 鍒犻櫎鍗曚釜鏁版嵁
+     */
+    public void deleteItem(AnnualHealthStatusBean AnnualHealthStatusBean) {
+        model.deleteAnnualHealthStatus(String.valueOf(AnnualHealthStatusBean.getId()))
+                .compose(RxUtils.schedulersTransformer())
+                .subscribe(new Observer<ResultData<String>>() {
+                    @Override
+                    public void onSubscribe(Disposable d) {
+                        addSubscribe(d);
+                    }
+
+                    @Override
+                    public void onNext(ResultData<String> stringResultData) {
+                        if (stringResultData.getCode() == CODE_SUCCESS){
+                            List<AnnualHealthStatusBean> list = new ArrayList<>();
+                            list.add(AnnualHealthStatusBean);
+                            finishDeleteListLiveData.postValue(list);
+                            messageLiveData.postValue("鍒犻櫎鎴愬姛");
+                        }else {
+                            messageLiveData.postValue(stringResultData.getMsg());
+                        }
+                    }
+
+                    @Override
+                    public void onError(Throwable e) {
+                        messageLiveData.postValue(e.getMessage());
+                    }
+
+                    @Override
+                    public void onComplete() {
+
+                    }
+                });
+    }
+
+    public MutableLiveData<List<AnnualHealthStatusBean>> getCheckListLiveData() {
+        if (checkListLiveData==null){
+            checkListLiveData = new MutableLiveData<>();
+            checkListLiveData.postValue(new ArrayList<>());
+        }
+        if (checkListLiveData.getValue() == null){
+            checkListLiveData.postValue(new ArrayList<>());
+        }
+        return checkListLiveData;
+    }
+
+    public void setCheckListLiveData(MutableLiveData<List<AnnualHealthStatusBean>> checkListLiveData) {
+        this.checkListLiveData = checkListLiveData;
+    }
+
+    @NonNull
+    public MutableLiveData<AnnualHealthStatusRequestBean> getRequestBeanLiveData() {
+        if (requestBeanLiveData == null){
+            requestBeanLiveData = new MutableLiveData<>();
+        }
+        if (requestBeanLiveData.getValue() == null){
+            requestBeanLiveData.setValue(new AnnualHealthStatusRequestBean());
+        }
+        return requestBeanLiveData;
+    }
+
+    public void setRequestBeanLiveData(MutableLiveData<AnnualHealthStatusRequestBean> requestBeanLiveData) {
+        this.requestBeanLiveData = requestBeanLiveData;
+    }
+
     public MutableLiveData<List<AnnualHealthStatusBean>> getDataListLiveData() {
-        if (dataListLiveData == null) {
+        if (dataListLiveData == null){
             dataListLiveData = new MutableLiveData<>();
         }
         return dataListLiveData;
@@ -41,22 +261,92 @@
         this.dataListLiveData = dataListLiveData;
     }
 
-    /**
-     *  鑾峰彇骞村害鍋ュ悍鎯呭喌
-     */
-    public void getAnnualHealthStatus() {
-        List<AnnualHealthStatusBean> beans =  new ArrayList<>();
-        for (int i = 0; i < 10; i++) {
-            AnnualHealthStatusBean bean = new AnnualHealthStatusBean();
-            bean.setId(i);
-            bean.setTime("2020-0" + i + "-01");
-            bean.setType("浣撴");
-            bean.setHospital("浜烘皯鍖婚櫌");
-            bean.setName("浣撴牸妫�鏌�");
-            bean.setAttention("娉ㄦ剰淇濆仴");
-            bean.setRemark("鍏ㄥ叏韬鏌�");
-            beans.add(bean);
+    @NonNull
+    public MutableLiveData<List<AnnualHealthStatusBean>> getMoreListLiveData() {
+        if (moreListLiveData == null){
+            moreListLiveData = new MutableLiveData<>();
         }
-        dataListLiveData.setValue(beans);
+        return moreListLiveData;
+    }
+
+    public void setMoreListLiveData(MutableLiveData<List<AnnualHealthStatusBean>> moreListLiveData) {
+        this.moreListLiveData = moreListLiveData;
+    }
+
+    @NonNull
+    public MutableLiveData<Integer> getOperateTypeLiveData() {
+        if (operateTypeLiveData == null){
+            operateTypeLiveData = new MutableLiveData<>();
+            operateTypeLiveData.setValue(0);
+        }
+        return operateTypeLiveData;
+    }
+
+    public void setOperateTypeLiveData(MutableLiveData<Integer> operateTypeLiveData) {
+        this.operateTypeLiveData = operateTypeLiveData;
+    }
+
+    public LiveData<List<AnnualHealthStatusBean>> getFinishDeleteListLiveData() {
+        if (finishDeleteListLiveData == null){
+            finishDeleteListLiveData = new MutableLiveData<>();
+        }
+        return finishDeleteListLiveData;
+    }
+
+    public void setFinishDeleteListLiveData(MutableLiveData<List<AnnualHealthStatusBean>> finishDeleteListLiveData) {
+        this.finishDeleteListLiveData = finishDeleteListLiveData;
+    }
+
+    /**
+     * 鏀瑰彉鎺掑簭
+     * @param b true 闄嶅簭 false 鍗囧簭
+     */
+    public void changeOrder(boolean b) {
+        List<AnnualHealthStatusBean> list = getDataListLiveData().getValue();
+        if (list == null || list.isEmpty()){
+            return;
+        }
+        if (b) {
+            // 浠庢柊鍒版棫锛宯ull鎺掓渶鍚�
+            list.sort((o1, o2) -> {
+                String happenTime1 = o1.getCheckTime();
+                String happenTime2 = o2.getCheckTime();
+                if (TextUtils.isEmpty(happenTime1) && TextUtils.isEmpty(happenTime2)) {
+                    return 0;
+                } else if (TextUtils.isEmpty(happenTime1)) {
+                    return 1;
+                } else if (TextUtils.isEmpty(happenTime2)) {
+                    return -1;
+                } else {
+                    Date date1 = Utils.parseDate(happenTime1);
+                    Date date2 = Utils.parseDate(happenTime2);
+                    if (date1 != null && date2 != null) {
+                        return date2.compareTo(date1);
+                    }
+                    return 0;
+                }
+            });
+        } else  {
+            // 浠庢棫鍒版柊锛宯ull鎺掓渶鍓�
+            list.sort((o1, o2) -> {
+                String happenTime1 = o1.getCheckTime();
+                String happenTime2 = o2.getCheckTime();
+                if (TextUtils.isEmpty(happenTime1) && TextUtils.isEmpty(happenTime2)) {
+                    return 0;
+                } else if (TextUtils.isEmpty(happenTime1)) {
+                    return -1;
+                } else if (TextUtils.isEmpty(happenTime2)) {
+                    return 1;
+                } else {
+                    Date date1 = Utils.parseDate(happenTime1);
+                    Date date2 = Utils.parseDate(happenTime2);
+                    if (date1 != null && date2 != null) {
+                        return date1.compareTo(date2);
+                    }
+                    return 0;
+                }
+            });
+        }
+        getDataListLiveData().setValue(list);
     }
 }

--
Gitblit v1.9.1