AdSpecialMapper.xml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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.ylcm.sys.mapper.AdSpecialMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.ylcm.sys.domain.AdSpecial">
  6. <id column="id" property="id" />
  7. <result column="type" property="type" />
  8. <result column="product_name" property="productName" />
  9. <result column="brand_name" property="brandName" />
  10. <result column="adv_master" property="advMaster" />
  11. <result column="media_name" property="mediaName" />
  12. <result column="show_env" property="showEnv" />
  13. <result column="tv_name" property="tvName" />
  14. <result column="show_time" property="showTime" />
  15. <result column="show_date" property="showDate" />
  16. <result column="show_duration" property="showDuration" />
  17. <result column="price" property="price" />
  18. <result column="phone" property="phone" />
  19. <result column="status" property="status" />
  20. <result column="crt_time" property="crtTime" />
  21. <result column="upd_time" property="updTime" />
  22. </resultMap>
  23. <!-- 通用查询结果列 -->
  24. <sql id="Base_Column_List">
  25. id, type, product_name, brand_name, adv_master, media_name, show_env, tv_name, show_time, show_date, show_duration, price, phone, status, crt_time, upd_time
  26. </sql>
  27. <!-- 专题基本字段 -->
  28. <sql id="Page_Column_List">
  29. a.id, a.type, a.product_name, a.brand_name, a.adv_master, a.media_name, a.show_env, a.tv_name, a.show_time, a.show_date, a.show_duration, a.price, a.phone,
  30. b.first_ind, b.second_ind
  31. </sql>
  32. <sql id="WHERE_GET_PAGE">
  33. <trim prefix="where" prefixOverrides="and|or">
  34. a.status = 0 AND b.status = 0
  35. <if test="queryBean.type != null">
  36. AND a.type= #{queryBean.type}
  37. </if>
  38. <if test="queryBean.keyword != null and queryBean.keyword !='' ">
  39. AND (position(#{queryBean.keyword} in COALESCE(a.product_name,'')) > 0 OR position(#{queryBean.keyword} in COALESCE(a.brand_name,'')) > 0
  40. OR position(#{queryBean.keyword} in COALESCE(a.adv_master,'')) > 0 OR position(#{queryBean.keyword} in COALESCE(a.tv_name,'')) > 0)
  41. </if>
  42. <if test="queryBean.mediaName != null and queryBean.mediaName != ''">
  43. AND a.media_name= #{queryBean.mediaName}
  44. </if>
  45. <if test="queryBean.showEnv != null">
  46. AND a.show_env= #{queryBean.showEnv}
  47. </if>
  48. <if test="queryBean.firstInd != null and queryBean.firstInd != ''">
  49. AND b.first_ind= #{queryBean.firstInd}
  50. </if>
  51. <if test="queryBean.secondInd != null and queryBean.secondInd != ''">
  52. AND b.second_ind= #{queryBean.secondInd}
  53. </if>
  54. <if test="queryBean.startDate != null and queryBean.startDate != ''">
  55. <![CDATA[ AND a.show_date >= #{queryBean.startDate}]]>
  56. </if>
  57. <if test="queryBean.endDate != null and queryBean.endDate != ''">
  58. <![CDATA[ AND a.show_date <= #{queryBean.endDate}]]>
  59. </if>
  60. </trim>
  61. </sql>
  62. <select id="getPage" resultType="com.ylcm.sys.vo.AdSpecialAnalysisVO">
  63. SELECT
  64. <include refid ="Page_Column_List"/>
  65. FROM ad_special a
  66. <if test="queryBean.type != null and queryBean.type == 0">
  67. JOIN ad_product b on a.product_name = b.product_name AND COALESCE(a.brand_name, '') = COALESCE(b.brand_name, '')
  68. </if>
  69. <if test="queryBean.type != null and queryBean.type == 1">
  70. JOIN ad_platform b on a.product_name = b.platform_name AND COALESCE(a.brand_name, '') = COALESCE(b.brand_name, '')
  71. </if>
  72. <include refid ="WHERE_GET_PAGE"/>
  73. ORDER BY a.id DESC
  74. </select>
  75. <select id="getALLPage" resultType="com.ylcm.sys.vo.AdSpecialAnalysisVO">
  76. SELECT a.* FROM
  77. (
  78. SELECT <include refid ="Page_Column_List"/>
  79. FROM ad_special a
  80. JOIN ad_product b on a.product_name = b.product_name AND COALESCE(a.brand_name, '') = COALESCE(b.brand_name, '')
  81. <include refid ="WHERE_GET_PAGE"/>
  82. UNION ALL
  83. SELECT <include refid ="Page_Column_List"/>
  84. FROM ad_special a
  85. JOIN ad_platform b on a.product_name = b.platform_name AND COALESCE(a.brand_name, '') = COALESCE(b.brand_name, '')
  86. <include refid ="WHERE_GET_PAGE"/>
  87. ) a ORDER BY a.id DESC
  88. </select>
  89. <select id="specialTop" resultType="com.ylcm.sys.vo.AdSpecialTopVO">
  90. SELECT
  91. a.product_name as productName, b.second_ind as secondInd, sum(a.show_duration) duration, SUM(1) frequency
  92. FROM
  93. ad_special a
  94. <if test="type == 0">
  95. JOIN ad_product b on a.product_name = b.product_name AND COALESCE(a.brand_name, '') = COALESCE(b.brand_name, '')
  96. </if>
  97. <if test="type == 1">
  98. JOIN ad_platform b on a.product_name = b.platform_name AND COALESCE(a.brand_name, '') = COALESCE(b.brand_name, '')
  99. </if>
  100. <where>
  101. a.status = 0 AND b.status = 0
  102. <if test="type != null">
  103. AND a.type = #{type}
  104. </if>
  105. <if test="startDate != null and startDate != ''">
  106. AND a.show_date >= #{startDate}
  107. </if>
  108. <if test="endDate != null and endDate != ''">
  109. AND #{endDate} >= a.show_date
  110. </if>
  111. </where>
  112. GROUP BY a.product_name,b.second_ind
  113. ORDER BY sum(a.show_duration) DESC LIMIT 30
  114. </select>
  115. <select id="mediaDist" resultType="com.ylcm.sys.vo.AdSpecialDistVO">
  116. SELECT media_name name,SUM(1) total, SUM(show_duration) duration
  117. FROM ad_special
  118. <where>
  119. status = 0
  120. <if test="type != null">
  121. AND type = #{type}
  122. </if>
  123. <if test="startDate != null and startDate != ''">
  124. AND show_date >= #{startDate}
  125. </if>
  126. <if test="endDate != null and endDate != ''">
  127. AND #{endDate} >= show_date
  128. </if>
  129. <if test="productName != null and productName != ''">
  130. AND product_name = #{productName}
  131. </if>
  132. </where>
  133. GROUP BY media_name
  134. </select>
  135. <select id="tvDist" resultType="com.ylcm.sys.vo.AdSpecialDistVO">
  136. SELECT tv_name name,SUM(1) total, SUM(show_duration) duration
  137. FROM ad_special
  138. <where>
  139. status = 0 and show_env = 1
  140. <if test="type != null">
  141. AND type = #{type}
  142. </if>
  143. <if test="startDate != null and startDate != ''">
  144. AND show_date >= #{startDate}
  145. </if>
  146. <if test="endDate != null and endDate != ''">
  147. AND #{endDate} >= show_date
  148. </if>
  149. <if test="productName != null and productName != ''">
  150. AND product_name = #{productName}
  151. </if>
  152. </where>
  153. GROUP BY tv_name
  154. </select>
  155. <select id="secondIndDist" resultType="com.ylcm.sys.vo.AdSpecialDistVO">
  156. SELECT
  157. a.product_name name,
  158. SUM(1) total, SUM(a.show_duration) duration
  159. FROM ad_special a
  160. <if test="type == 0">
  161. JOIN ad_product b on a.product_name = b.product_name AND COALESCE(a.brand_name, '') = COALESCE(b.brand_name, '')
  162. </if>
  163. <if test="type == 1">
  164. JOIN ad_platform b on a.product_name = b.platform_name AND COALESCE(a.brand_name, '') = COALESCE(b.brand_name, '')
  165. </if>
  166. <where>
  167. a.status = 0
  168. <if test="type != null">
  169. AND a.type = #{type} AND b.status = 0
  170. </if>
  171. <if test="startDate != null and startDate != ''">
  172. AND a.show_date >= #{startDate}
  173. </if>
  174. <if test="endDate != null and endDate != ''">
  175. AND #{endDate} >= a.show_date
  176. </if>
  177. <if test="type != null and secondInd != null and secondInd != ''">
  178. AND b.second_ind = #{secondInd}
  179. </if>
  180. </where>
  181. GROUP BY a.product_name
  182. <if test="launch != null and launch == 0">
  183. ORDER BY SUM(1) DESC
  184. </if>
  185. <if test="launch != null and launch == 1">
  186. ORDER BY SUM(a.show_duration) DESC
  187. </if>
  188. </select>
  189. <select id="benchmarkingPage" resultType="com.ylcm.sys.vo.AdSpecialAnalysisBenchmarkingVO">
  190. SELECT a.id , a.product_name as productName
  191. <if test="queryBean.type == 0">
  192. ,b.name_img_url as imgUrl
  193. </if>
  194. <if test="queryBean.type == 1">
  195. ,b.img_url as imgUrl
  196. </if>
  197. FROM ad_special a
  198. <if test="queryBean.type == 0">
  199. LEFT JOIN ad_product b on a.product_name = b.product_name
  200. </if>
  201. <if test="queryBean.type == 1">
  202. LEFT JOIN ad_platform b on a.product_name = b.platform_name
  203. </if>
  204. <where>
  205. a.status = 0
  206. <if test="queryBean.type != null">
  207. AND a.type = #{queryBean.type} AND b.status = 0
  208. </if>
  209. <if test="queryBean.productName != null and queryBean.productName !='' ">
  210. AND a.product_name LIKE CONCAT('%',#{queryBean.productName},'%')
  211. </if>
  212. <if test="queryBean.idList != null and queryBean.idList.size() > 0">
  213. <foreach collection="queryBean.idList" item="id" open="AND a.id in (" separator="," close=")" >
  214. #{id}
  215. </foreach>
  216. </if>
  217. <if test="queryBean.productNameList != null and queryBean.productNameList.size() > 0">
  218. <foreach collection="queryBean.productNameList" item="productNameList" open="AND a.product_name not in (" separator="," close=")" >
  219. #{productNameList}
  220. </foreach>
  221. </if>
  222. </where>
  223. GROUP BY a.product_name
  224. ORDER BY a.crt_time DESC
  225. </select>
  226. <!-- 同步专题栏目/产品信息 -->
  227. <update id="upSyscAdSpecialProductName">
  228. UPDATE ad_special SET product_name = #{productName}, brand_name = #{brandName},upd_time = now()
  229. WHERE status = 0 AND type= #{type} AND product_name = #{oldProductName}
  230. <choose>
  231. <when test="oldBrandName != null and oldBrandName !='' ">
  232. AND brand_name = #{oldBrandName}
  233. </when>
  234. <otherwise>
  235. AND (brand_name is null OR brand_name = '')
  236. </otherwise>
  237. </choose>
  238. </update>
  239. </mapper>