Browse Source

修改微信小程序接口

yangxiaokun 3 years ago
parent
commit
f185ba8457

+ 0 - 61
src/main/java/com/zy/bms/controller/PrivilegeApplyController.java

@@ -1,61 +0,0 @@
-package com.zy.bms.controller;
-
-import com.zy.bms.common.ServerResponse;
-import com.zy.bms.entity.PrivilegeApplyRecord;
-import com.zy.bms.pojo.io.PrivilegeApplyIO;
-import com.zy.bms.service.IPrivilegeApplyRecordService;
-import com.zy.bms.service.IUserPrivilegeService;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.annotation.Resource;
-import java.time.LocalDateTime;
-
-/**
- * 权限申请记录 前端控制器
- *
- * @author chenyi
- * @since 2021-07-12
- */
-@RestController
-@RequestMapping("/bms/api/operate/privilegeApply")
-public class PrivilegeApplyController extends BaseController {
-
-    @Resource
-    private IPrivilegeApplyRecordService privilegeApplyRecordService;
-
-    @Resource
-    private IUserPrivilegeService userPrivilegeService;
-
-    /**
-     * 分页查询
-     */
-    @GetMapping("listPage.do")
-    public ServerResponse listPage(PrivilegeApplyIO io) {
-        return ServerResponse.success(privilegeApplyRecordService.listPage(io));
-    }
-
-    /**
-     * 获取用户未有权限的设备组
-     */
-    @GetMapping("getNoPrivGroups.do")
-    public ServerResponse getNoPrivGroups() {
-        return ServerResponse.success(userPrivilegeService.getGroupByUserId(userId()));
-    }
-
-    /**
-     * 审核
-     */
-    @PostMapping("audit.do")
-    public ServerResponse audit(PrivilegeApplyRecord entity, String[] groups) {
-        //审核时间
-        entity.setAuditTime(LocalDateTime.now());
-        //保存有权限的设备组
-        if (entity.getStatus() != null && entity.getStatus() == 1) userPrivilegeService.saveBatch(userId(), groups);
-        //更新申请记录
-        privilegeApplyRecordService.updateById(entity);
-        return ServerResponse.success();
-    }
-}

+ 27 - 0
src/main/java/com/zy/bms/controller/UbiLpWxController.java

@@ -2,6 +2,7 @@ package com.zy.bms.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zy.bms.common.ServerResponse;
+import com.zy.bms.common.enums.ResponseCode;
 import com.zy.bms.entity.DeviceBase;
 import com.zy.bms.entity.User;
 import com.zy.bms.entity.UserPrivilege;
@@ -11,6 +12,7 @@ import com.zy.bms.service.*;
 import com.zy.bms.service.lp.ILpInfoRecordService;
 import com.zy.bms.service.lp.ILpInfoStateService;
 import com.zy.bms.utils.AesUtil;
+import com.zy.bms.utils.RabbitMQApi;
 import com.zy.bms.utils.RandomCode;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -64,9 +66,34 @@ public class UbiLpWxController extends BaseController {
         Map<String, String> res = new HashMap<>();
         res.put("userId", AesUtil.encrypt(user.getId().toString()));
         res.put("uuid", user.getRandomCode());
+        res.put("admin", user.getAdmin().toString());
         return ServerResponse.success(res);
     }
 
+    /**
+     * 查看当前在线设备 rabbitMQ
+     */
+    @GetMapping("connections.do")
+    public ServerResponse connections() {
+        User user = userService.getOne(new QueryWrapper<User>().eq("user_id", userId()));
+        if (user == null || user.getAdmin() != 1) {
+            return ServerResponse.custom(ResponseCode.AUTHOR);
+        }
+        return ServerResponse.success(RabbitMQApi.connections());
+    }
+
+    /**
+     * 查看当前注册的用户 rabbitMQ
+     */
+    @GetMapping("users.do")
+    public ServerResponse users() {
+        User user = userService.getOne(new QueryWrapper<User>().eq("user_id", userId()));
+        if (user == null || user.getAdmin() != 1) {
+            return ServerResponse.custom(ResponseCode.AUTHOR);
+        }
+        return ServerResponse.success(RabbitMQApi.users());
+    }
+
     /**
      * 查看用户拥有权限的设备组列表
      */

+ 41 - 0
src/main/java/com/zy/bms/controller/UserPrivilegeController.java

@@ -0,0 +1,41 @@
+package com.zy.bms.controller;
+
+import com.zy.bms.common.ServerResponse;
+import com.zy.bms.service.IUserPrivilegeService;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+/**
+ * 用户设备组权限
+ *
+ * @author chenyi
+ * @since 2021-07-12
+ */
+@RestController
+@RequestMapping("/bms/api/operate/userPrivilege")
+public class UserPrivilegeController extends BaseController {
+
+    @Resource
+    private IUserPrivilegeService userPrivilegeService;
+
+    /**
+     * 获取用户未有权限的设备组
+     */
+    @GetMapping("getGroupsByUserId.do")
+    public ServerResponse getGroupsByUserId(Integer userId) {
+        return ServerResponse.success(userPrivilegeService.getGroupByUserId(userId()));
+    }
+
+    /**
+     * 添加权限
+     */
+    @PostMapping("save.do")
+    public ServerResponse save(Integer userId, String[] groups) {
+        userPrivilegeService.saveBatch(userId, groups);
+        return ServerResponse.success();
+    }
+}

+ 0 - 63
src/main/java/com/zy/bms/entity/PrivilegeApplyRecord.java

@@ -1,63 +0,0 @@
-package com.zy.bms.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import lombok.Data;
-
-import java.time.LocalDateTime;
-import java.io.Serializable;
-
-/**
- * 权限申请记录
- *
- * @author chenyi
- * @since 2021-07-12
- */
-@Data
-public class PrivilegeApplyRecord implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    @TableId(type = IdType.AUTO)
-    private Integer id;
-
-    /**
-     * 用户ID
-     */
-    private Integer userId;
-
-    /**
-     * 姓名
-     */
-    private String name;
-
-    /**
-     * 手机号
-     */
-    private String phone;
-
-    /**
-     * 备注
-     */
-    private String remark;
-
-    /**
-     * 创建时间
-     */
-    private LocalDateTime createTime;
-
-    /**
-     * 1通过 -1拒绝 0待审核
-     */
-    private Integer status;
-
-    /**
-     * 审核时间
-     */
-    private LocalDateTime auditTime;
-
-    /**
-     * 拒绝原因
-     */
-    private String refuseReason;
-}

+ 5 - 0
src/main/java/com/zy/bms/entity/User.java

@@ -83,4 +83,9 @@ public class User implements Serializable {
      * 随机码
      */
     private String randomCode;
+
+    /**
+     * 是否是管理员
+     */
+    private Integer admin;
 }

+ 0 - 25
src/main/java/com/zy/bms/mapper/PrivilegeApplyRecordMapper.java

@@ -1,25 +0,0 @@
-package com.zy.bms.mapper;
-
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.zy.bms.entity.PrivilegeApplyRecord;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.zy.bms.pojo.io.PrivilegeApplyIO;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.springframework.stereotype.Repository;
-
-/**
- * 权限申请记录 Mapper 接口
- *
- * @author chenyi
- * @since 2021-07-12
- */
-@Mapper
-@Repository
-public interface PrivilegeApplyRecordMapper extends BaseMapper<PrivilegeApplyRecord> {
-    /**
-     * 分页查询
-     */
-    IPage<PrivilegeApplyRecord> listPage(Page<PrivilegeApplyRecord> page, @Param("io") PrivilegeApplyIO io);
-}

+ 0 - 21
src/main/java/com/zy/bms/service/IPrivilegeApplyRecordService.java

@@ -1,21 +0,0 @@
-package com.zy.bms.service;
-
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.zy.bms.entity.PrivilegeApplyRecord;
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.zy.bms.pojo.io.PrivilegeApplyIO;
-
-/**
- * 权限申请记录 服务类
- *
- * @author chenyi
- * @since 2021-07-12
- */
-public interface IPrivilegeApplyRecordService extends IService<PrivilegeApplyRecord> {
-
-    /**
-     * 分页查询
-     */
-    IPage<PrivilegeApplyRecord> listPage(PrivilegeApplyIO io);
-
-}

+ 0 - 27
src/main/java/com/zy/bms/service/impl/PrivilegeApplyRecordServiceImpl.java

@@ -1,27 +0,0 @@
-package com.zy.bms.service.impl;
-
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.zy.bms.entity.PrivilegeApplyRecord;
-import com.zy.bms.mapper.PrivilegeApplyRecordMapper;
-import com.zy.bms.pojo.io.PrivilegeApplyIO;
-import com.zy.bms.service.IPrivilegeApplyRecordService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
-
-/**
- * 权限申请记录 服务实现类
- *
- * @author chenyi
- * @since 2021-07-12
- */
-@Service
-public class PrivilegeApplyRecordServiceImpl extends ServiceImpl<PrivilegeApplyRecordMapper, PrivilegeApplyRecord> implements IPrivilegeApplyRecordService {
-
-    @Override
-    public IPage<PrivilegeApplyRecord> listPage(PrivilegeApplyIO io) {
-        Page<PrivilegeApplyRecord> page = new Page<>(io.getCurrent(), io.getSize());
-        return baseMapper.listPage(page, io);
-    }
-
-}

+ 56 - 4
src/main/java/com/zy/bms/utils/RabbitMQApi.java

@@ -1,11 +1,12 @@
 package com.zy.bms.utils;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpHeaders;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 /**
  * RabbitMQ HTTP API接口请求
@@ -15,6 +16,8 @@ import java.util.Map;
  */
 @Slf4j
 public class RabbitMQApi {
+    private final static String authorization = "Basic bHEyMDE5OkxpUXVhblJhYmJpdA==";
+
     /**
      * 向 MQTT 服务器申请用户,供设备进行登录
      * <p>
@@ -60,7 +63,7 @@ public class RabbitMQApi {
         String url = "http://view.ailishi.org:15672/api/users/" + username;
         //请求头
         HttpHeaders headers = new HttpHeaders();
-        headers.add("authorization", "Basic bHEyMDE5OkxpUXVhblJhYmJpdA==");
+        headers.add("authorization", authorization);
         //请求参数
         Map<String, String> params = new HashMap<>();
         params.put("username", username);
@@ -78,7 +81,7 @@ public class RabbitMQApi {
         String url = "http://view.ailishi.org:15672/api/permissions/%2F/" + clientId;
         //请求头
         HttpHeaders headers = new HttpHeaders();
-        headers.add("authorization", "Basic bHEyMDE5OkxpUXVhblJhYmJpdA==");
+        headers.add("authorization", authorization);
         //请求参数
         Map<String, String> params = new HashMap<>();
         params.put("username", clientId);
@@ -93,4 +96,53 @@ public class RabbitMQApi {
         }
         return true;
     }
+
+    /**
+     * 查询MQTT服务器链接状态
+     */
+    public static List<String> connections() {
+        String url = "http://view.ailishi.org:15672/api/connections";
+        List<String> result = new LinkedList<>();
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("authorization", authorization);
+        try {
+            String response = HttpUtil.getForEntity(url, headers);
+            //返回结果不为空
+            if (!response.equals("")) {
+                JSONArray jsonArray = JSON.parseArray(response);
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    JSONObject jsonObject = jsonArray.getJSONObject(i);
+                    result.add(jsonObject.getString("user"));
+                }
+            }
+        } catch (Exception e) {
+            log.error("查询MQTT服务器Connections错误", e);
+        }
+        return result;
+    }
+
+    /**
+     * 查询MQTT服务器注册的用户
+     */
+    public static List<String> users() {
+        String url = "http://view.ailishi.org:15672/api/users";
+        List<String> result = new LinkedList<>();
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("authorization", authorization);
+        try {
+            String response = HttpUtil.getForEntity(url, headers);
+            //返回结果不为空
+            if (!response.equals("")) {
+                JSONArray jsonArray = JSON.parseArray(response);
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    JSONObject jsonObject = jsonArray.getJSONObject(i);
+                    result.add(jsonObject.getString("name"));
+                }
+            }
+        } catch (Exception e) {
+            log.error("查询MQTT服务器users错误", e);
+        }
+        return result;
+    }
+
 }

+ 0 - 20
src/main/resources/mapper/PrivilegeApplyRecordMapper.xml

@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.zy.bms.mapper.PrivilegeApplyRecordMapper">
-
-    <select id="listPage" resultType="com.zy.bms.entity.PrivilegeApplyRecord">
-        SELECT
-            *
-        FROM
-            privilege_apply_record
-        <where>
-            <if test="io.key != null and io.key != ''">
-                AND (phone LIKE CONCAT('%',#{io.key},'%') OR remark LIKE CONCAT('%',#{io.key},'%'))
-            </if>
-            <if test="io.status != null">
-                AND status = #{io.status}
-            </if>
-        </where>
-    </select>
-
-</mapper>