Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

317 rader
10 KiB

  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.iformall.mapper.KwMerchantMeterMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.KwMerchantMeter">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  7. <result column="meter_id" jdbcType="BIGINT" property="meterId"/>
  8. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  9. <result column="status" jdbcType="INTEGER" property="status"/>
  10. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  11. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  12. </resultMap>
  13. <sql id="allColumns">
  14. `id`,`tenant_id`,`meter_id`,`merchant_id`,`status`,`create_time`,`update_time`
  15. </sql>
  16. <sql id="dynamicWhereConditions">
  17. where 1 = 1
  18. <if test=" null != id ">
  19. and `id` = #{id}
  20. </if>
  21. <if test=" null != tenantId ">
  22. and `tenant_id` = #{tenantId}
  23. </if>
  24. <if test=" null != merchantId ">
  25. and `merchant_id` = #{merchantId}
  26. </if>
  27. <if test=" null != meterId ">
  28. and `meter_id` = #{meterId}
  29. </if>
  30. <if test=" null != status ">
  31. and `status` = #{status}
  32. </if>
  33. <if test=" null != ids ">
  34. and id in
  35. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  36. #{idItem}
  37. </foreach>
  38. </if>
  39. <if test=" null != sortColumns">order by ${sortColumns}</if>
  40. </sql>
  41. <select id="findList" parameterType="com.iformall.domain.po.KwMerchantMeter" resultMap="BaseResultMap">
  42. select
  43. <include refid="allColumns"/>
  44. from kw_merchant_meter
  45. <include refid="dynamicWhereConditions"/>
  46. </select>
  47. <resultMap id="MeterBaseResultMap" type="com.iformall.domain.po.KwMeter">
  48. <id column="id" jdbcType="BIGINT" property="id"/>
  49. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  50. <result column="address" jdbcType="BIGINT" property="address"/>
  51. <result column="brand" jdbcType="VARCHAR" property="brand"/>
  52. <result column="place" jdbcType="VARCHAR" property="place"/>
  53. <result column="model" jdbcType="VARCHAR" property="model"/>
  54. <result column="protocol" jdbcType="INTEGER" property="protocol"/>
  55. <result column="bandrate" jdbcType="INTEGER" property="bandrate"/>
  56. <result column="last_online_time" jdbcType="TIMESTAMP" property="lastOnlineTime"/>
  57. <result column="online_status" jdbcType="INTEGER" property="onlineStatus"/>
  58. <result column="config" jdbcType="VARCHAR" property="config"/>
  59. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  60. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  61. <result column="box_id" jdbcType="BIGINT" property="boxId"/>
  62. <result column="status" jdbcType="INTEGER" property="status"/>
  63. <result column="bind_status" jdbcType="INTEGER" property="bindStatus"/>
  64. <association column="{meterId=id}" property="latestRecord"
  65. select="com.iformall.mapper.KwMeterDataMapper.findLastRecordList">
  66. </association >
  67. </resultMap>
  68. <resultMap id="MeterSimpleResultMap" type="com.iformall.domain.po.KwMeter">
  69. <id column="id" jdbcType="BIGINT" property="id"/>
  70. <association column="{meterId=id}" property="latestRecord"
  71. select="com.iformall.mapper.KwMeterDataMapper.findLastRecordList">
  72. </association >
  73. </resultMap>
  74. <select id="findSimpleMeterList" parameterType="java.util.Map" resultMap="MeterSimpleResultMap">
  75. select m.id from kw_merchant_meter mm
  76. left join kw_meter m on mm.`meter_id` = m.id
  77. where mm.`status` = 0
  78. <if test=" null != merchantId ">
  79. and mm.`merchant_id` = #{merchantId}
  80. </if>
  81. </select>
  82. <select id="countMeterList" parameterType="java.util.Map" resultType="java.lang.Integer">
  83. select count(*) from kw_merchant_meter mm
  84. left join kw_meter m on mm.`meter_id` = m.id
  85. where mm.`status` = 0
  86. <if test=" null != merchantId ">
  87. and mm.`merchant_id` = #{merchantId}
  88. </if>
  89. </select>
  90. <resultMap id="BaseResultMapListVo" type="com.iformall.domain.vo.KwMerchantMeterVo">
  91. <id column="id" jdbcType="BIGINT" property="id"/>
  92. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  93. <result column="status" jdbcType="INTEGER" property="status"/>
  94. <result column="name" jdbcType="VARCHAR" property="merchantName"/>
  95. <result column="link_phone" jdbcType="VARCHAR" property="merchantLinkPhone"/>
  96. <association column="{merchantId=id}" property="meterCount"
  97. select="com.iformall.mapper.KwMerchantMeterMapper.countMeterList">
  98. </association>
  99. <collection column="{merchantId=id}" property="meterList"
  100. ofType="com.iformall.domain.po.kwMeter"
  101. javaType="java.util.List"
  102. select="com.iformall.mapper.KwMerchantMeterMapper.findSimpleMeterList">
  103. </collection>
  104. </resultMap>
  105. <sql id="allColumnsVo">
  106. `id`, `tenant_id`, `merchant_id`, `status`, `name`, `link_phone`
  107. </sql>
  108. <select id="findVoList" parameterType="com.iformall.domain.dto.KwMerchantMeterDto" resultMap="BaseResultMapListVo">
  109. select <include refid="allColumnsVo"/>
  110. from (
  111. select merchant_id from kw_merchant_meter
  112. where `status` = 0
  113. <if test=" null != tenantId ">
  114. and `tenant_id` = #{tenantId}
  115. </if>
  116. <if test=" null != merchantId ">
  117. and `merchant_id` = #{merchantId}
  118. </if>
  119. group by merchant_id
  120. ) temp
  121. , wx_merchant
  122. where temp.merchant_id = id
  123. <if test=" null != merchantName and ''!=merchantName ">
  124. and `name` like concat('%', #{merchantName},'%')
  125. </if>
  126. <if test=" null != merchantLinkPhone and ''!=merchantLinkPhone ">
  127. and `link_phone` like concat('%', #{merchantLinkPhone},'%')
  128. </if>
  129. <if test=" null != merchantStatus ">
  130. and `status` = #{merchantStatus}
  131. </if>
  132. <if test=" null != businessId ">
  133. and `business_id` = #{businessId}
  134. </if>
  135. </select>
  136. <select id="findMeterList" parameterType="java.util.Map" resultMap="MeterBaseResultMap">
  137. select m.* from kw_merchant_meter mm
  138. left join kw_meter m on mm.`meter_id` = m.id
  139. where mm.`status` = 0
  140. <if test=" null != merchantId ">
  141. and mm.`merchant_id` = #{merchantId}
  142. </if>
  143. </select>
  144. <resultMap id="BaseResultMapVo" type="com.iformall.domain.vo.KwMerchantMeterVo">
  145. <id column="id" jdbcType="BIGINT" property="id"/>
  146. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  147. <result column="status" jdbcType="INTEGER" property="status"/>
  148. <result column="name" jdbcType="VARCHAR" property="merchantName"/>
  149. <result column="link_phone" jdbcType="VARCHAR" property="merchantLinkPhone"/>
  150. <collection column="{merchantId=id}" property="shopVoList"
  151. ofType="com.iformall.domain.vo.WxShopVo"
  152. javaType="java.util.List"
  153. select="com.iformall.mapper.WxShopMapper.findShopVoList">
  154. </collection>
  155. <collection column="{merchantId=id}" property="meterList"
  156. ofType="com.iformall.domain.po.kwMeter"
  157. javaType="java.util.List"
  158. select="com.iformall.mapper.KwMerchantMeterMapper.findMeterList">
  159. </collection>
  160. </resultMap>
  161. <select id="getById" parameterType="Long" resultMap="BaseResultMapVo">
  162. select <include refid="allColumnsVo"/>
  163. from (
  164. select merchant_id from kw_merchant_meter
  165. where `status` = 0
  166. and `merchant_id` = #{merchantId}
  167. group by merchant_id
  168. ) temp
  169. , wx_merchant
  170. where temp.merchant_id = id
  171. </select>
  172. <sql id="dynamicWhereConditionsVo">
  173. where 1 = 1
  174. <if test=" null != tenantId ">
  175. and `tenant_id` = #{tenantId}
  176. </if>
  177. <if test=" null != boxId ">
  178. and `box_id` = #{boxId}
  179. </if>
  180. <if test=" null != meterId ">
  181. and `meter_id` = #{meterId}
  182. </if>
  183. <if test=" null != address ">
  184. and `address` = #{address}
  185. </if>
  186. <if test=" null != startTime and null != endTime ">
  187. and `create_time` between #{startTime} and #{endTime}
  188. </if>
  189. </sql>
  190. <resultMap id="DataVoResultMap" type="com.iformall.domain.vo.KwMerchantMeterDataVo">
  191. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  192. <result column="totalPower" jdbcType="INTEGER" property="totalPower"/>
  193. <result column="lastTotalPower" jdbcType="INTEGER" property="lastTotalPower"/>
  194. <result column="usedPower" jdbcType="INTEGER" property="usedPower"/>
  195. <result column="reportTime" jdbcType="VARCHAR" property="reportTime"/>
  196. <result column="recordStartTime" jdbcType="TIMESTAMP" property="recordStartTime"/>
  197. <result column="recordEndTime" jdbcType="TIMESTAMP" property="recordEndTime"/>
  198. <result column="merchantId" jdbcType="BIGINT" property="merchantId"/>
  199. <result column="merchantName" jdbcType="VARCHAR" property="merchantName"/>
  200. <result column="merchantLinkPhone" jdbcType="VARCHAR" property="merchantLinkPhone"/>
  201. <result column="businessId" jdbcType="INTEGER" property="businessId"/>
  202. <result column="businessTitle" jdbcType="VARCHAR" property="businessTitle"/>
  203. </resultMap>
  204. <select id="findDataVoList" parameterType="com.iformall.domain.dto.KwMerchantMeterDataDto" resultMap="DataVoResultMap">
  205. select
  206. temp.tenant_id,
  207. <if test=" null != merchantId ">
  208. mm.merchant_id as merchantId,
  209. m.name as merchantName,
  210. m.link_phone as merchantLinkPhone,
  211. </if>
  212. <if test=" null != businessId ">
  213. m.business_id as businessId,
  214. </if>
  215. min(temp.recordStartTime) as recordStartTime,
  216. max(temp.recordEndTime) as recordEndTime,
  217. sum(temp.totalPower) as totalPower,
  218. sum(temp.lastTotalPower) as lastTotalPower,
  219. sum(temp.usedPower) as usedPower
  220. from
  221. kw_merchant_meter mm,
  222. (SELECT
  223. tenant_id,box_id,meter_id,
  224. min(last_device_time) as recordStartTime,
  225. min(last_total_power) as lastTotalPower,
  226. max(device_time) as recordEndTime,
  227. max(total_power) as totalPower,
  228. sum(used_power) as usedPower
  229. FROM kw_meter_data
  230. <include refid="dynamicWhereConditionsVo"/>
  231. group by meter_id
  232. ) as temp,
  233. wx_merchant m
  234. where mm.status = 0
  235. and mm.meter_id = temp.meter_id
  236. and mm.merchant_id = m.id
  237. <if test=" null != merchantStatus ">
  238. and m`status` = #{merchantStatus}
  239. </if>
  240. group by
  241. temp.tenant_id
  242. <if test=" null != merchantId ">
  243. ,merchantId
  244. </if>
  245. <if test=" null != businessId ">
  246. ,businessId
  247. </if>
  248. <if test=" null != sortColumns">order by ${sortColumns}</if>
  249. <if test=" null != limitCount">limit #{limitCount}</if>
  250. </select>
  251. <update id="unbindBatch" parameterType="java.lang.Long">
  252. update kw_merchant_meter set status = 1
  253. where status = 0
  254. and `merchant_id` = #{merchantId}
  255. </update>
  256. <update id="unbind" parameterType="java.lang.Long">
  257. update kw_merchant_meter set status = 1
  258. where status = 0
  259. and `meter_id` = #{meterId}
  260. </update>
  261. </mapper>