FollowController.java
7.57 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
package cn.fw.valhalla.controller.app;
import cn.fw.common.page.AppPage;
import cn.fw.common.web.auth.LoginAuthBean;
import cn.fw.common.web.auth.annotation.CurrentUser;
import cn.fw.data.base.domain.common.Message;
import cn.fw.security.auth.client.annotation.Authorization;
import cn.fw.security.auth.client.annotation.IgnoreAuth;
import cn.fw.security.auth.client.enums.AuthType;
import cn.fw.valhalla.domain.dto.FollowAttachmentDTO;
import cn.fw.valhalla.domain.enums.FollowTypeEnum;
import cn.fw.valhalla.domain.query.FollowQueryVO;
import cn.fw.valhalla.domain.vo.follow.FollowDetailVO;
import cn.fw.valhalla.domain.vo.follow.FollowRecordVO;
import cn.fw.valhalla.domain.vo.follow.FollowTodoListVO;
import cn.fw.valhalla.service.bus.follow.FollowBizService;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import static cn.fw.common.businessvalidator.Validator.BV;
import static cn.fw.common.web.util.ExceptionHandler.handleException;
import static cn.fw.common.web.util.ResultBuilder.failureWithMessage;
import static cn.fw.common.web.util.ResultBuilder.success;
import static cn.fw.valhalla.common.constant.MessageStr.QUERY_FAILURE;
/**
* @author : kurisu
* @className : FollowController
* @description : 跟进控制器
* @date: 2020-08-15 16:23
*/
@Slf4j
@RestController
@Authorization(AuthType.APP)
@Validated
@RequestMapping("/app/follow")
public class FollowController {
private final FollowBizService followBizService;
@Autowired
public FollowController(final FollowBizService followBizService) {
this.followBizService = followBizService;
}
@GetMapping("/todo/list")
public Message<AppPage<FollowTodoListVO>> todoList(@CurrentUser LoginAuthBean currentUser, final FollowQueryVO queryVO) {
final String msg = "分页查询 跟进待办列表[follow/todo/list]";
try {
log.info("{}: param[{}]", msg, queryVO.getType());
BV.notNull(queryVO.getType(), "跟进类型不正确");
AppPage<FollowTodoListVO> page = followBizService.todoList(queryVO, currentUser);
return success(page, data -> log.info("dataSize: {}", CollectionUtils.isEmpty(data.getData()) ? 0 : data.getData().size()));
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[{}]", msg, queryVO.getType(), e));
return failureWithMessage(QUERY_FAILURE);
}
}
@GetMapping("/todo/detail")
public Message<FollowDetailVO> todoDetail(@NotNull(message = "跟进记录id不能为空") final Long id,
@NotNull(message = "跟进类型不能为空") final Integer type) {
final String msg = "查询跟进待办详情[follow/todo/detail]";
try {
log.info("{}: param[{} {}]", msg, id, type);
FollowTypeEnum typeEnum = FollowTypeEnum.ofValue(type);
BV.notNull(typeEnum, "跟进类型不正确");
FollowDetailVO detailVO = followBizService.todoDetail(id, typeEnum);
return success(detailVO, data -> log.info("{}", data));
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[{} {}]", msg, id, type, e));
return failureWithMessage(QUERY_FAILURE);
}
}
@GetMapping("/approve/detail")
@IgnoreAuth
public Message<FollowDetailVO> approveDetail(@NotNull(message = "跟进记录id不能为空") final Long recordId,
@NotNull(message = "跟进类型不能为空") final Integer type) {
final String msg = "查询跟进战败审批详情[follow/approve/detail]";
try {
log.info("{}: param[{} {}]", msg, recordId, type);
FollowTypeEnum typeEnum = FollowTypeEnum.ofValue(type);
BV.notNull(typeEnum, "跟进类型不正确");
FollowDetailVO detailVO = followBizService.approveDetail(recordId, typeEnum);
return success(detailVO, data -> log.info("{}", data));
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[{} {}]", msg, recordId, type, e));
return failureWithMessage(QUERY_FAILURE);
}
}
@GetMapping("/todo/record")
@IgnoreAuth
public Message<List<FollowRecordVO>> todoRecord(@NotNull(message = "跟进任务id不能为空") final Long taskId,
@NotNull(message = "跟进类型不能为空") final Integer type) {
final String msg = "查询跟进历史记录[follow/todo/record]";
try {
log.info("{}: param[{} {}]", msg, taskId, type);
FollowTypeEnum typeEnum = FollowTypeEnum.ofValue(type);
BV.notNull(typeEnum, "跟进类型不正确");
return success(followBizService.todoRecord(taskId, typeEnum), data -> log.info("{}", data));
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[{} {}]", msg, taskId, type, e));
return failureWithMessage(QUERY_FAILURE);
}
}
@PostMapping("/defeat")
public Message<Void> defeat(@CurrentUser LoginAuthBean currentUser,
@NotNull(message = "跟进记录id不能为空") final Long id,
final String reason) {
final String msg = "主动战败[follow/defeat]";
try {
log.info("{}: param[recordId:{} reason:{}]", msg, id, reason);
followBizService.defeat(currentUser, reason, id);
log.info("操作成功");
return success();
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[{} {}]", msg, id, reason, e));
return failureWithMessage(QUERY_FAILURE);
}
}
@PostMapping("/todo/complete")
public Message<Void> complete(@CurrentUser LoginAuthBean currentUser,
@NotNull(message = "跟进记录id不能为空") final Long id,
@NotNull(message = "跟进类型不能为空") final Integer type) {
final String msg = "完成跟进待办[follow/todo/complete]";
try {
log.info("{}: param[{} {}]", msg, id, type);
FollowTypeEnum typeEnum = FollowTypeEnum.ofValue(type);
BV.notNull(typeEnum, "跟进类型不正确");
followBizService.completeRecord(id, typeEnum, currentUser);
log.info("操作成功");
return success();
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[{} {}]", msg, id, type, e));
return failureWithMessage(QUERY_FAILURE);
}
}
@PostMapping("/todo/upload")
public Message<Void> upload(@CurrentUser LoginAuthBean currentUser, @RequestBody @Valid final FollowAttachmentDTO dto) {
final String msg = "上传跟进凭证[follow/todo/upload]";
try {
log.info("{}: param[{}]", msg, dto);
BV.notNull(dto.getFollowType(), "跟进类型不正确");
followBizService.uploadAtt(dto, currentUser);
log.info("操作成功");
return success();
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[{}]", msg, dto, e));
return failureWithMessage(QUERY_FAILURE);
}
}
}