1 package com.foxinmy.weixin4j.model.card;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.List;
7
8 import com.alibaba.fastjson.JSONObject;
9 import com.alibaba.fastjson.annotation.JSONField;
10 import com.foxinmy.weixin4j.type.Week;
11 import com.foxinmy.weixin4j.util.NameValue;
12 import com.foxinmy.weixin4j.util.StringUtil;
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class CouponAdvanceInfo implements Serializable {
27
28 private static final long serialVersionUID = 3626615706377721404L;
29
30
31
32 @JSONField(name = "use_condition")
33 private final JSONObject useCondition;
34
35
36
37 @JSONField(name = "abstract")
38 private final JSONObject abstractConver;
39
40
41
42 @JSONField(name = "text_image_list")
43 private final List<JSONObject> slideImages;
44
45
46
47 @JSONField(name = "time_limit")
48 private final List<JSONObject> timeLimits;
49
50
51
52 @JSONField(name = "business_service")
53 private final List<BusinessService> businessServices;
54
55 private CouponAdvanceInfo(Builder builder) {
56 this.useCondition = builder.useCondition;
57 this.abstractConver = builder.abstractConver;
58 this.slideImages = builder.slideImages;
59 this.timeLimits = builder.timeLimits;
60 this.businessServices = builder.businessServices;
61 }
62
63
64 public JSONObject getUseCondition() {
65 return useCondition;
66 }
67
68 public JSONObject getAbstractConver() {
69 return abstractConver;
70 }
71
72 public List<JSONObject> getSlideImages() {
73 return slideImages;
74 }
75
76 public List<JSONObject> getTimeLimits() {
77 return timeLimits;
78 }
79
80 public List<BusinessService> getBusinessServices() {
81 return businessServices;
82 }
83
84
85
86
87
88
89
90
91
92 public static final class Builder {
93
94
95
96 private JSONObject useCondition;
97
98
99
100 private JSONObject abstractConver;
101
102
103
104 private List<JSONObject> slideImages;
105
106
107
108 private List<JSONObject> timeLimits;
109
110
111
112 private List<BusinessService> businessServices;
113
114 public Builder() {
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128 public Builder useCondition(String acceptCategory, String rejectCategory) {
129 return useCondition(acceptCategory, rejectCategory, 0, null, true);
130 }
131
132
133
134
135
136
137
138
139
140
141 public Builder useCondition(int leastCost, String objectUseFor) {
142 return useCondition(null, null, leastCost, objectUseFor, true);
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 public Builder useCondition(String acceptCategory,
162 String rejectCategory, int leastCost, String objectUseFor,
163 boolean canUseWithOtherDiscount) {
164 if(useCondition == null)
165 useCondition = new JSONObject();
166 useCondition.clear();
167 if (StringUtil.isNotBlank(acceptCategory)) {
168 useCondition.put("accept_category", acceptCategory);
169 }
170 if (StringUtil.isNotBlank(rejectCategory)) {
171 useCondition.put("reject_category", rejectCategory);
172 }
173 if (leastCost > 0) {
174 useCondition.put("least_cost", leastCost);
175 }
176 if (StringUtil.isNotBlank(objectUseFor)) {
177 useCondition.put("object_use_for", objectUseFor);
178 }
179 useCondition.put("can_use_with_other_discount",
180 canUseWithOtherDiscount);
181 return this;
182 }
183
184
185
186
187
188
189
190
191
192
193 public Builder abstractConver(String abstracts, String... convers) {
194 if(abstractConver == null)
195 abstractConver = new JSONObject();
196 abstractConver.clear();
197 abstractConver.put("abstract", abstracts);
198 abstractConver.put("icon_url_list", convers);
199 return this;
200 }
201
202
203
204
205
206
207
208
209 public Builder slideImages(NameValue... slideImages) {
210 if(this.slideImages == null)
211 this.slideImages = new ArrayList<JSONObject>();
212 this.slideImages.clear();
213 for (NameValue nv : slideImages) {
214 JSONObject slide = new JSONObject();
215 slide.put("text", nv.getName());
216 slide.put("image_url", nv.getValue());
217 this.slideImages.add(slide);
218 }
219 return this;
220 }
221
222
223
224
225
226
227
228
229
230
231 public Builder slideImage(String title, String url) {
232 if(this.slideImages == null)
233 this.slideImages = new ArrayList<JSONObject>();
234 JSONObject slide = new JSONObject();
235 slide.put("text", title);
236 slide.put("image_url", url);
237 this.slideImages.add(slide);
238 return this;
239 }
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254 public Builder timeLimit(Week week, int beginHour, int beignMinute) {
255 return timeLimit(week, beginHour, beignMinute, 0, 0);
256 }
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277 public Builder timeLimit(Week week, int beginHour, int beignMinute,
278 int endHour, int endMinute) {
279 if(this.timeLimits == null)
280 this.timeLimits = new ArrayList<JSONObject>();
281 JSONObject timeLimit = new JSONObject();
282 if (week != null) {
283 timeLimit.put("type", week.name());
284 }
285 timeLimit.put("begin_hour", beginHour);
286 if (beignMinute > 0) {
287 timeLimit.put("begin_minute", beignMinute);
288 }
289 timeLimit.put("end_hour", endHour);
290 if (endMinute > 0) {
291 timeLimit.put("end_minute", endMinute);
292 }
293 this.timeLimits.add(timeLimit);
294 return this;
295 }
296
297
298
299
300
301
302
303
304 public Builder businessServices(BusinessService... businessServices) {
305 if(this.businessServices == null)
306 this.businessServices = new ArrayList<BusinessService>();
307 this.businessServices.addAll(Arrays.asList(businessServices));
308 return this;
309 }
310
311 public CouponAdvanceInfo build(){
312 return new CouponAdvanceInfo(this);
313 }
314 }
315
316
317
318
319
320
321
322
323
324 public enum BusinessService {
325
326
327
328 BIZ_SERVICE_DELIVER,
329
330
331
332 BIZ_SERVICE_FREE_PARK,
333
334
335
336 BIZ_SERVICE_WITH_PET,
337
338
339
340 BIZ_SERVICE_FREE_WIFI;
341 }
342 }