IContentDao.xml 17 KB

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