CommonController.java
3.27 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
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.annotation.IgnoreUserToken;
import cn.fw.security.auth.client.enums.AuthType;
import cn.fw.valhalla.domain.vo.PostUserVO;
import cn.fw.valhalla.service.bus.CommonService;
import cn.fw.valhalla.service.bus.LeaveNeedDoBizService;
import lombok.extern.slf4j.Slf4j;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
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
@Authorization(AuthType.APP)
@Validated
@RequestMapping("/app/common")
public class CommonController {
private final CommonService commonService;
private final LeaveNeedDoBizService leaveNeedDoBizService;
@Autowired
public CommonController(final CommonService commonService,
final LeaveNeedDoBizService leaveNeedDoBizService) {
this.commonService = commonService;
this.leaveNeedDoBizService = leaveNeedDoBizService;
}
@GetMapping("/staff/list")
@IgnoreAuth
public Message<List<PostUserVO>> list(@NotNull(message = "服务站ID不能为空") final Long shopId,
@NotNull(message = "跟进类型不能为空") final Integer type) {
final String msg = "查询跟进人员[app/common/staff/list]";
try {
log.info("{}: param[shopId: {} type: {}]", msg, shopId, type);
List<PostUserVO> list = commonService.getUsers(shopId, type);
return success(list, data -> log.info("{}", data));
} catch (Exception ex) {
handleException(ex, e -> log.error("{}失败:param[shopId: {} type: {}]", msg, shopId, type, e));
return failureWithMessage(SAVE_FAILURE);
}
}
@PutMapping("/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);
}
}
}