Authored by ping

update

@@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
20 <value>/ActivateUnionRest/activateUnion</value> 20 <value>/ActivateUnionRest/activateUnion</value>
21 <value>/ClickUnionRest/addUnion</value> 21 <value>/ClickUnionRest/addUnion</value>
22 <value>/ClickUnionRest/addUnion4Special</value> 22 <value>/ClickUnionRest/addUnion4Special</value>
  23 + <value>/ClickUnionRest/addMonitor</value>
23 <value>/ActivateUnionRest/test</value> 24 <value>/ActivateUnionRest/test</value>
24 </list> 25 </list>
25 </property> 26 </property>
@@ -6,6 +6,10 @@ package com.yoho.unions.server.restapi; @@ -6,6 +6,10 @@ 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.servlet.http.HttpServletRequest;
  10 +import javax.servlet.http.HttpServletResponse;
  11 +
  12 +import org.apache.commons.lang.StringUtils;
9 import org.slf4j.Logger; 13 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory; 14 import org.slf4j.LoggerFactory;
11 import org.springframework.beans.BeanUtils; 15 import org.springframework.beans.BeanUtils;
@@ -44,11 +48,22 @@ public class ActivateUnionRest { @@ -44,11 +48,22 @@ public class ActivateUnionRest {
44 * @return 48 * @return
45 */ 49 */
46 @RequestMapping("/activateUnion") 50 @RequestMapping("/activateUnion")
47 - @ResponseBody public ActiveUnionResponseBO activateUnion(ActivateUnionRequestVO vo) { 51 + @ResponseBody public ActiveUnionResponseBO activateUnion(ActivateUnionRequestVO vo, HttpServletRequest request, HttpServletResponse response) {
48 log.info("activateUnion with param is {}", vo); 52 log.info("activateUnion with param is {}", vo);
49 if ("iphone".equals(vo.getClient_type())) { 53 if ("iphone".equals(vo.getClient_type())) {
50 vo.setClient_type(ClientTypeEnum.IOS.getName()); 54 vo.setClient_type(ClientTypeEnum.IOS.getName());
51 } 55 }
  56 + String agent = request.getHeader("user-agent");
  57 + log.info("addMonitor user-agent={}", agent);
  58 + if (StringUtils.isEmpty(vo.getTd()) && StringUtils.isNotEmpty(agent)) {
  59 + if (agent.toLowerCase().indexOf("mac os x") >= 0 || agent.toLowerCase().indexOf("iphone") >= 0) {
  60 + String version = agent.substring(agent.indexOf(" OS ") + 4, agent.indexOf(" like"));
  61 + vo.setTd("ios_" + version.replaceAll("_", "."));
  62 + log.info("activateUnion request={}", vo);
  63 + }
  64 + }
  65 +
  66 +
52 ActivateUnionRequestBO bo = new ActivateUnionRequestBO(); 67 ActivateUnionRequestBO bo = new ActivateUnionRequestBO();
53 BeanUtils.copyProperties(vo, bo); 68 BeanUtils.copyProperties(vo, bo);
54 String clientType = vo.getClient_type(); 69 String clientType = vo.getClient_type();
@@ -84,4 +84,27 @@ public class ClickUnionRest { @@ -84,4 +84,27 @@ public class ClickUnionRest {
84 } 84 }
85 } 85 }
86 86
  87 + @RequestMapping("/addMonitor")
  88 + public void addMonitor(ClickUnionRequestBO bo, HttpServletRequest request, HttpServletResponse response) {
  89 + try {
  90 + bo.setClientIp(RemoteIPInterceptor.getRemoteIP());
  91 + String agent = request.getHeader("user-agent");
  92 + log.info("addMonitor user-agent={}", agent);
  93 + if (!StringUtils.isEmpty(agent)) {
  94 + if (agent.toLowerCase().indexOf("mac os x") >= 0 || agent.toLowerCase().indexOf("iphone") >= 0) {
  95 + String version = agent.substring(agent.indexOf(" OS ") + 4, agent.indexOf(" like"));
  96 + bo.setTd("ios_" + version.replaceAll("_", "."));
  97 + bo.setClient_type("ios");
  98 + bo.setAppid("490655927");
  99 + log.info("addMonitor request={}", bo);
  100 + }
  101 + }
  102 + unionService.clickUnion(bo);
  103 + log.info("addMonitor with result is {}, and request is {}", response, bo);
  104 + response.setStatus(200);
  105 + } catch (Exception e) {
  106 + log.error("addMonitor error with request={}", bo, e);
  107 + }
  108 + }
  109 +
87 } 110 }