Skip to content

Commit e00af92

Browse files
authored
🎨 #3274【企业微信】 修复oa审批创建模板单选多选下拉组件企微信参数定义错误,拆分不共用模板详情实体
1 parent 222c23c commit e00af92

File tree

4 files changed

+178
-3
lines changed

4 files changed

+178
-3
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpOaApprovalTemplate.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import lombok.experimental.Accessors;
99
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateContent;
1010
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateTitle;
11+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
1112

1213
import java.io.Serializable;
1314
import java.util.List;
@@ -37,4 +38,12 @@ public class WxCpOaApprovalTemplate implements Serializable {
3738
@SerializedName("template_content")
3839
private TemplateContent templateContent;
3940

41+
public static WxCpOaApprovalTemplate fromJson(String json) {
42+
return WxCpGsonBuilder.create().fromJson(json, WxCpOaApprovalTemplate.class);
43+
}
44+
45+
public String toJson() {
46+
return WxCpGsonBuilder.create().toJson(this);
47+
}
48+
4049
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpOaApprovalTemplateResult.java

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
package me.chanjar.weixin.cp.bean.oa;
22

33
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
46
import lombok.Data;
5-
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateContent;
7+
import lombok.NoArgsConstructor;
8+
import lombok.experimental.Accessors;
69
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateTitle;
10+
import me.chanjar.weixin.cp.bean.oa.templatedata.control.*;
11+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
712

813
import java.io.Serializable;
914
import java.util.List;
1015

1116
/**
1217
* 审批模板详情
1318
*
14-
* @author gyv12345 @163.com
19+
* @author gyv12345 @163.com / Wang_Wong
1520
*/
1621
@Data
22+
@Builder
23+
@NoArgsConstructor
24+
@AllArgsConstructor
25+
@Accessors(chain = true)
1726
public class WxCpOaApprovalTemplateResult implements Serializable {
1827
private static final long serialVersionUID = 6690547131189343887L;
1928

@@ -29,4 +38,98 @@ public class WxCpOaApprovalTemplateResult implements Serializable {
2938
@SerializedName("template_content")
3039
private TemplateContent templateContent;
3140

41+
@Data
42+
public static class TemplateContent implements Serializable {
43+
private static final long serialVersionUID = -5640250983775840865L;
44+
45+
private List<TemplateControls> controls;
46+
}
47+
48+
@Data
49+
public static class TemplateControls implements Serializable {
50+
51+
private static final long serialVersionUID = -7496794407355510374L;
52+
53+
private TemplateProperty property;
54+
55+
private TemplateConfig config;
56+
}
57+
58+
@Data
59+
public static class TemplateProperty implements Serializable {
60+
61+
private static final long serialVersionUID = -3429251158540167453L;
62+
63+
private String control;
64+
65+
private String id;
66+
67+
private List<TemplateTitle> title;
68+
69+
private List<TemplateTitle> placeholder;
70+
71+
private Integer require;
72+
73+
@SerializedName("un_print")
74+
private Integer unPrint;
75+
76+
private TemplateConfig config;
77+
}
78+
79+
@Data
80+
public static class TemplateConfig implements Serializable {
81+
82+
private static final long serialVersionUID = 6993937809371277669L;
83+
84+
private TemplateDate date;
85+
86+
private TemplateSelector selector;
87+
88+
private TemplateContact contact;
89+
90+
private TemplateTable table;
91+
92+
private TemplateAttendance attendance;
93+
94+
@SerializedName("vacation_list")
95+
private TemplateVacation vacationList;
96+
97+
}
98+
99+
@Data
100+
public static class TemplateSelector implements Serializable {
101+
private static final long serialVersionUID = 4995408101489736881L;
102+
103+
/**
104+
* single-单选;multi-多选
105+
*/
106+
private String type;
107+
108+
private List<TemplateOption> options;
109+
}
110+
111+
@Data
112+
public static class TemplateOption implements Serializable {
113+
114+
private static final long serialVersionUID = -7883792668568772078L;
115+
116+
private String key;
117+
118+
/**
119+
* 获取审批模板详情,value为list类型
120+
* https://developer.work.weixin.qq.com/document/path/91982
121+
*/
122+
@SerializedName("value")
123+
private List<TemplateTitle> value;
124+
125+
}
126+
127+
public static WxCpOaApprovalTemplateResult fromJson(String json) {
128+
return WxCpGsonBuilder.create().fromJson(json, WxCpOaApprovalTemplateResult.class);
129+
}
130+
131+
public String toJson() {
132+
return WxCpGsonBuilder.create().toJson(this);
133+
}
134+
32135
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/templatedata/TemplateOptions.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import lombok.Data;
44

55
import java.io.Serializable;
6-
import java.util.List;
76

87
/**
98
* The type Template options.
@@ -17,5 +16,12 @@ public class TemplateOptions implements Serializable {
1716

1817
private String key;
1918

19+
/**
20+
* 创建审批模板,value为对象类型
21+
* https://developer.work.weixin.qq.com/document/path/97437#%E9%99%845-%E5%8D%95%E9%80%89%E5%A4%9A%E9%80%89%E6%8E%A7%E4%BB%B6%EF%BC%88control%E5%8F%82%E6%95%B0%E4%B8%BAselector%EF%BC%89
22+
*
23+
* 获取审批模板详情,value为list类型
24+
* https://developer.work.weixin.qq.com/document/path/91982
25+
**/
2026
private TemplateTitle value;
2127
}

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ public void testGetApprovalDetail() throws WxErrorException {
211211
*/
212212
@Test
213213
public void testGetTemplateDetail() throws WxErrorException {
214+
215+
String json = "{\"errcode\":0,\"errmsg\":\"ok\",\"template_names\":[{\"text\":\"销售用章申请-CIC测试\",\"lang\":\"zh_CN\"}],\"template_content\":{\"controls\":[{\"property\":{\"control\":\"Text\",\"id\":\"Text-1642064119106\",\"title\":[{\"text\":\"甲方全称\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请输入\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1}},{\"property\":{\"control\":\"Selector\",\"id\":\"Selector-1641521155746\",\"title\":[{\"text\":\"用章公司\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请选择\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1},\"config\":{\"selector\":{\"type\":\"single\",\"options\":[{\"key\":\"option-1641521155746\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1703845381898\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1643277806277\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1641521181119\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1641521191559\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1641521216515\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1650417735718\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1652756795298\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1664422448363\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1673487035814\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1675128722320\",\"value\":[{\"text\":\"事务所\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1678071926146\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1678071927225\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1703845339862\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1703845330660\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1684459670059\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1698111016115\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1705559650950\",\"value\":[{\"text\":\"有限公司\",\"lang\":\"zh_CN\"}]}],\"op_relations\":[]}}},{\"property\":{\"control\":\"Text\",\"id\":\"Text-1641521297125\",\"title\":[{\"text\":\"渠道来源\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请输入\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1}},{\"property\":{\"control\":\"Selector\",\"id\":\"Selector-1641521316173\",\"title\":[{\"text\":\"印章类型\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请选择\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1},\"config\":{\"selector\":{\"type\":\"single\",\"options\":[{\"key\":\"option-1641521316173\",\"value\":[{\"text\":\"公章\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1641521316174\",\"value\":[{\"text\":\"业务章\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1641521339762\",\"value\":[{\"text\":\"法人章\",\"lang\":\"zh_CN\"}]}],\"op_relations\":[]}}},{\"property\":{\"control\":\"Selector\",\"id\":\"Selector-1641521355432\",\"title\":[{\"text\":\"是否外带\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请选择\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1},\"config\":{\"selector\":{\"type\":\"single\",\"options\":[{\"key\":\"option-1641521355432\",\"value\":[{\"text\":\"\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1641521355433\",\"value\":[{\"text\":\"\",\"lang\":\"zh_CN\"}]}],\"op_relations\":[]}}},{\"property\":{\"control\":\"Selector\",\"id\":\"Selector-1648619603087\",\"title\":[{\"text\":\"盖章形式\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请选择\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1},\"config\":{\"selector\":{\"type\":\"single\",\"options\":[{\"key\":\"option-1648619603087\",\"value\":[{\"text\":\"电子合同章\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1648619603088\",\"value\":[{\"text\":\"纸质合同章\",\"lang\":\"zh_CN\"}]}],\"op_relations\":[]}}},{\"property\":{\"control\":\"Textarea\",\"id\":\"Textarea-1641521378351\",\"title\":[{\"text\":\"用印事由\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请输入\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1}},{\"property\":{\"control\":\"Date\",\"id\":\"Date-1641521411373\",\"title\":[{\"text\":\"借用时间\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请选择\",\"lang\":\"zh_CN\"}],\"require\":0,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1},\"config\":{\"date\":{\"type\":\"hour\"}}},{\"property\":{\"control\":\"Date\",\"id\":\"Date-1641521421730\",\"title\":[{\"text\":\"归还时间\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请选择\",\"lang\":\"zh_CN\"}],\"require\":0,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1},\"config\":{\"date\":{\"type\":\"hour\"}}},{\"property\":{\"control\":\"Selector\",\"id\":\"Selector-1641521441251\",\"title\":[{\"text\":\"文件类型\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请选择\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1},\"config\":{\"selector\":{\"type\":\"single\",\"options\":[{\"key\":\"option-1641521441251\",\"value\":[{\"text\":\"业务合同\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1643278221491\",\"value\":[{\"text\":\"人事行政类文件\",\"lang\":\"zh_CN\"}]},{\"key\":\"option-1641521534238\",\"value\":[{\"text\":\"经纪人、商事服务合作合同\",\"lang\":\"zh_CN\"}]}],\"op_relations\":[]}}},{\"property\":{\"control\":\"Text\",\"id\":\"Text-1641521571559\",\"title\":[{\"text\":\"文件名称\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请输入\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1}},{\"property\":{\"control\":\"Text\",\"id\":\"Text-1641521587698\",\"title\":[{\"text\":\"文件份数\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请输入整数\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1}},{\"property\":{\"control\":\"Date\",\"id\":\"Date-1641521607834\",\"title\":[{\"text\":\"用印日期\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"请选择\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1},\"config\":{\"date\":{\"type\":\"day\"}}},{\"property\":{\"control\":\"File\",\"id\":\"File-1641521617014\",\"title\":[{\"text\":\"附件\",\"lang\":\"zh_CN\"}],\"placeholder\":[{\"text\":\"一定要上传所盖章原件,以附件内容为主\",\"lang\":\"zh_CN\"}],\"require\":1,\"un_print\":0,\"inner_id\":\"\",\"un_replace\":0,\"display\":1},\"config\":{\"file\":{\"is_only_photo\":0}}}]}}";
216+
WxCpOaApprovalTemplateResult oaApprovalTemplateResult = WxCpOaApprovalTemplateResult.fromJson(json);
217+
System.out.println("模板信息:" + oaApprovalTemplateResult.toJson());
218+
214219
String templateId = "3TkZjxugodbqpEMk9j7X6h6zKqYkc7MxQrrFmT7H";
215220
WxCpOaApprovalTemplateResult result = wxService.getOaService().getTemplateDetail(templateId);
216221
assertThat(result).isNotNull();
@@ -321,9 +326,61 @@ public void testSetOneUserQuota() throws WxErrorException {
321326

322327
}
323328

329+
/**
330+
* 创建审批模板
331+
* https://developer.work.weixin.qq.com/document/path/97437
332+
*/
324333
@Test
325334
public void testCreateOaApprovalTemplate() {
326335
//TODO
336+
String json = "{\n" +
337+
" \"template_name\": [{\n" +
338+
" \"text\": \"我的api测试模版\",\n" +
339+
" \"lang\": \"zh_CN\"\n" +
340+
" }],\n" +
341+
" \"template_content\": {\n" +
342+
" \"controls\": [{\n" +
343+
" \"property\": {\n" +
344+
" \"control\": \"Selector\",\n" +
345+
" \"id\": \"Selector-01\",\n" +
346+
" \"title\": [{\n" +
347+
" \"text\": \"控件名称\",\n" +
348+
" \"lang\": \"zh_CN\"\n" +
349+
" }],\n" +
350+
" \"placeholder\": [{\n" +
351+
" \"text\": \"控件说明\",\n" +
352+
" \"lang\": \"zh_CN\"\n" +
353+
" }],\n" +
354+
" \"require\": 0,\n" +
355+
" \"un_print\": 1\n" +
356+
" },\n" +
357+
" \"config\":{\n" +
358+
" \"selector\": {\n" +
359+
" \"type\": \"multi\",\n" +
360+
" \"options\": [\n" +
361+
" {\n" +
362+
" \"key\": \"option-1\", \n" +
363+
" \"value\":{\n" +
364+
" \"text\":\"选项1\",\n" +
365+
" \"lang\":\"zh_CN\"\n" +
366+
" }\n" +
367+
" },\n" +
368+
" {\n" +
369+
" \"key\": \"option-2\",\n" +
370+
" \"value\":{\n" +
371+
" \"text\":\"选项2\",\n" +
372+
" \"lang\":\"zh_CN\"\n" +
373+
" }\n" +
374+
" }\n" +
375+
" ]\n" +
376+
" }\n" +
377+
" }\n" +
378+
" }]\n" +
379+
" }\n" +
380+
"}";
381+
WxCpOaApprovalTemplate createTemplate = WxCpOaApprovalTemplate.fromJson(json);
382+
System.out.println("create_template数据为:" + createTemplate.toJson());
383+
327384
}
328385

329386
@Test

0 commit comments

Comments
 (0)