@SuppressWarnings("unchecked")
 @Override
 public String execute() throws Exception {
   String callbackFunction = (String) getParamName("callback");
   String user_name = (String) getParamName("user_name"); // 用户名称
   String type = (String) getParamName("type"); // 页面类型1:到达率
   String bgDate = (String) getParamName("bgDate"); // 开始时间
   String endDate = (String) getParamName("endDate"); // 结束时间
   String searchSource = (String) getParamName("searchSource"); // 查询来源
   Map param = new HashMap();
   param.put("user_name", user_name);
   param.put("type", type);
   param.put("bgDate", bgDate);
   param.put("endDate", endDate);
   param.put("searchSource", searchSource);
   Connection con = null;
   con = C3P0Utils.getConnection();
   ExecuteSql excuteSql = new ExecuteSql(con);
   Map result = new HashMap();
   // http://localhost:8082/iptv/cntv/getSearchDataByArea.jsonp?callback=?&user_name=admin&type=1&bgDate=2014-10-22&endDate=2014-10-23&searchSource=DaodaArea
   try {
     String channelSql = createQuerySql(param);
     String checkedChannel = excuteSql.executeSqlAsHashMapClobGetTure(channelSql);
     if (checkedChannel != null && !"".equals(checkedChannel)) {
       checkedChannel = checkedChannel.substring(0, checkedChannel.length() - 1);
       param.put("checkedChannel", checkedChannel);
       String dataSql = createQuerySqlData(param);
       Map map = excuteSql.executeSqlAsHashMapClobGetArea(dataSql, param);
       result.put(param.get("searchSource"), map);
     } else {
       Map map = new HashMap();
       map.put("name", "false");
       result.put(param.get("searchSource"), map); // 没有进行频道设置时,返回false
     }
     Converter<Map> converterJsonpStrategy = null;
     if (dataType.equals("jsonp")) {
       converterJsonpStrategy = new ConverterJsonp<Map>();
     } else if (dataType.equals("json")) {
       converterJsonpStrategy = new ConverterJson<Map>();
     }
     ConverterContext<Map> context = new ConverterContext<Map>(converterJsonpStrategy);
     String runConverter = context.runConverter(result);
     build(runConverter);
     log.info("数据:" + runConverter);
   } catch (Exception e) {
     log.error("获取数据失败");
     e.printStackTrace();
   } finally {
     C3P0Utils.closeConnection();
   }
   return null;
 }
示例#2
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Connection con = null;
    try {
      con = C3P0Utils.getConnection();
      ExecuteSql excuteSql = new ExecuteSql(con);
      String sql = "select * from userdailycount order by date asc";
      ResultSet rs = excuteSql.executeSql(sql);
      String date = "";
      String nowDate = "";
      List<String> list = new ArrayList<String>();
      if (rs.next()) {
        date = rs.getString(2);
        nowDate = DailyUserCountData.nextDay(rs.getString(2));
        list.add(rs.getString(3));
      }
      while (rs.next()) {
        while (!rs.getString(2).equals(nowDate)) {

          nowDate = DailyUserCountData.nextDay(nowDate);
          list.add("0");
        }
        list.add(rs.getString(3));
        nowDate = DailyUserCountData.nextDay(nowDate);
      }

      System.out.println(list);
      System.out.println(date);
      response.setContentType("text;html;charset=utf-8");
      ServletOutputStream out = response.getOutputStream();
      JSONObject json = new JSONObject();
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
      long time = format.parse(date).getTime();
      json.put("data", list);
      json.put("date", time);
      out.print(json.toString());
      out.flush();
      out.close();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      C3P0Utils.closeConnection();
    }
  }