CommonController.java
6.31 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
package cn.fw.valhalla.controller.app;
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.common.utils.DateUtil;
import cn.fw.valhalla.domain.vo.PostUserVO;
import cn.fw.valhalla.service.bus.CommonService;
import cn.fw.valhalla.service.bus.CustomerImportBizService;
import cn.fw.valhalla.service.bus.CustomerRetentionRatioBizService;
import cn.fw.valhalla.service.bus.LeaveNeedDoBizService;
import cn.fw.valhalla.service.data.FollowRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
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.SAVE_FAILURE;
/**
* @author : kurisu
* @className : CommonController
* @description : 公共接口
* @date: 2020-10-22 11:06
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@Authorization(AuthType.APP)
@Validated
@RequestMapping("/app/common")
public class CommonController {
private final CommonService commonService;
private final LeaveNeedDoBizService leaveNeedDoBizService;
private final CustomerImportBizService customerImportBizService;
private final CustomerRetentionRatioBizService customerRetentionRatioBizService;
@GetMapping("/staff/list")
@IgnoreAuth
public Message<List<PostUserVO>> list(@NotNull(message = "服务站ID不能为空") final Long shopId) {
final String msg = "查询人员[app/common/staff/list]";
try {
log.info("{}: param[shopId: {}]", msg, shopId);
List<PostUserVO> list = commonService.getUsers(shopId);
return success(list, data -> log.info("{}", data));
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[shopId: {}]", msg, shopId, e));
return failureWithMessage(SAVE_FAILURE);
}
}
@GetMapping("/leave/add")
@Authorization(AuthType.NONE)
public Message<Void> add(@NotNull(message = "服务站ID不能为空") final Long shopId,
@NotNull(message = "用户ID不能为空") final Long userId) {
final String msg = "添加离职待分配数据[app/common/leave/add]";
try {
log.info("{}: param[shopId: {} userId: {}]", msg, shopId, userId);
leaveNeedDoBizService.add(userId, shopId);
return success();
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[shopId: {} userId: {}]", msg, shopId, userId, e));
return failureWithMessage(SAVE_FAILURE);
}
}
@GetMapping("/import/deal")
@Authorization(AuthType.NONE)
public Message<Void> dealImport() {
final String msg = "处理导入的档案数据[app/common/import/deal]";
try {
log.info("{} 开始", msg);
customerImportBizService.integrated();
log.info("{} 结束", msg);
return success();
} catch (Exception ex) {
handleException(ex, e -> log.error("{} 失败", msg, e));
return failureWithMessage(SAVE_FAILURE);
}
}
@GetMapping("/import/apportion")
@Authorization(AuthType.NONE)
public Message<Void> apportion() {
final String msg = "导入的档案分配顾问[app/common/import/apportion]";
try {
log.info("{} 开始", msg);
customerImportBizService.apportion();
log.info("{} 结束", msg);
return success();
} catch (Exception ex) {
handleException(ex, e -> log.error("{} 失败", msg, e));
return failureWithMessage(SAVE_FAILURE);
}
}
@GetMapping("/crr/extracting")
@Authorization(AuthType.NONE)
public Message<Void> crrExtracting(String date) {
final String msg = "抽取保有客保持率数据[app/common/crr/extracting]";
try {
log.info("{} 开始", msg);
Date nowDate = new Date();
if (StringUtils.isNotBlank(date) && NumberUtils.isDigits(date)) {
LocalDateTime localDateTime = Instant.ofEpochMilli(NumberUtils.toLong(date)).atZone(ZoneId.systemDefault()).toLocalDateTime();
nowDate = DateUtil.localDateTime2Date(localDateTime);
}
customerRetentionRatioBizService.extracting(DateUtil.startDate(nowDate));
log.info("{} 结束", msg);
return success();
} catch (Exception ex) {
handleException(ex, e -> log.error("{} 失败", msg, e));
return failureWithMessage(SAVE_FAILURE);
}
}
/**
* 交车后取消订单时回滚档案
*
* @param vin
* @return
*/
@GetMapping("/customer/rollback")
@Authorization(AuthType.NONE)
public Message<Void> customerRollback(@NotBlank(message = "车架号不能为空") String vin,
@RequestParam(defaultValue = "2", required = false, name = "groupId") Long groupId) {
final String msg = "交车后取消订单时回滚档案[app/common/customer/rollback]";
try {
log.info("{} param[vin: {} groupId: {}]", msg, vin, groupId);
commonService.rollBack(vin, groupId);
return success();
} catch (Exception ex) {
handleException(ex, e -> log.error("{} 失败 param[vin: {} groupId: {}]", msg, vin, groupId, e));
return failureWithMessage(SAVE_FAILURE);
}
}
}