tjx
2025-11-25 ac891b014f5110e01fd19bc537f208ae9e7c689c
src/test/java/com/gs/xky/XkyApplicationTests.java
@@ -1,6 +1,7 @@
package com.gs.xky;
import com.gs.xky.service.XkyService;
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;
@@ -12,12 +13,61 @@
    @Autowired
    private XkyService xkyService;
    private VwCjScSjTsBbService vwCjScSjTsBbService;
    @Autowired
    private WorkWXService workWXService;
    /**
     * 测试导出生产数据并发送钉钉消息
     * 功能:查询VW_CJ_SC_SJ_TS_BB表数据 -> 导出Excel -> 发送钉钉文件消息
     */
    @Test
    void contextLoads() throws IOException {
    void testExportAndSendProductionData() throws Exception {
        System.out.println("=== 开始测试导出生产数据并发送钉钉 ===");
        xkyService.GetSaveDetail();
        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("=== 测试结束 ===");
    }
}