1 package com.foxinmy.weixin4j.mp.model;
2
3 import java.io.Serializable;
4
5 import com.alibaba.fastjson.JSONObject;
6 import com.alibaba.fastjson.annotation.JSONField;
7 import com.foxinmy.weixin4j.mp.type.ClientPlatformType;
8 import com.foxinmy.weixin4j.mp.type.Lang;
9 import com.foxinmy.weixin4j.type.Gender;
10
11
12
13
14
15
16
17
18
19
20 public class MenuMatchRule implements Serializable {
21
22 private static final long serialVersionUID = 8115117407710728580L;
23
24 private JSONObject matchRule;
25
26 public MenuMatchRule() {
27 this.matchRule = new JSONObject();
28 }
29
30
31
32
33 private Integer tagId;
34
35 @JSONField(name = "tag_id")
36 public MenuMatchRule group(int tagId) {
37 matchRule.put("tag_id", tagId);
38 this.tagId = tagId;
39 return this;
40 }
41
42
43
44
45 private Gender gender;
46
47 @JSONField(name = "sex")
48 public void gender0(int sex) {
49 this.gender = Gender.values().length >= sex ? Gender.values()[sex - 1]
50 : null;
51 }
52
53 public MenuMatchRule gender(Gender gender) {
54 if (gender != null && gender != Gender.unknown) {
55 matchRule.put("sex", gender.ordinal() + 1);
56 }
57 this.gender = gender;
58 return this;
59 }
60
61
62
63
64 private ClientPlatformType platformType;
65
66
67
68
69
70 @JSONField(name = "client_platform_type")
71 public void platform0(int platform) {
72 this.platformType = ClientPlatformType.values().length >= platform ? ClientPlatformType
73 .values()[platform - 1] : null;
74 }
75
76 public MenuMatchRule platform(ClientPlatformType platformType) {
77 if (platformType != null) {
78 matchRule.put("client_platform_type", platformType.ordinal() + 1);
79 }
80 this.platformType = platformType;
81 return this;
82 }
83
84 private String country;
85
86
87
88
89
90
91
92
93
94
95
96 @JSONField(name = "country")
97 public MenuMatchRule country(String country) {
98 matchRule.put("country", country);
99 this.country = country;
100 return this;
101 }
102
103 private String province;
104
105
106
107
108
109
110
111
112
113
114
115 @JSONField(name = "province")
116 public MenuMatchRule province(String province) {
117 matchRule.put("province", province);
118 this.province = province;
119 return this;
120 }
121
122 private String city;
123
124
125
126
127
128
129
130
131
132
133
134 @JSONField(name = "city")
135 public MenuMatchRule city(String city) {
136 matchRule.put("city", city);
137 this.city = city;
138 return this;
139 }
140
141
142
143
144 private Lang language;
145
146
147
148
149
150 @JSONField(name = "language")
151 public void language0(int language) {
152 this.language = Lang.values().length >= language ? Lang.values()[language - 1]
153 : null;
154 }
155
156 public MenuMatchRule language(Lang language) {
157 if (language != null) {
158 matchRule.put("language", language.ordinal() + 1);
159 }
160 this.language = language;
161 return this;
162 }
163
164 public ClientPlatformType getPlatformType() {
165 return platformType;
166 }
167
168 public Integer getTagId() {
169 return tagId;
170 }
171
172 public Gender getGender() {
173 return gender;
174 }
175
176 public String getCountry() {
177 return country;
178 }
179
180 public String getProvince() {
181 return province;
182 }
183
184 public String getCity() {
185 return city;
186 }
187
188 public Lang getLanguage() {
189 return language;
190 }
191
192 public boolean hasRule() {
193 return !matchRule.isEmpty();
194 }
195
196 public JSONObject getRule() {
197 return this.matchRule;
198 }
199
200 @Override
201 public String toString() {
202 return "MenuMatchRule [tagId=" + tagId + ", gender=" + gender
203 + ", platformType=" + platformType + ", country=" + country
204 + ", province=" + province + ", city=" + city + ", language="
205 + language + "]";
206 }
207 }