Gb1400ResponseUtil.java 2.9 KB
package com.viontech.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.Date;
import java.util.List;

/**
 * @author vion
 **/
public class Gb1400ResponseUtil {

    public static JSONObject success(String id, String requestURL) {
        JSONObject response = new JSONObject();
        response.put("Id", id);
        response.put("LocalTime", new Date());
        response.put("RequestURL", requestURL);
        response.put("StatusCode", 0);
        response.put("StatusString", "成功");

        JSONObject result = new JSONObject();
        result.put("ResponseStatusObject", response);
        return result;
    }

    public static JSONObject success(String requestURL) {
        JSONObject response = new JSONObject();
        response.put("Id", null);
        response.put("LocalTime", new Date());
        response.put("RequestURL", requestURL);
        response.put("StatusCode", 0);
        response.put("StatusString", "成功");
        JSONObject result = new JSONObject();
        result.put("ResponseStatusObject", response);
        return result;
    }

    public static JSONObject successList(String requestURL) {
        JSONObject item = new JSONObject();
        item.put("Id", null);
        item.put("LocalTime", new Date());
        item.put("RequestURL", requestURL);
        item.put("StatusCode", 0);
        item.put("StatusString", "成功");

        JSONArray items = new JSONArray();
        items.add(item);

        JSONObject object = new JSONObject();
        object.put("ResponseStatusObject", items);

        JSONObject result = new JSONObject();
        result.put("ResponseStatusListObject", object);
        return result;
    }

    public static JSONObject responseStatusListObject(List<JSONObject> list) {
        JSONObject object = new JSONObject();
        object.put("ResponseStatusObject", list);

        JSONObject result = new JSONObject();
        result.put("ResponseStatusListObject", object);
        return result;
    }

    public static JSONObject buildResponseStatusObject(String id, String requestURL, Integer StatusCode, String StatusString) {
        JSONObject response = new JSONObject();
        response.put("Id", id);
        response.put("LocalTime", new Date());
        response.put("RequestURL", requestURL);
        response.put("StatusCode", StatusCode);
        response.put("StatusString", StatusString);
        return response;
    }

    public static JSONObject error(Integer errorNo, String errorMsg, String requestURL) {
        JSONObject response = new JSONObject();
        response.put("Id", null);
        response.put("LocalTime", new Date());
        response.put("RequestURL", requestURL);
        response.put("StatusCode", errorNo);
        response.put("StatusString", errorMsg);
        JSONObject result = new JSONObject();
        result.put("ResponseStatusObject", response);
        return result;
    }
}