banner.sql.xml 18 KB

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