mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 10:56:50 +08:00
推荐列表查询接口修改
This commit is contained in:
@@ -34,11 +34,11 @@ public interface CasesRecordDao extends JpaRepository<Cases, String>, JpaSpecifi
|
||||
" or b.keyword3 like CONCAT('%',:#{#condition.keyWord},'%')" +
|
||||
" or b.keyword4 like CONCAT('%',:#{#condition.keyWord},'%')" +
|
||||
" or b.keyword5 like CONCAT('%',:#{#condition.keyWord},'%'),1=1)" +
|
||||
" and if(:#{#condition.years} is not null ,YEAR(b.sys_create_time) in (:#{#condition.years}),1=1 )" +
|
||||
" and if(:#{#condition.majorType} is not null ,b.major_type = :#{#condition.majorType},1=1) " +
|
||||
" and if(:#{#condition.org1} is not null,b.org_domain_parent in (:#{#condition.org1}),1=1)" +
|
||||
" and if(:#{#condition.org2} is not null,b.org_domain_parent2 in (:#{#condition.org2}),1=1)" +
|
||||
" and if(:#{#condition.org3} is not null,b.org_domain_parent3 in (:#{#condition.org3}),1=1)" +
|
||||
" and if(coalesce(:#{#condition.years},null) is null OR YEAR(b.sys_create_time) in (:#{#condition.years}))" +
|
||||
" and if(:#{#condition.majorType} !='' ,b.major_type = :#{#condition.majorType},1=1) " +
|
||||
" and if(:#{#condition.org1Empty}, 1=1, b.org_domain_parent in (:#{#condition.org1}))" +
|
||||
" and if(:#{#condition.org2Empty}, 1=1, b.org_domain_parent2 in (:#{#condition.org2}))" +
|
||||
" and if(:#{#condition.org3Empty}, 1=1, b.org_domain_parent3 in (:#{#condition.org3}))" +
|
||||
" group by b.id order by a.sys_create_time DESC",
|
||||
countQuery = "select count(*)" +
|
||||
" from boe_cases_recommend_push_record a LEFT JOIN boe_cases b on a.case_id = b.id and b.deleted=0 " +
|
||||
@@ -50,11 +50,11 @@ public interface CasesRecordDao extends JpaRepository<Cases, String>, JpaSpecifi
|
||||
" or b.keyword3 like CONCAT('%',:#{#condition.keyWord},'%')" +
|
||||
" or b.keyword4 like CONCAT('%',:#{#condition.keyWord},'%')" +
|
||||
" or b.keyword5 like CONCAT('%',:#{#condition.keyWord},'%'),1=1)" +
|
||||
" and if(:#{#condition.years} is not null ,YEAR(b.sys_create_time) in (:#{#condition.years}),1=1 )" +
|
||||
" and if(:#{#condition.majorType} is not null ,b.major_type = :#{#condition.majorType},1=1) " +
|
||||
" and if(:#{#condition.org1} is not null,b.org_domain_parent in (:#{#condition.org1}),1=1)" +
|
||||
" and if(:#{#condition.org2} is not null,b.org_domain_parent2 in (:#{#condition.org2}),1=1)" +
|
||||
" and if(:#{#condition.org3} is not null,b.org_domain_parent3 in (:#{#condition.org3}),1=1)" +
|
||||
" and :#{#condition.yearsEmpty} = false OR YEAR(b.sys_create_time) in (:#{#condition.years})" +
|
||||
" and if(:#{#condition.majorType} !='' ,b.major_type = :#{#condition.majorType},1=1) " +
|
||||
" and if(:#{#condition.org1Empty}, 1=1, b.org_domain_parent in (:#{#condition.org1}))" +
|
||||
" and if(:#{#condition.org2Empty}, 1=1, b.org_domain_parent2 in (:#{#condition.org2}))" +
|
||||
" and if(:#{#condition.org3Empty}, 1=1, b.org_domain_parent3 in (:#{#condition.org3}))" +
|
||||
" group by b.id")
|
||||
Page<Cases> queryList(Pageable pageable, @Param("condition") CasePageVo casePage);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xboe.module.boecase.dto;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -61,6 +62,9 @@ public class CasePageVo extends PageDto {
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
public boolean isYearsEmpty() {
|
||||
return CollUtil.isEmpty(this.years);
|
||||
}
|
||||
|
||||
public List<String> getOrg1() {
|
||||
if (CollectionUtils.isNotEmpty(this.orgDomainDtos)) {
|
||||
@@ -69,6 +73,18 @@ public class CasePageVo extends PageDto {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isOrg1Empty() {
|
||||
return CollUtil.isEmpty(this.getOrg1());
|
||||
}
|
||||
|
||||
public boolean isOrg2Empty() {
|
||||
return CollUtil.isEmpty(this.getOrg2());
|
||||
}
|
||||
|
||||
public boolean isOrg3Empty() {
|
||||
return CollUtil.isEmpty(this.getOrg3());
|
||||
}
|
||||
|
||||
public List<String> getOrg2() {
|
||||
if (CollectionUtils.isNotEmpty(this.orgDomainDtos)) {
|
||||
return orgDomainDtos.stream().flatMap(it->it.getChildren().stream()).map(OrgDomainDto::getParent).filter(StrUtil::isNotBlank).collect(Collectors.toList());
|
||||
|
||||
@@ -331,13 +331,106 @@ public class CasesServiceImpl implements ICasesService {
|
||||
|
||||
@Override
|
||||
public PageList<Cases> queryRecommendPageCasesV2(CasePageVo caseVo) {
|
||||
PageRequest pageRequest = PageRequest.of(caseVo.getPageIndex(), caseVo.getPageSize());
|
||||
Page<Cases> cases = casesRecordDao.queryList(pageRequest, caseVo);
|
||||
PageList<Cases> pageList = new PageList<>();
|
||||
pageList.setCount((int) cases.getTotalElements());
|
||||
pageList.setPageSize(cases.getSize());
|
||||
pageList.setList(cases.getContent());
|
||||
return pageList;
|
||||
|
||||
PageList<Cases> page = null;
|
||||
QueryBuilder query=QueryBuilder.from("CasesRecommendPushRecord a, Cases b");
|
||||
query.addFields("b");
|
||||
query.addFilter(FieldFilters.eqField("a.caseId", "b.id"));
|
||||
query.addFilter(FieldFilters.eq("b.deleted",false));
|
||||
query.addFilter(FieldFilters.eq("a.pushUserId",caseVo.getUserId()));
|
||||
List<IFieldFilter> likes = new ArrayList<IFieldFilter>();
|
||||
String keyword = caseVo.getKeyWord();
|
||||
likes.add(FieldFilters.like("b.title", LikeMatchMode.ANYWHERE, keyword));
|
||||
likes.add(FieldFilters.like("b.authorName", LikeMatchMode.ANYWHERE, keyword));
|
||||
likes.add(FieldFilters.like("b.keyword1", LikeMatchMode.ANYWHERE, keyword));
|
||||
likes.add(FieldFilters.like("b.keyword2", LikeMatchMode.ANYWHERE, keyword));
|
||||
likes.add(FieldFilters.like("b.keyword3", LikeMatchMode.ANYWHERE, keyword));
|
||||
likes.add(FieldFilters.like("b.keyword4", LikeMatchMode.ANYWHERE, keyword));
|
||||
likes.add(FieldFilters.like("b.keyword5", LikeMatchMode.ANYWHERE, keyword));
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
|
||||
if (StringUtil.isNotBlank(caseVo.getKeyWord())) {
|
||||
filters.add(FieldFilters.or(likes));
|
||||
}
|
||||
//创建时间过滤
|
||||
List<Object> years = caseVo.getYears();
|
||||
if (CollUtil.isNotEmpty(years)) {
|
||||
filters.add(new CustomFieldInFilter("YEAR(b.sysCreateTime)", "b.sysCreateTime", years));
|
||||
}
|
||||
//增加只是查询有附件的
|
||||
filters.add(FieldFilters.isNotNull("b.filePath"));
|
||||
filters.add(FieldFilters.ne("b.filePath", ""));
|
||||
|
||||
String majorType = caseVo.getMajorType();
|
||||
if (StringUtil.isNotBlank(majorType)) {
|
||||
List<CasesMajorType> casesTypes = casesMajorTypeRepoDao.findCasesBy(StrUtil.split(majorType, ","));
|
||||
if (CollUtil.isNotEmpty(casesTypes)) {
|
||||
List<String> caseIds = casesTypes.stream().map(CasesMajorType::getCaseId).collect(Collectors.toList());
|
||||
query.addFilter(FieldFilters.in("b.id", caseIds));
|
||||
} else {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
List<OrgDomainDto> orgDomainDtos = caseVo.getOrgDomainDtos();
|
||||
IFieldFilter orgDomain = null;
|
||||
if (CollUtil.isNotEmpty(orgDomainDtos)) {
|
||||
for (int i = 0; i < orgDomainDtos.size(); i++) {
|
||||
OrgDomainDto domainDto = orgDomainDtos.get(i);
|
||||
String orgDomainParent = domainDto.getParent();
|
||||
IFieldFilter itemFilter = FieldFilters.eq("b.orgDomainParent", orgDomainParent);
|
||||
List<OrgDomainDto> orgDomainParent2 = domainDto.getChildren();
|
||||
if (CollUtil.isNotEmpty(orgDomainParent2)) {
|
||||
List<String> seconds = orgDomainParent2.stream().map(OrgDomainDto::getParent).collect(Collectors.toList());
|
||||
IFieldFilter orgDomainParentFilter = FieldFilters.in("b.orgDomainParent2", seconds);
|
||||
itemFilter = FieldFilters.and(itemFilter, orgDomainParentFilter);
|
||||
}
|
||||
for (OrgDomainDto orgDomainDto : orgDomainParent2) {
|
||||
List<OrgDomainDto> orgDomainParent3 = orgDomainDto.getChildren();
|
||||
if (CollUtil.isNotEmpty(orgDomainParent3)) {
|
||||
List<String> thirds = orgDomainParent3.stream().map(OrgDomainDto::getParent).collect(Collectors.toList());
|
||||
IFieldFilter orgDomainParent3Filter = FieldFilters.eq("b.orgDomainParent3", thirds);
|
||||
itemFilter = FieldFilters.and(itemFilter, orgDomainParent3Filter);
|
||||
}
|
||||
}
|
||||
if (i == 0) {
|
||||
orgDomain = itemFilter;
|
||||
} else {
|
||||
orgDomain = FieldFilters.or(orgDomain, itemFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Objects.nonNull(orgDomain)) {
|
||||
filters.add(orgDomain);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(caseVo.getCaseType())) {
|
||||
filters.add(FieldFilters.eq("b.caseType", caseVo.getCaseType()));
|
||||
}
|
||||
OrderCondition order = null;
|
||||
if (StringUtils.isNotBlank(caseVo.getOrderField())) {
|
||||
if (caseVo.getOrderAsc() == null || caseVo.getOrderAsc()) {
|
||||
order = OrderCondition.asc(caseVo.getOrderField());
|
||||
} else {
|
||||
order = OrderCondition.desc(caseVo.getOrderField());
|
||||
}
|
||||
} else {
|
||||
order = OrderCondition.desc("b.pushTime");
|
||||
}
|
||||
|
||||
query.addFilters(filters);
|
||||
query.addGroupBy("b.id");
|
||||
query.addOrder(order);
|
||||
query.addOrder(OrderCondition.rand());
|
||||
query.setPageIndex(caseVo.getPageIndex());
|
||||
query.setPageSize(caseVo.getPageSize());
|
||||
page = casesDao.findPage(query.builder());
|
||||
return page;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String rename = "a.name".replaceAll("\\.", "");
|
||||
System.out.println(rename);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,17 @@ class CasesServiceImplTest {
|
||||
System.out.println(casesV2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryRecommendPageCasesV2() throws JsonProcessingException {
|
||||
String jsonStr = "{\"pageIndex\":1,\"pageSize\":10,\"orderField\":\"excellent\",\"majorType\":\"\",\"orgDomainDtos\":[],\"orderAsc\":false,\"excellent\":true,\"breCommend\":true,\"caseType\":\"\",\"authorName\":\"\",\"notInIds\":[],\"type\":\"recommend\",\"userId\":\"\",\"parent\":\"\",\"children\":[],\"name\":\"\",\"years\":[2023,2022,2020,2021]}";
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||
CasePageVo pageVo = mapper.readValue(jsonStr, CasePageVo.class);
|
||||
pageVo.setUserId("965342027497607168");
|
||||
PageList<Cases> casesV2 = casesService.queryRecommendPageCasesV2(pageVo);
|
||||
System.out.println(casesV2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryCaseV2() {
|
||||
CurrentUser currentUser = new CurrentUser();
|
||||
|
||||
Reference in New Issue
Block a user