yangys
2024-05-07 ec2552d891e163bd9054e0554188afc575bcdb70
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
package com.qianwen.smartman.modules.sync.controller;
 
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.sync.constant.DingConstant;
import com.qianwen.smartman.modules.sync.constant.OuterAppConfigConstant;
import com.qianwen.smartman.modules.sync.entity.OuterAppConfig;
import com.qianwen.smartman.modules.sync.service.IDingSyncService;
import com.qianwen.smartman.modules.sync.service.IOuterAppConfigService;
import com.qianwen.smartman.modules.sync.vo.SyncResultVO;
import com.qianwen.smartman.modules.system.service.IUserOauthService;
import com.qianwen.smartman.modules.system.service.IUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
@RequestMapping({"blade-sync/ding-sync"})
@Api(value = "钉钉通讯录同步", tags = {"钉钉通讯录同步"})
@RestController
public class DingSyncController {
    private final IUserService userService;
    private final IUserOauthService userOauthService;
    private final IDingSyncService dingSyncService;
    private final IOuterAppConfigService outerAppConfigService;
 
    public DingSyncController(final IUserService userService, final IUserOauthService userOauthService, final IDingSyncService dingSyncService, final IOuterAppConfigService outerAppConfigService) {
        this.userService = userService;
        this.userOauthService = userOauthService;
        this.dingSyncService = dingSyncService;
        this.outerAppConfigService = outerAppConfigService;
    }
 
    @ApiOperationSupport(order = 1)
    @GetMapping({"/sync-immediately"})
    @ApiOperation(value = "钉钉立即同步", notes = "")
    public R sync() {
        OuterAppConfig outerAppConfig = this.outerAppConfigService.getAppConfig(OuterAppConfigConstant.DING);
        if (Func.isNotEmpty(outerAppConfig) && outerAppConfig.getStatus().equals(CommonConstant.ENABLE)) {
            SyncResultVO syncResultVO = this.dingSyncService.syncImmediately();
            return R.data(syncResultVO);
        }
        return R.fail(MessageUtils.message("sys.outer.config.is.bind", new Object[0]));
    }
 
    @ApiOperationSupport(order = 2)
    @GetMapping({"/scan"})
    @ApiOperation(value = "钉钉扫码绑定", notes = "")
    public R<T> scanCodeBind(@RequestParam("code") String code, @RequestParam("state") String state) {
        return R.status(this.dingSyncService.scanCodeBind(code, state).booleanValue());
    }
 
    @ApiOperationSupport(order = 2)
    @GetMapping({"/unbind/{id}"})
    @ApiOperation(value = "钉钉解绑", notes = "")
    public R<T> unbind(@PathVariable Long id) {
        return R.status(this.dingSyncService.unbind(id, DingConstant.DING_AUTH_KEY).booleanValue());
    }
}