|  |  | 
 |  |  | package com.doumee.keyCabinet.ui.keyCabinet; | 
 |  |  |  | 
 |  |  | import android.app.Application; | 
 |  |  | import android.text.TextUtils; | 
 |  |  |  | 
 |  |  | import androidx.annotation.NonNull; | 
 |  |  | import androidx.databinding.ObservableField; | 
 |  |  | import androidx.hilt.lifecycle.ViewModelInject; | 
 |  |  | import androidx.lifecycle.MutableLiveData; | 
 |  |  |  | 
 |  |  | import com.doumee.keyCabinet.MApplication; | 
 |  |  | import com.doumee.keyCabinet.bean.CabinetDetailBean; | 
 |  |  | import com.doumee.keyCabinet.bean.LoginBean; | 
 |  |  | import com.doumee.keyCabinet.bean.ManageKeyCabinetBean; | 
 |  |  | import com.doumee.keyCabinet.dao.CabinetGridDo; | 
 |  |  | import com.doumee.keyCabinet.event.HttpEvent; | 
 |  |  | import com.doumee.keyCabinet.http.Apis; | 
 |  |  | import com.doumee.keyCabinet.http.param.BaseResponse; | 
 |  |  | import com.doumee.keyCabinet.http.param.BatchOpenGridAdminParam; | 
 |  |  | import com.doumee.keyCabinet.http.param.CancelFaultParam; | 
 |  |  | import com.doumee.keyCabinet.http.param.CloseGridParam; | 
 |  |  | import com.doumee.keyCabinet.http.param.MarkFaultParam; | 
 |  |  | import com.doumee.keyCabinet.http.param.MarkRepairParam; | 
 |  |  | import com.doumee.keyCabinet.utils.ParamsUtil; | 
 |  |  | import com.doumee.lib_coremodel.base.BaseModel; | 
 |  |  | import com.doumee.lib_coremodel.base.DataViewModel; | 
 |  |  | import com.doumee.lib_coremodel.http.rxJava.SimpleObserver; | 
 |  |  | import com.doumee.lib_coremodel.http.utils.RxUtils; | 
 |  |  |  | 
 |  |  | import org.greenrobot.eventbus.EventBus; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | public class ManageCabinetVM extends DataViewModel { | 
 |  |  |     public ObservableField<CabinetDetailBean> dataOb = new ObservableField<>(); | 
 |  |  |     private MutableLiveData<List<ManageKeyCabinetBean>> datasLD = new MutableLiveData<>(); | 
 |  |  |  | 
 |  |  |     @ViewModelInject | 
 |  |  |     public ManageCabinetVM(@NonNull Application application, BaseModel model) { | 
 |  |  |         super(application, model); | 
 |  |  | 
 |  |  |     protected void clickByTypeCommand(int type) { | 
 |  |  |         doAction(type); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void getCabinetDetail(){ | 
 |  |  |         /*CabinetDetailBean bean = new CabinetDetailBean(); | 
 |  |  |         bean.setGridNum(24); | 
 |  |  |         bean.setOnlineKeyNum(1); | 
 |  |  |         bean.setOutKeyNum(2); | 
 |  |  |         bean.setErrGridNum(3); | 
 |  |  |         bean.setServiceKeyNum(4); | 
 |  |  |         bean.setUnBindGridNum(5); | 
 |  |  |         dataOb.set(bean); | 
 |  |  |         List<ManageKeyCabinetBean> datas = new ArrayList<>(); | 
 |  |  |         for(int i=1;i<=16;i++){ | 
 |  |  |             ManageKeyCabinetBean b = new ManageKeyCabinetBean(); | 
 |  |  |             b.setBindStatus(0); | 
 |  |  |             b.setBoardCode("1"); | 
 |  |  |             b.setCarCode("车牌"+i); | 
 |  |  |             b.setChannelCode(i+""); | 
 |  |  |             b.setCode("A柜"+i); | 
 |  |  |             b.setId(i); | 
 |  |  |             b.setKeyStatus(0); | 
 |  |  |             b.setKeyCode(null); | 
 |  |  |             b.setStatus(0); | 
 |  |  |             b.setWorkingStatus(0); | 
 |  |  |             datas.add(b); | 
 |  |  |         } | 
 |  |  |         for(int i=17;i<=24;i++){ | 
 |  |  |             ManageKeyCabinetBean b = new ManageKeyCabinetBean(); | 
 |  |  |             b.setBindStatus(0); | 
 |  |  |             b.setBoardCode("2"); | 
 |  |  |             b.setCarCode("车牌"+i); | 
 |  |  |             b.setChannelCode((i-16)+""); | 
 |  |  |             b.setCode("B柜"+i); | 
 |  |  |             b.setId(i); | 
 |  |  |             b.setKeyStatus(0); | 
 |  |  |             b.setKeyCode(null); | 
 |  |  |             b.setStatus(0); | 
 |  |  |             b.setWorkingStatus(0); | 
 |  |  |             datas.add(b); | 
 |  |  |         } | 
 |  |  |         ManageKeyCabinetBean b1 = datas.get(0); | 
 |  |  |         b1.setKeyCode("C97B092F"); | 
 |  |  |         b1.setKeyStatus(1); | 
 |  |  |         b1.setBindStatus(1); | 
 |  |  |  | 
 |  |  |         ManageKeyCabinetBean b2 = datas.get(1); | 
 |  |  |         b2.setKeyStatus(2); | 
 |  |  |         b2.setBindStatus(1); | 
 |  |  |  | 
 |  |  |         ManageKeyCabinetBean b3 = datas.get(2); | 
 |  |  |         b3.setKeyStatus(3); | 
 |  |  |         b3.setBindStatus(1); | 
 |  |  |  | 
 |  |  |         ManageKeyCabinetBean b4 = datas.get(3); | 
 |  |  |         b4.setKeyStatus(1); | 
 |  |  |         b4.setWorkingStatus(1); | 
 |  |  |         b4.setBindStatus(1); | 
 |  |  |  | 
 |  |  |         datasLD.setValue(datas);*/ | 
 |  |  |  | 
 |  |  |         showLoading(true); | 
 |  |  |         getRetrofitService(Apis.class).getCabinetDetail(MApplication.getLoginBean().getToken(), | 
 |  |  |                         MApplication.getConfigBean().getId()) | 
 |  |  |                 .compose(RxUtils.schedulersTransformer()) | 
 |  |  |                 .subscribe(new SimpleObserver<BaseResponse<CabinetDetailBean>>(rxJavaGcManager) { | 
 |  |  |                     @Override | 
 |  |  |                     public void onNext(@NonNull BaseResponse<CabinetDetailBean> response) { | 
 |  |  |                         if(200==response.getCode()){ | 
 |  |  |                             dataOb.set(response.getData()); | 
 |  |  |                             if(response.getData()!=null){ | 
 |  |  |                                 MApplication.getLoginBean().setMemberId(response.getData().getMemberId()); | 
 |  |  |                                 if(response.getData().getCabinetGridInfoVOList()!=null){ | 
 |  |  |                                     datasLD.setValue(response.getData().getCabinetGridInfoVOList()); | 
 |  |  |                                 }else { | 
 |  |  |                                     datasLD.setValue(new ArrayList<>()); | 
 |  |  |                                 } | 
 |  |  |                             }else { | 
 |  |  |                                 datasLD.setValue(new ArrayList<>()); | 
 |  |  |                             } | 
 |  |  |                         }else { | 
 |  |  |                             toast(response.getMessage()); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onError(@NonNull Throwable e) { | 
 |  |  |                         toast(e.getMessage()); | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onComplete() { | 
 |  |  |                         hideLoading(); | 
 |  |  |                     } | 
 |  |  |                 }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void batchOpenGridAdmin(List<Integer> gridIdList,boolean isAll){ | 
 |  |  |         /*if(isAll) { | 
 |  |  |             doAction(8); | 
 |  |  |         }else { | 
 |  |  |             doAction(10); | 
 |  |  |         } | 
 |  |  |         if(true){ | 
 |  |  |             return; | 
 |  |  |         }*/ | 
 |  |  |         showLoading(true); | 
 |  |  |         BatchOpenGridAdminParam param = new BatchOpenGridAdminParam(); | 
 |  |  |         param.setCabinetId(MApplication.getConfigBean().getId()); | 
 |  |  |         param.setGridIdList(gridIdList); | 
 |  |  |         getRetrofitService(Apis.class).batchOpenGridAdmin(MApplication.getLoginBean().getToken(), | 
 |  |  |                         ParamsUtil.encodeRequestBody(param)) | 
 |  |  |                 .compose(RxUtils.schedulersTransformer()) | 
 |  |  |                 .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { | 
 |  |  |                     @Override | 
 |  |  |                     public void onNext(@NonNull BaseResponse response) { | 
 |  |  |                         if(200==response.getCode()){ | 
 |  |  |                             EventBus.getDefault().post(new HttpEvent("批量开门 - 管理员接口成功")); | 
 |  |  |                             if(isAll) { | 
 |  |  |                                 doAction(8); | 
 |  |  |                             }else { | 
 |  |  |                                 doAction(10); | 
 |  |  |                             } | 
 |  |  |                         }else { | 
 |  |  |                             toast(response.getMessage()); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onError(@NonNull Throwable e) { | 
 |  |  |                         toast(e.getMessage()); | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onComplete() { | 
 |  |  |                         hideLoading(); | 
 |  |  |                     } | 
 |  |  |                 }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void cancelFault(List<Integer> gridIdList){ | 
 |  |  |  | 
 |  |  |         showLoading(true); | 
 |  |  |         CancelFaultParam param = new CancelFaultParam(); | 
 |  |  |         param.setCabinetId(MApplication.getConfigBean().getId()); | 
 |  |  |         param.setGridIdList(gridIdList); | 
 |  |  |         getRetrofitService(Apis.class).cancelFault(MApplication.getLoginBean().getToken(), | 
 |  |  |                         ParamsUtil.encodeRequestBody(param)) | 
 |  |  |                 .compose(RxUtils.schedulersTransformer()) | 
 |  |  |                 .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { | 
 |  |  |                     @Override | 
 |  |  |                     public void onNext(@NonNull BaseResponse response) { | 
 |  |  |                         EventBus.getDefault().post(new HttpEvent("标记柜格正常接口成功")); | 
 |  |  |                         if(200==response.getCode()){ | 
 |  |  |                             getCabinetDetail(); | 
 |  |  |                         }else { | 
 |  |  |                             toast(response.getMessage()); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onError(@NonNull Throwable e) { | 
 |  |  |                         toast(e.getMessage()); | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onComplete() { | 
 |  |  |                         hideLoading(); | 
 |  |  |                     } | 
 |  |  |                 }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void markFault(List<Integer> gridIdList){ | 
 |  |  |         showLoading(true); | 
 |  |  |         MarkFaultParam param = new MarkFaultParam(); | 
 |  |  |         param.setCabinetId(MApplication.getConfigBean().getId()); | 
 |  |  |         param.setGridIdList(gridIdList); | 
 |  |  |         getRetrofitService(Apis.class).markFault(MApplication.getLoginBean().getToken(), | 
 |  |  |                         ParamsUtil.encodeRequestBody(param)) | 
 |  |  |                 .compose(RxUtils.schedulersTransformer()) | 
 |  |  |                 .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { | 
 |  |  |                     @Override | 
 |  |  |                     public void onNext(@NonNull BaseResponse response) { | 
 |  |  |                         if(200==response.getCode()){ | 
 |  |  |                             EventBus.getDefault().post(new HttpEvent("标记柜格故障接口成功")); | 
 |  |  |                             getCabinetDetail(); | 
 |  |  |                         }else { | 
 |  |  |                             toast(response.getMessage()); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onError(@NonNull Throwable e) { | 
 |  |  |                         toast(e.getMessage()); | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onComplete() { | 
 |  |  |                         hideLoading(); | 
 |  |  |                     } | 
 |  |  |                 }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void markRepair(List<Integer> gridIdList){ | 
 |  |  |         showLoading(true); | 
 |  |  |         MarkRepairParam param = new MarkRepairParam(); | 
 |  |  |         param.setCabinetId(MApplication.getConfigBean().getId()); | 
 |  |  |         param.setGridIdList(gridIdList); | 
 |  |  |         getRetrofitService(Apis.class).markRepair(MApplication.getLoginBean().getToken(), | 
 |  |  |                         ParamsUtil.encodeRequestBody(param)) | 
 |  |  |                 .compose(RxUtils.schedulersTransformer()) | 
 |  |  |                 .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { | 
 |  |  |                     @Override | 
 |  |  |                     public void onNext(@NonNull BaseResponse response) { | 
 |  |  |                         if(200==response.getCode()){ | 
 |  |  |                             EventBus.getDefault().post(new HttpEvent("标记维修保养接口成功")); | 
 |  |  |                             getCabinetDetail(); | 
 |  |  |                         }else { | 
 |  |  |                             toast(response.getMessage()); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onError(@NonNull Throwable e) { | 
 |  |  |                         toast(e.getMessage()); | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onComplete() { | 
 |  |  |                         hideLoading(); | 
 |  |  |                     } | 
 |  |  |                 }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 关门 | 
 |  |  |      * @param gridDo | 
 |  |  |      */ | 
 |  |  |     public void closeGrid(CabinetGridDo gridDo){ | 
 |  |  |         CloseGridParam param = new CloseGridParam(); | 
 |  |  |         LoginBean loginBean = MApplication.getLoginBean(); | 
 |  |  |         param.setCabinetId(MApplication.getConfigBean().getId()); | 
 |  |  |         param.setAuthType(loginBean.getAuthType()); | 
 |  |  |         param.setMemberId(loginBean.getMemberId()); | 
 |  |  |         param.setGridId(gridDo.getGridId()); | 
 |  |  |         param.setKeyStatus(!TextUtils.isEmpty(gridDo.getCurKeyCode())?1:2); | 
 |  |  |         toast(gridDo.getGridKey()+"关闭,当前钥匙号:"+gridDo.getCurKeyCode()); | 
 |  |  |         getRetrofitService(Apis.class).closeGrid(ParamsUtil.encodeRequestBody(param)) | 
 |  |  |                 .compose(RxUtils.schedulersTransformer()) | 
 |  |  |                 .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { | 
 |  |  |                     @Override | 
 |  |  |                     public void onNext(@NonNull BaseResponse response) { | 
 |  |  |                         if(response.getCode()==200){ | 
 |  |  |                             EventBus.getDefault().post(new HttpEvent("关闭柜格接口成功")); | 
 |  |  |                             getCabinetDetail(); | 
 |  |  |                             doAction(11); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onError(@NonNull Throwable e) { | 
 |  |  |  | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     @Override | 
 |  |  |                     public void onComplete() { | 
 |  |  |  | 
 |  |  |                     } | 
 |  |  |                 }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public MutableLiveData<List<ManageKeyCabinetBean>> getDatasLD() { | 
 |  |  |         return datasLD; | 
 |  |  |     } | 
 |  |  | } |