25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

366 satır
12 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. <if test=" null != businessForRule and '' != businessForRule ">
  86. and `id` in (${businessForRule})
  87. </if>
  88. order by create_date asc
  89. </select>
  90. <select id="findListForMerchant" resultMap="BaseResultMap">
  91. select
  92. <include refid="allColumns"/>
  93. from wx_business b
  94. where b.`final_tenant_id` = #{finalTenantId}
  95. <if test=" 1 == isRoot">
  96. and b.`parent_id` is null
  97. </if>
  98. <if test=" null != isDel ">
  99. and b.`is_del` = #{isDel}
  100. </if>
  101. <if test=" null != businessForRule and '' != businessForRule ">
  102. and `id` in (${businessForRule})
  103. </if>
  104. and
  105. (select count(*) from wx_merchant m
  106. where b.id = m.business_id
  107. <if test=" null != tenantId and '' != tenantId">
  108. and m.`tenant_id` = #{tenantId}
  109. </if>
  110. <if test=" null != parentTenantId and '' != parentTenantId">
  111. and m.`parent_tenant_id` = #{parentTenantId}
  112. </if>
  113. and m.status = 1
  114. and m.is_public = 1) > 0
  115. order by create_date asc
  116. </select>
  117. <select id="findListForCoupon" resultMap="BaseResultMap">
  118. select
  119. <include refid="allColumns"/>
  120. from wx_business b
  121. where b.`final_tenant_id` = #{finalTenantId}
  122. <if test=" 1 == isRoot">
  123. and b.`parent_id` is null
  124. </if>
  125. <if test=" null != isDel ">
  126. and b.`is_del` = #{isDel}
  127. </if>
  128. <if test=" null != businessForRule and '' != businessForRule ">
  129. and `id` in (${businessForRule})
  130. </if>
  131. and
  132. (select count(*) from wx_coupon_channel cc
  133. where b.id = cc.business
  134. and cc.status = 0
  135. <if test=" null != tenantId and '' != tenantId">
  136. and cc.`tenant_id` = #{tenantId}
  137. </if>
  138. <if test=" null != parentTenantId and '' != parentTenantId">
  139. and cc.`parent_tenant_id` = #{parentTenantId}
  140. </if>
  141. <if test=" null != platCode and platCode == 1">
  142. and cc.target_ad = 1
  143. </if>
  144. <if test=" null != platCode and platCode == 3">
  145. and cc.target_ad = 101
  146. </if>
  147. ) > 0
  148. order by create_date asc
  149. </select>
  150. <select id="businessDataList" parameterType="com.iformall.domain.po.WxBusiness" resultType="hashmap">
  151. select b.id,b.title,
  152. round(
  153. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  154. from wx_merchant m
  155. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id where m.business_id = b.id
  156. <if test=" null != tenantId and '' != tenantId">
  157. and m.`tenant_id` = #{tenantId}
  158. </if>
  159. <if test=" null != parentTenantId and '' != parentTenantId">
  160. and m.`parent_tenant_id` = #{parentTenantId}
  161. </if>
  162. and STR_TO_DATE(mtd.report_date,'%Y-%m-%d') between #{startdate} and #{enddate} and m.status = 1 and m.is_del = 0 )
  163. /100,2) volume,
  164. round(
  165. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  166. from wx_merchant m
  167. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id where m.business_id = b.id
  168. <if test=" null != tenantId and '' != tenantId">
  169. and m.`tenant_id` = #{tenantId}
  170. </if>
  171. <if test=" null != parentTenantId and '' != parentTenantId">
  172. and m.`parent_tenant_id` = #{parentTenantId}
  173. </if>
  174. and STR_TO_DATE(mtd.report_date,'%Y-%m-%d') between #{startdate} and #{enddate} and m.status = 1 and m.is_del = 0 )
  175. /
  176. (select if(sum(ws.operation_area) is null,0,sum(ws.operation_area))
  177. from wx_merchant m
  178. left join wx_merchant_shop mtd on mtd.merchant_id = m.id
  179. left join wx_shop ws on(mtd.shop_id = ws.id)
  180. where m.business_id = b.id and m.status = 1 and m.is_del = 0
  181. <if test=" null != tenantId and '' != tenantId">
  182. and m.`tenant_id` = #{tenantId}
  183. </if>
  184. <if test=" null != parentTenantId and '' != parentTenantId">
  185. and m.`parent_tenant_id` = #{parentTenantId}
  186. </if>
  187. )
  188. /100,2) sale,
  189. (select ifnull(sum(rent_area),0) from wx_rent_contract where business_id=b.id
  190. <if test=" null != tenantId and '' != tenantId">
  191. and `tenant_id` = #{tenantId}
  192. </if>
  193. <if test=" null != parentTenantId and '' != parentTenantId">
  194. and `parent_tenant_id` = #{parentTenantId}
  195. </if>
  196. and status in (2,3,4)) area,
  197. round(
  198. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  199. from wx_merchant m
  200. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id where m.business_id = b.id
  201. <if test=" null != tenantId and '' != tenantId">
  202. and m.`tenant_id` = #{tenantId}
  203. </if>
  204. <if test=" null != parentTenantId and '' != parentTenantId">
  205. and m.`parent_tenant_id` = #{parentTenantId}
  206. </if>
  207. and STR_TO_DATE(mtd.report_date,'%Y-%m-%d') between #{startdate} and #{enddate} and m.status = 1 and m.is_del = 0 ) /
  208. (select sum(mtd.trade_count)
  209. from wx_merchant m
  210. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id where m.business_id = b.id
  211. <if test=" null != tenantId and '' != tenantId">
  212. and m.`tenant_id` = #{tenantId}
  213. </if>
  214. <if test=" null != parentTenantId and '' != parentTenantId">
  215. and m.`parent_tenant_id` = #{parentTenantId}
  216. </if>
  217. and STR_TO_DATE(mtd.report_date,'%Y-%m-%d') between #{startdate} and #{enddate} and m.status = 1 and m.is_del = 0 )
  218. /100,2) comPrice
  219. from wx_business b
  220. </select>
  221. <select id="devoteList" parameterType="com.iformall.domain.po.WxBusiness" resultType="hashmap">
  222. select mm.name merchantName,
  223. round(
  224. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  225. from wx_merchant m
  226. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id
  227. where m.business_id = #{id}
  228. <if test=" null != tenantId and '' != tenantId">
  229. and m.`tenant_id` = #{tenantId}
  230. </if>
  231. <if test=" null != parentTenantId and '' != parentTenantId">
  232. and m.`parent_tenant_id` = #{parentTenantId}
  233. </if>
  234. and mtd.report_date between #{startdate} and #{enddate}
  235. and m.status = 1 and m.is_del = 0 and m.id = mm.id)
  236. /
  237. (select if(sum(ws.operation_area) is null,0,sum(ws.operation_area))
  238. from wx_merchant m
  239. left join wx_merchant_shop mtd on mtd.merchant_id = m.id
  240. left join wx_shop ws on(mtd.shop_id = ws.id)
  241. where m.status = 1 and m.is_del = 0 and m.business_id = #{id}
  242. <if test=" null != tenantId and '' != tenantId">
  243. and m.`tenant_id` = #{tenantId}
  244. </if>
  245. <if test=" null != parentTenantId and '' != parentTenantId">
  246. and m.`parent_tenant_id` = #{parentTenantId}
  247. </if>
  248. and m.id = mm.id)
  249. /100,2) sale,
  250. round(
  251. round(
  252. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  253. from wx_merchant m
  254. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id
  255. where m.business_id = #{id}
  256. <if test=" null != tenantId and '' != tenantId">
  257. and m.`tenant_id` = #{tenantId}
  258. </if>
  259. <if test=" null != parentTenantId and '' != parentTenantId">
  260. and m.`parent_tenant_id` = #{parentTenantId}
  261. </if>
  262. and mtd.report_date between #{startdate} and #{enddate}
  263. and m.status = 1 and m.is_del = 0 and m.id = mm.id)/
  264. (select if(sum(ws.operation_area) is null,0,sum(ws.operation_area))
  265. from wx_merchant m
  266. left join wx_merchant_shop mtd on mtd.merchant_id = m.id
  267. left join wx_shop ws on(mtd.shop_id = ws.id)
  268. where m.status = 1 and m.is_del = 0 and m.business_id = #{id}
  269. <if test=" null != tenantId and '' != tenantId">
  270. and m.`tenant_id` = #{tenantId}
  271. </if>
  272. <if test=" null != parentTenantId and '' != parentTenantId">
  273. and m.`parent_tenant_id` = #{parentTenantId}
  274. </if>
  275. and m.id = mm.id)/100,2)
  276. /
  277. round(
  278. (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))
  279. from wx_merchant m
  280. left join wx_merchant_trade_daily mtd on mtd.merchant_id = m.id
  281. where m.business_id = #{id}
  282. <if test=" null != tenantId and '' != tenantId">
  283. and m.`tenant_id` = #{tenantId}
  284. </if>
  285. <if test=" null != parentTenantId and '' != parentTenantId">
  286. and m.`parent_tenant_id` = #{parentTenantId}
  287. </if>
  288. and mtd.report_date between #{startdate} and #{enddate}
  289. and m.status = 1 and m.is_del = 0 )
  290. /
  291. (select if(sum(ws.operation_area) is null,0,sum(ws.operation_area))
  292. from wx_merchant m
  293. left join wx_merchant_shop mtd on mtd.merchant_id = m.id
  294. left join wx_shop ws on(mtd.shop_id = ws.id)
  295. where m.business_id = #{id}
  296. <if test=" null != tenantId and '' != tenantId">
  297. and m.`tenant_id` = #{tenantId}
  298. </if>
  299. <if test=" null != parentTenantId and '' != parentTenantId">
  300. and m.`parent_tenant_id` = #{parentTenantId}
  301. </if>
  302. and m.status = 1 and m.is_del = 0 )
  303. /100,2)
  304. *100,2) devoteRate
  305. from wx_merchant mm
  306. left join wx_merchant_trade_daily mtd on mtd.merchant_id = mm.id
  307. left join wx_merchant_shop wmt on wmt.merchant_id = mm.id
  308. left join wx_shop ws on(wmt.shop_id = ws.id)
  309. where mm.business_id=#{id}
  310. <if test=" null != tenantId and '' != tenantId">
  311. and mm.`tenant_id` = #{tenantId}
  312. </if>
  313. <if test=" null != parentTenantId and '' != parentTenantId">
  314. and mm.`parent_tenant_id` = #{parentTenantId}
  315. </if>
  316. and mm.status = 1 and mm.is_del = 0
  317. and mtd.report_date between #{startdate} and #{enddate}
  318. group by mm.id
  319. order by devoteRate desc
  320. <if test="null != limitStart and null != limitEnd">
  321. limit #{limitStart},#{limitEnd}
  322. </if>
  323. </select>
  324. <insert id="insertWithId" parameterType="com.iformall.domain.po.WxBusiness" >
  325. INSERT INTO wx_business (
  326. `id`,`title`,`type`,`create_date`,`update_date`,`final_tenant_id`,`is_system`
  327. )
  328. VALUES(
  329. #{id},#{title},#{type},#{createDate},#{updateDate},#{finalTenantId},#{isSystem}
  330. );
  331. </insert>
  332. </mapper>