Exemplo n.º 1
0
 /** 根据经纬度获取地址 */
 public static AMapAddress getAddress(double longitude, double latitude) {
   AMapAddress address = null;
   String url = MessageFormat.format(aMapUrl, String.valueOf(longitude), String.valueOf(latitude));
   String str = HttpUtils.get(url);
   try {
     if (StringUtils.isNotBlank(url)) {
       JSONObject json = JSONObject.parseObject(str);
       if (null != json) {
         int status = json.getIntValue("status");
         if (status == 1) {
           JSONObject regeocode = json.getJSONObject("regeocode");
           if (null != regeocode) {
             JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
             if (null != addressComponent) {
               // city 值不固定
               String province = addressComponent.getString("province");
               String citycode = addressComponent.getString("citycode");
               String city = addressComponent.getString("city");
               if (StringUtils.isNotBlank(city) && city.equals("[]")) {
                 city = "";
               }
               address = new AMapAddress();
               address.setCityCode(citycode);
               address.setProvince(province);
               address.setCity(city);
             }
           }
         }
       }
     }
   } catch (Exception e) {
   }
   return address;
 }
Exemplo n.º 2
0
  public static JSONObject loadMemoryInfo(String app) {
    try {
      MemoryMXBean mBean = JMConnManager.getMemoryMBean(app);
      MemoryUsage nonHeap = mBean.getNonHeapMemoryUsage();
      MemoryUsage heap = mBean.getHeapMemoryUsage();

      JSONObject map = new JSONObject(true);
      buildMemoryJSon(heap, "heap", map);
      buildMemoryJSon(nonHeap, "nonheap", map);

      JSONObject heapChild = new JSONObject();
      JSONObject nonheapChild = new JSONObject();

      JSONObject heapUsed = new JSONObject();
      JSONObject heapMax = new JSONObject();
      heapUsed.put("used", heap.getUsed());
      heapMax.put("used", heap.getCommitted());
      heapChild.put("HeapUsed", heapUsed);
      heapChild.put("HeapCommit", heapMax);

      JSONObject nonheapUsed = new JSONObject();
      JSONObject noheapMax = new JSONObject();
      nonheapUsed.put("used", nonHeap.getUsed());
      noheapMax.put("used", nonHeap.getCommitted());

      nonheapChild.put("NonheapUsed", nonheapUsed);
      nonheapChild.put("NonheapCommit", noheapMax);

      ObjectName obj = new ObjectName("java.lang:type=MemoryPool,*");
      MBeanServerConnection conn = JMConnManager.getConn(app);
      Set<ObjectInstance> MBeanset = conn.queryMBeans(obj, null);
      for (ObjectInstance objx : MBeanset) {
        String name = objx.getObjectName().getCanonicalName();
        String keyName = objx.getObjectName().getKeyProperty("name");
        MemoryPoolMXBean bean = JMConnManager.getServer(app, name, MemoryPoolMXBean.class);
        JSONObject item = toJson(bean.getUsage());
        if (JMConnManager.HEAP_ITEM.contains(keyName)) {
          heapChild.put(keyName, item);
        } else {
          nonheapChild.put(keyName, item);
        }
      }
      map.getJSONObject("heap").put("childs", heapChild);
      map.getJSONObject("nonheap").put("childs", nonheapChild);

      return map;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 3
0
  @Override
  public UserDataResponse parse(String paramString) {
    UserDataResponse response = null;
    try {
      response = new UserDataResponse();
      JSONObject jsonObject = JSON.parseObject(paramString);
      response.StateCode = jsonObject.getString(ERROR_CODE);
      response.Msg = jsonObject.getString(MSG);
      JSONObject object = jsonObject.getJSONObject("Data");

      UserData userData = new UserData();
      if (object != null) {
        userData.Birthday = object.getString("Birthday"); // 生日
        userData.Age = object.getString("Age"); // 年龄
        userData.Email = object.getString("Email"); // 邮箱
        userData.Gender = object.getString("Gender"); // 性别
        userData.QQ = object.getString("QQ"); // QQ
        userData.Name = object.getString("Name"); // 姓名

        userData.GradeName = object.getString("GradeName"); // 等级名称
        userData.NestGradeName = object.getString("NestGradeName"); // 下一等级名称
        userData.Point = object.getIntValue("Point"); // 积分
        userData.Exp = object.getIntValue("Exp"); // 经验
        userData.NeedExp = object.getIntValue("NeedExp"); // 这一级的总经验
      }

      // userData.Nickname = jsonObject.getString("Nickname");// 昵称

      response.userData = userData;

    } catch (Exception e) {
      e.printStackTrace();
    }
    return response;
  }
Exemplo n.º 4
0
  /**
   * 获取用户列表
   *
   * @param nextOpenId nextOpenId
   * @param accessToken
   * @return 用户列表
   * @throws ServiceException 服务异常
   */
  public static UserOpenIdListResponse getUserOpenIdList(String nextOpenId, String accessToken)
      throws ServiceException {
    // url and params
    nextOpenId = StringUtils.isEmpty(nextOpenId) ? "" : nextOpenId;
    String url = getRequestUrl(WechatUrlConstants.USER_GET, accessToken);
    url = url.replace("NEXT_OPENID", nextOpenId);

    // call wx and get response
    JSONObject responseJson = getWxJSONObjectResponseFromHttpGetMethod(url);
    int total = responseJson.getIntValue("total");
    JSONObject dataJson = responseJson.getJSONObject("data");
    JSONArray openidArray = dataJson.getJSONArray("openid");
    List<String> openIdList = new ArrayList<String>();
    for (int index = 0; index < openidArray.size(); index++) {
      String openId = openidArray.getString(index);
      openIdList.add(openId);
    }
    String respNextOpenid = responseJson.getString("next_openid");

    UserOpenIdListResponse result = new UserOpenIdListResponse();
    result.setTotal(total);
    result.setNextOpenid(respNextOpenid);
    result.setOpenIdList(openIdList);
    return result;
  }
Exemplo n.º 5
0
  private List<TaobaoCommentBean> parseTmallComment(String result, Task task) {

    String json = result.substring(1, result.length() - 1);
    JSONObject parseObject = JSON.parseObject(json);
    JSONArray jsonArray = parseObject.getJSONArray("comments");
    List<TaobaoCommentBean> beans = new ArrayList<TaobaoCommentBean>(jsonArray.size());
    JSONObject jsonObject = null;
    TaobaoCommentBean bean = null;
    for (int i = 0; i < jsonArray.size(); i++) {
      bean = new TaobaoCommentBean();
      bean.setType(task.getExtra());
      try {
        jsonObject = jsonArray.getJSONObject(i);
        String aucNumId = jsonObject.getJSONObject("auction").getString("aucNumId");
        bean.setItemId(aucNumId);
        String rateId = jsonObject.getString("rateId");
        bean.setId(rateId);
        String content = jsonObject.getString("content");
        bean.setConmment(content.trim());
        String vip = jsonObject.getJSONObject("user").getString("vip");
        bean.setVip(vip);
        String nick = jsonObject.getJSONObject("user").getString("nick");
        bean.setNick(nick);
        String day = jsonObject.getString("date");
        bean.setCommentTime(day);
        JSONObject jsonTmp = jsonObject.getJSONObject("reply");

        if (jsonTmp != null) {
          String reply = jsonTmp.getString("content");
          bean.setReply(reply.trim());
        }
        jsonTmp = jsonObject.getJSONObject("append");
        if (jsonTmp != null) {
          String append = jsonTmp.getString("content");
          bean.setAppandConmment(append.trim());
        }
        beans.add(bean);
      } catch (Exception e) {

      }
    }
    return beans;
  }
  public boolean check(JSONObject jsonObject) {

    boolean result = true;

    // response不处理
    if (StringUtils.isNotBlank(jsonObject.getString(FieldName.bidResponseTime))) {
      return false;
    }

    if (jsonObject.getJSONObject(FieldName.Tanx.mobile) == null) {
      return false;
    }

    JSONObject device =
        jsonObject.getJSONObject(FieldName.Tanx.mobile).getJSONObject(FieldName.Tanx.device);

    if (device == null || StringUtils.isBlank(device.getString(FieldName.Tanx.device_id))) {
      return false;
    }

    return result;
  }
Exemplo n.º 7
0
  public void JsonData(String datas) {
    try {
      JSONObject resultO = JSON.parseObject(datas);
      String reason = resultO.getString("Success");
      if (reason.equals("Success")) {
        JSONObject result = resultO.getJSONObject("result");
        JSONArray data = result.getJSONArray("data");

      } else Log.i("MSG", "解析失败");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 8
0
 @Override
 public void handleMessage(Message msg) {
   super.handleMessage(msg);
   switch (msg.what) {
     case 1:
       setmap(urlstr);
       calssAdapter = new CalssAdapter(array, ReplyPhoto.this);
       calss.setAdapter(calssAdapter);
       break;
     case 2:
       Toast.makeText(ReplyPhoto.this, "获取分类失败,请检查网络", Toast.LENGTH_SHORT).show();
       break;
     case 3:
       Toast.makeText(ReplyPhoto.this, "暂无分类", Toast.LENGTH_SHORT).show();
       break;
     case 4:
       dialog.dismiss();
       Toast.makeText(ReplyPhoto.this, "失败", Toast.LENGTH_SHORT).show();
       break;
     case 5:
       dialog.dismiss();
       JSONObject jsonObject = JSON.parseObject(str);
       int a = jsonObject.getIntValue("ret");
       if (a == 200) {
         JSONObject jsonObject1 = jsonObject.getJSONObject("data");
         int b = jsonObject1.getIntValue("code");
         if (b == 0) {
           //                            Bimp.tempSelectBitmap.clear();
           Bimp.tempSelectBitmap.clear();
           Bimp.max = 0;
           Intent intent = new Intent("data.broadcast.action");
           sendBroadcast(intent);
           for (int i = 0; i < PublicWay.activityList.size(); i++) {
             if (null != PublicWay.activityList.get(i)) {
               PublicWay.activityList.get(i).finish();
             }
           }
           //                            finish();
           Intent intent1 = new Intent();
           intent1.setAction("com.servicedemo4");
           intent1.putExtra("getmeeage", "4");
           ReplyPhoto.this.sendBroadcast(intent1);
         } else {
           handlers.sendEmptyMessage(4);
         }
       } else {
         handlers.sendEmptyMessage(4);
       }
       break;
   }
 }
Exemplo n.º 9
0
  @Override
  public void onResponse(CottyResponse cottyResponse) {
    System.out.println(cottyResponse.getContent());
    JSONObject jsonObject = JSONObject.parseObject(cottyResponse.getContent());
    Map<Long, CottyFriend> cottyFriendMap = new HashMap<Long, CottyFriend>();

    if (jsonObject.getInteger("retcode").equals(0)) {
      JSONObject resultObject = jsonObject.getJSONObject("result");
      JSONArray friendArray = resultObject.getJSONArray("friends");
      JSONArray infoArray = resultObject.getJSONArray("info");
      JSONArray marknameArray = resultObject.getJSONArray("marknames");
      JSONArray vipArray = resultObject.getJSONArray("vipinfo");

      for (int i = 0; i < friendArray.size(); i++) {
        JSONObject friendObject = friendArray.getJSONObject(i);
        CottyFriend cottyFriend = new CottyFriend().setUIN(friendObject.getLong("uin"));
        cottyFriendMap.put(friendObject.getLong("uin"), cottyFriend);
      }
      for (int i = 0; i < infoArray.size(); i++) {
        JSONObject infoObject = infoArray.getJSONObject(i);
        CottyFriend cottyFriend = cottyFriendMap.get(infoObject.getLong("uin"));
        if (cottyFriend != null) {
          cottyFriend
              .setFaceCode(infoObject.getInteger("face"))
              .setNick(infoObject.getString("nick"));
        }
      }

      for (int i = 0; i < marknameArray.size(); i++) {
        JSONObject markObject = marknameArray.getJSONObject(i);
        CottyFriend cottyFriend = cottyFriendMap.get(markObject.getLong("uin"));
        if (cottyFriend != null) {
          cottyFriend.setMarkName(markObject.getString("markname"));
        }
      }

      for (int i = 0; i < vipArray.size(); i++) {
        JSONObject vipObject = vipArray.getJSONObject(i);
        CottyFriend cottyFriend = cottyFriendMap.get(vipObject.getLong("u"));
        if (cottyFriend != null) {
          cottyFriend
              .setVIP(vipObject.getInteger("is_vip").equals(1) ? true : false)
              .setVIPLevel(vipObject.getInteger("vip_level"));
        }
      }
      this.cottySession.addAttribute("cottyFriend", cottyFriendMap);
    } else {
      throw new CottyException("friend return unknow data...");
    }
  }
Exemplo n.º 10
0
 public static AreaDomain getUserAreaByIP(final String ip) {
   AreaDomain areaDomain = null;
   try {
     JSONObject jsonObject =
         HttpService.doHttpRequestGetJson(requestURL.replaceAll("USERIP", ip), "GET", null);
     if (jsonObject.getInteger("code") == 0) {
       jsonObject = jsonObject.getJSONObject("data");
       areaDomain = JSONObject.toJavaObject(jsonObject, AreaDomain.class);
     }
   } catch (Exception e) {
     logger.warn("通过淘宝API根据IP获取地址出错");
   }
   return areaDomain;
 }
Exemplo n.º 11
0
  /**
   * 微信创建分组
   *
   * @param group 分组对象
   * @param accessToken
   * @return 分组信息
   * @throws ServiceException ServiceException
   */
  public static Group createGroup(Group group, String accessToken) throws ServiceException {
    // url and params
    String url = getRequestUrl(WechatUrlConstants.GROUPS_CREATE, accessToken);
    JSONObject groupJson = new JSONObject();
    groupJson.put("name", group.getName());
    JSONObject requestJson = new JSONObject();
    requestJson.put("group", groupJson);

    // call weixin service and get group object
    JSONObject responseJson = getWxJSONObjectResponseFromHttpPostMethod(url, requestJson);
    JSONObject respGroupJson = responseJson.getJSONObject("group");
    Integer id = respGroupJson.getInteger("id");
    group.setId(id);
    LOGGER.debug(respGroupJson.toJSONString());
    return group;
  }
Exemplo n.º 12
0
 /**
  * 第三方套件获取企业号管理员登录信息
  *
  * @param authCode oauth2.0授权企业号管理员登录产生的code
  * @return 登陆信息
  * @see <a
  *     href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E7%AE%A1%E7%90%86%E5%91%98%E7%99%BB%E5%BD%95%E4%BF%A1%E6%81%AF">授权获取企业号管理员登录信息</a>
  * @see com.foxinmy.weixin4j.qy.model.OUserInfo
  * @throws WeixinException
  */
 public OUserInfo getOUserInfoByCode(String authCode) throws WeixinException {
   String oauth_logininfo_uri = getRequestUri("oauth_logininfo_uri");
   WeixinResponse response =
       weixinExecutor.post(
           String.format(oauth_logininfo_uri, providerTokenManager.getAccessToken()),
           String.format("{\"auth_code\":\"%s\"}", authCode));
   JSONObject obj = response.getAsJson();
   OUserInfo oUser = JSON.toJavaObject(obj, OUserInfo.class);
   obj = obj.getJSONObject("redirect_login_info");
   Token loginInfo =
       new Token(obj.getString("login_ticket"), obj.getLongValue("expires_in") * 1000l);
   oUser.setRedirectLoginInfo(loginInfo);
   cacheStorager.caching(
       getLoginTicketCacheKey(oUser.getCorpInfo().getCorpId()), oUser.getRedirectLoginInfo());
   return oUser;
 }
Exemplo n.º 13
0
 public void setmap(String str) {
   JSONObject jsonObject = JSON.parseObject(str);
   JSONObject jsonObject1 = jsonObject.getJSONObject("data");
   int a = jsonObject1.getIntValue("code");
   if (a == 0) {
     JSONArray jsonArray = jsonObject1.getJSONArray("info");
     for (int i = 0; i < jsonArray.size(); i++) {
       JSONObject jsonObject2 = jsonArray.getJSONObject(i);
       hashMap = new HashMap<>();
       hashMap.put("id", jsonObject2.getString("id") == null ? "" : jsonObject2.getString("id"));
       hashMap.put(
           "title", jsonObject2.getString("title") == null ? "" : jsonObject2.getString("title"));
       hashMap.put(
           "path", jsonObject2.getString("path") == null ? "" : jsonObject2.getString("path"));
       hashMap.put("select", "0");
       array.add(hashMap);
     }
   } else {
     handlers.sendEmptyMessage(3);
   }
 }
Exemplo n.º 14
0
  private void setArray(String str) {
    JSONObject jsonObject = JSON.parseObject(str);
    JSONObject jsonObject1 = jsonObject.getJSONObject("data");
    if (jsonObject1.getIntValue("code") == 0) {
      JSONArray jsonArray = jsonObject1.getJSONArray("info");
      for (int i = 0; i < jsonArray.size(); i++) {
        hashMap = new HashMap<>();
        JSONObject jsonObject2 = jsonArray.getJSONObject(i);
        hashMap.put("id", jsonObject2.getString("id") == null ? "" : jsonObject2.getString("id"));
        hashMap.put(
            "title", jsonObject2.getString("title") == null ? "" : jsonObject2.getString("title"));
        hashMap.put(
            "description",
            jsonObject2.getString("description") == null
                ? ""
                : jsonObject2.getString("description"));
        hashMap.put(
            "view", jsonObject2.getString("view") == null ? "" : jsonObject2.getString("view"));
        hashMap.put(
            "picList",
            jsonObject2.getString("picList") == null ? "" : jsonObject2.getString("picList"));
        hashMap.put(
            "name", jsonObject2.getString("name") == null ? "" : jsonObject2.getString("name"));
        hashMap.put(
            "category_id",
            jsonObject2.getString("category_id") == null
                ? ""
                : jsonObject2.getString("category_id"));
        arrayList.add(hashMap);
      }

    } else {
      if (page != 1) {
        page--;
      }
      Toast.makeText(SearchNews.this, R.string.nomore, Toast.LENGTH_SHORT).show();
    }
  }
Exemplo n.º 15
0
  /**
   * 通过IP获取地址
   *
   * @param ip
   * @return
   */
  public static String getIpInfo(String ip) {
    String info = "";
    try {
      URL url = new URL("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip);
      HttpURLConnection htpcon = (HttpURLConnection) url.openConnection();
      htpcon.setRequestMethod("GET");
      htpcon.setDoOutput(true);
      htpcon.setDoInput(true);
      htpcon.setUseCaches(false);

      InputStream in = htpcon.getInputStream();
      BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
      StringBuffer temp = new StringBuffer();
      String line = bufferedReader.readLine();
      while (line != null) {
        temp.append(line).append("\r\n");
        line = bufferedReader.readLine();
      }
      bufferedReader.close();
      JSONObject obj = (JSONObject) JSON.parse(temp.toString());
      if (obj.getIntValue("code") == 0) {
        JSONObject data = obj.getJSONObject("data");
        info += data.getString("country") + " ";
        info += data.getString("region") + " ";
        info += data.getString("city") + " ";
        info += data.getString("isp");
      }
    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (ProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return info;
  }
Exemplo n.º 16
0
  /**
   * 登陆
   *
   * @param headers
   * @param content
   * @return
   */
  @Path("/login")
  @POST
  @Produces("application/json;charset=utf-8")
  public String login(
      @Context HttpHeaders headers, @Context HttpServletRequest request, String content) {
    if (StringUtils.isBlank(content)) {
      OpenResult.parameterError("无参数").buildJson();
    }
    JSONObject json = JSONObject.parseObject(content);
    String loginName = json.getString("loginname");
    String passwd = json.getString("passwd");
    // 在header中新增 调用应用名称标识(以header 参数传输,名字有用户中心统一分配)app必传参数
    // 登录名类型 1:身份证,2:用户名,3:手机,4:邮箱
    // int nametype = json.getIntValue("nametype");
    String ip = IPUtils.getRemoteIpAdress(request);
    String clientinfo = json.getString("clientinfo");
    String cccode = json.getString("cccode");

    if (StringUtils.isBlank(loginName) || StringUtils.isBlank(passwd)) {
      return OpenResult.parameterError("参数不正确").buildJson();
    }
    // 校验登录名是否符合 手机号 用户名 身份证号 邮箱正确格式
    LoginResult loginResult = null;
    JSONObject result = null;
    try {
      // result = loginOutService.userLogin(loginName, passwd);
      result = loginOutService.userLoginParamAll(loginName, passwd, ip, clientinfo, cccode);
      if (result != null) {
        int retcode = result.getIntValue("retcode");
        String msg = result.getString("msg");

        if (retcode != 0) {
          return OpenResult.parameterError(retcode, msg).buildJson();
        }
        int failtimes = result.getIntValue("failtimes");
        String userId = result.getString("userid");
        // 输入错误次数大于13次 账户友好提示信息
        if ((failtimes == 0 && StringUtils.isEmpty(userId))) {
          return OpenResult.commonError(OpenResult.NOACCESS_ERROR, UserHelp.LOGIN_TIMES_L_13)
              .buildJson();
        } else if (failtimes > 0) {
          if (failtimes < 13) {
            return OpenResult.commonError(OpenResult.NOACCESS_ERROR, UserHelp.LOGIN_TIMES_L_13)
                .buildJson();
          } else {
            return OpenResult.commonError(OpenResult.NOACCESS_ERROR, UserHelp.LOGIN_TIMES_13)
                .buildJson();
          }
        } else {
          loginResult = new LoginResult();
          loginResult.setUserid(userId);
          loginResult.setUniquecode(result.getString("uniquecode"));
          loginResult.setCompanyuser(result.getIntValue("companyuser"));
          loginResult.setRegtime(result.getString("regtime"));
          loginResult.setUserstatus(result.getIntValue("userstatus"));
          loginResult.setFailtimes(result.getIntValue("failtimes"));
          loginResult.setFrozenremainseconds(result.getIntValue("frozenremainseconds"));
          loginResult.setLastsuccesstime(result.getString("lastsuccesstime"));

          JSONObject userContrInfo = personalService.getUserInfo(userId);
          String mobileNo = null;
          String idnumber = null;
          String realname = null;
          if (userContrInfo != null) {
            retcode = userContrInfo.getIntValue("retcode");
            msg = userContrInfo.getString("msg");
            if (retcode != 0) {
              return OpenResult.parameterError(retcode, msg).buildJson();
            }
            mobileNo = userContrInfo.getJSONObject("user").getString("mobileno");

            idnumber = userContrInfo.getJSONObject("user").getString("idnumber");
            realname = userContrInfo.getJSONObject("user").getString("realname");
          } else {
            return OpenResult.unknown("服务异常").buildJson();
          }

          String sessionId = generateSessionId(loginResult);
          loginResult.setSessionId(sessionId);

          // 将中信证券所需的 mobileno devid 存入session中
          String devId = getDevId(headers);
          JSONObject securitiesInfo = setSecuritiesInfoJson(devId, mobileNo);
          boolean securitiesFlag = setSecuritiesInfo(sessionId, securitiesInfo.toJSONString());
          if (!securitiesFlag) {
            log.debug("登陆时SecuritiesInfo放入缓存结果--" + securitiesFlag);
          }
          mobileNo = InfoMasker.masker(mobileNo, 3, 4, "*", 1);
          loginResult.setMobileno(mobileNo);

          // 将userId放入缓存中
          boolean sign = setMemcacheUserId(sessionId, userId);
          if (!sign) {
            log.debug("登陆时userId放入缓存结果--" + sign);
          }
          String deafultBroker = "ZXZQ";
          // 是否绑定券商
          List<Broker> brokers = accountService.queryBindedBrokers(userId);
          int bindStatus = 0;
          if (CollectionUtils.isEmpty(brokers)) {
            bindStatus = 1;
          } else {
            bindStatus = 2;
          }
          // 资金账号
          String fundAccount = "";
          BindInfo bindInfo = accountService.getBindInfo(userId, deafultBroker);
          if (bindInfo != null) {
            fundAccount = bindInfo.getFundAccount();
          }

          // 是否填写 身份证 真实姓名 1未绑定
          int bindId = 0;
          if (StringUtils.isEmpty(idnumber) || StringUtils.isEmpty(realname)) {
            bindId = 1;
          } else {
            bindId = 2;
          }
          loginResult.setBindStatus(bindStatus);
          loginResult.setBindId(bindId);
          loginResult.setFundAccount(fundAccount);
          loginResult.setDeafultBroker(deafultBroker);
          String str = OpenResult.ok().add("data", loginResult).buildJson();
          return str;
        }

      } else {
        return OpenResult.unknown("服务异常").buildJson();
      }
    } catch (StockServiceException e) {
      log.error("登录异常:" + e);
      return OpenResult.parameterError(result.getIntValue("retcode"), result.getString("msg"))
          .buildJson();
    } catch (ServiceException e) {
      log.error("登录异常:" + e);
      return OpenResult.serviceError(e.getErrorNo(), e.getErrorInfo()).buildJson();
    } catch (Exception e) {
      log.error("登录异常:" + e);
      return OpenResult.unknown(e.getMessage()).buildJson();
    }
  }
Exemplo n.º 17
0
  @Override
  public int executeUpdate(String sql) throws SQLException {
    checkClosed();
    beforeExecute();

    long begin = System.currentTimeMillis();

    try {
      executeInstance = runClientSQL(sql);

      boolean complete = false;
      while (!complete) {
        try {
          Thread.sleep(POOLING_INTERVAL);
        } catch (InterruptedException e) {
          break;
        }

        Instance.TaskStatus.Status status;
        try {
          status = executeInstance.getTaskStatus().get("SQL").getStatus();
        } catch (NullPointerException e) {
          continue;
        }
        switch (status) {
          case SUCCESS:
            complete = true;
            break;
          case FAILED:
            connHanlde.log.fine("update failed");
            throw new SQLException(executeInstance.getTaskResults().get("SQL"), "FAILED");
          case CANCELLED:
            connHanlde.log.info("update cancelled");
            throw new SQLException("update cancelled", "CANCELLED");
          case WAITING:
          case RUNNING:
          case SUSPENDED:
            break;
        }
      }

      long end = System.currentTimeMillis();
      connHanlde.log.fine("It took me " + (end - begin) + " ms to execute update");

      // extract update count
      Instance.TaskSummary taskSummary = executeInstance.getTaskSummary("SQL");
      if (taskSummary != null) {
        JSONObject jsonSummary = JSON.parseObject(taskSummary.getJsonSummary());
        JSONObject outputs = jsonSummary.getJSONObject("Outputs");

        if (outputs.size() > 0) {
          updateCount = 0;
          for (Object item : outputs.values()) {
            JSONArray array = (JSONArray) item;
            updateCount += array.getInteger(0);
          }
        }
      }
    } catch (OdpsException e) {
      throw new SQLException(e);
    }

    connHanlde.log.fine("successfully updated " + updateCount + " records");
    return updateCount;
  }
Exemplo n.º 18
0
  @Override
  public Object launchAppraisal(JSONObject jsonAppraisalObj) {
    // 判断对象是否有参数
    if (!CollectionUtils.isEmpty(jsonAppraisalObj)) {
      // 获取命令信息
      JSONObject jsonCommandInfo = jsonAppraisalObj.getJSONObject("commandInfo");
      if (CollectionUtils.isEmpty(jsonCommandInfo)) {
        throw new EnergyException("命令信息不能为空!");
      }
      String commandType = jsonCommandInfo.getString("commandType");
      if (StringUtils.isEmpty(commandType)) {
        throw new EnergyException("命令类型不能为空!");
      }
      if (!Constants.CMD_GENERAL.equals(commandType)) {
        throw new EnergyException("无效的命令类型:" + commandType);
      }

      // 获取当前用户
      WeixinUser weixinUser = SystemCacheUtil.getInstance().getCurrentUser();
      // 创建评价对象
      Appraisal appraisal = new Appraisal();

      appraisal.setUserId(weixinUser.getUserid());
      appraisal.setUserName(weixinUser.getName());
      appraisal.setTheme(jsonAppraisalObj.getString("theme"));
      appraisal.setOverallMerit(jsonAppraisalObj.getBoolean("overallMerit"));

      // 评价id
      String id = jsonAppraisalObj.getString("id");
      // 是否存在id 草稿 重新发起 都会存在id
      boolean hasId = false;
      if (StringUtils.isNotEmpty(id)) {
        appraisal.setId(id);
        hasId = true;
        // 清除与审批相关的 人员
        entityAccountService.deleteByEntityId(appraisal.getId());
      } else {
        appraisal.setId(CommonUtil.GeneGUID());
      }
      // 实体关系
      List<EntityAccount> entityAccountList = null;
      // 草稿状态下只存储
      if (Constants.CMD_DRAFT.equalsIgnoreCase(commandType)) {

      } else
      /** 发起审批操作 */
      if (Constants.CMD_GENERAL.equalsIgnoreCase(commandType)) {
        appraisal.setStatus(Status.未评价.value());
        appraisal.setCreateTime(new Date());
        if (hasId) {
          appraisalDao.updateAppraisal(appraisal);
        } else {
          appraisalDao.addAppraisal(appraisal);
        }
        // 问题记录

        List<ProblemTemplate> problemTemplateList =
            generateProblemTemplate(jsonAppraisalObj, appraisal.getId());
        if (!CollectionUtils.isEmpty(problemTemplateList)) {
          if (null != appraisal.getOverallMerit() && appraisal.getOverallMerit()) {
            ProblemTemplate problemTemplate = new ProblemTemplate();
            problemTemplate.setId(CommonUtil.GeneGUID());
            problemTemplate.setAppraisalId(appraisal.getId());
            problemTemplate.setQuota("需要填写综合评价");
            problemTemplateList.add(problemTemplate);
          }
          problemTemplateService.addProblemTemplate(
              problemTemplateList.toArray(new ProblemTemplate[] {}));
        }
        // 被评价人 评价人
        entityAccountList = generateEntityAccount(jsonAppraisalObj, appraisal.getId());
        if (!CollectionUtils.isEmpty(entityAccountList)) {
          StringBuffer shUser = new StringBuffer();
          for (EntityAccount entityAccount : entityAccountList) {
            if (EntityType.PJ.value().equals(entityAccount.getEntityType())) {
              if (PersonType.PJ.value().equals(entityAccount.getPersonType())) {
                shUser.append('|').append(entityAccount.getAccountId());
              }
            } else {
              LOGGER.error("人员列表数据内容非法!" + JSON.toJSONString(entityAccountList));
              throw new EnergyException("人员列表数据内容非法!");
            }
          }
          entityAccountService.addEntityAccount(entityAccountList.toArray(new EntityAccount[] {}));
          if (shUser.length() > 0) {
            shUser.deleteCharAt(0);
          }
          if (StringUtils.isNotEmpty(shUser.toString())) {
            // 给审核人推送消息
            SystemCacheUtil.getInstance()
                .getLinkedQueue()
                .add(
                    new AppraisalMsgExecutor(
                        appraisal.getId(), shUser.toString(), "template_appraisal_sh"));
          }
        } else {
          LOGGER.error("被评价或评价人不能为空!");
          throw new EnergyException("被评价或评价人不能为空!");
        }
      }
      return appraisal.getId();
    } else {
      LOGGER.warn("评价信息为空!");
    }
    return null;
  }
  public DBObject buildDbObject(JSONObject jsonObject) {

    if (!check(jsonObject)) {
      return null;
    }

    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    JSONObject mobile = jsonObject.getJSONObject(FieldName.Tanx.mobile);
    JSONObject device = mobile.getJSONObject(FieldName.Tanx.device);
    String deviceId = device.getString(FieldName.Tanx.device_id);

    // 过滤非法deviceId
    if (deviceId.contains("000000000000000") || deviceId.contains(":")) {
      logger.info("=== ignore deviceId:{}", deviceId);
      return null;
    }

    // 新增, 不更新的
    BasicDBObject setObj =
        new BasicDBObject(FieldName.field_deviceId, deviceId)
            .append(FieldName.field_deviceIdMd5, DigestUtils.md5Hex(deviceId))
            .append(FieldName.field_deviceIdSha1, DigestUtils.sha1Hex(deviceId));

    // brand
    if (StringUtils.isNotBlank(device.getString(FieldName.Tanx.brand))) {
      setObj.append(FieldName.field_brand, device.getString(FieldName.Tanx.brand));
    }
    // model
    if (StringUtils.isNotBlank(device.getString(FieldName.Tanx.model))) {
      setObj.append(FieldName.field_model, device.getString(FieldName.Tanx.model));
    }
    // platform
    if (StringUtils.isNotBlank(device.getString(FieldName.Tanx.platform))) {
      setObj.append(FieldName.field_platform, device.getString(FieldName.Tanx.platform));
    }
    // os
    if (StringUtils.isNotBlank(device.getString(FieldName.Tanx.os))) {
      setObj.append(FieldName.field_os, device.getString(FieldName.Tanx.os));
    }
    // os_version
    if (StringUtils.isNotBlank(device.getString(FieldName.Tanx.os_version))) {
      setObj.append(FieldName.field_osVersion, device.getString(FieldName.Tanx.os_version));
    }
    // mac
    String mac = device.getString(FieldName.Tanx.mac);
    if (StringUtils.isNotBlank(mac) && mac.contains(":")) {
      setObj
          .append(FieldName.field_mac, mac)
          .append(FieldName.field_macMd5, DigestUtils.md5Hex(mac))
          .append(FieldName.field_macSha1, DigestUtils.sha1Hex(mac));
    }
    // device_size
    if (StringUtils.isNotBlank(device.getString(FieldName.Tanx.device_size))) {
      setObj.append(FieldName.field_deviceSize, device.getString(FieldName.Tanx.device_size));
    }

    // builder.add(MongoSink.OP_SET_ON_INSERT, setObj);

    BasicDBObject addToSetObj = new BasicDBObject();

    // ip
    if (StringUtils.isNotBlank(jsonObject.getString(FieldName.Tanx.ip))) {
      addToSetObj.append(FieldName.field_ipList, jsonObject.getString(FieldName.Tanx.ip));
    }

    // 城市名称
    if (StringUtils.isNotBlank(jsonObject.getString(FieldName.Tanx.city))) {
      addToSetObj.append(FieldName.field_cityList, jsonObject.getString(FieldName.Tanx.city));
    }

    // 追加的数据,geo
    if (StringUtils.isNotBlank(device.getString(FieldName.Tanx.latitude))
        && StringUtils.isNotBlank(device.getString(FieldName.Tanx.longitude))) {
      addToSetObj.append(
          FieldName.field_geoList,
          new BasicDBObject(FieldName.field_latitude, device.getString(FieldName.Tanx.latitude))
              .append(FieldName.field_longitude, device.getString(FieldName.Tanx.longitude)));
    }

    builder.add(MongoSink.OP_ADD_TO_SET, addToSetObj);

    // app
    if (StringUtils.isNotBlank(mobile.getString(FieldName.Tanx.package_name))) {

      BasicDBObject appObj = new BasicDBObject();
      appObj.append(FieldName.field_packageName, mobile.getString(FieldName.Tanx.package_name));
      if (StringUtils.isNotBlank(mobile.getString(FieldName.Tanx.app_name))) {
        appObj.append(FieldName.field_appName, mobile.getString(FieldName.Tanx.app_name));
      }

      // app分类
      if (mobile.getJSONArray(FieldName.Tanx.app_categories) != null
          && !mobile.getJSONArray(FieldName.Tanx.app_categories).isEmpty()) {
        appObj.append(
            FieldName.field_appCategorys,
            mobile
                .getJSONArray(FieldName.Tanx.app_categories)
                .getJSONObject(0)
                .getString(FieldName.Tanx.id));
      }

      if (StringUtils.isNotBlank(jsonObject.getString(FieldName.bidRequestTime))) {
        appObj.append(FieldName.lastUseTime, jsonObject.getString(FieldName.bidRequestTime));
      }

      // mongo 不支持包含点. 的做key, 替换为_下划线
      setObj.append(
          FieldName.field_appList + mobile.getString(FieldName.Tanx.package_name).replace(".", "_"),
          appObj);
    }

    if (addToSetObj.isEmpty()) {
      return null;
    }

    // app需要记录最后使用日期, 每次都更新
    builder.add(MongoSink.OP_SET, setObj);

    return builder.get();
  }
Exemplo n.º 20
0
  @Override
  public Object appraisalOperate(JSONObject jsonAppraisalInfo) {
    // 判断对象是否有参数
    if (!CollectionUtils.isEmpty(jsonAppraisalInfo)) {
      // 获取命令信息
      JSONObject jsonCommandInfo = jsonAppraisalInfo.getJSONObject("commandInfo");
      if (CollectionUtils.isEmpty(jsonCommandInfo)) {
        throw new EnergyException("命令信息不能为空!");
      }
      String commandType = jsonCommandInfo.getString("commandType");
      if (StringUtils.isEmpty(commandType)) {
        throw new EnergyException("命令类型不能为空!");
      }

      String id = jsonAppraisalInfo.getString("id");
      if (StringUtils.isEmpty(id)) {
        throw new EnergyException("参数id不能为空!");
      }
      int type = jsonCommandInfo.getIntValue("commandType");
      // 获取当前用户
      WeixinUser weixinUser = SystemCacheUtil.getInstance().getCurrentUser();
      Appraisal currentAppraisal = appraisalDao.getAppraisalById(id);
      if (null == currentAppraisal) {
        throw new EnergyException(
            SpringContextUtil.getI18n("1002003", new String[] {"id", id}, null));
      }
      // 实体账户id
      if (Status.已评价.value().equals(currentAppraisal.getStatus())) {
        throw new EnergyException("当前评价已处理!");
      }
      switch (type) {
          // 提交评价
        case 1:
          // 获取问题列表
          String eaId = jsonAppraisalInfo.getString("eaId");
          if (StringUtils.isEmpty(eaId)) {
            throw new EnergyException(
                SpringContextUtil.getI18n("1002002", new String[] {"eaId", eaId}, null));
          }
          EntityAccount entityAccount = entityAccountService.getEntityAccountById(eaId);
          if (null == entityAccount) {
            throw new EnergyException(
                SpringContextUtil.getI18n("1002003", new String[] {"eaId", eaId}, null));
          }

          Score score = new Score();
          score.setAppraisalId(id);
          score.setRaterId(weixinUser.getUserid());
          score.setUserId(entityAccount.getAccountId());
          List<Score> scoreList = scoreService.getScore(score);
          if (!CollectionUtils.isEmpty(scoreList)) {
            throw new EnergyException("您已评价,不能重复评价!");
          }
          scoreList = generateProblemScore(jsonAppraisalInfo, id, weixinUser, entityAccount);
          if (!CollectionUtils.isEmpty(scoreList)) {
            scoreService.addScore(scoreList.toArray(new Score[] {}));
          }

          // 实体账户id
          if (!Status.评价中.value().equals(currentAppraisal.getStatus())) {
            Appraisal appraisal = new Appraisal();
            appraisal.setId(id);
            appraisal.setStatus(Status.评价中.value());
            appraisalDao.updateAppraisal(appraisal);
          }
          // 这里对每一个人评价进行标记 主要记录当前第几个人操作
          int appraiseTimes = entityAccount.getAppraiseTimes() + 1;
          entityAccount = new EntityAccount();
          entityAccount.setId(eaId);
          entityAccount.setAppraiseTimes(appraiseTimes);
          entityAccountService.updateEntityAccount(entityAccount);

          entityAccount = new EntityAccount();
          entityAccount.setEntityId(id);
          entityAccount.setPersonType(PersonType.PJ.value());
          // 获取总评价人数
          int count = (int) entityAccountService.getEntityAccountCount(entityAccount);
          // 查询所有带评价人 当前是否都已被评价
          entityAccount = new EntityAccount();
          entityAccount.setEntityId(id);
          entityAccount.setPersonType(PersonType.BPJ.value());
          List<EntityAccount> entityAccountList =
              entityAccountService.getEntityAccount(entityAccount);
          if (!CollectionUtils.isEmpty(entityAccountList)) {
            for (EntityAccount ea : entityAccountList) {
              if (ea.getAppraiseTimes() != count) {
                return null;
              }
            }
            Appraisal appraisal = new Appraisal();
            appraisal.setId(id);
            appraisal.setStatus(Status.已评价.value());
            appraisalDao.updateAppraisal(appraisal);
          }

          break;
          // 取消评价
        case 2:

          // 如果当前已被评价那么 禁止操作
          if (Status.未评价.value().equals(currentAppraisal.getStatus())) {
            // 被评价人 评价人 问题
            entityAccountService.deleteByEntityId(id);
            problemTemplateService.deleteByAppraisalId(id);
            appraisalDao.deleteAppraisalById(id);
          } else {
            throw new EnergyException("当前评价进行中不能操作!");
          }
          break;
        default:
          throw new EnergyException("无效操作!");
      }
    } else {
      LOGGER.warn("评价操作信息为空!");
    }
    return null;
  }