Commit 834cb473 authored by sgjj's avatar sgjj

自定义搜索

parent 19694505
...@@ -20,5 +20,5 @@ public interface IContentBiz extends IBaseBiz { ...@@ -20,5 +20,5 @@ public interface IContentBiz extends IBaseBiz {
List<ContentBean> queryIdsByCategoryIdForParser(String categoryId, String beginTime, String endTime, String orderBy, String order); List<ContentBean> queryIdsByCategoryIdForParser(String categoryId, String beginTime, String endTime, String orderBy, String order);
int getSearchCount(ModelEntity contentModel, Map whereMap, int appId, String categoryIds); int getSearchCount(ModelEntity contentModel, List diyList, Map whereMap, int appId, String categoryIds);
} }
\ No newline at end of file
...@@ -63,10 +63,10 @@ public class ContentBizImpl extends BaseBizImpl implements IContentBiz { ...@@ -63,10 +63,10 @@ public class ContentBizImpl extends BaseBizImpl implements IContentBiz {
} }
@Override @Override
public int getSearchCount(ModelEntity contentModel, Map whereMap, int appId, String categoryIds) { public int getSearchCount(ModelEntity contentModel, List diyList, Map whereMap, int appId, String categoryIds) {
if (contentModel!=null) { if (contentModel!=null) {
return contentDao.getSearchCount(contentModel.getModelTableName(),whereMap, appId,categoryIds); return contentDao.getSearchCount(contentModel.getModelTableName(),diyList,whereMap, appId,categoryIds);
} }
return contentDao.getSearchCount(null,whereMap, appId,categoryIds); return contentDao.getSearchCount(null,null,whereMap, appId,categoryIds);
} }
} }
\ No newline at end of file
...@@ -34,6 +34,6 @@ public interface IContentDao extends IBaseDao { ...@@ -34,6 +34,6 @@ public interface IContentDao extends IBaseDao {
* list[2]:是否是等值查询 list[3]:字段的值 * list[2]:是否是等值查询 list[3]:字段的值
* @return 文章实体总数 * @return 文章实体总数
*/ */
int getSearchCount(@Param("tableName") String tableName, @Param("map") Map<String, List> map, int getSearchCount(@Param("tableName") String tableName, @Param("diyList") List diyList,@Param("map") Map<String, Object> map,
@Param("websiteId") int websiteId, @Param("ids") String ids); @Param("websiteId") int websiteId, @Param("ids") String ids);
} }
\ No newline at end of file
...@@ -254,71 +254,43 @@ ...@@ -254,71 +254,43 @@
left join cms_category c left join cms_category c
ON a.content_category_id ON a.content_category_id
= c.id = c.id
<if test="tableName!=null and tableName!=''">left join ${tableName} d on d.link_id=a.id <if test="tableName!=null and tableName!='' and diyMap!=null">left join ${tableName} d on d.link_id=a.id
</if> </if>
where a.app_id = #{websiteId} <where>
<if test="ids!=null and ids!=''"> a.app_id = #{websiteId}
and FIND_IN_SET(content_category_id,'${ids}') <if test="ids!=null and ids!=''">
</if> and FIND_IN_SET(content_category_id,'${ids}')
<foreach item="item" index="key" collection="map" open="" </if>
separator="" close=""> <if test="map.content_title!=null">
<if test=" item[0] == false"> and a.content_title like CONCAT("%",'${map.content_title}',"%")
and ${key} </if>
<if test="map.content_author!=null">
and a.content_author like CONCAT("%",'${map.content_author}',"%")
</if>
<if test="map.content_source!=null">
and a.content_source like CONCAT("%",'${map.content_source}',"%")
</if>
<if test="map.content_type!=null">
and a.content_type like CONCAT("%",'${map.content_type}',"%")
</if>
<if test="map.content_description!=null">
and a.content_description like CONCAT("%",'${map.content_description}',"%")
</if> </if>
<if test="item[0]== true"> <if test="map.content_keyword!=null">
and d.${key} and a.content_keyword like CONCAT("%",'${map.content_keyword}',"%")
</if> </if>
<!-- 数字类型的查找 item[1]:字段是否为数字类型false:数字 --> <if test="map.content_details!=null">
<if test="item[1] == false"> and a.content_details like CONCAT("%",'${map.content_details}',"%")
<!--item[2]: 是采用等值还是区间查询。false:区间 itme[3][0]第一个值item[3][1]的二个值 -->
<if test="item[2] == true">
=
<foreach item="val" index="index" collection="item[3]">#{val}
</foreach>
</if>
<if test="item[2] == false">
between
<foreach item="val" index="index" collection="item[3]"
separator="and">
#{val}
</foreach>
</if>
</if> </if>
<!-- 字符型数据的查找 item[1]:字段是否为数字类型true:字符串 --> <if test="tableName!=null and tableName!='' and diyMap!=null">
<if test="item[1] == true"> <foreach item="item" index="index" collection="diyList" open=""
<!--item[2]: 是采用模糊查询。false:不采用模糊 --> separator="" close="">
<if test="item[2] == true"> and d.${item.key} like CONCAT("%",'${item.value}',"%")
<include refid="queryLike"></include> </foreach>
</if>
<if test="item[2] == false">
=
<foreach item="val" index="index" collection="item[3]">#{val}
</foreach>
</if>
</if> </if>
</foreach> </where>
</select> </select>
<!-- 根据字段条件查找文章实体开始 -->
<sql id="queryLike" databaseId="mysql">
like CONCAT("%",
<foreach item="val" index="index" collection="item[3]">
<if test="index==0">#{val}</if>
</foreach>
,"%")
</sql>
<sql id="queryLike" databaseId="oracle">
like '%'||
<foreach item="val" index="index" collection="item[3]">
<if test="index==0">#{val}</if>
</foreach>
||'%'
</sql>
<sql id="queryLike" databaseId="sqlServer">
like '%'+
<foreach item="val" index="index" collection="item[3]">
<if test="index==0">#{val}</if>
</foreach>
+'%'
</sql>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment