Browse Source

修改微信小程序接口

yangxiaokun 3 years ago
parent
commit
becafa3a19

+ 2 - 7
src/main/java/com/zy/bms/controller/UbiLpWxController.java

@@ -111,9 +111,7 @@ public class UbiLpWxController extends BaseController {
      */
     @GetMapping("getDevicesByUserId.do")
     public ServerResponse getDevicesByUserId() {
-        List<String> groupIds = userPrivilegeService.getGroupIdsByUserId(userId());
-        if (groupIds == null || groupIds.isEmpty()) return ServerResponse.success(null);
-        return ServerResponse.success(deviceBaseService.listByGroupIdsWx(groupIds));
+        return ServerResponse.success(deviceBaseService.listByUserIdWx(userId()));
     }
 
     /**
@@ -124,11 +122,8 @@ public class UbiLpWxController extends BaseController {
         DeviceBase device = deviceBaseService.getOne(new QueryWrapper<DeviceBase>().eq("open_num", openNum));
         if (device == null) return ServerResponse.warning("设备码错误!");
         //如果该用户没有该设备组权限,则加上权限
-        if (userPrivilegeService.getOne(new QueryWrapper<UserPrivilege>()
-                .eq("group_id", device.getGroupId())
-                .eq("user_id", userId())) == null) {
+        if (!userPrivilegeService.hasPrivilege(userId(), device.getGroupId()))
             userPrivilegeService.save(new UserPrivilege(userId(), device.getGroupId()));
-        }
         return ServerResponse.success(device.getType());
     }
 

+ 1 - 18
src/main/java/com/zy/bms/mapper/DeviceBaseMapper.java

@@ -2,13 +2,10 @@ package com.zy.bms.mapper;
 
 import com.zy.bms.entity.DeviceBase;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.zy.bms.pojo.vo.DeviceWxListVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
-import java.util.List;
-
 /**
  * 设备静态信息 Mapper 接口
  *
@@ -19,24 +16,10 @@ import java.util.List;
 @Repository
 public interface DeviceBaseMapper extends BaseMapper<DeviceBase> {
 
-    /**
-     * 检查设备码是否存在
-     *
-     * @param openNum 设备码
-     */
-    int checkOpenNum(@Param("openNum") String openNum);
-
     /**
      * 通过设备组查询类型
      *
      * @param groupId 设备组
      */
-    String getTypeByGroupId(String groupId);
-
-    /**
-     * 通过设备组集合查询全部设备
-     *
-     * @param groupIds 设备组集合
-     */
-    List<DeviceWxListVo> listByGroupIds(@Param("groupIds") List<String> groupIds);
+    String getTypeByGroupId(@Param("groupId") String groupId);
 }

+ 2 - 1
src/main/java/com/zy/bms/mapper/lp/LpInfoStateMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zy.bms.entity.lp.LpInfoState;
 import com.zy.bms.pojo.io.DeviceIO;
+import com.zy.bms.pojo.vo.DeviceWxListVo;
 import com.zy.bms.pojo.vo.LpDeviceListVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -42,7 +43,7 @@ public interface LpInfoStateMapper extends BaseMapper<LpInfoState> {
      *
      * @param userId 用户ID
      */
-    List<LpInfoState> listByUserId(@Param("userId") Integer userId);
+    List<DeviceWxListVo> listByUserId(@Param("userId") Integer userId);
 
     /**
      * 更新唤醒时间和阈值

+ 8 - 2
src/main/java/com/zy/bms/mapper/ubi/UbiInfoStateMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zy.bms.entity.ubi.UbiInfoState;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.zy.bms.pojo.io.DeviceIO;
+import com.zy.bms.pojo.vo.DeviceWxListVo;
 import com.zy.bms.pojo.vo.UbiDeviceDetailVo;
 import com.zy.bms.pojo.vo.UbiDeviceListVo;
 import org.apache.ibatis.annotations.Mapper;
@@ -40,11 +41,16 @@ public interface UbiInfoStateMapper extends BaseMapper<UbiInfoState> {
     UbiDeviceDetailVo getDetail(@Param("openNum") String openNum);
 
     /**
-     * 微信端
-     * 通过设备组分页查询设备列表
+     * 通过设备组 查询设备集合
      *
      * @param groupId 设备组
      */
     List<UbiInfoState> listByGroupId(@Param("groupId") String groupId);
 
+    /**
+     * 通过用户ID 查询设备集合
+     *
+     * @param userId 用户ID
+     */
+    List<DeviceWxListVo> listByUserId(@Param("userId") Integer userId);
 }

+ 2 - 9
src/main/java/com/zy/bms/service/IDeviceBaseService.java

@@ -15,13 +15,6 @@ import java.util.Map;
  */
 public interface IDeviceBaseService extends IService<DeviceBase> {
 
-    /**
-     * 校验设备码是否存在
-     *
-     * @param openNum 设备码
-     */
-    boolean checkOpenNum(String openNum);
-
     /**
      * 微信
      * 通过设备组查询设备集合
@@ -34,9 +27,9 @@ public interface IDeviceBaseService extends IService<DeviceBase> {
      * 微信
      * 通过设备组集合查询全部设备
      *
-     * @param groupIds 设备组ID集合
+     * @param userId 用户ID
      */
-    Map<String, List<DeviceWxListVo>> listByGroupIdsWx(List<String> groupIds);
+    Map<String, List<DeviceWxListVo>> listByUserIdWx(Integer userId);
 
     /**
      * 微信

+ 8 - 0
src/main/java/com/zy/bms/service/IUserPrivilegeService.java

@@ -30,6 +30,14 @@ public interface IUserPrivilegeService extends IService<UserPrivilege> {
      */
     Map<String, List<GroupListVo>> getGroupByUserId(Integer userId);
 
+    /**
+     * 查询用户是否有某设备组的权限
+     *
+     * @param userId  用户ID
+     * @param groupId 设备组
+     */
+    boolean hasPrivilege(Integer userId, String groupId);
+
     /**
      * 批量保存实体类
      *

+ 10 - 9
src/main/java/com/zy/bms/service/impl/DeviceBaseServiceImpl.java

@@ -14,6 +14,7 @@ import com.zy.bms.service.ubi.IUbiInfoStateService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -33,11 +34,6 @@ public class DeviceBaseServiceImpl extends ServiceImpl<DeviceBaseMapper, DeviceB
     @Resource
     private ILpInfoStateService lpInfoStateService;
 
-    @Override
-    public boolean checkOpenNum(String openNum) {
-        return baseMapper.checkOpenNum(openNum) > 0;
-    }
-
     @Override
     public List listByGroupIdWx(String groupId) {
         String type = baseMapper.getTypeByGroupId(groupId);
@@ -54,10 +50,15 @@ public class DeviceBaseServiceImpl extends ServiceImpl<DeviceBaseMapper, DeviceB
     }
 
     @Override
-    public Map<String, List<DeviceWxListVo>> listByGroupIdsWx(List<String> groupIds) {
-        List<DeviceWxListVo> list = baseMapper.listByGroupIds(groupIds);
-        if (list.isEmpty()) return null;
-        return list.stream().collect(Collectors.groupingBy(DeviceWxListVo::getGroupId));
+    public Map<String, List<DeviceWxListVo>> listByUserIdWx(Integer userId) {
+        List<DeviceWxListVo> result = new ArrayList<>();
+        //路牌
+        List<DeviceWxListVo> lpList = lpInfoStateService.listByUserId(userId);
+        if (lpList != null) result.addAll(lpList);
+        //普适型
+        List<DeviceWxListVo> ubiList = ubiInfoStateService.listByUserId(userId);
+        if (ubiList != null) result.addAll(ubiList);
+        return result.isEmpty() ? null : result.stream().collect(Collectors.groupingBy(DeviceWxListVo::getGroupId));
     }
 
     @Override

+ 8 - 0
src/main/java/com/zy/bms/service/impl/UserPrivilegeServiceImpl.java

@@ -1,5 +1,6 @@
 package com.zy.bms.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zy.bms.entity.UserPrivilege;
 import com.zy.bms.mapper.UserPrivilegeMapper;
 import com.zy.bms.pojo.vo.GroupListVo;
@@ -42,6 +43,13 @@ public class UserPrivilegeServiceImpl extends ServiceImpl<UserPrivilegeMapper, U
                 .collect(Collectors.groupingBy(GroupListVo::getItem));
     }
 
+    @Override
+    public boolean hasPrivilege(Integer userId, String groupId) {
+        return baseMapper.selectOne(new QueryWrapper<UserPrivilege>()
+                .eq("group_id", groupId)
+                .eq("user_id", userId)) != null;
+    }
+
     @Override
     public void saveBatch(Integer userId, String[] groups) {
         baseMapper.saveBatch(userId, groups);

+ 8 - 0
src/main/java/com/zy/bms/service/lp/ILpInfoStateService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zy.bms.entity.lp.LpInfoState;
 import com.zy.bms.pojo.io.DeviceIO;
+import com.zy.bms.pojo.vo.DeviceWxListVo;
 import com.zy.bms.pojo.vo.LpDeviceListVo;
 
 import java.util.List;
@@ -31,6 +32,13 @@ public interface ILpInfoStateService extends IService<LpInfoState> {
      */
     List<LpInfoState> listByGroupId(String groupId);
 
+    /**
+     * 通过用户ID 查询设备集合
+     *
+     * @param userId 用户ID
+     */
+    List<DeviceWxListVo> listByUserId(Integer userId);
+
     /**
      * 通过设备ID获取设备信息
      *

+ 6 - 0
src/main/java/com/zy/bms/service/lp/impl/LpInfoStateServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zy.bms.entity.lp.LpInfoState;
 import com.zy.bms.mapper.lp.LpInfoStateMapper;
 import com.zy.bms.pojo.io.DeviceIO;
+import com.zy.bms.pojo.vo.DeviceWxListVo;
 import com.zy.bms.pojo.vo.LpDeviceListVo;
 import com.zy.bms.service.lp.ILpInfoStateService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -35,6 +36,11 @@ public class LpInfoStateServiceImpl extends ServiceImpl<LpInfoStateMapper, LpInf
         return baseMapper.listByGroupId(groupId);
     }
 
+    @Override
+    public List<DeviceWxListVo> listByUserId(Integer userId) {
+        return baseMapper.listByUserId(userId);
+    }
+
     @Override
     public LpInfoState getByOpenNum(String openNum) {
         return baseMapper.selectOne(new QueryWrapper<LpInfoState>().eq("open_num", openNum));

+ 7 - 0
src/main/java/com/zy/bms/service/ubi/IUbiInfoStateService.java

@@ -5,6 +5,7 @@ import com.zy.bms.entity.ubi.UbiInfoState;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zy.bms.pojo.io.DeviceIO;
 import com.zy.bms.pojo.io.PageIO;
+import com.zy.bms.pojo.vo.DeviceWxListVo;
 import com.zy.bms.pojo.vo.UbiDeviceDetailVo;
 import com.zy.bms.pojo.vo.UbiDeviceListVo;
 
@@ -42,4 +43,10 @@ public interface IUbiInfoStateService extends IService<UbiInfoState> {
      */
     List<UbiInfoState> listByGroupId(String groupId);
 
+    /**
+     * 通过用户ID 查询设备集合
+     *
+     * @param userId 用户ID
+     */
+    List<DeviceWxListVo> listByUserId(Integer userId);
 }

+ 6 - 0
src/main/java/com/zy/bms/service/ubi/impl/UbiInfoStateServiceImpl.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zy.bms.entity.ubi.UbiInfoState;
 import com.zy.bms.mapper.ubi.UbiInfoStateMapper;
 import com.zy.bms.pojo.io.DeviceIO;
+import com.zy.bms.pojo.vo.DeviceWxListVo;
 import com.zy.bms.pojo.vo.UbiDeviceDetailVo;
 import com.zy.bms.pojo.vo.UbiDeviceListVo;
 import com.zy.bms.service.ubi.IUbiInfoStateService;
@@ -50,4 +51,9 @@ public class UbiInfoStateServiceImpl extends ServiceImpl<UbiInfoStateMapper, Ubi
         return baseMapper.listByGroupId(groupId);
     }
 
+    @Override
+    public List<DeviceWxListVo> listByUserId(Integer userId) {
+        return baseMapper.listByUserId(userId);
+    }
+
 }

+ 0 - 36
src/main/resources/mapper/DeviceBaseMapper.xml

@@ -2,44 +2,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.DeviceBaseMapper">
 
-    <select id="checkOpenNum" resultType="java.lang.Integer">
-        SELECT IFNULL((SELECT 1 FROM device_base WHERE open_num = #{openNum} LIMIT 1), 0)
-    </select>
-
     <select id="getTypeByGroupId" resultType="java.lang.String">
         SELECT type FROM device_base WHERE group_id = #{group_id} LIMIT 1
     </select>
 
-    <select id="listByGroupIds" resultType="com.zy.bms.pojo.vo.DeviceWxListVo">
-        SELECT
-        t1.open_num,
-        t1.group_id,
-        t1.type,
-        t2.update_time,
-        IF(TIMESTAMPDIFF(SECOND, t2.update_time, NOW()) > t2.wake_int * 3600 + 180,0,1) AS `status`
-        FROM
-        device_base t1
-        INNER JOIN lp_info_state t2 ON t1.open_num = t2.open_num AND t1.type = 'lupai'
-        WHERE
-         t1.group_id IN
-        <foreach collection="groupIds" open="(" separator="," close=")" item="groupId">
-            #{groupId}
-        </foreach>
-        UNION
-        SELECT
-        t1.open_num,
-        t1.group_id,
-        t1.type,
-        t2.update_time,
-        IF(TIMESTAMPDIFF(SECOND, t2.update_time, NOW()) > IFNULL(t2.freq, 0) + 180,0,1) AS `status`
-        FROM
-        device_base t1
-        INNER JOIN ubi_info_state t2 ON t1.open_num = t2.open_num AND t1.type = 'gnss'
-        WHERE
-        t1.group_id IN
-        <foreach collection="groupIds" open="(" separator="," close=")" item="groupId">
-            #{groupId}
-        </foreach>
-    </select>
-
 </mapper>

+ 13 - 5
src/main/resources/mapper/LpInfoStateMapper.xml

@@ -25,11 +25,19 @@
         </if>
     </select>
 
-    <select id="listByUserId" resultType="com.zy.bms.entity.lp.LpInfoState">
-        SELECT t2.*
-        FROM device_base t1
-                 LEFT JOIN lp_info_state t2 ON t1.open_num = t2.open_num
-        WHERE t1.group_id IN (SELECT group_id FROM user_privilege WHERE user_id = #{userId})
+    <select id="listByUserId" resultType="com.zy.bms.pojo.vo.DeviceWxListVo">
+        SELECT
+            t1.open_num,
+            t1.group_id,
+            t1.type,
+            t2.update_time,
+            IF(TIMESTAMPDIFF(SECOND, t2.update_time, NOW()) > t2.wake_int * 3600 + 180,0,1) AS `status`
+        FROM
+            device_base t1
+        LEFT JOIN lp_info_state t2 ON t1.open_num = t2.open_num
+        WHERE
+            t1.type = 'lupai'
+            AND t1.group_id IN (SELECT group_id FROM user_privilege WHERE user_id = #{userId})
     </select>
 
     <select id="listByGroupId" resultType="com.zy.bms.entity.lp.LpInfoState">

+ 15 - 0
src/main/resources/mapper/UbiInfoStateMapper.xml

@@ -39,4 +39,19 @@
         WHERE open_num IN (SELECT open_num FROM device_base WHERE type = 'gnss' AND group_id = #{groupId})
     </select>
 
+    <select id="listByUserId" resultType="com.zy.bms.pojo.vo.DeviceWxListVo">
+        SELECT
+            t1.open_num,
+            t1.group_id,
+            t1.type,
+            t2.update_time,
+            IF(TIMESTAMPDIFF(SECOND, t2.update_time, NOW()) > IFNULL(t2.freq, 0) + 180,0,1) AS `status`
+        FROM
+            device_base t1
+        LEFT JOIN ubi_info_state t2 ON t1.open_num = t2.open_num
+        WHERE
+            t1.type = 'gnss'
+            AND t1.group_id IN (SELECT group_id FROM user_privilege WHERE user_id = #{userId})
+    </select>
+
 </mapper>