| | |
| | | import com.doumee.keyCabinet.bean.CabinetFaceBean; |
| | | import com.doumee.keyCabinet.bean.DevConfigBean; |
| | | import com.doumee.keyCabinet.bean.FaceUserBean; |
| | | import com.doumee.keyCabinet.bean.KeyCabinetBean; |
| | | import com.doumee.keyCabinet.bean.LoginBean; |
| | | import com.doumee.keyCabinet.bean.ManageKeyCabinetBean; |
| | | import com.doumee.keyCabinet.dao.CabinetGridDo; |
| | | import com.doumee.keyCabinet.dao.DaoManager; |
| | | import com.doumee.keyCabinet.event.DevConfigEvent; |
| | | 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.CloseGridParam; |
| | | import com.doumee.keyCabinet.http.param.DevErrInfoParam; |
| | | import com.doumee.keyCabinet.http.param.DevLoginParam; |
| | | import com.doumee.keyCabinet.http.param.FaceUserParam; |
| | | import com.doumee.keyCabinet.http.param.RequestBaseObject; |
| | | import com.doumee.keyCabinet.http.param.SyncGridDataParam; |
| | | import com.doumee.keyCabinet.http.param.TimeOutUnCloseAlarmParam; |
| | | import com.doumee.keyCabinet.utils.BraceletLogUtils; |
| | | import com.doumee.keyCabinet.utils.LMobileInfo; |
| | | import com.doumee.keyCabinet.utils.LanguageUtil; |
| | | import com.doumee.keyCabinet.utils.ParamsUtil; |
| | | import com.doumee.keyCabinet.utils.i485.SportUtils; |
| | | 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.GsonTools; |
| | | import com.doumee.lib_coremodel.http.utils.RxUtils; |
| | | import com.doumee.lib_coremodel.util.SpUtil; |
| | | import com.doumee.lib_coremodel.util.StringUtil; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | import okhttp3.Headers; |
| | | import retrofit2.Response; |
| | | |
| | | public class MainVM extends DataViewModel { |
| | | public ObservableField<String> dayObs = new ObservableField<>(""); |
| | | public ObservableField<String> timeObs = new ObservableField<>(""); |
| | |
| | | |
| | | private MutableLiveData<List<FaceUserBean>> faceLD = new MutableLiveData<>(); |
| | | private MutableLiveData<DevConfigBean> confidLD = new MutableLiveData<>(); |
| | | |
| | | private boolean isSubmit = false; |
| | | |
| | | public void setSubmit(boolean submit) { |
| | | isSubmit = submit; |
| | | } |
| | | |
| | | @ViewModelInject |
| | | public MainVM(@NonNull Application application, BaseModel model) { |
| | |
| | | |
| | | public void devLogin(){ |
| | | //清除登录信息 |
| | | MApplication.saveConfigBean(new DevConfigBean()); |
| | | EventBus.getDefault().post(new HttpEvent("获取钥匙柜基本信息-请求")); |
| | | getRetrofitService(Apis.class).getCabinetInfoForDriver(LMobileInfo.getDeviceUniqueId()) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | |
| | | if(200==response.getCode()){ |
| | | if(response.getData()!=null){ |
| | | MApplication.saveConfigBean(response.getData()); |
| | | EventBus.getDefault().post(new HttpEvent("酒精检测开关:"+response.getData().getAlcoholStatus())); |
| | | confidLD.setValue(response.getData()); |
| | | if(response.getData().getCabinetGridInfoVOList()!=null){ |
| | | updateDao(response.getData().getCabinetGridInfoVOList()); |
| | |
| | | toast(MApplication.mContext.getString(R.string.guide_toast_1)); |
| | | } |
| | | }else { |
| | | MApplication.saveConfigBean(new DevConfigBean()); |
| | | toast(response.getMessage()); |
| | | } |
| | | } |
| | |
| | | } |
| | | List<CabinetGridDo> addList = new ArrayList<>(); |
| | | List<CabinetGridDo> updateList = new ArrayList<>(); |
| | | List<SyncGridDataParam.GridDTO> errList = new ArrayList<>(); |
| | | for(ManageKeyCabinetBean bean:beans){ |
| | | String key = SportUtils.intToHex(Integer.parseInt(bean.getBoardCode()))+SportUtils.intToHex(Integer.parseInt(bean.getChannelCode())); |
| | | if(oldMap.containsKey(key)){ |
| | |
| | | gridDo.setWorkingStatus(bean.getWorkingStatus()); |
| | | updateList.add(gridDo); |
| | | oldMap.remove(key); |
| | | if(isSubmit&&!isCheck(gridDo.getKeyCode(),gridDo.getCurKeyCode())){ |
| | | SyncGridDataParam.GridDTO errDo = new SyncGridDataParam.GridDTO(); |
| | | errDo.setActualLable(gridDo.getCurKeyCode()); |
| | | errDo.setBoardCode(bean.getBoardCode()); |
| | | errDo.setChannelCode(bean.getChannelCode()); |
| | | errList.add(errDo); |
| | | } |
| | | }else { |
| | | //新增 |
| | | CabinetGridDo gridDo = new CabinetGridDo(); |
| | |
| | | DaoManager.getCabinetGridDao().insert(addList); |
| | | } |
| | | |
| | | //todo 去掉 |
| | | CabinetGridDo gridDo = oldMap.get("0101"); |
| | | if(gridDo!=null){ |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"=================>更新数据当前钥匙1:"+gridDo.getCurKeyCode())); |
| | | } |
| | | |
| | | if(updateList.size()>0){ |
| | | CabinetGridDo[] upList = new CabinetGridDo[updateList.size()]; |
| | | for(int i=0;i<updateList.size();i++){ |
| | |
| | | } |
| | | DaoManager.getCabinetGridDao().update(upList); |
| | | } |
| | | if(errList.size()>0){ |
| | | syncGridData(errList); |
| | | } |
| | | } |
| | | |
| | | private boolean isCheck(String v1,String v2){ |
| | | if(TextUtils.isEmpty(v1)&&TextUtils.isEmpty(v2)){ |
| | | return true; |
| | | }else if(TextUtils.isEmpty(v1)&&!TextUtils.isEmpty(v2)){ |
| | | return false; |
| | | }else if(!TextUtils.isEmpty(v1)&&TextUtils.isEmpty(v2)){ |
| | | return false; |
| | | } |
| | | return v1.equals(v2); |
| | | } |
| | | |
| | | public void devHeart(){ |
| | |
| | | }); |
| | | } |
| | | |
| | | public void syncGridData(List<SyncGridDataParam.GridDTO> errList){ |
| | | SyncGridDataParam param = new SyncGridDataParam(); |
| | | param.setCode(LMobileInfo.getDeviceUniqueId()); |
| | | param.setGridDTOList(errList); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(SyncGridDataParam.GridDTO d:errList){ |
| | | if(sb.length()>0){ |
| | | sb.append(","); |
| | | } |
| | | sb.append(d.getBoardCode()+"_"+d.getChannelCode()+":"+d.getActualLable()); |
| | | } |
| | | EventBus.getDefault().post(new HttpEvent("上报错误钥匙信息===》"+sb.toString())); |
| | | getRetrofitService(Apis.class).syncGridData(ParamsUtil.encodeRequestBody(param)) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { |
| | | @Override |
| | | public void onNext(@NonNull BaseResponse response) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onError(@NonNull Throwable e) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public MutableLiveData<List<FaceUserBean>> getFaceLD() { |
| | | return faceLD; |
| | | } |
| | | |
| | | public void getFaceDatas() { |
| | | //showLoading(true); |
| | | addInfo("查询人脸数据======》调用接口"); |
| | | getRetrofitService(Apis.class).allFaceList( LMobileInfo.getDeviceUniqueId()) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse<CabinetFaceBean>>(rxJavaGcManager) { |
| | |
| | | param.setCabinetId(MApplication.getConfigBean().getId()); |
| | | param.setMemberId(loginBean.getMemberId()); |
| | | param.setGridId(gridDo.getGridId()); |
| | | EventBus.getDefault().post(new HttpEvent("===>超时未关门-请求")); |
| | | getRetrofitService(Apis.class).timeOutUnCloseAlarm(ParamsUtil.encodeRequestBody(param)) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { |
| | | @Override |
| | | public void onNext(@NonNull BaseResponse response) { |
| | | toast("超时未关门接口调用成功"); |
| | | toast("===>超时未关门-返回"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | param.setMemberId(loginBean.getMemberId()); |
| | | param.setGridId(gridDo.getGridId()); |
| | | param.setKeyStatus(!TextUtils.isEmpty(gridDo.getCurKeyCode())?1:2); |
| | | EventBus.getDefault().post(new HttpEvent("===>首页关闭柜格-请求")); |
| | | getRetrofitService(Apis.class).closeGrid(ParamsUtil.encodeRequestBody(param)) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { |
| | | @Override |
| | | public void onNext(@NonNull BaseResponse response) { |
| | | toast("关门接口调用成功"); |
| | | EventBus.getDefault().post(new HttpEvent("===>首页关闭柜格-返回")); |
| | | } |
| | | |
| | | @Override |