View Javadoc
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   * id参数集
15   *
16   * @className IdParameter
17   * @author jinyu(foxinmy@gmail.com)
18   * @date 2015年3月30日
19   * @since JDK 1.6
20   * @see
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  	 * 增加成员ID列表,最多支持1000个
50  	 *
51  	 * @param userIds
52  	 * @return
53  	 */
54  	public IdParameter putUserIds(String... userIds) {
55  		this.userIds.addAll(Arrays.asList(userIds));
56  		return this;
57  	}
58  
59  	/**
60  	 * 新增部门ID列表,最多支持100个
61  	 *
62  	 * @param partyIds
63  	 * @return
64  	 */
65  	public IdParameter putPartyIds(Integer... partyIds) {
66  		this.partyIds.addAll(Arrays.asList(partyIds));
67  		return this;
68  	}
69  
70  	/**
71  	 * 新增标签ID列表
72  	 *
73  	 * @param tagIds
74  	 * @return
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 	 * @return
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 }