mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-10 03:16:48 +08:00
首页推荐案例查询
This commit is contained in:
@@ -3,6 +3,7 @@ package com.xboe.module.boecase.service;
|
||||
import java.util.List;
|
||||
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.module.boecase.dto.*;
|
||||
import com.xboe.module.boecase.entity.Cases;
|
||||
import com.xboe.module.dict.entity.DictItem;
|
||||
@@ -100,5 +101,7 @@ public interface ICasesService{
|
||||
|
||||
|
||||
PageList<Cases> queryRecommendPageCasesV2(CasePageVo req);
|
||||
|
||||
List<CasesVo> caseIndexV2(CurrentUser current);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.xboe.module.boecase.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.text.split.SplitIter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.xboe.common.OrderCondition;
|
||||
@@ -8,6 +10,7 @@ import com.xboe.common.OrderDirection;
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.common.utils.IDGenerator;
|
||||
import com.xboe.common.utils.StringUtil;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.core.orm.*;
|
||||
import com.xboe.module.boecase.dao.*;
|
||||
import com.xboe.module.boecase.dto.*;
|
||||
@@ -337,6 +340,8 @@ public class CasesServiceImpl implements ICasesService {
|
||||
return pageList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 案例分页查询,是否置顶
|
||||
*/
|
||||
@@ -825,6 +830,71 @@ public class CasesServiceImpl implements ICasesService {
|
||||
return casesVos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前用户有推荐案例,从推荐案例列表中随机抽取3个案例展示在首页;没有推荐案例,优先展示置顶案例,如无置顶展示最热案例
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<CasesVo> caseIndexV2(CurrentUser current) {
|
||||
int CASE_LEN = 3;
|
||||
String accountId = current.getAccountId();
|
||||
List<Cases> result = new ArrayList<>();
|
||||
try {
|
||||
String hql = "select a.caseId FROM CasesRecommendPushRecord a left join Cases b ON a.caseId = b.id WHERE a.pushUserId=:1 b.deleted = false group by a.caseId ORDER By a.recommendTime DESC LIMIT "+CASE_LEN;
|
||||
List<Object[]> listFields = casesRecommendDao.findListFields(hql, accountId);
|
||||
List<Long> caseIds = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(listFields)) {
|
||||
for (Object[] objs : listFields) {
|
||||
caseIds.add(resultToVo(objs));
|
||||
}
|
||||
}
|
||||
int caseIdLen = caseIds.size();
|
||||
if (caseIdLen < CASE_LEN) {
|
||||
if(caseIdLen != 0){
|
||||
IFieldFilter id = FieldFilters.in("id", caseIds);
|
||||
List<Cases> recommendCases = casesDao.findList(id);
|
||||
result.addAll(recommendCases);
|
||||
}
|
||||
IFieldFilter deleted = FieldFilters.eq("deleted", false);
|
||||
IFieldFilter isTop = FieldFilters.eq("isTop", true);
|
||||
List<Cases> topCases = casesDao.findList(CASE_LEN, OrderCondition.desc("topTime"), isTop, deleted);
|
||||
if (CollUtil.isNotEmpty(topCases)) {
|
||||
List<Cases> subCases = CollUtil.sub(topCases, 0, CASE_LEN - caseIdLen);
|
||||
result.addAll(subCases);
|
||||
}
|
||||
if(result.size() < CASE_LEN){
|
||||
OrderCondition views = OrderCondition.desc("views");
|
||||
List<Cases> hotCases = casesDao.findListByFilters(CASE_LEN, views, ListUtil.toList(deleted));
|
||||
if (CollUtil.isNotEmpty(hotCases)) {
|
||||
List<Cases> subCases = CollUtil.sub(hotCases, 0, CASE_LEN - result.size());
|
||||
result.addAll(subCases);
|
||||
}
|
||||
}
|
||||
if(result.size() < CASE_LEN){
|
||||
List<Cases> defaultCases = casesDao.findList(CASE_LEN, OrderCondition.desc("sysCreateTime"), deleted);
|
||||
if (CollUtil.isNotEmpty(defaultCases)) {
|
||||
List<Cases> subCases = CollUtil.sub(defaultCases, 0, CASE_LEN - result.size());
|
||||
result.addAll(subCases);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
IFieldFilter id = FieldFilters.in("id", caseIds);
|
||||
List<Cases> recommendCases = casesDao.findList(id);
|
||||
result.addAll(recommendCases);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("查询失败",e);
|
||||
}
|
||||
List<CasesVo> casesVos = BeanUtil.copyToList(result, CasesVo.class);
|
||||
return casesVos;
|
||||
}
|
||||
|
||||
private Long resultToVo(Object[] objs) {
|
||||
Long caseId = (Long) objs[0];
|
||||
return caseId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void excellent(String id, Boolean excellent) {
|
||||
//取消时,把时间清空
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.xboe.core.CurrentUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -67,6 +68,19 @@ public class PortalIndexApi extends ApiBaseController{
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value="/casesV2",method = {RequestMethod.GET})
|
||||
public JsonResponse<List<CasesVo>> caseList() {
|
||||
try {
|
||||
CurrentUser current = this.getCurrent();
|
||||
List<CasesVo> casesVos = casesService.caseIndexV2(current);
|
||||
return success(casesVos);
|
||||
}catch(Exception e) {
|
||||
log.error("查询案例数据错误",e);
|
||||
return error("查询案例数据错误",e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章排行榜
|
||||
* */
|
||||
|
||||
Reference in New Issue
Block a user