Browse Source

更新小程序接口

chenyi406 3 years ago
parent
commit
e81fa87a14

+ 1 - 1
src/main/java/com/zy/bms/config/InterceptorCfg.java

@@ -39,7 +39,7 @@ public class InterceptorCfg implements WebMvcConfigurer {
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         registry.addInterceptor(ubiAppAuthInterceptor)
-                .addPathPatterns("/bms/api/ubiapp/**");
+                .addPathPatterns("/bms/api/wx_app/**");
 
         registry.addInterceptor(operateAuthInterceptor)
                 .addPathPatterns("/bms/api/operate/**")

+ 1 - 1
src/main/java/com/zy/bms/config/interceptor/UbiAppAuthInterceptor.java

@@ -19,7 +19,7 @@ public class UbiAppAuthInterceptor extends HandlerInterceptorAdapter {
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
         String channel = request.getHeader("channel");
-        if (channel.equals("ubi-app") && request.getHeader("app_user") != null) return true;
+        if (channel.equals("wx-app") && request.getHeader("app_user") != null) return true;
         request.getRequestDispatcher("/bms/api/common/author.do").forward(request, response);
         return false;
     }

+ 10 - 5
src/main/java/com/zy/bms/controller/UbiLpWxController.java

@@ -14,11 +14,11 @@ import com.zy.bms.utils.AesUtil;
 import com.zy.bms.utils.RandomCode;
 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.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 /**
  * 普适型,路牌 微信小程序接口
@@ -26,6 +26,8 @@ import java.util.Set;
  * @author yang xiao kun
  * create on 2021/8/24
  */
+@RestController
+@RequestMapping("/bms/api/wx_app")
 public class UbiLpWxController extends BaseController {
     @Resource
     private IUserService userService;
@@ -59,7 +61,10 @@ public class UbiLpWxController extends BaseController {
             user.setRandomCode(RandomCode.UUID_8());
             userService.save(user);
         }
-        return ServerResponse.success(AesUtil.encrypt(user.getId().toString()));
+        Map<String, String> res = new HashMap<>();
+        res.put("userId", AesUtil.encrypt(user.getId().toString()));
+        res.put("uuid", user.getRandomCode());
+        return ServerResponse.success(res);
     }
 
     /**
@@ -92,7 +97,7 @@ public class UbiLpWxController extends BaseController {
      * 分组查询设备列表
      */
     @GetMapping("getDevicesByUserId.do")
-    public ServerResponse getDevicesByGroupId() {
+    public ServerResponse getDevicesByUserId() {
         List<String> groupIds = userPrivilegeService.getGroupIdsByUserId(userId());
         if (groupIds.isEmpty()) return ServerResponse.success(null);
         return ServerResponse.success(deviceBaseService.listByGroupIdsWx(groupIds));

+ 3 - 3
src/main/java/com/zy/bms/mapper/GroupMapper.java

@@ -6,6 +6,7 @@ import com.zy.bms.entity.Group;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.zy.bms.pojo.io.GroupIO;
 import com.zy.bms.pojo.vo.GroupListVo;
+import com.zy.bms.pojo.vo.GroupListWxVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
@@ -13,9 +14,7 @@ import org.springframework.stereotype.Repository;
 import java.util.List;
 
 /**
- * <p>
  * 项目组 Mapper 接口
- * </p>
  *
  * @author yangxiaokun
  * @since 2021-06-03
@@ -41,5 +40,6 @@ public interface GroupMapper extends BaseMapper<Group> {
      *
      * @param userId 用户ID
      */
-    List<Group> getByUserId(@Param("userId") Integer userId);
+    List<GroupListWxVo> getByUserId(@Param("userId") Integer userId);
+
 }

+ 4 - 0
src/main/java/com/zy/bms/mapper/lp/LpInfoRecordMapper.java

@@ -3,7 +3,9 @@ package com.zy.bms.mapper.lp;
 import com.zy.bms.entity.lp.LpInfoRecord;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.zy.bms.pojo.io.LpInfoRecordIO;
+import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
 
 import java.util.List;
 
@@ -13,6 +15,8 @@ import java.util.List;
  * @author chenyi
  * @since 2021-08-26
  */
+@Mapper
+@Repository
 public interface LpInfoRecordMapper extends BaseMapper<LpInfoRecord> {
 
     /**

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

@@ -35,7 +35,7 @@ public interface LpInfoStateMapper extends BaseMapper<LpInfoState> {
      *
      * @param groupId 设备组
      */
-    List<LpDeviceListVo> listByGroupIdWx(String groupId);
+    List<LpInfoState> listByGroupId(@Param("groupId") String groupId);
 
     /**
      * 通过用户ID 查询设备集合

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

@@ -45,6 +45,6 @@ public interface UbiInfoStateMapper extends BaseMapper<UbiInfoState> {
      *
      * @param groupId 设备组
      */
-    List<UbiDeviceListVo> listByGroupIdWx(@Param("groupId") String groupId);
+    List<UbiInfoState> listByGroupId(@Param("groupId") String groupId);
 
 }

+ 31 - 0
src/main/java/com/zy/bms/pojo/vo/GroupListWxVo.java

@@ -0,0 +1,31 @@
+package com.zy.bms.pojo.vo;
+
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * 微信
+ * 设备组列表视图
+ *
+ * @author yang xiao kun
+ * create on 2021/5/19
+ */
+@Data
+public class GroupListWxVo {
+
+    /**
+     * 项目组编号
+     */
+    private String code;
+
+    /**
+     * 项目组名称
+     */
+    private String name;
+
+    /**
+     * 设备数量
+     */
+    private Integer num;
+}

+ 2 - 1
src/main/java/com/zy/bms/service/IGroupService.java

@@ -5,6 +5,7 @@ import com.zy.bms.entity.Group;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zy.bms.pojo.io.GroupIO;
 import com.zy.bms.pojo.vo.GroupListVo;
+import com.zy.bms.pojo.vo.GroupListWxVo;
 
 import java.util.List;
 
@@ -35,5 +36,5 @@ public interface IGroupService extends IService<Group> {
      *
      * @param userId 用户ID
      */
-    List<Group> getByUserId(Integer userId);
+    List<GroupListWxVo> getByUserId(Integer userId);
 }

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

@@ -43,11 +43,11 @@ public class DeviceBaseServiceImpl extends ServiceImpl<DeviceBaseMapper, DeviceB
         String type = baseMapper.getTypeByGroupId(groupId);
         //普适型设备
         if (type.equals(Constant.DEVICE_TYPE.UBI)) {
-            return ubiInfoStateService.listByGroupIdWx(groupId);
+            return ubiInfoStateService.listByGroupId(groupId);
         }
         //路牌设备
         if (type.equals(Constant.DEVICE_TYPE.LP)) {
-            return lpInfoStateService.listByGroupIdWx(groupId);
+            return lpInfoStateService.listByGroupId(groupId);
         }
         return null;
     }

+ 2 - 1
src/main/java/com/zy/bms/service/impl/GroupServiceImpl.java

@@ -6,6 +6,7 @@ import com.zy.bms.entity.Group;
 import com.zy.bms.mapper.GroupMapper;
 import com.zy.bms.pojo.io.GroupIO;
 import com.zy.bms.pojo.vo.GroupListVo;
+import com.zy.bms.pojo.vo.GroupListWxVo;
 import com.zy.bms.service.IGroupService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
@@ -33,7 +34,7 @@ public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements
     }
 
     @Override
-    public List<Group> getByUserId(Integer userId) {
+    public List<GroupListWxVo> getByUserId(Integer userId) {
         return baseMapper.getByUserId(userId);
     }
 }

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

@@ -29,7 +29,7 @@ public interface ILpInfoStateService extends IService<LpInfoState> {
      *
      * @param groupId 设备组
      */
-    List<LpDeviceListVo> listByGroupIdWx(String groupId);
+    List<LpInfoState> listByGroupId(String groupId);
 
     /**
      * 通过设备ID获取设备信息

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

@@ -31,8 +31,8 @@ public class LpInfoStateServiceImpl extends ServiceImpl<LpInfoStateMapper, LpInf
     }
 
     @Override
-    public List<LpDeviceListVo> listByGroupIdWx(String groupId) {
-        return baseMapper.listByGroupIdWx(groupId);
+    public List<LpInfoState> listByGroupId(String groupId) {
+        return baseMapper.listByGroupId(groupId);
     }
 
     @Override

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

@@ -40,6 +40,6 @@ public interface IUbiInfoStateService extends IService<UbiInfoState> {
      *
      * @param groupId 设备组
      */
-    List<UbiDeviceListVo> listByGroupIdWx(String groupId);
+    List<UbiInfoState> listByGroupId(String groupId);
 
 }

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

@@ -46,8 +46,8 @@ public class UbiInfoStateServiceImpl extends ServiceImpl<UbiInfoStateMapper, Ubi
     }
 
     @Override
-    public List<UbiDeviceListVo> listByGroupIdWx(String groupId) {
-        return baseMapper.listByGroupIdWx(groupId);
+    public List<UbiInfoState> listByGroupId(String groupId) {
+        return baseMapper.listByGroupId(groupId);
     }
 
 }

+ 13 - 13
src/main/resources/mapper/GroupMapper.xml

@@ -30,22 +30,22 @@
     </select>
 
     <select id="getAllList" resultType="com.zy.bms.pojo.vo.GroupListVo">
-        SELECT
-        t1.code,
-        t1.name,
-        t2.name AS item
+        SELECT t1.code,
+               t1.name,
+               t2.name AS item
         FROM item_group t1
-        LEFT JOIN item t2 ON t1.item_id = t2.id
+                 LEFT JOIN item t2 ON t1.item_id = t2.id
     </select>
 
-    <select id="getByUserId" resultType="com.zy.bms.entity.Group">
-        SELECT
-            *
-        FROM
-            item_group
-        WHERE
-            `code` IN (SELECT group_id FROM user_privilege WHERE userId = #{userId})
-            AND `status` = 1
+    <select id="getByUserId" resultType="com.zy.bms.pojo.vo.GroupListWxVo">
+        SELECT any_value(t1.code)          AS code,
+               any_value(t1.name)          AS name,
+               COUNT(DISTINCT t2.open_num) AS num
+        FROM item_group t1
+                 LEFT JOIN device_base t2 ON t1.code = t2.group_id
+        WHERE t1.code IN (SELECT group_id FROM user_privilege WHERE user_id = #{userId})
+          AND t1.status = 1
+        GROUP BY t1.code
     </select>
 
 </mapper>

+ 4 - 11
src/main/resources/mapper/LpInfoStateMapper.xml

@@ -32,17 +32,10 @@
         WHERE t1.group_id IN (SELECT group_id FROM user_privilege WHERE user_id = #{userId})
     </select>
 
-    <select id="listByGroupIdWx" resultType="com.zy.bms.pojo.vo.LpDeviceListVo">
-        SELECT
-            t1.open_num,
-            t2.wake_int,
-            t2.update_time
-        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 = #{group}
+    <select id="listByGroupId" resultType="com.zy.bms.entity.lp.LpInfoState">
+        SELECT *
+        FROM lp_info_state
+        WHERE open_num IN (SELECT open_num FROM device_base WHERE type = 'lupai' AND group_id = #{groupId})
     </select>
 
     <update id="updateWakeAndThresh">

+ 26 - 37
src/main/resources/mapper/UbiInfoStateMapper.xml

@@ -4,50 +4,39 @@
 
     <select id="listPage" resultType="com.zy.bms.pojo.vo.UbiDeviceListVo">
         SELECT
-            t1.open_num,
-            t1.username,
-            t1.password,
-            t1.sn,
-            t1.create_time,
-            t1.group_id,
-            t2.*
+        t1.open_num,
+        t1.username,
+        t1.password,
+        t1.sn,
+        t1.create_time,
+        t1.group_id,
+        t2.*
         FROM
-            device_base t1
-        LEFT JOIN
-            ubi_info_state t2 ON t1.open_num = t2.open_num
+        device_base t1
+        LEFT JOIN ubi_info_state t2 ON t1.open_num = t2.open_num
         WHERE
-            t1.type = "gnss"
-            <if test="io.openNum != null and io.openNum != ''">
-                AND t1.open_num LIKE CONCAT('%',#{io.openNum},'%')
-            </if>
-            <if test="io.groupId != null and io.groupId > -1">
-                AND t1.group_id = #{io.groupId}
-            </if>
-            <if test="io.status != null and io.status > -1">
-                AND t2.status = #{io.status}
-            </if>
+        t1.type = 'gnss'
+        <if test="io.openNum != null and io.openNum != ''">
+            AND t1.open_num LIKE CONCAT('%',#{io.openNum},'%')
+        </if>
+        <if test="io.groupId != null and io.groupId > -1">
+            AND t1.group_id = #{io.groupId}
+        </if>
+        <if test="io.status != null and io.status > -1">
+            AND t2.status = #{io.status}
+        </if>
     </select>
 
     <select id="getDetail" resultType="com.zy.bms.pojo.vo.UbiDeviceDetailVo">
-        SELECT
-            *
-        FROM
-            ubi_info_state
-        WHERE
-            open_num = #{openNum}
+        SELECT *
+        FROM ubi_info_state
+        WHERE open_num = #{openNum}
     </select>
 
-    <select id="listByGroupIdWx" resultType="com.zy.bms.pojo.vo.UbiDeviceListVo">
-        SELECT
-            t1.open_num,
-            t2.freq,
-            t2.update_time
-        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 = #{group}
+    <select id="listByGroupId" resultType="com.zy.bms.entity.ubi.UbiInfoState">
+        SELECT *
+        FROM ubi_info_state
+        WHERE open_num IN (SELECT open_num FROM device_base WHERE type = 'gnss' AND group_id = #{groupId})
     </select>
 
 </mapper>