FollowApiServiceImpl.java
7.9 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package cn.fw.shirasawa.server.controller.api;
import cn.fw.common.web.annotation.ControllerMethod;
import cn.fw.data.base.domain.common.Message;
import cn.fw.shirasawa.common.utils.MessageFormatUtil;
import cn.fw.shirasawa.domain.dto.FollowTaskCompleteDTO;
import cn.fw.shirasawa.domain.dto.FollowTerminationDTO;
import cn.fw.shirasawa.domain.dto.OriginalDataDTO;
import cn.fw.shirasawa.domain.enums.FollowTypeEnum;
import cn.fw.shirasawa.sdk.api.FollowApiService;
import cn.fw.shirasawa.sdk.enums.BusinessTypeEnum;
import cn.fw.shirasawa.sdk.enums.DataTypeEnum;
import cn.fw.shirasawa.sdk.param.*;
import cn.fw.shirasawa.sdk.result.SucessFollowRecordVo;
import cn.fw.shirasawa.service.bus.follow.FollowBizService;
import cn.fw.shirasawa.service.bus.follow.OriginalDataBizService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import static cn.fw.common.businessvalidator.Validator.BV;
import static cn.fw.common.web.util.ResultBuilder.success;
/**
* @author : kurisu
* @className : FollowApiServiceImpl
* @description : 跟进api
* @date: 2020-08-14 17:53
*/
@Slf4j
@RestController
@RequestMapping("/api/shirasawa/follow")
public class FollowApiServiceImpl implements FollowApiService {
@Value("${follow.max-size}")
@Getter
private int maxSize;
private final OriginalDataBizService originalDataBizService;
private final FollowBizService followBizService;
@Autowired
public FollowApiServiceImpl(final OriginalDataBizService originalDataBizService,
final FollowBizService followBizService) {
this.originalDataBizService = originalDataBizService;
this.followBizService = followBizService;
}
@Override
@PostMapping("/generate")
@ControllerMethod("生成跟进任务")
public Message<Void> generate(@Valid @RequestBody FollowGenerateDTO generateDTO) {
if (BusinessTypeEnum.PS.equals(generateDTO.getBusinessType())) {
BV.notNull(generateDTO.getMemberId(), () -> "会员号不能为空");
BV.notNull(generateDTO.getCustomerId(), () -> "档案id不能为空");
}
if (DataTypeEnum.AC.equals(generateDTO.getType())) {
BV.isNotBlank(generateDTO.getPlateNo(), () -> "车牌号不能为空");
BV.isNotBlank(generateDTO.getContacts(), () -> "联系方式不能为空");
}
if (BusinessTypeEnum.AS.equals(generateDTO.getBusinessType()) && !DataTypeEnum.AC.equals(generateDTO.getType())) {
BV.isNotBlank(generateDTO.getFrameNo(), () -> "车架号不能为空");
}
OriginalDataDTO dataDTO = new OriginalDataDTO();
BeanUtils.copyProperties(generateDTO, dataDTO);
DataTypeEnum type = generateDTO.getType();
dataDTO.setDataType(type.getValue());
dataDTO.setBizType(generateDTO.getBusinessType());
originalDataBizService.saveOrigin(dataDTO);
return success();
}
@Override
@PostMapping("/generate_batch")
@ControllerMethod("批量生成跟进任务")
public Message<Void> generateBatch(@Valid @RequestBody CustomList<FollowGenerateDTO> paramList) {
BV.isNotEmpty(paramList, () -> "列表不能为空");
BV.isTrue(paramList.size() <= getMaxSize(), () -> MessageFormatUtil.MessageFormatTransfer("最多支持一次性生成{0}条任务", getMaxSize()));
List<OriginalDataDTO> list = new ArrayList<>();
for (FollowGenerateDTO param : paramList) {
if (BusinessTypeEnum.PS.equals(param.getBusinessType())) {
BV.notNull(param.getCustomerId(), () -> "档案id不能为空");
}
if (DataTypeEnum.AC.equals(param.getType())) {
BV.isNotBlank(param.getPlateNo(), () -> "车牌号不能为空");
BV.isNotBlank(param.getContacts(), () -> "联系方式不能为空");
}
if (BusinessTypeEnum.AS.equals(param.getBusinessType()) && !DataTypeEnum.AC.equals(param.getType())) {
BV.isNotBlank(param.getFrameNo(), () -> "车架号不能为空");
}
OriginalDataDTO dataDTO = new OriginalDataDTO();
BeanUtils.copyProperties(param, dataDTO);
dataDTO.setDataType(param.getType().getValue());
dataDTO.setBizType(param.getBusinessType());
list.add(dataDTO);
}
originalDataBizService.saveBatchOrigin(list);
return success();
}
@Override
@PutMapping("/complete/record")
@ControllerMethod("完成跟进待办")
public Message<Void> completeFollow(@RequestParam("recordId") Long recordId, @RequestParam("userId") Long userId) {
followBizService.completeRecord(recordId, userId);
return success();
}
@Override
@PostMapping("/create/record")
@ControllerMethod("生成下一次待办")
public Message<Boolean> createNextRecord(@Valid @RequestBody NewRecordDTO newRecordDTO) {
return success(followBizService.createNewRecord(newRecordDTO));
}
@Override
@PostMapping("/complete/task")
@ControllerMethod("完成跟进任务")
public Message<Void> completeTask(@Valid @RequestBody TaskCompleteDTO taskCompleteDTO) {
FollowTaskCompleteDTO dto = new FollowTaskCompleteDTO();
BeanUtils.copyProperties(taskCompleteDTO, dto);
dto.setFollowType(FollowTypeEnum.ofValue(taskCompleteDTO.getType().getValue()));
dto.setBizType(taskCompleteDTO.getBusinessType());
followBizService.completeTask(dto);
return success();
}
@Override
@PostMapping("/termination/task")
@ControllerMethod("终止跟进任务")
public Message<Void> terminationTask(@Valid @RequestBody TerminationDTO terminationDTO) {
FollowTerminationDTO followTerminationDTO = new FollowTerminationDTO();
BeanUtils.copyProperties(terminationDTO, followTerminationDTO);
followTerminationDTO.setFollowType(FollowTypeEnum.ofValue(terminationDTO.getType().getValue()));
followTerminationDTO.setBizType(terminationDTO.getBusinessType());
followBizService.terminationTask(followTerminationDTO);
return success();
}
@Override
@PostMapping("/termination_batch")
@ControllerMethod("批量终止跟进任务")
public Message<Void> terminationBatch(@Valid @RequestBody CustomList<TerminationDTO> paramList) {
BV.isNotEmpty(paramList, () -> "列表不能为空");
BV.isTrue(paramList.size() <= getMaxSize(), () -> MessageFormatUtil.MessageFormatTransfer("最多支持一次性结束{0}条任务", getMaxSize()));
List<FollowTerminationDTO> list = new ArrayList<>();
for (TerminationDTO dto : paramList) {
FollowTerminationDTO followTerminationDTO = new FollowTerminationDTO();
BeanUtils.copyProperties(dto, followTerminationDTO);
followTerminationDTO.setFollowType(FollowTypeEnum.ofValue(dto.getType().getValue()));
followTerminationDTO.setBizType(dto.getBusinessType());
list.add(followTerminationDTO);
}
followBizService.terminationTaskBatch(list);
return success();
}
@Override
@GetMapping("/getCompletedFollowRecord")
@ControllerMethod("获取已完成的跟进记录")
public Message<List<SucessFollowRecordVo>> getCompletedFollowRecord(@RequestParam("bizType") @NotNull(message = "业务类型不能为空!") Integer bizType,
@RequestParam("customerId") @NotEmpty(message = "档案id不能为空!") List<Long> customerId) {
return success(followBizService.getCompletedFollowRecord(bizType, customerId));
}
}