|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import androidx.annotation.NonNull; | 
|---|
|  |  |  | import androidx.hilt.lifecycle.ViewModelInject; | 
|---|
|  |  |  | import androidx.lifecycle.MutableLiveData; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.doumee.keyCabinet.MApplication; | 
|---|
|  |  |  | import com.doumee.keyCabinet.bean.FaceUserBean; | 
|---|
|  |  |  | import com.doumee.keyCabinet.bean.KeyCabinetBean; | 
|---|
|  |  |  | import com.doumee.keyCabinet.http.Apis; | 
|---|
|  |  |  | import com.doumee.keyCabinet.http.param.BaseResponse; | 
|---|
|  |  |  | import com.doumee.keyCabinet.http.param.GetDriverGridParam; | 
|---|
|  |  |  | import com.doumee.keyCabinet.http.param.OpenGridDriverParam; | 
|---|
|  |  |  | 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.checkerframework.checker.units.qual.A; | 
|---|
|  |  |  | import org.greenrobot.eventbus.EventBus; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Random; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class KeyCabinetVM extends DataViewModel { | 
|---|
|  |  |  | private MutableLiveData<List<KeyCabinetBean>> datasLD = new MutableLiveData<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ViewModelInject | 
|---|
|  |  |  | public KeyCabinetVM(@NonNull Application application, BaseModel model) { | 
|---|
|  |  |  | super(application, model); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void clickByTypeCommand(int type) { | 
|---|
|  |  |  | doAction(type); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void getDatas(){ | 
|---|
|  |  |  | /*List<KeyCabinetBean> list = new ArrayList<>(); | 
|---|
|  |  |  | KeyCabinetBean b1 = new KeyCabinetBean(); | 
|---|
|  |  |  | b1.setCabinetName("A01"); | 
|---|
|  |  |  | b1.setCarCode("苏A18829"); | 
|---|
|  |  |  | list.add(b1); | 
|---|
|  |  |  | KeyCabinetBean b2 = new KeyCabinetBean(); | 
|---|
|  |  |  | b2.setCabinetName("A02"); | 
|---|
|  |  |  | b2.setCarCode("苏A18820"); | 
|---|
|  |  |  | list.add(b2); | 
|---|
|  |  |  | datasLD.setValue(list);*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GetDriverGridParam param = new GetDriverGridParam(); | 
|---|
|  |  |  | param.setType(MApplication.getLoginBean().getFlag()); | 
|---|
|  |  |  | param.setCabinetId(MApplication.getConfigBean().getId()); | 
|---|
|  |  |  | param.setMemberId(MApplication.getLoginBean().getMemberId()); | 
|---|
|  |  |  | param.setAutoMemberId(MApplication.getLoginBean().getAutoMemberId()); | 
|---|
|  |  |  | showLoading(true); | 
|---|
|  |  |  | getRetrofitService(Apis.class).getDriverGrid(ParamsUtil.encodeRequestBody(param)) | 
|---|
|  |  |  | .compose(RxUtils.schedulersTransformer()) | 
|---|
|  |  |  | .subscribe(new SimpleObserver<BaseResponse<List<KeyCabinetBean>>>(rxJavaGcManager) { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onNext(@NonNull BaseResponse<List<KeyCabinetBean>> response) { | 
|---|
|  |  |  | if(200==response.getCode()){ | 
|---|
|  |  |  | //查询数据 | 
|---|
|  |  |  | if(response.getData()!=null&&response.getData().size()>0){ | 
|---|
|  |  |  | datasLD.setValue(response.getData()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | toast(response.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onError(@NonNull Throwable e) { | 
|---|
|  |  |  | toast(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onComplete() { | 
|---|
|  |  |  | hideLoading(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void openGridDriver(KeyCabinetBean selectBean){ | 
|---|
|  |  |  | OpenGridDriverParam param = new OpenGridDriverParam(); | 
|---|
|  |  |  | param.setCabinetId(selectBean.getCabinetId()); | 
|---|
|  |  |  | param.setGridId(selectBean.getId()); | 
|---|
|  |  |  | param.setMemberId(MApplication.getLoginBean().getMemberId()); | 
|---|
|  |  |  | param.setAuthType(MApplication.getLoginBean().getAuthType()); | 
|---|
|  |  |  | showLoading(true); | 
|---|
|  |  |  | getRetrofitService(Apis.class).openGridDriver(ParamsUtil.encodeRequestBody(param)) | 
|---|
|  |  |  | .compose(RxUtils.schedulersTransformer()) | 
|---|
|  |  |  | .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onNext(@NonNull BaseResponse response) { | 
|---|
|  |  |  | if(200==response.getCode()){ | 
|---|
|  |  |  | //开门 | 
|---|
|  |  |  | doAction(2); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | toast(response.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onError(@NonNull Throwable e) { | 
|---|
|  |  |  | toast(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onComplete() { | 
|---|
|  |  |  | hideLoading(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public MutableLiveData<List<KeyCabinetBean>> getDatasLD() { | 
|---|
|  |  |  | return datasLD; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|