IContentDao.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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="net.mingsoft.cms.dao.IContentDao">
  4. <resultMap id="resultMap" type="net.mingsoft.cms.entity.ContentEntity">
  5. <id column="id" property="id" /><!--编号 -->
  6. <result column="content_title" property="contentTitle" /><!--文章标题 -->
  7. <result column="content_category_id" property="contentCategoryId" /><!--所属栏目 -->
  8. <result column="content_type" property="contentType" /><!--文章类型 -->
  9. <result column="content_display" property="contentDisplay" /><!--是否显示 -->
  10. <result column="content_author" property="contentAuthor" /><!--文章作者 -->
  11. <result column="content_source" property="contentSource" /><!--文章来源 -->
  12. <result column="content_datetime" property="contentDatetime" /><!--发布时间 -->
  13. <result column="content_sort" property="contentSort" /><!--自定义顺序 -->
  14. <result column="content_img" property="contentImg" /><!--文章缩略图 -->
  15. <result column="content_description" property="contentDescription" /><!--描述 -->
  16. <result column="content_keyword" property="contentKeyword" /><!--关键字 -->
  17. <result column="content_details" property="contentDetails" /><!--文章内容 -->
  18. <result column="content_url" property="contentUrl" /><!--文章跳转链接地址 -->
  19. <result column="content_hit" property="contentHit" /><!--点击次数 -->
  20. <result column="app_id" property="appId" /><!--文章管理的应用id -->
  21. <result column="create_by" property="createBy" /><!--创建人 -->
  22. <result column="create_date" property="createDate" /><!--创建时间 -->
  23. <result column="update_by" property="updateBy" /><!--修改人 -->
  24. <result column="update_date" property="updateDate" /><!--修改时间 -->
  25. <result column="del" property="del" /><!--删除标记 -->
  26. </resultMap>
  27. <resultMap id="resultContentMap" type="net.mingsoft.cms.bean.ContentBean">
  28. <id column="id" property="id" /><!--编号 -->
  29. <result column="content_title" property="contentTitle" /><!--文章标题 -->
  30. <result column="content_category_id" property="contentCategoryId" /><!--所属栏目 -->
  31. <result column="content_type" property="contentType" /><!--文章类型 -->
  32. <result column="content_display" property="contentDisplay" /><!--是否显示 -->
  33. <result column="content_author" property="contentAuthor" /><!--文章作者 -->
  34. <result column="content_source" property="contentSource" /><!--文章来源 -->
  35. <result column="content_datetime" property="contentDatetime" /><!--发布时间 -->
  36. <result column="content_sort" property="contentSort" /><!--自定义顺序 -->
  37. <result column="content_img" property="contentImg" /><!--文章缩略图 -->
  38. <result column="content_description" property="contentDescription" /><!--描述 -->
  39. <result column="content_keyword" property="contentKeyword" /><!--关键字 -->
  40. <result column="content_details" property="contentDetails" /><!--文章内容 -->
  41. <result column="content_url" property="contentUrl" /><!--文章跳转链接地址 -->
  42. <result column="static_url" property="staticUrl" /><!--静态地址 -->
  43. <result column="content_hit" property="contentHit" /><!--点击次数 -->
  44. <result column="app_id" property="appId" /><!--文章管理的应用id -->
  45. <result column="create_by" property="createBy" /><!--创建人 -->
  46. <result column="create_date" property="createDate" /><!--创建时间 -->
  47. <result column="update_by" property="updateBy" /><!--修改人 -->
  48. <result column="update_date" property="updateDate" /><!--修改时间 -->
  49. <result column="del" property="del" /><!--删除标记 -->
  50. </resultMap>
  51. <resultMap id="resultBean" type="net.mingsoft.cms.bean.CategoryBean">
  52. <id column="id" property="id" /><!--编号 -->
  53. <id column="article_Id" property="articleId" /><!--编号 -->
  54. <result column="category_title" property="categoryTitle" /><!--栏目管理名称 -->
  55. <result column="category_id" property="categoryId" /><!--所属栏目 -->
  56. <result column="category_type" property="categoryType" /><!--栏目管理属性 -->
  57. <result column="category_sort" property="categorySort" /><!--自定义顺序 -->
  58. <result column="category_list_url" property="categoryListUrl" /><!--列表模板 -->
  59. <result column="category_url" property="categoryUrl" /><!--内容模板 -->
  60. <result column="category_keyword" property="categoryKeyword" /><!--栏目管理关键字 -->
  61. <result column="category_descrip" property="categoryDescrip" /><!--栏目管理描述 -->
  62. <result column="category_img" property="categoryImg" /><!--缩略图 -->
  63. <result column="category_diy_url" property="categoryDiyUrl" /><!--自定义链接 -->
  64. <result column="mdiy_model_id" property="mdiyModelId" /><!--栏目管理的内容模型id -->
  65. <result column="category_datetime" property="categoryDatetime" /><!--类别发布时间 -->
  66. <result column="category_manager_id" property="categoryManagerId" /><!--发布用户id -->
  67. <result column="app_id" property="appId" /><!--应用编号 -->
  68. <result column="dict_id" property="dictId" /><!--字典对应编号 -->
  69. <result column="category_flag" property="categoryFlag" /><!--栏目属性 -->
  70. <result column="category_path" property="categoryPath" /><!--栏目路径 -->
  71. <result column="category_parent_id" property="categoryParentId" /><!--父类型编号 -->
  72. <result column="create_by" property="createBy" /><!--创建人 -->
  73. <result column="create_date" property="createDate" /><!--创建时间 -->
  74. <result column="update_by" property="updateBy" /><!--修改人 -->
  75. <result column="update_date" property="updateDate" /><!--修改时间 -->
  76. <result column="del" property="del" /><!--删除标记 -->
  77. </resultMap>
  78. <!--保存-->
  79. <insert id="saveEntity" useGeneratedKeys="true" keyProperty="id"
  80. parameterType="net.mingsoft.cms.entity.ContentEntity" >
  81. insert into cms_content
  82. <trim prefix="(" suffix=")" suffixOverrides=",">
  83. <if test="contentTitle != null and contentTitle != ''">content_title,</if>
  84. <if test="contentCategoryId != null and contentCategoryId != ''">content_category_id,</if>
  85. <if test="contentType != null ">content_type,</if>
  86. <if test="contentDisplay != null and contentDisplay != ''">content_display,</if>
  87. <if test="contentAuthor != null and contentAuthor != ''">content_author,</if>
  88. <if test="contentSource != null and contentSource != ''">content_source,</if>
  89. <if test="contentDatetime != null">content_datetime,</if>
  90. <if test="contentSort != null">content_sort,</if>
  91. <if test="contentImg != null and contentImg != ''">content_img,</if>
  92. <if test="contentDescription != null and contentDescription != ''">content_description,</if>
  93. <if test="contentKeyword != null and contentKeyword != ''">content_keyword,</if>
  94. <if test="contentDetails != null and contentDetails != ''">content_details,</if>
  95. <if test="contentUrl != null and contentUrl != ''">content_url,</if>
  96. <if test="contentHit != null">content_hit,</if>
  97. <if test="appId != null">app_id,</if>
  98. <if test="createBy &gt; 0">create_by,</if>
  99. <if test="createDate != null">create_date,</if>
  100. <if test="updateBy &gt; 0">update_by,</if>
  101. <if test="updateDate != null">update_date,</if>
  102. <if test="del != null">del,</if>
  103. </trim>
  104. <trim prefix="values (" suffix=")" suffixOverrides=",">
  105. <if test="contentTitle != null and contentTitle != ''">#{contentTitle},</if>
  106. <if test="contentCategoryId != null and contentCategoryId != ''">#{contentCategoryId},</if>
  107. <if test="contentType != null ">#{contentType},</if>
  108. <if test="contentDisplay != null and contentDisplay != ''">#{contentDisplay},</if>
  109. <if test="contentAuthor != null and contentAuthor != ''">#{contentAuthor},</if>
  110. <if test="contentSource != null and contentSource != ''">#{contentSource},</if>
  111. <if test="contentDatetime != null">#{contentDatetime},</if>
  112. <if test="contentSort != null">#{contentSort},</if>
  113. <if test="contentImg != null and contentImg != ''">#{contentImg},</if>
  114. <if test="contentDescription != null and contentDescription != ''">#{contentDescription},</if>
  115. <if test="contentKeyword != null and contentKeyword != ''">#{contentKeyword},</if>
  116. <if test="contentDetails != null and contentDetails != ''">#{contentDetails},</if>
  117. <if test="contentUrl != null and contentUrl != ''">#{contentUrl},</if>
  118. <if test="contentHit != null">#{contentHit},</if>
  119. <if test="appId != null">#{appId},</if>
  120. <if test="createBy &gt; 0">#{createBy},</if>
  121. <if test="createDate != null">#{createDate},</if>
  122. <if test="updateBy &gt; 0">#{updateBy},</if>
  123. <if test="updateDate != null">#{updateDate},</if>
  124. <if test="del != null">#{del},</if>
  125. </trim>
  126. </insert>
  127. <!--更新-->
  128. <update id="updateEntity" parameterType="net.mingsoft.cms.entity.ContentEntity">
  129. update cms_content
  130. <set>
  131. <if test="contentTitle != null and contentTitle != ''">content_title=#{contentTitle},</if>
  132. <if test="contentCategoryId != null and contentCategoryId != ''">content_category_id=#{contentCategoryId},</if>
  133. <if test="contentType != null ">content_type=#{contentType},</if>
  134. <if test="contentDisplay != null and contentDisplay != ''">content_display=#{contentDisplay},</if>
  135. <if test="contentAuthor != null ">content_author=#{contentAuthor},</if>
  136. <if test="contentSource != null ">content_source=#{contentSource},</if>
  137. <if test="contentDatetime != null">content_datetime=#{contentDatetime},</if>
  138. <if test="contentSort != null">content_sort=#{contentSort},</if>
  139. <if test="contentImg != null and contentImg != ''">content_img=#{contentImg},</if>
  140. <if test="contentDescription != null ">content_description=#{contentDescription},</if>
  141. <if test="contentKeyword != null ">content_keyword=#{contentKeyword},</if>
  142. <if test="contentDetails != null ">content_details=#{contentDetails},</if>
  143. <if test="contentUrl != null and contentUrl != ''">content_url=#{contentUrl},</if>
  144. <if test="contentHit != null">content_hit=#{contentHit},</if>
  145. <if test="appId != null">app_id=#{appId},</if>
  146. <if test="createBy &gt; 0">create_by=#{createBy},</if>
  147. <if test="createDate != null">create_date=#{createDate},</if>
  148. <if test="updateBy &gt; 0">update_by=#{updateBy},</if>
  149. <if test="updateDate != null">update_date=#{updateDate},</if>
  150. <if test="del != null">del=#{del},</if>
  151. </set>
  152. where id = #{id}
  153. </update>
  154. <!--根据id获取-->
  155. <select id="getEntity" resultMap="resultMap" parameterType="int">
  156. select * from cms_content where id=#{id} and del=0
  157. </select>
  158. <!--根据实体获取-->
  159. <select id="getByEntity" resultMap="resultMap" parameterType="net.mingsoft.cms.entity.ContentEntity">
  160. select * from cms_content
  161. <where>
  162. del=0
  163. <if test="contentTitle != null and contentTitle != ''">and content_title like CONCAT('%',#{contentTitle},'%')</if>
  164. <if test="contentCategoryId != null and contentCategoryId != ''">and content_category_id=#{contentCategoryId}</if>
  165. <if test="contentType != null and contentType != ''">and content_type=#{contentType}</if>
  166. <if test="contentDisplay != null and contentDisplay != ''">and content_display=#{contentDisplay}</if>
  167. <if test="contentAuthor != null and contentAuthor != ''">and content_author=#{contentAuthor}</if>
  168. <if test="contentSource != null and contentSource != ''">and content_source=#{contentSource}</if>
  169. <if test="contentDatetime != null"> and content_datetime=#{contentDatetime} </if>
  170. <if test="contentSort != null"> and content_sort=#{contentSort} </if>
  171. <if test="contentImg != null and contentImg != ''">and content_img=#{contentImg}</if>
  172. <if test="contentDescription != null and contentDescription != ''">and content_description=#{contentDescription}</if>
  173. <if test="contentKeyword != null and contentKeyword != ''">and content_keyword=#{contentKeyword}</if>
  174. <if test="contentDetails != null and contentDetails != ''">and content_details=#{contentDetails}</if>
  175. <if test="contentUrl != null and contentUrl != ''">and content_url=#{contentUrl}</if>
  176. <if test="contentHit != null">and content_hit=#{contentHit}</if>
  177. <if test="appId != null"> and app_id=#{appId} </if>
  178. <if test="createBy &gt; 0"> and create_by=#{createBy} </if>
  179. <if test="createDate != null"> and create_date=#{createDate} </if>
  180. <if test="updateBy &gt; 0"> and update_by=#{updateBy} </if>
  181. <if test="updateDate != null"> and update_date=#{updateDate} </if>
  182. </where>
  183. limit 0,1
  184. </select>
  185. <!--删除-->
  186. <delete id="deleteEntity" parameterType="int">
  187. update cms_content set del=1 where id=#{id}
  188. </delete>
  189. <!--删除-->
  190. <delete id="deleteEntityByCategoryIds" >
  191. update cms_content set del=1
  192. <where>
  193. content_category_id in <foreach collection="ids" item="item" index="index"
  194. open="(" separator="," close=")">#{item}</foreach>
  195. </where>
  196. </delete>
  197. <!--批量删除-->
  198. <delete id="delete" >
  199. update cms_content set del=1
  200. <where>
  201. id in <foreach collection="ids" item="item" index="index"
  202. open="(" separator="," close=")">#{item}</foreach>
  203. </where>
  204. </delete>
  205. <!--查询全部-->
  206. <select id="queryAll" resultMap="resultMap">
  207. select * from cms_content where del=0 order by id desc
  208. </select>
  209. <!--条件查询-->
  210. <select id="query" resultMap="resultContentMap">
  211. select ct.*,CONCAT("/html/",ct.app_id,category_path,"/",ct.id,".html") AS static_url from (
  212. select ct.*,cc.category_path from cms_content ct
  213. join cms_category cc on ct.content_category_id=cc.id
  214. <where>
  215. ct.del=0
  216. <if test="contentTitle != null and contentTitle != ''"> and content_title like CONCAT('%',#{contentTitle},'%')</if>
  217. <if test="contentCategoryId != null and contentCategoryId != ''"> and (content_category_id=#{contentCategoryId} or content_category_id in
  218. (select id FROM cms_category where <include refid="queryWhereCategoryId"></include>))</if>
  219. <if test="contentType != null and contentType != ''"> and content_type LIKE CONCAT('%',#{contentType},'%')</if>
  220. <if test="contentDisplay != null and contentDisplay != ''"> and content_display=#{contentDisplay}</if>
  221. <if test="contentAuthor != null and contentAuthor != ''"> and content_author=#{contentAuthor}</if>
  222. <if test="contentSource != null and contentSource != ''"> and content_source=#{contentSource}</if>
  223. <if test="contentDatetime != null"> and content_datetime=#{contentDatetime} </if>
  224. <if test="contentSort != null"> and content_sort=#{contentSort} </if>
  225. <if test="contentImg != null and contentImg != ''"> and content_img=#{contentImg}</if>
  226. <if test="contentDescription != null and contentDescription != ''"> and content_description=#{contentDescription}</if>
  227. <if test="contentKeyword != null and contentKeyword != ''"> and content_keyword=#{contentKeyword}</if>
  228. <if test="contentDetails != null and contentDetails != ''"> and content_details=#{contentDetails}</if>
  229. <if test="contentUrl != null and contentUrl != ''"> and content_url=#{contentUrl}</if>
  230. <if test="contentHit != null"> and content_hit=#{contentHit}</if>
  231. <if test="appId != null"> and ct.app_id=#{appId} </if>
  232. <if test="createBy &gt; 0"> and ct.create_by=#{createBy} </if>
  233. <if test="createDate != null"> and ct.create_date=#{createDate} </if>
  234. <if test="updateBy &gt; 0"> and ct.update_by=#{updateBy} </if>
  235. <if test="updateDate != null"> and update_date=#{updateDate} </if>
  236. </where>
  237. )ct ORDER BY date_format(ct.content_datetime,'%Y-%m-%d') desc,content_sort desc
  238. </select>
  239. <sql id="queryWhereCategoryId" databaseId="mysql">
  240. find_in_set('${contentCategoryId}',CATEGORY_PARENT_ID)
  241. </sql>
  242. <sql id="queryWhereCategoryId" databaseId="oracle" >
  243. instr(','||'${contentCategoryId}'||',', ','||CATEGORY_PARENT_ID||',')>0
  244. </sql>
  245. <sql id="queryWhereCategoryId" databaseId="sqlServer">
  246. CHARINDEX(','+'${contentCategoryId}'+',' , ','+CATEGORY_PARENT_ID +',')>0
  247. </sql>
  248. <!-- 根据站点编号、开始、结束时间和栏目编号查询文章编号集合 -->
  249. <select id="queryIdsByCategoryIdForParser" resultMap="resultBean" >
  250. select
  251. cms_content.id article_id,c.*
  252. FROM cms_content
  253. LEFT JOIN cms_category c ON content_category_id = c.id
  254. where cms_content.del=0
  255. <if test="appId &gt; 0">
  256. and cms_content.app_id = #{appId}
  257. </if>
  258. <!-- 查询子栏目数据 -->
  259. <if test="contentCategoryId &gt; 0">
  260. and (content_category_id=#{contentCategoryId} or content_category_id in
  261. (select id FROM cms_category where <include refid="queryWhereCategoryId"></include>))
  262. </if>
  263. <if test="beginTime!=null and beginTime!=''">
  264. and content_datetime &gt;= #{beginTime}
  265. </if>
  266. <if test="endTime!=null and endTime!=''">
  267. and content_datetime &gt;= #{endTime}
  268. </if>
  269. <if test="flag!=null and flag!=''">
  270. and cms_content.content_type in ( #{flag})
  271. </if>
  272. <if test="noflag!=null and noflag!=''">
  273. and (cms_content.content_type not in ( #{noflag} ) or cms_content.content_type is null)
  274. </if>
  275. <if test="orderBy!=null and orderBy!='' ">
  276. <if test="orderBy=='date'">ORDER BY content_datetime</if>
  277. <if test="orderBy=='hit'">ORDER BY content_hit</if>
  278. <if test="orderBy=='sort'">ORDER BY content_sort</if>
  279. <if test="orderBy!='date' and orderBy!='hit' and orderBy!='sort'">
  280. ORDER BY cms_content.id
  281. </if>
  282. <choose>
  283. <when test="order!=null and order!=''">
  284. ${order}
  285. </when>
  286. <otherwise>
  287. desc
  288. </otherwise>
  289. </choose>
  290. </if>
  291. </select>
  292. <select id="getSearchCount" resultType="int">
  293. select count(*) from
  294. cms_content a
  295. left join cms_category c
  296. ON a.content_category_id
  297. = c.id
  298. <if test="tableName!=null and tableName!='' and diyMap!=null">left join ${tableName} d on d.link_id=a.id
  299. </if>
  300. <where>
  301. a.del=0 and a.app_id = #{websiteId}
  302. <if test="ids!=null and ids!=''">
  303. and FIND_IN_SET(content_category_id,#{ids})
  304. </if>
  305. <if test="map.content_title!=null">
  306. and a.content_title like CONCAT("%",#{map.content_title},"%")
  307. </if>
  308. <if test="map.content_author!=null">
  309. and a.content_author like CONCAT("%",#{map.content_author},"%")
  310. </if>
  311. <if test="map.content_source!=null">
  312. and a.content_source like CONCAT("%",#{map.content_source},"%")
  313. </if>
  314. <if test="map.content_type!=null">
  315. and <foreach item="item" index="index" collection="map.content_type.split(',')" open="(" separator="or" close=")">
  316. FIND_IN_SET('${item}',a.content_type)
  317. </foreach>
  318. </if>
  319. <if test="map.content_description!=null">
  320. and a.content_description like CONCAT("%",#{map.content_description},"%")
  321. </if>
  322. <if test="map.content_keyword!=null">
  323. and a.content_keyword like CONCAT("%",#{map.content_keyword},"%")
  324. </if>
  325. <if test="map.content_details!=null">
  326. and a.content_details like CONCAT("%",#{map.content_details},"%")
  327. </if>
  328. <if test="map.content_datetime_start!=null and map.content_datetime_end!=null">
  329. and a.content_datetime between #{map.content_datetime_start} and #{map.content_datetime_end}
  330. </if>
  331. <if test="tableName!=null and tableName!='' and diyMap!=null">
  332. <foreach item="item" index="index" collection="diyList" open=""
  333. separator="" close="">
  334. and d.${field.key} like CONCAT("%",#{item.value},"%")
  335. </foreach>
  336. </if>
  337. </where>
  338. </select>
  339. </mapper>