ElectricBoxMapper.xml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.ElectricBoxDao">
  4. <select id="getElectricBoxListBySectionId" resultType="com.welampiot.dto.ElectricBoxDTO" parameterType="ElectricBoxDTO">
  5. select e.id,e.areaid as areaId,e.sectionid as sectionId,e.name,e.address,(select count(*) from air_switch_info c where c.box_id = e.id) as airCount,
  6. e.longitude,e.latitude,e.image,e.install_date installDate,e.expiration_date expirationDate,
  7. (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) as onlineCount,e.devType
  8. from electric_box e
  9. where 1=1 <if test="keyword != null and keyword != ''">
  10. and (e.name like '%${keyword}%' or e.address like '%${keyword}%')
  11. </if>
  12. <choose>
  13. <when test="status == 1">
  14. and (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) > 0
  15. </when>
  16. <when test="status == 2">
  17. and (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) = 0
  18. </when>
  19. </choose>
  20. <if test="sectionList != null and !sectionList.isEmpty()">
  21. and e.sectionid in
  22. <foreach item="dto" collection="sectionList" open="(" separator="," close=")">
  23. #{dto}
  24. </foreach>
  25. </if>
  26. order by convert(e.name using gbk) asc,e.id desc
  27. <if test="page >= 0 and count > 0">
  28. limit #{page},#{count}
  29. </if>
  30. </select>
  31. <select id="getTotalByStatus" resultType="Integer" parameterType="ElectricBoxDTO">
  32. select count(*) as total
  33. from (select e.id
  34. from electric_box e
  35. left join air_switch_info a on e.id = a.box_id
  36. <if test="sectionList != null and !sectionList.isEmpty()">
  37. where e.sectionid in
  38. <foreach item="dto" collection="sectionList" open="(" separator="," close=")">
  39. #{dto}
  40. </foreach>
  41. </if>
  42. group by e.id) b
  43. </select>
  44. <select id="getOnlineTotalByStatus" resultType="Integer" parameterType="ElectricBoxDTO">
  45. select count(*) as total
  46. from (select e.id
  47. from electric_box e
  48. left join air_switch_info a on e.id = a.box_id
  49. where(select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) > 0
  50. <if test="sectionList != null and !sectionList.isEmpty()">
  51. and e.sectionid in
  52. <foreach item="dto" collection="sectionList" open="(" separator="," close=")">
  53. #{dto}
  54. </foreach>
  55. </if>
  56. group by e.id) b
  57. </select>
  58. <select id="getOfflineTotalByStatus" resultType="Integer" parameterType="ElectricBoxDTO">
  59. select count(*) as total
  60. from (select e.id
  61. from electric_box e
  62. left join air_switch_info a on e.id = a.box_id
  63. where (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) = 0
  64. <if test="sectionList != null and !sectionList.isEmpty()">
  65. and e.sectionid in
  66. <foreach item="dto" collection="sectionList" open="(" separator="," close=")">
  67. #{dto}
  68. </foreach>
  69. </if>
  70. group by e.id) b
  71. </select>
  72. <insert id="add" parameterType="com.welampiot.dto.ElectricBoxDTO" useGeneratedKeys="true" keyProperty="id"
  73. >
  74. insert into electric_box(name,address,areaid,sectionid,longitude,latitude,createTime,devType
  75. <if test="installDate != null">,install_date</if>
  76. <if test="expirationDate != null">,expiration_date</if>
  77. )
  78. values
  79. (#{name},#{address},#{areaId},#{sectionId},#{longitude},#{latitude},#{createTime},#{devType}
  80. <if test="installDate != null">,#{installDate}</if>
  81. <if test="expirationDate != null">,#{expirationDate}</if>
  82. )
  83. </insert>
  84. <update id="update" parameterType="com.welampiot.dto.ElectricBoxDTO"
  85. >
  86. update electric_box
  87. set
  88. name=#{name},
  89. address=#{address},
  90. areaid=#{areaId},
  91. sectionid=#{sectionId},
  92. longitude=#{longitude},
  93. latitude=#{latitude},
  94. <if test="installDate != null">install_date=#{installDate},</if>
  95. <if test="expirationDate != null">expiration_date=#{expirationDate},</if>
  96. devType=#{devType}
  97. where id = #{id}
  98. </update>
  99. <select id="checkData" resultType="Integer" parameterType="ElectricBoxDTO">
  100. select count(e.id)
  101. from electric_box e
  102. where 1=1
  103. <if test="sectionList != null and !sectionList.isEmpty()">
  104. and e.sectionid in
  105. <foreach item="dto" collection="sectionList" open="(" separator="," close=")">
  106. #{dto}
  107. </foreach>
  108. </if>
  109. <if test="sectionId != null">
  110. and e.sectionid = #{sectionId}
  111. </if>
  112. <if test="name != null">
  113. and e.name = #{name}
  114. </if>
  115. <if test="id != null">
  116. and e.id != #{id}
  117. </if>
  118. </select>
  119. <delete id="delete" parameterType="com.welampiot.dto.AirSwitchInfoDTO">
  120. delete from electric_box where id=#{id}
  121. </delete>
  122. <select id="getDetailsById" resultType="com.welampiot.dto.ElectricBoxDTO" parameterType="int">
  123. select id,areaid as areaId,sectionid as sectionId,name,address,longitude,latitude,image,install_date installDate,expiration_date expirationDate,devType
  124. from electric_box
  125. where id = #{id}
  126. </select>
  127. <update id="changeElectricBoxLocationById" parameterType="ElectricBoxDTO">
  128. update
  129. `electric_box` e
  130. set
  131. e.longitude = #{longitude},
  132. e.latitude = #{latitude}
  133. where e.id = #{id}
  134. </update>
  135. </mapper>