InfoMapper.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.caimei.modules.info.dao.InfoDao">
  4. <sql id="infoColumns">
  5. a.id AS "id",
  6. a.typeId AS "infoType.id",
  7. a.title AS "title",
  8. a.label AS "label",
  9. a.publisher AS "publisher",
  10. a.source AS "source",
  11. a.publishSource,
  12. s.name as "shopName",
  13. a.recommendContent AS "recommendContent",
  14. a.infoContent AS "infoContent",
  15. a.guidanceImage AS "guidanceImage",
  16. a.homePageImage AS "homePageImage",
  17. a.pubdate AS "pubdate",
  18. a.keyword AS "keyword",
  19. a.recommendStatus AS "recommendStatus",
  20. a.enabledStatus AS "enabledStatus",
  21. a.basePraise AS "basePraise",
  22. a.basePv AS "basePv",
  23. a.priorityIndex AS "priorityIndex",
  24. a.auditStatus,
  25. a.onlineStatus,
  26. a.failReason,
  27. c.num AS "realPraise",
  28. c.pv AS "pv",
  29. a.createBy AS "createBy.id",
  30. a.createDate AS "createDate",
  31. a.updateBy AS "updateBy.id",
  32. a.updateDate AS "updateDate",
  33. a.topPosition AS "topPosition",
  34. b.name AS "infoType.name"
  35. </sql>
  36. <sql id="infoJoins">
  37. LEFT JOIN info_type b ON a.typeId=b.id
  38. LEFT JOIN info_praise c ON a.id=c.infoId
  39. left join shop s on a.shopId = s.shopID
  40. </sql>
  41. <select id="get" resultType="Info">
  42. SELECT
  43. <include refid="infoColumns"/>
  44. FROM info a
  45. <include refid="infoJoins"/>
  46. WHERE a.id = #{id}
  47. </select>
  48. <select id="findByProjectId" resultType="Info">
  49. SELECT
  50. <include refid="infoColumns"/>
  51. FROM info a
  52. LEFT JOIN info_type b ON a.typeId=b.id
  53. LEFT JOIN info_praise c ON a.id=c.infoId
  54. LEFT JOIN project_info d ON a.id=d.infoId
  55. WHERE d.projectId = #{param1}
  56. </select>
  57. <select id="findList" resultType="Info">
  58. SELECT
  59. <include refid="infoColumns"/>
  60. FROM info a
  61. <include refid="infoJoins"/>
  62. <where>
  63. <if test="id != null and id != ''">
  64. AND a.id = #{id}
  65. </if>
  66. <if test="null !=infoType">
  67. <if test="infoType.id != null and infoType.id != ''">
  68. AND a.typeId = #{infoType.id}
  69. </if>
  70. </if>
  71. <if test="title != null and title != ''">
  72. AND a.title LIKE concat('%',#{title},'%')
  73. </if>
  74. <if test="label != null and label != ''">
  75. AND concat(',',a.label,',') LIKE concat('%,',#{label},',%')
  76. </if>
  77. <if test="publisher != null and publisher != ''">
  78. AND a.publisher LIKE concat('%',#{publisher},'%')
  79. </if>
  80. <if test="recommendStatus != null and recommendStatus != ''">
  81. AND a.recommendStatus = #{recommendStatus}
  82. </if>
  83. <if test="enabledStatus != null and enabledStatus != ''">
  84. AND a.enabledStatus = #{enabledStatus}
  85. </if>
  86. <if test="topFlag != null and topFlag != ''">
  87. <choose>
  88. <when test='topFlag == "1"'>
  89. and topPosition is not null and topPosition != ''
  90. </when>
  91. <when test='topFlag == "0"'>
  92. and topPosition is null or topPosition = ''
  93. </when>
  94. </choose>
  95. </if>
  96. <if test="topPosition != null and topPosition != ''">
  97. and topPosition = #{topPosition}
  98. </if>
  99. <if test="publishSource == null">
  100. and publishSource = 1
  101. </if>
  102. <if test="publishSource != null">
  103. and publishSource = #{publishSource}
  104. </if>
  105. <if test="auditStatus != null">
  106. and a.auditStatus = #{auditStatus}
  107. </if>
  108. <if test="onlineStatus != null">
  109. and a.onlineStatus = #{onlineStatus}
  110. </if>
  111. <if test="shopName != null and shopName != ''">
  112. AND s.name LIKE concat('%',#{shopName},'%')
  113. </if>
  114. <if test="startPubDate != null and startPubDate != ''">
  115. AND a.pubdate <![CDATA[ >= ]]> #{startPubDate}
  116. </if>
  117. <if test="endPubDate != null and endPubDate != ''">
  118. AND a.pubdate <![CDATA[ <= ]]> #{endPubDate}
  119. </if>
  120. <!-- AND b.enabledStatus='1' -->
  121. </where>
  122. <choose>
  123. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  124. ORDER BY ${page.orderBy}
  125. </when>
  126. <otherwise>
  127. ORDER BY a.pubdate DESC
  128. </otherwise>
  129. </choose>
  130. </select>
  131. <select id="findAllList" resultType="Info">
  132. SELECT
  133. <include refid="infoColumns"/>
  134. FROM info a
  135. <include refid="infoJoins"/>
  136. <where>
  137. </where>
  138. <choose>
  139. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  140. ORDER BY ${page.orderBy}
  141. </when>
  142. <otherwise>
  143. ORDER BY a.updateDate DESC
  144. </otherwise>
  145. </choose>
  146. </select>
  147. <select id="getSensitiveWords" resultType="java.lang.String">
  148. select words
  149. from cm_sensitive_words
  150. where id = 1 and status = 1
  151. <if test="checkPoint != null">
  152. and checkPoints like concat('%',#{checkPoint},'%')
  153. </if>
  154. </select>
  155. <insert id="insert" parameterType="Info" keyProperty="id" useGeneratedKeys="true">
  156. INSERT INTO info(
  157. typeId,
  158. title,
  159. label,
  160. publisher,
  161. source,
  162. recommendContent,
  163. infoContent,
  164. guidanceImage,
  165. homePageImage,
  166. pubdate,
  167. keyword,
  168. recommendStatus,
  169. enabledStatus,
  170. basePraise,
  171. basePv,
  172. createBy,
  173. createDate,
  174. updateBy,
  175. updateDate,
  176. topPosition
  177. ) VALUES (
  178. #{infoType.id},
  179. #{title},
  180. #{label},
  181. #{publisher},
  182. #{source},
  183. #{recommendContent},
  184. #{infoContent},
  185. #{guidanceImage},
  186. #{homePageImage},
  187. #{pubdate},
  188. #{keyword},
  189. #{recommendStatus},
  190. #{enabledStatus},
  191. #{basePraise},
  192. #{basePv},
  193. #{createBy.id},
  194. #{createDate},
  195. #{updateBy.id},
  196. #{updateDate},
  197. #{topPosition}
  198. )
  199. </insert>
  200. <update id="update">
  201. UPDATE info SET
  202. typeId = #{infoType.id},
  203. title = #{title},
  204. label = #{label},
  205. publisher = #{publisher},
  206. source = #{source},
  207. recommendContent = #{recommendContent},
  208. infoContent = #{infoContent},
  209. guidanceImage = #{guidanceImage},
  210. homePageImage = #{homePageImage},
  211. pubdate = #{pubdate},
  212. keyword = #{keyword},
  213. recommendStatus = #{recommendStatus},
  214. enabledStatus = #{enabledStatus},
  215. basePraise = #{basePraise},
  216. basePv = #{basePv},
  217. updateBy = #{updateBy.id},
  218. updateDate = #{updateDate},
  219. <if test="auditFlag != null and auditFlag == 1">
  220. <if test="auditStatus != null">
  221. auditStatus = #{auditStatus},
  222. </if>
  223. <if test="onlineStatus != null">
  224. onlineStatus = #{onlineStatus},
  225. </if>
  226. <if test="failReason != null and failReason != ''">
  227. failReason = #{failReason},
  228. </if>
  229. </if>
  230. topPosition = #{topPosition}
  231. WHERE id = #{id}
  232. </update>
  233. <delete id="delete">
  234. DELETE FROM info
  235. WHERE id = #{id}
  236. </delete>
  237. <delete id="deleteInfoPraise">
  238. DELETE FROM info_praise
  239. WHERE infoId = #{param1}
  240. </delete>
  241. <delete id="deleteByTypeId">
  242. DELETE FROM info
  243. WHERE typeId = #{param1}
  244. </delete>
  245. <delete id="deleteInfoPageByInfoId">
  246. DELETE FROM info_page
  247. WHERE infoId = #{param1}
  248. </delete>
  249. <update id="updateEnabledStatusByIds">
  250. UPDATE info a SET a.enabledStatus = #{param1}
  251. WHERE a.id IN
  252. <foreach collection="param2" item="id" index="index" open="(" separator="," close=")" >
  253. #{id}
  254. </foreach>
  255. </update>
  256. <update id="updateRecommendStatusByIds">
  257. UPDATE info a SET a.recommendStatus = #{param1}
  258. WHERE a.id IN
  259. <foreach collection="param2" item="id" index="index" open="(" separator="," close=")" >
  260. #{id}
  261. </foreach>
  262. </update>
  263. <insert id="insertInfoPraise">
  264. INSERT INTO info_praise VALUES(#{param1},0,0)
  265. </insert>
  266. <insert id="insertInfoPage">
  267. INSERT INTO info_page(infoId,page,infoContent)
  268. <foreach collection="param2" item="infoContent" index="index" separator=" union all ">
  269. SELECT #{param1},#{index}+1,#{infoContent}
  270. </foreach>
  271. </insert>
  272. <update id="updateReplaceByLabel">
  273. UPDATE info a SET a.label=REPLACE(a.label,#{param1},#{param2}) WHERE CONCAT(',',a.label,',') LIKE CONCAT('%,',#{param1},',%')
  274. </update>
  275. <update id="auditInfo">
  276. update info
  277. set auditStatus = #{auditStatus},
  278. failReason = #{failReason}
  279. <if test="pubdate != null">
  280. ,pubdate = #{pubdate}
  281. </if>
  282. where id = #{id}
  283. </update>
  284. <update id="offlineInfo">
  285. update info set onlineStatus = 3 where id = #{id}
  286. </update>
  287. </mapper>