tjx
2025-11-25 2c1a6f5df6ca8938e5e71b4c51e0e8315cf7f45a
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
package com.gs.xky;
 
import com.gs.xky.service.VwCjScSjTsBbService;
import com.gs.xky.service.WorkWXService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
 
import java.io.IOException;
import java.util.List;
 
@SpringBootTest
class XkyApplicationTests {
 
 
    @Autowired
    private VwCjScSjTsBbService vwCjScSjTsBbService;
 
    @Autowired
    private WorkWXService workWXService;
 
    /**
     * 测试导出生产数据并发送钉钉消息
     * 功能:查询VW_CJ_SC_SJ_TS_BB表数据 -> 导出Excel -> 发送钉钉文件消息
     */
    @Test
    void testExportAndSendProductionData() throws Exception {
        System.out.println("=== 开始测试导出生产数据并发送钉钉 ===");
 
        try {
            boolean result = vwCjScSjTsBbService.exportAndSendToDingtalk();
 
            if (result) {
                System.out.println("✓ 生产数据导出并发送成功");
                System.out.println("  - 数据已从 VW_CJ_SC_SJ_TS_BB 表查询");
                System.out.println("  - Excel 文件已生成并保存到 D:\\BIFile\\");
                System.out.println("  - 钉钉文件消息已发送");
            } else {
                System.out.println("✗ 生产数据导出或发送失败");
            }
        } catch (Exception e) {
            System.out.println("✗ 导出并发送时发生异常: " + e.getMessage());
            e.printStackTrace();
        }
 
        System.out.println("=== 测试结束 ===");
    }
 
    /**
     * 测试获取企业微信access_token
     * 功能:调用企业微信API获取access_token
     */
    @Test
    void testGetWorkWXAccessToken() {
        System.out.println("=== 开始测试获取企业微信access_token ===");
 
        try {
            String accessToken = workWXService.getAccessToken();
 
            if (accessToken != null && !accessToken.isEmpty()) {
                System.out.println("✓ 成功获取企业微信access_token");
                System.out.println("  - access_token: " + accessToken);
                System.out.println("  - token长度: " + accessToken.length());
            } else {
                System.out.println("✗ 获取的access_token为空");
            }
        } catch (IOException e) {
            System.out.println("✗ 获取access_token失败: " + e.getMessage());
            e.printStackTrace();
        }
 
        System.out.println("=== 测试结束 ===");
    }
 
    /**
     * 测试获取企业微信用户列表
     * 功能:调用企业微信API获取所有用户的userid和部门信息
     */
    @Test
    void testGetWorkWXUserList() {
        System.out.println("=== 开始测试获取企业微信用户列表 ===");
 
        try {
            List<WorkWXService.DeptUser> userList = workWXService.getUserList();
 
            if (userList != null && !userList.isEmpty()) {
                System.out.println("✓ 成功获取企业微信用户列表");
                System.out.println("  - 用户总数: " + userList.size());
                System.out.println("  - 前5条数据:");
                userList.stream().limit(5).forEach(user -> {
                    System.out.println("    * userid: " + user.getUserid() + ", department: " + user.getDepartment());
                });
            } else {
                System.out.println("✗ 获取的用户列表为空");
            }
        } catch (IOException e) {
            System.out.println("✗ 获取用户列表失败: " + e.getMessage());
            e.printStackTrace();
        }
 
        System.out.println("=== 测试结束 ===");
    }
}