UbiLpWxController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package com.zy.bms.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.zy.bms.common.ServerResponse;
  4. import com.zy.bms.entity.DeviceBase;
  5. import com.zy.bms.entity.UserPrivilege;
  6. import com.zy.bms.entity.lp.LpInfoState;
  7. import com.zy.bms.pojo.io.LpInfoRecordIO;
  8. import com.zy.bms.service.IDeviceBaseService;
  9. import com.zy.bms.service.IGroupService;
  10. import com.zy.bms.service.IPostMqttMsgService;
  11. import com.zy.bms.service.IUserPrivilegeService;
  12. import com.zy.bms.service.lp.ILpInfoRecordService;
  13. import com.zy.bms.service.lp.ILpInfoStateService;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import javax.annotation.Resource;
  17. import java.util.HashSet;
  18. import java.util.List;
  19. import java.util.Set;
  20. /**
  21. * 普适型,路牌 微信小程序接口
  22. *
  23. * @author yang xiao kun
  24. * create on 2021/8/24
  25. */
  26. public class UbiLpWxController extends BaseController {
  27. @Resource
  28. private IUserPrivilegeService userPrivilegeService;
  29. @Resource
  30. private IGroupService groupService;
  31. @Resource
  32. private IDeviceBaseService deviceBaseService;
  33. @Resource
  34. private IPostMqttMsgService postMqttMsgService;
  35. @Resource
  36. private ILpInfoStateService lpInfoStateService;
  37. @Resource
  38. private ILpInfoRecordService lpInfoRecordService;
  39. /**
  40. * 查看用户拥有权限的设备组列表
  41. */
  42. @GetMapping("getGroups.do")
  43. public ServerResponse getGroupsByUserId() {
  44. return ServerResponse.success(groupService.getByUserId(userId()));
  45. }
  46. /**
  47. * 校验设备码是否存在
  48. */
  49. @GetMapping("checkOpenNum.do")
  50. public ServerResponse checkOpenNum(String openNum) {
  51. return ServerResponse.success(deviceBaseService.checkOpenNum(openNum));
  52. }
  53. /**
  54. * 通过设备组ID查询设备列表
  55. */
  56. @GetMapping("getDevicesByGroupId.do")
  57. public ServerResponse getDevicesByGroupId(String groupId) {
  58. Set<String> groupIds = new HashSet<>(userPrivilegeService.getGroupIdsByUserId(userId()));
  59. if (!groupIds.contains(groupId)) return ServerResponse.warning("无权限");
  60. return ServerResponse.success(deviceBaseService.listByGroupIdWx(groupId));
  61. }
  62. /**
  63. * 分组查询设备列表
  64. */
  65. @GetMapping("getDevicesByUserId.do")
  66. public ServerResponse getDevicesByGroupId() {
  67. List<String> groupIds = userPrivilegeService.getGroupIdsByUserId(userId());
  68. if (groupIds.isEmpty()) return ServerResponse.success(null);
  69. return ServerResponse.success(deviceBaseService.listByGroupIdsWx(groupIds));
  70. }
  71. /**
  72. * 扫码查询
  73. */
  74. @GetMapping("scan.do")
  75. public ServerResponse scan(String openNum) {
  76. DeviceBase device = deviceBaseService.getOne(new QueryWrapper<DeviceBase>().eq("open_num", openNum));
  77. if (device == null) return ServerResponse.warning("设备码错误!");
  78. //如果该用户没有该设备组权限,则加上权限
  79. UserPrivilege userPrivilege = userPrivilegeService.getOne(new QueryWrapper<UserPrivilege>()
  80. .eq("group_id", device.getGroupId()).eq("user_id", userId()));
  81. if (userPrivilege == null) {
  82. UserPrivilege entity = new UserPrivilege();
  83. entity.setUserId(userId());
  84. entity.setGroupId(device.getGroupId());
  85. userPrivilegeService.save(entity);
  86. }
  87. return ServerResponse.success(deviceBaseService.getDetailWx(openNum));
  88. }
  89. /**
  90. * 获取设备详情信息
  91. */
  92. @GetMapping("getDeviceDetail.do")
  93. public ServerResponse getDeviceDetail(String openNum) {
  94. return ServerResponse.success(deviceBaseService.getDetailWx(openNum));
  95. }
  96. /**
  97. * 更新唤醒时间和阈值
  98. */
  99. @PostMapping("update.do")
  100. public ServerResponse update(LpInfoState entity) {
  101. return ServerResponse.success(lpInfoStateService.updateWakeAndThresh(entity));
  102. }
  103. /**
  104. * 蜂鸣器
  105. */
  106. @GetMapping("buzzing.do")
  107. public ServerResponse buzzing(String openNum) {
  108. postMqttMsgService.requestBuzzingUbi(openNum);
  109. return ServerResponse.success();
  110. }
  111. /**
  112. * 立即请求获取最新心跳包
  113. */
  114. @GetMapping("heartbeat.do")
  115. public ServerResponse heartbeat(String openNum) {
  116. postMqttMsgService.requestHeartbeatUbi(openNum);
  117. return ServerResponse.success();
  118. }
  119. /**
  120. * 查询路牌设备历史记录
  121. */
  122. @GetMapping("getLpHistoryData.do")
  123. public ServerResponse getLpHistoryData(LpInfoRecordIO io) {
  124. return ServerResponse.success(lpInfoRecordService.getHistoryList(io));
  125. }
  126. }