HomeActivityHelp.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package xn.xxp;
  2. import android.os.CountDownTimer;
  3. import android.util.Log;
  4. import com.blankj.utilcode.util.LogUtils;
  5. import org.greenrobot.eventbus.EventBus;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import http.client.ApiRepository;
  9. import http.vo.request.NoticeReq;
  10. import http.vo.response.HomeRightResp;
  11. import http.vo.response.LabBulletinBoardVo;
  12. import http.vo.response.LabWarnVo;
  13. import io.reactivex.rxjava3.functions.Consumer;
  14. import xn.xxp.home.adapter.HomeBoardAdapter;
  15. import xn.xxp.app.LabApp;
  16. import xn.xxp.mqtt.event.WarningEvent;
  17. import xn.xxp.room.RoomTool;
  18. import xn.xxp.room.bean.NoticeSummary;
  19. import xn.xxp.room.dao.NoticeSummaryDao;
  20. import xn.xxp.utils.Tool;
  21. public class HomeActivityHelp {
  22. private HomeActivity activity;
  23. // 心跳
  24. private CountDownTimer heartbeatCountDownTimer;
  25. public HomeActivityHelp(HomeActivity homePageActivity) {
  26. activity = homePageActivity;
  27. heartbeatCountDownTimer = new CountDownTimer(3000, 1000) {
  28. @Override
  29. public void onTick(long millisUntilFinished) {
  30. }
  31. @Override
  32. public void onFinish() {
  33. activity.addDisposable(ApiRepository.INSTANCE.heartbeat(activity.deviceConfig.getDevId()).subscribe(aBoolean -> {
  34. }, throwable -> {
  35. }));
  36. heartbeatCountDownTimer.start();
  37. }
  38. };
  39. heartbeatCountDownTimer.start();
  40. }
  41. public void onDestroy() {
  42. if (null != heartbeatCountDownTimer) {
  43. heartbeatCountDownTimer.cancel();
  44. }
  45. }
  46. /**
  47. * 刷卡响应
  48. */
  49. public void dispatchReadCardResult(String s) {
  50. activity.showLoading("加载中...");
  51. activity.addDisposable(ApiRepository.INSTANCE.getCardIsOpen(String.valueOf(activity.labConfig.getLabId()), s).subscribe(userVo -> {
  52. activity.dismissLoading();
  53. LabApp.userVo = userVo;
  54. // Tool.INSTANCE.openDoor();
  55. }, onError));
  56. }
  57. /**
  58. * 查询首页右侧人员信息
  59. * 值班人员
  60. * 实验室人员
  61. * 准入人员
  62. */
  63. public void queryPerson() {
  64. activity.addDisposable(ApiRepository.INSTANCE.homeRightInfo(String.valueOf(activity.labConfig.getLabId())).subscribe(this::dispatchLabPerson, onError));
  65. }
  66. /**
  67. * 查询底部物联设备
  68. */
  69. public void queryBulletinBoard() {
  70. activity.addDisposable(ApiRepository.INSTANCE.functionList(String.valueOf(activity.labConfig.getLabId())).subscribe(this::dispatchLabDevice, throwable -> {
  71. activity.dismissLoading();
  72. LogUtils.e(Log.getStackTraceString(throwable));
  73. activity.showNetError(throwable);
  74. activity.homeBoardAdapter.setEmptyView(R.layout.view_list_empty);
  75. }));
  76. }
  77. public void queryWarnList() {
  78. activity.addDisposable(ApiRepository.INSTANCE.warnList(String.valueOf(activity.labConfig.getLabId())).subscribe(new Consumer<List<LabWarnVo>>() {
  79. @Override
  80. public void accept(List<LabWarnVo> labWarnVos) throws Throwable {
  81. EventBus.getDefault().post(new WarningEvent(labWarnVos));
  82. }
  83. }, new Consumer<Throwable>() {
  84. @Override
  85. public void accept(Throwable throwable) throws Throwable {
  86. LogUtils.e(Log.getStackTraceString(throwable));
  87. }
  88. }));
  89. }
  90. /**
  91. * 查询通知消息
  92. */
  93. public void queryNoticeMsgList() {
  94. NoticeReq noticeReq = new NoticeReq();
  95. List<Long> businessTypeList = new ArrayList<>() {
  96. {
  97. add(0L);
  98. add(1L);
  99. add(13L);
  100. }
  101. };
  102. noticeReq.setBusinessTypeList(businessTypeList);
  103. noticeReq.setSubIds(String.valueOf(activity.labConfig.getLabId()));
  104. noticeReq.setPage(1);
  105. noticeReq.setPageSize(100);
  106. activity.addDisposable(ApiRepository.INSTANCE.newMsgGroup(noticeReq).subscribe(noticeSummaryVoList -> {
  107. if (null != noticeSummaryVoList && !noticeSummaryVoList.isEmpty()) {
  108. NoticeSummaryDao noticeSummaryDao = RoomTool.getInstance().noticeSummaryDao();
  109. noticeSummaryDao.insert(noticeSummaryVoList.toArray(new NoticeSummary[0]));
  110. }
  111. activity.binding.titleBar.updateNotice(noticeSummaryVoList);
  112. }, onError));
  113. }
  114. private void queryWarning() {
  115. activity.addDisposable(ApiRepository.INSTANCE.warnList(String.valueOf(activity.labConfig.getLabId())).subscribe(new Consumer<List<LabWarnVo>>() {
  116. @Override
  117. public void accept(List<LabWarnVo> labWarnVos) throws Exception {
  118. activity.homeBoardAdapter.updateWaringValue(labWarnVos);
  119. }
  120. }, onError));
  121. }
  122. private void dispatchLabDevice(List<LabBulletinBoardVo> labBulletinBoardVos) {
  123. if (null != labBulletinBoardVos && !labBulletinBoardVos.isEmpty()) {
  124. if (null == activity.homeBoardAdapter) {
  125. activity.homeBoardAdapter = new HomeBoardAdapter();
  126. }
  127. activity.homeBoardAdapter.setNewInstance(labBulletinBoardVos);
  128. // activity.binding.bulletinBoardView.initTimer(4, labBulletinBoardVos.size());
  129. // activity.binding.bulletinBoardView.startAuto(3000);
  130. queryWarning();
  131. } else {
  132. activity.homeBoardAdapter.setEmptyView(R.layout.view_list_empty);
  133. }
  134. }
  135. private void dispatchLabPerson(HomeRightResp data) {
  136. // 值班人员
  137. if (null != data.dutyUser && !data.dutyUser.isEmpty()) {
  138. activity.personList.clear();
  139. activity.personList.addAll(data.dutyUser);
  140. activity.personFlipperAdapter.notifyDataSetChanged();
  141. activity.binding.dutyPerson.startFlipping();
  142. } else {
  143. activity.personList.clear();
  144. activity.personFlipperAdapter.notifyDataSetChanged();
  145. activity.binding.dutyPerson.stopFlipping();
  146. }
  147. // 实验人员
  148. if (null != data.tentativeUser && !data.tentativeUser.isEmpty()) {
  149. activity.experimentList.clear();
  150. activity.experimentList.addAll(data.tentativeUser);
  151. activity.experimentAdapter.notifyDataSetChanged();
  152. activity.binding.experimentPerson.startFlipping();
  153. } else {
  154. activity.experimentList.clear();
  155. activity.experimentAdapter.notifyDataSetChanged();
  156. activity.binding.experimentPerson.stopFlipping();
  157. }
  158. // 准入人员
  159. if (null != data.securityUser && !data.securityUser.isEmpty()) {
  160. activity.accessList.clear();
  161. activity.accessList.addAll(data.securityUser);
  162. activity.accessAdapter.notifyDataSetChanged();
  163. activity.binding.accessPerson.startFlipping();
  164. } else {
  165. activity.accessList.clear();
  166. activity.accessAdapter.notifyDataSetChanged();
  167. activity.binding.accessPerson.stopFlipping();
  168. }
  169. }
  170. private final Consumer<Throwable> onError = new Consumer<Throwable>() {
  171. @Override
  172. public void accept(Throwable throwable) throws Exception {
  173. activity.dismissLoading();
  174. activity.showNetError(throwable);
  175. LogUtils.e(Log.getStackTraceString(throwable));
  176. }
  177. };
  178. }