| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.doumee.keyCabinet.ui.main; |
| | | |
| | | 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.R; |
| | | 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.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 org.greenrobot.eventbus.EventBus; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | 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<>(""); |
| | | public ObservableField<String> infoObs = new ObservableField<>(""); |
| | | |
| | | private MutableLiveData<List<FaceUserBean>> faceLD = new MutableLiveData<>(); |
| | | private MutableLiveData<DevConfigBean> confidLD = new MutableLiveData<>(); |
| | | |
| | | @ViewModelInject |
| | | public MainVM(@NonNull Application application, BaseModel model) { |
| | | super(application, model); |
| | | } |
| | | |
| | | @Override |
| | | protected void clickByTypeCommand(int type) { |
| | | doAction(type); |
| | | } |
| | | |
| | | public void devLogin(){ |
| | | //æ¸
é¤ç»å½ä¿¡æ¯ |
| | | EventBus.getDefault().post(new HttpEvent("è·åé¥åæåºæ¬ä¿¡æ¯-请æ±")); |
| | | getRetrofitService(Apis.class).getCabinetInfoForDriver(LMobileInfo.getDeviceUniqueId()) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse<DevConfigBean>>(rxJavaGcManager) { |
| | | @Override |
| | | public void onNext(@NonNull BaseResponse<DevConfigBean> response) { |
| | | if(200==response.getCode()){ |
| | | if(response.getData()!=null){ |
| | | MApplication.saveConfigBean(response.getData()); |
| | | confidLD.setValue(response.getData()); |
| | | if(response.getData().getCabinetGridInfoVOList()!=null){ |
| | | updateDao(response.getData().getCabinetGridInfoVOList()); |
| | | } |
| | | }else { |
| | | toast(MApplication.mContext.getString(R.string.guide_toast_1)); |
| | | } |
| | | }else { |
| | | MApplication.saveConfigBean(new DevConfigBean()); |
| | | toast(response.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(@NonNull Throwable e) { |
| | | toast(e.getMessage()); |
| | | EventBus.getDefault().post(new HttpEvent("è·åé¥åæåºæ¬ä¿¡æ¯-é误ï¼"+ e.getMessage())); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void updateDao(List<ManageKeyCabinetBean> beans){ |
| | | List<CabinetGridDo> gridDos = DaoManager.getCabinetGridDao().loadAll(); |
| | | HashMap<String,CabinetGridDo> oldMap = new HashMap<>(); |
| | | for(CabinetGridDo d:gridDos){ |
| | | oldMap.put(d.getGridKey(),d); |
| | | } |
| | | List<CabinetGridDo> addList = new ArrayList<>(); |
| | | List<CabinetGridDo> updateList = new ArrayList<>(); |
| | | for(ManageKeyCabinetBean bean:beans){ |
| | | String key = SportUtils.intToHex(Integer.parseInt(bean.getBoardCode()))+SportUtils.intToHex(Integer.parseInt(bean.getChannelCode())); |
| | | if(oldMap.containsKey(key)){ |
| | | //ä¿®æ¹ |
| | | CabinetGridDo gridDo = oldMap.get(key); |
| | | gridDo.setGridId(bean.getId()); |
| | | gridDo.setCabinetName(bean.getCode()); |
| | | gridDo.setKeyCode(bean.getKeyCode()); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | gridDo.setBindStatus(bean.getBindStatus()); |
| | | gridDo.setGridStatus(bean.getStatus()); |
| | | gridDo.setKeyStatus(bean.getKeyStatus()); |
| | | gridDo.setWorkingStatus(bean.getWorkingStatus()); |
| | | updateList.add(gridDo); |
| | | oldMap.remove(key); |
| | | }else { |
| | | //æ°å¢ |
| | | CabinetGridDo gridDo = new CabinetGridDo(); |
| | | gridDo.setGridId(bean.getId()); |
| | | gridDo.setCabinetName(bean.getCode()); |
| | | gridDo.setGridKey(key); |
| | | gridDo.setKeyCode(bean.getKeyCode()); |
| | | gridDo.setBindStatus(bean.getBindStatus()); |
| | | gridDo.setGridStatus(bean.getStatus()); |
| | | gridDo.setKeyStatus(bean.getKeyStatus()); |
| | | gridDo.setWorkingStatus(bean.getWorkingStatus()); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | addList.add(gridDo); |
| | | } |
| | | } |
| | | if(oldMap.size()>0) { |
| | | CabinetGridDo[] dels = new CabinetGridDo[oldMap.size()]; |
| | | int i=0; |
| | | for (String key : oldMap.keySet()) { |
| | | dels[i] = oldMap.get(key); |
| | | i++; |
| | | } |
| | | //å é¤å¤ç |
| | | DaoManager.getCabinetGridDao().delete(dels); |
| | | } |
| | | if(addList.size()>0){ |
| | | DaoManager.getCabinetGridDao().insert(addList); |
| | | } |
| | | |
| | | if(updateList.size()>0){ |
| | | CabinetGridDo[] upList = new CabinetGridDo[updateList.size()]; |
| | | for(int i=0;i<updateList.size();i++){ |
| | | upList[i] = updateList.get(i); |
| | | } |
| | | DaoManager.getCabinetGridDao().update(upList); |
| | | } |
| | | } |
| | | |
| | | public void devHeart(){ |
| | | if (MApplication.getConfigBean().getId()==null) { |
| | | return; |
| | | } |
| | | getRetrofitService(Apis.class).heart(MApplication.getConfigBean().getId()) |
| | | .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); |
| | | getRetrofitService(Apis.class).allFaceList( LMobileInfo.getDeviceUniqueId()) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse<CabinetFaceBean>>(rxJavaGcManager) { |
| | | @Override |
| | | public void onNext(@NonNull BaseResponse<CabinetFaceBean> response) { |
| | | if(200==response.getCode()){ |
| | | //æ¥è¯¢æ°æ® |
| | | if(response.getData()!=null){ |
| | | CabinetFaceBean faceBean = response.getData(); |
| | | List<FaceUserBean> datas = new ArrayList<>(); |
| | | if(faceBean!=null&&faceBean.getAutoFaceList()!=null){ |
| | | for(FaceUserBean bean:faceBean.getAutoFaceList()){ |
| | | bean.setGroupId("0"); |
| | | } |
| | | datas.addAll(faceBean.getAutoFaceList()); |
| | | } |
| | | if(faceBean!=null&&faceBean.getDriverFaceList()!=null){ |
| | | for(FaceUserBean bean:faceBean.getDriverFaceList()){ |
| | | bean.setGroupId("1"); |
| | | } |
| | | datas.addAll(faceBean.getDriverFaceList()); |
| | | } |
| | | faceLD.setValue(datas); |
| | | } |
| | | }else { |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(@NonNull Throwable e) { |
| | | //toast(e.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | //hideLoading(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public void upErrInfo(SpUtil.SPBean bean) { |
| | | if (true) { |
| | | return; |
| | | } |
| | | RequestBaseObject<DevErrInfoParam> request = new RequestBaseObject<>(); |
| | | DevErrInfoParam param = new DevErrInfoParam(); |
| | | param.setDevCode(LMobileInfo.getDeviceUniqueId()); |
| | | param.setErrInfo(bean.getValue()); |
| | | request.setParam(param); |
| | | getRetrofitService(Apis.class).upErrInfo(ParamsUtil.encodeRequestBody(request)) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { |
| | | @Override |
| | | public void onNext(@NonNull BaseResponse response) { |
| | | if(200==response.getCode()){ |
| | | SpUtil.remoreString(bean.getKey()); |
| | | }else { |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(@NonNull Throwable e) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public List<CabinetGridDo> getOpenGrids(){ |
| | | return DaoManager.getCabinetGridDao().getOpenGrids(); |
| | | } |
| | | |
| | | public void updateGrids(List<CabinetGridDo> updateList){ |
| | | if(updateList.size()>0){ |
| | | CabinetGridDo[] upList = new CabinetGridDo[updateList.size()]; |
| | | for(int i=0;i<updateList.size();i++){ |
| | | upList[i] = updateList.get(i); |
| | | } |
| | | DaoManager.getCabinetGridDao().update(upList); |
| | | } |
| | | addInfo("æ´æ°åºæ°æ®:ä¿®æ¹" + updateList.size()); |
| | | } |
| | | |
| | | public void timeOutUnCloseAlarm(CabinetGridDo gridDo){ |
| | | TimeOutUnCloseAlarmParam param = new TimeOutUnCloseAlarmParam(); |
| | | LoginBean loginBean = MApplication.getLoginBean(); |
| | | param.setCabinetId(MApplication.getConfigBean().getId()); |
| | | param.setMemberId(loginBean.getMemberId()); |
| | | param.setGridId(gridDo.getGridId()); |
| | | getRetrofitService(Apis.class).timeOutUnCloseAlarm(ParamsUtil.encodeRequestBody(param)) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse>(rxJavaGcManager) { |
| | | @Override |
| | | public void onNext(@NonNull BaseResponse response) { |
| | | toast("è¶
æ¶æªå
³é¨æ¥å£è°ç¨æå"); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(@NonNull Throwable e) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | 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); |
| | | getRetrofitService(Apis.class).closeGrid(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<DevConfigBean> getConfidLD() { |
| | | return confidLD; |
| | | } |
| | | |
| | | public void addInfo(String info){ |
| | | String s = infoObs.get(); |
| | | s=info+"\n"+s; |
| | | infoObs.set(s); |
| | | } |
| | | } |