|
@@ -61,163 +61,162 @@ public class UnionServiceImpl implements IUnionService { |
|
@@ -61,163 +61,162 @@ public class UnionServiceImpl implements IUnionService { |
61
|
|
61
|
|
62
|
@Override
|
62
|
@Override
|
63
|
public UnionResponse clickUnion(ClickUnionRequestBO request) throws ServiceException {
|
63
|
public UnionResponse clickUnion(ClickUnionRequestBO request) throws ServiceException {
|
64
|
- log.info("enter clickUnion with param is {}", request);
|
|
|
65
|
- //检查输入参数
|
|
|
66
|
- if (StringUtils.isEmpty(request.getAppid())) {
|
|
|
67
|
- log.warn("clickUnion error because appid is empty with param is {}", request);
|
|
|
68
|
- return new UnionResponse(201, "appid is empty");
|
|
|
69
|
- }
|
|
|
70
|
- if (StringUtils.isEmpty(request.getTd())) {
|
|
|
71
|
- log.warn("clickUnion error because td is empty with param is {}", request);
|
|
|
72
|
- return new UnionResponse(201, "td is empty");
|
|
|
73
|
- }
|
|
|
74
|
- if (StringUtils.isEmpty(request.getUnion_type())) {
|
|
|
75
|
- log.warn("clickUnion error because union_type is empty with param is {}", request);
|
|
|
76
|
- return new UnionResponse(201, "union_type is empty");
|
|
|
77
|
- }
|
|
|
78
|
- if (StringUtils.isEmpty(request.getCallbackurl())) {
|
|
|
79
|
- log.warn("clickUnion error because callbackurl is empty with param is {}", request);
|
|
|
80
|
- return new UnionResponse(201, "callbackurl is empty");
|
|
|
81
|
- }
|
|
|
82
|
|
64
|
|
83
|
- //组装redis保存的key
|
|
|
84
|
- String key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd();
|
|
|
85
|
-
|
|
|
86
|
-// String value = yhValueOperations.get(key);
|
|
|
87
|
-// log.info("clickUnion get key={}, value={}", key, value);
|
|
|
88
|
-// //如果redis中已经存在该用户点击信息,则不再重复保存
|
|
|
89
|
-// if (StringUtils.isNotEmpty(value)) {
|
|
|
90
|
-// log.warn("clickUnion error click info is exists with param is {}", request);
|
|
|
91
|
-// return new UnionResponse(202, "click info is exists");
|
|
|
92
|
-// }
|
|
|
93
|
-
|
|
|
94
|
-// //查询该用户是否已经激活过
|
|
|
95
|
-//
|
|
|
96
|
-// UnionLogs union = unionLogsDAO.selectByTd(request.getTd());
|
|
|
97
|
-// log.info("clickUnion in selectByTd result is {}", union);
|
|
|
98
|
-// if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) {
|
|
|
99
|
-// //如果90天之内有过激活日志,则不允许重复激活
|
|
|
100
|
-// log.warn("clickUnion error because 90 days has activate info with param is {}", request);
|
|
|
101
|
-// return new UnionResponse(203, "have activite in 90 days");
|
|
|
102
|
-// }
|
|
|
103
|
-
|
|
|
104
|
- //保存到缓存中,有效期三个小时
|
|
|
105
|
try {
|
65
|
try {
|
|
|
66
|
+ log.info("enter clickUnion with param is {}", request);
|
|
|
67
|
+ //检查输入参数
|
|
|
68
|
+ if (StringUtils.isEmpty(request.getAppid())) {
|
|
|
69
|
+ log.warn("clickUnion error because appid is empty with param is {}", request);
|
|
|
70
|
+ return new UnionResponse(201, "appid is empty");
|
|
|
71
|
+ }
|
|
|
72
|
+ if (StringUtils.isEmpty(request.getTd())) {
|
|
|
73
|
+ log.warn("clickUnion error because td is empty with param is {}", request);
|
|
|
74
|
+ return new UnionResponse(201, "td is empty");
|
|
|
75
|
+ }
|
|
|
76
|
+ if (StringUtils.isEmpty(request.getUnion_type())) {
|
|
|
77
|
+ log.warn("clickUnion error because union_type is empty with param is {}", request);
|
|
|
78
|
+ return new UnionResponse(201, "union_type is empty");
|
|
|
79
|
+ }
|
|
|
80
|
+ if (StringUtils.isEmpty(request.getCallbackurl())) {
|
|
|
81
|
+ log.warn("clickUnion error because callbackurl is empty with param is {}", request);
|
|
|
82
|
+ return new UnionResponse(201, "callbackurl is empty");
|
|
|
83
|
+ }
|
|
|
84
|
+
|
|
|
85
|
+ //组装redis保存的key
|
|
|
86
|
+ String key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd();
|
|
|
87
|
+
|
|
|
88
|
+// String value = yhValueOperations.get(key);
|
|
|
89
|
+// log.info("clickUnion get key={}, value={}", key, value);
|
|
|
90
|
+// //如果redis中已经存在该用户点击信息,则不再重复保存
|
|
|
91
|
+// if (StringUtils.isNotEmpty(value)) {
|
|
|
92
|
+// log.warn("clickUnion error click info is exists with param is {}", request);
|
|
|
93
|
+// return new UnionResponse(202, "click info is exists");
|
|
|
94
|
+// }
|
|
|
95
|
+
|
|
|
96
|
+// //查询该用户是否已经激活过
|
|
|
97
|
+//
|
|
|
98
|
+// UnionLogs union = unionLogsDAO.selectByTd(request.getTd());
|
|
|
99
|
+// log.info("clickUnion in selectByTd result is {}", union);
|
|
|
100
|
+// if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) {
|
|
|
101
|
+// //如果90天之内有过激活日志,则不允许重复激活
|
|
|
102
|
+// log.warn("clickUnion error because 90 days has activate info with param is {}", request);
|
|
|
103
|
+// return new UnionResponse(203, "have activite in 90 days");
|
|
|
104
|
+// }
|
|
|
105
|
+
|
|
|
106
|
+ //保存到缓存中,有效期三个小时
|
106
|
yhValueOperations.setIfAbsent(key, JSON.toJSONString(request));
|
107
|
yhValueOperations.setIfAbsent(key, JSON.toJSONString(request));
|
107
|
DynamicIntProperty activeTime = DynamicPropertyFactory.getInstance().getIntProperty("activeTime", 3 * 60 * 60);
|
108
|
DynamicIntProperty activeTime = DynamicPropertyFactory.getInstance().getIntProperty("activeTime", 3 * 60 * 60);
|
108
|
yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.SECONDS);
|
109
|
yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.SECONDS);
|
109
|
log.info("clickUnion set redis success with request={}", request);
|
110
|
log.info("clickUnion set redis success with request={}", request);
|
|
|
111
|
+
|
|
|
112
|
+
|
|
|
113
|
+// if (union != null) {
|
|
|
114
|
+// //如果90天以内,已经存在点击记录,则不需要插入或更新数据库
|
|
|
115
|
+// log.info("clickUnion have click in 90 days with request={}", request);
|
|
|
116
|
+// return new UnionResponse();
|
|
|
117
|
+// }
|
|
|
118
|
+ //保存信息到数据库
|
|
|
119
|
+// UnionLogs logs = new UnionLogs();
|
|
|
120
|
+// logs.setTd(request.getTd());
|
|
|
121
|
+// logs.setAppId(request.getAppid());
|
|
|
122
|
+// logs.setClientType(request.getClient_type());
|
|
|
123
|
+// logs.setUnionType(Byte.valueOf(request.getUnion_type()));
|
|
|
124
|
+// logs.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
125
|
+// logs.setUpdateTime(logs.getCreateTime());
|
|
|
126
|
+// logs.setAddParams(JSON.toJSONString(request));
|
|
|
127
|
+// logs.setIsActivate(Byte.valueOf("0"));
|
|
|
128
|
+// unionLogsDAO.insert(logs);
|
|
|
129
|
+
|
|
|
130
|
+ return new UnionResponse();
|
110
|
} catch (Exception e) {
|
131
|
} catch (Exception e) {
|
111
|
- log.error("clickUnion error set redis error with request={}", request);
|
|
|
112
|
- return new UnionResponse(204, "set redis error");
|
132
|
+ log.error("clickUnion error with request={}", request, e);
|
|
|
133
|
+ return new UnionResponse(300, e.getMessage());
|
113
|
}
|
134
|
}
|
114
|
|
135
|
|
115
|
|
136
|
|
116
|
-// if (union != null) {
|
|
|
117
|
-// //如果90天以内,已经存在点击记录,则不需要插入或更新数据库
|
|
|
118
|
-// log.info("clickUnion have click in 90 days with request={}", request);
|
|
|
119
|
-// return new UnionResponse();
|
|
|
120
|
-// }
|
|
|
121
|
- //保存信息到数据库
|
|
|
122
|
-// UnionLogs logs = new UnionLogs();
|
|
|
123
|
-// logs.setTd(request.getTd());
|
|
|
124
|
-// logs.setAppId(request.getAppid());
|
|
|
125
|
-// logs.setClientType(request.getClient_type());
|
|
|
126
|
-// logs.setUnionType(Byte.valueOf(request.getUnion_type()));
|
|
|
127
|
-// logs.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
128
|
-// logs.setUpdateTime(logs.getCreateTime());
|
|
|
129
|
-// logs.setAddParams(JSON.toJSONString(request));
|
|
|
130
|
-// logs.setIsActivate(Byte.valueOf("0"));
|
|
|
131
|
-// unionLogsDAO.insert(logs);
|
|
|
132
|
-
|
|
|
133
|
- return new UnionResponse();
|
|
|
134
|
}
|
137
|
}
|
135
|
|
138
|
|
136
|
@Override
|
139
|
@Override
|
137
|
public UnionResponse activateUnion(ActivateUnionRequestBO request) throws ServiceException {
|
140
|
public UnionResponse activateUnion(ActivateUnionRequestBO request) throws ServiceException {
|
138
|
- log.info("activateUnion with request is {}", request);
|
|
|
139
|
- //检查输入参数
|
|
|
140
|
- if (StringUtils.isEmpty(request.getAppid())) {
|
|
|
141
|
- log.warn("activateUnion error because appid is empty with param is {}", request);
|
|
|
142
|
- return new UnionResponse(201, "appid is empty");
|
|
|
143
|
- }
|
|
|
144
|
- if (StringUtils.isEmpty(request.getTd())) {
|
|
|
145
|
- log.warn("activateUnion error because td is empty with param is {}", request);
|
|
|
146
|
- return new UnionResponse(201, "td is empty");
|
|
|
147
|
- }
|
|
|
148
|
- if (StringUtils.isEmpty(request.getUdid())) {
|
|
|
149
|
- log.warn("activateUnion error because udid is empty with param is {}", request);
|
|
|
150
|
- return new UnionResponse(201, "udid is empty");
|
|
|
151
|
- }
|
|
|
152
|
-
|
|
|
153
|
- if (ClientTypeEnum.IOS.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getIdfa())) {
|
|
|
154
|
- log.warn("activateUnion error because idfa is empty with request is {}", request);
|
|
|
155
|
- return new UnionResponse(201, "idfa is empty");
|
|
|
156
|
- }
|
|
|
157
|
-
|
|
|
158
|
- if (ClientTypeEnum.ANDROID.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getImei())) {
|
|
|
159
|
- log.warn("activateUnion error because imei is empty with request is {}", request);
|
|
|
160
|
- return new UnionResponse(201, "imei is empty");
|
|
|
161
|
- }
|
|
|
162
|
-
|
|
|
163
|
- //组装redis保存的key
|
|
|
164
|
- String key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd();
|
|
|
165
|
- String value = "";
|
|
|
166
|
try {
|
141
|
try {
|
167
|
- value = yhValueOperations.get(key);
|
|
|
168
|
- } catch (Exception e) {
|
|
|
169
|
- log.error("activateUnion error get redis error with request={}", request);
|
|
|
170
|
- return new UnionResponse(204, "get redis error");
|
|
|
171
|
- }
|
|
|
172
|
-
|
|
|
173
|
- log.info("activateUnion get key={}, value={}", key, value);
|
|
|
174
|
- //如果redis中不存在存在该用户点击信息,则退出
|
|
|
175
|
- if (StringUtils.isEmpty(value)) {
|
|
|
176
|
- log.warn("activateUnion error user not click info. with param is {}", request);
|
|
|
177
|
- return new UnionResponse(204, "user not click");
|
|
|
178
|
- }
|
|
|
179
|
-
|
|
|
180
|
- //把存储的字符串变为对象
|
|
|
181
|
- ClickUnionRequestBO click = JSON.parseObject(value, ClickUnionRequestBO.class);
|
|
|
182
|
- //查询该td在90天内是否已经激活过
|
|
|
183
|
- UnionLogs union = unionLogsDAO.selectByClientType(request.getClient_type(), request.getIdfa(), request.getImei(), Byte.valueOf(click.getUnion_type()));
|
|
|
184
|
- log.info("activateUnion in selectByClientType result is {}", union);
|
|
|
185
|
- //没有点击记录,则退出
|
|
|
186
|
-// if (union == null) {
|
|
|
187
|
-// log.warn("activateUnion error because not click record with request is {}", request);
|
|
|
188
|
-// return new UnionResponse(205, "not click record");
|
|
|
189
|
-// }
|
|
|
190
|
-
|
|
|
191
|
- if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) {
|
|
|
192
|
- //如果90天之内有过激活日志,则不允许重复激活
|
|
|
193
|
- log.warn("activateUnion error because 90 days has activate info with param is {}", request);
|
|
|
194
|
- return new UnionResponse(203, "have activite in 90 days");
|
|
|
195
|
- }
|
|
|
196
|
-
|
|
|
197
|
-
|
|
|
198
|
- //UnionTypeModel type = UnionConstant.unionTypeMap.get(Integer.parseInt(click.getUnion_type()));
|
|
|
199
|
-
|
|
|
200
|
- String url = click.getCallbackurl();
|
|
|
201
|
- if (url.indexOf("?") > 0) {
|
|
|
202
|
- url += "&identify_id=" + click.getIdentify_id();
|
|
|
203
|
- } else {
|
|
|
204
|
- url += "?identify_id=" + click.getIdentify_id();
|
|
|
205
|
- }
|
142
|
+ log.info("activateUnion with request is {}", request);
|
|
|
143
|
+ // 检查输入参数
|
|
|
144
|
+ if (StringUtils.isEmpty(request.getAppid())) {
|
|
|
145
|
+ log.warn("activateUnion error because appid is empty with param is {}", request);
|
|
|
146
|
+ return new UnionResponse(201, "appid is empty");
|
|
|
147
|
+ }
|
|
|
148
|
+ if (StringUtils.isEmpty(request.getTd())) {
|
|
|
149
|
+ log.warn("activateUnion error because td is empty with param is {}", request);
|
|
|
150
|
+ return new UnionResponse(201, "td is empty");
|
|
|
151
|
+ }
|
|
|
152
|
+ if (StringUtils.isEmpty(request.getUdid())) {
|
|
|
153
|
+ log.warn("activateUnion error because udid is empty with param is {}", request);
|
|
|
154
|
+ return new UnionResponse(201, "udid is empty");
|
|
|
155
|
+ }
|
|
|
156
|
+
|
|
|
157
|
+ if (ClientTypeEnum.IOS.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getIdfa())) {
|
|
|
158
|
+ log.warn("activateUnion error because idfa is empty with request is {}", request);
|
|
|
159
|
+ return new UnionResponse(201, "idfa is empty");
|
|
|
160
|
+ }
|
|
|
161
|
+
|
|
|
162
|
+ if (ClientTypeEnum.ANDROID.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getImei())) {
|
|
|
163
|
+ log.warn("activateUnion error because imei is empty with request is {}", request);
|
|
|
164
|
+ return new UnionResponse(201, "imei is empty");
|
|
|
165
|
+ }
|
|
|
166
|
+
|
|
|
167
|
+ // 组装redis保存的key
|
|
|
168
|
+ String key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd();
|
|
|
169
|
+ String value = yhValueOperations.get(key);
|
|
|
170
|
+
|
|
|
171
|
+ log.info("activateUnion get key={}, value={}", key, value);
|
|
|
172
|
+ // 如果redis中不存在存在该用户点击信息,则退出
|
|
|
173
|
+ if (StringUtils.isEmpty(value)) {
|
|
|
174
|
+ log.warn("activateUnion error user not click info. with param is {}", request);
|
|
|
175
|
+ return new UnionResponse(204, "user not click");
|
|
|
176
|
+ }
|
|
|
177
|
+
|
|
|
178
|
+ // 把存储的字符串变为对象
|
|
|
179
|
+ ClickUnionRequestBO click = JSON.parseObject(value, ClickUnionRequestBO.class);
|
|
|
180
|
+ // 查询该td在90天内是否已经激活过
|
|
|
181
|
+ UnionLogs union = unionLogsDAO.selectByClientType(request.getClient_type(), request.getIdfa(), request.getImei(), Byte.valueOf(click.getUnion_type()));
|
|
|
182
|
+ log.info("activateUnion in selectByClientType result is {}", union);
|
|
|
183
|
+ // 没有点击记录,则退出
|
|
|
184
|
+ // if (union == null) {
|
|
|
185
|
+ // log.warn("activateUnion error because not click record with request is {}",
|
|
|
186
|
+ // request);
|
|
|
187
|
+ // return new UnionResponse(205, "not click record");
|
|
|
188
|
+ // }
|
|
|
189
|
+
|
|
|
190
|
+ if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) {
|
|
|
191
|
+ // 如果90天之内有过激活日志,则不允许重复激活
|
|
|
192
|
+ log.warn("activateUnion error because 90 days has activate info with param is {}", request);
|
|
|
193
|
+ return new UnionResponse(203, "have activite in 90 days");
|
|
|
194
|
+ }
|
|
|
195
|
+
|
|
|
196
|
+ // UnionTypeModel type =
|
|
|
197
|
+ // UnionConstant.unionTypeMap.get(Integer.parseInt(click.getUnion_type()));
|
|
|
198
|
+
|
|
|
199
|
+ String url = click.getCallbackurl();
|
|
|
200
|
+ if (url.indexOf("?") > 0) {
|
|
|
201
|
+ url += "&identify_id=" + click.getIdentify_id();
|
|
|
202
|
+ } else {
|
|
|
203
|
+ url += "?identify_id=" + click.getIdentify_id();
|
|
|
204
|
+ }
|
|
|
205
|
+
|
|
|
206
|
+ if (ClientTypeEnum.IOS.getName().equals(request.getClient_type())) {
|
|
|
207
|
+ url += "&idfa=" + click.getIdfa();
|
|
|
208
|
+ } else {
|
|
|
209
|
+ url += "&imei=" + click.getImei();
|
|
|
210
|
+ }
|
|
|
211
|
+
|
|
|
212
|
+ // 调用接口发送短信请求
|
|
|
213
|
+ AsyncFuture<String> response = service.get("union.activate", url, null, String.class, null);
|
|
|
214
|
+ String result = response.get();
|
|
|
215
|
+ log.info("activateUnion call union url={}, and result={}", url, result);
|
206
|
|
216
|
|
207
|
- if (ClientTypeEnum.IOS.getName().equals(request.getClient_type())) {
|
|
|
208
|
- url += "&idfa=" + click.getIdfa();
|
|
|
209
|
- } else {
|
|
|
210
|
- url += "&imei=" + click.getImei();
|
|
|
211
|
- }
|
|
|
212
|
-
|
|
|
213
|
- // 调用接口发送短信请求
|
|
|
214
|
- AsyncFuture<String> response = service.get("union.activate", url, null, String.class, null);
|
|
|
215
|
- String result = response.get();
|
|
|
216
|
- log.info("activateUnion call union url={}, and result={}", url, result);
|
|
|
217
|
- try {
|
|
|
218
|
JSONObject json = JSON.parseObject(result);
|
217
|
JSONObject json = JSON.parseObject(result);
|
219
|
if (json.getInteger("code") == 200) {
|
218
|
if (json.getInteger("code") == 200) {
|
220
|
- //调用成功,更新数据库
|
219
|
+ // 调用成功,更新数据库
|
221
|
UnionLogs logs = new UnionLogs();
|
220
|
UnionLogs logs = new UnionLogs();
|
222
|
logs.setAppId(click.getAppid());
|
221
|
logs.setAppId(click.getAppid());
|
223
|
logs.setUdid(request.getUdid());
|
222
|
logs.setUdid(request.getUdid());
|
|
@@ -232,9 +231,9 @@ public class UnionServiceImpl implements IUnionService { |
|
@@ -232,9 +231,9 @@ public class UnionServiceImpl implements IUnionService { |
232
|
logs.setAddParams(value);
|
231
|
logs.setAddParams(value);
|
233
|
logs.setTd(request.getTd());
|
232
|
logs.setTd(request.getTd());
|
234
|
unionLogsDAO.insert(logs);
|
233
|
unionLogsDAO.insert(logs);
|
235
|
-
|
234
|
+
|
236
|
UnionTypeModel u = UnionConstant.unionTypeMap.get(Integer.parseInt(click.getUnion_type()));
|
235
|
UnionTypeModel u = UnionConstant.unionTypeMap.get(Integer.parseInt(click.getUnion_type()));
|
237
|
- //记录日志
|
236
|
+ // 记录日志
|
238
|
JSONObject j = new JSONObject();
|
237
|
JSONObject j = new JSONObject();
|
239
|
j.put("apptype", request.getClient_type());
|
238
|
j.put("apptype", request.getClient_type());
|
240
|
j.put("appid", click.getAppid());
|
239
|
j.put("appid", click.getAppid());
|
|
@@ -251,9 +250,10 @@ public class UnionServiceImpl implements IUnionService { |
|
@@ -251,9 +250,10 @@ public class UnionServiceImpl implements IUnionService { |
251
|
return new UnionResponse(json.getInteger("code"), json.getString("message"));
|
250
|
return new UnionResponse(json.getInteger("code"), json.getString("message"));
|
252
|
}
|
251
|
}
|
253
|
} catch (Exception e) {
|
252
|
} catch (Exception e) {
|
254
|
- log.error("activateUnion result is not json with url={}, result={}", url, result);
|
|
|
255
|
- return new UnionResponse(210, "error");
|
253
|
+ log.error("activateUnion error with request={}", request, e);
|
|
|
254
|
+ return new UnionResponse(300, e.getMessage());
|
256
|
}
|
255
|
}
|
|
|
256
|
+
|
257
|
}
|
257
|
}
|
258
|
|
258
|
|
259
|
} |
259
|
} |