WechatScanLoginMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.template.mapper.WechatScanLoginMapper">
  4. <resultMap id="Tj" type="com.template.model.tongji.Tj">
  5. <result property="name" column="name"/>
  6. <result property="num" column="num"/>
  7. </resultMap>
  8. <resultMap id="Tjt" type="com.template.model.tongji.All">
  9. <result property="total" column="total"/>
  10. </resultMap>
  11. <resultMap id="Elct" type="com.template.model.tongji.DAll">
  12. <result property="num" column="num"/>
  13. </resultMap>
  14. <resultMap id="Energy" type="com.template.model.tongji.EnergyTj">
  15. <result property="name" column="name"/>
  16. <result property="meterName" column="meter_name"/>
  17. <result property="num" column="num"/>
  18. </resultMap>
  19. <resultMap id="MonthT" type="com.template.model.tongji.EnergyTj">
  20. <result property="id" column="id"/>
  21. <result property="name" column="name"/>
  22. <result property="type" column="type"/>
  23. <result property="date" column="date"/>
  24. <result property="num" column="num"/>
  25. </resultMap>
  26. <resultMap id="DayT" type="com.template.model.tongji.EnergyTj">
  27. <result property="id" column="id"/>
  28. <result property="name" column="name"/>
  29. <result property="type" column="type"/>
  30. <result property="date" column="date"/>
  31. <result property="num" column="num"/>
  32. </resultMap>
  33. <resultMap id="meterMonthDataVo" type="com.template.model.tongji.MeterMonthDataVo">
  34. <result property="id" column="id"/>
  35. <result property="buildAddress" column="build_address"/>
  36. <result property="address" column="address"/>
  37. <result property="meterPower" column="meter_power"/>
  38. <result property="meterNo" column="meter_no"/>
  39. <result property="createTime" column="create_time"/>
  40. </resultMap>
  41. <resultMap id="meterMonthData" type="com.template.model.tongji.MeterMonthData">
  42. <result property="id" column="id"/>
  43. <result property="name" column="name"/>
  44. <result property="type" column="type"/>
  45. <result property="date" column="date"/>
  46. <result property="num" column="num"/>
  47. </resultMap>
  48. <!--用户类别统计-->
  49. <select id="getUserIdTj" parameterType="com.template.model.tongji.Tj" resultMap="Tj">
  50. select a.name,IFNULL(b.num,0) as num from `smart_identity` a
  51. left join (
  52. select identity_id,COUNT(*) as num from `smart_user`
  53. where is_cancel=0 and deleted=0 group by identity_id ) b
  54. on a.id=b.identity_id where a.`deleted`=0
  55. </select>
  56. <!--用户总数-->
  57. <select id="getUserIdTjt" parameterType="com.template.model.tongji.Tj" resultMap="Tjt">
  58. select count(*) as total from `smart_user` where is_cancel=0 and deleted=0
  59. </select>
  60. <!--水表总计-->
  61. <select id="getWaterTj" parameterType="com.template.model.tongji.Tj" resultMap="Elct">
  62. select ifnull(sum(meter_power),0) as num from `smart_meter_detail` where meter_type=0 and deleted=0
  63. </select>
  64. <!--电表总计-->
  65. <select id="getElcTj" parameterType="com.template.model.tongji.Tj" resultMap="Elct">
  66. select ifnull(sum(meter_power),0) as num from `smart_meter_detail` where meter_type=1 and deleted=0
  67. </select>
  68. <!--每个月各水表数据统计-->
  69. <select id="getWaterTjByMonAndBuild" parameterType="String" resultMap="Energy">
  70. select e.name,d.name as meter_name,d.num from (
  71. select c.name,b.build_id,a.num from (
  72. select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
  73. where deleted=0 and meter_type=0 and update_time like concat(#{month}, '%')
  74. group by meter_id ) a left join `smart_build_meter` b
  75. on a.meter_id=b.meter_id
  76. left join `smart_meter` c on a.meter_id=c.id
  77. where b.meter_type=0 and c.meter_type=0 and b.`deleted`=0 and c.`deleted`=0 ) d
  78. left join `smart_build` e on d.build_id=e.id
  79. where e.deleted=0
  80. </select>
  81. <!--每个月各电表数据统计-->
  82. <select id="getElcTjByMonAndBuild" parameterType="String" resultMap="Energy">
  83. select e.name,d.name as meter_name,d.num from (
  84. select c.name,b.build_id,a.num from (
  85. select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
  86. where deleted=0 and meter_type=1 and update_time like concat(#{month}, '%')
  87. group by meter_id ) a left join `smart_build_meter` b
  88. on a.meter_id=b.meter_id
  89. left join `smart_meter` c on a.meter_id=c.id
  90. where b.meter_type=1 and c.meter_type=1 and b.`deleted`=0 and c.`deleted`=0 ) d
  91. left join `smart_build` e on d.build_id=e.id
  92. where e.deleted=0
  93. </select>
  94. <!--每个月每个楼栋查询-->
  95. <select id="getTjByMon" parameterType="String" resultMap="MonthT">
  96. select * from `month_meter_detail` where `name`=#{name} and `meter_name`=#{meterName} and `date`=#{month} and `type`=#{type}
  97. </select>
  98. <insert id="insertMonthMeter" parameterType="com.template.model.tongji.EnergyTj" useGeneratedKeys="true">
  99. INSERT INTO `month_meter_detail`
  100. <trim prefix="(" suffix=")" suffixOverrides=",">
  101. <if test="name != null">`name`,</if>
  102. <if test="meterName != null">`meter_name`,</if>
  103. <if test="type != null">`type`,</if>
  104. <if test="date != null">`date`,</if>
  105. <if test="num != null">`num`,</if>
  106. </trim>
  107. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  108. <if test="name != null">#{name},</if>
  109. <if test="meterName != null">#{meterName},</if>
  110. <if test="type != null">#{type},</if>
  111. <if test="date != null">#{date},</if>
  112. <if test="num != null">#{num},</if>
  113. </trim>
  114. </insert>
  115. <update id="updateMonthMeter">
  116. UPDATE `month_meter_detail`
  117. <trim prefix="SET" suffixOverrides=",">
  118. num=#{energyTj.num}
  119. </trim>
  120. <where>
  121. and id=#{energyTj.id}
  122. </where>
  123. </update>
  124. <!--每天各水表数据统计-->
  125. <select id="getWaterTjByDayAndBuild" parameterType="String" resultMap="Energy">
  126. select e.name,d.name as meter_name,d.num from (
  127. select c.name,b.build_id,a.num from (
  128. select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
  129. where deleted=0 and meter_type=0 and update_time like concat(#{day}, '%')
  130. group by meter_id ) a left join `smart_build_meter` b
  131. on a.meter_id=b.meter_id
  132. left join `smart_meter` c on a.meter_id=c.id
  133. where b.meter_type=0 and c.meter_type=0 and b.`deleted`=0 and c.`deleted`=0 ) d
  134. left join `smart_build` e on d.build_id=e.id
  135. where e.deleted=0
  136. </select>
  137. <!--每天各电表数据统计-->
  138. <select id="getElcTjByDayAndBuild" parameterType="String" resultMap="Energy">
  139. select e.name,d.name as meter_name,d.num from (
  140. select c.name,b.build_id,a.num from (
  141. select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
  142. where deleted=0 and meter_type=1 and update_time like concat(#{day}, '%')
  143. group by meter_id ) a left join `smart_build_meter` b
  144. on a.meter_id=b.meter_id
  145. left join `smart_meter` c on a.meter_id=c.id
  146. where b.meter_type=1 and c.meter_type=1 and b.`deleted`=0 and c.`deleted`=0 ) d
  147. left join `smart_build` e on d.build_id=e.id
  148. where e.deleted=0
  149. </select>
  150. <select id="getTjByDay" parameterType="String" resultMap="DayT">
  151. select * from `day_meter_detail` where `name`=#{name} and `meter_name`=#{meterName} and `date`=#{day} and `type`=#{type}
  152. </select>
  153. <insert id="insertDayMeter" parameterType="com.template.model.tongji.EnergyTj" useGeneratedKeys="true">
  154. INSERT INTO `day_meter_detail`
  155. <trim prefix="(" suffix=")" suffixOverrides=",">
  156. <if test="name != null">`name`,</if>
  157. <if test="meterName != null">`meter_name`,</if>
  158. <if test="type != null">`type`,</if>
  159. <if test="date != null">`date`,</if>
  160. <if test="num != null">`num`,</if>
  161. </trim>
  162. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  163. <if test="name != null">#{name},</if>
  164. <if test="meterName != null">#{meterName},</if>
  165. <if test="type != null">#{type},</if>
  166. <if test="date != null">#{date},</if>
  167. <if test="num != null">#{num},</if>
  168. </trim>
  169. </insert>
  170. <update id="updateDayMeter">
  171. UPDATE `day_meter_detail`
  172. <trim prefix="SET" suffixOverrides=",">
  173. num=#{energyTj.num}
  174. </trim>
  175. <where>
  176. and id=#{energyTj.id}
  177. </where>
  178. </update>
  179. <!--每个月水费数据-->
  180. <select id="getMonWater" parameterType="String" resultMap="Tj">
  181. select * from `month_meter_detail` where type=0 and `date`=#{month}
  182. </select>
  183. <!--每个月电费数据-->
  184. <select id="getMonElc" parameterType="String" resultMap="Tj">
  185. select * from `month_meter_detail` where type=1 and `date`=#{month}
  186. </select>
  187. <!--区域能耗统计-->
  188. <select id="getMeterMonthPage" resultMap="meterMonthData">
  189. select * from (select a.id,a.`name`,a.`date`,a.`num` w_num,b.num as e_num
  190. from `month_meter_detail` a,`month_meter_detail` b
  191. where a.`type`=0 and b.`type`=1 and a.name=b.`name`
  192. and a.`date`=b.`date` ) a
  193. <where>
  194. <if test="meterMonthData.date != null and meterMonthData.date != ''"> a.date like concat(#{meterMonthData.date}, '%')</if>
  195. </where>
  196. order by a.date desc
  197. </select>
  198. <!--实时抄表-->
  199. <select id="getMeterDayPage" resultMap="meterMonthDataVo">
  200. select smd.id,sm.build_address,sm.address,smd.meter_power,sm.meter_no,smd.create_time from smart_meter_detail smd
  201. left join smart_meter sm on sm.deleted = 0 and sm.id = smd.meter_id
  202. where smd.deleted = 0
  203. <where>
  204. <if test="meterMonthData.date != null and meterMonthData.date != ''"> AND smd.create_time like concat(#{meterMonthData.date}, '%')</if>
  205. <if test="meterMonthData.type != null and meterMonthData.type != ''"> AND smd.meter_type = #{meterMonthData.type}</if>
  206. </where>
  207. order by smd.create_time desc
  208. </select>
  209. </mapper>