banner.sql.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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="bannerSqlMapper">
  4. <sql id="base_column_advertiser">
  5. id,
  6. banner_template_id as bannerTemplateId,
  7. order_id as orderId,
  8. campaign_id as campaignId,
  9. adgroup_id as adGroupId,
  10. visit_address as visitAddress,
  11. click_address as clickAddress,
  12. impression_address as impressionAddress
  13. status,
  14. checked,
  15. updated,
  16. supdated
  17. </sql>
  18. <sql id="base_column_operator">
  19. b.id as bannerId,
  20. banner_template_id as bannerTemplateId,
  21. order_id as orderId,
  22. campaign_id as campaignId,
  23. adgroup_id as adGroupId,
  24. visit_address as visitAddress,
  25. click_address as clickAddress,
  26. impression_address as impressionAddress,
  27. b.checked as checked,
  28. IFNULL(bo.checked,-1) as operatorChecked,
  29. b.updated as updated,
  30. memo
  31. </sql>
  32. <sql id="banner_template_base_column">
  33. bt.id as banner_templateId,
  34. advertiser_id as advertiserId,
  35. name,
  36. path,
  37. path_small as pathSmall,
  38. type,
  39. width,
  40. height,
  41. bt.status as status,
  42. bt.updated as bannerTemplateUpdated
  43. </sql>
  44. <delete id="deleteBanner" parameterType="HashMap">
  45. delete from t_banner where
  46. id in
  47. <foreach item="id" collection="idList" open="(" separator=","
  48. close=")">
  49. #{id}
  50. </foreach>
  51. </delete>
  52. <update id="updateBannerStatus" parameterType="HashMap">
  53. update t_banner
  54. set status=#{status},updated = #{updated},supdated = #{supdated}
  55. where id in
  56. <foreach item="id" collection="idList" open="(" separator=","
  57. close=")">
  58. #{id}
  59. </foreach>
  60. </update>
  61. <select id="countByParams" parameterType="map" resultType="int">
  62. select count(a.id) from t_banner a ,t_banner_template b
  63. <where>
  64. a.banner_template_id = b.id and a.adgroup_id=#{adGroupId}
  65. <if test="value !=null">
  66. and name like #{value}
  67. </if>
  68. </where>
  69. and a.status != -1
  70. </select>
  71. <select id="countByAdGroupId" parameterType="long" resultType="int">
  72. select count(id) from t_banner
  73. where adgroup_id = #{adGroupId}
  74. </select>
  75. <select id="findById1" parameterType="long" resultType="com.cloudcross.ssp.model.Banner">
  76. select
  77. <include refid="base_column"/>
  78. from t_banner
  79. <where>
  80. adgroup_id = #{adGroupId}
  81. </where>
  82. </select>
  83. <select id="findById" parameterType="long" resultMap="Banner">
  84. select a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,
  85. a.click_address as clickAddress,a.impression_address as impressionAddress,a.status as status1,a.checked as checked,a.updated as updated, b.id as bannerTemplateId,b.agent_id as agentId,b.advertiser_id as advertiserId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id
  86. <where>
  87. a.id=#{id}
  88. </where>
  89. </select>
  90. <select id="findById" parameterType="int" resultMap="banner">
  91. select <include refid="base_column"/> ,<include refid="banner_template_base_column"/>
  92. from t_banner b inner join t_banner_template bt on b.banner_template_id = bt.id left join t_banner_operator bo
  93. on b.id=bo.banner_id where b.id=#{id}
  94. </select>
  95. <select id="findByParams" parameterType="map" resultMap="Banner">
  96. select a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,
  97. a.click_address as clickAddress,a.impression_address as impressionAddress,a.status as status1,a.checked as checked,a.updated as updated,a.supdated as supdated,b.id as bannerTemplateId,b.agent_id as agentId,b.advertiser_id as advertiserId,b.agent_id as agentId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id
  98. <where>
  99. a.adgroup_id=#{adGroupId}
  100. <if test="value !=null">
  101. and name like #{value}
  102. </if>
  103. </where>
  104. and a.status != -1
  105. order by a.id desc
  106. limit #{pager.offset}, #{pager.limit}
  107. </select>
  108. <select id="countByZoneSize" parameterType="HashMap" resultType="int">
  109. select count(*) from t_banner b inner join t_banner_template bt on b.banner_template_id = bt.id
  110. where bt.status != -1 and checked != 2 and checked !=0
  111. <if test="zoneList.size()>0">
  112. and
  113. <foreach item="zone" collection="zoneList"
  114. open="(" separator="or" close=")" >
  115. bt.width &lt;= #{zone.width} and bt.height &lt;= #{zone.height}
  116. </foreach>
  117. </if>
  118. <if test="searchKey!=null and searchValue!=null">
  119. and bt.name like #{searchValue}
  120. </if>
  121. <if test="checked!=null">
  122. and b.checked like #{checked}
  123. </if>
  124. </select>
  125. <select id="findByZoneSize" parameterType="HashMap" resultMap="banner">
  126. select <include refid="base_column_operator"/> ,<include refid="banner_template_base_column"/>
  127. from t_banner b inner join t_banner_template bt on b.banner_template_id = bt.id
  128. where bt.status != -1 and checked != 2 and checked !=0
  129. <if test="zoneList.size()>0">
  130. and
  131. <foreach item="zone" collection="zoneList"
  132. open="(" separator="or" close=")" >
  133. bt.width &lt;= #{zone.width} and bt.height &lt;= #{zone.height}
  134. </foreach>
  135. </if>
  136. <if test="searchKey!=null and searchValue!=null">
  137. and bt.name like #{searchValue}
  138. </if>
  139. <if test="checked!=null">
  140. and b.checked like #{checked}
  141. </if>
  142. order by b.id desc
  143. <if test="pager!=null">
  144. limit #{pager.offset}, #{pager.limit}
  145. </if>
  146. </select>
  147. <resultMap type="com.cloudcross.ssp.model.Banner" id="Banner">
  148. <id property="id" column="id"/>
  149. <result property="bannerTemplateId" column="bannerTemplateId"/>
  150. <result property="status" column="status1"/>
  151. <result property="orderId" column="orderId"/>
  152. <result property="campaignId" column="campaignId"/>
  153. <result property="adGroupId" column="adGroupId"/>
  154. <result property="visitAddress" column="visitAddress"/>
  155. <result property="clickAddress" column="clickAddress"/>
  156. <result property="impressionAddress" column="impressionAddress"/>
  157. <result property="checked" column="checked"/>
  158. <result property="updated" column="updated"/>
  159. <result property="supdated" column="supdated"/>
  160. <association property="bannerTemplate" javaType="com.cloudcross.ssp.model.BannerTemplate" resultMap="bannerTemplate"/>
  161. </resultMap>
  162. <resultMap type="com.cloudcross.ssp.model.BannerTemplate" id="bannerTemplate">
  163. <id property="id" column="bannerTemplateId"/>
  164. <result property="advertiserId" column="advertiserId"/>
  165. <result property="agentId" column="agentId"/>
  166. <result property="name" column="name"/>
  167. <result property="path" column="path"/>
  168. <result property="pathSmall" column="pathSmall"/>
  169. <result property="type" column="type"/>
  170. <result property="width" column="width"/>
  171. <result property="height" column="height"/>
  172. <result property="status" column="status"/>
  173. <result property="updated" column="updated"/>
  174. </resultMap>
  175. <resultMap type="com.cloudcross.ssp.model.Banner" id="banneroperator">
  176. <id property="id" column="bannerId"/>
  177. <result property="bannerTemplateId" column="bannerTemplateId"/>
  178. <result property="orderId" column="orderId"/>
  179. <result property="campaignId" column="campaignId"/>
  180. <result property="adGroupId" column="adgroupId"/>
  181. <result property="visitAddress" column="visitAddress"/>
  182. <result property="clickAddress" column="clickAddress"/>
  183. <result property="impressionAddress" column="impressionAddress"/>
  184. <result property="checked" column="checked"/>
  185. <result property="operatorChecked" column="operatorChecked"/>
  186. <result property="updated" column="updated"/>
  187. <result property="memo" column="memo"/>
  188. <association property="bannerTemplate" resultMap="com.cloudcross.ssp.model.BannerTemplate"/>
  189. </resultMap>
  190. <resultMap type="com.cloudcross.ssp.operator.model.BannerTemplate" id="bannerTemplate">
  191. <id property="id" column="banner_templateId"/>
  192. <result property="advertiserId" column="advertiserId"/>
  193. <result property="name" column="name"/>
  194. <result property="path" column="path"/>
  195. <result property="pathSmall" column="pathSmall"/>
  196. <result property="type" column="type"/>
  197. <result property="width" column="width"/>
  198. <result property="height" column="height"/>
  199. <result property="status" column="status"/>
  200. <result property="updated" column="bannerTemplateUpdated"/>
  201. </resultMap>
  202. <insert id="addBanner" parameterType="com.cloudcross.ssp.model.Banner" useGeneratedKeys="true"
  203. keyProperty="id">
  204. insert into
  205. t_banner(banner_template_id,order_id,campaign_id,adgroup_id,visit_address,click_address,impression_address,checked,memo,updated,supdated
  206. )
  207. values (
  208. #{bannerTemplateId},#{orderId},#{campaignId},#{adGroupId},#{visitAddress},#{clickAddress},#{impressionAddress},#{checked},#{memo},#{updated},#{supdated}
  209. )
  210. </insert>
  211. <update id="editBanner" parameterType="com.cloudcross.ssp.model.Banner">
  212. update t_banner a,t_banner_template b
  213. set b.name = #{bannerTemplate.name},
  214. b.updated = #{bannerTemplate.updated},
  215. a.visit_address = #{visitAddress},
  216. a.click_address = #{clickAddress},
  217. a.impression_address = #{impressionAddress},
  218. a.checked = 0,
  219. a.updated = #{updated},
  220. a.supdated = #{supdated}
  221. WHERE b.id = a.banner_template_id and a.id = #{id}
  222. </update>
  223. <update id="updataBanner" parameterType="com.cloudcross.ssp.model.Banner">
  224. update t_banner a,t_banner_template b
  225. set a.banner_template_id = #{bannerTemplateId},
  226. b.name = #{bannerTemplate.name},
  227. b.updated = #{bannerTemplate.updated},
  228. a.visit_address = #{visitAddress},
  229. a.click_address = #{clickAddress},
  230. a.impression_address = #{impressionAddress},
  231. a.checked = 0,
  232. a.updated = #{updated},
  233. a.supdated = #{supdated}
  234. WHERE b.id = #{bannerTemplate.id} and a.id = #{id}
  235. </update>
  236. <update id="updataOperatorBanner" parameterType="HashMap">
  237. update t_banner_operator
  238. set checked = 0,supdated = #{supdated}
  239. WHERE banner_id in
  240. <foreach item="id" collection="idList" open="(" separator=","
  241. close=")">
  242. #{id}
  243. </foreach>
  244. </update>
  245. <!-- 根据adgroupId修改banner的supdated -->
  246. <update id="updateBannerSupdated" parameterType="HashMap">
  247. update t_banner
  248. set t_banner.supdated= #{modifyDate}
  249. where t_banner.adgroup_id in
  250. <foreach item="adgroupId" collection="adGroupIdList"
  251. open="(" separator="," close=")">
  252. #{adgroupId}
  253. </foreach>
  254. </update>
  255. <!-- 根据orderId修改banner的supdated -->
  256. <update id="updateBannerSupdatedByOrderId" parameterType="HashMap">
  257. update t_banner
  258. set t_banner.supdated=#{modifyDate}
  259. where t_banner.order_id in
  260. <foreach item="orderId" collection="orderIdList"
  261. open="(" separator="," close=")">
  262. #{orderId}
  263. </foreach>
  264. </update>
  265. <!-- 根据campaignid修改banner的supdated -->
  266. <update id="updateBannerSupdatedByCampaignId" parameterType="HashMap">
  267. update t_banner
  268. set t_banner.supdated=#{modifyDate}
  269. where t_banner.campaign_id in
  270. <foreach item="campaignId" collection="campaignIdList"
  271. open="(" separator="," close=")">
  272. #{campaignId}
  273. </foreach>
  274. </update>
  275. <update id="updateStatusByOrderId" parameterType="HashMap">
  276. update t_banner a,t_banner_template b
  277. set b.status=#{status},b.updated = #{modifyDate},a.updated = #{modifyDate}
  278. where
  279. a.banner_template_id = b.id and
  280. a.order_id in
  281. <foreach item="orderId" collection="orderIdList" open="(" separator="," close=")">
  282. #{orderId}
  283. </foreach>
  284. </update>
  285. <update id="updateStatusByCampaignId" parameterType="HashMap">
  286. update t_banner a,t_banner_template b
  287. set b.status=#{status},b.updated = #{modifyDate},a.updated = #{modifyDate}
  288. where
  289. a.banner_template_id = b.id and
  290. a.campaign_id in
  291. <foreach item="campaignId" collection="campaignIdList" open="(" separator="," close=")">
  292. #{campaignId}
  293. </foreach>
  294. </update>
  295. <update id="updateStatusByAdGroupId" parameterType="HashMap">
  296. update t_banner a,t_banner_template b
  297. set b.status=#{status},b.updated = #{modifyDate},a.updated = #{modifyDate}
  298. where
  299. a.banner_template_id = b.id and
  300. a.adgroup_id in
  301. <foreach item="adGroupId" collection="adGroupIdList" open="(" separator="," close=")">
  302. #{adGroupId}
  303. </foreach>
  304. </update>
  305. <select id="countByParams1" parameterType="map" resultType="int">
  306. select count(a.id)
  307. from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id
  308. <where>
  309. a.status != -1 and b.status != -1
  310. <if test="orderMark == null">
  311. and a.order_id = #{orderId}
  312. </if>
  313. <if test="campaignMark == null">
  314. and a.campaign_id = #{campaignId}
  315. </if>
  316. <if test="adGroupMark == null">
  317. and a.adgroup_id = #{adGroupId}
  318. </if>
  319. <if test="status!=null">
  320. and a.status = #{status} and b.status = #{status}
  321. </if>
  322. <if test="bannerTemplateName != null">
  323. and b.name like #{bannerTemplateName}
  324. </if>
  325. <if test="agentId!=null">
  326. and b.agent_id = #{agentId}
  327. </if>
  328. <if test="agentId == null">
  329. and b.advertiser_id = #{advertiserId}
  330. </if>
  331. </where>
  332. </select>
  333. <select id="findByParams1" parameterType="map" resultMap="Banner">
  334. select a.status as status1,a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,
  335. a.click_address as clickAddress,a.impression_address as impressionAddress, a.checked as checked,a.updated as updated,b.id as bannerTemplateId,b.agent_id as agentId,b.advertiser_id as advertiserId,b.agent_id as agentId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id
  336. <where>
  337. a.status != -1 and b.status != -1
  338. <if test="orderMark == null">
  339. and a.order_id = #{orderId}
  340. </if>
  341. <if test="campaignMark == null">
  342. and a.campaign_id = #{campaignId}
  343. </if>
  344. <if test="adGroupMark == null">
  345. and a.adgroup_id = #{adGroupId}
  346. </if>
  347. <if test="status!=null">
  348. and a.status = #{status} and b.status = #{status}
  349. </if>
  350. <if test="bannerTemplateName != null">
  351. and b.name like #{bannerTemplateName}
  352. </if>
  353. <if test="agentId!=null">
  354. and b.agent_id = #{agentId}
  355. </if>
  356. <if test="agentId == null">
  357. and b.advertiser_id = #{advertiserId}
  358. </if>
  359. </where>
  360. order by a.id desc
  361. limit #{pager.offset}, #{pager.limit}
  362. </select>
  363. <select id="findByParams2" parameterType="map" resultMap="Banner">
  364. select a.status as status1,a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,
  365. a.click_address as clickAddress,a.impression_address as impressionAddress, a.checked as checked,a.updated as updated,b.id as bannerTemplateId,b.agent_id as agentId,b.advertiser_id as advertiserId,b.agent_id as agentId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id
  366. <where>
  367. a.status != -1 and b.status != -1
  368. <if test="orderMark == null">
  369. and a.order_id = #{orderId}
  370. </if>
  371. <if test="campaignMark == null">
  372. and a.campaign_id = #{campaignId}
  373. </if>
  374. <if test="adGroupMark == null">
  375. and a.adgroup_id = #{adGroupId}
  376. </if>
  377. <if test="status!=null">
  378. and a.status = #{status} and b.status = #{status}
  379. </if>
  380. <if test="bannerTemplateName != null">
  381. and b.name like #{bannerTemplateName}
  382. </if>
  383. <if test="agentId!=null">
  384. and b.agent_id = #{agentId}
  385. </if>
  386. <if test="agentId == null">
  387. and b.advertiser_id = #{advertiserId}
  388. </if>
  389. </where>
  390. order by a.id desc
  391. </select>
  392. <update id="updateOperatorBannerTime" parameterType="HashMap">
  393. update t_banner_operator
  394. set supdated = #{supdated}
  395. where banner_id in
  396. <foreach item="id" collection="idList" open="(" separator=","
  397. close=")">
  398. #{id}
  399. </foreach>
  400. </update>
  401. <update id="updateBannerStatus" parameterType="HashMap">
  402. update t_banner
  403. set checked = #{checked},updated = #{updated}
  404. where id in
  405. <foreach item="bannerId" collection="bannerIdList"
  406. open="(" separator="," close=")">
  407. #{bannerId}
  408. </foreach>
  409. </update>
  410. <update id="updateOperatorBanner" parameterType="HashMap">
  411. update t_banner_operator
  412. set operator_id=#{operatorId},checked = #{operatorChecked},supdated = #{supdated}
  413. where banner_id = #{bannerId}
  414. </update>
  415. <select id="countByOperator" parameterType="HashMap" resultType="int">
  416. select count(*) from t_banner b inner join t_banner_template bt on b.banner_template_id = bt.id left join t_banner_operator bo
  417. on b.id=bo.banner_id and bo.operator_id=#{operatorId}
  418. where b.status = 0 and bt.status = 0 and b.checked = 1
  419. <if test="zoneList.size()>0">
  420. and
  421. <foreach item="zone" collection="zoneList"
  422. open="(" separator="or" close=")" >
  423. bt.width &lt;= #{zone.width} and bt.height &lt;= #{zone.height}
  424. </foreach>
  425. </if>
  426. <if test="searchKey!=null and searchValue!=null">
  427. and bt.name like #{searchValue}
  428. </if>
  429. <if test="operatorChecked!=null">
  430. <choose>
  431. <when test="operatorChecked == 0">
  432. and ISNULL(bo.checked) or bo.checked =0
  433. </when>
  434. <otherwise>
  435. and bo.checked=#{operatorChecked}
  436. </otherwise>
  437. </choose>
  438. </if>
  439. </select>
  440. </mapper>