| | |
| | | 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.ui.guide.GuideActivity; |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | doAction(type); |
| | | } |
| | | |
| | | private boolean isReq = false; |
| | | |
| | | public void resetReq(){ |
| | | isReq = false; |
| | | } |
| | | |
| | | public void devLogin(){ |
| | | //清除登录信息 |
| | | if(isReq){ |
| | | return; |
| | | } |
| | | isReq = true; |
| | | MApplication.saveConfigBean(new DevConfigBean()); |
| | | 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) { |
| | | EventBus.getDefault().post(new HttpEvent("获取钥匙柜基本信息-返回:"+ GsonTools.changeGsonToJson(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)); |
| | | } |
| | |
| | | @Override |
| | | public void onError(@NonNull Throwable e) { |
| | | toast(e.getMessage()); |
| | | EventBus.getDefault().post(new HttpEvent("获取钥匙柜基本信息-错误:"+ e.getMessage())); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | isReq = false; |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | 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); |
| | | }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(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 (true) { |
| | | return; |
| | | } |
| | | DevLoginParam param = new DevLoginParam(); |
| | | param.setCode(LMobileInfo.getDeviceUniqueId()); |
| | | //showLoading(true); |
| | | getRetrofitService(Apis.class).allFaceList( ParamsUtil.encodeRequestBody(param)) |
| | | getRetrofitService(Apis.class).allFaceList( LMobileInfo.getDeviceUniqueId()) |
| | | .compose(RxUtils.schedulersTransformer()) |
| | | .subscribe(new SimpleObserver<BaseResponse<CabinetFaceBean>>(rxJavaGcManager) { |
| | | @Override |
| | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 上传手环日志 |
| | | */ |
| | | public void upBraceletLog() { |
| | | if (true) { |
| | | return; |
| | | public List<CabinetGridDo> getOpenGrids(){ |
| | | return DaoManager.getCabinetGridDao().getOpenGrids(); |
| | | } |
| | | |
| | | public void insertGrids(List<CabinetGridDo> addList){ |
| | | if(addList.size()>0){ |
| | | DaoManager.getCabinetGridDao().insert(addList); |
| | | } |
| | | if(BraceletLogUtils.COUNT>100||(System.currentTimeMillis() - BraceletLogUtils.lastTime > 600000)){ |
| | | BraceletLogUtils.lastTime = System.currentTimeMillis(); |
| | | String text = BraceletLogUtils.getAllLog(); |
| | | if(TextUtils.isEmpty(text)){ |
| | | return; |
| | | addInfo("更新库数据:新增" + addList.size()); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | RequestBaseObject<DevErrInfoParam> request = new RequestBaseObject<>(); |
| | | DevErrInfoParam param = new DevErrInfoParam(); |
| | | param.setDevCode(LMobileInfo.getDeviceUniqueId()); |
| | | param.setErrInfo(text); |
| | | 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()){ |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(@NonNull Throwable e) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | 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) { |
| | | |
| | | } |
| | | |
| | | @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"; |
| | | infoObs.set(s); |
| | | } |
| | | } |