GroupMapper.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package com.genersoft.iot.vmp.gb28181.dao;
  2. import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
  3. import com.genersoft.iot.vmp.gb28181.bean.Group;
  4. import com.genersoft.iot.vmp.gb28181.bean.GroupTree;
  5. import com.genersoft.iot.vmp.gb28181.bean.Region;
  6. import org.apache.ibatis.annotations.*;
  7. import java.util.List;
  8. import java.util.Set;
  9. @Mapper
  10. public interface GroupMapper {
  11. @Insert("INSERT INTO wvp_common_group (device_id, name, parent_device_id, business_group, platform_id, create_time, update_time) " +
  12. "VALUES (#{deviceId}, #{name}, #{parentDeviceId}, #{businessGroup}, #{platformId}, #{createTime}, #{updateTime})")
  13. @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
  14. int add(Group group);
  15. @Insert("INSERT INTO wvp_common_group (device_id, name, business_group, platform_id, create_time, update_time) " +
  16. "VALUES (#{deviceId}, #{name}, #{businessGroup}, #{platformId}, #{createTime}, #{updateTime})")
  17. @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
  18. int addBusinessGroup(Group group);
  19. @Delete("DELETE FROM wvp_common_group WHERE id=#{id}")
  20. int delete(@Param("id") int id);
  21. @Update(" UPDATE wvp_common_group " +
  22. " SET update_time=#{updateTime}, device_id=#{deviceId}, name=#{name}, parent_device_id=#{parentDeviceId}, business_group=#{businessGroup}" +
  23. " WHERE id = #{id}")
  24. int update(Group group);
  25. @Select(value = {" <script>" +
  26. "SELECT * from wvp_common_group WHERE 1=1 " +
  27. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  28. " <if test='parentId != null and businessGroupId != null '> AND parent_device_id = #{parentId} AND business_group=#{businessGroup} </if> " +
  29. "ORDER BY id " +
  30. " </script>"})
  31. List<Group> query(@Param("query") String query, @Param("parentId") String parentId, @Param("businessGroup") String businessGroup);
  32. @Select(value = {" <script>" +
  33. "SELECT * from wvp_common_group WHERE parent_device_id = #{parentId} "+
  34. " <if test='platformId != null'> AND platform_id = #{platformId}</if> " +
  35. " <if test='platformId == null'> AND platform_id is null</if> " +
  36. " </script>"})
  37. List<Group> getChildren(@Param("parentId") String parentId , @Param("platformId") Integer platformId);
  38. @Select("SELECT * from wvp_common_group WHERE id = #{id} ")
  39. Group queryOne(@Param("id") int id);
  40. @Select(" select coalesce(dc.gb_civil_code, dc.civil_code) as civil_code " +
  41. " from wvp_device_channel dc " +
  42. " where coalesce(dc.gb_civil_code, dc.civil_code) not in " +
  43. " (select device_id from wvp_common_group)")
  44. List<String> getUninitializedCivilCode();
  45. @Select(" <script>" +
  46. " SELECT device_id from wvp_common_group " +
  47. " where device_id in " +
  48. " <foreach collection='codes' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
  49. " </script>")
  50. List<String> queryInList(Set<String> codes);
  51. @Insert(" <script>" +
  52. " INSERT INTO wvp_common_group (" +
  53. " device_id," +
  54. " name, " +
  55. " parent_device_id," +
  56. " business_group," +
  57. " create_time," +
  58. " update_time) " +
  59. " VALUES " +
  60. " <foreach collection='groupList' index='index' item='item' separator=','> " +
  61. " (#{item.deviceId}, #{item.name}, #{item.parentDeviceId}, #{item.businessGroup},#{item.createTime},#{item.updateTime})" +
  62. " </foreach> " +
  63. " </script>")
  64. int batchAdd(List<Group> groupList);
  65. @Select(" <script>" +
  66. " SELECT " +
  67. " device_id as id," +
  68. " name as label, " +
  69. " parent_device_id," +
  70. " business_group," +
  71. " id as db_id," +
  72. " 0 as type," +
  73. " false as is_leaf" +
  74. " from wvp_common_group " +
  75. " where 1=1 " +
  76. " <if test='parentId != null'> and parent_device_id = #{parentId} </if> " +
  77. " <if test='parentId == null'> and parent_device_id is null </if> " +
  78. " <if test='platformId != null'> and platform_id = #{platformId} </if> " +
  79. " <if test='platformId == null'> and platform_id is null </if> " +
  80. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  81. " </script>")
  82. List<GroupTree> queryForTree(@Param("query") String query, @Param("parentId") String parentId,
  83. @Param("platformId") Integer platformId);
  84. @Select(" <script>" +
  85. " SELECT " +
  86. " device_id as id," +
  87. " name as label, " +
  88. " parent_device_id," +
  89. " business_group," +
  90. " id as db_id," +
  91. " 0 as type," +
  92. " false as is_leaf" +
  93. " from wvp_common_group " +
  94. " where parent_device_id is null and business_group = #{businessGroup} and device_id != #{businessGroup}" +
  95. " <if test='platformId != null'> and platform_id = #{platformId} </if> " +
  96. " <if test='platformId == null'> and platform_id is null </if> " +
  97. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  98. " </script>")
  99. List<GroupTree> queryForTreeByBusinessGroup(@Param("query") String query,
  100. @Param("businessGroup") String businessGroup,
  101. @Param("platformId") Integer platformId);
  102. @Select(" <script>" +
  103. " SELECT " +
  104. " device_id as id," +
  105. " name as label, " +
  106. " parent_device_id," +
  107. " id as db_id," +
  108. " 0 as type," +
  109. " false as is_leaf" +
  110. " from wvp_common_group " +
  111. " where device_id=business_group" +
  112. " <if test='platformId != null'> AND platform_id = #{platformId} </if> " +
  113. " <if test='platformId == null'> AND platform_id is null </if> " +
  114. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  115. " </script>")
  116. List<GroupTree> queryBusinessGroupForTree(String query, Integer platformId);
  117. @Select("SELECT * from wvp_common_group WHERE device_id = #{deviceId} and business_group = #{businessGroup}")
  118. Group queryOneByDeviceId(@Param("deviceId") String deviceId, @Param("businessGroup") String businessGroup);
  119. @Delete("<script>" +
  120. " DELETE FROM wvp_common_group WHERE id in " +
  121. " <foreach collection='allChildren' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  122. " </script>")
  123. int batchDelete(List<Group> allChildren);
  124. @Select("SELECT * from wvp_common_group WHERE device_id = #{businessGroup} and business_group = #{businessGroup} ")
  125. Group queryBusinessGroup(@Param("businessGroup") String businessGroup);
  126. @Select("SELECT * from wvp_common_group WHERE business_group = #{businessGroup} ")
  127. List<Group> queryByBusinessGroup(@Param("businessGroup") String businessGroup);
  128. @Delete("DELETE FROM wvp_common_group WHERE business_group = #{businessGroup}")
  129. int deleteByBusinessGroup(@Param("businessGroup") String businessGroup);
  130. @Update(" UPDATE wvp_common_group " +
  131. " SET parent_device_id=#{group.deviceId}, business_group = #{group.businessGroup}" +
  132. " WHERE parent_device_id = #{oldDeviceId}")
  133. int updateChild(@Param("oldDeviceId") String oldDeviceId, Group group);
  134. @Select(" <script>" +
  135. " SELECT * from wvp_common_group " +
  136. " where device_id in " +
  137. " <foreach collection='groupList' item='item' open='(' separator=',' close=')' > #{item.deviceId}</foreach>" +
  138. " </script>")
  139. List<Region> queryInGroupList(List<Group> groupList);
  140. @Select(" <script>" +
  141. " SELECT " +
  142. " device_id as gb_device_id," +
  143. " name as gb_name," +
  144. " business_group as gb_business_group," +
  145. " 1 as gb_parental," +
  146. " parent_device_id as gb_parent_id" +
  147. " from wvp_common_group " +
  148. " where (device_id, business_group) in " +
  149. " <foreach collection='channelList' item='item' open='(' separator=',' close=')' > (#{item.gbParentId}, #{item.gbBusinessGroupId})</foreach>" +
  150. " </script>")
  151. List<CommonGBChannel> queryInChannelList(List<CommonGBChannel> channelList);
  152. }