Merge remote-tracking branch 'origin/master'

This commit is contained in:
tianbj 2019-12-28 15:15:32 +08:00
commit c5638d64b1
1 changed files with 165 additions and 165 deletions

View File

@ -318,171 +318,171 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
/** // /**
* 实现前端页面的文章搜索 // * 实现前端页面的文章搜索
* // *
* @param request // * @param request
* 搜索id // * 搜索id
* @param response // * @param response
*/ // */
@RequestMapping(value = "search") // @RequestMapping(value = "search")
@ResponseBody // @ResponseBody
public void search(HttpServletRequest request, HttpServletResponse response) { // public void search(HttpServletRequest request, HttpServletResponse response) {
//
Map<String, Object> map = new HashMap<>(); // Map<String, Object> map = new HashMap<>();
// 读取请求字段 // // 读取请求字段
Map<String, String[]> field = request.getParameterMap(); // Map<String, String[]> field = request.getParameterMap();
Map<String, String> basicField = getMapByProperties(net.mingsoft.mdiy.constant.Const.BASIC_FIELD); // Map<String, String> basicField = getMapByProperties(net.mingsoft.mdiy.constant.Const.BASIC_FIELD);
// 文章字段集合 // // 文章字段集合
Map<String, Object> articleFieldName = new HashMap<String, Object>(); // Map<String, Object> articleFieldName = new HashMap<String, Object>();
// 自定义字段集合 // // 自定义字段集合
Map<String, String> diyFieldName = new HashMap<String, String>(); // Map<String, String> diyFieldName = new HashMap<String, String>();
CategoryEntity column = null; // 当前栏目 // CategoryEntity column = null; // 当前栏目
ModelEntity contentModel = null; // 栏目对应模型 // ModelEntity contentModel = null; // 栏目对应模型
List<DiyModelMap> fieldValueList = new ArrayList<DiyModelMap>(); // 栏目对应字段的值 // List<DiyModelMap> fieldValueList = new ArrayList<DiyModelMap>(); // 栏目对应字段的值
int typeId = 0; // int typeId = 0;
String categoryIds = BasicUtil.getString("categoryId"); // String categoryIds = BasicUtil.getString("categoryId");
//当传递了栏目编号但不是栏目集合 // //当传递了栏目编号但不是栏目集合
if(!StringUtil.isBlank(categoryIds) && !categoryIds.contains(",")){ // if(!StringUtil.isBlank(categoryIds) && !categoryIds.contains(",")){
typeId = Integer.parseInt(categoryIds); // typeId = Integer.parseInt(categoryIds);
} // }
//记录自定义模型字段名 // //记录自定义模型字段名
List filedStr = new ArrayList<>(); // List filedStr = new ArrayList<>();
//根据栏目确定自定义模型 // //根据栏目确定自定义模型
if(typeId>0){ // if(typeId>0){
column = (CategoryEntity) categoryBiz.getEntity(Integer.parseInt(typeId+"")); // column = (CategoryEntity) categoryBiz.getEntity(Integer.parseInt(typeId+""));
// 获取表单类型的id // // 获取表单类型的id
if (column != null&&ObjectUtil.isNotNull(column.getMdiyModelId())) { // if (column != null&&ObjectUtil.isNotNull(column.getMdiyModelId())) {
contentModel = (ModelEntity) modelBiz.getEntity(Integer.parseInt(column.getMdiyModelId())); // contentModel = (ModelEntity) modelBiz.getEntity(Integer.parseInt(column.getMdiyModelId()));
if (contentModel != null) { // if (contentModel != null) {
Map<String,String> fieldMap = contentModel.getFieldMap(); // Map<String,String> fieldMap = contentModel.getFieldMap();
for (String s : fieldMap.keySet()) { // for (String s : fieldMap.keySet()) {
filedStr.add(fieldMap.get(s)); // filedStr.add(fieldMap.get(s));
} // }
map.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName()); // map.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName());
} // }
} // }
map.put(ParserUtil.COLUMN, column); // map.put(ParserUtil.COLUMN, column);
//设置栏目编号 // //设置栏目编号
// map.put(ParserUtil.TYPE_ID, typeId); //// map.put(ParserUtil.TYPE_ID, typeId);
} // }
//
// 遍历取字段集合 // // 遍历取字段集合
if (field != null) { // if (field != null) {
for (Map.Entry<String, String[]> entry : field.entrySet()) { // for (Map.Entry<String, String[]> entry : field.entrySet()) {
if (entry != null) { // if (entry != null) {
String value = entry.getValue()[0]; // 处理由get方法请求中文乱码问题 // String value = entry.getValue()[0]; // 处理由get方法请求中文乱码问题
if (ObjectUtil.isNull(value)) { // if (ObjectUtil.isNull(value)) {
continue; // continue;
} // }
if (request.getMethod().equals(RequestMethod.GET)) { // 如果是get方法需要将请求地址参数转吗 // if (request.getMethod().equals(RequestMethod.GET)) { // 如果是get方法需要将请求地址参数转吗
try { // try {
value = new String(value.getBytes("ISO-8859-1"), Const.UTF8); // value = new String(value.getBytes("ISO-8859-1"), Const.UTF8);
} catch (UnsupportedEncodingException e) { // } catch (UnsupportedEncodingException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
// 若为文章字段则保存至文章字段集合否则保存至自定义字段集合 // // 若为文章字段则保存至文章字段集合否则保存至自定义字段集合
if (ObjectUtil.isNotNull(basicField.get(entry.getKey())) && ObjectUtil.isNotNull(value)) { // if (ObjectUtil.isNotNull(basicField.get(entry.getKey())) && ObjectUtil.isNotNull(value)) {
articleFieldName.put(entry.getKey(), value); // articleFieldName.put(entry.getKey(), value);
} else { // } else {
if (!StringUtil.isBlank(value)) { // if (!StringUtil.isBlank(value)) {
diyFieldName.put(entry.getKey(), value); // diyFieldName.put(entry.getKey(), value);
//判断请求中的是否是自定义模型中的字段 // //判断请求中的是否是自定义模型中的字段
if(filedStr.contains(entry.getKey())){ // if(filedStr.contains(entry.getKey())){
//设置自定义模型字段和值 // //设置自定义模型字段和值
DiyModelMap diyMap = new DiyModelMap(); // DiyModelMap diyMap = new DiyModelMap();
diyMap.setKey(entry.getKey()); // diyMap.setKey(entry.getKey());
diyMap.setValue(value); // diyMap.setValue(value);
fieldValueList.add(diyMap); // fieldValueList.add(diyMap);
} // }
} // }
} // }
} // }
} // }
} // }
//添加自定义模型的字段和值 // //添加自定义模型的字段和值
if(fieldValueList.size()>0){ // if(fieldValueList.size()>0){
map.put("diyModel", fieldValueList); // map.put("diyModel", fieldValueList);
} // }
//组织where查询条件 // //组织where查询条件
Map whereMap = ObjectUtil.isNotNull(contentModel)? // Map whereMap = ObjectUtil.isNotNull(contentModel)?
this.searchMap(articleFieldName, diyFieldName, JSONArray.parseArray(contentModel.getModelField())): // this.searchMap(articleFieldName, diyFieldName, JSONArray.parseArray(contentModel.getModelField())):
new HashMap(); // new HashMap();
//
// 获取符合条件的文章总数 // // 获取符合条件的文章总数
int count = contentBiz.getSearchCount(contentModel, whereMap, BasicUtil.getAppId(), categoryIds); // int count = contentBiz.getSearchCount(contentModel, whereMap, BasicUtil.getAppId(), categoryIds);
//设置分页类 // //设置分页类
PageBean page = new PageBean(); // PageBean page = new PageBean();
//读取模板的分页数量 // //读取模板的分页数量
int size = BasicUtil.getInt(ParserUtil.SIZE,10); // int size = BasicUtil.getInt(ParserUtil.SIZE,10);
try { // try {
size = TagParser.getPageSize(ParserUtil.read(SEARCH+ParserUtil.HTM_SUFFIX,false )); // size = TagParser.getPageSize(ParserUtil.read(SEARCH+ParserUtil.HTM_SUFFIX,false ));
} catch (TemplateNotFoundException e1) { // } catch (TemplateNotFoundException e1) {
e1.printStackTrace(); // e1.printStackTrace();
} catch (MalformedTemplateNameException e1) { // } catch (MalformedTemplateNameException e1) {
e1.printStackTrace(); // e1.printStackTrace();
} catch (ParseException e1) { // } catch (ParseException e1) {
e1.printStackTrace(); // e1.printStackTrace();
} catch (IOException e1) { // } catch (IOException e1) {
e1.printStackTrace(); // e1.printStackTrace();
} // }
int total = PageUtil.totalPage(count, size); // int total = PageUtil.totalPage(count, size);
//
int pageNo = BasicUtil.getInt(ParserUtil.PAGE_NO, 1); // int pageNo = BasicUtil.getInt(ParserUtil.PAGE_NO, 1);
if(pageNo >= total && total!=0) { // if(pageNo >= total && total!=0) {
pageNo = total; // pageNo = total;
} // }
//获取总数 // //获取总数
page.setTotal(total); // page.setTotal(total);
//设置页面显示数量 // //设置页面显示数量
page.setSize(size); // page.setSize(size);
//设置列表当前页 // //设置列表当前页
//
page.setPageNo(pageNo); // page.setPageNo(pageNo);
//
String str = ParserUtil.PAGE_NO+","+ParserUtil.SIZE; // String str = ParserUtil.PAGE_NO+","+ParserUtil.SIZE;
//设置分页的统一链接 // //设置分页的统一链接
String url = BasicUtil.getUrl()+request.getServletPath() +"?" + BasicUtil.assemblyRequestUrlParams(str.split(",")); // String url = BasicUtil.getUrl()+request.getServletPath() +"?" + BasicUtil.assemblyRequestUrlParams(str.split(","));
String pageNoStr = "&"+ParserUtil.SIZE+"="+size+"&"+ParserUtil.PAGE_NO+"="; // String pageNoStr = "&"+ParserUtil.SIZE+"="+size+"&"+ParserUtil.PAGE_NO+"=";
//下一页 // //下一页
String nextUrl = url + pageNoStr+((pageNo+1 > total)?total:pageNo+1); // String nextUrl = url + pageNoStr+((pageNo+1 > total)?total:pageNo+1);
//首页 // //首页
String indexUrl = url + pageNoStr + 1; // String indexUrl = url + pageNoStr + 1;
//尾页 // //尾页
String lastUrl = url + pageNoStr + total; // String lastUrl = url + pageNoStr + total;
//上一页 当前页为1时上一页就是1 // //上一页 当前页为1时上一页就是1
String preUrl = url + pageNoStr + ((pageNo==1) ? 1:pageNo-1); // String preUrl = url + pageNoStr + ((pageNo==1) ? 1:pageNo-1);
//
page.setIndexUrl(indexUrl); // page.setIndexUrl(indexUrl);
page.setNextUrl(nextUrl); // page.setNextUrl(nextUrl);
page.setPreUrl(preUrl); // page.setPreUrl(preUrl);
page.setLastUrl(lastUrl); // page.setLastUrl(lastUrl);
map.put(ParserUtil.URL, BasicUtil.getUrl()); // map.put(ParserUtil.URL, BasicUtil.getUrl());
Map<String, Object> searchMap = BasicUtil.assemblyRequestMap(); // Map<String, Object> searchMap = BasicUtil.assemblyRequestMap();
searchMap.put(ParserUtil.PAGE_NO, pageNo); // searchMap.put(ParserUtil.PAGE_NO, pageNo);
map.put(SEARCH, searchMap); // map.put(SEARCH, searchMap);
map.put(ParserUtil.PAGE, page); // map.put(ParserUtil.PAGE, page);
//动态解析 // //动态解析
map.put(ParserUtil.IS_DO,false); // map.put(ParserUtil.IS_DO,false);
//设置动态请求的模块路径 // //设置动态请求的模块路径
map.put(ParserUtil.MODEL_NAME, "mcms"); // map.put(ParserUtil.MODEL_NAME, "mcms");
//解析后的内容 // //解析后的内容
String content = ""; // String content = "";
try { // try {
//根据模板路径参数生成 // //根据模板路径参数生成
content = CmsParserUtil.generate(SEARCH+ParserUtil.HTM_SUFFIX,map, isMobileDevice(request)); // content = CmsParserUtil.generate(SEARCH+ParserUtil.HTM_SUFFIX,map, isMobileDevice(request));
} catch (TemplateNotFoundException e) { // } catch (TemplateNotFoundException e) {
e.printStackTrace(); // e.printStackTrace();
} catch (MalformedTemplateNameException e) { // } catch (MalformedTemplateNameException e) {
e.printStackTrace(); // e.printStackTrace();
} catch (ParseException e) { // } catch (ParseException e) {
e.printStackTrace(); // e.printStackTrace();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
this.outString(response, content); // this.outString(response, content);
} // }
/** /**
* 动态组织查询where条件 获取查询条件的Map key:字段名 value:List 字段的各种判断值 list[0]:是否为自定义字段 * 动态组织查询where条件 获取查询条件的Map key:字段名 value:List 字段的各种判断值 list[0]:是否为自定义字段