InfoMapper.xml 8.1 KB

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