RegionMapper.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.Region;
  5. import com.genersoft.iot.vmp.gb28181.bean.RegionTree;
  6. import org.apache.ibatis.annotations.*;
  7. import java.util.List;
  8. import java.util.Set;
  9. @Mapper
  10. public interface RegionMapper {
  11. @Insert("INSERT INTO wvp_common_region (device_id, name, parent_id, parent_device_id, create_time, update_time) " +
  12. "VALUES (#{deviceId}, #{name}, #{parentId}, #{parentDeviceId}, #{createTime}, #{updateTime})")
  13. @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
  14. void add(Region region);
  15. @Delete("DELETE FROM wvp_common_region WHERE id=#{id}")
  16. int delete(@Param("id") int id);
  17. @Update(" UPDATE wvp_common_region " +
  18. " SET update_time=#{updateTime}, device_id=#{deviceId}, name=#{name}, parent_id=#{parentId}, parent_device_id=#{parentDeviceId}" +
  19. " WHERE id = #{id}")
  20. int update(Region region);
  21. @Select(value = {" <script>" +
  22. "SELECT * from wvp_common_region WHERE 1=1 " +
  23. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  24. " <if test='parentId != null'> AND parent_device_id = #{parentId}</if> " +
  25. "ORDER BY id " +
  26. " </script>"})
  27. List<Region> query(@Param("query") String query, @Param("parentId") String parentId);
  28. @Select("SELECT * from wvp_common_region WHERE parent_id = #{parentId} ORDER BY id ")
  29. List<Region> getChildren(@Param("parentId") Integer parentId);
  30. @Select("SELECT * from wvp_common_region WHERE id = #{id} ")
  31. Region queryOne(@Param("id") int id);
  32. @Select(" select dc.civil_code as civil_code " +
  33. " from wvp_device_channel dc " +
  34. " where dc.civil_code not in " +
  35. " (select device_id from wvp_common_region)")
  36. List<String> getUninitializedCivilCode();
  37. @Select(" <script>" +
  38. " SELECT device_id from wvp_common_region " +
  39. " where device_id in " +
  40. " <foreach collection='codes' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
  41. " </script>")
  42. List<String> queryInList(Set<String> codes);
  43. @Insert(" <script>" +
  44. " INSERT INTO wvp_common_region (" +
  45. " device_id," +
  46. " name, " +
  47. " parent_device_id," +
  48. " parent_id," +
  49. " create_time," +
  50. " update_time) " +
  51. " VALUES " +
  52. " <foreach collection='regionList' index='index' item='item' separator=','> " +
  53. " (#{item.deviceId}, #{item.name}, #{item.parentDeviceId},#{item.parentId},#{item.createTime},#{item.updateTime})" +
  54. " </foreach> " +
  55. " </script>")
  56. @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
  57. int batchAdd(List<Region> regionList);
  58. @Select(" <script>" +
  59. " SELECT " +
  60. " *, " +
  61. " concat('region', id) as tree_id," +
  62. " 0 as type," +
  63. " false as is_leaf" +
  64. " from wvp_common_region " +
  65. " where " +
  66. " <if test='parentId != null'> parent_id = #{parentId} </if> " +
  67. " <if test='parentId == null'> parent_id is null </if> " +
  68. " <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
  69. " </script>")
  70. List<RegionTree> queryForTree(@Param("query") String query, @Param("parentId") Integer parentId);
  71. @Delete("<script>" +
  72. " DELETE FROM wvp_common_region WHERE id in " +
  73. " <foreach collection='allChildren' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  74. " </script>")
  75. void batchDelete(List<Region> allChildren);
  76. @Select(" <script>" +
  77. " SELECT * from wvp_common_region " +
  78. " where device_id in " +
  79. " <foreach collection='regionList' item='item' open='(' separator=',' close=')' > #{item.deviceId}</foreach>" +
  80. " </script>")
  81. List<Region> queryInRegionListByDeviceId(List<Region> regionList);
  82. @Select(" <script>" +
  83. " SELECT " +
  84. " wcr.device_id as gb_device_id," +
  85. " wcr.name as gb_name" +
  86. " from wvp_common_region wcr" +
  87. " left join wvp_platform_region wpr on wcr.id = wpr.region_id" +
  88. " where wpr.platform_id = #{platformId} " +
  89. " </script>")
  90. List<CommonGBChannel> queryByPlatform(@Param("platformId") Integer platformId);
  91. @Update(value = " <script>" +
  92. " update wvp_common_region w1 " +
  93. " inner join (select * from wvp_common_region ) w2 on w1.parent_device_id = w2.device_id " +
  94. " set w1.parent_id = w2.id" +
  95. " where w1.id in " +
  96. " <foreach collection='regionListForAdd' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  97. " </script>", databaseId = "mysql")
  98. @Update( value = " <script>" +
  99. " update wvp_common_region w1\n" +
  100. " set parent_id = w2.id\n" +
  101. " from wvp_common_region w2\n" +
  102. " where w1.parent_device_id = w2.device_id\n" +
  103. " and w1.id in " +
  104. " <foreach collection='regionListForAdd' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  105. " </script>", databaseId = "kingbase")
  106. @Update( value = " <script>" +
  107. " update wvp_common_region w1\n" +
  108. " set parent_id = w2.id\n" +
  109. " from wvp_common_region w2\n" +
  110. " where w1.parent_device_id = w2.device_id\n" +
  111. " and w1.id in " +
  112. " <foreach collection='regionListForAdd' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  113. " </script>", databaseId = "postgresql")
  114. void updateParentId(List<Region> regionListForAdd);
  115. @Update(" <script>" +
  116. " update wvp_common_region" +
  117. " set parent_device_id = #{parentDeviceId}" +
  118. " where parent_id = #{parentId} " +
  119. " </script>")
  120. void updateChild(@Param("parentId") int parentId, @Param("parentDeviceId") String parentDeviceId);
  121. @Select("SELECT * from wvp_common_region WHERE device_id = #{deviceId} ")
  122. Region queryByDeviceId(@Param("deviceId") String deviceId);
  123. @Select(" <script>" +
  124. " SELECT " +
  125. " * " +
  126. " from wvp_common_region " +
  127. " where id in " +
  128. " <foreach collection='regionSet' item='item' open='(' separator=',' close=')' > #{item.parentId}</foreach>" +
  129. " </script>")
  130. Set<Region> queryParentInChannelList(Set<Region> regionSet);
  131. @Select(" <script>" +
  132. " SELECT " +
  133. " * " +
  134. " from wvp_common_region " +
  135. " where device_id in " +
  136. " <foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.gbCivilCode}</foreach>" +
  137. " order by id " +
  138. "</script>")
  139. Set<Region> queryByChannelList(List<CommonGBChannel> channelList);
  140. @Select(" <script>" +
  141. " SELECT * " +
  142. " from wvp_common_region wcr" +
  143. " left join wvp_platform_region wpr on wpr.region_id = wcr.id and wpr.platform_id = #{platformId}" +
  144. " where wpr.platform_id is null and wcr.device_id in " +
  145. " <foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.gbCivilCode}</foreach>" +
  146. " </script>")
  147. Set<Region> queryNotShareRegionForPlatformByChannelList(List<CommonGBChannel> channelList, @Param("platformId") Integer platformId);
  148. @Select(" <script>" +
  149. " SELECT * " +
  150. " from wvp_common_region wcr" +
  151. " left join wvp_platform_region wpr on wpr.region_id = wcr.id and wpr.platform_id = #{platformId}" +
  152. " where wpr.platform_id IS NULL and wcr.id in " +
  153. " <foreach collection='allRegion' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
  154. " </script>")
  155. Set<Region> queryNotShareRegionForPlatformByRegionList(Set<Region> allRegion, @Param("platformId") Integer platformId);
  156. }