|
|
@ -30,7 +30,6 @@ import com.crm.opportunity.mapper.OpportunitySchemeCardMapper; |
|
|
import com.crm.opportunity.mapper.OpportunityStageHistoryMapper; |
|
|
import com.crm.opportunity.mapper.OpportunityStageHistoryMapper; |
|
|
import com.crm.opportunity.mapper.OpportunityViewLogMapper; |
|
|
import com.crm.opportunity.mapper.OpportunityViewLogMapper; |
|
|
import com.crm.opportunity.query.OpportunityViewQuery; |
|
|
import com.crm.opportunity.query.OpportunityViewQuery; |
|
|
import com.crm.preference.domain.dto.SavedView; |
|
|
|
|
|
import com.crm.preference.service.SavedViewService; |
|
|
import com.crm.preference.service.SavedViewService; |
|
|
import com.crm.rule.domain.dto.SysRegionDTO; |
|
|
import com.crm.rule.domain.dto.SysRegionDTO; |
|
|
import com.crm.rule.domain.entity.OpportunityStageNode; |
|
|
import com.crm.rule.domain.entity.OpportunityStageNode; |
|
|
@ -101,8 +100,13 @@ public class OpportunityViewQueryImpl implements OpportunityViewQuery { |
|
|
|
|
|
|
|
|
LambdaQueryWrapper<Opportunity> wrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<Opportunity> wrapper = new LambdaQueryWrapper<>(); |
|
|
applyViewFilters(wrapper, param, currentUserId); |
|
|
applyViewFilters(wrapper, param, currentUserId); |
|
|
applySavedView(wrapper, param, currentUserId); |
|
|
String savedViewOrderBy = applySavedView(wrapper, param, currentUserId); |
|
|
|
|
|
if (StrUtil.isNotBlank(savedViewOrderBy)) { |
|
|
|
|
|
// 自定义视图排序(票 14 定义 2)替代默认 createTime 倒序
|
|
|
|
|
|
wrapper.last("ORDER BY " + savedViewOrderBy); |
|
|
|
|
|
} else { |
|
|
wrapper.orderByDesc(Opportunity::getCreateTime); |
|
|
wrapper.orderByDesc(Opportunity::getCreateTime); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Page<Opportunity> page = opportunityMapper.selectPage(PageConverter.toMpPage(param), wrapper); |
|
|
Page<Opportunity> page = opportunityMapper.selectPage(PageConverter.toMpPage(param), wrapper); |
|
|
PageResult<OpportunityDTO> result = new PageResult<>(page).convert(OpportunityDTO::fromEntity); |
|
|
PageResult<OpportunityDTO> result = new PageResult<>(page).convert(OpportunityDTO::fromEntity); |
|
|
@ -131,6 +135,7 @@ public class OpportunityViewQueryImpl implements OpportunityViewQuery { |
|
|
LambdaQueryWrapper<Opportunity> wrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<Opportunity> wrapper = new LambdaQueryWrapper<>(); |
|
|
wrapper.in(Opportunity::getId, orderedIds); |
|
|
wrapper.in(Opportunity::getId, orderedIds); |
|
|
applyCommonFilters(wrapper, param); |
|
|
applyCommonFilters(wrapper, param); |
|
|
|
|
|
// RECENT 为时间序(view_log 倒序),自定义视图仅叠加条件过滤,不接排序(时间序优先)
|
|
|
applySavedView(wrapper, param, currentUserId); |
|
|
applySavedView(wrapper, param, currentUserId); |
|
|
wrapper.last("order by field(id," + orderedIds.stream() |
|
|
wrapper.last("order by field(id," + orderedIds.stream() |
|
|
.map(String::valueOf).collect(Collectors.joining(",")) + ")"); |
|
|
.map(String::valueOf).collect(Collectors.joining(",")) + ")"); |
|
|
@ -449,21 +454,26 @@ public class OpportunityViewQueryImpl implements OpportunityViewQuery { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 自定义视图条件叠加(票 14):{@code param.savedViewId} 非空时,读当前用户 |
|
|
* 自定义视图叠加(票 14):{@code param.savedViewId} 非空时,读当前用户 |
|
|
* {@code opportunity.sales} scope 下该视图的检索条件,翻译后 AND 叠在当前数据集之上。 |
|
|
* {@code opportunity.sales} scope 下该视图,把检索条件翻译后 AND 叠在当前数据集之上, |
|
|
* <p>视图不存在(已删 / 非本人)→ 无额外条件(等价写回未选自定义视图)。 |
|
|
* 并返回排序列片段供调用方替代默认排序。 |
|
|
* 排序(sortField/sortDirection)本期不入库级排序(列表默认按 createTime),留后续实现。</p> |
|
|
* <p>视图不存在(已删 / 非本人)或 savedViewId 空 → 返回 {@code null}(无额外条件且回落默认排序)。</p> |
|
|
|
|
|
* |
|
|
|
|
|
* @return 自定义视图排序列片段(如 {@code "owner_user_id DESC"});无排序 / 排序字段不在字段池 → {@code null} |
|
|
*/ |
|
|
*/ |
|
|
private void applySavedView(LambdaQueryWrapper<Opportunity> wrapper, |
|
|
private String applySavedView(LambdaQueryWrapper<Opportunity> wrapper, |
|
|
OpportunityPageParam param, Long currentUserId) { |
|
|
OpportunityPageParam param, Long currentUserId) { |
|
|
if (StrUtil.isBlank(param.getSavedViewId())) { |
|
|
if (StrUtil.isBlank(param.getSavedViewId())) { |
|
|
return; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
savedViewService.list(currentUserId, SAVED_VIEW_SCOPE).stream() |
|
|
return savedViewService.list(currentUserId, SAVED_VIEW_SCOPE).stream() |
|
|
.filter(v -> param.getSavedViewId().equals(v.viewId())) |
|
|
.filter(v -> param.getSavedViewId().equals(v.viewId())) |
|
|
.findFirst() |
|
|
.findFirst() |
|
|
.map(SavedView::conditions) |
|
|
.map(v -> { |
|
|
.ifPresent(conditions -> savedViewFilter.apply(wrapper, conditions)); |
|
|
savedViewFilter.apply(wrapper, v.conditions()); |
|
|
|
|
|
return savedViewFilter.orderByClause(v.sortField(), v.sortDirection()); |
|
|
|
|
|
}) |
|
|
|
|
|
.orElse(null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private Long getCurrentUserId() { |
|
|
private Long getCurrentUserId() { |
|
|
|