GroupMapper.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.welampiot.dao.GroupDao">
  4. <select id="getListBySection" parameterType="java.util.List" resultType="com.welampiot.dto.GroupDTO">
  5. select id,name from `group`
  6. <if test="sectionList != null and !sectionList.isEmpty()">
  7. where sectionid in
  8. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  9. #{vo}
  10. </foreach>
  11. </if>
  12. </select>
  13. <select id="getListByVO" parameterType="com.welampiot.vo.GroupVO" resultType="com.welampiot.dto.GroupDTO">
  14. select g.id,g.name,g.number,g.sectionid as sectionId,g.areaid as areaId,g.type,g.value,g.lampid as lampId,
  15. (select count(id) from lampinfo where find_in_set(id,g.lampid)) as lampCount,g.onLight,g.offLight,g.day_or_night,g.patrolinterval as patrolInterval,g.devType,s.name as section,p.name as policy,
  16. <choose>
  17. <when test="version == 1">
  18. gl.english_name as area
  19. </when>
  20. <when test="version == 2">
  21. gl.ru_name as area
  22. </when>
  23. <otherwise>
  24. gl.chinese_name as area
  25. </otherwise>
  26. </choose>
  27. from `group` as g
  28. left join section s on g.sectionid = s.id
  29. left join global_location gl on gl.id = s.pid
  30. left join policy p on g.value = p.id
  31. where 1=1
  32. <if test="sectionList != null and !sectionList.isEmpty()">
  33. and g.sectionid in
  34. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  35. #{vo}
  36. </foreach>
  37. </if>
  38. <if test="devType != null">
  39. and g.devType = #{devType}
  40. </if>
  41. <if test="keyword != null">
  42. and g.name like '%#{keyword}%'
  43. </if>
  44. order by g.name asc
  45. <if test="offset != null and limit != null">
  46. limit #{offset},#{limit}
  47. </if>
  48. </select>
  49. <select id="getCountByVO" parameterType="com.welampiot.dto.GroupDTO" resultType="Integer">
  50. select count(*)
  51. from `group` as g
  52. where 1=1
  53. <if test="sectionList != null and !sectionList.isEmpty()">
  54. and g.sectionid in
  55. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  56. #{vo}
  57. </foreach>
  58. </if>
  59. <if test="devType != null">
  60. and g.devType = #{devType}
  61. </if>
  62. <if test="keyword != null">
  63. and g.name like '%#{keyword}%'
  64. </if>
  65. </select>
  66. <select id="getDetailByVO" parameterType="com.welampiot.vo.GroupVO" resultType="com.welampiot.dto.GroupDTO">
  67. select
  68. g.name,g.number,g.id,g.areaid as areaId,g.sectionid as sectionId,(select count(id) from lampinfo where find_in_set(id,g.lampid)) as lampCount,g.type,g.value,s.name as section,g.lampid as lampId,
  69. <choose>
  70. <when test="version == 1">
  71. gl.english_name as area
  72. </when>
  73. <when test="version == 2">
  74. gl.ru_name as area
  75. </when>
  76. <otherwise>
  77. gl.chinese_name as area
  78. </otherwise>
  79. </choose>
  80. from `group` as g
  81. left join section s on g.sectionid = s.id
  82. left join global_location gl on gl.id = s.pid
  83. where g.id=#{id}
  84. <if test="sectionList != null and !sectionList.isEmpty()">
  85. and g.sectionid in
  86. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  87. #{vo}
  88. </foreach>
  89. </if>
  90. limit 1
  91. </select>
  92. <insert id="add" parameterType="com.welampiot.dto.GroupDTO" useGeneratedKeys="true" keyProperty="id"
  93. >
  94. insert into `group` (name,number,lampid,areaid,sectionid,lampcount,createtime,devType,updatetime
  95. )
  96. values
  97. (#{name},#{number},#{lampId},#{areaId},#{sectionId},#{lampCount},#{createTime},#{devType},#{updateTime}
  98. )
  99. </insert>
  100. <select id="checkData" resultType="Integer" parameterType="com.welampiot.dto.GroupDTO">
  101. select count(id) from `group`
  102. where 1=1
  103. <if test="sectionId != null">
  104. and sectionid = #{sectionId}
  105. </if>
  106. <if test="name != null">
  107. and name = #{name}
  108. </if>
  109. <if test="number != null">
  110. and number = #{number}
  111. </if>
  112. <if test="id != null">
  113. and id != #{id}
  114. </if>
  115. </select>
  116. <update id="update" parameterType="com.welampiot.dto.GroupDTO" useGeneratedKeys="true" keyProperty="id"
  117. >
  118. update `group` set
  119. name = #{name},
  120. number = #{number},
  121. lampid = #{lampId},
  122. areaid = #{areaId},
  123. sectionid = #{sectionId},
  124. lampcount = #{lampCount},
  125. devType = #{devType},
  126. updatetime = #{updateTime}
  127. where id = #{id}
  128. </update>
  129. <delete id="deleteById">
  130. delete from `group` where id=#{id};
  131. </delete>
  132. <select id="getGroupListByDTO" resultType="GroupDTO">
  133. select g.name,g.id,g.value,g.type,g.offLight,g.onLight,g.updatetime as updateTime,g.lampcount as lampCount,g.color_temp as colarTemp,s.timezone
  134. from `group` g
  135. left join section s on g.sectionid = s.id
  136. where 1=1
  137. <if test="keyword != null and keyword != ''">
  138. and g.name like '%${keyword}%'
  139. </if>
  140. <if test="sectionList != null and !sectionList.isEmpty()">
  141. and g.sectionid in
  142. <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
  143. #{dto}
  144. </foreach>
  145. </if>
  146. <choose>
  147. <when test="devType == 0">
  148. and g.devType = 0
  149. </when>
  150. <when test="devType == 1">
  151. and g.devType = 1
  152. </when>
  153. </choose>
  154. </select>
  155. <select id="findPolicyNameByValue" resultType="String">
  156. select p.name
  157. from policy p
  158. where p.id = #{id}
  159. </select>
  160. <select id="getGroupTotalByDTO" resultType="Integer">
  161. select count(g.id)
  162. from `group` g
  163. where 1=1
  164. <if test="sectionList != null and !sectionList.isEmpty()">
  165. and g.sectionid in
  166. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  167. #{item}
  168. </foreach>
  169. </if>
  170. <if test="areaId != null and areaId != 0">
  171. and g.areaid = #{areaId}
  172. </if>
  173. </select>
  174. <select id="getGroupDTOById" resultType="GroupDTO">
  175. select
  176. g.id,
  177. g.lampid as lampId,
  178. g.devType,
  179. g.patrolinterval as patrolInterval,
  180. g.type,
  181. g.value
  182. from `group` g
  183. where g.id = #{id}
  184. </select>
  185. <update id="updateGroupLampId" parameterType="GroupDTO">
  186. update
  187. `group` g
  188. set
  189. g.lampid = #{lampId}
  190. where
  191. g.id = #{id}
  192. </update>
  193. <select id="getListByIds" resultType="GroupDTO">
  194. select id,lampid,number from `group`
  195. <trim prefix="where" suffixOverrides="and|or">
  196. <if test="ids !=null">
  197. id in
  198. <foreach collection="ids" open="(" close=")" item="id" separator=",">
  199. #{id}
  200. </foreach>
  201. </if>
  202. </trim>
  203. </select>
  204. </mapper>