|
@@ -0,0 +1,116 @@
|
|
|
+package com.zy.bms.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.zy.bms.common.ServerResponse;
|
|
|
+import com.zy.bms.entity.DeviceBase;
|
|
|
+import com.zy.bms.entity.UserPrivilege;
|
|
|
+import com.zy.bms.entity.lp.LpInfoState;
|
|
|
+import com.zy.bms.service.IDeviceBaseService;
|
|
|
+import com.zy.bms.service.IGroupService;
|
|
|
+import com.zy.bms.service.IPostMqttMsgService;
|
|
|
+import com.zy.bms.service.IUserPrivilegeService;
|
|
|
+import com.zy.bms.service.lp.ILpInfoStateService;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 普适型,路牌 微信小程序接口
|
|
|
+ *
|
|
|
+ * @author yang xiao kun
|
|
|
+ * create on 2021/8/24
|
|
|
+ */
|
|
|
+public class UbiLpWxController extends BaseController {
|
|
|
+ @Resource
|
|
|
+ private IUserPrivilegeService userPrivilegeService;
|
|
|
+ @Resource
|
|
|
+ private IGroupService groupService;
|
|
|
+ @Resource
|
|
|
+ private IDeviceBaseService deviceBaseService;
|
|
|
+ @Resource
|
|
|
+ private IPostMqttMsgService postMqttMsgService;
|
|
|
+ @Resource
|
|
|
+ private ILpInfoStateService lpInfoStateService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看用户拥有权限的设备组列表
|
|
|
+ */
|
|
|
+ @GetMapping("getGroups.do")
|
|
|
+ public ServerResponse getGroupsByUserId() {
|
|
|
+ return ServerResponse.success(groupService.getByUserId(userId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验设备码是否存在
|
|
|
+ */
|
|
|
+ @GetMapping("checkOpenNum.do")
|
|
|
+ public ServerResponse checkOpenNum(String openNum) {
|
|
|
+ return ServerResponse.success(deviceBaseService.checkOpenNum(openNum));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过设备组ID查询设备列表
|
|
|
+ */
|
|
|
+ @GetMapping("getDevices.do")
|
|
|
+ public ServerResponse getDevicesByGroupId(String groupId) {
|
|
|
+ Set<String> groupIds = new HashSet<>(userPrivilegeService.getGroupIdsByUserId(userId()));
|
|
|
+ if (!groupIds.contains(groupId)) return ServerResponse.warning("无权限");
|
|
|
+ return ServerResponse.success(deviceBaseService.listByGroupIdWx(groupId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 扫码查询
|
|
|
+ */
|
|
|
+ @GetMapping("scan.do")
|
|
|
+ public ServerResponse scan(String openNum) {
|
|
|
+ DeviceBase device = deviceBaseService.getOne(new QueryWrapper<DeviceBase>().eq("open_num", openNum));
|
|
|
+ if (device == null) return ServerResponse.warning("设备码错误!");
|
|
|
+ //如果该用户没有该设备组权限,则加上权限
|
|
|
+ UserPrivilege userPrivilege = userPrivilegeService.getOne(new QueryWrapper<UserPrivilege>()
|
|
|
+ .eq("group_id", device.getGroupId()).eq("user_id", userId()));
|
|
|
+ if (userPrivilege == null) {
|
|
|
+ UserPrivilege entity = new UserPrivilege();
|
|
|
+ entity.setUserId(userId());
|
|
|
+ entity.setGroupId(device.getGroupId());
|
|
|
+ userPrivilegeService.save(entity);
|
|
|
+ }
|
|
|
+ return ServerResponse.success(deviceBaseService.getDetailWx(openNum));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取设备详情信息
|
|
|
+ */
|
|
|
+ @GetMapping("getDeviceDetail.do")
|
|
|
+ public ServerResponse getDeviceDetail(String openNum) {
|
|
|
+ return ServerResponse.success(deviceBaseService.getDetailWx(openNum));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新唤醒时间和阈值
|
|
|
+ */
|
|
|
+ @PostMapping("update.do")
|
|
|
+ public ServerResponse update(LpInfoState entity) {
|
|
|
+ return ServerResponse.success(lpInfoStateService.updateWakeAndThresh(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 蜂鸣器
|
|
|
+ */
|
|
|
+ @GetMapping("buzzing.do")
|
|
|
+ public ServerResponse buzzing(String openNum) {
|
|
|
+ postMqttMsgService.requestBuzzingUbi(openNum);
|
|
|
+ return ServerResponse.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 立即请求获取最新心跳包
|
|
|
+ */
|
|
|
+ @GetMapping("heartbeat.do")
|
|
|
+ public ServerResponse heartbeat(String openNum) {
|
|
|
+ postMqttMsgService.requestHeartbeatUbi(openNum);
|
|
|
+ return ServerResponse.success();
|
|
|
+ }
|
|
|
+}
|