ArtMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  4. <mapper namespace="com.zhyc.xps.sys.mapper.ArtMapper">
  5. <resultMap id="ArtDtoResultMap" type="com.zhyc.xps.sys.dto.ArtDto">
  6. <result column="oc_id" property="ocId" jdbcType="BIGINT" /><!--OC ID-->
  7. <result column="art_id" property="artId" jdbcType="BIGINT" /><!--ART ID-->
  8. <result column="art_cat_id" property="artCatId" jdbcType="BIGINT" />
  9. <result column="art_author" property="artAuthor" jdbcType="VARCHAR" />
  10. <result column="art_title" property="artTitle" jdbcType="VARCHAR" />
  11. <result column="art_source" property="artSource" jdbcType="VARCHAR" />
  12. <result column="is_fixed" property="isFixed" jdbcType="BIGINT" />
  13. <result column="editor_id" property="editorId" jdbcType="BIGINT" />
  14. <result column="issued_at" property="issuedAt" jdbcType="DATE" />
  15. <result column="status" property="status" jdbcType="BIGINT" />
  16. <result column="art_cat_title" property="artCatTitle" jdbcType="VARCHAR" />
  17. <result column="editor_name" property="editorName" jdbcType="VARCHAR" />
  18. </resultMap>
  19. <resultMap id="ArtDtoDetailResultMap" type="com.zhyc.xps.sys.dto.ArtDetailDto" extends="ArtDtoResultMap">
  20. <result column="art_content" property="artContent" jdbcType="VARCHAR" />
  21. </resultMap>
  22. <sql id="ArtDto_Cols">
  23. A.oc_id,
  24. A.art_id,
  25. A.art_cat_id,
  26. B.art_cat_title,
  27. A.art_title,
  28. A.art_author,
  29. A.art_source,
  30. A.is_fixed,
  31. A.issued_at,
  32. A.editor_id,
  33. C.account_name AS editor_name,
  34. A.status
  35. </sql>
  36. <sql id="ArtDetail_Cols">
  37. A.oc_id,
  38. A.art_id,
  39. A.art_cat_id,
  40. B.art_cat_title,
  41. A.art_title,
  42. A.art_author,
  43. A.art_content,
  44. A.art_source,
  45. A.is_fixed,
  46. A.issued_at,
  47. A.editor_id,
  48. C.account_name AS editor_name,
  49. A.status
  50. </sql>
  51. <!--基于ID查询-->
  52. <select id="getById" resultMap="ArtDtoDetailResultMap">
  53. SELECT
  54. <include refid="ArtDetail_Cols"/>
  55. FROM art AS A
  56. LEFT JOIN art_cat AS B ON (A.oc_id = B.oc_id AND A.art_cat_id = B.art_cat_id)
  57. LEFT JOIN account AS C ON (A.oc_id = C.oc_id AND A.editor_id = C.account_id)
  58. WHERE A.deleted_flag = 0 AND A.oc_id = #{ocId ,jdbcType=BIGINT} AND A.art_id = #{artId ,jdbcType=BIGINT}
  59. </select>
  60. <!--分页查询-->
  61. <select id="getByPage" resultMap="ArtDtoResultMap" parameterType="java.util.Map">
  62. SELECT
  63. <include refid="ArtDto_Cols"/>
  64. FROM art AS A
  65. LEFT JOIN art_cat AS B ON (A.oc_id = B.oc_id AND A.art_cat_id = B.art_cat_id)
  66. LEFT JOIN account AS C ON (A.oc_id = C.oc_id AND A.editor_id = C.account_id)
  67. WHERE A.deleted_flag = 0 AND A.oc_id = #{ocId, jdbcType=BIGINT}
  68. <if test="artCatId != null">
  69. AND A.art_cat_id = #{artCatId, jdbcType=BIGINT}
  70. </if>
  71. <if test="artCatList != null">
  72. AND A.art_cat_id IN
  73. <foreach collection="artCatList" item="artCatId" index="index" open="(" close=")" separator=",">
  74. #{artCatId}
  75. </foreach>
  76. </if>
  77. <if test="keywords != null and keywords != ''">
  78. AND A.art_title like "%"#{keywords}"%"
  79. </if>
  80. <if test="rootId != null">
  81. AND B.root_id = #{rootId ,jdbcType=BIGINT}
  82. </if>
  83. <if test="status != null">
  84. AND A.status = #{status ,jdbcType=BIGINT}
  85. </if>
  86. <if test="editorId != null">
  87. AND A.editor_id = #{editorId ,jdbcType=BIGINT}
  88. </if>
  89. <if test="nodeLeft != null and nodeRight != null">
  90. <![CDATA[
  91. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  92. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  93. ]]>
  94. </if>
  95. ORDER BY A.created_at DESC
  96. </select>
  97. <!--分页查询-->
  98. <select id="getByList" resultMap="ArtDtoResultMap" parameterType="java.util.Map">
  99. SELECT
  100. <include refid="ArtDto_Cols"/>
  101. FROM art AS A
  102. LEFT JOIN art_cat AS B ON (A.oc_id = B.oc_id AND A.art_cat_id = B.art_cat_id)
  103. LEFT JOIN account AS C ON (A.oc_id = C.oc_id AND A.editor_id = C.account_id)
  104. WHERE A.deleted_flag = 0 AND A.oc_id = #{ocId, jdbcType=BIGINT}
  105. <if test="artCatId != null">
  106. AND A.art_cat_id = #{artCatId, jdbcType=BIGINT}
  107. </if>
  108. <if test="artCatList != null">
  109. AND A.art_cat_id IN
  110. <foreach collection="artCatList" item="artCatId" index="index" open="(" close=")" separator=",">
  111. #{artCatId}
  112. </foreach>
  113. </if>
  114. <if test="keywords != null and keywords != ''">
  115. AND A.art_title like "%"#{keywords}"%"
  116. </if>
  117. <if test="rootId != null">
  118. AND B.root_id = #{rootId ,jdbcType=BIGINT}
  119. </if>
  120. <if test="status != null">
  121. AND A.status = #{status ,jdbcType=BIGINT}
  122. </if>
  123. <if test="editorId != null">
  124. AND A.editor_id = #{editorId ,jdbcType=BIGINT}
  125. </if>
  126. <if test="nodeLeft != null and nodeRight != null">
  127. <![CDATA[
  128. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  129. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  130. ]]>
  131. </if>
  132. ORDER BY A.created_at DESC
  133. <if test="limit!=null">
  134. LIMIT 0, #{limit, jdbcType=BIGINT}
  135. </if>
  136. </select>
  137. <!--分页查询-->
  138. <select id="getTopByList" resultMap="ArtDtoResultMap" parameterType="java.util.Map">
  139. SELECT
  140. <include refid="ArtDto_Cols"/>
  141. FROM art AS A
  142. LEFT JOIN art_cat AS B ON (A.oc_id = B.oc_id AND A.art_cat_id = B.art_cat_id)
  143. LEFT JOIN account AS C ON (A.oc_id = C.oc_id AND A.editor_id = C.account_id)
  144. WHERE A.oc_id = #{ocId, jdbcType=BIGINT} AND A.deleted_flag = 0
  145. <if test="artCatId != null">
  146. AND A.art_cat_id = #{artCatId, jdbcType=BIGINT}
  147. </if>
  148. <if test="artCatList != null">
  149. AND A.art_cat_id in #{artCatList, jdbcType=BIGINT}
  150. </if>
  151. <if test="keywords != null and keywords != ''">
  152. AND A.art_title like "%"#{keywords}"%"
  153. </if>
  154. <if test="rootId != null">
  155. AND B.root_id = #{rootId ,jdbcType=BIGINT}
  156. </if>
  157. <if test="status != null">
  158. AND A.status = #{status ,jdbcType=BIGINT}
  159. </if>
  160. <if test="editorId != null">
  161. AND A.editor_id = #{editorId ,jdbcType=BIGINT}
  162. </if>
  163. <if test="nodeLeft != null and nodeRight != null">
  164. <![CDATA[
  165. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  166. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  167. ]]>
  168. </if>
  169. ORDER BY A.created_at DESC
  170. </select>
  171. <!--新增-->
  172. <insert id="create" parameterType="com.zhyc.xps.sys.entity.Art" useGeneratedKeys="true" keyProperty="artId">
  173. INSERT INTO art
  174. <trim prefix="(" suffix=")" suffixOverrides=",">
  175. <if test="ocId != null">
  176. oc_id,
  177. </if>
  178. <if test="artId != null">
  179. art_id,
  180. </if>
  181. <if test="artCatId != null">
  182. art_cat_id,
  183. </if>
  184. <if test="artTitle != null and artTitle!=''">
  185. art_title,
  186. </if>
  187. <if test="artAuthor != null and artAuthor != ''">
  188. art_author,
  189. </if>
  190. <if test="artContent != null and artContent != ''">
  191. art_content,
  192. </if>
  193. <if test="artSource != null and artSource != ''">
  194. art_source,
  195. </if>
  196. <if test="isFixed != null">
  197. is_fixed,
  198. </if>
  199. <if test="issuedAt != null">
  200. issued_at,
  201. </if>
  202. <if test="editorId != null">
  203. editor_id,
  204. </if>
  205. <if test="status != null">
  206. status,
  207. </if>
  208. <if test="createdBy != null">
  209. created_by,
  210. </if>
  211. <if test="createdAt != null">
  212. created_at,
  213. </if>
  214. </trim>
  215. <trim prefix="values (" suffix=")" suffixOverrides=",">
  216. <if test="ocId != null">
  217. #{ocId ,jdbcType=BIGINT},
  218. </if>
  219. <if test="artId != null">
  220. #{artId ,jdbcType=BIGINT},
  221. </if>
  222. <if test="artCatId != null">
  223. #{artCatId ,jdbcType=BIGINT},
  224. </if>
  225. <if test="artTitle != null and artTitle!=''">
  226. #{artTitle ,jdbcType=VARCHAR},
  227. </if>
  228. <if test="artAuthor != null and artAuthor != ''">
  229. #{artAuthor ,jdbcType=VARCHAR},
  230. </if>
  231. <if test="artContent != null and artContent != ''">
  232. #{artContent ,jdbcType=VARCHAR},
  233. </if>
  234. <if test="artSource != null and artSource != ''">
  235. #{artSource ,jdbcType=VARCHAR},
  236. </if>
  237. <if test="isFixed != null">
  238. #{isFixed ,jdbcType=BIGINT},
  239. </if>
  240. <if test="issuedAt != null">
  241. #{issuedAt ,jdbcType=DATE},
  242. </if>
  243. <if test="editorId != null">
  244. #{editorId ,jdbcType=BIGINT},
  245. </if>
  246. <if test="status != null">
  247. #{status ,jdbcType=BIGINT},
  248. </if>
  249. <if test="createdBy != null">
  250. #{createdBy ,jdbcType=BIGINT},
  251. </if>
  252. <if test="createdAt != null">
  253. #{createdAt ,jdbcType=TIMESTAMP},
  254. </if>
  255. </trim>
  256. </insert>
  257. <!--修改-->
  258. <update id="update" parameterType="com.zhyc.xps.sys.entity.Art">
  259. UPDATE art
  260. <trim suffixOverrides=",">
  261. <set>
  262. <if test="artCatId != null">
  263. art_cat_id = #{artCatId ,jdbcType=BIGINT},
  264. </if>
  265. <if test="artTitle != null">
  266. art_title =#{artTitle ,jdbcType=VARCHAR},
  267. </if>
  268. <if test="artAuthor != null and artAuthor != ''">
  269. art_author = #{artAuthor ,jdbcType=VARCHAR},
  270. </if>
  271. <if test="artContent != null">
  272. art_content = #{artContent ,jdbcType=VARCHAR},
  273. </if>
  274. <if test="artSource != null and artSource != ''">
  275. art_source = #{artSource ,jdbcType=VARCHAR},
  276. </if>
  277. <if test="isFixed != null">
  278. is_fixed = #{isFixed ,jdbcType=BIGINT},
  279. </if>
  280. <if test="status != null">
  281. status = #{status ,jdbcType=BIGINT},
  282. </if>
  283. <if test="issuedAt != null">
  284. issued_at = #{issuedAt ,jdbcType=DATE},
  285. </if>
  286. <if test="editorId != null">
  287. editor_id = #{editorId ,jdbcType=BIGINT},
  288. </if>
  289. <if test="updatedBy != null">
  290. updated_by = #{updatedBy ,jdbcType=BIGINT},
  291. </if>
  292. <if test="updatedAt != null">
  293. updated_at = #{updatedAt ,jdbcType=TIMESTAMP},
  294. </if>
  295. </set>
  296. </trim>
  297. WHERE oc_id = #{ocId ,jdbcType=BIGINT} AND art_id = #{artId ,jdbcType=BIGINT}
  298. </update>
  299. <!--删除-->
  300. <update id="delete" parameterType="java.util.Map">
  301. UPDATE art
  302. <trim suffixOverrides=",">
  303. <set>
  304. <if test="deletedBy != null">
  305. deleted_by = #{deletedBy ,jdbcType=BIGINT},
  306. </if>
  307. <if test="deletedAt != null">
  308. deleted_at = #{deletedAt ,jdbcType=DATE},
  309. </if>
  310. <if test="deletedFlag != null">
  311. deleted_flag = #{deletedFlag ,jdbcType=BIGINT},
  312. </if>
  313. </set>
  314. </trim>
  315. WHERE oc_id = #{ocId,jdbcType=BIGINT} AND deleted_flag = 0
  316. <if test="artId != null ">
  317. AND art_id = #{artId ,jdbcType=BIGINT}
  318. </if>
  319. <if test="artCatId != null ">
  320. AND art_cat_id = #{artCatId ,jdbcType=BIGINT}
  321. </if>
  322. </update>
  323. <!--获取成员数目-->
  324. <select id="getArtCountOfArtCat" parameterType="java.util.Map" resultType="java.lang.Long">
  325. SELECT
  326. count(*)
  327. FROM art AS A
  328. LEFT JOIN art_cat AS B ON (A.oc_id = B.oc_id AND A.art_cat_id = B.art_cat_id)
  329. WHERE A.oc_id = #{ocId ,jdbcType=BIGINT} AND A.deleted_flag = 0
  330. <if test="artCatId != null ">
  331. AND art_cat_id = #{artCatId ,jdbcType=BIGINT}
  332. </if>
  333. <if test="nodeLeft != null and nodeRight != null">
  334. <![CDATA[
  335. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  336. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  337. ]]>
  338. </if>
  339. </select>
  340. </mapper>