|  |  |  | 
|---|
|  |  |  | package com.doumee.keyCabinet.ui.keyCabinet; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import android.app.Application; | 
|---|
|  |  |  | import android.text.TextUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import androidx.annotation.NonNull; | 
|---|
|  |  |  | import androidx.databinding.ObservableField; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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.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 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()) | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 { | 
|---|
|  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void batchOpenGridAdmin(List<Integer> gridIdList){ | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onNext(@NonNull BaseResponse response) { | 
|---|
|  |  |  | if(200==response.getCode()){ | 
|---|
|  |  |  | doAction(8); | 
|---|
|  |  |  | if(isAll) { | 
|---|
|  |  |  | toast("批量开门成功"); | 
|---|
|  |  |  | doAction(8); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | doAction(10); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | toast(response.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void cancelFault(List<Integer> gridIdList){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | showLoading(true); | 
|---|
|  |  |  | CancelFaultParam param = new CancelFaultParam(); | 
|---|
|  |  |  | param.setCabinetId(MApplication.getConfigBean().getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onNext(@NonNull BaseResponse response) { | 
|---|
|  |  |  | if(200==response.getCode()){ | 
|---|
|  |  |  | toast("标记柜格正常成功"); | 
|---|
|  |  |  | getCabinetDetail(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | toast(response.getMessage()); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onNext(@NonNull BaseResponse response) { | 
|---|
|  |  |  | if(200==response.getCode()){ | 
|---|
|  |  |  | toast("标记柜格故障成功"); | 
|---|
|  |  |  | getCabinetDetail(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | toast(response.getMessage()); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onNext(@NonNull BaseResponse response) { | 
|---|
|  |  |  | if(200==response.getCode()){ | 
|---|
|  |  |  | toast("标记维修保养成功"); | 
|---|
|  |  |  | getCabinetDetail(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | toast(response.getMessage()); | 
|---|
|  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 关门 | 
|---|
|  |  |  | * @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){ | 
|---|
|  |  |  | getCabinetDetail(); | 
|---|
|  |  |  | doAction(11); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onError(@NonNull Throwable e) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onComplete() { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public MutableLiveData<List<ManageKeyCabinetBean>> getDatasLD() { | 
|---|
|  |  |  | return datasLD; | 
|---|
|  |  |  | } | 
|---|