Ejemplo n.º 1
0
 // 岗位级别联动菜单
 public String getStates() throws Exception {
   try {
     String code = getRequest().getParameter("code");
     Dictvalue dictvalue = dictvalueManager.findByCode(code);
     List list = new ArrayList(dictvalue.getDictvalues());
     JsonConfig cfg = new JsonConfig();
     cfg.setJsonPropertyFilter(
         new PropertyFilter() {
           public boolean apply(Object source, String name, Object value) {
             if (name.equals("code") || name.equals("value")) {
               return false;
             } else {
               return true;
             }
           }
         });
     String ss = JSONArray.fromObject(list, cfg).toString();
     StringBuffer returnstr = new StringBuffer("");
     returnstr.append(ss);
     super.renderHtmlUTF(returnstr.toString());
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Ejemplo n.º 2
0
  public String execute() throws Exception {

    response.setCharacterEncoding("UTF-8"); // 编码
    int count = memberFriendService.findMemberCountByInsertDate(insertDate); // 统计数量
    List list =
        memberFriendService.findMemerFriendListByTime(page, rows, insertDate); // 根据投票选项编号,查找详情列表
    PrintWriter out = response.getWriter();
    try {
      JsonConfig cfg = new JsonConfig();
      cfg.registerJsonValueProcessor(
          java.util.Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
      JSONArray arr = JSONArray.fromObject(list, cfg);
      JSONObject jsonObj = new JSONObject();
      jsonObj.put("rows", arr);
      jsonObj.put("total", count);
      out.write(jsonObj.toString());
      out.flush();
      out.close();

    } catch (Exception e) {

      e.printStackTrace();
    }
    return null;
  }
 @Override
 public String getDataRetailsNoRetailResult(String brand, Date date) {
   Date yesterday = getYesterday(date);
   List<DataRetailsNoRetail> noRetails = this.dataDaoV2.getDataRetailsNoRetail(yesterday, brand);
   Collections.sort(noRetails);
   DataRetailsNoRetailResult drssr = new DataRetailsNoRetailResult();
   drssr.setDate(yesterday);
   drssr.setResult(0);
   drssr.setNoRetails(new ArrayList<DataRetailsChannelNoRetailResult>());
   DataRetailsChannelNoRetailResult all = new DataRetailsChannelNoRetailResult();
   all.setChannel("全部");
   all.setStores(noRetails);
   drssr.getNoRetails().add(all);
   DataRetailsChannelNoRetailResult r = null;
   for (DataRetailsNoRetail drnr : noRetails) {
     if (StringUtils.isNotEmpty(drnr.getChannel())) {
       if (r == null || !r.getChannel().equals(drnr.getChannel())) {
         r = new DataRetailsChannelNoRetailResult();
         r.setStores(new ArrayList<DataRetailsNoRetail>());
         r.setChannel(drnr.getChannel());
         drssr.getNoRetails().add(r);
       }
       r.getStores().add(drnr);
     }
   }
   JsonConfig jsonConfig = new JsonConfig();
   jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
   jsonConfig.registerJsonValueProcessor(Integer.class, new IntegerJsonValueProcessor());
   String result = JSONObject.fromObject(drssr, jsonConfig).toString();
   return result;
 }
Ejemplo n.º 4
0
  public String showJson() {
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.registerJsonBeanProcessor(
        Sucursal.class,
        new JsonBeanProcessor() {

          @Override
          public JSONObject processBean(Object bean, JsonConfig jsonConfig) {
            Sucursal sucursal = (Sucursal) bean;
            JSONObject row = new JSONObject();
            row.element("id", sucursal.getId());

            JSONArray cell = new JSONArray();
            cell.add(sucursal.getNombre());
            cell.add(sucursal.getDireccion());
            cell.add(sucursal.getTelefono());

            row.element("cell", cell);

            return row;
          }
        });

    JSONObject rootObj = new JSONObject();
    JSONArray jrows = (JSONArray) JSONSerializer.toJSON(sucursales, jsonConfig);

    rootObj.element("rows", jrows);
    rootObj.element("records", sucursales.size());
    rootObj.element("total", Math.ceil((double) sucursales.size() / rows));
    rootObj.element("page", page);

    writeResponse(rootObj);
    return JSON;
  }
Ejemplo n.º 5
0
  public String query() throws IOException {
    List<Song> songs = songService.findSongs();

    JsonConfig jc = new JsonConfig();
    jc.setExcludes(
        new String[] {
          "recorder",
          "copyright",
          "size",
          "initiateName",
          "keyword",
          "date",
          "description",
          "singer"
        });

    JSONArray jsonArray = JSONArray.fromObject(songs, jc);

    String json = jsonArray.toString();

    System.out.print(json);
    ServletActionContext.getResponse().setContentType("text/json;charset=UTF-8");
    System.out.println(json);
    ServletActionContext.getResponse().getWriter().print(json);

    return NONE;
  }
Ejemplo n.º 6
0
  public String play() throws IOException {
    Song song = songService.findById(model.getSongId());

    JsonConfig jc = new JsonConfig();
    jc.setExcludes(
        new String[] {
          "recorder",
          "copyright",
          "size",
          "initiateName",
          "keyword",
          "date",
          "description",
          "singer"
        });

    JSONObject jsonObject = JSONObject.fromObject(song, jc);

    String json = jsonObject.toString();

    System.out.print(json);
    ServletActionContext.getResponse().setContentType("text/json;charset=UTF-8");
    System.out.println(json);
    ServletActionContext.getResponse().getWriter().print(json);

    return NONE;
  }
 public String getWorkMainById(String wmId) {
   WorkMain workMain = this.workManageDaoImpl.getWorkMainById(wmId);
   JsonConfig config = new JsonConfig();
   config.setExcludes(new String[] {"workItems"});
   JSONObject json = JSONObject.fromObject(workMain, config);
   return json.toString();
 }
 // 按id查询
 @RequestMapping("fenghuang/ZiyuanJiudianSelectId.do")
 @ResponseBody
 public Map<String, Object> jiudianSelectId(
     HttpServletRequest request, HttpServletResponse response, long id) {
   Map<String, Object> result = new HashMap<String, Object>();
   try {
     List<Map<String, Object>> jdlist = izyjd.jiudianSelectId(id);
     for (int i = 0; i < jdlist.size(); i++) {
       for (Entry<String, Object> entry : jdlist.get(i).entrySet()) {
         if (entry.getValue() == null) {
           entry.setValue("");
         }
       }
     }
     result.put("rows", jdlist);
     JsonConfig config = new JsonConfig();
     config.registerJsonValueProcessor(Timestamp.class, new DateJsonValueProcessor("yyyy-MM-dd"));
     // 把MAP转换成JSON,返回到前台
     JSONObject fromObject = JSONObject.fromObject(result, config);
     return fromObject;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return result;
 }
  @Override
  public String getRetailChartResultForJson(String brand, String type, Date date) {
    Date yesterday = getYesterday(date);
    List<RetailResult> dataProvider = this.getRetailChartResult(brand, type, date);
    RetailChartResult rcr = new RetailChartResult();
    rcr.setDataProvider(dataProvider);
    rcr.setHeight(700 + dataProvider.size() * 80);
    rcr.setTop(300 + dataProvider.size() * 5);

    double total = 0;
    for (RetailResult rr : dataProvider) {
      if (rr.getDayAmount() != null) {
        total += rr.getDayAmount();
      }
    }
    rcr.setDate(yesterday);
    rcr.setTotal(Math.round(total));
    rcr.setCount(dataProvider.size());
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
    jsonConfig.registerJsonValueProcessor(Integer.class, new IntegerJsonValueProcessor());

    String result = JSONObject.fromObject(rcr, jsonConfig).toString();
    return result;
  }
 // 模糊查询
 @RequestMapping("fenghuang/ZyjiudianSelectLike.do")
 @ResponseBody
 public Map<String, Object> jiudianSelectLike(
     HttpServletRequest request,
     HttpServletResponse response,
     Integer page,
     Integer rows,
     String name,
     String chengshi,
     String weihuren) {
   try {
     Pagination<Jiudian> pagination =
         (Pagination<Jiudian>) izyjd.jiudianSelectLike(page, rows, name, chengshi, weihuren);
     List<Map<String, Object>> jiudianList = pagination.getResultList();
     Map<String, Object> returnValue = new HashMap<String, Object>();
     for (int i = 0; i < jiudianList.size(); i++) {
       for (Entry<String, Object> entry : jiudianList.get(i).entrySet()) {
         if (entry.getValue() == null) {
           entry.setValue("");
         }
       }
     }
     returnValue.put("total", pagination.getTotalRows());
     returnValue.put("rows", jiudianList);
     JsonConfig config = new JsonConfig();
     config.registerJsonValueProcessor(Timestamp.class, new DateJsonValueProcessor("yyyy-MM-dd"));
     // 把MAP转换成JSON,返回到前台
     JSONObject fromObject = JSONObject.fromObject(returnValue, config);
     // System.out.println(fromObject);
     return fromObject;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Ejemplo n.º 11
0
  public ActionForward updateAppointmentReason(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HashMap<String, Object> hashMap = new HashMap<String, Object>();

    OscarAppointmentDao appointmentDao =
        (OscarAppointmentDao) SpringUtils.getBean("oscarAppointmentDao");

    Appointment appointment =
        appointmentDao.find(Integer.parseInt(request.getParameter("appointmentNo")));

    if (appointment != null) {
      appointment.setReason(request.getParameter("reason"));
      appointmentDao.merge(appointment);

      hashMap.put("success", true);
      hashMap.put("appointmentNo", appointment.getId());
    }

    JsonConfig config = new JsonConfig();
    config.registerJsonBeanProcessor(java.sql.Date.class, new JsDateJsonBeanProcessor());

    JSONObject json = JSONObject.fromObject(hashMap, config);
    response.getOutputStream().write(json.toString().getBytes());

    return null;
  }
Ejemplo n.º 12
0
  public ActionForward getBillingDxAutocompleteList(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    DiagnosticCodeDao diagnosticCodeDao =
        (DiagnosticCodeDao) SpringUtils.getBean("diagnosticCodeDao");

    String query = request.getParameter("query");

    List<DiagnosticCode> queryResults =
        diagnosticCodeDao.findByDiagnosticCodeAndRegion(query, "ON");
    HashMap<String, Object> hashMap = new HashMap<String, Object>();

    hashMap.put("dxCode", queryResults);

    JsonConfig config = new JsonConfig();
    config.registerJsonBeanProcessor(java.sql.Date.class, new JsDateJsonBeanProcessor());

    JSONObject json = JSONObject.fromObject(hashMap, config);
    response.getOutputStream().write(json.toString().getBytes());

    return null;
  }
Ejemplo n.º 13
0
  public ActionForward getBillingAutocompleteList(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    BillingServiceDao billingServiceDao =
        (BillingServiceDao) SpringUtils.getBean("billingServiceDao");

    String query = request.getParameter("query");

    List<BillingService> queryResults =
        billingServiceDao.findBillingCodesByCode("%" + query + "%", "ON", new Date(), 1);
    HashMap<String, Object> hashMap = new HashMap<String, Object>();

    hashMap.put("billing", queryResults);

    JsonConfig config = new JsonConfig();
    config.registerJsonBeanProcessor(java.sql.Date.class, new JsDateJsonBeanProcessor());

    JSONObject json = JSONObject.fromObject(hashMap, config);
    response.getOutputStream().write(json.toString().getBytes());

    return null;
  }
Ejemplo n.º 14
0
  public String sddata() {
    try {
      Map<String, Object> params = new HashMap<String, Object>();
      params.put("staffno", staffno);
      if (!statusid.equals("")) {
        String statusWhere =
            " CHARINDEX(','+CAST(A.StatusId AS VARCHAR(4))+',','," + statusid + ",') > 0 ";
        params.put("statusWhere", statusWhere);
      }
      params.put("starttime", startDate);
      params.put("endtime", endDate);

      List<StatusDetail> lists = statusDetailService.retrieveForMod(params);
      for (StatusDetail entity : lists) {
        entity.setStatusName(HelperUtils.getLanguageValue("zh", entity.getStatusName()));
      }
      JsonConfig jsonConfig = new JsonConfig();
      jsonConfig.registerJsonValueProcessor(
          Date.class, new JsonDateValueProcessor("yyyy-MM-dd HH:mm:ss"));
      JSONArray json = JSONArray.fromObject(lists, jsonConfig);
      String s = json.toString();
      postJSON("{\"rows\":" + s + "}");
    } catch (Exception ex) {
      throw ex;
    }
    return null;
  }
Ejemplo n.º 15
0
 public static JsonConfig configDateTimeJson(String[] excludes) {
   JsonConfig jsonConfig = new JsonConfig();
   setConfig(jsonConfig, excludes);
   jsonConfig.registerJsonValueProcessor(Date.class, new DateTimeJsonValueProcessor());
   jsonConfig.registerJsonValueProcessor(Timestamp.class, new DateTimeJsonValueProcessor());
   return jsonConfig;
 }
Ejemplo n.º 16
0
  /**
   * 除去不想生成的字段(特别适合去掉级联的对象)+时间转换
   *
   * @param excludes 除去不想生成的字�?
   * @param datePattern
   * @return
   */
  public static JsonConfig configJson(String[] excludes, String datePattern) {
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setExcludes(excludes);
    jsonConfig.setIgnoreDefaultExcludes(true);
    jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
    jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor(datePattern));

    return jsonConfig;
  }
Ejemplo n.º 17
0
  public ActionForward saveMacro(
      ActionMapping maping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    EyeformMacroDao eyeformMacroDao = (EyeformMacroDao) SpringUtils.getBean("eyeformMacroDao");
    HashMap<String, Object> hashMap = new HashMap<String, Object>();

    try {
      EyeformMacro macro = new EyeformMacro();
      if (request.getParameter("macroIdField") != null
          && request.getParameter("macroIdField").length() > 0) {
        macro = eyeformMacroDao.find(Integer.parseInt(request.getParameter("macroIdField")));
        macro = (macro == null ? new EyeformMacro() : macro);
      }

      macro.setMacroName(request.getParameter("macroNameBox"));
      macro.setImpressionText(request.getParameter("macroImpressionBox"));
      macro.setPlanText(request.getParameter("macroPlanBox"));
      macro.setCopyFromLastImpression(
          Boolean.parseBoolean(request.getParameter("macroCopyFromLastImpression")));

      if (request.getParameter("billingData") != null
          && request.getParameter("billingData").length() > 0) {
        String[] billingItems = request.getParameterValues("billingData");

        List<EyeformMacroBillingItem> billingItemList = new LinkedList<EyeformMacroBillingItem>();
        for (String b : billingItems) {
          EyeformMacroBillingItem billingItem = new EyeformMacroBillingItem();
          String billingCode = b.substring(0, b.indexOf("|"));
          String multiplier = b.substring(b.indexOf("|"));

          billingItem.setBillingServiceCode(billingCode);
          billingItem.setMultiplier(Double.parseDouble(multiplier));

          billingItemList.add(billingItem);
        }

        macro.setBillingItems(billingItemList);
      }

      eyeformMacroDao.merge(macro);

      hashMap.put("saved", macro.getId());
    } catch (Exception e) {
      hashMap.put("error", e.getMessage());
    }

    JsonConfig config = new JsonConfig();
    config.registerJsonBeanProcessor(java.sql.Date.class, new JsDateJsonBeanProcessor());

    JSONObject json = JSONObject.fromObject(hashMap, config);
    response.getOutputStream().write(json.toString().getBytes());

    return null;
  }
  private AchievementBean[] parseAchievementsJSon(String json) {
    JSONUtils.getMorpherRegistry().registerMorpher(new EnumMorpher(Category.class));
    JSONUtils.getMorpherRegistry().registerMorpher(new EnumMorpher(Difficulty.class));
    JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(json);
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setArrayMode(JsonConfig.MODE_OBJECT_ARRAY);
    jsonConfig.setRootClass(AchievementBean.class);

    return (AchievementBean[]) JSONSerializer.toJava(jsonArray, jsonConfig);
  }
Ejemplo n.º 19
0
 private <T> Object getBean(JSONObject jsonObject, Class<T> clazz) {
   // 声明JsonConfig对象
   JsonConfig cfg = new JsonConfig();
   // 设置属性包装器
   cfg.setPropertySetStrategy(new PropertyStrategyWrapper(PropertySetStrategy.DEFAULT));
   // 设置要转换成的JavaBean
   cfg.setRootClass(clazz);
   // 转换
   Object object = JSONObject.toBean(jsonObject, cfg);
   return object;
 }
Ejemplo n.º 20
0
 public String getWorkItemsById(String wmId) {
   List<WorkItem> workItems = this.workManageDaoImpl.getWorkItemsById(wmId);
   JsonConfig config = new JsonConfig();
   config.setExcludes(new String[] {"workMain"});
   config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessImpl("yyyy/MM/dd"));
   JSONArray data = JSONArray.fromObject(workItems, config);
   JSONObject json = new JSONObject();
   json.put("datas", data);
   json.put("results", workItems.size());
   return json.toString();
 }
Ejemplo n.º 21
0
 @RequestMapping(value = "getDetailInfo.sdo")
 public @ResponseBody String getDetailInfo(@RequestParam("id") int id) {
   JSONObject obj = new JSONObject();
   obj.put("success", true);
   UserEty userEty = (UserEty) userDao.selectById(id);
   JsonConfig config = new JsonConfig();
   config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
   JSONObject dataObj = JSONObject.fromObject(userEty, config);
   obj.put("data", dataObj);
   return obj.toString();
 }
Ejemplo n.º 22
0
 public static void testJson2Java2() {
   String productImageListStore =
       "[{\"bigProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1_big.jpg\",\"id\":\"b955bd91c8b64844b4681b2eb44849d1\",\"smallProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1_small.jpg\",\"sourceProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1.jpeg\",\"thumbnailProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1_thumbnail.jpg\"}]";
   JsonConfig jsonConfig = new JsonConfig();
   jsonConfig.setRootClass(ProductImage.class);
   JSONArray jsonArray = JSONArray.fromObject(productImageListStore);
   List<ProductImage> list = (List<ProductImage>) JSONSerializer.toJava(jsonArray, jsonConfig);
   for (ProductImage p : list) {
     System.out.println(p.getBigProductImagePath());
   }
 }
Ejemplo n.º 23
0
  public void queryMsgCenter() {

    PrintWriter out = null;
    JSONObject json = new JSONObject();
    try {
      request.setCharacterEncoding("utf-8");
      response.setContentType("text/json");
      response.setCharacterEncoding("utf-8");
      out = response.getWriter();
      String serialnumid = request.getParameter("serialnumid");

      Serialnumber serialnumber = serialNumService.Find(serialnumid);
      if (serialnumber == null) {
        json.put("state", 2);
        json.put("info", "找不到此序列号的信息");
        json.put("serialnumid", serialnumid);

        out.print(json);
        out.close();

        return;
      }

      JSONArray locfecnce = this.getElcInfoJson(serialnumber.getSerialnumber());
      JSONArray detach = this.getDetachJson(serialnumber.getSerialnumber());
      JSONArray fee = this.getFeeBalanceJson(serialnumid);
      JSONArray battery = this.getBatteryJson(serialnumber.getSerialnumber());

      JsonConfig jsonSerialNumConfig = Jsonconf.getSertialNumJsonConf(request);
      jsonSerialNumConfig.setExcludes(
          new String[] {"floglastip", "fphonetime", "fqrcode", "id", "fislostinfo", "fislosttime"});

      json.put("state", 1);
      json.put("info", "成功查询");

      json.put("serialNumber", JSONArray.fromObject(serialnumber, jsonSerialNumConfig));
      json.put("notifyFecnce", locfecnce);
      json.put("nofityDetach", detach);
      json.put("notifyFee", fee);
      json.put("notifyBattery", battery);

    } catch (Exception e) {
      json.put("state", -1);
      json.put("info", e.getMessage());
      json.put("serialNumber", null);
      json.put("notifyFecnce", null);
      json.put("nofityDetach", null);
      json.put("notifyFee", null);
      json.put("notifyBattery", null);
    } finally {
      out.print(json);
      out.close();
    }
  }
Ejemplo n.º 24
0
  private JSONArray getBatteryJson(String serialNumber) {

    JSONArray arrayObj = null;

    LocationInfo battery = liDao.findBySeriaNumber(serialNumber);

    JsonConfig jconfig = Jsonconf.getCommonJsonConf();
    jconfig.setExcludes(new String[] {"location", "text", "lng", "lat", "id", "faddtime"});

    arrayObj = JSONArray.fromObject(battery, jconfig);

    return arrayObj;
  }
 @Override
 public String getIndexResult(String[] brands, Date date) {
   if (date != null) {
     DayStatus ds = dataDaoV2.getDayStatus(date);
     if (ds == null || ds.getStatus() == null || ds.getStatus() == 0) {
       SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日");
       return this.getErrorResult(3002, sdf.format(date) + "没有相关数据,请重新选择日期");
     }
   }
   Date yesterday = getYesterday(date);
   Set<String> bSet = new HashSet<String>();
   for (String brand : brands) {
     bSet.add(brand);
   }
   List<BrandResult> indexBrandResults = dataDaoV2.getBrandResult(yesterday, brands);
   for (BrandResult ibr : indexBrandResults) {
     if (springProperty.isMockValue()) {
       ibr.setDayAmount(10000L);
     }
     bSet.remove(ibr.getBrand());
   }
   for (String brand : bSet) {
     BrandResult ibr = new BrandResult(brand, "", 0);
     indexBrandResults.add(ibr);
   }
   IndexStatResult ir = new IndexStatResult();
   ir.setBrands(indexBrandResults);
   ir.setResult(0);
   ir.setDate(yesterday);
   ir.setClientVersion(springProperty.getClientVersion());
   Date realYesterday =
       DateUtils.addDays(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH), -1);
   DayStatus ds = dataDaoV2.getDayStatus(realYesterday);
   if (ds != null && ds.getStatus() != null && ds.getStatus().intValue() != 0) {
     ir.setYesterday(true);
   } else {
     ir.setYesterday(false);
   }
   List<Date> availableDates = dataDaoV2.getAvailableDates(realYesterday);
   List<String> ads = new ArrayList<String>();
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   for (Date ad : availableDates) {
     ads.add(sdf.format(ad));
   }
   ir.setAvailableDates(ads);
   JsonConfig jsonConfig = new JsonConfig();
   jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
   jsonConfig.registerJsonValueProcessor(Integer.class, new IntegerJsonValueProcessor());
   String result = JSONObject.fromObject(ir, jsonConfig).toString();
   return result;
 }
Ejemplo n.º 26
0
 public void getsendMessageNotimeOut(Integer keys, Object message) {
   IoSession session = getSession(keys);
   log.info("反向发送消息到客户端Session---key=" + keys + "----------消息=" + message);
   if (MemoryData.minaClientSendTime.get(keys) != null
       && new Date().getTime() - MemoryData.minaClientSendTime.get(keys).getTime() > 1000 * 60
       && session.isConnected()) {
     System.out.println("发送消息----------------------------");
     JsonConfig config = new JsonConfig();
     config.registerDefaultValueProcessor(Integer.class, new MyDefaultIntegerValueProcessor());
     JSONObject json = JSONObject.fromObject(message, config);
     log.info("转化后的json的内容:" + json);
     session.write(json);
   }
 }
  @Override
  public String getGoodRankResult(String brand, Date date) {
    Date yesterday = getYesterday(date);
    List<GoodRankResult> rankResult = this.dataDaoV2.getGoodRankResult(yesterday, brand);
    try {
      for (GoodRankResult grr : rankResult) {
        if (StringUtils.isNotEmpty(grr.getImageLink())) {
          if (!grr.getImageLink().startsWith("http")) {
            grr.setImageLink(
                springProperty.getServerUrl()
                    + "/peacebird/goodImage.do?path="
                    + URLEncoder.encode(grr.getImageLink(), "utf-8"));
          }
        } else {
          grr.setImageLink(
              springProperty.getServerUrl()
                  + "/peacebird/goodImage.do?path="
                  + URLEncoder.encode("nogoods.gif", "utf-8"));
        }
        if (StringUtils.isNotEmpty(grr.getImageLinkMin())) {
          if (!grr.getImageLinkMin().startsWith("http")) {
            grr.setImageLinkMin(
                springProperty.getServerUrl()
                    + "/peacebird/goodImage.do?path="
                    + URLEncoder.encode(grr.getImageLinkMin(), "utf-8"));
          }

        } else {
          grr.setImageLinkMin(
              springProperty.getServerUrl()
                  + "/peacebird/goodImage.do?path="
                  + URLEncoder.encode("nogoods_min.jpg", "utf-8"));
        }
      }
    } catch (Exception e) {
      log.error("", e);
    }

    GoodRankStatResult grsr = new GoodRankStatResult();
    grsr.setDate(yesterday);
    grsr.setResult(0);
    grsr.setGoods(rankResult);

    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
    jsonConfig.registerJsonValueProcessor(Integer.class, new IntegerJsonValueProcessor());
    String result = JSONObject.fromObject(grsr, jsonConfig).toString();
    return result;
  }
Ejemplo n.º 28
0
 /**
  * 将对象等转换为json格式并输出 @Title outJson
  *
  * @author hedj @Description:
  * @date 2013-12-6
  * @param obj 要转换的对象
  * @param objs 可变参数 第一个参数日期格式,默认为"yyyy-MM-dd"
  * @return
  */
 public static String toJsonString(Object obj, Object... objs) {
   try {
     String dateFormat = DateUtil.DATE_FORMAT;
     if (objs != null && objs.length > 0) {
       dateFormat = (String) objs[0];
     }
     JsonConfig config = new JsonConfig();
     config.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor(dateFormat));
     config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
     return JSONObject.fromObject(obj, config).toString();
   } catch (Exception e) {
     log.error(" 转换JSON错误:", e);
     return "";
   }
 }
Ejemplo n.º 29
0
  /**
   * 把数据对象转换成json字符串 DTO对象形如:{"id" : idValue, "name" : nameValue, ...} 数组对象形如:[{}, {}, {}, ...]
   * map对象形如:{key1 : {"id" : idValue, "name" : nameValue, ...}, key2 : {}, ...}
   *
   * @param object
   * @return
   */
  public static String getJSONString(Object object) throws Exception {
    String jsonString = null;
    // 日期值处理器
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.registerJsonValueProcessor(java.util.Date.class, new JsonDateValueProcessor());
    if (object != null) {
      if (object instanceof Collection || object instanceof Object[]) {
        jsonString = JSONArray.fromObject(object, jsonConfig).toString();
      } else {
        jsonString = JSONObject.fromObject(object, jsonConfig).toString();
      }
    }

    return jsonString == null ? "{}" : jsonString;
  }
 @Override
 public String getChannelResult(String brand, Date date) {
   Date yesterday = getYesterday(date);
   List<ChannelResult> channelResult = this.dataDaoV2.getChannelResult(yesterday, brand);
   Collections.sort(channelResult);
   ChannelStatResult csr = new ChannelStatResult();
   csr.setChannel(channelResult);
   csr.setResult(0);
   csr.setDate(yesterday);
   JsonConfig jsonConfig = new JsonConfig();
   jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
   jsonConfig.registerJsonValueProcessor(Integer.class, new IntegerJsonValueProcessor());
   String result = JSONObject.fromObject(csr, jsonConfig).toString();
   return result;
 }