View Javadoc
1   package com.foxinmy.weixin4j.qy.model;
2   
3   import java.io.Serializable;
4   import java.util.Arrays;
5   import java.util.List;
6   
7   import com.alibaba.fastjson.annotation.JSONField;
8   import com.foxinmy.weixin4j.qy.type.UserStatus;
9   import com.foxinmy.weixin4j.type.Gender;
10  import com.foxinmy.weixin4j.util.NameValue;
11  
12  /**
13   * 部门成员对象
14   *
15   * @className User
16   * @author jinyu(foxinmy@gmail.com)
17   * @date 2014年11月19日
18   * @since JDK 1.6
19   */
20  public class User implements Serializable {
21  
22  	private static final long serialVersionUID = 4747301605060801611L;
23  	/**
24  	 * 必须 员工UserID。对应管理端的帐号,企业内必须唯一。长度为1~64个字符
25  	 */
26  	@JSONField(name = "userid")
27  	private String userId;
28  	/**
29  	 * 必须 成员名称。长度为1~64个字符
30  	 */
31  	private String name;
32  	/**
33  	 * 非必须 成员所属部门id列表,不超过20个
34  	 */
35  	@JSONField(name = "department")
36  	private List<Integer> partyIds;
37  	/**
38  	 * 部门内的排序值,默认为0。数量必须和department一致,数值越大排序越前面。有效的值范围是[0, 2^32)
39  	 */
40  	private List<Long> order;
41  	/**
42  	 * 非必须 职位信息。长度为0~64个字符
43  	 */
44  	private String position;
45  	/**
46  	 * 非必须 手机号码。企业内必须唯一,mobile/weixinid/email三者不能同时为空
47  	 */
48  	private String mobile;
49  	/**
50  	 * 非必须 性别。gender=0表示男,=1表示女。默认gender=0
51  	 */
52  	private Integer gender;
53  	/**
54  	 * 非必须 邮箱。长度为0~64个字符。企业内必须唯一
55  	 */
56  	private String email;
57  	/**
58  	 * 头像url。注:如果要获取小图将url最后的"/0"改成"/64"即可
59  	 */
60  	private String avatar;
61  	/**
62  	 * 关注状态: 1=已关注,2=已冻结,4=未关注
63  	 */
64  	private Integer status;
65  	/**
66  	 * 非必须 扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值
67  	 */
68  	private List<NameValue> extattr;
69  
70  	/**
71  	 * 英文名。长度为1-64个字节。
72  	 */
73  	@JSONField(name = "english_name")
74  	private String englishName;
75  	/**
76  	 * 座机。长度0-64个字节。
77  	 */
78  	private String telephone;
79  	/**
80  	 * 上级字段,标识是否为上级。
81  	 */
82  	@JSONField(name = "isleader")
83  	private Boolean isLeader;
84  	/**
85  	 * 启用/禁用成员。1表示启用成员,0表示禁用成员
86  	 */
87  	private Boolean enable;
88  
89  	protected User() {
90  	}
91  
92  	public User(String userId, String name) {
93  		this.userId = userId;
94  		this.name = name;
95  	}
96  
97  	public String getUserId() {
98  		return userId;
99  	}
100 
101 	public String getName() {
102 		return name;
103 	}
104 
105 	public List<Integer> getPartyIds() {
106 		return partyIds;
107 	}
108 
109 	public void setPartyIds(Integer... partyIds) {
110 		this.partyIds = Arrays.asList(partyIds);
111 	}
112 
113 	public String getPosition() {
114 		return position;
115 	}
116 
117 	public String getMobile() {
118 		return mobile;
119 	}
120 
121 	public Integer getGender() {
122 		return gender;
123 	}
124 
125 	@JSONField(serialize = false)
126 	public Gender getFormatGender() {
127 		if (gender != null) {
128 			if (gender.intValue() == 0) {
129 				return Gender.male;
130 			} else if (gender.intValue() == 1) {
131 				return Gender.female;
132 			} else {
133 				return Gender.unknown;
134 			}
135 		}
136 		return null;
137 	}
138 
139 	public String getEmail() {
140 		return email;
141 	}
142 
143 	public String getAvatar() {
144 		return avatar;
145 	}
146 
147 	@JSONField(serialize = false)
148 	public UserStatus getFormatStatus() {
149 		if (status != null) {
150 			for (UserStatus userStatus : UserStatus.values()) {
151 				if (userStatus.getVal() == status) {
152 					return userStatus;
153 				}
154 			}
155 		}
156 		return null;
157 	}
158 
159 	public Integer getStatus() {
160 		return status;
161 	}
162 
163 	@JSONField(serialize = false)
164 	public Boolean getFormatEnable() {
165 		if (status != null) {
166 			return status.intValue() != 2;
167 		}
168 		return Boolean.FALSE;
169 	}
170 
171 	public void setEnable(boolean enable) {
172 		this.status = enable ? 1 : 0;
173 	}
174 
175 	public List<NameValue> getExtattr() {
176 		return extattr;
177 	}
178 
179 	public void setExtattr(List<NameValue> extattr) {
180 		this.extattr = extattr;
181 	}
182 
183 	public void setExtattr(NameValue... extattr) {
184 		this.extattr = Arrays.asList(extattr);
185 	}
186 
187 	public void pushExattr(String name, String value) {
188 		extattr.add(new NameValue(name, value));
189 	}
190 
191 	// ---------- setter 应该全部去掉
192 
193 	public void setUserId(String userId) {
194 		this.userId = userId;
195 	}
196 
197 	public void setName(String name) {
198 		this.name = name;
199 	}
200 
201 	public void setPartyIds(List<Integer> partyIds) {
202 		this.partyIds = partyIds;
203 	}
204 
205 	public void setPosition(String position) {
206 		this.position = position;
207 	}
208 
209 	public void setMobile(String mobile) {
210 		this.mobile = mobile;
211 	}
212 
213 	public void setGender(Integer gender) {
214 		this.gender = gender;
215 	}
216 
217 	public void setEmail(String email) {
218 		this.email = email;
219 	}
220 
221 	public void setAvatar(String avatar) {
222 		this.avatar = avatar;
223 	}
224 
225 	public void setStatus(Integer status) {
226 		this.status = status;
227 	}
228 
229 	public String getEnglishName() {
230 		return englishName;
231 	}
232 
233 	public void setEnglishName(String englishName) {
234 		this.englishName = englishName;
235 	}
236 
237 	public String getTelephone() {
238 		return telephone;
239 	}
240 
241 	public void setTelephone(String telephone) {
242 		this.telephone = telephone;
243 	}
244 
245 	public Boolean getIsLeader() {
246 		return isLeader;
247 	}
248 
249 	public void setIsLeader(Boolean isLeader) {
250 		this.isLeader = isLeader;
251 	}
252 
253 	public Boolean getEnable() {
254 		return enable;
255 	}
256 
257 	public void setEnable(Boolean enable) {
258 		this.enable = enable;
259 	}
260 
261 	public List<Long> getOrder() {
262 		return order;
263 	}
264 
265 	public void setOrder(List<Long> order) {
266 		this.order = order;
267 	}
268 
269 	@Override
270 	public int hashCode() {
271 		final int prime = 31;
272 		int result = 1;
273 		result = prime * result + ((userId == null) ? 0 : userId.hashCode());
274 		return result;
275 	}
276 
277 	@Override
278 	public boolean equals(Object obj) {
279 		if (this == obj)
280 			return true;
281 		if (obj == null)
282 			return false;
283 		if (getClass() != obj.getClass())
284 			return false;
285 		User other = (User) obj;
286 		if (userId == null) {
287 			if (other.userId != null)
288 				return false;
289 		} else if (!userId.equals(other.userId))
290 			return false;
291 		return true;
292 	}
293 
294 	@Override
295 	public String toString() {
296 		return "User [userId=" + userId + ", name=" + name + ", partyIds=" + partyIds + ", position=" + position
297 				+ ", mobile=" + mobile + ", gender=" + gender + ", email=" + email + ", avatar=" + avatar + ", status="
298 				+ status + ", extattr=" + extattr + ", englishName=" + englishName + ", telephone=" + telephone
299 				+ ", isLeader=" + isLeader + ", enable=" + enable + ", order=" + order + "]";
300 	}
301 }