相关推荐—后台
/**
* @param request
* @param response
* @param model
* 2018年11月9日
* 相关推荐=后台+app
* Administrator
*/
@RequestMapping(value = "/forApp/xgtj.jspx")
public void xgtj(Integer contentId,HttpServletRequest request,
HttpServletResponse response, ModelMap model){
String title = request.getParameter("title");
//首先找到这篇文章
Content content = contentMng.findById(contentId);
List<Content> list = new ArrayList<Content>();
if(title != null && (!title.equals(""))){
List<Content> listA = wapContentManager.getTitleList(title,0, 5);
list.addAll(listA);
}
Map<String, Object> contentMap = new HashMap<String, Object>();
JSONArray jArray = new JSONArray();
//拼装content数组
combinationJSONByMarkApp(jArray,list,title);
contentMap.put("page", 0);
contentMap.put("totalPage", gloableSet.getMaxPage());
contentMap.put("data", jArray);
BaseAppUtils.responseObj(response, contentMap);
}
相关推荐—app
/**
* @param request
* @param response
* @param model
* 相关推荐app
* Administrator
*/
@RequestMapping(value = "/forApp/xgtjApp.jspx")
public void xgtjApp(HttpServletRequest request,
HttpServletResponse response, ModelMap model){
// 文章Id
Integer contentId = 0;
String contentIdStr = request.getParameter("contentId");
if (!BaseAppUtils.isEmptyAfterTrim(contentIdStr)) {
contentId = Integer.parseInt(contentIdStr);
}
// 文章Id
Integer userId = 0;
String userIdStr = request.getParameter("userId");
if (!BaseAppUtils.isEmptyAfterTrim(userIdStr)) {
userId = Integer.parseInt(userIdStr);
}
//20181205oceanli
ContentStatus status = ContentStatus.checked;
Content content = contentMng.findById(contentId);
List<ContentApp> appList = new ArrayList<ContentApp>();
List<ContentRecommend> list = contentRecommendMng.getContentRecommendListByContentId(content.getId());
//新增推荐功能20181205oceanli,
//1.用户没有后台点击相关推荐的文章的情况下
if(null == list || list.size() ==0){
//查询热词稿件
List<Content> findByAll = contentMng.findByAll(null, false, false, null,
9, 4, null, null, status, null, null, null, null);
//取出五条热词推荐
for (int i = 0; i < 5; i++) {
Content findById = contentMng.findById(findByAll.get(i).getId());
ContentApp app = getContentAppByContent(
findById, userId);
appList.add(app);
}
//2.用户后台点击相关推荐的文章不满足五条的情况
}else if(list.size() < 5){
//首先循环手动添加的推荐稿件
for (ContentRecommend contentRecommend : list) {
Content findById = contentMng.findById(contentRecommend.getRecommendId());
ContentApp app = getContentAppByContent(
findById, userId);
appList.add(app);
}
//动态加满5条oceanli 20181206 start
//查询热词稿件
List<Content> findByAll = contentMng.findByAll(null, false, false, null,
9, 4, null, null, status, null, null, null, null);
//然后将推荐+热词稿件=5条
for (int j = 0; j < 5-list.size(); j++) {
Content findById1 = contentMng.findById(findByAll.get(j).getId());
ContentApp app = getContentAppByContent(
findById1, userId);
appList.add(app);
}
//动态加满5条oceanli 20181206 end
//20181214 ocean 数据接收到之后判断去重,之后添加热词排行的下一条数据 start=================================================================
for ( int i = 0 ; i < appList.size() - 1 ; i ++ ) {
for ( int j = appList.size() - 1 ; j > i; j -- ) {
if (appList.get(j).getId().equals(appList.get(i).getId())) {
appList.remove(j);
Content findById1 = contentMng.findById(findByAll.get(j).getId());
ContentApp app = getContentAppByContent(
findById1, userId);
appList.add(app);
}
}
}
//20181214 ocean 数据接收到之后判断去重,之后添加热词排行的下一条数据 end =================================================================
//3.用户后台点击相关推荐的文章满足五条或者五条以上
}else if(list.size() >= 5){
//控制条数为5
int m=0;
for (ContentRecommend contentRecommend : list) {
Content findById = contentMng.findById(contentRecommend.getRecommendId());
ContentApp app = getContentAppByContent(
findById, userId);
appList.add(app);
m++;
if(m>=5){
break;
}
}
}
BaseAppUtils.resposneJson(response, appList);
}