🐛 #3394【企业微信】修复“审批状态通知事件”企微回调XML序列化的bug

This commit is contained in:
小梁 2024-10-29 14:44:06 +08:00 committed by GitHub
parent 542f93c3be
commit 63131ec61f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 86 additions and 6 deletions

View File

@ -91,19 +91,19 @@ public class WxCpXmlApprovalInfo implements Serializable {
/**
* 审批流程信息
*/
@XStreamImplicit(itemFieldName = "ApprovalNodes")
@XStreamAlias("ApprovalNodes")
private List<ApprovalNode> approvalNodes;
/**
* 抄送信息可能有多个抄送人
*/
@XStreamImplicit(itemFieldName = "NotifyNodes")
@XStreamAlias("NotifyNodes")
private List<NotifyNode> notifyNodes;
/**
* 抄送人信息
*/
@XStreamAlias("NotifyNodes")
@XStreamAlias("NotifyNode")
@Data
public static class NotifyNode implements Serializable {
private static final long serialVersionUID = -979255011922209018L;
@ -141,7 +141,7 @@ public class WxCpXmlApprovalInfo implements Serializable {
/**
* 审批流程信息可以有多个审批节点
*/
@XStreamAlias("ApprovalNodes")
@XStreamAlias("ApprovalNode")
@Data
public static class ApprovalNode implements Serializable {
private static final long serialVersionUID = -979255011922209018L;
@ -167,7 +167,7 @@ public class WxCpXmlApprovalInfo implements Serializable {
/**
* 审批节点信息当节点为标签或上级时一个节点可能有多个分支
*/
@XStreamImplicit(itemFieldName = "Items")
@XStreamAlias("Items")
private List<Item> items;
}
@ -175,7 +175,7 @@ public class WxCpXmlApprovalInfo implements Serializable {
/**
* 审批节点分支当节点为标签或上级时一个节点可能有多个分支
*/
@XStreamAlias("Items")
@XStreamAlias("Item")
@Data
public static class Item implements Serializable {
private static final long serialVersionUID = -979255011922209018L;

View File

@ -301,4 +301,84 @@ public class WxCpXmlMessageTest {
System.out.println(XStreamTransformer.toXml(WxCpXmlMessage.class, wxCpXmlMessage));
}
/**
* Test open approval change.
*/
public void testOpenApprovalChange() {
String xml = "<xml>\n" +
" <ToUserName><![CDATA[wwddddccc7775555aaa]]></ToUserName>\n" +
" <FromUserName><![CDATA[sys]]></FromUserName>\n" +
" <CreateTime>1527838022</CreateTime>\n" +
" <MsgType><![CDATA[event]]></MsgType>\n" +
" <Event><![CDATA[open_approval_change]]></Event>\n" +
" <AgentID>1</AgentID>\n" +
" <ApprovalInfo>\n" +
" <ThirdNo><![CDATA[201806010001]]></ThirdNo>\n" +
" <OpenSpName><![CDATA[付款]]></OpenSpName>\n" +
" <OpenTemplateId><![CDATA[1234567890]]></OpenTemplateId>\n" +
" <OpenSpStatus>1</OpenSpStatus>\n" +
" <ApplyTime>1527837645</ApplyTime>\n" +
" <ApplyUserName><![CDATA[xiaoming]]></ApplyUserName>\n" +
" <ApplyUserId><![CDATA[1]]></ApplyUserId>\n" +
" <ApplyUserParty><![CDATA[产品部]]></ApplyUserParty>\n" +
" <ApplyUserImage><![CDATA[http://www.qq.com/xxx.png]]></ApplyUserImage>\n" +
" <ApprovalNodes>\n" +
" <ApprovalNode>\n" +
" <NodeStatus>1</NodeStatus>\n" +
" <NodeAttr>1</NodeAttr>\n" +
" <NodeType>1</NodeType>\n" +
" <Items>\n" +
" <Item>\n" +
" <ItemName><![CDATA[xiaohong]]></ItemName>\n" +
" <ItemUserId><![CDATA[2]]></ItemUserId>\n" +
" <ItemImage><![CDATA[http://www.qq.com/xxx.png]]></ItemImage>\n" +
" <ItemStatus>1</ItemStatus>\n" +
" <ItemSpeech><![CDATA[]]></ItemSpeech>\n" +
" <ItemOpTime>0</ItemOpTime>\n" +
" </Item>\n" +
" </Items>\n" +
" </ApprovalNode>\n" +
" <ApprovalNode>\n" +
" <NodeStatus>1</NodeStatus>\n" +
" <NodeAttr>1</NodeAttr>\n" +
" <NodeType>1</NodeType>\n" +
" <Items>\n" +
" <Item>\n" +
" <ItemName><![CDATA[xiaohong]]></ItemName>\n" +
" <ItemUserId><![CDATA[2]]></ItemUserId>\n" +
" <ItemImage><![CDATA[http://www.qq.com/xxx.png]]></ItemImage>\n" +
" <ItemStatus>1</ItemStatus>\n" +
" <ItemSpeech><![CDATA[]]></ItemSpeech>\n" +
" <ItemOpTime>0</ItemOpTime>\n" +
" </Item>\n" +
" <Item>\n" +
" <ItemName><![CDATA[xiaohong]]></ItemName>\n" +
" <ItemUserId><![CDATA[2]]></ItemUserId>\n" +
" <ItemImage><![CDATA[http://www.qq.com/xxx.png]]></ItemImage>\n" +
" <ItemStatus>1</ItemStatus>\n" +
" <ItemSpeech><![CDATA[]]></ItemSpeech>\n" +
" <ItemOpTime>0</ItemOpTime>\n" +
" </Item>\n" +
" </Items>\n" +
" </ApprovalNode>\n" +
" </ApprovalNodes>\n" +
" <NotifyNodes>\n" +
" <NotifyNode>\n" +
" <ItemName><![CDATA[xiaogang]]></ItemName>\n" +
" <ItemUserId><![CDATA[3]]></ItemUserId>\n" +
" <ItemImage><![CDATA[http://www.qq.com/xxx.png]]></ItemImage>\n" +
" </NotifyNode>\n" +
" </NotifyNodes>\n" +
" <approverstep>0</approverstep>\n" +
" </ApprovalInfo>\n" +
"</xml>\n";
WxCpXmlMessage wxCpXmlMessage = WxCpXmlMessage.fromXml(xml);
assertThat(wxCpXmlMessage).isNotNull();
assertThat(wxCpXmlMessage.getApprovalInfo().getApprovalNodes()).isNotEmpty();
assertThat(wxCpXmlMessage.getApprovalInfo().getApprovalNodes().get(0).getItems()).isNotEmpty();
assertThat(wxCpXmlMessage.getApprovalInfo().getApprovalNodes().get(0).getItems().get(0).getItemName()).isNotEmpty();
assertThat(wxCpXmlMessage.getApprovalInfo().getNotifyNodes().get(0).getItemName()).isNotEmpty();
}
}