|
|
@@ -32,13 +32,14 @@ public class KeyPersonService {
|
|
|
Page<OctopusEffectRecord> p = new Page<>(page, pageSize);
|
|
|
LambdaQueryWrapper<OctopusEffectRecord> q = new LambdaQueryWrapper<OctopusEffectRecord>()
|
|
|
.eq(OctopusEffectRecord::getUserId, userId);
|
|
|
- if (effectType != null && effectType > 0) {
|
|
|
- q.apply("effect_type & {0}", effectType);
|
|
|
- }
|
|
|
q.orderByDesc(OctopusEffectRecord::getCreatedAt);
|
|
|
effectRecordMapper.selectPage(p, q);
|
|
|
|
|
|
- List<Map<String, Object>> list = p.getRecords().stream().map(this::toEffectVO).collect(Collectors.toList());
|
|
|
+ // 自动计算标签
|
|
|
+ Map<Long, List<String>> typeMap = computeEffectTypes(p.getRecords());
|
|
|
+ List<Map<String, Object>> list = p.getRecords().stream()
|
|
|
+ .map(r -> toEffectVO(r, typeMap.getOrDefault(r.getId(), new ArrayList<>())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
Map<String, Object> data = new LinkedHashMap<>();
|
|
|
data.put("list", list);
|
|
|
data.put("total", p.getTotal());
|
|
|
@@ -47,12 +48,12 @@ public class KeyPersonService {
|
|
|
return Result.success(data);
|
|
|
}
|
|
|
|
|
|
- private Map<String, Object> toEffectVO(OctopusEffectRecord r) {
|
|
|
+ private Map<String, Object> toEffectVO(OctopusEffectRecord r, List<String> computedTypes) {
|
|
|
Map<String, Object> m = new LinkedHashMap<>();
|
|
|
m.put("id", r.getId());
|
|
|
m.put("memberOrderId", r.getMemberOrderId());
|
|
|
m.put("effectType", r.getEffectType());
|
|
|
- m.put("effectTypeList", parseEffectType(r.getEffectType()));
|
|
|
+ m.put("effectTypeList", computedTypes);
|
|
|
m.put("effectAmount", r.getEffectAmount());
|
|
|
m.put("effectDesc", r.getEffectDesc());
|
|
|
m.put("status", r.getStatus());
|
|
|
@@ -60,13 +61,76 @@ public class KeyPersonService {
|
|
|
return m;
|
|
|
}
|
|
|
|
|
|
- private List<String> parseEffectType(Integer type) {
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
- if (type == null) return list;
|
|
|
- if ((type & 1) != 0) list.add("金额大");
|
|
|
- if ((type & 2) != 0) list.add("频次高");
|
|
|
- if ((type & 4) != 0) list.add("新成交");
|
|
|
- return list;
|
|
|
+ /**
|
|
|
+ * 自动计算成效类型标签:
|
|
|
+ * - 金额大:金额 Top 3
|
|
|
+ * - 频次高:与某关键人的成交次数最多
|
|
|
+ * - 新成交:时间最近的1条
|
|
|
+ */
|
|
|
+ private Map<Long, List<String>> computeEffectTypes(List<OctopusEffectRecord> records) {
|
|
|
+ Map<Long, List<String>> typeMap = new HashMap<>();
|
|
|
+ if (records.isEmpty()) return typeMap;
|
|
|
+
|
|
|
+ // 初始化所有记录为空列表
|
|
|
+ for (OctopusEffectRecord r : records) {
|
|
|
+ typeMap.put(r.getId(), new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 金额大:按金额降序取 Top 3
|
|
|
+ List<OctopusEffectRecord> sortedByAmount = new ArrayList<>(records);
|
|
|
+ sortedByAmount.sort((a, b) -> {
|
|
|
+ BigDecimal amtA = a.getEffectAmount() != null ? a.getEffectAmount() : BigDecimal.ZERO;
|
|
|
+ BigDecimal amtB = b.getEffectAmount() != null ? b.getEffectAmount() : BigDecimal.ZERO;
|
|
|
+ return amtB.compareTo(amtA);
|
|
|
+ });
|
|
|
+ for (int i = 0; i < Math.min(3, sortedByAmount.size()); i++) {
|
|
|
+ typeMap.get(sortedByAmount.get(i).getId()).add("金额大");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 频次高:统计每个关键人的成交次数,取最多的
|
|
|
+ Map<Long, Long> personCount = new HashMap<>();
|
|
|
+ for (OctopusEffectRecord r : records) {
|
|
|
+ List<OctopusEffectKeyPerson> rels = ekpMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<OctopusEffectKeyPerson>().eq(OctopusEffectKeyPerson::getEffectId, r.getId())
|
|
|
+ );
|
|
|
+ for (OctopusEffectKeyPerson rel : rels) {
|
|
|
+ personCount.put(rel.getKeyPersonId(), personCount.getOrDefault(rel.getKeyPersonId(), 0L) + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!personCount.isEmpty()) {
|
|
|
+ Long maxCount = personCount.values().stream().max(Long::compareTo).orElse(0L);
|
|
|
+ if (maxCount >= 2) { // 只有频次>=2才标记
|
|
|
+ for (Map.Entry<Long, Long> entry : personCount.entrySet()) {
|
|
|
+ if (entry.getValue() == maxCount) {
|
|
|
+ // 找到该关键人的所有成效记录
|
|
|
+ for (OctopusEffectRecord r : records) {
|
|
|
+ List<OctopusEffectKeyPerson> rels = ekpMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<OctopusEffectKeyPerson>()
|
|
|
+ .eq(OctopusEffectKeyPerson::getEffectId, r.getId())
|
|
|
+ .eq(OctopusEffectKeyPerson::getKeyPersonId, entry.getKey())
|
|
|
+ );
|
|
|
+ if (!rels.isEmpty()) {
|
|
|
+ typeMap.get(r.getId()).add("频次高");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 新成交:时间最近的1条
|
|
|
+ OctopusEffectRecord newest = records.stream()
|
|
|
+ .max((a, b) -> {
|
|
|
+ if (a.getCreatedAt() == null) return -1;
|
|
|
+ if (b.getCreatedAt() == null) return 1;
|
|
|
+ return a.getCreatedAt().compareTo(b.getCreatedAt());
|
|
|
+ })
|
|
|
+ .orElse(null);
|
|
|
+ if (newest != null) {
|
|
|
+ typeMap.get(newest.getId()).add("新成交");
|
|
|
+ }
|
|
|
+
|
|
|
+ return typeMap;
|
|
|
}
|
|
|
|
|
|
public Result<OctopusEffectRecord> addEffect(Long userId, Long memberOrderId, Integer effectType,
|