WechatScanLoginMapper.xml 10 KB

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