Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

341 wiersze
11 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.WxBusinessMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxBusiness">
  5. <id column="id" jdbcType="INTEGER" property="id" />
  6. <result column="title" jdbcType="VARCHAR" property="title" />
  7. <result column="type" jdbcType="INTEGER" property="type" />
  8. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  9. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  10. <result column="final_tenant_id" jdbcType="VARCHAR" property="finalTenantId" />
  11. <result column="is_system" jdbcType="INTEGER" property="isSystem" />
  12. <result column="parent_id" jdbcType="INTEGER" property="parentId" />
  13. <result column="is_del" jdbcType="INTEGER" property="isDel" />
  14. </resultMap>
  15. <sql id="allColumns">
  16. `id`,`title`,`type`,`create_date`,`update_date`,`final_tenant_id`,`is_system`,`parent_id`,`is_del`
  17. </sql>
  18. <sql id="dynamicWhereConditions">
  19. where 1 = 1
  20. <if test=" null != id ">
  21. and `id` = #{id}
  22. </if>
  23. <if test=" null != title ">
  24. and `title` like concat('%', #{title},'%')
  25. </if>
  26. <if test=" null != type ">
  27. and `type` = #{type}
  28. </if>
  29. <if test=" null != createDate ">
  30. and `create_date` = #{createDate}
  31. </if>
  32. <if test=" null != updateDate ">
  33. and `update_date` = #{updateDate}
  34. </if>
  35. <if test=" null != finalTenantId ">
  36. and `final_tenant_id` = #{finalTenantId}
  37. </if>
  38. <if test=" null != isSystem ">
  39. and `is_system` = #{isSystem}
  40. </if>
  41. <if test=" null != parentId ">
  42. and `parent_id` = #{parentId}
  43. </if>
  44. <if test=" null != isDel ">
  45. and `is_del` = #{isDel}
  46. </if>
  47. <if test=" null != ids ">
  48. and id in
  49. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  50. #{idItem}
  51. </foreach>
  52. </if>
  53. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  54. </sql>
  55. <select id="selectById" parameterType="Map" resultMap="BaseResultMap">
  56. select
  57. <include refid="allColumns"/>
  58. from wx_business where id = #{id} and `final_tenant_id` = #{finalTenantId}
  59. </select>
  60. <select id="selectByIds" parameterType="Map" resultMap="BaseResultMap">
  61. select
  62. <include refid="allColumns"/>
  63. from wx_business where `final_tenant_id` = #{finalTenantId}
  64. and id in
  65. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  66. #{idItem}
  67. </foreach>
  68. </select>
  69. <select id="findList" parameterType="com.iformall.domain.po.WxBusiness" resultMap="BaseResultMap">
  70. select
  71. <include refid="allColumns"/>
  72. from wx_business
  73. <include refid="dynamicWhereConditions" />
  74. </select>
  75. <select id="findListAll" parameterType="com.iformall.domain.po.WxBusiness" resultMap="BaseResultMap">
  76. select
  77. <include refid="allColumns"/>
  78. from wx_business where `final_tenant_id` = #{finalTenantId}
  79. <if test=" 1 == isRoot">
  80. and `parent_id` is null
  81. </if>
  82. <if test=" null != isDel ">
  83. and `is_del` = #{isDel}
  84. </if>
  85. order by create_date asc
  86. </select>
  87. <select id="findListForMerchant" resultMap="BaseResultMap">
  88. select
  89. <include refid="allColumns"/>
  90. from wx_business b
  91. where b.`final_tenant_id` = #{finalTenantId}
  92. <if test=" 1 == isRoot">
  93. and b.`parent_id` is null
  94. </if>
  95. and
  96. (select count(*) from wx_merchant m
  97. where b.id = m.business_id
  98. <if test=" null != tenantId and '' != tenantId">
  99. and m.`tenant_id` = #{tenantId}
  100. </if>
  101. <if test=" null != parentTenantId and '' != parentTenantId">
  102. and m.`parent_tenant_id` = #{parentTenantId}
  103. </if>
  104. and m.status = 1
  105. and m.is_public = 1) > 0
  106. order by create_date asc
  107. </select>
  108. <select id="findListForCoupon" resultMap="BaseResultMap">
  109. select
  110. <include refid="allColumns"/>
  111. from wx_business b
  112. where b.`final_tenant_id` = #{finalTenantId}
  113. <if test=" 1 == isRoot">
  114. and b.`parent_id` is null
  115. </if>
  116. and
  117. (select count(*) from wx_coupon_channel cc
  118. where b.id = cc.business
  119. and cc.status = 0
  120. <if test=" null != tenantId and '' != tenantId">
  121. and cc.`tenant_id` = #{tenantId}
  122. </if>
  123. <if test=" null != parentTenantId and '' != parentTenantId">
  124. and cc.`parent_tenant_id` = #{parentTenantId}
  125. </if>
  126. <if test=" null != platCode and platCode == 1">
  127. and cc.target_ad = 1
  128. </if>
  129. <if test=" null != platCode and platCode == 3">
  130. and cc.target_ad = 101
  131. </if>
  132. ) > 0
  133. order by create_date asc
  134. </select>
  135. <select id="businessDataList" parameterType="com.iformall.domain.po.WxBusiness" resultType="hashmap">
  136. select b.id,b.title,
  137. round(
  138. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  139. from wx_merchant m
  140. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id where m.business_id = b.id
  141. <if test=" null != tenantId and '' != tenantId">
  142. and m.`tenant_id` = #{tenantId}
  143. </if>
  144. <if test=" null != parentTenantId and '' != parentTenantId">
  145. and m.`parent_tenant_id` = #{parentTenantId}
  146. </if>
  147. and STR_TO_DATE(mtd.report_date,'%Y-%m-%d') between #{startdate} and #{enddate} and m.status = 1 and m.is_del = 0 )
  148. /100,2) volume,
  149. round(
  150. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  151. from wx_merchant m
  152. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id where m.business_id = b.id
  153. <if test=" null != tenantId and '' != tenantId">
  154. and m.`tenant_id` = #{tenantId}
  155. </if>
  156. <if test=" null != parentTenantId and '' != parentTenantId">
  157. and m.`parent_tenant_id` = #{parentTenantId}
  158. </if>
  159. and STR_TO_DATE(mtd.report_date,'%Y-%m-%d') between #{startdate} and #{enddate} and m.status = 1 and m.is_del = 0 )
  160. /
  161. (select if(sum(ws.operation_area) is null,0,sum(ws.operation_area))
  162. from wx_merchant m
  163. left join wx_merchant_shop mtd on mtd.merchant_id = m.id
  164. left join wx_shop ws on(mtd.shop_id = ws.id)
  165. where m.business_id = b.id and m.status = 1 and m.is_del = 0
  166. <if test=" null != tenantId and '' != tenantId">
  167. and m.`tenant_id` = #{tenantId}
  168. </if>
  169. <if test=" null != parentTenantId and '' != parentTenantId">
  170. and m.`parent_tenant_id` = #{parentTenantId}
  171. </if>
  172. )
  173. /100,2) sale,
  174. (select ifnull(sum(rent_area),0) from wx_rent_contract where business_id=b.id
  175. <if test=" null != tenantId and '' != tenantId">
  176. and `tenant_id` = #{tenantId}
  177. </if>
  178. <if test=" null != parentTenantId and '' != parentTenantId">
  179. and `parent_tenant_id` = #{parentTenantId}
  180. </if>
  181. and status in (2,3,4)) area,
  182. round(
  183. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  184. from wx_merchant m
  185. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id where m.business_id = b.id
  186. <if test=" null != tenantId and '' != tenantId">
  187. and m.`tenant_id` = #{tenantId}
  188. </if>
  189. <if test=" null != parentTenantId and '' != parentTenantId">
  190. and m.`parent_tenant_id` = #{parentTenantId}
  191. </if>
  192. and STR_TO_DATE(mtd.report_date,'%Y-%m-%d') between #{startdate} and #{enddate} and m.status = 1 and m.is_del = 0 ) /
  193. (select sum(mtd.trade_count)
  194. from wx_merchant m
  195. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id where m.business_id = b.id
  196. <if test=" null != tenantId and '' != tenantId">
  197. and m.`tenant_id` = #{tenantId}
  198. </if>
  199. <if test=" null != parentTenantId and '' != parentTenantId">
  200. and m.`parent_tenant_id` = #{parentTenantId}
  201. </if>
  202. and STR_TO_DATE(mtd.report_date,'%Y-%m-%d') between #{startdate} and #{enddate} and m.status = 1 and m.is_del = 0 )
  203. /100,2) comPrice
  204. from wx_business b
  205. </select>
  206. <select id="devoteList" parameterType="com.iformall.domain.po.WxBusiness" resultType="hashmap">
  207. select mm.name merchantName,
  208. round(
  209. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  210. from wx_merchant m
  211. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id
  212. where m.business_id = #{id}
  213. <if test=" null != tenantId and '' != tenantId">
  214. and m.`tenant_id` = #{tenantId}
  215. </if>
  216. <if test=" null != parentTenantId and '' != parentTenantId">
  217. and m.`parent_tenant_id` = #{parentTenantId}
  218. </if>
  219. and mtd.report_date between #{startdate} and #{enddate}
  220. and m.status = 1 and m.is_del = 0 and m.id = mm.id)
  221. /
  222. (select if(sum(ws.operation_area) is null,0,sum(ws.operation_area))
  223. from wx_merchant m
  224. left join wx_merchant_shop mtd on mtd.merchant_id = m.id
  225. left join wx_shop ws on(mtd.shop_id = ws.id)
  226. where m.status = 1 and m.is_del = 0 and m.business_id = #{id}
  227. <if test=" null != tenantId and '' != tenantId">
  228. and m.`tenant_id` = #{tenantId}
  229. </if>
  230. <if test=" null != parentTenantId and '' != parentTenantId">
  231. and m.`parent_tenant_id` = #{parentTenantId}
  232. </if>
  233. and m.id = mm.id)
  234. /100,2) sale,
  235. round(
  236. round(
  237. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  238. from wx_merchant m
  239. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id
  240. where m.business_id = #{id}
  241. <if test=" null != tenantId and '' != tenantId">
  242. and m.`tenant_id` = #{tenantId}
  243. </if>
  244. <if test=" null != parentTenantId and '' != parentTenantId">
  245. and m.`parent_tenant_id` = #{parentTenantId}
  246. </if>
  247. and mtd.report_date between #{startdate} and #{enddate}
  248. and m.status = 1 and m.is_del = 0 and m.id = mm.id)/
  249. (select if(sum(ws.operation_area) is null,0,sum(ws.operation_area))
  250. from wx_merchant m
  251. left join wx_merchant_shop mtd on mtd.merchant_id = m.id
  252. left join wx_shop ws on(mtd.shop_id = ws.id)
  253. where m.status = 1 and m.is_del = 0 and m.business_id = #{id}
  254. <if test=" null != tenantId and '' != tenantId">
  255. and m.`tenant_id` = #{tenantId}
  256. </if>
  257. <if test=" null != parentTenantId and '' != parentTenantId">
  258. and m.`parent_tenant_id` = #{parentTenantId}
  259. </if>
  260. and m.id = mm.id)/100,2)
  261. /
  262. round(
  263. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  264. from wx_merchant m
  265. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id
  266. where m.business_id = #{id}
  267. <if test=" null != tenantId and '' != tenantId">
  268. and m.`tenant_id` = #{tenantId}
  269. </if>
  270. <if test=" null != parentTenantId and '' != parentTenantId">
  271. and m.`parent_tenant_id` = #{parentTenantId}
  272. </if>
  273. and mtd.report_date between #{startdate} and #{enddate}
  274. and m.status = 1 and m.is_del = 0 )
  275. /
  276. (select if(sum(ws.operation_area) is null,0,sum(ws.operation_area))
  277. from wx_merchant m
  278. left join wx_merchant_shop mtd on mtd.merchant_id = m.id
  279. left join wx_shop ws on(mtd.shop_id = ws.id)
  280. where m.business_id = #{id}
  281. <if test=" null != tenantId and '' != tenantId">
  282. and m.`tenant_id` = #{tenantId}
  283. </if>
  284. <if test=" null != parentTenantId and '' != parentTenantId">
  285. and m.`parent_tenant_id` = #{parentTenantId}
  286. </if>
  287. and m.status = 1 and m.is_del = 0 )
  288. /100,2)
  289. *100,2) devoteRate
  290. from wx_merchant mm
  291. left join wx_merchant_trade_daily mtd on mtd.merchant_id = mm.id
  292. left join wx_merchant_shop wmt on wmt.merchant_id = mm.id
  293. left join wx_shop ws on(wmt.shop_id = ws.id)
  294. where mm.business_id=#{id}
  295. <if test=" null != tenantId and '' != tenantId">
  296. and mm.`tenant_id` = #{tenantId}
  297. </if>
  298. <if test=" null != parentTenantId and '' != parentTenantId">
  299. and mm.`parent_tenant_id` = #{parentTenantId}
  300. </if>
  301. and mm.status = 1 and mm.is_del = 0
  302. and mtd.report_date between #{startdate} and #{enddate}
  303. group by mm.id
  304. order by devoteRate desc
  305. <if test="null != limitStart and null != limitEnd">
  306. limit #{limitStart},#{limitEnd}
  307. </if>
  308. </select>
  309. </mapper>