WechatScanLoginMapper.xml 13 KB

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