@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;
 }
Exemplo n.º 2
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;
 }
  @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;
  }
 @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;
 }
  @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;
  }
 @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;
 }
  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;
  }
 // 模糊查询
 @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;
 }
 // 按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;
 }
Exemplo n.º 10
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;
  }
Exemplo n.º 11
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;
  }
Exemplo n.º 12
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();
 }
Exemplo n.º 13
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();
 }
  @Override
  public String getStoreRankResult(String brand, Date date) {
    Date yesterday = getYesterday(date);
    List<String> channels = this.dataDaoV2.getAllChannelForRank(yesterday, brand);
    Collections.sort(channels, new ChannelComparator());
    List<ChannelRankResult> crrList = new ArrayList<ChannelRankResult>();

    List<StoreRankResult> allRankResult =
        this.dataDaoV2.getAllStoreRankResult(yesterday, brand, "desc");
    List<StoreRankResult> allReverseRankResult =
        this.dataDaoV2.getAllStoreRankResult(yesterday, brand, "asc");
    ChannelRankResult acrr = new ChannelRankResult();
    acrr.setChannel("全部");
    acrr.setRanks(allRankResult);
    acrr.setReverseRanks(allReverseRankResult);
    crrList.add(0, acrr);

    for (String channel : channels) {
      List<StoreRankResult> rankResult =
          this.dataDaoV2.getStoreRankResult(yesterday, brand, channel, "asc");
      List<StoreRankResult> reverseRankResult =
          this.dataDaoV2.getStoreRankResult(yesterday, brand, channel, "desc");
      ChannelRankResult crr = new ChannelRankResult();
      crr.setChannel(channel);
      crr.setRanks(rankResult);
      crr.setReverseRanks(reverseRankResult);
      crrList.add(crr);
    }
    StoreRankStatResult rsr = new StoreRankStatResult();
    rsr.setResult(0);
    rsr.setDate(yesterday);
    rsr.setChannels(crrList);
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
    jsonConfig.registerJsonValueProcessor(Integer.class, new IntegerJsonValueProcessor());
    String result = JSONObject.fromObject(rsr, jsonConfig).toString();
    return result;
  }
  @Override
  public String getDataRetailStoreSumResult(String brand, Date date) {
    Date yesterday = getYesterday(date);
    List<DataRetailStoreSum> monthlySums =
        this.dataDaoV2.getDataRetailStoreSum(yesterday, brand, "months");

    List<DataRetailStoreSum> yearlySums =
        this.dataDaoV2.getDataRetailStoreSum(yesterday, brand, "years");

    Collections.sort(monthlySums);
    Collections.sort(yearlySums);

    DataRetailStoreSumResult drssr = new DataRetailStoreSumResult();
    drssr.setDate(yesterday);
    drssr.setResult(0);
    drssr.setMonthlySums(monthlySums);
    drssr.setYearlySums(yearlySums);
    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;
  }
Exemplo n.º 16
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 "";
   }
 }
Exemplo n.º 17
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;
  }
Exemplo n.º 18
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;
  }
Exemplo n.º 19
0
 public String getWorkMainPage(int start, int limit, String userId) {
   JSONObject json = new JSONObject();
   try {
     List<WorkMain> workMains = workManageDaoImpl.getWorkMainPage(start, limit, userId);
     int workMainNum = workManageDaoImpl.getWorkMainPageNum(userId);
     JsonConfig config = new JsonConfig();
     config.setExcludes(new String[] {"workItems"});
     config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessImpl("yyyy/MM/dd"));
     JSONArray data = JSONArray.fromObject(workMains, config);
     json.put("datas", data);
     json.put("results", workMainNum);
     json.put("start", start);
     json.put("limit", limit);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return json.toString();
 }
Exemplo n.º 20
0
 /**
  * 将对象等转换为json格式并输出 @Title outJson
  *
  * @author hedj @Description:
  * @date 2013-12-6
  * @param obj 要转换的对象
  * @param objs 可变参数 第一个参数日期格式,默认为"yyyy-MM-dd"
  * @return
  */
 public static String outJson(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);
     String json = JSONObject.fromObject(obj, config).toString();
     getResponse().setContentType("text/html;charset=UTF-8");
     PrintWriter out = getResponse().getWriter();
     out.write(json);
     return json;
   } catch (Exception e) {
     log.error(" 转换JSON错误:", e);
     return "";
   }
 }
Exemplo n.º 21
0
  public String lddata() {
    try {
      Map<String, Object> params = new HashMap<String, Object>();
      params.put("staffnolists", "A.StaffNo = '" + staffno + "'");
      params.put("starttime", startDate);
      params.put("endtime", endDate);

      List<LogDetail> lists = logDetailService.retrieveForMod(params);
      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;
  }
 /**
  * 显示历史jobs信息
  *
  * @param response
  * @return
  * @throws Exception
  */
 @ResponseBody
 @RequestMapping(value = "/loadhistory")
 public DaoPage getJobByName(
     HttpServletResponse response, @RequestParam Map<String, Object> parameter) throws Exception {
   StringBuffer sqlBuffer = new StringBuffer();
   System.out.println((String) parameter.get("id"));
   DaoPage daoPage =
       jobDefinitionService.getJobByName(
           parameter,
           Integer.parseInt(parameter.get("page").toString()),
           Integer.parseInt(parameter.get("rows").toString()));
   JSONObject result = new JSONObject();
   JsonConfig jsonConfig = new JsonConfig();
   jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
   JSONArray jsonArray = JSONArray.fromObject(daoPage.getResult(), jsonConfig);
   result.put("total", daoPage.getRecordCount());
   result.put("rows", jsonArray); // daoPage.getr
   result.put("pages", daoPage.getPageCount());
   result.put("success", true);
   retJson(response, result);
   return null;
 }
Exemplo n.º 23
0
  /**
   * 策略日期列表
   *
   * @param mapping
   * @param actionForm
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  @SuppressWarnings("unchecked")
  public ActionForward tacticsDateList(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    try {
      ListQuery listQuery = new ListQuery(TacticsDate.class, request);
      List<TacticsDate> result = tacticsManager.getTacticsDateList(listQuery);
      if (result.size() > 0) {
        result = (List<TacticsDate>) result.get(1);
      }
      JsonConfig config = new JsonConfig();
      config.registerJsonValueProcessor(java.sql.Date.class, new JsonDateToStringProcessorImpl());
      config.setJsonPropertyFilter(new IgnoreFieldProcessorImpl(true, new String[] {"tactics"}));

      JSONArray dates = JSONArray.fromObject(result, config);
      print(dates.toString(), response);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }
    return mapping.findForward("tacticsList");
  }
Exemplo n.º 24
0
  public String itdata() {
    try {
      Map<String, Object> params = new HashMap<String, Object>();
      params.put("staffno", staffno);
      if (!regionmarketid.equals("")) {
        String regionmarketWhere =
            " CHARINDEX(','+CAST(A.RegionMarketId AS VARCHAR(4))+',',',"
                + regionmarketid
                + ",') > 0 ";
        params.put("regionmarketWhere", regionmarketWhere);
      }
      if (!tickettypeid.equals("")) {
        String tickettypeWhere =
            " CHARINDEX(','+CAST(A.TicketTypeId AS VARCHAR(4))+',','," + tickettypeid + ",') > 0 ";
        params.put("tickettypeWhere", tickettypeWhere);
      }
      params.put("starttime", startDate);
      params.put("endtime", endDate);

      List<IssueType> lists = issueTypeService.retrieveForMod(params);
      for (IssueType entity : lists) {
        entity.setRegionMarketName(
            (HelperUtils.getLanguageValue("zh", entity.getRegionMarketName())));
        entity.setTicketTypeName((HelperUtils.getLanguageValue("zh", entity.getTicketTypeName())));
      }
      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;
  }
Exemplo n.º 25
0
 static {
   jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor());
   jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class, new DateJsonValueProcessor());
 }
Exemplo n.º 26
0
  /**
   * Process HTTP request.
   *
   * @param act Action.
   * @param req Http request.
   * @param res Http response.
   */
  private void processRequest(String act, HttpServletRequest req, HttpServletResponse res) {
    res.setContentType("application/json");
    res.setCharacterEncoding("UTF-8");

    GridRestCommand cmd = command(req);

    if (cmd == null) {
      res.setStatus(HttpServletResponse.SC_BAD_REQUEST);

      return;
    }

    if (!authChecker.apply(req.getHeader("X-Signature"))) {
      res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

      return;
    }

    GridRestResponse cmdRes;

    Map<String, Object> params = parameters(req);

    try {
      GridRestRequest cmdReq = createRequest(cmd, params, req);

      if (log.isDebugEnabled()) log.debug("Initialized command request: " + cmdReq);

      cmdRes = hnd.handle(cmdReq);

      if (cmdRes == null)
        throw new IllegalStateException("Received null result from handler: " + hnd);

      byte[] sesTok = cmdRes.sessionTokenBytes();

      if (sesTok != null) cmdRes.setSessionToken(U.byteArray2HexString(sesTok));

      res.setStatus(HttpServletResponse.SC_OK);
    } catch (Exception e) {
      res.setStatus(HttpServletResponse.SC_OK);

      U.error(log, "Failed to process HTTP request [action=" + act + ", req=" + req + ']', e);

      cmdRes = new GridRestResponse(STATUS_FAILED, e.getMessage());
    } catch (Throwable e) {
      U.error(log, "Failed to process HTTP request [action=" + act + ", req=" + req + ']', e);

      throw e;
    }

    JsonConfig cfg = new GridJettyJsonConfig();

    // Workaround for not needed transformation of string into JSON object.
    if (cmdRes.getResponse() instanceof String)
      cfg.registerJsonValueProcessor(cmdRes.getClass(), "response", SKIP_STR_VAL_PROC);

    if (cmdRes.getResponse() instanceof GridClientTaskResultBean
        && ((GridClientTaskResultBean) cmdRes.getResponse()).getResult() instanceof String)
      cfg.registerJsonValueProcessor(cmdRes.getResponse().getClass(), "result", SKIP_STR_VAL_PROC);

    JSON json;

    try {
      json = JSONSerializer.toJSON(cmdRes, cfg);
    } catch (JSONException e) {
      U.error(log, "Failed to convert response to JSON: " + cmdRes, e);

      json = JSONSerializer.toJSON(new GridRestResponse(STATUS_FAILED, e.getMessage()), cfg);
    }

    try {
      if (log.isDebugEnabled())
        log.debug("Parsed command response into JSON object: " + json.toString(2));

      res.getWriter().write(json.toString());

      if (log.isDebugEnabled())
        log.debug(
            "Processed HTTP request [action=" + act + ", jsonRes=" + cmdRes + ", req=" + req + ']');
    } catch (IOException e) {
      U.error(log, "Failed to send HTTP response: " + json.toString(2), e);
    }
  }
Exemplo n.º 27
0
 public static JsonConfig configJson() {
   JsonConfig jcf = new JsonConfig();
   jcf.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
   jcf.setExcludes(new String[] {"dlogs"});
   return jcf;
 }
  public JsonUtils() {
    jsonConfig = new JsonConfig();

    jsonConfig.registerJsonValueProcessor(
        DateTime.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
            return new JSONRawString("Timeline.DateTime." + ((DateTime) arg1).toString());
          }
        });
    jsonConfig.registerJsonBeanProcessor(
        JsonConstructor.class,
        new JsonBeanProcessor() {

          public JSONObject processBean(Object arg0, JsonConfig arg1) {
            return (JSONObject)
                arg1.findJsonValueProcessor(JsonConstructor.class)
                    .processObjectValue(null, arg0, arg1);
          }
        });
    jsonConfig.registerJsonValueProcessor(
        JsonConstructor.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            return processObjectValue(null, arg0, arg1);
          }

          public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
            JsonConstructor<?> constructor = (JsonConstructor<?>) arg1;
            return new JSONRawString(
                constructor.getName()
                    + "("
                    + WebUtils.toString(JSONObject.fromObject(constructor.getObject(), arg2))
                    + ")");
          }
        });
    jsonConfig.registerJsonValueProcessor(
        RawString.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
            return new JSONRawString(((RawString) arg1).toString());
          }
        });
    jsonConfig.registerJsonValueProcessor(
        RawString.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
            return new JSONRawString(((RawString) arg1).toString());
          }
        });
    jsonConfig.registerJsonValueProcessor(
        Date.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
            Date date = (Date) arg1;
            String dateString = new SimpleDateFormat("yyyy").format(date);
            String retval = "Timeline.DateTime.parseGregorianDateTime(\"" + dateString + "\")";
            return new JSONRawString(retval);
          }
        });
    jsonConfig.registerJsonValueProcessor(
        Date.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
            Date date = (Date) arg1;
            String dateString = new SimpleDateFormat("yyyy").format(date);
            String retval = "Timeline.DateTime.parseGregorianDateTime(\"" + dateString + "\")";
            return new JSONRawString(retval);
          }
        });
  }
Exemplo n.º 29
0
 static {
   jsonConfig.setExcludes(new String[] {"retweetedStatus"});
   jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
 }
  @Override
  public String getBrandResult(String brand, Date date) {
    Date yesterday = getYesterday(date);

    BrandStatResult bsr = new BrandStatResult();
    BrandResult br = new BrandResult(brand, "", 0);
    br.setBrand(brand);
    br.setDate(yesterday);
    Double lastDayAmount = 0.0;
    List<BrandResult> bcr = this.dataDaoV2.getBrandResultByChannel(yesterday, brand);
    for (BrandResult b : bcr) {
      if (springProperty.isMockValue()) {
        b.setDayAmount(10000L);
      }
      if (b.getChannel().equals(Constants.B2C)) {
        // 统计数据不包括电商的
        continue;
      }
      if (b.getPerDayAmount() != null) {
        lastDayAmount += b.getPerDayAmount();
      }
      if (b.getDayAmount() != null) {
        br.setDayAmount(b.getDayAmount() + br.getDayAmount());
      }
    }
    if (lastDayAmount != 0) {
      br.setDayLike(br.getDayAmount() / lastDayAmount - 1);
    }
    Collections.sort(bcr);
    bsr.setBrand(brand);
    bsr.setResult(0);
    bsr.setBrandResult(br);
    if (!brand.equals(Constants.B2C)) {
      bsr.setChannels(bcr);
    }

    Date firstDayOfThisWeek = getCalendarDate(yesterday, Calendar.WEEK_OF_MONTH);
    // daily line chart
    List<BrandLineChartResult> dailyLineChart =
        this.dataDaoV2.getBrandLineChartDayResult(yesterday, brand, "days", 8);
    bsr.setDailyLineChart(dailyLineChart);
    setLineChartColorAndDateStr(dailyLineChart, brand, Calendar.DAY_OF_MONTH, firstDayOfThisWeek);
    List<BrandLineChartResult> weeklyLineChart =
        this.dataDaoV2.getBrandLineChartDayResult(
            this.getCalendarDate(yesterday, Calendar.WEEK_OF_MONTH), brand, "weeks", 8);
    bsr.setWeeklyLineChart(weeklyLineChart);
    setLineChartColorAndDateStr(weeklyLineChart, brand, Calendar.WEEK_OF_MONTH, null);
    List<BrandLineChartResult> monthLineChart =
        this.dataDaoV2.getBrandLineChartDayResult(
            this.getCalendarDate(yesterday, Calendar.MONTH), brand, "months", 12);
    bsr.setMonthlyLineChart(monthLineChart);
    setLineChartColorAndDateStr(monthLineChart, brand, Calendar.MONTH, null);
    List<BrandLineChartResult> yearLineChart =
        this.dataDaoV2.getBrandLineChartDayResult(
            this.getCalendarDate(yesterday, Calendar.YEAR), brand, "years", 3);
    bsr.setYearlyLineChart(yearLineChart);
    setLineChartColorAndDateStr(yearLineChart, brand, Calendar.YEAR, null);
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
    jsonConfig.registerJsonValueProcessor(Integer.class, new IntegerJsonValueProcessor());
    String result = JSONObject.fromObject(bsr, jsonConfig).toString();
    return result;
  }