SFFollowStrategy.java
3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package cn.fw.shirasawa.service.bus.follow.strategy.impl;
import cn.fw.shirasawa.domain.db.OriginalData;
import cn.fw.shirasawa.domain.db.follow.FollowRecord;
import cn.fw.shirasawa.domain.db.follow.FollowTask;
import cn.fw.shirasawa.domain.db.pool.CluePool;
import cn.fw.shirasawa.domain.enums.ClueStatusEnum;
import cn.fw.shirasawa.domain.enums.FollowTypeEnum;
import cn.fw.shirasawa.service.bus.follow.strategy.AbstractFollowStrategy;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static cn.fw.common.businessvalidator.Validator.BV;
/**
* 补贴跟进
*
* @author : kurisu
* @version : 1.0
* @className : SFFollowStrategy
* @description : 补贴跟进
* @date : 2023-03-13 15:16
*/
@Slf4j
@Component
@SuppressWarnings("Duplicates")
public class SFFollowStrategy extends AbstractFollowStrategy {
@Value("${follow.todo.SFCode}")
@Getter
private String SFCode;
@Override
public FollowTypeEnum getFollowType() {
return FollowTypeEnum.SF;
}
@Override
public String getTodoCode() {
return getSFCode();
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean origin2task(OriginalData originalData) throws Exception {
List<CluePool> list = cluePoolService.list(Wrappers.<CluePool>lambdaQuery()
.eq(CluePool::getClueType, getFollowType())
.eq(CluePool::getCustomerId, originalData.getCustomerId())
.eq(CluePool::getRefererId, originalData.getDetailId())
.eq(CluePool::getGroupId, originalData.getGroupId())
.in(CluePool::getClueStatus, ClueStatusEnum.ONGOING, ClueStatusEnum.WAITING)
);
if (!CollectionUtils.isEmpty(list)) {
return true;
}
CluePool cluePool = transformClue(originalData);
cluePool.setStartTime(originalData.getGenerateTime());
LocalDateTime deadLine = Optional.ofNullable(originalData.getDeadline()).orElse(LocalDate.now().plusYears(10L).atStartOfDay());
cluePool.setDeadline(deadLine.minusSeconds(1L));
return cluePoolService.save(cluePool);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void startClue(CluePool cluePool) throws Exception {
dealRepeatClue(cluePool, this);
FollowTask task = this.createTask(cluePool);
boolean saveTask = followTaskService.save(task);
BV.isTrue(saveTask, () -> "生成跟进任务失败");
FollowRecord record = createRecord(task);
record.setTodoCode(getTodoCode());
record.setNote(cluePool.getNote());
record.setContacts(cluePool.getContacts());
if (Objects.nonNull(cluePool.getFirstDeadline())) {
record.setDeadline(cluePool.getFirstDeadline());
}
followRecordService.save(record);
cluePool.setClueStatus(ClueStatusEnum.ONGOING);
cluePoolService.updateById(cluePool);
}
}