Search in sources :

Example 41 with JSONObject

use of com.alibaba.fastjson.JSONObject in project benchmark by seelunzi.

the class ExOrderServiceImpl method getNewListMarket.

/*     */
/*     */
/*     */
/*     */
/*     */
public String getNewListMarket(String header, String timeorder) /*     */
{
    /* 187 */
    String[] headarry = header.split("_");
    /* 188 */
    int keepDecimalForCoin = 8;
    /* 189 */
    int keepDecimalForCurrency = 8;
    /*     */
    /* 191 */
    String str = this.redisService.get("cn:coinInfoList");
    /* 192 */
    if (!StringUtils.isEmpty(str)) {
        /* 193 */
        JSONArray pa = JSON.parseArray(str);
        /* 194 */
        if (pa != null) {
            /* 195 */
            for (int i = 0; i < pa.size(); i++) {
                /* 196 */
                JSONObject obj = pa.getJSONObject(i);
                /* 197 */
                if (header.equals(obj.getString("coinCode") + "_" + obj.getString("fixPriceCoinCode"))) {
                    /* 198 */
                    keepDecimalForCoin = obj.getIntValue("keepDecimalForCoin");
                    /* 199 */
                    keepDecimalForCurrency = obj.getIntValue("keepDecimalForCurrency");
                    /* 200 */
                    break;
                /*     */
                }
            /*     */
            }
        /*     */
        }
    /*     */
    }
    /*     */
    /* 206 */
    Map<String, Object> seramap = new HashMap();
    /* 207 */
    seramap.put("coinCode", headarry[0]);
    /* 208 */
    seramap.put("fixPriceCoinCode", headarry[1]);
    /* 209 */
    seramap.put("count", ExchangeDataCacheRedis.LastOrderRecordsLmit);
    /* 210 */
    List<ExOrderInfo> list = null;
    /* 211 */
    if (timeorder.equals("asc")) {
        /* 212 */
        String v = header + ":" + "LastOrderRecords";
        /* 213 */
        if (!StringUtil.isEmpty(v)) {
            /* 214 */
            list = this.exOrderInfoDao.findNewList(seramap);
            /* 215 */
            this.redisService.save(header + ":" + "LastOrderRecords", JSON.toJSONString(list));
        /*     */
        } else {
            /* 217 */
            list = JSON.parseArray(v, ExOrderInfo.class);
        /*     */
        }
    /*     */
    } else /*     */
    {
        /* 221 */
        String v = this.redisService.get(header + ":" + "LastOrderRecords");
        /* 222 */
        if (StringUtil.isEmpty(v)) {
            /* 223 */
            list = this.exOrderInfoDao.findNewListDesc(seramap);
            /* 224 */
            Collections.reverse(list);
            /* 225 */
            this.redisService.save(header + ":" + "LastOrderRecords", JSON.toJSONString(list));
        /*     */
        } else {
            /* 227 */
            list = JSON.parseArray(v, ExOrderInfo.class);
            /* 228 */
            Collections.reverse(list);
        /*     */
        }
    /*     */
    }
    /*     */
    /* 232 */
    List<MarketTradesSub> listsub = new ArrayList();
    /* 233 */
    for (ExOrderInfo l : list) {
        /* 234 */
        MarketTradesSub sub = new MarketTradesSub();
        /* 235 */
        sub.setAmount(l.getTransactionCount().setScale(keepDecimalForCoin, 4));
        /* 236 */
        sub.setPrice(l.getTransactionPrice().setScale(keepDecimalForCurrency, 4));
        /* 237 */
        sub.setTid(l.getOrderNum());
        /* 238 */
        sub.setType(l.getInOrOutTransaction());
        /* 239 */
        sub.setTime(l.getTransactionTime().getTime() / 1000L);
        /* 240 */
        listsub.add(sub);
    /*     */
    }
    /* 242 */
    SortList<MarketTradesSub> sort = new SortList();
    /* 243 */
    sort.Sort(listsub, "getTime", "desc");
    /* 244 */
    MarketTrades marketTrades = new MarketTrades();
    /* 245 */
    marketTrades.setTrades(listsub);
    /* 246 */
    return JSON.toJSONString(marketTrades).toString();
/*     */
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray) ExOrderInfo(hry.trade.entrust.model.ExOrderInfo) MarketTrades(hry.trade.websoketContext.model.MarketTrades) JSONObject(com.alibaba.fastjson.JSONObject) MarketTradesSub(hry.trade.websoketContext.model.MarketTradesSub) SortList(hry.core.util.SortList) JSONObject(com.alibaba.fastjson.JSONObject)

Example 42 with JSONObject

use of com.alibaba.fastjson.JSONObject in project WeexErosFramework by bmfe.

the class EventFetch method fetch.

public void fetch(String params, final Context context, final JSCallback jscallback) {
    ParseManager parseManager = ManagerFactory.getManagerService(ParseManager.class);
    AxiosManager axiosManager = ManagerFactory.getManagerService(AxiosManager.class);
    JSONObject object = parseManager.parseObject(params);
    final String mUrl = object.getString("url");
    Boolean noRepeat = object.getBoolean("noRepeat");
    if (noRepeat != null && noRepeat) {
        axiosManager.cancel(mUrl);
    }
    switch(object.getString("method")) {
        case OkHttpUtils.METHOD.GET:
            AxiosGet axiosGet = parseManager.parseObject(params, AxiosGet.class);
            get(context, axiosManager, axiosGet, jscallback);
            break;
        case OkHttpUtils.METHOD.POST:
            AxiosPost axiosPost = parseManager.parseObject(params, AxiosPost.class);
            post(context, axiosManager, axiosPost, jscallback);
            break;
        case OkHttpUtils.METHOD.HEAD:
            AxiosGet axiosHead = parseManager.parseObject(params, AxiosGet.class);
            head(context, axiosManager, axiosHead, jscallback);
            break;
        case OkHttpUtils.METHOD.DELETE:
            AxiosPost axiosDelete = parseManager.parseObject(params, AxiosPost.class);
            delete(context, axiosManager, axiosDelete, jscallback);
            break;
        case OkHttpUtils.METHOD.PUT:
            AxiosPost axiosPut = parseManager.parseObject(params, AxiosPost.class);
            put(context, axiosManager, axiosPut, jscallback);
            break;
        case OkHttpUtils.METHOD.PATCH:
            AxiosPost axiosPatch = parseManager.parseObject(params, AxiosPost.class);
            patch(context, axiosManager, axiosPatch, jscallback);
            break;
    }
}
Also used : AxiosManager(com.benmu.framework.manager.impl.AxiosManager) JSONObject(com.alibaba.fastjson.JSONObject) AxiosGet(com.benmu.framework.model.AxiosGet) AxiosPost(com.benmu.framework.model.AxiosPost) ParseManager(com.benmu.framework.manager.impl.ParseManager)

Example 43 with JSONObject

use of com.alibaba.fastjson.JSONObject in project ranch by heisedebaise.

the class EditorServiceImpl method queryUser.

@Override
public JSONObject queryUser() {
    PageList<RoleModel> roles = roleService.query(userHelper.id());
    JSONArray list = new JSONArray();
    roles.getList().forEach(role -> list.add(find(role.getEditor())));
    JSONObject object = roles.toJson(false);
    object.put("list", list);
    return object;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) RoleModel(org.lpw.ranch.editor.role.RoleModel)

Example 44 with JSONObject

use of com.alibaba.fastjson.JSONObject in project ranch by heisedebaise.

the class ElementServiceImpl method sort.

@Override
public JSONArray sort(String editor, String parent, String[] ids, String[] modifies) {
    JSONArray array = new JSONArray();
    if (ids.length > modifies.length)
        return array;
    if (validator.isEmpty(parent))
        parent = editor;
    for (int i = 0; i < ids.length; i++) {
        ElementModel element = findById(ids[i]);
        if (element == null || !element.getEditor().equals(editor) || !element.getParent().equals(parent) || element.getSort() == i + 1 || element.getModify() != numeric.toLong(modifies[i]))
            continue;
        save(element, i + 1);
        JSONObject object = new JSONObject();
        object.put("id", element.getId());
        object.put("modify", element.getModify());
        array.add(object);
    }
    return array;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray)

Example 45 with JSONObject

use of com.alibaba.fastjson.JSONObject in project ranch by heisedebaise.

the class ElementServiceImpl method batch.

@Override
public JSONArray batch(String parameters) {
    JSONArray array = new JSONArray();
    JSONArray params = json.toArray(parameters);
    if (params == null) {
        logger.warn(null, "批量操作参数集[{}]解析失败!", parameters);
        return array;
    }
    String editor = null;
    int size = params.size();
    for (int i = 0; i < size; i++) {
        JSONObject object = params.getJSONObject(i);
        if (!object.containsKey("editor"))
            return array;
        if (i == 0) {
            editor = object.getString("editor");
            if (editorService.findById(editor) == null || !roleService.hasType(null, editor, RoleService.Type.Editor))
                return array;
        } else if (!object.getString("editor").equals(editor))
            return array;
        switch(object.getString("operation")) {
            case "save":
                if (parentNotExists(object.getString("parent")) || modifyDisable(object.getString("id"), false, editor, object.getLongValue("modify")))
                    return array;
                continue;
            case "sort":
                if (parentNotExists(object.getString("parent")))
                    return array;
                continue;
            case "delete":
                if (modifyDisable(object.getString("id"), true, editor, object.getLongValue("modify")))
                    return array;
                continue;
            default:
                return array;
        }
    }
    for (int i = 0; i < size; i++) {
        JSONObject object = params.getJSONObject(i);
        switch(object.getString("operation")) {
            case "save":
                Map<String, String> map = new HashMap<>();
                object.keySet().stream().filter(key -> !key.equals("operation")).forEach(key -> map.put(key, object.getString(key)));
                array.add(save(modelHelper.fromMap(map, ElementModel.class)));
                continue;
            case "sort":
                array.add(sort(editor, object.getString("parent"), converter.toArray(object.getString("ids"), ","), converter.toArray(object.getString("modifies"), ",")));
                continue;
            case "delete":
                delete(object.getString("id"));
                array.add("");
        }
    }
    return array;
}
Also used : MinuteJob(org.lpw.tephra.scheduler.MinuteJob) TimeUnit(org.lpw.tephra.util.TimeUnit) Cache(org.lpw.tephra.cache.Cache) Timestamp(java.sql.Timestamp) Json(org.lpw.tephra.util.Json) HashMap(java.util.HashMap) ModelHelper(org.lpw.tephra.dao.model.ModelHelper) DateTime(org.lpw.tephra.util.DateTime) EditorService(org.lpw.ranch.editor.EditorService) LogService(org.lpw.ranch.editor.log.LogService) Inject(javax.inject.Inject) JSONArray(com.alibaba.fastjson.JSONArray) Numeric(org.lpw.tephra.util.Numeric) Converter(org.lpw.tephra.util.Converter) Service(org.springframework.stereotype.Service) RoleService(org.lpw.ranch.editor.role.RoleService) Map(java.util.Map) JSONObject(com.alibaba.fastjson.JSONObject) Logger(org.lpw.tephra.util.Logger) Validator(org.lpw.tephra.util.Validator) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONArray(com.alibaba.fastjson.JSONArray)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1750 HashMap (java.util.HashMap)302 JSONArray (com.alibaba.fastjson.JSONArray)279 Test (org.junit.Test)217 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)182 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)165 IOException (java.io.IOException)138 ArrayList (java.util.ArrayList)125 Map (java.util.Map)111 AuthPassport (com.ngtesting.platform.util.AuthPassport)96 UserVo (com.ngtesting.platform.vo.UserVo)76 Date (java.util.Date)76 List (java.util.List)72 File (java.io.File)70 UnitResponse (info.xiancloud.core.message.UnitResponse)61 JSONException (com.alibaba.fastjson.JSONException)46 StringEntity (org.apache.http.entity.StringEntity)46 HttpResponse (org.apache.http.HttpResponse)44 Header (org.apache.http.Header)36 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)30