ChannelMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.bz.smart_city.dao.ChannelMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.Channel">
  6. <result column="id" property="id" jdbcType="INTEGER"/>
  7. <result column="parent_id" property="parentId" jdbcType="INTEGER"/>
  8. <result column="channel_name" property="channelName" jdbcType="VARCHAR"/>
  9. <result column="channel_code" property="channelCode" jdbcType="VARCHAR"/>
  10. <result column="status" property="status" jdbcType="INTEGER"/>
  11. <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
  12. <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
  13. <result column="update_date" property="updateDate" jdbcType="TIMESTAMP"/>
  14. <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
  15. <result column="channel_desc" property="channelDesc" jdbcType="VARCHAR"/>
  16. <result column="icon" property="icon" jdbcType="VARCHAR"/>
  17. <result column="sort" property="sort" jdbcType="INTEGER"/>
  18. </resultMap>
  19. <!--auto generated Code-->
  20. <sql id="Base_Column_List">
  21. id,
  22. parent_id,
  23. channel_name,
  24. channel_code,
  25. status,
  26. create_date,
  27. create_by,
  28. update_date,
  29. update_by,
  30. channel_desc,
  31. icon,
  32. sort
  33. </sql>
  34. <!--auto generated Code-->
  35. <insert id="insert" useGeneratedKeys="true" keyProperty="channel.id">
  36. INSERT INTO sc_channel (
  37. id,
  38. parent_id,
  39. channel_name,
  40. status,
  41. create_date,
  42. create_by,
  43. update_date,
  44. update_by,
  45. channel_desc,
  46. channel_code,
  47. icon,
  48. sort
  49. ) VALUES (
  50. #{channel.id,jdbcType=INTEGER},
  51. #{channel.parentId,jdbcType=INTEGER},
  52. #{channel.channelName,jdbcType=VARCHAR},
  53. #{channel.status,jdbcType=INTEGER},
  54. #{channel.createDate,jdbcType=TIMESTAMP},
  55. #{channel.createBy,jdbcType=VARCHAR},
  56. #{channel.updateDate,jdbcType=TIMESTAMP},
  57. #{channel.updateBy,jdbcType=VARCHAR},
  58. #{channel.channelDesc,jdbcType=VARCHAR},
  59. #{channel.channelCode,jdbcType=VARCHAR},
  60. #{channel.icon,jdbcType=VARCHAR},
  61. #{channel.sort,jdbcType=INTEGER}
  62. )
  63. </insert>
  64. <!--auto generated Code-->
  65. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="channel.id">
  66. INSERT INTO sc_channel
  67. <trim prefix="(" suffix=")" suffixOverrides=",">
  68. <if test="channel.id!=null"> id,</if>
  69. <if test="channel.parentId!=null"> parent_id,</if>
  70. <if test="channel.channelName!=null"> channel_name,</if>
  71. <if test="channel.status!=null"> status,</if>
  72. <if test="channel.createDate!=null"> create_date,</if>
  73. <if test="channel.createBy!=null"> create_by,</if>
  74. <if test="channel.updateDate!=null"> update_date,</if>
  75. <if test="channel.updateBy!=null"> update_by,</if>
  76. <if test="channel.channelDesc!=null"> channel_desc,</if>
  77. <if test="channel.channelCode!=null"> channel_code,</if>
  78. <if test="channel.icon!=null"> icon,</if>
  79. <if test="channel.sort!=null"> sort</if>
  80. </trim>
  81. VALUES
  82. <trim prefix="(" suffix=")" suffixOverrides=",">
  83. <if test="channel.id!=null"> #{channel.id,jdbcType=INTEGER},</if>
  84. <if test="channel.parentId!=null"> #{channel.parentId,jdbcType=INTEGER},</if>
  85. <if test="channel.channelName!=null"> #{channel.channelName,jdbcType=VARCHAR},</if>
  86. <if test="channel.status!=null"> #{channel.status,jdbcType=INTEGER},</if>
  87. <if test="channel.createDate!=null"> #{channel.createDate,jdbcType=TIMESTAMP},</if>
  88. <if test="channel.createBy!=null"> #{channel.createBy,jdbcType=VARCHAR},</if>
  89. <if test="channel.updateDate!=null"> #{channel.updateDate,jdbcType=TIMESTAMP},</if>
  90. <if test="channel.updateBy!=null"> #{channel.updateBy,jdbcType=VARCHAR},</if>
  91. <if test="channel.channelDesc!=null"> #{channel.channelDesc,jdbcType=VARCHAR},</if>
  92. <if test="channel.channelCode!=null"> #{channel.channelCode,jdbcType=VARCHAR},</if>
  93. <if test="channel.icon!=null"> #{channel.icon,jdbcType=VARCHAR},</if>
  94. <if test="channel.sort!=null"> #{channel.sort,jdbcType=INTEGER}</if>
  95. </trim>
  96. </insert>
  97. <!--auto generated Code-->
  98. <insert id="insertList">
  99. INSERT INTO sc_channel(
  100. id,
  101. parent_id,
  102. channel_name,
  103. status,
  104. create_date,
  105. create_by,
  106. update_date,
  107. update_by,
  108. channel_desc,
  109. channel_code,
  110. icon,
  111. sort
  112. )VALUES
  113. <foreach collection="channels" item="channel" index="index" separator=",">
  114. (
  115. #{channel.id,jdbcType=INTEGER},
  116. #{channel.parentId,jdbcType=INTEGER},
  117. #{channel.channelName,jdbcType=VARCHAR},
  118. #{channel.status,jdbcType=INTEGER},
  119. #{channel.createDate,jdbcType=TIMESTAMP},
  120. #{channel.createBy,jdbcType=VARCHAR},
  121. #{channel.updateDate,jdbcType=TIMESTAMP},
  122. #{channel.updateBy,jdbcType=VARCHAR},
  123. #{channel.channelDesc,jdbcType=VARCHAR},
  124. #{channel.channelCode,jdbcType=VARCHAR},
  125. #{channel.icon,jdbcType=VARCHAR},
  126. #{channel.sort,jdbcType=INTEGER}
  127. )
  128. </foreach>
  129. </insert>
  130. <!--auto generated Code-->
  131. <update id="updateByPrimaryKeySelective">
  132. UPDATE sc_channel
  133. <set>
  134. <if test="channel.id != null"> id = #{channel.id,jdbcType=INTEGER},</if>
  135. <if test="channel.parentId != null"> parent_id = #{channel.parentId,jdbcType=INTEGER},</if>
  136. <if test="channel.channelName != null"> channel_name = #{channel.channelName,jdbcType=VARCHAR},</if>
  137. <if test="channel.status != null"> status = #{channel.status,jdbcType=INTEGER},</if>
  138. <if test="channel.createDate != null"> create_date = #{channel.createDate,jdbcType=TIMESTAMP},</if>
  139. <if test="channel.createBy != null"> create_by = #{channel.createBy,jdbcType=VARCHAR},</if>
  140. <if test="channel.updateDate != null"> update_date = #{channel.updateDate,jdbcType=TIMESTAMP},</if>
  141. <if test="channel.updateBy != null"> update_by = #{channel.updateBy,jdbcType=VARCHAR},</if>
  142. <if test="channel.channelDesc != null"> channel_desc = #{channel.channelDesc,jdbcType=VARCHAR},</if>
  143. <if test="channel.channelCode != null"> channel_code = #{channel.channelCode,jdbcType=VARCHAR},</if>
  144. <if test="channel.icon != null"> icon = #{channel.icon,jdbcType=VARCHAR},</if>
  145. <if test="channel.sort != null"> sort = #{channel.sort,jdbcType=INTEGER}</if>
  146. </set>
  147. WHERE id = #{channel.id,jdbcType=INTEGER}
  148. </update>
  149. <select id="getList" resultType="com.bz.smart_city.dto.ChannelDeviceCountDto">
  150. SELECT
  151. sc.* ,
  152. IF(smt.id is null,0,1) is_water_channel
  153. FROM
  154. sc_channel sc left join sc_w_meter_type smt on (sc.id = smt.channel_id)
  155. WHERE
  156. sc.STATUS = 1
  157. AND sc.parent_id != 0
  158. ORDER BY
  159. sc.sort ASC
  160. </select>
  161. <select id="getListByIds" resultType="com.bz.smart_city.dto.ChannelDeviceCountDto">
  162. select
  163. distinct sc.*,
  164. IF(smt.id is null,0,1) is_water_channel
  165. from sc_channel sc left join sc_w_meter_type smt on (sc.id = smt.channel_id)
  166. where sc.status = 1 and sc.parent_id != 0
  167. <if test="channelList != null and channelList.size() != 0">
  168. and sc.id in <foreach collection="channelList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  169. </if>
  170. order by sc.sort asc
  171. </select>
  172. <select id="getChanelCountDeviceNum" resultType="com.bz.smart_city.dto.ChannelDeviceCountDto">
  173. select
  174. sc.id,
  175. sc.parent_id,
  176. sc.channel_name,
  177. (
  178. SELECT count(1) FROM sc_device sd
  179. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sd.id and sdd.status = 1)</if>
  180. WHERE sd.status=1 and sd.sys_id = sc.id
  181. <if test="siteId != null"> and sd.site_id = #{siteId} </if>
  182. <if test="buildingId != null"> and sd.building_id = #{buildingId} </if>
  183. <if test="deviceStatus != null">AND sd.device_status = #{deviceStatus} </if>
  184. <if test="deviceNo != null and deviceNo != ''"> AND sd.device_no LIKE concat('%',#{deviceNo},'%')</if>
  185. <if test="deviceTypeId != null"> AND sd.device_type = #{deviceTypeId} </if>
  186. <if test="locDesc != null and locDesc != ''"> AND sd.loc_desc LIKE concat('%',#{locDesc},'%')</if>
  187. <if test="programItems != null and programItems.size() != 0"> and
  188. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  189. sdd.${item.dimensionCode} = #{item.dimensionValue}
  190. </foreach>
  191. </if>
  192. ) as num
  193. from sc_channel sc where sc.status = 1 and sc.parent_id != 0
  194. <if test="channelList != null and channelList.size() != 0">
  195. and sc.id in <foreach collection="channelList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  196. </if>
  197. order by sc.sort asc
  198. </select>
  199. <select id="getChanelCountErrorNum" resultType="com.bz.smart_city.dto.ChannelDeviceCountDto">
  200. select
  201. sc.id,
  202. sc.parent_id,
  203. sc.channel_name,
  204. (
  205. SELECT count(1) FROM sc_device_error sde
  206. left join sc_device sd on sd.id = sde.device_id and sd.status = 1
  207. left join sc_building sb on(sb.id = sde.building_id and sb.status = 1)
  208. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sde.device_id and sdd.status = 1)</if>
  209. WHERE sde.status = 1 and sde.sys_id=sc.id
  210. <if test="siteId != null"> and sde.site_id=#{siteId} </if>
  211. <if test="buildingId != null"> and sde.building_id=#{buildingId} </if>
  212. <if test="deviceNo != null and deviceNo != ''"> AND sde.device_no LIKE concat('%',#{deviceNo},'%')</if>
  213. <if test="alarmCategory != null"> AND sde.alarm_category = #{alarmCategory} </if>
  214. <if test="handleStatus != null"> AND sde.handle_status = #{handleStatus} </if>
  215. <if test="deviceTypeId != null"> AND sd.device_type = #{deviceTypeId} </if>
  216. <if test="location != null and location != ''"> and sde.location LIKE concat('%',#{location},'%')</if>
  217. <if test="startDate != null"> and sde.alarm_time <![CDATA[ >= ]]> #{startDate}</if>
  218. <if test="endDate != null"> and sde.alarm_time <![CDATA[ <= ]]> #{endDate}</if>
  219. <if test="programItems != null and programItems.size() != 0"> and
  220. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  221. sdd.${item.dimensionCode} = #{item.dimensionValue}
  222. </foreach>
  223. </if>
  224. ) as num
  225. from sc_channel sc where sc.status = 1 and sc.parent_id != 0
  226. <if test="channelList != null and channelList.size() != 0">
  227. and sc.id in <foreach collection="channelList" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  228. </if>
  229. order by sc.sort asc
  230. </select>
  231. <select id="getSelect" resultType="com.bz.smart_city.dto.ChannelDto">
  232. select sc.*,if(isnull(ssc.id),0,1) AS isSelected from sc_channel sc
  233. left join sc_site_channel ssc on ssc.channel_id = sc.id AND ssc.site_id = #{siteId} AND ssc.status=1
  234. WHERE sc.status = 1 order by sc.sort asc
  235. </select>
  236. <select id="getChannelBySiteId" resultType="java.lang.Integer">
  237. select channel_id from sc_site_channel where status = 1 and site_id = #{siteId}
  238. </select>
  239. <select id="findList" resultMap="lazyLoadDeviceTypeId">
  240. select <include refid="Base_Column_List"/> from sc_channel
  241. where status = 1 and parent_id = 1
  242. <if test="name != null and name != ''"> AND channel_name LIKE concat('%',#{name},'%') </if>
  243. order by create_date desc
  244. </select>
  245. <resultMap id="lazyLoadDeviceTypeId" type="com.bz.smart_city.dto.ChannelDto" extends="BaseResultMap">
  246. <collection property="deviceTypeIds" ofType="java.lang.Integer" select="com.bz.smart_city.dao.ChannelDeviceTypeUseMapper.findDeviceTypeByChannelId"
  247. column="id"></collection>
  248. </resultMap>
  249. <select id="findByNameUnique" resultType="int">
  250. select count(1) from sc_channel
  251. where status = 1 and channel_name = #{channelName}
  252. <if test="id != null"> and id != #{id}</if>
  253. </select>
  254. <select id="findById" resultMap="BaseResultMap">
  255. select <include refid="Base_Column_List"/> from sc_channel
  256. where status = 1 and id = #{sysId}
  257. </select>
  258. <select id="getUserChannelList" resultMap="BaseResultMap">
  259. SELECT
  260. sc.*
  261. FROM
  262. sc_channel sc
  263. WHERE
  264. sc.id IN (
  265. SELECT
  266. sp.sys_id
  267. FROM
  268. sc_role_permission srp
  269. RIGHT JOIN sc_permission sp ON sp.id = srp.pid
  270. WHERE
  271. srp.rid IN (
  272. SELECT
  273. sur.rid
  274. FROM
  275. sc_user_role sur
  276. LEFT JOIN sc_user su ON su.id = sur.uid
  277. LEFT JOIN sc_role sr ON sr.id = sur.rid
  278. WHERE
  279. sur.uid = #{userId}
  280. AND su.STATUS = 1
  281. AND sur.STATUS = 1
  282. <if test="siteId != null"> and sr.site_id=#{siteId} </if>
  283. )
  284. AND is_menu = 1
  285. AND srp.STATUS = 1
  286. AND sp.STATUS = 1
  287. AND sp.sys_id IS NOT NULL
  288. GROUP BY
  289. sp.sys_id
  290. )
  291. </select>
  292. <select id="getChannelListBySiteId" resultMap="BaseResultMap">
  293. select sc.id,sc.parent_id,sc.channel_name from sc_site_channel ssc
  294. left join sc_channel sc on(sc.id = ssc.channel_id)
  295. where ssc.status = 1 and sc.status = 1 and ssc.site_id = #{siteId}
  296. </select>
  297. <select id="getChannelList" resultMap="BaseResultMap">
  298. select
  299. sc.*
  300. from sc_channel sc where sc.status = 1 and sc.parent_id != 0 order by sc.sort asc
  301. </select>
  302. <!--多个站点的场景ID-->
  303. <select id="getChannelIdsByMultiSite" resultType="java.lang.Integer">
  304. select sc.id,sc.parent_id,sc.channel_name from sc_site_channel ssc
  305. left join sc_channel sc on(sc.id = ssc.channel_id)
  306. where ssc.status = 1 and sc.status = 1
  307. <if test="siteIds != null and siteIds.size() != 0"> and ssc.site_id in <foreach collection="siteIds" item="item" open="(" separator="," close=")">#{item}</foreach></if>
  308. GROUP BY sc.id,sc.parent_id,sc.channel_name
  309. </select>
  310. <select id="getOptionChanelList" resultType="com.bz.smart_city.dto.ChannelDto">
  311. select sc.id,sc.parent_id,sc.channel_name,sc.channel_code,if((select count(1) from sc_permission where status = 1 and sys_id = sc.id)>0,1,0) AS isSelected from sc_channel sc
  312. where sc.status = 1 and sc.parent_id = 1
  313. </select>
  314. <select id="findChannelByCode" resultType="com.bz.smart_city.dto.ChannelDto">
  315. select
  316. <include refid="Base_Column_List" />
  317. from
  318. sc_channel
  319. where status = 1
  320. and channel_code = #{channelCode}
  321. </select>
  322. <select id="getWaterChanelList" resultType="com.bz.smart_city.dto.ChannelDeviceCountDto">
  323. select
  324. distinct sc.*,
  325. IF(smt.id is null,0,1) is_water_channel
  326. from sc_channel sc left join sc_w_meter_type smt on (sc.id = smt.channel_id)
  327. where sc.status = 1 and sc.parent_id != 0
  328. and smt.level= 2
  329. order by sc.sort asc
  330. </select>
  331. </mapper>