| @@ -8,6 +8,7 @@ import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.PostMapping; | import org.springframework.web.bind.annotation.PostMapping; | ||||
| import org.springframework.web.bind.annotation.RequestBody; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| @@ -75,5 +76,13 @@ public class DataTowerController extends BaseController { | |||||
| return new ResultData(data); | return new ResultData(data); | ||||
| } | } | ||||
| @ApiOperation("查询客流") | |||||
| @PostMapping("/queryCustomerData") | |||||
| public ResultData queryCustomerData(@RequestBody Map<String, String> params) { | |||||
| logger.debug("[" + getIpAddr() + "] DataTowerController::queryCustomer"); | |||||
| return dataTowerService.queryCustomerData(getTenantId(), params); | |||||
| } | |||||
| } | } | ||||
| @@ -1,6 +1,8 @@ | |||||
| package com.iformall.service; | package com.iformall.service; | ||||
| import com.iformall.common.ResultData; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| public interface DataTowerService { | public interface DataTowerService { | ||||
| @@ -15,4 +17,6 @@ public interface DataTowerService { | |||||
| Map<String,Object> queryCustomer(String tenantId); | Map<String,Object> queryCustomer(String tenantId); | ||||
| ResultData queryCustomerData(String tenantId, Map<String, String> params); | |||||
| } | } | ||||
| @@ -673,17 +673,10 @@ public class DataTowerServiceImpl implements DataTowerService { | |||||
| wxMall = list.get(0); | wxMall = list.get(0); | ||||
| String wiwideUrl = wxMall.getWiwideUrl(); | String wiwideUrl = wxMall.getWiwideUrl(); | ||||
| Map<String, Object> datamap = new HashMap<>(2); | Map<String, Object> datamap = new HashMap<>(2); | ||||
| Date expiredTime = wxMall.getExpiredTime(); | |||||
| String token = wxMall.getToken(); | |||||
| if (!StringUtils.isEmpty(token) && expiredTime!=null && expiredTime.after(new Date())) { | |||||
| datamap.put("token", wxMall.getToken()); | |||||
| } else { | |||||
| String data = WiwideUtil.queryToken(wxMall); | |||||
| token = (String) JSONObject.parseObject(data).get("data"); | |||||
| datamap.put("token", token); | |||||
| updateToken(wxMall, token); | |||||
| } | |||||
| datamap.put("token", getWiwideToken(wxMall)); | |||||
| datamap.put("url", wiwideUrl); | datamap.put("url", wiwideUrl); | ||||
| return datamap; | return datamap; | ||||
| } | } | ||||
| @@ -701,6 +694,43 @@ public class DataTowerServiceImpl implements DataTowerService { | |||||
| } | } | ||||
| } | } | ||||
| private String getWiwideToken(WxMall wxMall) { | |||||
| Date expiredTime = wxMall.getExpiredTime(); | |||||
| String token = wxMall.getToken(); | |||||
| if (StringUtils.isEmpty(token) || expiredTime == null || expiredTime.before(new Date())) { | |||||
| String data = WiwideUtil.queryToken(wxMall); | |||||
| token = (String) JSONObject.parseObject(data).get("data"); | |||||
| updateToken(wxMall, token); | |||||
| } | |||||
| return token; | |||||
| } | |||||
| @Override | |||||
| public ResultData queryCustomerData(String tenantId, Map<String, String> params) { | |||||
| WxMall wxMall = new WxMall(); | |||||
| wxMall.setTenantId(tenantId); | |||||
| List<WxMall> list = wxMallMapper.findList(wxMall); | |||||
| wxMall = list.get(0); | |||||
| if (wxMall == null) | |||||
| return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND); | |||||
| String res = WiwideUtil.queryData(wxMall, getWiwideToken(wxMall), params); | |||||
| JSONObject result = JSONObject.parseObject(res); | |||||
| if (result.getInteger("result") == 200) | |||||
| return new ResultData(result.getInteger("result"), | |||||
| result.getString("msg"), | |||||
| result.getJSONObject("data")); | |||||
| else | |||||
| return new ResultData(result.getInteger("result"), | |||||
| result.getString("msg")); | |||||
| } | |||||
| public TreeMap getTimeTreeMap() { | public TreeMap getTimeTreeMap() { | ||||
| TreeMap<Object, Object> timemap = new TreeMap(); | TreeMap<Object, Object> timemap = new TreeMap(); | ||||
| timemap.put("06:00", 0); | timemap.put("06:00", 0); | ||||
| @@ -137,6 +137,70 @@ public class HttpUtil { | |||||
| return null; | return null; | ||||
| } | } | ||||
| /** | |||||
| * post请求(用于key-value格式的参数,wiwide) | |||||
| * @param url | |||||
| * @param params | |||||
| * @return | |||||
| */ | |||||
| public static String doPostWiwide(String url, String token, Map params){ | |||||
| // 定义HttpClient | |||||
| CloseableHttpClient client = HttpClients.createDefault(); | |||||
| BufferedReader in = null; | |||||
| try { | |||||
| // 实例化HTTP方法 | |||||
| HttpPost request = new HttpPost(); | |||||
| request.setURI(new URI(url)); | |||||
| request.setHeader("Content-Type", "application/x-www-form-urlencoded"); | |||||
| request.setHeader("Accept-Charset", "utf-8"); | |||||
| request.setHeader("wiwidefumaotoken", token); | |||||
| //设置参数 | |||||
| List<NameValuePair> nvps = new ArrayList<NameValuePair>(); | |||||
| for (Iterator iter = params.keySet().iterator(); iter.hasNext();) { | |||||
| String name = (String) iter.next(); | |||||
| String value = String.valueOf(params.get(name)); | |||||
| nvps.add(new BasicNameValuePair(name, value)); | |||||
| //System.out.println(name +"-"+value); | |||||
| } | |||||
| request.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8)); | |||||
| HttpResponse response = client.execute(request); | |||||
| int code = response.getStatusLine().getStatusCode(); | |||||
| if(code == 200){ //请求成功 | |||||
| in = new BufferedReader(new InputStreamReader(response.getEntity() | |||||
| .getContent(),"utf-8")); | |||||
| StringBuffer sb = new StringBuffer(""); | |||||
| String line = ""; | |||||
| String NL = System.getProperty("line.separator"); | |||||
| while ((line = in.readLine()) != null) { | |||||
| sb.append(line + NL); | |||||
| } | |||||
| in.close(); | |||||
| client.close(); | |||||
| return sb.toString(); | |||||
| } | |||||
| else{ // | |||||
| logger.info("状态码:" + code); | |||||
| client.close(); | |||||
| } | |||||
| } | |||||
| catch(Exception e){ | |||||
| logger.error(e.getMessage()); | |||||
| return null; | |||||
| } | |||||
| return null; | |||||
| } | |||||
| /** | /** | ||||
| * post请求(用于请求json格式的参数) | * post请求(用于请求json格式的参数) | ||||
| * @param url | * @param url | ||||
| @@ -142,4 +142,10 @@ public class WiwideUtil { | |||||
| logger.info("商场:" + wxMall.getName() + ",返回TOKEN" + token); | logger.info("商场:" + wxMall.getName() + ",返回TOKEN" + token); | ||||
| return token; | return token; | ||||
| } | } | ||||
| public static String queryData(WxMall wxMall, String token, Map<String, String> params) { | |||||
| String data = HttpUtil.doPostWiwide(wxMall.getWiwideUrl() + "/reports/data", token, params); | |||||
| return data; | |||||
| } | |||||
| } | } | ||||