Exemple #1
0
  // 电子围栏进出
  private JSONArray getElcInfoJson(String serialNumber) {
    JSONArray arrayObj = new JSONArray();

    LocElectfenceDaoIml locelect = new LocElectfenceDaoIml();
    HashMap<String, String> queryMap = new HashMap<String, String>();

    queryMap.put("serialNumber", serialNumber);

    List<LocElectfence> listLocElectfence = locelect.GetAll(1, 2, queryMap);

    if (!listLocElectfence.isEmpty()) {

      JsonConfig jsonConfig = new JsonConfig();

      jsonConfig.registerJsonValueProcessor(
          java.sql.Timestamp.class,
          new JsonValueProcessor() {
            private SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // new
            // SimpleDateFormat("yyyy-MM-dd");

            public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {
              return value == null ? "" : sd.format(value);
            }

            public Object processArrayValue(Object value, JsonConfig jsonConfig) {
              return null;
            }
          });

      jsonConfig.setExcludes(
          new String[] {
            "faddtime",
            "feltfenceid",
            "feltlatitude",
            "feltlongitude",
            "ffieldstatus",
            "fincreaseid",
            "flatitude",
            "flocfenid",
            "flongitude",
            "battery"
          });

      arrayObj = JSONArray.fromObject(listLocElectfence, jsonConfig);
    }

    return arrayObj;
  }
Exemple #2
0
  public void queryLocEleChange() {
    PrintWriter out = null;
    JSONObject json = new JSONObject();
    try {
      request.setCharacterEncoding("utf-8");
      response.setContentType("text/json");
      response.setCharacterEncoding("utf-8");
      out = response.getWriter();

      String serialNumber = request.getParameter("serialNumber");
      String areaNumber = request.getParameter("areaNumber");
      String areaName = request.getParameter("areaName");

      areaName = Tools.DecodeUtf8String(areaName);

      LocElectfenceDaoIml locelect = new LocElectfenceDaoIml();

      try {
        HashMap<String, String> queryMap = new HashMap<String, String>();

        queryMap.put("serialNumber", serialNumber);
        queryMap.put("areaNumber", areaNumber);
        queryMap.put("areaName", areaName);

        List<LocElectfence> listLocElectfence = locelect.GetAll(1, 2, queryMap);

        // List<LocElectfence> listLocElectfence= new
        // ArrayList<LocElectfence>();

        System.out.println(listLocElectfence.size());
        if (!listLocElectfence.isEmpty()) {

          JsonConfig jsonConfig = new JsonConfig();

          jsonConfig.registerJsonValueProcessor(
              java.sql.Timestamp.class,
              new JsonValueProcessor() {
                private SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // new
                // SimpleDateFormat("yyyy-MM-dd");

                public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {
                  return value == null ? "" : sd.format(value);
                }

                public Object processArrayValue(Object value, JsonConfig jsonConfig) {
                  return null;
                }
              });

          jsonConfig.setExcludes(
              new String[] {
                "faddtime",
                "feltfenceid",
                "feltlatitude",
                "feltlongitude",
                "ffieldstatus",
                "fincreaseid",
                "flatitude",
                "flocfenid",
                "flongitude"
              });

          // jsonArr.add(JSONArray.fromObject(listLocElectfence,jsonConfig));
          // jsonArr.add(listLocElectfence);

          json.put("state", 1);
          json.put("info", "成功查询");
          json.put("data", JSONArray.fromObject(listLocElectfence, jsonConfig));
        } else {
          json.put("state", 1);
          json.put("info", "成功查询,数据为空");
          json.put("data", null);
        }

      } catch (RuntimeException ex) {
        json.put("state", 1);
        json.put("info", ex.getMessage());
        json.put("data", null);
      }
    } catch (Exception e) {
      json.put("state", -1);
      json.put("info", e.getMessage());
      json.put("data", null);
    } finally {
      out.print(json);
      out.close();
    }
  }