Java Code Examples for com.alibaba.fastjson.JSONObject#getLong()
The following examples show how to use
com.alibaba.fastjson.JSONObject#getLong() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchoolListRequest.java From Almost-Famous with MIT License | 6 votes |
@Override public void completed(HttpResponse result) { JSONObject object = getJSONObject(result); Integer code = object.getInteger("code"); String data = object.getString("data"); if (code == ErrorCode.SCHOOL_NOT_EXIST.value()) { if (log.isErrorEnabled()) { log.error("获取签到信息失败"); } } JSONObject dataObj = FastJsonUtils.parseObject(data); Long rid = dataObj.getLong("rid"); String schools = dataObj.getString("schools"); Map<Integer, SchoolBean> schoolLst = Misc.parseToMap(schools, Integer.class, SchoolBean.class); RobotMgr robotMgr = SpringContextUtils.getBean("robotMgr", RobotMgr.class); Robot robot = robotMgr.getRobot(rid); School school = new School(); school.setRid(rid); school.setSchools(schoolLst); robot.setOccupation(school); if (log.isDebugEnabled()) { log.debug("rid {}, 职业列表, {}", rid, schoolLst); } }
Example 2
Source File: SinkerWriteBolt.java From DBus with Apache License 2.0 | 6 votes |
@Override public void execute(Tuple input) { List<DBusConsumerRecord<String, byte[]>> data = (List<DBusConsumerRecord<String, byte[]>>) input.getValueByField("data"); try { if (isCtrl(data)) { JSONObject json = JSON.parseObject(new String(data.get(0).value(), "utf-8")); logger.info("[write bolt] received reload message .{} ", json); Long id = json.getLong("id"); if (ctrlMsgId == id) { logger.info("[write bolt] ignore duplicate ctrl messages . {}", json); } else { ctrlMsgId = id; processCtrlMsg(json); } } else { sendData(data); } collector.ack(input); } catch (Exception e) { logger.error("[write bolt] execute error.", e); collector.fail(input); } }
Example 3
Source File: SaveUserTagListener.java From MicroCommunity with Apache License 2.0 | 6 votes |
/** * 用户打标信息保存至 business表中 * * @param dataFlowContext 数据对象 * @param business 当前业务对象 */ @Override protected void doSaveBusiness(DataFlowContext dataFlowContext, Business business) { JSONObject data = business.getDatas(); Assert.notEmpty(data, "没有datas 节点,或没有子节点需要处理"); Assert.jsonObjectHaveKey(data, UserTagPo.class.getSimpleName(), "datas 节点下没有包含 businessUser 节点"); JSONObject businessUser = data.getJSONObject(UserTagPo.class.getSimpleName()); Assert.jsonObjectHaveKey(businessUser, "userId", "businessUser 节点下没有包含 userId 节点"); if (businessUser.getLong("userId") <= 0) { throw new ListenerExecuteException(ResponseConstant.RESULT_PARAM_ERROR, "用户打标(saveUserTag)保存失败,userId 不正确" + businessUser.getInteger("userId")); } dataFlowContext.addParamOut("userId", businessUser.getString("userId")); businessUser.put("bId", business.getbId()); businessUser.put("operate", StatusConstant.OPERATE_ADD); //保存用户信息 userServiceDaoImpl.saveBusinessUserTag(businessUser); }
Example 4
Source File: ProgressRequest.java From Almost-Famous with MIT License | 6 votes |
@Override public void completed(HttpResponse result) { JSONObject object = getJSONObject(result); Integer code = object.getInteger("code"); String data = object.getString("data"); if (code == ErrorCode.SERVER_SUCCESS.value()) { JSONObject dataObj = FastJsonUtils.parseObject(data); Long rid = dataObj.getLong("rid"); String chapters = dataObj.getString("chapters"); Map<Integer, ChapterBean> chapterMap = Misc.parseToMap(chapters, Integer.class, ChapterBean.class); RobotMgr robotMgr = SpringContextUtils.getBean("robotMgr", RobotMgr.class); Robot robot = robotMgr.getRobotMap().get(rid); Chapter chapter = new Chapter(); chapter.setRid(rid); chapter.setChapters(chapterMap); robot.setChapter(chapter); if (log.isInfoEnabled()) { log.info("进度列表 {}", chapterMap); } } }
Example 5
Source File: AVIMTypedMessage.java From java-unified-sdk with Apache License 2.0 | 6 votes |
/** * 从 conversation 数据中解析 lastMessage * @return */ static AVIMMessage parseMessage(String conversationId, JSONObject jsonObject) { if (null != jsonObject && jsonObject.containsKey(KEY_MESSAGE_ID)) { try { String from = jsonObject.getString(KEY_MESSAGE_FROM); String data = jsonObject.getString(KEY_MESSAGE_CONTENT); long timestamp = jsonObject.getLong(KEY_MESSAGE_TIMESTAMP); String msgId = jsonObject.getString(KEY_MESSAGE_ID); AVIMMessage message = new AVIMMessage(conversationId, from, timestamp, -1); message.setMessageId(msgId); message.setContent(data); return AVIMMessageManagerHelper.parseTypedMessage(message); } catch (Exception e) {} } return null; }
Example 6
Source File: SignInAction.java From Almost-Famous with MIT License | 6 votes |
@Override public Resoult execute(JSONObject jsonObject, HttpServletRequest request, HttpServletResponse response) { Long rid = jsonObject.getLong("rid"); Integer day = jsonObject.getInteger("day"); ErrorCode code = iSignRewardService.getSignReward(rid, day); if (ErrorCode.SERVER_SUCCESS != code) { return Resoult.error(RegisterProtocol.SIGN_IN_ACTION_RESP, code, ""); } //推送GM // Resoult result = GameUtils.getActorCurrency(roleService.selectByRoleId(rid), rid); // sendMessage.send(rid, result); // sendMessage.sendNow(rid); Map<String, Object> data = GameUtils.getActorCurrencyData(roleService.selectByRoleId(rid), rid); return Resoult.ok(RegisterProtocol.SIGN_IN_ACTION_RESP).responseBody(data); }
Example 7
Source File: ClientListController.java From RCT with Apache License 2.0 | 6 votes |
@RequestMapping(value = { "statistics" }, method = RequestMethod.POST) @ResponseBody public RestResponse statistics(@RequestBody String internal) { JSONObject json = JSONObject.parseObject(internal); Long id = json.getLong("id"); int groupBy = json.getIntValue("groupBy"); List<Entry<String, Integer>> maps = clientListService.statistics(id, groupBy); List<JSONObject> res = new ArrayList<>(maps.size()); for (int i = 0; i < maps.size(); i++) { JSONObject obj = new JSONObject(); obj.put("ip", maps.get(i).getKey()); obj.put("count", maps.get(i).getValue()); res.add(obj); } return SUCCESS_DATA(res); }
Example 8
Source File: RewardListRequest.java From Almost-Famous with MIT License | 6 votes |
@Override public void completed(HttpResponse result) { JSONObject object = getJSONObject(result); Integer code = object.getInteger("code"); if (code == ErrorCode.SIGN_LIST_ERROR.value()) { if (log.isErrorEnabled()) { log.error("获取签到信息失败"); } } else if (code == ErrorCode.SERVER_SUCCESS.value()) { String data = object.getString("data"); JSONObject dataObj = FastJsonUtils.parseObject(data); Long rid = dataObj.getLong("rid"); String rewards = dataObj.getString("rewards"); Map<Integer, RewardBean> rewardList = Misc.parseToMap(rewards, Integer.class, RewardBean.class); Robot robot = SpringContextUtils.getBean("robotMgr", RobotMgr.class).getRobot(rid); SignReward signReward = new SignReward(rid, rewardList); robot.setSignReward(signReward); if (log.isDebugEnabled()) { log.debug("rid {}, 签到记录 {}", rid, rewardList); } } }
Example 9
Source File: HuobiProExchange.java From GOAi with GNU Affero General Public License v3.0 | 5 votes |
/** * 解析订单 * @param result 订单结果 * @param data json * @param tip 错误提示 * @return 解析订单 */ protected Order parseOrder(String result, JSONObject data, String tip) { Long time = data.getLong("created-at"); String id = data.getString("id"); String[] types = data.getString("type").split("-"); Side side = Side.valueOf(types[0].toUpperCase()); Type type = null; switch (types[1]) { case "limit": type = Type.LIMIT; break; case "market": type = Type.MARKET; break; case "ioc": type = Type.IMMEDIATE_OR_CANCEL; break; default: } State state; switch (data.getString("state")) { case SUBMITTING: case SUBMITTED: state = State.SUBMIT; break; case PARTIAL_FILLED: state = State.PARTIAL; break; case CANCELLING: state = State.SUBMIT; break; case FILLED: state = State.FILLED; break; case CANCELED: state = State.CANCEL; break; case PARTIAL_CANCELED: state = State.UNDONE; break; default: log.error("{} {} parseOrder state --> {}", name, tip, data); return null; } BigDecimal price = data.getBigDecimal("price"); BigDecimal amount = data.getBigDecimal("amount"); BigDecimal deal = null != data.getBigDecimal("field-amount") ? data.getBigDecimal("field-amount") : data.getBigDecimal("filled-amount"); BigDecimal fieldCashAmount = null != data.getBigDecimal("field-cash-amount") ? data.getBigDecimal("field-cash-amount") : data.getBigDecimal("filled-cash-amount"); BigDecimal average = exist(deal) && greater(deal, ZERO) ? div(fieldCashAmount, deal, 16) : null; if (state == State.SUBMIT && null != deal && greater(deal, ZERO)) { state = State.PARTIAL; } return new Order(result, time, id, side, type, state, price, amount, deal, average); }
Example 10
Source File: Format.java From java-youtube-downloader with Apache License 2.0 | 5 votes |
protected Format(JSONObject json) { Itag itag; try { itag = Itag.valueOf("i" + json.getInteger("itag")); } catch (ExceptionInInitializerError e) { e.printStackTrace(); itag = Itag.unknown; itag.setId(json.getIntValue("itag")); } this.itag = itag; url = json.getString("url").replace("\\u0026", "&"); mimeType = json.getString("mimeType"); bitrate = json.getInteger("bitrate"); contentLength = json.getLong("contentLength"); lastModified = json.getLong("lastModified"); approxDurationMs = json.getLong("approxDurationMs"); if (mimeType == null || mimeType.isEmpty()) extension = Extension.UNKNOWN; else if (mimeType.contains(Extension.MP4.value())) extension = Extension.MP4; else if (mimeType.contains(Extension.WEBM.value())) extension = Extension.WEBM; else if (mimeType.contains(Extension.FLV.value())) extension = Extension.FLV; else if (mimeType.contains(Extension.HLS.value())) extension = Extension.HLS; else if (mimeType.contains(Extension.THREEGP.value())) extension = Extension.THREEGP; else if (mimeType.contains(Extension.M4A.value())) extension = Extension.MP4; else extension = Extension.UNKNOWN; }
Example 11
Source File: JwtUtils.java From microservices-platform with Apache License 2.0 | 5 votes |
/** * 判断jwt是否过期 * @param claims jwt内容 * @param currTime 当前时间 * @return 未过期:true,已过期:false */ public static boolean checkExp(JSONObject claims, long currTime) { long exp = claims.getLong("exp"); if (exp < currTime) { return false; } return true; }
Example 12
Source File: MemberConsumer.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 重置用户钱包地址 * @param record */ @KafkaListener(topics = {"reset-member-address"}) public void resetAddress(ConsumerRecord<String,String> record){ String content = record.value(); JSONObject json = JSON.parseObject(content); Coin coin = coinService.findByUnit(record.key()); Assert.notNull(coin,"coin null"); if(coin.getEnableRpc()==BooleanEnum.IS_TRUE){ MemberWallet memberWallet = memberWalletService.findByCoinUnitAndMemberId(record.key(),json.getLong("uid")); Assert.notNull(memberWallet,"wallet null"); String account = "U" + json.getLong("uid")+ GeneratorUtil.getNonceString(4); //远程RPC服务URL,后缀为币种单位 String serviceName = "SERVICE-RPC-" + coin.getUnit(); try{ String url = "http://" + serviceName + "/rpc/address/{account}"; ResponseEntity<MessageResult> result = restTemplate.getForEntity(url, MessageResult.class, account); logger.info("remote call:service={},result={}", serviceName, result); if (result.getStatusCode().value() == 200) { MessageResult mr = result.getBody(); if (mr.getCode() == 0) { String address = mr.getData().toString(); memberWallet.setAddress(address); } } } catch (Exception e){ logger.error("call {} failed,error={}",serviceName,e.getMessage()); } memberWalletService.save(memberWallet); } }
Example 13
Source File: DockerMetrics.java From OpenFalcon-SuitAgent with Apache License 2.0 | 5 votes |
private List<CollectObject> getNetMetrics(String containerName,JSONObject container){ List<CollectObject> collectObjectList = new ArrayList<>(); boolean hasNetwork = container.getJSONObject("spec").getBoolean("has_network"); collectObjectList.add(new CollectObject(containerName,"has_network",hasNetwork ? "1" : "0","")); if(hasNetwork){ JSONArray stats = container.getJSONArray("stats"); int count = stats.size(); JSONObject stat = stats.getJSONObject(count - 1); JSONObject network = stat.getJSONObject("network"); JSONArray interfaces = network.getJSONArray("interfaces"); for (Object ifObj : interfaces) { JSONObject ifJson = (JSONObject) ifObj; String ifName = ifJson.getString("name"); String tag = "ifName=" + ifName; long rxBytes = ifJson.getLong("rx_bytes"); long rxPackets = ifJson.getLong("rx_packets"); long rxErrors = ifJson.getLong("rx_errors"); long rxDropped = ifJson.getLong("rx_dropped"); long txBytes = ifJson.getLong("tx_bytes"); long txPackets = ifJson.getLong("tx_packets"); long txErrors = ifJson.getLong("tx_errors"); long txDropped = ifJson.getLong("tx_dropped"); collectObjectList.add(new CollectObject(containerName,"net.if.in.bytes",String.valueOf(rxBytes),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.in.packets",String.valueOf(rxPackets),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.in.errors",String.valueOf(rxErrors),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.in.dropped",String.valueOf(rxDropped),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.out.bytes",String.valueOf(txBytes),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.out.packets",String.valueOf(txPackets),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.out.errors",String.valueOf(txErrors),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.out.dropped",String.valueOf(txDropped),tag)); } } return collectObjectList; }
Example 14
Source File: HeartbeatDefaultHandler.java From DBus with Apache License 2.0 | 5 votes |
@Override public void handle(Tuple tuple) { EmitData data = (EmitData) tuple.getValueByField(Constants.EmitFields.DATA); List<PairWrapper<String, Object>> wrapperList = data.get(EmitData.MESSAGE); DataTable table = data.get(EmitData.DATA_TABLE); MetaVersion ver = data.get(EmitData.VERSION); for (PairWrapper<String, Object> wrapper : wrapperList) { Object packet = wrapper.getPairValue("PACKET"); if (packet == null) { logger.warn("[appender-heartbeat] data error. wrapper:{}", JSON.toJSONString(wrapper)); continue; } JSONObject json = JSON.parseObject(packet.toString()); String dbSchema = wrapper.getPairValue("SCHEMA_NAME").toString(); String tableName = wrapper.getPairValue("TABLE_NAME").toString(); String pos = generateUmsId(wrapper.getProperties(Constants.MessageBodyKey.POS).toString()); // oracle 数据格式:2017-03-24 14:28:00.995660,mysql格式:2017-03-24 14:28:00.995 // 暂时不要统一 //String opts = wrapper.getProperties(Constants.MessageBodyKey.OP_TS).toString().substring(0, 23); String opts = wrapper.getProperties(Constants.MessageBodyKey.OP_TS).toString(); long time = json.getLong("time"); long txTime = json.getLong("txTime"); String targetTopic = listener.getTargetTopic(dbSchema, tableName); // 发送Heartbeat listener.sendHeartbeat(message(table, ver, pos, opts), targetTopic, buildKey(time + "|" + txTime, table, ver)); } }
Example 15
Source File: HcFtpToFileSystemConfigAction.java From MicroCommunity with Apache License 2.0 | 5 votes |
/** * 根据TaskId 获取任务属性 * * @return */ public JSONObject queryTaskAttrs(HttpServletRequest request) { // 请求参数为{"taskId":"12"} String ftpItemJson = request.getParameter("ftpItemJson"); if (logger.isDebugEnabled()) { logger.debug("---【PrvncFtpToFileSystemConfigAction.queryTaskAttrs】入参为:" + ftpItemJson, ftpItemJson); } JSONObject paramIn = null; try { // 校验格式是否正确 paramIn = JSONObject.parseObject(ftpItemJson); } catch (Exception e) { logger.error("传入参数格式不正确:" + ftpItemJson, e); resultMsg = createResultMsg("1999", "传入参数格式不正确:" + ftpItemJson, ""); return resultMsg; } long taskId = paramIn.getLong("taskId"); Map info = new HashMap(); info.put("taskId", taskId); List<Map> itemAttrs = iHcFtpFileDAO.queryFtpItemAttrsByTaskId(info); String itemsAttrs = JSONObject.toJSONString(itemAttrs); resultMsg = this.createResultMsg("0000", "成功", "{\"TASK_ATTRS\":" + itemsAttrs + "}"); return resultMsg; }
Example 16
Source File: AnalyzerStatusThread.java From redis-manager with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void handleAnalyzerStatusMessage(JSONObject message) { String analyzeIP = message.getString("ip"); if (message.get("scheduleInfo") == null || "".equals(message.getString("scheduleInfo").trim())) { return; } JSONObject scheduleInfo = message.getJSONObject("scheduleInfo"); Long scheduleID = scheduleInfo.getLong("scheduleID"); Map<String, Map<String, String>> rdbAnalyzeStatus = (Map<String, Map<String, String>>) message .get("rdbAnalyzeStatus"); List<ScheduleDetail> scheduleDetails = new ArrayList<>(); Map<String, String> newScheduleDtailsInstance = new HashMap<>(); for (Entry<String, Map<String, String>> entry : rdbAnalyzeStatus.entrySet()) { String port = entry.getKey(); if (entry.getValue() == null) { continue; } Map<String, String> analyzeInfo = entry.getValue(); AnalyzeStatus status = AnalyzeStatus.fromString(analyzeInfo.get("status")); String count = analyzeInfo.get("count"); String instance = analyzeIP + ":" + port; if (count == null || count.equals("")) { count = "0"; } ScheduleDetail s = new ScheduleDetail(scheduleID, instance, Integer.parseInt(count), true, status); scheduleDetails.add(s); newScheduleDtailsInstance.put(instance, instance); } // 将新旧信息合并 List<ScheduleDetail> oldScheduleDetails = AppCache.scheduleDetailMap.get(rdbAnalyze.getId()); List<ScheduleDetail> oldNeedScheduleDetails = new ArrayList<>(); if (oldScheduleDetails != null && oldScheduleDetails.size() > 0) { for (ScheduleDetail detail : oldScheduleDetails) { if (newScheduleDtailsInstance.containsKey(detail.getInstance())) { continue; } oldNeedScheduleDetails.add(detail); } scheduleDetails.addAll(oldNeedScheduleDetails); } AppCache.scheduleDetailMap.put(rdbAnalyze.getId(), scheduleDetails); }
Example 17
Source File: DockerMetrics.java From SuitAgent with Apache License 2.0 | 4 votes |
private List<CollectObject> getNetMetrics(String containerName,JSONObject container){ List<CollectObject> collectObjectList = new ArrayList<>(); boolean hasNetwork = container.getJSONObject("spec").getBoolean("has_network"); collectObjectList.add(new CollectObject(containerName,"has_network",hasNetwork ? "1" : "0","")); if(hasNetwork){ JSONArray stats = container.getJSONArray("stats"); int count = stats.size(); JSONObject stat = stats.getJSONObject(count - 1); JSONObject network = stat.getJSONObject("network"); JSONArray interfaces = network.getJSONArray("interfaces"); for (Object ifObj : interfaces) { JSONObject ifJson = (JSONObject) ifObj; String ifName = ifJson.getString("name"); String tag = "ifName=" + ifName; long rxBytes = ifJson.getLong("rx_bytes"); long rxPackets = ifJson.getLong("rx_packets"); long rxErrors = ifJson.getLong("rx_errors"); long rxDropped = ifJson.getLong("rx_dropped"); long txBytes = ifJson.getLong("tx_bytes"); long txPackets = ifJson.getLong("tx_packets"); long txErrors = ifJson.getLong("tx_errors"); long txDropped = ifJson.getLong("tx_dropped"); collectObjectList.add(new CollectObject(containerName,"net.if.in.bytes",String.valueOf(rxBytes),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.in.packets",String.valueOf(rxPackets),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.in.errors",String.valueOf(rxErrors),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.in.dropped",String.valueOf(rxDropped),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.bytes",String.valueOf(rxBytes),tag,CounterType.COUNTER)); collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.packets",String.valueOf(rxPackets),tag,CounterType.COUNTER)); collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.errors",String.valueOf(rxErrors),tag,CounterType.COUNTER)); collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.dropped",String.valueOf(rxDropped),tag,CounterType.COUNTER)); collectObjectList.add(new CollectObject(containerName,"net.if.out.bytes",String.valueOf(txBytes),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.out.packets",String.valueOf(txPackets),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.out.errors",String.valueOf(txErrors),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.out.dropped",String.valueOf(txDropped),tag)); collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.bytes",String.valueOf(txBytes),tag,CounterType.COUNTER)); collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.packets",String.valueOf(txPackets),tag,CounterType.COUNTER)); collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.errors",String.valueOf(txErrors),tag,CounterType.COUNTER)); collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.dropped",String.valueOf(txDropped),tag,CounterType.COUNTER)); } } return collectObjectList; }
Example 18
Source File: BinanceExchange.java From GOAi with GNU Affero General Public License v3.0 | 4 votes |
private Order parseOrder(String result, JSONObject t) { /* * "symbol": "LTCBTC", * "orderId": 1, * "clientOrderId": "myOrder1", * "price": "0.1", * "origQty": "1.0", * "executedQty": "0.0", * "cummulativeQuoteQty": "0.0", * "status": "NEW", * "timeInForce": "GTC", * "type": "LIMIT", * "side": "BUY", * "stopPrice": "0.0", * "icebergQty": "0.0", * "time": 1499827319559, * "updateTime": 1499827319559, * "isWorking": true */ Long time = t.getLong("updateTime"); String id = t.getString("orderId"); State state = null; switch (t.getString("status")) { case "NEW": state = State.SUBMIT; break; case "PARTIALLY_FILLED": state = State.PARTIAL; break; case "FILLED": state = State.FILLED; break; case "CANCELED": state = State.CANCEL; break; case "PENDING_CANCEL": state = State.CANCEL; break; case "REJECTED": state = State.CANCEL; break; case "EXPIRED": state = State.CANCEL; break; default: } Side side = Side.valueOf(t.getString("side")); Type type = null; //STOP_LOSS //STOP_LOSS_LIMIT //TAKE_PROFIT //TAKE_PROFIT_LIMIT //LIMIT_MAKER switch (t.getString("type")) { case "LIMIT" : type = Type.LIMIT; break; case "MARKET" : type = Type.MARKET; break; default: } BigDecimal price = t.getBigDecimal("price"); BigDecimal amount = t.getBigDecimal("origQty"); BigDecimal deal = t.getBigDecimal("executedQty"); BigDecimal average = greater(deal, ZERO) ? div(t.getBigDecimal("cummulativeQuoteQty"), deal) : ZERO; return new Order(result, time, id, side, type, greater(deal, ZERO) && state == State.CANCEL ? State.UNDONE : state, price, amount, deal, average); }
Example 19
Source File: ClusterInstantPerfValueAjax.java From tddl5 with Apache License 2.0 | 4 votes |
private AjaxResult getClusterInfo(AjaxParams params) { JSONArray array = params.getArray(); long clusterId = params.getClusterId(); JSONObject json = null; if (array.size() > 0) { json = array.getJSONObject(0); } AjaxResult rs = new AjaxResult(); rs.setId(clusterId); List<CobarDO> nodes = xmlAccesser.getCobarDAO().getCobarList(clusterId); rs.setTotal(nodes.size()); for (CobarDO cobar : nodes) { if (ConstantDefine.IN_ACTIVE.equals(cobar.getStatus())) { continue; } CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(cobar.getId()); if (!perfAccesser.checkConnection()) { rs.addError(1); StringBuilder sb = new StringBuilder("getClusterInfo : cobar connect error for [ Name:"); sb.append(cobar.getName()).append(" Host:").append(cobar.getHost()).append(" ]"); logger.error(sb.toString()); continue; } rs.addActive(1); rs.setSchema(perfAccesser.listDataBases().size()); List<ProcessorStatus> list = perfAccesser.listProccessorStatus(); rs.addNetIn(groupByPList(list, NET_IN)); rs.addNetOut(groupByPList(list, NET_OUT)); rs.addConnection(groupByPList(list, CONNECTION)); rs.setTimestamp(list.get(list.size() - 1).getSampleTimeStamp()); List<CommandStatus> commandList = perfAccesser.listCommandStatus(); rs.addRequest(groupByCList(commandList, REQUEST_COUNT)); } if (json != null && json.getLong("netIn") != -1) { long o_tiemstamp = json.getLong("timestamp"); rs.setNetIn_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(rs.getNetIn(), json.getLong("netIn"), rs.getTimestamp(), o_tiemstamp, 1000.0)))); rs.setNetOut_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(rs.getNetOut(), json.getLong("netOut"), rs.getTimestamp(), o_tiemstamp, 1000.0)))); rs.setRequest_deriv(FormatUtil.formatNumber(Math.round(MathUtil.getDerivate(rs.getRequest(), json.getLong("reCount"), rs.getTimestamp(), o_tiemstamp, 1000.0)))); } return rs; }
Example 20
Source File: HoubiProUtil.java From GOAi with GNU Affero General Public License v3.0 | 3 votes |
/** * 解析 深度 * { * "status":"ok", * "ch":"market.btcusdt.depth.step0", * "ts":1549001152532, * "tick":{ * "bids":[ * [ * 3415.41, * 0.0183 * ], ... * ], * "asks":[ * [ * 3415.96, * 0.0542 * ], ... * ], * "ts":1549001152017, * "version":100159087527 * } * } * @param result 原始数据 * @return Depth */ public static Depth parseDepth(String result) { JSONObject r = JSON.parseObject(result); if (OK.equals(r.getString(STATUS))) { JSONObject tick = r.getJSONObject("tick"); Long time = tick.getLong("ts"); return CommonUtil.parseDepthByIndex(time, tick.getJSONArray("asks"), tick.getJSONArray("bids")); } return null; }