Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 2, 2025

PR #3687 引入的演示代码使用了 Java 10+ 的 var 关键字,且调用了不存在的方法导致编译失败。

修复内容

Java 8 兼容性

  • 添加 import me.chanjar.weixin.cp.bean.oa.WxCpOaApprovalTemplateResult
  • var templateResultWxCpOaApprovalTemplateResult templateResult

方法调用修正

  • detail.getSpStatus().getCode()detail.getSpStatus() (枚举类型无 getCode)
  • detail.getApplyer()detail.getApplier()
  • detail.getSpRecord()detail.getSpRecords() (数组字段)
  • record.getSpStatus()record.getStatus()
  • approvalInfo.getCount()approvalInfo.getSpNoList().size()
// Before
var templateResult = wxCpService.getOaService().getTemplateDetail(templateId);
System.out.println("审批状态: " + detail.getSpStatus().getCode());

// After
WxCpOaApprovalTemplateResult templateResult = wxCpService.getOaService().getTemplateDetail(templateId);
System.out.println("审批状态: " + detail.getSpStatus());
Original prompt

Issue

The test/demo class weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpApprovalWorkflowDemo.java currently uses Java local variable type inference (var) in templateManagement(), which causes compilation failures in projects/builds using Java 8. The demo file is also missing an explicit import for WxCpOaApprovalTemplateResult.

Goal

Create a small change to make the demo Java 8 compatible by replacing the use of 'var' with an explicit type and adding the required import. Keep all other code unchanged.

Files to change

  1. weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpApprovalWorkflowDemo.java

Change details

  • Add import: me.chanjar.weixin.cp.bean.oa.WxCpOaApprovalTemplateResult
  • In templateManagement(), replace:
    var templateResult = wxCpService.getOaService().getTemplateDetail(templateId);
    with:
    WxCpOaApprovalTemplateResult templateResult = wxCpService.getOaService().getTemplateDetail(templateId);

Provide the updated file contents (full file) below. This is a minimal, non-behavioral change intended only to fix compilation on Java8.

Updated file contents:

package me.chanjar.weixin.cp.demo;

import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.oa.WxCpApprovalDetailResult;
import me.chanjar.weixin.cp.bean.oa.WxCpApprovalInfo;
import me.chanjar.weixin.cp.bean.oa.WxCpOaApplyEventRequest;
import me.chanjar.weixin.cp.bean.oa.applydata.ApplyDataContent;
import me.chanjar.weixin.cp.bean.oa.applydata.ContentValue;
import me.chanjar.weixin.cp.bean.oa.WxCpOaApprovalTemplateResult;

import java.util.Arrays;
import java.util.Date;

/**

  • 企业微信流程审批功能演示代码

  • WeChat Enterprise Workflow Approval Demo

  • 演示如何使用WxJava SDK中已实现的完整审批流程功能

  • Demonstrates how to use the comprehensive approval workflow features already implemented in WxJava SDK

  • 文档参考 Documentation Reference: https://work.weixin.qq.com/api/doc/90000/90135/91853
    */
    public class WxCpApprovalWorkflowDemo {

    private WxCpService wxCpService;

    public WxCpApprovalWorkflowDemo(WxCpService wxCpService) {
    this.wxCpService = wxCpService;
    }

    public String submitApprovalApplication() throws Exception {
    WxCpOaApplyEventRequest request = new WxCpOaApplyEventRequest()
    .setCreatorUserId("creator_user_id")
    .setTemplateId("3Tka1eD6v6JfzhDMqPd3aMkFdxqtJMc2ZRioUBGCNS")
    .setUseTemplateApprover(0)
    .setApprovers(Arrays.asList(
    new WxCpOaApplyEventRequest.Approver()
    .setAttr(2)
    .setUserIds(new String[]{"approver1", "approver2"})
    ))
    .setNotifiers(new String[]{"notifier1", "notifier2"})
    .setNotifyType(1)
    .setApplyData(new WxCpOaApplyEventRequest.ApplyData()
    .setContents(Arrays.asList(
    new ApplyDataContent()
    .setControl("Text")
    .setId("Text-1234567890")
    .setValue(new ContentValue().setText("这是一个审批申请的文本内容")),
    new ApplyDataContent()
    .setControl("Number")
    .setId("Number-1234567890")
    .setValue(new ContentValue().setNewNumber("1000")),
    new ApplyDataContent()
    .setControl("Money")
    .setId("Money-1234567890")
    .setValue(new ContentValue().setNewMoney("10000"))
    ))
    );

     String spNo = wxCpService.getOaService().apply(request);
     System.out.println("审批申请提交成功,审批单号: " + spNo);
     return spNo;
    

    }

    public void getApprovalDetails(String spNo) throws Exception {
    WxCpApprovalDetailResult result = wxCpService.getOaService().getApprovalDetail(spNo);
    WxCpApprovalDetailResult.WxCpApprovalDetail detail = result.getInfo();
    System.out.println("审批单号: " + detail.getSpNo());
    System.out.println("审批名称: " + detail.getSpName());
    System.out.println("审批状态: " + detail.getSpStatus().getCode());
    System.out.println("申请人: " + detail.getApplyer().getUserId());
    System.out.println("申请时间: " + detail.getApplyTime());
    if (detail.getSpRecord() != null) {
    detail.getSpRecord().forEach(record -> {
    System.out.println("审批节点状态: " + record.getSpStatus());
    System.out.println("审批人: " + record.getDetails());
    });
    }
    }

    public void batchGetApprovalInfo() throws Exception {
    Date startTime = new Date(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000L);
    Date endTime = new Date();
    WxCpApprovalInfo approvalInfo = wxCpService.getOaService().getApprovalInfo(startTime, endTime, "0", 100, null);
    System.out.println("获取到的审批单数量: " + approvalInfo.getCount());
    if (approvalInfo.getSpNoList() != null) {
    approvalInfo.getSpNoList().forEach(spNo -> System.out.println("审批单号: " + spNo));
    ...

This pull request was created as a result of the following prompt from Copilot chat.

Issue

The test/demo class weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpApprovalWorkflowDemo.java currently uses Java local variable type inference (var) in templateManagement(), which causes compilation failures in projects/builds using Java 8. The demo file is also missing an explicit import for WxCpOaApprovalTemplateResult.

Goal

Create a small change to make the demo Java 8 compatible by replacing the use of 'var' with an explicit type and adding the required import. Keep all other code unchanged.

Files to change

  1. weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpApprovalWorkflowDemo.java

Change details

  • Add import: me.chanjar.weixin.cp.bean.oa.WxCpOaApprovalTemplateResult
  • In templateManagement(), replace:
    var templateResult = wxCpService.getOaService().getTemplateDetail(templateId);
    with:
    WxCpOaApprovalTemplateResult templateResult = wxCpService.getOaService().getTemplateDetail(templateId);

Provide the updated file contents (full file) below. This is a minimal, non-behavioral change intended only to fix compilation on Java8.

Updated file contents:

package me.chanjar.weixin.cp.demo;

import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.oa.WxCpApprovalDetailResult;
import me.chanjar.weixin.cp.bean.oa.WxCpApprovalInfo;
import me.chanjar.weixin.cp.bean.oa.WxCpOaApplyEventRequest;
import me.chanjar.weixin.cp.bean.oa.applydata.ApplyDataContent;
import me.chanjar.weixin.cp.bean.oa.applydata.ContentValue;
import me.chanjar.weixin.cp.bean.oa.WxCpOaApprovalTemplateResult;

import java.util.Arrays;
import java.util.Date;

/**

  • 企业微信流程审批功能演示代码

  • WeChat Enterprise Workflow Approval Demo

  • 演示如何使用WxJava SDK中已实现的完整审批流程功能

  • Demonstrates how to use the comprehensive approval workflow features already implemented in WxJava SDK

  • 文档参考 Documentation Reference: https://work.weixin.qq.com/api/doc/90000/90135/91853
    */
    public class WxCpApprovalWorkflowDemo {

    private WxCpService wxCpService;

    public WxCpApprovalWorkflowDemo(WxCpService wxCpService) {
    this.wxCpService = wxCpService;
    }

    public String submitApprovalApplication() throws Exception {
    WxCpOaApplyEventRequest request = new WxCpOaApplyEventRequest()
    .setCreatorUserId("creator_user_id")
    .setTemplateId("3Tka1eD6v6JfzhDMqPd3aMkFdxqtJMc2ZRioUBGCNS")
    .setUseTemplateApprover(0)
    .setApprovers(Arrays.asList(
    new WxCpOaApplyEventRequest.Approver()
    .setAttr(2)
    .setUserIds(new String[]{"approver1", "approver2"})
    ))
    .setNotifiers(new String[]{"notifier1", "notifier2"})
    .setNotifyType(1)
    .setApplyData(new WxCpOaApplyEventRequest.ApplyData()
    .setContents(Arrays.asList(
    new ApplyDataContent()
    .setControl("Text")
    .setId("Text-1234567890")
    .setValue(new ContentValue().setText("这是一个审批申请的文本内容")),
    new ApplyDataContent()
    .setControl("Number")
    .setId("Number-1234567890")
    .setValue(new ContentValue().setNewNumber("1000")),
    new ApplyDataContent()
    .setControl("Money")
    .setId("Money-1234567890")
    .setValue(new ContentValue().setNewMoney("10000"))
    ))
    );

     String spNo = wxCpService.getOaService().apply(request);
     System.out.println("审批申请提交成功,审批单号: " + spNo);
     return spNo;
    

    }

    public void getApprovalDetails(String spNo) throws Exception {
    WxCpApprovalDetailResult result = wxCpService.getOaService().getApprovalDetail(spNo);
    WxCpApprovalDetailResult.WxCpApprovalDetail detail = result.getInfo();
    System.out.println("审批单号: " + detail.getSpNo());
    System.out.println("审批名称: " + detail.getSpName());
    System.out.println("审批状态: " + detail.getSpStatus().getCode());
    System.out.println("申请人: " + detail.getApplyer().getUserId());
    System.out.println("申请时间: " + detail.getApplyTime());
    if (detail.getSpRecord() != null) {
    detail.getSpRecord().forEach(record -> {
    System.out.println("审批节点状态: " + record.getSpStatus());
    System.out.println("审批人: " + record.getDetails());
    });
    }
    }

    public void batchGetApprovalInfo() throws Exception {
    Date startTime = new Date(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000L);
    Date endTime = new Date();
    WxCpApprovalInfo approvalInfo = wxCpService.getOaService().getApprovalInfo(startTime, endTime, "0", 100, null);
    System.out.println("获取到的审批单数量: " + approvalInfo.getCount());
    if (approvalInfo.getSpNoList() != null) {
    approvalInfo.getSpNoList().forEach(spNo -> System.out.println("审批单号: " + spNo));
    }
    }

    public void templateManagement() throws Exception {
    String templateId = "3Tka1eD6v6JfzhDMqPd3aMkFdxqtJMc2ZRioUBGCNS";
    WxCpOaApprovalTemplateResult templateResult = wxCpService.getOaService().getTemplateDetail(templateId);
    System.out.println("模板名称: " + templateResult.getTemplateNames());
    System.out.println("模板内容: " + templateResult.getTemplateContent());
    }

    public void completeWorkflowDemo() {
    try {
    System.out.println("=== 企业微信流程审批完整演示 ===");
    System.out.println("\n1. 提交审批申请...");
    String spNo = submitApprovalApplication();
    System.out.println("\n2. 获取审批详情...");
    getApprovalDetails(spNo);
    System.out.println("\n3. 批量获取审批信息...");
    batchGetApprovalInfo();
    System.out.println("\n4. 模板管理...");
    templateManagement();
    System.out.println("\n=== 演示完成 ===");
    System.out.println("WxJava SDK 已经完整支持企业微信流程审批功能!");
    } catch (Exception e) {
    System.err.println("演示过程中发生错误: " + e.getMessage());
    e.printStackTrace();
    }
    }

    public static void main(String[] args) {
    System.out.println("企业微信流程审批功能演示");
    System.out.println("该演示代码展示了WxJava SDK中已经完整实现的审批流程功能");
    System.out.println("包括文档91853中描述的所有核心功能");
    System.out.println("");
    System.out.println("主要功能:");
    System.out.println("- 提交审批申请 (/cgi-bin/oa/applyevent)");
    System.out.println("- 获取审批详情 (/cgi-bin/oa/getapprovaldetail)");
    System.out.println("- 批量获取审批单号 (/cgi-bin/oa/getapprovalinfo)");
    System.out.println("- 模板管理功能");
    System.out.println("- 审批流程引擎支持");
    System.out.println("");
    System.out.println("如需运行演示,请配置正确的企业微信服务参数。");
    }
    }


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix Java 8 compatibility in WxCpApprovalWorkflowDemo 修复 WxCpApprovalWorkflowDemo.java 的 Java 8 兼容性和编译错误 Dec 2, 2025
Copilot AI requested a review from binarywang December 2, 2025 04:00
@binarywang binarywang marked this pull request as ready for review December 2, 2025 04:02
@binarywang binarywang merged commit 3bf3595 into develop Dec 2, 2025
1 check passed
@binarywang binarywang deleted the copilot/fix-java-8-compatibility branch December 2, 2025 04:03
@binarywang binarywang added this to the 4.8.0 milestone Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants