GroupMapper.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 org.apache.ibatis.annotations.*;
  6. import java.util.List;
  7. import java.util.Set;
  8. @Mapper
  9. public interface GroupMapper {
  10. @Insert("INSERT INTO wvp_common_group (device_id, name, parent_id, parent_device_id, business_group, create_time, update_time) " +
  11. "VALUES (#{deviceId}, #{name}, #{parentId}, #{parentDeviceId}, #{businessGroup}, #{createTime}, #{updateTime})")
  12. @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
  13. int add(Group group);
  14. @Insert("INSERT INTO wvp_common_group (device_id, name, business_group, create_time, update_time) " +
  15. "VALUES (#{deviceId}, #{name}, #{businessGroup}, #{createTime}, #{updateTime})")
  16. @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
  17. int addBusinessGroup(Group group);
  18. @Delete("DELETE FROM wvp_common_group WHERE id=#{id}")
  19. int delete(@Param("id") int id);
  20. @Update(" UPDATE wvp_common_group " +
  21. " SET update_time=#{updateTime}, device_id=#{deviceId}, name=#{name}, parent_id=#{parentId}, parent_device_id=#{parentDeviceId}, business_group=#{businessGroup}" +
  22. " WHERE id = #{id}")
  23. int update(Group group);
  24. @Select(value = {" <script>" +
  25. "SELECT * from wvp_common_group WHERE 1=1 " +
  26. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  27. " <if test='parentId != null and businessGroupId != null '> AND parent_device_id = #{parentId} AND business_group=#{businessGroup} </if> " +
  28. "ORDER BY id " +
  29. " </script>"})
  30. List<Group> query(@Param("query") String query, @Param("parentId") String parentId, @Param("businessGroup") String businessGroup);
  31. @Select("SELECT * from wvp_common_group WHERE parent_id = #{parentId} ")
  32. List<Group> getChildren(@Param("parentId") int parentId);
  33. @Select("SELECT * from wvp_common_group WHERE id = #{id} ")
  34. Group queryOne(@Param("id") int id);
  35. @Insert(" <script>" +
  36. " INSERT INTO wvp_common_group (" +
  37. " device_id," +
  38. " name, " +
  39. " parent_device_id," +
  40. " parent_id," +
  41. " business_group," +
  42. " create_time," +
  43. " update_time) " +
  44. " VALUES " +
  45. " <foreach collection='groupList' index='index' item='item' separator=','> " +
  46. " (#{item.deviceId}, #{item.name}, #{item.parentDeviceId}, #{item.parentId}, #{item.businessGroup},#{item.createTime},#{item.updateTime})" +
  47. " </foreach> " +
  48. " </script>")
  49. @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
  50. int batchAdd(List<Group> groupList);
  51. @Select(" <script>" +
  52. " SELECT " +
  53. " * , " +
  54. " 0 as type," +
  55. " false as is_leaf" +
  56. " from wvp_common_group " +
  57. " where 1=1 " +
  58. " <if test='parentId != null'> and parent_id = #{parentId} </if> " +
  59. " <if test='parentId == null'> and parent_id is null </if> " +
  60. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  61. " </script>")
  62. List<GroupTree> queryForTree(@Param("query") String query, @Param("parentId") Integer parentId);
  63. @Select(" <script>" +
  64. " SELECT " +
  65. " * , " +
  66. " 0 as type," +
  67. " false as is_leaf" +
  68. " from wvp_common_group " +
  69. " where parent_id is not null and business_group = #{businessGroup} and device_id != #{businessGroup}" +
  70. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  71. " </script>")
  72. List<GroupTree> queryForTreeByBusinessGroup(@Param("query") String query,
  73. @Param("businessGroup") String businessGroup);
  74. @Select(" <script>" +
  75. " SELECT " +
  76. " *," +
  77. " 0 as type," +
  78. " false as is_leaf" +
  79. " from wvp_common_group " +
  80. " where device_id=business_group" +
  81. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  82. " </script>")
  83. List<GroupTree> queryBusinessGroupForTree(@Param("query") String query);
  84. @Select("SELECT * from wvp_common_group WHERE device_id = #{deviceId} and business_group = #{businessGroup}")
  85. Group queryOneByDeviceId(@Param("deviceId") String deviceId, @Param("businessGroup") String businessGroup);
  86. @Delete("<script>" +
  87. " DELETE FROM wvp_common_group WHERE id in " +
  88. " <foreach collection='allChildren' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  89. " </script>")
  90. int batchDelete(List<Group> allChildren);
  91. @Select("SELECT * from wvp_common_group WHERE device_id = #{businessGroup} and business_group = #{businessGroup} ")
  92. Group queryBusinessGroup(@Param("businessGroup") String businessGroup);
  93. @Select("SELECT * from wvp_common_group WHERE business_group = #{businessGroup} ")
  94. List<Group> queryByBusinessGroup(@Param("businessGroup") String businessGroup);
  95. @Delete("DELETE FROM wvp_common_group WHERE business_group = #{businessGroup}")
  96. int deleteByBusinessGroup(@Param("businessGroup") String businessGroup);
  97. @Update(" UPDATE wvp_common_group " +
  98. " SET parent_device_id=#{group.deviceId}, business_group = #{group.businessGroup}" +
  99. " WHERE parent_id = #{parentId}")
  100. int updateChild(@Param("parentId") Integer parentId, Group group);
  101. @Select(" <script>" +
  102. " SELECT * from wvp_common_group " +
  103. " where device_id in " +
  104. " <foreach collection='groupList' item='item' open='(' separator=',' close=')' > #{item.deviceId}</foreach>" +
  105. " </script>")
  106. List<Group> queryInGroupListByDeviceId(List<Group> groupList);
  107. @Select(" <script>" +
  108. " SELECT " +
  109. " * " +
  110. " from wvp_common_group " +
  111. " where (device_id, business_group) in " +
  112. " <foreach collection='channelList' item='item' open='(' separator=',' close=')' > (#{item.gbParentId}, #{item.gbBusinessGroupId})</foreach>" +
  113. " </script>")
  114. Set<Group> queryInChannelList(List<CommonGBChannel> channelList);
  115. @Select(" <script>" +
  116. " SELECT " +
  117. " * " +
  118. " from wvp_common_group " +
  119. " where id in " +
  120. " <foreach collection='groupSet' item='item' open='(' separator=',' close=')' > #{item.parentId}</foreach>" +
  121. " </script>")
  122. Set<Group> queryParentInChannelList(Set<Group> groupSet);
  123. @Select(" <script>" +
  124. " SELECT " +
  125. " wcg.device_id as gb_device_id," +
  126. " wcg.name as gb_name," +
  127. " wcg.business_group as gb_business_group," +
  128. " 1 as gb_parental," +
  129. " wcg.parent_device_id as gb_parent_id" +
  130. " from wvp_common_group wcg" +
  131. " left join wvp_platform_group wpg on wpg.group_id = wcg.id" +
  132. " where wpg.platform_id = #{platformId} " +
  133. " </script>")
  134. List<CommonGBChannel> queryForPlatform(@Param("platformId") Integer platformId);
  135. @Select(" <script>" +
  136. " SELECT * " +
  137. " from wvp_common_group wcg" +
  138. " left join wvp_platform_group wpg on wpg.group_id = wcg.id and wpg.platform_id = #{platformId}" +
  139. " where wpg.platform_id is null and wcg.device_id in " +
  140. " <foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.gbParentId}</foreach>" +
  141. " </script>")
  142. Set<Group> queryNotShareForPlatformByChannelList(List<CommonGBChannel> channelList, @Param("platformId") Integer platformId);
  143. @Select(" <script>" +
  144. " SELECT * " +
  145. " from wvp_common_group wcg" +
  146. " left join wvp_platform_group wpg on wpg.group_id = wcg.id and wpg.platform_id = #{platformId}" +
  147. " where wpg.platform_id IS NULL and wcg.id in " +
  148. " <foreach collection='allGroup' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  149. " </script>")
  150. Set<Group> queryNotShareForPlatformByGroupList(Set<Group> allGroup, @Param("platformId") Integer platformId);
  151. @Select(" <script>" +
  152. " SELECT " +
  153. " * " +
  154. " from wvp_common_group " +
  155. " where device_id in " +
  156. " <foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.gbParentId}</foreach>" +
  157. " </script>")
  158. Set<Group> queryByChannelList(List<CommonGBChannel> channelList);
  159. @Update(" <script>" +
  160. " update wvp_common_group w1 " +
  161. " inner join (select * from wvp_common_group ) w2 on w1.parent_device_id = w2.device_id " +
  162. " set w1.parent_id = w2.id" +
  163. " where w1.id in " +
  164. " <foreach collection='groupListForAdd' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  165. " </script>")
  166. void updateParentId(List<Group> groupListForAdd);
  167. @Update(" <script>" +
  168. " update wvp_common_group w1 " +
  169. " inner join (select * from wvp_common_group ) w2" +
  170. " on w1.parent_device_id is null" +
  171. " and w2.parent_device_id is null" +
  172. " and w2.device_id = w2.business_group " +
  173. " and w1.business_group = w2.device_id " +
  174. " and w1.device_id != w1.business_group " +
  175. " set w1.parent_id = w2.id" +
  176. " where w1.id in " +
  177. " <foreach collection='groupListForAdd' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  178. " </script>")
  179. void updateParentIdWithBusinessGroup(List<Group> groupListForAdd);
  180. }