后台服务
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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