Search in sources :

Example 41 with JSONArray

use of net.sf.json.JSONArray in project erp-catering by liuyandong33.

the class ElemeService method saveElemeOrder.

/**
 * 保存饿了么订单
 *
 * @param elemeCallbackMessage
 * @param uuid
 * @throws IOException
 */
@Transactional(rollbackFor = Exception.class)
public void saveElemeOrder(ElemeCallbackMessage elemeCallbackMessage, String uuid) throws IOException {
    JSONObject messageJsonObject = JSONObject.fromObject(elemeCallbackMessage.getMessage());
    String openId = messageJsonObject.getString("openId");
    String[] array = openId.split("Z");
    BigInteger tenantId = NumberUtils.createBigInteger(array[0]);
    BigInteger branchId = NumberUtils.createBigInteger(array[1]);
    SearchModel branchSearchModel = new SearchModel(true);
    branchSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
    branchSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
    branchSearchModel.addSearchCondition("shop_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, elemeCallbackMessage.getShopId());
    Branch branch = branchMapper.find(branchSearchModel);
    Validate.notNull(branch, "门店不存在!");
    String tenantCode = branch.getTenantCode();
    // 开始保存饿了么订单
    String id = messageJsonObject.getString("id");
    messageJsonObject.remove("id");
    JSONArray phoneList = messageJsonObject.optJSONArray("phoneList");
    messageJsonObject.remove("phoneList");
    JSONArray elemeGroupJsonArray = messageJsonObject.optJSONArray("groups");
    messageJsonObject.remove("groups");
    JSONArray orderActivityJsonArray = messageJsonObject.optJSONArray("orderActivities");
    messageJsonObject.remove("orderActivities");
    BigInteger userId = CommonUtils.getServiceSystemUserId();
    // TODO 上线之前删除
    userId = BigInteger.ONE;
    ElemeOrder elemeOrder = GsonUtils.fromJson(messageJsonObject.toString(), ElemeOrder.class, "yyyy-MM-dd'T'HH:mm:ss");
    elemeOrder.setTenantId(tenantId);
    elemeOrder.setTenantCode(tenantCode);
    elemeOrder.setBranchId(branchId);
    elemeOrder.setCreateUserId(userId);
    elemeOrder.setLastUpdateUserId(userId);
    elemeOrder.setLastUpdateRemark("饿了么系统推送新订单,保存订单!");
    elemeOrderMapper.insert(elemeOrder);
    BigInteger elemeOrderId = elemeOrder.getId();
    List<ElemeOrderItem> elemeOrderItems = new ArrayList<ElemeOrderItem>();
    int elemeGroupJsonArraySize = elemeGroupJsonArray.size();
    for (int index = 0; index < elemeGroupJsonArraySize; index++) {
        JSONObject elemeGroupJsonObject = elemeGroupJsonArray.getJSONObject(index);
        ElemeOrderGroup elemeOrderGroup = new ElemeOrderGroup();
        elemeOrderGroup.setTenantId(tenantId);
        elemeOrderGroup.setTenantCode(tenantCode);
        elemeOrderGroup.setBranchId(branchId);
        elemeOrderGroup.setElemeOrderId(elemeOrderId);
        elemeOrderGroup.setOrderId(id);
        elemeOrderGroup.setName(elemeGroupJsonObject.optString("name"));
        elemeOrderGroup.setType(elemeGroupJsonObject.optString("type"));
        elemeOrderGroup.setCreateUserId(userId);
        elemeOrderGroup.setLastUpdateUserId(userId);
        elemeOrderGroup.setLastUpdateRemark("饿了么系统推送新订单,保存订单分组!");
        elemeOrderGroupMapper.insert(elemeOrderGroup);
        JSONArray elemeOrderItemJsonArray = elemeGroupJsonObject.optJSONArray("items");
        int elemeOrderItemJsonArraySize = elemeOrderItemJsonArray.size();
        for (int elemeOrderItemJsonArrayIndex = 0; elemeOrderItemJsonArrayIndex < elemeOrderItemJsonArraySize; elemeOrderItemJsonArrayIndex++) {
            JSONObject elemeOrderItemJsonObject = elemeOrderItemJsonArray.optJSONObject(elemeOrderItemJsonArrayIndex);
            ElemeOrderItem elemeOrderItem = new ElemeOrderItem();
            elemeOrderItem.setTenantId(tenantId);
            elemeOrderItem.setTenantCode(tenantCode);
            elemeOrderItem.setBranchId(branchId);
            elemeOrderItem.setElemeOrderId(elemeOrderId);
            elemeOrderItem.setOrderId(id);
            elemeOrderItem.setElemeOrderGroupId(elemeOrderGroup.getId());
            elemeOrderItem.setElemeItemId(BigInteger.valueOf(elemeOrderItemJsonObject.getLong("id")));
            elemeOrderItem.setSkuId(BigInteger.valueOf(elemeOrderItemJsonObject.getLong("skuId")));
            elemeOrderItem.setName(elemeOrderItemJsonObject.getString("name"));
            elemeOrderItem.setCategoryId(BigInteger.valueOf(elemeOrderItemJsonObject.getLong("categoryId")));
            elemeOrderItem.setPrice(BigDecimal.valueOf(elemeOrderItemJsonObject.optDouble("price")));
            elemeOrderItem.setQuantity(elemeOrderItemJsonObject.optInt("quantity"));
            elemeOrderItem.setTotal(BigDecimal.valueOf(elemeOrderItemJsonObject.optDouble("total")));
            elemeOrderItem.setExtendCode(elemeOrderItemJsonObject.optString("extendCode"));
            elemeOrderItem.setBarCode(elemeOrderItemJsonObject.optString("barCode"));
            elemeOrderItem.setUserPrice(BigDecimal.valueOf(elemeOrderItemJsonObject.getDouble("userPrice")));
            elemeOrderItem.setShopPrice(BigDecimal.valueOf(elemeOrderItemJsonObject.getDouble("shopPrice")));
            elemeOrderItem.setVfoodId(BigInteger.valueOf(elemeOrderItemJsonObject.getLong("vfoodId")));
            Double weight = elemeOrderItemJsonObject.optDouble("weight");
            if (!Double.isNaN(weight)) {
                elemeOrderItem.setWeight(BigDecimal.valueOf(Double.valueOf(weight.toString())));
            }
            elemeOrderItem.setCreateUserId(userId);
            elemeOrderItem.setLastUpdateUserId(userId);
            elemeOrderItem.setLastUpdateRemark("饿了么系统推送新订单,保存菜品信息!");
            elemeOrderItemMapper.insert(elemeOrderItem);
            JSONArray elemeOrderItemAttributeJsonArray = elemeOrderItemJsonObject.optJSONArray("attributes");
            if (elemeOrderItemAttributeJsonArray != null) {
                int elemeOrderItemAttributeJsonArraySize = elemeOrderItemAttributeJsonArray.size();
                for (int elemeOrderItemAttributeJsonArrayIndex = 0; elemeOrderItemAttributeJsonArrayIndex < elemeOrderItemAttributeJsonArraySize; elemeOrderItemAttributeJsonArrayIndex++) {
                    JSONObject elemeOrderItemAttributeJsonObject = elemeOrderItemAttributeJsonArray.optJSONObject(index);
                    ElemeOrderItemAttribute elemeOrderItemAttribute = new ElemeOrderItemAttribute();
                    elemeOrderItemAttribute.setTenantId(tenantId);
                    elemeOrderItemAttribute.setTenantCode(tenantCode);
                    elemeOrderItemAttribute.setBranchId(branchId);
                    elemeOrderItemAttribute.setElemeOrderId(elemeOrderId);
                    elemeOrderItemAttribute.setOrderId(id);
                    elemeOrderItemAttribute.setElemeOrderItemId(elemeOrderItem.getId());
                    elemeOrderItemAttribute.setName(elemeOrderItemAttributeJsonObject.optString("name"));
                    elemeOrderItemAttribute.setValue(elemeOrderItemAttributeJsonObject.optString("value"));
                    elemeOrderItemAttribute.setCreateUserId(userId);
                    elemeOrderItemAttribute.setLastUpdateUserId(userId);
                    elemeOrderItemAttribute.setLastUpdateRemark("饿了么系统推送新订单,保存菜品属性!");
                    elemeOrderItemAttributeMapper.insert(elemeOrderItemAttribute);
                }
            }
            JSONArray elemeOrderItemNewSpecJsonArray = elemeOrderItemJsonObject.optJSONArray("newSpecs");
            if (elemeOrderItemNewSpecJsonArray != null) {
                int elemeOrderItemNewSpecJsonArraySize = elemeOrderItemNewSpecJsonArray.size();
                for (int elemeOrderItemNewSpecJsonArrayIndex = 0; elemeOrderItemNewSpecJsonArrayIndex < elemeOrderItemNewSpecJsonArraySize; elemeOrderItemNewSpecJsonArrayIndex++) {
                    JSONObject elemeOrderItemNewSpecJsonObject = elemeOrderItemNewSpecJsonArray.optJSONObject(index);
                    ElemeOrderItemNewSpec elemeOrderItemNewSpec = new ElemeOrderItemNewSpec();
                    elemeOrderItemNewSpec.setTenantId(tenantId);
                    elemeOrderItemNewSpec.setTenantCode(tenantCode);
                    elemeOrderItemNewSpec.setBranchId(branchId);
                    elemeOrderItemNewSpec.setElemeOrderId(elemeOrderId);
                    elemeOrderItemNewSpec.setOrderId(id);
                    elemeOrderItemNewSpec.setElemeOrderItemId(elemeOrderItem.getId());
                    elemeOrderItemNewSpec.setName(elemeOrderItemNewSpecJsonObject.optString("name"));
                    elemeOrderItemNewSpec.setValue(elemeOrderItemNewSpecJsonObject.optString("value"));
                    elemeOrderItemNewSpec.setCreateUserId(userId);
                    elemeOrderItemNewSpec.setLastUpdateUserId(userId);
                    elemeOrderItemNewSpec.setLastUpdateRemark("饿了么系统推送新订单,保存菜品规格!");
                    elemeOrderItemNewSpecMapper.insert(elemeOrderItemNewSpec);
                }
            }
        }
    }
    if (orderActivityJsonArray != null) {
        int orderActivityJsonArraySize = orderActivityJsonArray.size();
        for (int orderActivityJsonArrayIndex = 0; orderActivityJsonArrayIndex < orderActivityJsonArraySize; orderActivityJsonArrayIndex++) {
            JSONObject elemeActivityJsonObject = orderActivityJsonArray.optJSONObject(orderActivityJsonArrayIndex);
            ElemeOrderActivity elemeOrderActivity = new ElemeOrderActivity();
            elemeOrderActivity.setTenantId(tenantId);
            elemeOrderActivity.setTenantCode(tenantCode);
            elemeOrderActivity.setBranchId(branchId);
            elemeOrderActivity.setElemeOrderId(elemeOrderId);
            elemeOrderActivity.setOrderId(id);
            elemeOrderActivity.setElemeActivityId(BigInteger.valueOf(elemeActivityJsonObject.optLong("id")));
            elemeOrderActivity.setName(elemeActivityJsonObject.optString("name"));
            elemeOrderActivity.setCategoryId(elemeActivityJsonObject.optInt("categoryId"));
            elemeOrderActivity.setElemePart(BigDecimal.valueOf(elemeActivityJsonObject.optDouble("elemePart")));
            elemeOrderActivity.setRestaurantPart(BigDecimal.valueOf(elemeActivityJsonObject.optDouble("restaurantPart")));
            elemeOrderActivity.setAmount(BigDecimal.valueOf(elemeActivityJsonObject.optDouble("amount")));
            elemeOrderActivity.setCreateUserId(userId);
            elemeOrderActivity.setLastUpdateUserId(userId);
            elemeOrderActivity.setLastUpdateRemark("饿了么系统推送新订单,保存饿了么订单活动!");
            elemeOrderActivityMapper.insert(elemeOrderActivity);
        }
    }
    elemeCallbackMessage.setOrderId(id);
    elemeCallbackMessageMapper.insert(elemeCallbackMessage);
    // publishElemeOrderMessage(elemeOrder.getTenantId(), elemeOrder.getBranchId(), elemeOrderId, elemeCallbackMessage.getType(), uuid);
    pushElemeMessage(tenantId, branchId, elemeOrderId, elemeCallbackMessage.getType(), uuid, 5, 60000);
}
Also used : JSONArray(net.sf.json.JSONArray) ArrayList(java.util.ArrayList) JSONObject(net.sf.json.JSONObject) BigInteger(java.math.BigInteger) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with JSONArray

use of net.sf.json.JSONArray in project fmv by f-agu.

the class MovieMetadatas method create.

/**
 * @param jsonObject
 * @return
 */
public static MovieMetadatas create(JSONObject jsonObject) {
    List<InfoBase> objects = new ArrayList<>(4);
    JSONArray names = jsonObject.names();
    Iterator<?> namesIterator = names.iterator();
    MovieMetadatas movieMetadatas = new MovieMetadatas(objects, jsonObject.toString());
    while (namesIterator.hasNext()) {
        String name = (String) namesIterator.next();
        Factory<?> factory = FACTORY_MAP.get(name);
        if (factory == null) {
            continue;
        }
        Object object = jsonObject.get(name);
        if (object instanceof JSONArray) {
            JSONArray array = (JSONArray) object;
            ListIterator<?> listIterator = array.listIterator();
            while (listIterator.hasNext()) {
                Object next = listIterator.next();
                if (next instanceof JSONObject) {
                    JSONObject nextJson = (JSONObject) next;
                    InfoBase obj = factory.create(nextJson, movieMetadatas);
                    if (obj != null) {
                        objects.add(obj);
                    }
                } else {
                // System.out.println(next);
                }
            }
        } else if (object instanceof JSONObject) {
            InfoBase obj = factory.create((JSONObject) object, movieMetadatas);
            if (obj != null) {
                objects.add(obj);
            }
        }
    }
    return movieMetadatas;
}
Also used : JSONObject(net.sf.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) JSONObject(net.sf.json.JSONObject)

Example 43 with JSONArray

use of net.sf.json.JSONArray in project onebusaway-application-modules by camsys.

the class CustomJsonLibHandler method fromObject.

public String fromObject(Object obj, String resultCode, Writer stream) throws IOException {
    String callback = null;
    HttpServletRequest req = ServletActionContext.getRequest();
    if (req != null)
        callback = req.getParameter("callback");
    String value = null;
    if (obj != null) {
        if (isArray(obj)) {
            JSONArray jsonArray = JSONArray.fromObject(obj);
            value = jsonArray.toString();
        } else {
            JSONObject jsonObject = JSONObject.fromObject(obj);
            value = jsonObject.toString();
        }
    }
    if (value != null) {
        if (callback != null)
            stream.write(callback + "(" + value + ")");
        else
            stream.write(value);
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray)

Example 44 with JSONArray

use of net.sf.json.JSONArray in project ngtesting-platform by aaronchen2k.

the class JsonUtils method getIntegerArray4Json.

/**
 * json 字符串转成Integer数组
 *
 * @param jsonString json字符串
 * @return 返回Integer数组
 */
public static Integer[] getIntegerArray4Json(String jsonString) {
    JSONArray jsonArray = JSONArray.fromObject(jsonString);
    Integer[] integerArray = new Integer[jsonArray.size()];
    for (int i = 0; i < jsonArray.size(); i++) {
        integerArray[i] = Integer.valueOf(jsonArray.getInt(i));
    }
    return integerArray;
}
Also used : JSONArray(net.sf.json.JSONArray)

Example 45 with JSONArray

use of net.sf.json.JSONArray in project ngtesting-platform by aaronchen2k.

the class JsonUtils method getLongArray4Json.

/**
 * json 字符串转成Long数组
 *
 * @param jsonString json字符串
 * @return 返回Long数组
 */
public static Long[] getLongArray4Json(String jsonString) {
    JSONArray jsonArray = JSONArray.fromObject(jsonString);
    Long[] longArray = new Long[jsonArray.size()];
    for (int i = 0; i < jsonArray.size(); i++) {
        longArray[i] = Long.valueOf(jsonArray.getLong(i));
    }
    return longArray;
}
Also used : JSONArray(net.sf.json.JSONArray)

Aggregations

JSONArray (net.sf.json.JSONArray)144 JSONObject (net.sf.json.JSONObject)109 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)22 HashMap (java.util.HashMap)20 File (java.io.File)16 Test (org.junit.Test)15 JSON (net.sf.json.JSON)14 Map (java.util.Map)12 JsonConfig (net.sf.json.JsonConfig)10 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)9 URI (java.net.URI)8 SimpleChartData (com.sohu.cache.web.chart.model.SimpleChartData)6 Date (java.util.Date)6 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)5 OutputStream (java.io.OutputStream)5 List (java.util.List)5 CAFunctorFactory (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory)4 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)4