| | |
| | | package com.doumee.keyCabinet.ui.keyCabinet; |
| | | |
| | | import androidx.annotation.Nullable; |
| | | import androidx.appcompat.app.AppCompatActivity; |
| | | import androidx.lifecycle.Observer; |
| | | |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.text.SpannableString; |
| | | import android.text.Spanned; |
| | | import android.text.TextUtils; |
| | | import android.text.style.TextAppearanceSpan; |
| | | import android.view.KeyEvent; |
| | | import android.view.View; |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | | import com.doumee.keyCabinet.R; |
| | | import com.doumee.keyCabinet.base.MyBaseActivity; |
| | | import com.doumee.keyCabinet.bean.CabinetDetailBean; |
| | | import com.doumee.keyCabinet.bean.ManageKeyCabinetBean; |
| | | import com.doumee.keyCabinet.dao.CabinetGridDo; |
| | | import com.doumee.keyCabinet.dao.DaoManager; |
| | | import com.doumee.keyCabinet.databinding.ManageCabinetActivityBinding; |
| | | import com.doumee.keyCabinet.event.CheckGridStatusEvent; |
| | | import com.doumee.keyCabinet.event.CloseGridOneResultEvent; |
| | | import com.doumee.keyCabinet.event.GetKeyStatusEvent; |
| | | import com.doumee.keyCabinet.event.HttpEvent; |
| | | import com.doumee.keyCabinet.event.KeyResultEvent; |
| | | import com.doumee.keyCabinet.event.ManageOpenGridResultEvent; |
| | | import com.doumee.keyCabinet.event.OpenAllGridEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridListEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridOneResultEvent; |
| | | import com.doumee.keyCabinet.event.TimeClockEvent; |
| | | import com.doumee.keyCabinet.ui.keyCabinet.adapter.ManageCabinetRcvAdapter; |
| | | import com.doumee.keyCabinet.utils.i485.SportUtils; |
| | | import com.doumee.lib_coremodel.bean.event.ActionEventData; |
| | | import com.doumee.lib_coremodel.util.RecyclerHelp; |
| | | import com.doumee.lib_coremodel.util.StringUtil; |
| | | import com.example.datalibrary.db.DBManager; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | import dagger.hilt.android.AndroidEntryPoint; |
| | |
| | | @AndroidEntryPoint |
| | | public class ManageCabinetActivity extends MyBaseActivity<ManageCabinetVM, ManageCabinetActivityBinding> { |
| | | private ManageCabinetRcvAdapter adapter; |
| | | //1待全开,2待批量开 |
| | | private int status; |
| | | |
| | | //是否可批量操作 |
| | | private boolean isCanPL = false; |
| | | //可标记:全借出、全故障 |
| | | private boolean isCanBJ = false; |
| | | private int keyStatus = -1; |
| | | |
| | | @Override |
| | | public int getLayoutId() { |
| | | return R.layout.manage_cabinet_activity; |
| | | } |
| | | |
| | | private HashMap<String,String> waitOpenMap = new HashMap<>(); |
| | | |
| | | @Override |
| | | public void initView(@Nullable Bundle savedInstanceState) { |
| | | isAddCountTimer = false; |
| | | normalConfig(); |
| | | getDB().setModel(getVM()); |
| | | |
| | | adapter = new ManageCabinetRcvAdapter(this, R.layout.manage_cabinet_rcv_item, new ManageCabinetRcvAdapter.OnItemClick() { |
| | | @Override |
| | | public void onItemClick(ManageKeyCabinetBean item) { |
| | | updateBtnStatus(); |
| | | } |
| | | }); |
| | | RecyclerHelp.bindVG(this,getDB().rcvKm,3,30); |
| | | getDB().rcvKm.setAdapter(adapter); |
| | | } |
| | | |
| | | @Override |
| | |
| | | getVM().getDatasLD().observe(this, new Observer<List<ManageKeyCabinetBean>>() { |
| | | @Override |
| | | public void onChanged(List<ManageKeyCabinetBean> gridInfoBeans) { |
| | | |
| | | if(getDB().clCz.getVisibility()==View.VISIBLE){ |
| | | getDB().clCz.setVisibility(View.GONE); |
| | | } |
| | | if(gridInfoBeans.size()>0){ |
| | | adapter.refreshData(gridInfoBeans); |
| | | getVM().emptyVisibility.set(View.GONE); |
| | | //更新信息 |
| | | updateDao(gridInfoBeans); |
| | | }else { |
| | | getVM().emptyVisibility.set(View.VISIBLE); |
| | | } |
| | | } |
| | | }); |
| | | getVM().getCabinetDetail(); |
| | | } |
| | | |
| | | private void updateBtnStatus(){ |
| | | List<ManageKeyCabinetBean> datas = adapter.getListData(); |
| | | isCanPL = false; |
| | | isCanBJ = false; |
| | | keyStatus = -1; |
| | | for(ManageKeyCabinetBean d:datas){ |
| | | if(d.getIsSelected().get()){ |
| | | isCanPL = true; |
| | | isCanBJ = true; |
| | | if(keyStatus==-1){ |
| | | keyStatus = getGridStatus(d); |
| | | }else { |
| | | if(keyStatus!=getGridStatus(d)){ |
| | | //不同 |
| | | keyStatus = -2; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(isCanPL){ |
| | | getDB().tvPlOpen.setBackgroundResource(R.drawable.shape_mb_bt_ok); |
| | | }else { |
| | | getDB().tvPlOpen.setBackgroundResource(R.drawable.shape_mb_bt_faile); |
| | | } |
| | | if(isCanBJ){ |
| | | getDB().tvBj.setBackgroundResource(R.drawable.shape_mb_bt_ok); |
| | | }else { |
| | | getDB().tvBj.setBackgroundResource(R.drawable.shape_mb_bt_faile); |
| | | } |
| | | } |
| | | |
| | | private int getGridStatus(ManageKeyCabinetBean grid){ |
| | | if(grid.getWorkingStatus()==1){ |
| | | return 4; |
| | | }else { |
| | | return grid.getKeyStatus(); |
| | | } |
| | | } |
| | | |
| | | 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> 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); |
| | | } |
| | | } |
| | | if(updateList.size()>0){ |
| | | CabinetGridDo[] upList = new CabinetGridDo[updateList.size()]; |
| | | for(int i=0;i<updateList.size();i++){ |
| | | upList[i] = updateList.get(i); |
| | | } |
| | | //todo 去掉 |
| | | CabinetGridDo gridDo = oldMap.get("0101"); |
| | | if(gridDo!=null){ |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"=================>更新数据当前钥匙2:"+gridDo.getCurKeyCode())); |
| | | } |
| | | |
| | | DaoManager.getCabinetGridDao().update(upList); |
| | | } |
| | | } |
| | | |
| | | private List<Integer> bjIds = new ArrayList<>(); |
| | | private boolean isGz = true; |
| | | private boolean isAllOpen = false; |
| | | @Override |
| | | protected void doRegister(int type, ActionEventData data) { |
| | | switch (type){ |
| | | case 1: |
| | | //todo wmf 校验柜子是否都已关闭 |
| | | //校验柜子是否都已关闭 |
| | | if(checkOpen()){ |
| | | return; |
| | | } |
| | | finish(); |
| | | break; |
| | | case 2: |
| | | { |
| | | //全开 |
| | | status = 1; |
| | | //todo 全开 |
| | | //批量开门,校验是否可打开 |
| | | List<Integer> ids = new ArrayList<>(); |
| | | List<ManageKeyCabinetBean> datas = adapter.getListData(); |
| | | for (ManageKeyCabinetBean bean : datas) { |
| | | ids.add(bean.getId()); |
| | | } |
| | | if (ids.size() == 0) { |
| | | Toast.makeText(mContext, "请选择柜格", Toast.LENGTH_SHORT).show(); |
| | | return; |
| | | } |
| | | getVM().batchOpenGridAdmin(ids,true); |
| | | } |
| | | break; |
| | | case 3: { |
| | | if(!isCanPL){ |
| | | return; |
| | | } |
| | | //批量开门,校验是否可打开 |
| | | List<Integer> ids = new ArrayList<>(); |
| | | List<ManageKeyCabinetBean> datas = adapter.getListData(); |
| | |
| | | Toast.makeText(mContext, "请选择柜格", Toast.LENGTH_SHORT).show(); |
| | | return; |
| | | } |
| | | getVM().batchOpenGridAdmin(ids); |
| | | getVM().batchOpenGridAdmin(ids,false); |
| | | }break; |
| | | case 8: |
| | | status = 2; |
| | | //todo 批量开 |
| | | break; |
| | | case 8: { |
| | | //全开 |
| | | isAllOpen = true; |
| | | List<ManageKeyCabinetBean> datas = adapter.getListData(); |
| | | for (ManageKeyCabinetBean bean : datas) { |
| | | String key = SportUtils.intToHex(Integer.parseInt(bean.getBoardCode()))+ |
| | | SportUtils.intToHex(Integer.parseInt(bean.getChannelCode())); |
| | | waitOpenMap.put(key,bean.getCode()); |
| | | } |
| | | waitResultCount = 2; |
| | | EventBus.getDefault().post(new OpenAllGridEvent()); |
| | | }break; |
| | | case 10: { |
| | | //批量开 |
| | | isAllOpen = false; |
| | | List<ManageKeyCabinetBean> datas = adapter.getListData(); |
| | | List<String> keys = new ArrayList<>(); |
| | | for (ManageKeyCabinetBean bean : datas) { |
| | | if(bean.getIsSelected().get()) { |
| | | String key = SportUtils.intToHex(Integer.parseInt(bean.getBoardCode())) + |
| | | SportUtils.intToHex(Integer.parseInt(bean.getChannelCode())); |
| | | waitOpenMap.put(key, bean.getCode()); |
| | | keys.add(key); |
| | | } |
| | | } |
| | | waitResultCount = keys.size(); |
| | | EventBus.getDefault().post(new OpenGridListEvent(keys)); |
| | | }break; |
| | | case 4: { |
| | | //标记 |
| | | if(!isCanBJ){ |
| | | return; |
| | | } |
| | | bjIds.clear(); |
| | | isGz = true; |
| | | |
| | | List<ManageKeyCabinetBean> datas = adapter.getListData(); |
| | | for (ManageKeyCabinetBean bean : datas) { |
| | | if (bean.getIsSelected().get()) { |
| | | bjIds.add(bean.getId()); |
| | | if(bean.getWorkingStatus()==0){ |
| | | isGz = false; |
| | | } |
| | | } |
| | | } |
| | | if (bjIds.size() == 0) { |
| | | Toast.makeText(mContext, "请选择柜格", Toast.LENGTH_SHORT).show(); |
| | | return; |
| | | } |
| | | if(isGz){ |
| | | if(keyStatus==4){ |
| | | //全为故障 |
| | | getDB().tvBjgz.setText("标记为正常"); |
| | | getDB().tvBjgz.setTextColor(0xff279BAA); |
| | | getDB().tvBjgz.setBackgroundResource(R.drawable.shape_mb_cz_2_bg); |
| | | getDB().tvBy.setVisibility(View.GONE); |
| | | }else { |
| | | //标记故障 |
| | | getDB().tvBjgz.setText("标记为故障"); |
| | | getDB().tvBjgz.setTextColor(0xffFF3600); |
| | | getDB().tvBjgz.setBackgroundResource(R.drawable.shape_mb_cz_1_bg); |
| | | if(keyStatus==2) { |
| | | //0未绑定 1在位 2借出 3维修保养 |
| | | getDB().tvBy.setVisibility(View.VISIBLE); |
| | | }else { |
| | | getDB().tvBy.setVisibility(View.GONE); |
| | | } |
| | | } |
| | | getDB().clCz.setVisibility(View.VISIBLE); |
| | | }break; |
| | |
| | | getVM().markRepair(bjIds); |
| | | break; |
| | | case 7: |
| | | if(isGz) { |
| | | if(keyStatus==4) { |
| | | //正常 |
| | | getVM().cancelFault(bjIds); |
| | | }else { |
| | |
| | | getVM().markFault(bjIds); |
| | | } |
| | | break; |
| | | case 9: { |
| | | updateBtnStatus(); |
| | | if(isShowOpenTip==true) { |
| | | //清空开门提醒 |
| | | isShowOpenTip = false; |
| | | getDB().clKmTip.setVisibility(View.GONE); |
| | | }else { |
| | | getDB().clKmTip.setVisibility(View.GONE); |
| | | } |
| | | }break; |
| | | case 11: |
| | | updateBtnStatus(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | //退出关门提醒 |
| | | private int tipDownCount = 10; |
| | | private boolean isShowTip; |
| | | |
| | | //开门提醒 |
| | | private int openTipDownCount = 60; |
| | | private boolean isShowOpenTip; |
| | | @Subscribe |
| | | public void TimeClockEvent(TimeClockEvent e){ |
| | | if(isShowTip){ |
| | | if(tipDownCount==0){ |
| | | isShowTip = false; |
| | | getDB().clTip.setVisibility(View.GONE); |
| | | }else { |
| | | tipDownCount--; |
| | | getDB().tvDjs.setText(tipDownCount+"s"); |
| | | } |
| | | } |
| | | if(isShowOpenTip){ |
| | | if(openTipDownCount==0){ |
| | | doRegister(9,null); |
| | | }else { |
| | | openTipDownCount--; |
| | | getDB().tvClKmClose.setText(openTipDownCount+"s 自动关闭"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 校验是否有没关门的 |
| | | * @return |
| | | */ |
| | | private boolean checkOpen(){ |
| | | List<CabinetGridDo> gridDos = DaoManager.getCabinetGridDao().getOpenGrids(); |
| | | if (gridDos.size() > 0) { |
| | | tipDownCount = 10; |
| | | isShowTip = true; |
| | | getDB().tvDjs.setText(tipDownCount + "s"); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(CabinetGridDo d:gridDos){ |
| | | if (sb.length()>0) { |
| | | sb.append("、"); |
| | | } |
| | | String name = d.getCabinetName(); |
| | | if (TextUtils.isEmpty(name)) { |
| | | name = gridDos.get(0).getGridKey(); |
| | | } |
| | | sb.append(name); |
| | | } |
| | | getDB().tvTip22.setText(getTipText(sb.toString()), TextView.BufferType.SPANNABLE); |
| | | getDB().clTip.setVisibility(View.VISIBLE); |
| | | return true; |
| | | }else { |
| | | isShowTip = false; |
| | | getDB().clTip.setVisibility(View.GONE); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | private SpannableString getTipText(String name){ |
| | | String text = "请关闭"+name+"柜门"; |
| | | SpannableString styledText = new SpannableString(text); |
| | | styledText.setSpan(new TextAppearanceSpan(this,R.style.style_tip2), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | styledText.setSpan(new TextAppearanceSpan(this, R.style.style_tip1), |
| | | 3, 3+name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | styledText.setSpan(new TextAppearanceSpan(this,R.style.style_tip2), name.length()+3, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | return styledText; |
| | | } |
| | | |
| | | private SpannableString getTipText2(String begin,String name,String end){ |
| | | String text = begin+name+end; |
| | | SpannableString styledText = new SpannableString(text); |
| | | styledText.setSpan(new TextAppearanceSpan(this,R.style.style_tip2), 0, begin.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | styledText.setSpan(new TextAppearanceSpan(this, R.style.style_tip1), |
| | | begin.length(), begin.length()+name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | styledText.setSpan(new TextAppearanceSpan(this,R.style.style_tip2), begin.length()+name.length(), text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | return styledText; |
| | | } |
| | | |
| | | private void showKeyErrTip(String name){ |
| | | getDB().imgClKm1.setImageResource(R.mipmap.ic_jjfail); |
| | | getDB().tvClKm1.setText("识别失败"); |
| | | getDB().tvClKm2.setText(getTipText2("钥匙柜",name,"识别失败"), TextView.BufferType.SPANNABLE); |
| | | getDB().tvClKmClose.setText("重新存放"); |
| | | getDB().tvClKmClose.setTextColor(0xffffffff); |
| | | getDB().tvClKmClose.setBackgroundResource(R.drawable.shape_mb_bt_ok); |
| | | isShowOpenTip = false; |
| | | getDB().clKmTip.setVisibility(View.VISIBLE); |
| | | } |
| | | |
| | | @Override |
| | | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| | | if(keyCode == KeyEvent.KEYCODE_BACK){ |
| | | if(checkOpen()){ |
| | | return true; |
| | | } |
| | | } |
| | | return super.onKeyDown(keyCode, event); |
| | | } |
| | | |
| | | private int waitResultCount = 0; |
| | | /** |
| | | * 开门返回 |
| | | * @param e |
| | | */ |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void ManageOpenGridResultEvent(ManageOpenGridResultEvent e){ |
| | | if(!isFinishing()){ |
| | | if(waitResultCount>0){ |
| | | waitResultCount--; |
| | | } |
| | | if(waitResultCount>0){ |
| | | return; |
| | | } |
| | | EventBus.getDefault().post(new CheckGridStatusEvent()); |
| | | //校验是否已全开 |
| | | List<CabinetGridDo> gridDos = DaoManager.getCabinetGridDao().loadAll(); |
| | | List<String> msgList = new ArrayList<>(); |
| | | for(String key:waitOpenMap.keySet()){ |
| | | msgList.add(waitOpenMap.get(key)); |
| | | } |
| | | EventBus.getDefault().post(new HttpEvent("总共要打开数:"+waitOpenMap.size())); |
| | | for(CabinetGridDo d:gridDos){ |
| | | if(d.getIsOpen()==1) { |
| | | EventBus.getDefault().post(new HttpEvent("打开了:"+d.getGridKey())); |
| | | waitOpenMap.remove(d.getGridKey()); |
| | | } |
| | | } |
| | | if(waitOpenMap.size()==0){ |
| | | if(getDB().clKmTip.getVisibility()==View.VISIBLE){ |
| | | //已弹出就不提示了 |
| | | return; |
| | | } |
| | | EventBus.getDefault().post(new HttpEvent("全部打开了:"+waitOpenMap.size())); |
| | | //打开成功 |
| | | if(isAllOpen){ |
| | | getDB().tvClKm2.setText("一键全开成功,领还后请关门"); |
| | | }else { |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| | | msgList.sort((a,b)->{ |
| | | return a.compareTo(b); |
| | | }); |
| | | } |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(String key:msgList){ |
| | | if(sb.length()>0){ |
| | | sb.append("、"); |
| | | } |
| | | sb.append(key); |
| | | } |
| | | getDB().tvClKm2.setText(getTipText2("钥匙柜",sb.toString(),"开门成功,领还后请关门"), TextView.BufferType.SPANNABLE); |
| | | } |
| | | getDB().imgClKm1.setImageResource(R.mipmap.ic_success); |
| | | getDB().tvClKm1.setText("柜门打开成功"); |
| | | }else { |
| | | //部分开门失败 |
| | | EventBus.getDefault().post(new HttpEvent("部分打开了:"+waitOpenMap.size())); |
| | | msgList.clear(); |
| | | for (String key : waitOpenMap.keySet()) { |
| | | msgList.add(waitOpenMap.get(key)); |
| | | } |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| | | msgList.sort((a, b) -> { |
| | | return a.compareTo(b); |
| | | }); |
| | | } |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (String key : msgList) { |
| | | if (sb.length() > 0) { |
| | | sb.append("、"); |
| | | } |
| | | sb.append(key); |
| | | } |
| | | getDB().imgClKm1.setImageResource(R.mipmap.ic_jjfail); |
| | | getDB().tvClKm1.setText("柜门打开失败"); |
| | | getDB().tvClKm2.setText(getTipText2("钥匙柜",sb.toString(),"开门失败"), TextView.BufferType.SPANNABLE); |
| | | } |
| | | getDB().tvClKmClose.setText("60s 自动关闭"); |
| | | getDB().tvClKmClose.setTextColor(0xff279baa); |
| | | getDB().tvClKmClose.setBackgroundResource(R.drawable.shape_mb_bg01); |
| | | openTipDownCount = 60; |
| | | isShowOpenTip = true; |
| | | getDB().clKmTip.setVisibility(View.VISIBLE); |
| | | |
| | | if(!isAllOpen) { |
| | | //清除已选择的 |
| | | List<ManageKeyCabinetBean> datas = adapter.getListData(); |
| | | for (ManageKeyCabinetBean bean : datas) { |
| | | if (bean.getIsSelected().get()) { |
| | | String key = SportUtils.intToHex(Integer.parseInt(bean.getBoardCode())) + |
| | | SportUtils.intToHex(Integer.parseInt(bean.getChannelCode())); |
| | | if (!waitOpenMap.containsKey(key)) { |
| | | bean.getIsSelected().set(false); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | waitOpenMap.clear(); |
| | | } |
| | | } |
| | | |
| | | private String sygKey; |
| | | @Subscribe |
| | | public void OpenGridOneResultEvent(OpenGridOneResultEvent e){ |
| | | if(!isFinishing()){ |
| | | if(e.getIsOpen()==0){ |
| | | if(e.getKey().equals(sygKey)){ |
| | | return; |
| | | } |
| | | sygKey = e.getKey(); |
| | | //开门失败,重新开门 |
| | | EventBus.getDefault().post(new OpenGridEvent(Integer.parseInt(e.getKey().substring(2,4), 16)+"", |
| | | Integer.parseInt(e.getKey().substring(0,2), 16)+"")); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 关门 |
| | | * @param e |
| | | */ |
| | | @Subscribe(threadMode= ThreadMode.MAIN) |
| | | public void CloseGridOneResultEvent(CloseGridOneResultEvent e){ |
| | | if(!isFinishing()){ |
| | | //获取卡号 |
| | | EventBus.getDefault().post(new GetKeyStatusEvent()); |
| | | if(isShowTip){ |
| | | isShowTip = false; |
| | | getDB().clTip.setVisibility(View.GONE); |
| | | } |
| | | //校验卡号 |
| | | CabinetGridDo gridDo = DaoManager.getCabinetGridDao().getGridByKey(e.getKey()); |
| | | if(gridDo!=null){ |
| | | if(TextUtils.isEmpty(gridDo.getGridKey())){ |
| | | if(!TextUtils.isEmpty(gridDo.getCurKeyCode())){ |
| | | //未绑定的存放了钥匙 |
| | | showKeyErrTip(gridDo.getCabinetName()+"-"+gridDo.getCurKeyCode()); |
| | | //开门 |
| | | EventBus.getDefault().post(new OpenGridEvent(Integer.parseInt(e.getKey().substring(2,4), 16)+"", |
| | | Integer.parseInt(e.getKey().substring(0,2), 16)+"")); |
| | | return; |
| | | } |
| | | }else { |
| | | if(!TextUtils.isEmpty(gridDo.getCurKeyCode())){ |
| | | if(!gridDo.getCurKeyCode().equals(gridDo.getKeyCode())){ |
| | | //钥匙不匹配 |
| | | showKeyErrTip(gridDo.getCabinetName()+"-"+gridDo.getCurKeyCode()); |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"钥匙不匹配==>目标:"+gridDo.getKeyCode()+",当前:"+gridDo.getCurKeyCode())); |
| | | //开门 |
| | | EventBus.getDefault().post(new OpenGridEvent(Integer.parseInt(e.getKey().substring(2,4), 16)+"", |
| | | Integer.parseInt(e.getKey().substring(0,2), 16)+"")); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"门关闭成功==>目标:"+gridDo.getKeyCode()+",当前:"+gridDo.getCurKeyCode())); |
| | | getVM().closeGrid(gridDo); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Subscribe |
| | | public void KeyResultEvent(KeyResultEvent e){ |
| | | if(!isFinishing()){ |
| | | //校验卡号不对的,直接弹出 |
| | | List<CabinetGridDo> gridDos = DaoManager.getCabinetGridDao().loadAll(); |
| | | List<String> keys = new ArrayList<>(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(CabinetGridDo gridDo:gridDos){ |
| | | if(TextUtils.isEmpty(gridDo.getGridKey())){ |
| | | if(!TextUtils.isEmpty(gridDo.getCurKeyCode())&&gridDo.getIsOpen()==0){ |
| | | //未绑定的存放了钥匙 |
| | | keys.add(gridDo.getGridKey()); |
| | | if(sb.length()>0){ |
| | | sb.append("、"); |
| | | } |
| | | sb.append(gridDo.getCabinetName()); |
| | | } |
| | | }else { |
| | | if(!TextUtils.isEmpty(gridDo.getCurKeyCode())){ |
| | | if(!gridDo.getCurKeyCode().equals(gridDo.getKeyCode())&&gridDo.getIsOpen()==0){ |
| | | //钥匙不匹配 |
| | | keys.add(gridDo.getGridKey()); |
| | | if(sb.length()>0){ |
| | | sb.append("、"); |
| | | } |
| | | sb.append(gridDo.getCabinetName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(sb.length()>0){ |
| | | showKeyErrTip(sb.toString()); |
| | | } |
| | | if(keys.size()>0){ |
| | | //开门 |
| | | EventBus.getDefault().post(new OpenGridListEvent(keys)); |
| | | } |
| | | } |
| | | } |
| | | } |