1 package com.foxinmy.weixin4j.qy.model;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9
10 import com.alibaba.fastjson.annotation.JSONField;
11 import com.foxinmy.weixin4j.util.StringUtil;
12
13
14
15
16
17
18
19
20
21
22 public class IdParameter implements Serializable {
23
24 private static final long serialVersionUID = -2689758682205591133L;
25
26 public static final char SEPARATOR = '|';
27
28 public static final String SEPARATORS = String.format("\\%s",
29 String.valueOf(SEPARATOR));
30
31 @JSONField(name = "user")
32 private List<String> userIds;
33 @JSONField(name = "party")
34 private List<Integer> partyIds;
35 @JSONField(name = "tag")
36 private List<Integer> tagIds;
37
38 protected IdParameter() {
39 this.userIds = new ArrayList<String>();
40 this.partyIds = new ArrayList<Integer>();
41 this.tagIds = new ArrayList<Integer>();
42 }
43
44 public static IdParameter get(){
45 return new IdParameter();
46 }
47
48
49
50
51
52
53
54 public IdParameter putUserIds(String... userIds) {
55 this.userIds.addAll(Arrays.asList(userIds));
56 return this;
57 }
58
59
60
61
62
63
64
65 public IdParameter putPartyIds(Integer... partyIds) {
66 this.partyIds.addAll(Arrays.asList(partyIds));
67 return this;
68 }
69
70
71
72
73
74
75
76 public IdParameter putTagIds(Integer... tagIds) {
77 this.tagIds.addAll(Arrays.asList(tagIds));
78 return this;
79 }
80
81 public List<String> getUserIds() {
82 return userIds;
83 }
84
85 public List<Integer> getPartyIds() {
86 return partyIds;
87 }
88
89 public List<Integer> getTagIds() {
90 return tagIds;
91 }
92
93 public void setUserIds(List<String> userIds) {
94 this.userIds = userIds;
95 }
96
97 public void setPartyIds(List<Integer> partyIds) {
98 this.partyIds = partyIds;
99 }
100
101 public void setTagIds(List<Integer> tagIds) {
102 this.tagIds = tagIds;
103 }
104
105
106
107
108
109
110 public Map<String, String> getParameter() {
111 Map<String, String> parameterMap = new HashMap<String, String>();
112 if (userIds != null && !userIds.isEmpty()) {
113 parameterMap.put("touser", StringUtil.join(userIds, SEPARATOR));
114 }
115 if (partyIds != null && !partyIds.isEmpty()) {
116 parameterMap.put("toparty", StringUtil.join(partyIds, SEPARATOR));
117 }
118 if (tagIds != null && !tagIds.isEmpty()) {
119 parameterMap.put("totag", StringUtil.join(tagIds, SEPARATOR));
120 }
121 return parameterMap;
122 }
123
124 @Override
125 public String toString() {
126 return "IdParameter [userIds=" + userIds + ", partyIds=" + partyIds
127 + ", tagIds=" + tagIds + "]";
128 }
129 }