Authored by ping

update

@@ -6,8 +6,6 @@ package com.yoho.unions.server.restapi; @@ -6,8 +6,6 @@ package com.yoho.unions.server.restapi;
6 import java.util.concurrent.ExecutorService; 6 import java.util.concurrent.ExecutorService;
7 import java.util.concurrent.Executors; 7 import java.util.concurrent.Executors;
8 8
9 -import javax.annotation.Resource;  
10 -  
11 import org.slf4j.Logger; 9 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory; 10 import org.slf4j.LoggerFactory;
13 import org.springframework.beans.BeanUtils; 11 import org.springframework.beans.BeanUtils;
@@ -61,6 +61,8 @@ public class UnionServiceImpl implements IUnionService { @@ -61,6 +61,8 @@ 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 +
  65 + try {
64 log.info("enter clickUnion with param is {}", request); 66 log.info("enter clickUnion with param is {}", request);
65 //检查输入参数 67 //检查输入参数
66 if (StringUtils.isEmpty(request.getAppid())) { 68 if (StringUtils.isEmpty(request.getAppid())) {
@@ -102,15 +104,10 @@ public class UnionServiceImpl implements IUnionService { @@ -102,15 +104,10 @@ public class UnionServiceImpl implements IUnionService {
102 // } 104 // }
103 105
104 //保存到缓存中,有效期三个小时 106 //保存到缓存中,有效期三个小时
105 - try {  
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);
110 - } catch (Exception e) {  
111 - log.error("clickUnion error set redis error with request={}", request);  
112 - return new UnionResponse(204, "set redis error");  
113 - }  
114 111
115 112
116 // if (union != null) { 113 // if (union != null) {
@@ -131,12 +128,19 @@ public class UnionServiceImpl implements IUnionService { @@ -131,12 +128,19 @@ public class UnionServiceImpl implements IUnionService {
131 // unionLogsDAO.insert(logs); 128 // unionLogsDAO.insert(logs);
132 129
133 return new UnionResponse(); 130 return new UnionResponse();
  131 + } catch (Exception e) {
  132 + log.error("clickUnion error with request={}", request, e);
  133 + return new UnionResponse(300, e.getMessage());
  134 + }
  135 +
  136 +
134 } 137 }
135 138
136 @Override 139 @Override
137 public UnionResponse activateUnion(ActivateUnionRequestBO request) throws ServiceException { 140 public UnionResponse activateUnion(ActivateUnionRequestBO request) throws ServiceException {
  141 + try {
138 log.info("activateUnion with request is {}", request); 142 log.info("activateUnion with request is {}", request);
139 - //检查输入参数 143 + // 检查输入参数
140 if (StringUtils.isEmpty(request.getAppid())) { 144 if (StringUtils.isEmpty(request.getAppid())) {
141 log.warn("activateUnion error because appid is empty with param is {}", request); 145 log.warn("activateUnion error because appid is empty with param is {}", request);
142 return new UnionResponse(201, "appid is empty"); 146 return new UnionResponse(201, "appid is empty");
@@ -160,42 +164,37 @@ public class UnionServiceImpl implements IUnionService { @@ -160,42 +164,37 @@ public class UnionServiceImpl implements IUnionService {
160 return new UnionResponse(201, "imei is empty"); 164 return new UnionResponse(201, "imei is empty");
161 } 165 }
162 166
163 - //组装redis保存的key 167 + // 组装redis保存的key
164 String key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd(); 168 String key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd();
165 - String value = "";  
166 - 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 - } 169 + String value = yhValueOperations.get(key);
172 170
173 log.info("activateUnion get key={}, value={}", key, value); 171 log.info("activateUnion get key={}, value={}", key, value);
174 - //如果redis中不存在存在该用户点击信息,则退出 172 + // 如果redis中不存在存在该用户点击信息,则退出
175 if (StringUtils.isEmpty(value)) { 173 if (StringUtils.isEmpty(value)) {
176 log.warn("activateUnion error user not click info. with param is {}", request); 174 log.warn("activateUnion error user not click info. with param is {}", request);
177 return new UnionResponse(204, "user not click"); 175 return new UnionResponse(204, "user not click");
178 } 176 }
179 177
180 - //把存储的字符串变为对象 178 + // 把存储的字符串变为对象
181 ClickUnionRequestBO click = JSON.parseObject(value, ClickUnionRequestBO.class); 179 ClickUnionRequestBO click = JSON.parseObject(value, ClickUnionRequestBO.class);
182 - //查询该td在90天内是否已经激活过 180 + // 查询该td在90天内是否已经激活过
183 UnionLogs union = unionLogsDAO.selectByClientType(request.getClient_type(), request.getIdfa(), request.getImei(), Byte.valueOf(click.getUnion_type())); 181 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); 182 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 -// } 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 + // }
190 189
191 if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) { 190 if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) {
192 - //如果90天之内有过激活日志,则不允许重复激活 191 + // 如果90天之内有过激活日志,则不允许重复激活
193 log.warn("activateUnion error because 90 days has activate info with param is {}", request); 192 log.warn("activateUnion error because 90 days has activate info with param is {}", request);
194 return new UnionResponse(203, "have activite in 90 days"); 193 return new UnionResponse(203, "have activite in 90 days");
195 } 194 }
196 195
197 -  
198 - //UnionTypeModel type = UnionConstant.unionTypeMap.get(Integer.parseInt(click.getUnion_type())); 196 + // UnionTypeModel type =
  197 + // UnionConstant.unionTypeMap.get(Integer.parseInt(click.getUnion_type()));
199 198
200 String url = click.getCallbackurl(); 199 String url = click.getCallbackurl();
201 if (url.indexOf("?") > 0) { 200 if (url.indexOf("?") > 0) {
@@ -214,10 +213,10 @@ public class UnionServiceImpl implements IUnionService { @@ -214,10 +213,10 @@ public class UnionServiceImpl implements IUnionService {
214 AsyncFuture<String> response = service.get("union.activate", url, null, String.class, null); 213 AsyncFuture<String> response = service.get("union.activate", url, null, String.class, null);
215 String result = response.get(); 214 String result = response.get();
216 log.info("activateUnion call union url={}, and result={}", url, result); 215 log.info("activateUnion call union url={}, and result={}", url, result);
217 - try { 216 +
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());
@@ -234,7 +233,7 @@ public class UnionServiceImpl implements IUnionService { @@ -234,7 +233,7 @@ public class UnionServiceImpl implements IUnionService {
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 }