WechatScanLoginMapper.xml 13 KB

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