IContentDao.xml 18 KB

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