From b033abee65d9dd54624519b8d82fbcdad2294f89 Mon Sep 17 00:00:00 2001 From: Sun Xin Date: Mon, 4 Mar 2019 01:14:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mingsoft/cms/action/web/SearchAction.java | 116 +++++++++--------- src/main/webapp/templets/1/default/search.htm | 8 +- 2 files changed, 64 insertions(+), 60 deletions(-) diff --git a/src/main/java/net/mingsoft/cms/action/web/SearchAction.java b/src/main/java/net/mingsoft/cms/action/web/SearchAction.java index a2e653e0..6449b331 100644 --- a/src/main/java/net/mingsoft/cms/action/web/SearchAction.java +++ b/src/main/java/net/mingsoft/cms/action/web/SearchAction.java @@ -45,6 +45,7 @@ import net.mingsoft.basic.biz.IColumnBiz; import net.mingsoft.basic.entity.ColumnEntity; import net.mingsoft.cms.biz.IArticleBiz; import net.mingsoft.cms.util.CmsParserUtil; +import net.mingsoft.mdiy.biz.IContentModelFieldBiz; import net.mingsoft.mdiy.biz.ISearchBiz; import net.mingsoft.mdiy.entity.ContentModelFieldEntity; import net.mingsoft.mdiy.entity.SearchEntity; @@ -123,6 +124,8 @@ public class SearchAction extends BaseAction { Map basicField = getMapByProperties(net.mingsoft.mdiy.constant.Const.BASIC_FIELD); // 文章字段集合 Map articleFieldName = new HashMap(); + // 自定义字段集合 + Map diyFieldName = new HashMap(); // 遍历取字段集合 if (field != null) { for (Entry entry : field.entrySet()) { @@ -141,11 +144,15 @@ public class SearchAction extends BaseAction { // 若为文章字段,则保存至文章字段集合;否则保存至自定义字段集合 if (ObjectUtil.isNotNull(basicField.get(entry.getKey())) && ObjectUtil.isNotNull(value)) { articleFieldName.put(entry.getKey(), value); - } + } else { + if (!StringUtil.isBlank(value)) { + diyFieldName.put(entry.getKey(), value); + } + } } } } - Map whereMap = this.searchMap(articleFieldName, null, null); + Map whereMap = this.searchMap(articleFieldName, diyFieldName, null); // 获取符合条件的文章总数 int count = articleBiz.getSearchCount(null, whereMap, BasicUtil.getAppId(), null); int typeId = BasicUtil.getInt("categoryId",0); @@ -175,25 +182,22 @@ public class SearchAction extends BaseAction { next = pageNo+1; pre = pageNo ==1 ? 1 : pageNo+1; } - String url = BasicUtil.getUrl() + request.getServletPath() +"?"; + String url = BasicUtil.getUrl() + request.getServletPath() +"?" + BasicUtil.assemblyRequestUrlParams(ParserUtil.PAGE_NO.split("")); String pageNoStr = "&"+ParserUtil.PAGE_NO+"="; - BasicUtil.removeUrlParams(ParserUtil.PAGE_NO.split("")); //下一页 - String nextUrl = url + BasicUtil.assemblyRequestUrlParams()+pageNoStr+next; + String nextUrl = url + pageNoStr+next; //首页 - String indexUrl = url + BasicUtil.assemblyRequestUrlParams() + pageNoStr + 1; + String indexUrl = url + pageNoStr + 1; //尾页 - String lastUrl = url + BasicUtil.assemblyRequestUrlParams() + pageNoStr + total; + String lastUrl = url + pageNoStr + total; //上一页 - String preUrl = url + BasicUtil.assemblyRequestUrlParams() + pageNoStr + pre; + String preUrl = url + pageNoStr + pre; - Map pageMap = new HashMap(); - pageMap.put(ParserUtil.INDEX_URL, indexUrl); - pageMap.put(ParserUtil.NEXT_URL, nextUrl); - pageMap.put(ParserUtil.PRE_URL, preUrl); - pageMap.put(ParserUtil.LAST_URL, lastUrl); + map.put(ParserUtil.INDEX_URL, indexUrl); + map.put(ParserUtil.NEXT_URL, nextUrl); + map.put(ParserUtil.PRE_URL, preUrl); + map.put(ParserUtil.LAST_URL, lastUrl); map.put(ParserUtil.URL, BasicUtil.getUrl()); - map.put(ParserUtil.PAGE, pageMap); Map searchMap = new HashMap<>(); searchMap.put(BASIC_TITLE, BasicUtil.getString(BASIC_TITLE)); searchMap.put(ParserUtil.PAGE_NO, BasicUtil.getInt(ParserUtil.PAGE_NO,1)); @@ -256,48 +260,48 @@ public class SearchAction extends BaseAction { } // 遍历字段自定义字段 -// for (Iterator iter = diyFieldName.keySet().iterator(); iter.hasNext();) { -// String key = iter.next().toString(); -// String fieldValue = diyFieldName.get(key); -// // 获取字段实体 -// ContentModelFieldEntity field = this.get(key, fields); -// if (field != null) { -// List list = new ArrayList(); -// // 是否为自定义字段0 -// list.add(0, true); -// List listValue = new ArrayList(); -// // 字段的值 -// if (field.getFieldType() == IContentModelFieldBiz.INT || field.getFieldType() == IContentModelFieldBiz.FLOAT) { -// // 判断是否为区间查询 -// -// if (diyFieldName.get(key).toString().indexOf("-") > 0) { -// String[] values = fieldValue.toString().split("-"); -// // 是否是数字类型,false:是 -// list.add(false); -// // 是否是区间比较 false:是 -// list.add(false); -// // 字段值1 -// listValue.add(values[0]); -// listValue.add(values[1]); -// } else { -// // 是否是数字类型,false:是2 -// list.add(false); -// // 是否是区间比较 true:不是3 -// list.add(true); -// // 字段值 1 -// listValue.add(fieldValue); -// } -// } else { -// // 是否是数字类型,true:不是2 -// list.add(true); -// list.add(false); -// // 字段值 1 -// listValue.add(fieldValue); -// } -// list.add(listValue); -// map.put(key, list); -// } -// } + for (Iterator iter = diyFieldName.keySet().iterator(); iter.hasNext();) { + String key = iter.next().toString(); + String fieldValue = diyFieldName.get(key); + // 获取字段实体 + ContentModelFieldEntity field = this.get(key, fields); + if (field != null) { + List list = new ArrayList(); + // 是否为自定义字段0 + list.add(0, true); + List listValue = new ArrayList(); + // 字段的值 + if (field.getFieldType() == IContentModelFieldBiz.INT || field.getFieldType() == IContentModelFieldBiz.FLOAT) { + // 判断是否为区间查询 + + if (diyFieldName.get(key).toString().indexOf("-") > 0) { + String[] values = fieldValue.toString().split("-"); + // 是否是数字类型,false:是 + list.add(false); + // 是否是区间比较 false:是 + list.add(false); + // 字段值1 + listValue.add(values[0]); + listValue.add(values[1]); + } else { + // 是否是数字类型,false:是2 + list.add(false); + // 是否是区间比较 true:不是3 + list.add(true); + // 字段值 1 + listValue.add(fieldValue); + } + } else { + // 是否是数字类型,true:不是2 + list.add(true); + list.add(false); + // 字段值 1 + listValue.add(fieldValue); + } + list.add(listValue); + map.put(key, list); + } + } return map; } diff --git a/src/main/webapp/templets/1/default/search.htm b/src/main/webapp/templets/1/default/search.htm index f3a6e3ce..559e70d0 100644 --- a/src/main/webapp/templets/1/default/search.htm +++ b/src/main/webapp/templets/1/default/search.htm @@ -27,10 +27,10 @@