Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

285 строки
9.1 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. <select id="findSimpleMeterList" parameterType="java.util.Map" resultType="com.iformall.domain.po.KwMeter">
  48. select m.`id`, m.`total_power` from kw_merchant_meter mm
  49. left join kw_meter m on mm.`meter_id` = m.id
  50. where mm.`status` = 0
  51. <if test=" null != merchantId ">
  52. and mm.`merchant_id` = #{merchantId}
  53. </if>
  54. </select>
  55. <resultMap id="BaseResultMapListVo" type="com.iformall.domain.vo.KwMerchantMeterVo">
  56. <id column="id" jdbcType="BIGINT" property="id"/>
  57. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  58. <result column="status" jdbcType="INTEGER" property="status"/>
  59. <result column="name" jdbcType="VARCHAR" property="merchantName"/>
  60. <result column="link_phone" jdbcType="VARCHAR" property="merchantLinkPhone"/>
  61. <collection column="{merchantId=id}" property="meterList"
  62. ofType="com.iformall.domain.po.KwMeter"
  63. javaType="java.util.List"
  64. select="com.iformall.mapper.KwMerchantMeterMapper.findSimpleMeterList">
  65. </collection>
  66. </resultMap>
  67. <sql id="allColumnsVo">
  68. `id`, `tenant_id`, `merchant_id`, `status`, `name`, `link_phone`
  69. </sql>
  70. <select id="findVoList" parameterType="com.iformall.domain.dto.KwMerchantMeterDto" resultMap="BaseResultMapListVo">
  71. select <include refid="allColumnsVo"/>
  72. from (
  73. select merchant_id from kw_merchant_meter
  74. where `status` = 0
  75. <if test=" null != tenantId ">
  76. and `tenant_id` = #{tenantId}
  77. </if>
  78. <if test=" null != merchantId ">
  79. and `merchant_id` = #{merchantId}
  80. </if>
  81. group by merchant_id
  82. ) temp
  83. , wx_merchant
  84. where temp.merchant_id = id
  85. <if test=" null != merchantName and ''!=merchantName ">
  86. and `name` like concat('%', #{merchantName},'%')
  87. </if>
  88. <if test=" null != merchantLinkPhone and ''!=merchantLinkPhone ">
  89. and `link_phone` like concat('%', #{merchantLinkPhone},'%')
  90. </if>
  91. <if test=" null != merchantStatus ">
  92. and `status` = #{merchantStatus}
  93. </if>
  94. <if test=" null != businessId ">
  95. and `business_id` = #{businessId}
  96. </if>
  97. </select>
  98. <select id="findMeterList" parameterType="java.util.Map" resultType="com.iformall.domain.po.KwMeter">
  99. select m.* from kw_merchant_meter mm
  100. left join kw_meter m on mm.`meter_id` = m.id
  101. where mm.`status` = 0
  102. <if test=" null != merchantId ">
  103. and mm.`merchant_id` = #{merchantId}
  104. </if>
  105. </select>
  106. <resultMap id="BaseResultMapVo" type="com.iformall.domain.vo.KwMerchantMeterVo">
  107. <id column="id" jdbcType="BIGINT" property="id"/>
  108. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  109. <result column="status" jdbcType="INTEGER" property="status"/>
  110. <result column="name" jdbcType="VARCHAR" property="merchantName"/>
  111. <result column="link_phone" jdbcType="VARCHAR" property="merchantLinkPhone"/>
  112. <collection column="{merchantId=id}" property="shopVoList"
  113. ofType="com.iformall.domain.vo.WxShopVo"
  114. javaType="java.util.List"
  115. select="com.iformall.mapper.WxShopMapper.findShopVoList">
  116. </collection>
  117. <collection column="{merchantId=id}" property="meterList"
  118. ofType="com.iformall.domain.po.KwMeter"
  119. javaType="java.util.List"
  120. select="com.iformall.mapper.KwMerchantMeterMapper.findMeterList">
  121. </collection>
  122. </resultMap>
  123. <select id="getById" parameterType="Long" resultMap="BaseResultMapVo">
  124. select <include refid="allColumnsVo"/>
  125. from (
  126. select merchant_id from kw_merchant_meter
  127. where `status` = 0
  128. and `merchant_id` = #{merchantId}
  129. group by merchant_id
  130. ) temp
  131. , wx_merchant
  132. where temp.merchant_id = id
  133. </select>
  134. <sql id="dynamicWhereConditionsVo">
  135. where 1 = 1
  136. <if test=" null != tenantId ">
  137. and `tenant_id` = #{tenantId}
  138. </if>
  139. <if test=" null != boxId ">
  140. and `box_id` = #{boxId}
  141. </if>
  142. <if test=" null != meterId ">
  143. and `meter_id` = #{meterId}
  144. </if>
  145. <if test=" null != address ">
  146. and `address` = #{address}
  147. </if>
  148. <if test=" null != startTime and null != endTime ">
  149. and `create_time` between #{startTime} and #{endTime}
  150. </if>
  151. </sql>
  152. <resultMap id="DataVoResultMap" type="com.iformall.domain.vo.KwMerchantMeterDataVo">
  153. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  154. <result column="totalPower" jdbcType="INTEGER" property="totalPower"/>
  155. <result column="lastTotalPower" jdbcType="INTEGER" property="lastTotalPower"/>
  156. <result column="usedPower" jdbcType="INTEGER" property="usedPower"/>
  157. <result column="reportTime" jdbcType="VARCHAR" property="reportTime"/>
  158. <result column="recordStartTime" jdbcType="TIMESTAMP" property="recordStartTime"/>
  159. <result column="recordEndTime" jdbcType="TIMESTAMP" property="recordEndTime"/>
  160. <result column="merchantId" jdbcType="BIGINT" property="merchantId"/>
  161. <result column="merchantName" jdbcType="VARCHAR" property="merchantName"/>
  162. <result column="merchantLinkPhone" jdbcType="VARCHAR" property="merchantLinkPhone"/>
  163. <result column="businessId" jdbcType="INTEGER" property="businessId"/>
  164. <result column="businessTitle" jdbcType="VARCHAR" property="businessTitle"/>
  165. </resultMap>
  166. <select id="findDataVoList" parameterType="com.iformall.domain.dto.KwMerchantMeterDataDto" resultMap="DataVoResultMap">
  167. select
  168. temp.tenant_id,
  169. <if test=" null != merchantId ">
  170. mm.merchant_id as merchantId,
  171. m.name as merchantName,
  172. m.link_phone as merchantLinkPhone,
  173. </if>
  174. <if test=" null != businessId ">
  175. m.business_id as businessId,
  176. </if>
  177. min(temp.recordStartTime) as recordStartTime,
  178. max(temp.recordEndTime) as recordEndTime,
  179. sum(temp.totalPower) as totalPower,
  180. sum(temp.lastTotalPower) as lastTotalPower,
  181. sum(temp.usedPower) as usedPower
  182. from
  183. kw_merchant_meter mm,
  184. (SELECT
  185. tenant_id,box_id,meter_id,
  186. min(last_device_time) as recordStartTime,
  187. min(last_total_power) as lastTotalPower,
  188. max(device_time) as recordEndTime,
  189. max(total_power) as totalPower,
  190. sum(used_power) as usedPower
  191. FROM kw_meter_data
  192. <include refid="dynamicWhereConditionsVo"/>
  193. group by tenant_id,box_id,meter_id
  194. ) as temp,
  195. wx_merchant m
  196. where mm.status = 0
  197. and mm.meter_id = temp.meter_id
  198. and mm.merchant_id = m.id
  199. <if test=" null != merchantStatus ">
  200. and m`status` = #{merchantStatus}
  201. </if>
  202. group by
  203. temp.tenant_id
  204. <if test=" null != merchantId ">
  205. ,merchantId
  206. </if>
  207. <if test=" null != businessId ">
  208. ,businessId
  209. </if>
  210. <if test=" null != sortColumns">order by ${sortColumns}</if>
  211. <if test=" null != limitCount">limit #{limitCount}</if>
  212. </select>
  213. <update id="unbindBatch" parameterType="java.lang.Long">
  214. update kw_merchant_meter set status = 1
  215. where status = 0
  216. and `merchant_id` = #{merchantId}
  217. </update>
  218. <update id="unbind" parameterType="java.lang.Long">
  219. update kw_merchant_meter set status = 1
  220. where status = 0
  221. and `meter_id` = #{meterId}
  222. </update>
  223. <resultMap id="MerchantMeterMap" type="com.iformall.domain.vo.MerchantMeterVo">
  224. <result column="merchant_id" property="merchantId"/>
  225. <result column="merchant_name" property="merchantName"/>
  226. <result column="has" property="has"/>
  227. </resultMap>
  228. <select id="getMerchantMeter" resultMap="MerchantMeterMap">
  229. select m.id as merchant_id,m.name as merchant_name,ifnull(mm.status,0) has from wx_merchant m
  230. left join (select merchant_id,1 as status from kw_merchant_meter where status=0 group by merchant_id) mm on m.id=mm.merchant_id
  231. where m.status=1 and m.id not in(select merchant_id from wx_merchant_power_bill_config where tenant_id=#{tenantId})
  232. </select>
  233. </mapper>