zhanghua
2023-07-05 8439887c903fa52560af52b40e12a1baa8a123d3
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
package com.ycl.controller.dingding;
 
import com.ycl.api.CommonResult;
import com.ycl.bo.AdminUserDetails;
import com.ycl.common.dingding.DingCommon;
import com.ycl.controller.BaseController;
import com.ycl.entity.dingding.DingUserInfo;
import com.ycl.service.auth.AuthService;
import com.ycl.service.ding.BookRemarkService;
import com.ycl.service.ding.DingService;
import com.ycl.vo.AddressBookVO;
import com.ycl.vo.NewAddressBookVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
@RequestMapping("/ding")
@Api(tags = "钉钉")
public class DingController extends BaseController {
 
    @Autowired
    private DingCommon dingCommon;
    @Value("${jwt.tokenHead}")
    private String tokenHead;
    /**
     * DING 免登
     * 根据临时授权码和access_token获取用户信息
     *
     * @author cjx
     */
 
    @Autowired
    private AuthService authService;
 
    @Autowired
    private DingService dingService;
 
    @Autowired
    private BookRemarkService bookRemarkService;
 
    @ApiOperation(value = "根据钉钉授权码获取token")
    @GetMapping("/dingLogin")
    public CommonResult<Map> dingLogin(@RequestParam String code) {
        HashMap<String, Object> map = new HashMap<>();
        //获取用户信息
        DingUserInfo dingUser = dingCommon.getDingUserInfo(code);
        //按ding登录
        String token = authService.dingLogin(dingUser);
        map.put("token", token);
        map.put("tokenHead", tokenHead);
        map.put("accountId", dingUser.getAccountId());
        return CommonResult.success(map);
    }
 
    @ApiOperation(value = "通讯录")
    @GetMapping("/addressBook")
    public CommonResult<List<AddressBookVO>> getAddressBook() {
        AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
 
        return CommonResult.success(dingService.getAddressBook(user.getUserId()));
    }
 
 
    @ApiOperation(value = "通讯录递归")
    @GetMapping("/addressBookById")
    public CommonResult<List<AddressBookVO>> getAddressBook(@RequestParam("id") Long id) {
        AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return CommonResult.success(dingService.getAddressBookByParentId(id, user.getUserId()));
    }
 
 
 
 
    @ApiOperation(value = "通讯录递归")
    @GetMapping("/getDddressBook")
    public CommonResult<NewAddressBookVO> getNewAddressBook(@RequestParam("id") Long id) {
        AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return CommonResult.success(dingService.getAddressBookById(id, user.getUserId()));
    }
 
 
 
    @ApiOperation(value = "修改通讯录备注")
    @PutMapping("/remark")
    public CommonResult updateRemark(@RequestParam("userId") Long userId, @RequestParam("remark") String remark) {
        AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return CommonResult.success(bookRemarkService.updateRemark(user, userId, remark));
    }
 
 
}