예제 #1
0
  /**
   * 根据树节点的ID获取该节点的字节点的数据
   *
   * @param req 请求参数
   * @return
   */
  @RequestMapping(value = "/PositionController!getTreeDataById", method = RequestMethod.GET)
  @ResponseBody
  public String getTreeDataById(HttpServletRequest req) {
    DbContextHolder.clearDbType();
    String path = req.getContextPath();
    String basePath = path + "/";
    String id = req.getParameter("id");
    List<Position> treeDataByCode = null;
    // 检查USER
    Account user = (Account) req.getSession().getAttribute("user");
    if (user.getLevel() != 0) {
      // 市级用户
      if (id.matches("[1-9][0-9][0]{4}")) {
        //
        treeDataByCode = positionService.getPositionByUserid(user.getId().toString());
        for (Position position : treeDataByCode) {
          if (position != null) {
            setIcon(basePath, position);
          }
        }
        List<AccountDistrictRel> adRel = accountService.queryAccountDistrictRel(user);
        for (int i = 0; i < adRel.size(); i++) {
          AccountDistrictRel ar = adRel.get(i);
          Position p = new Position();
          p.setId(ar.getCode());
          p.setLeaf(0);
          p.setLevels(0);
          p.setName(ar.getName());
          p.setExpand(true);
          p.setpId(ar.getParent_code());
          // 看看是省、市、区
          setIcon(basePath, p);
          treeDataByCode.add(p);
        }
        JSONArray treeNodes = new JSONArray();
        treeNodes.addAll(treeDataByCode);
        return treeNodes.toString();
      }
    }

    Map<String, String> arguments = new HashMap<String, String>();
    arguments.put("parent_code", id);
    treeDataByCode = positionService.getAddrTree(arguments);
    for (Position position : treeDataByCode) {
      if (position != null) {
        setIcon(basePath, position);
      }
    }
    JSONArray treeNodes = new JSONArray();
    treeNodes.addAll(treeDataByCode);
    return treeNodes.toString();
  }
예제 #2
0
 /**
  * 获取树的节点数据
  *
  * @param req 请求参数
  * @return
  */
 @RequestMapping(value = "/euTreeData!getTreeData", method = RequestMethod.GET)
 @ResponseBody
 public JSONArray getEasyUiTreeData(HttpServletRequest req) {
   DbContextHolder.clearDbType();
   HashMap<String, String> map = new HashMap<String, String>();
   List<Position> treeDataByCode = new ArrayList<Position>();
   Account user = (Account) req.getSession().getAttribute("user");
   List<AccountDistrictRel> adRel = new ArrayList<AccountDistrictRel>();
   if (user.getParent_userid() == 0) {
     // 管理员查询所有
     map.put("parent_code", "0");
     treeDataByCode = positionService.getAddrTree(map);
     for (Position position : treeDataByCode) {
       if (position != null) {
         if (position.getLeaf() != 2) {
           position.setIsParent(true);
         }
       }
     }
     user.setLevel(-1);
   } else {
     treeDataByCode = positionService.getPositionByUserid(user.getId().toString());
     adRel = accountService.queryAccountDistrictRel(user);
   }
   Map<String, EasyUiTreeData> treeDatas =
       new HashMap<String, PositionController.EasyUiTreeData>();
   List<PositionController.EasyUiTreeData> mp = new ArrayList<PositionController.EasyUiTreeData>();
   for (AccountDistrictRel ad : adRel) {
     EasyUiTreeData data = new EasyUiTreeData();
     data.setText(ad.getName());
     data.setId(ad.getCode());
     Map<String, String> attributes = new HashMap<String, String>();
     attributes.put("level", user.getLevel().toString());
     attributes.put("pid", ad.getParent_code());
     data.setAttributes(attributes);
     treeDatas.put(ad.getCode(), data);
   }
   for (Position position : treeDataByCode) {
     EasyUiTreeData data = new EasyUiTreeData();
     if (position != null) {
       data.setId(position.getId());
       data.setText(position.getName());
       Map<String, String> attributes = new HashMap<String, String>();
       attributes.put("level", String.valueOf((user.getLevel() + 1)));
       attributes.put("pid", position.getpId());
       data.setAttributes(attributes);
       EasyUiTreeData easyUiTreeData = treeDatas.get(position.getpId());
       if (easyUiTreeData != null) {
         easyUiTreeData.getChildren().add(data);
       } else {
         mp.add(data);
       }
       //				mp.add(data);
     }
   }
   mp.addAll(treeDatas.values());
   JSONArray treeNodes = new JSONArray();
   treeNodes.addAll(mp);
   return treeNodes;
 }
예제 #3
0
  private JSONArray getData(List<StatisticsAAContext> dataList) {
    JSONArray dataArr = new JSONArray();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Map<String, JSONObject> map = new HashMap<String, JSONObject>();
    for (StatisticsAAContext sEty : dataList) {
      String statDate = df.format(sEty.getStatisticsTime());
      String key = sEty.getChannelSourceId() + "_" + sEty.getStatisticsClass();
      JSONObject aDataObj = map.get(key);
      if (aDataObj == null) {
        aDataObj = new JSONObject();
        map.put(key, aDataObj);
      }

      aDataObj.put("channelName", sEty.getChannelName());
      aDataObj.put("channelSourceId", sEty.getChannelSourceId());
      aDataObj.put("statisticsClass", sEty.getStatisticsClass());
      aDataObj.put("brandImpression_" + statDate, sEty.getBrandImpression());
      aDataObj.put("brandClick_" + statDate, sEty.getBrandClick());
      aDataObj.put("aaDisplayCount_" + statDate, sEty.getAaDisplayCount());
      aDataObj.put("aaClick_" + statDate, sEty.getAaClick());
      aDataObj.put("aaTest_" + statDate, sEty.getAaTest());
      aDataObj.put("vv_" + statDate, sEty.getVv());
      aDataObj.put("cv_" + statDate, sEty.getCv());
      aDataObj.put("normalOverCount_" + statDate, sEty.getNormalOverCount());
      aDataObj.put("suspendCount_" + statDate, sEty.getSuspendCount());
      aDataObj.put("statisticsTime_" + statDate, sEty.getStatisticsTime());
    }

    dataArr.addAll(map.values());
    return dataArr;
  }
예제 #4
0
 /**
  * 获取树的节点数据
  *
  * @param req 请求参数
  * @return
  */
 @RequestMapping(value = "/PositionController!getTreeData", method = RequestMethod.GET)
 @ResponseBody
 public String getTreeData(HttpServletRequest req) {
   DbContextHolder.clearDbType();
   HashMap<String, String> map = new HashMap<String, String>();
   List<Position> treeDataByCode = new ArrayList<Position>();
   String path = req.getContextPath();
   String basePath = path + "/";
   String uid = req.getParameter("userid");
   // 通过用户取
   Account acc = (Account) req.getSession().getAttribute("user");
   if (uid != null && !"".equals(uid)) {
     HashMap<String, Object> args = new HashMap<String, Object>();
     args.put("id", uid);
     List<Account> accounts = accountService.getAccount(args);
     if (accounts != null && accounts.size() > 0) {
       acc = accounts.get(0);
     }
   }
   if ((acc.getParent_userid() == null || acc.getParent_userid() == 0)) {
     map.put("parent_code", "0");
     treeDataByCode = positionService.getAddrTree(map);
     for (Position position : treeDataByCode) {
       if (position != null) {
         // 看看是省、市、区
         setIcon(basePath, position);
       }
     }
   } else {
     treeDataByCode = positionService.getPositionByUserid(acc.getId().toString());
     for (Position position : treeDataByCode) {
       if (position != null) {
         setIcon(basePath, position);
       }
     }
     List<AccountDistrictRel> adRel = accountService.queryAccountDistrictRel(acc);
     for (int i = 0; i < adRel.size(); i++) {
       AccountDistrictRel ar = adRel.get(i);
       Position p = new Position();
       p.setId(ar.getCode());
       p.setLeaf(0);
       p.setLevels(0);
       p.setName(ar.getName());
       p.setExpand(true);
       p.setpId(ar.getParent_code());
       // 看看是省、市、区
       setIcon(basePath, p);
       treeDataByCode.add(p);
     }
   }
   JSONArray treeNodes = new JSONArray();
   treeNodes.addAll(treeDataByCode);
   return treeNodes.toString();
 }
 private static JSONArray createGraphDatasets(Map<String, ArrayList<Number>> datasets) {
   JSONArray graphSeries = new JSONArray();
   for (Map.Entry<String, ArrayList<Number>> transactionData : datasets.entrySet()) {
     JSONObject dataset = new JSONObject();
     dataset.put("name", transactionData.getKey());
     JSONArray data = new JSONArray();
     data.addAll(transactionData.getValue());
     dataset.put("data", data);
     graphSeries.add(dataset);
   }
   return graphSeries;
 }
예제 #6
0
 public void showRequestList(RequestVO request) throws SeeWorldException {
   String reciever_id = request.getReciever_id();
   User reciever = userDao.findById(reciever_id);
   List<Request> list =
       requestDao.findByProperty(
           "from Request as model where model.reciever=? order by model.addTime desc", reciever);
   requestSum = list.size();
   if (requestSum > 0) {
     requestList = new JSONArray();
     requestList.addAll(vOPOTransformator.transferRequestToVOList(list));
   }
 }
예제 #7
0
 @RequestMapping(params = "method=page")
 @ResponseBody // 异步
 public Object page() {
   JSONArray json = null;
   try {
     List<User> users = this.userManager.findForPageList();
     json = new JSONArray();
     json.addAll(users);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return json;
 }
예제 #8
0
  public void search() {
    try {
      JSONObject retObj = new JSONObject();
      retObj.put("action", true);

      StatisticsAAContextForm sf =
          (StatisticsAAContextForm)
              EntityReflect.createObjectFromRequest(
                  ServletActionContext.getRequest(), StatisticsAAContextForm.class);
      List<StatisticsAAContext> dataList = statisticsAAContextDao.statistSearch(sf);
      retObj.put("size", dataList.size());

      JSONArray columModleArray = new JSONArray();
      JSONArray topGroup = new JSONArray();
      JSONArray secondGroup = new JSONArray();

      JSONObject jobj = new JSONObject();
      jobj.put("header", "");
      jobj.put("colspan", 2);
      jobj.put("align", "center");
      topGroup.add(jobj);
      secondGroup.add(jobj);

      JSONArray dayColumArr = createDayColum(dataList, topGroup, secondGroup);
      columModleArray.addAll(GridColumModleInfo);
      columModleArray.addAll(dayColumArr);

      retObj.put("columns", columModleArray);
      retObj.put("topGroup", topGroup);
      retObj.put("secondGroup", secondGroup);
      retObj.put("data", getData(dataList));
      retObj.put("fields", getFieldsNamesArray(dataList));

      AjaxOut.responseText(ServletActionContext.getResponse(), retObj.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #9
0
 public void gotoPage(RequestVO request, Integer requestSum, Integer currentPage)
     throws SeeWorldException {
   String reciever_id = request.getReciever_id();
   Pagination pager = new Pagination();
   pager.setLen(requestSum);
   pager.setPagesize(settingLogic.getIntConfigValue(Constant.REQUESTS_PER_PAGE));
   pager.setCurrentpage(currentPage);
   pager.setPagelist();
   String hql =
       "from Request as model where model.reciever='"
           + reciever_id
           + "' order by model.addTime desc";
   List<Request> allRequest = requestDao.getListByPage(hql, pager.getStart(), pager.getPagesize());
   requestList = new JSONArray();
   requestList.addAll(vOPOTransformator.transferRequestToVOList(allRequest));
   PageJson = JSONObject.fromObject(pager);
 }
예제 #10
0
  /**
   * Throttled controller that executes php function via rest http request, sends list invitation
   * emails to a given list. Executed by jsp job handler
   */
  @Override
  public void execute(JobExecutionContext context) throws JobExecutionException {
    sentLog = new JSONArray();
    JSONArray contactListSent;
    String rawJSONArray;
    int limit = 100;
    int offset = 0;
    int pageCounter = 1;
    int increment = limit;
    ;

    JobDataMap dataMap = context.getJobDetail().getJobDataMap();
    taskID = dataMap.getString("taskID");

    String userID = dataMap.getString("userid");

    String contactListID = dataMap.getString("contactListID");

    String contactListLink =
        Constants.DATABASE_BASE_URL + "/" + Constants.DATABASE_CONTACT_LISTS + "/" + contactListID;

    try {
      CouchUtilities.setTaskAsOpen(taskID);
      // System.out.println("uid: " + userID + " clid: " + contactListID);
      Thread.sleep(1000);
      int contactCount = CouchUtilities.getContactCountForContactList(userID, contactListID);

      double totalPages = Math.ceil((double) contactCount / (double) limit);
      // Set the contact list status as running
      JSONObject taskinfo = CouchUtilities.getTaskInfo(taskID);
      do {
        contactListSent = new JSONArray();
        rawJSONArray = new String();
        taskinfo.put("offset", offset);
        taskinfo.put("limit", limit);
        // CouchUtilities.setContactListRunningStatus(true, contactListLink);

        // Set the task status as in progress in task.json

        String strTaskInfo = taskinfo.toString();
        // System.out.println("TaskINFO: " + strTaskInfo);
        String URL =
            UpdentityConstants.REST_URL
                + "?action=send_optin_emails&uid="
                + userID
                + "&clid="
                + contactListID;
        CouchConnect request = new CouchConnect(URL);
        // EXECUTE BULK SEND
        try {
          Thread.sleep(250); // wait 1/4 of a sec for added stability
          rawJSONArray = request.post(strTaskInfo);

          /* debug code for dev
           *
          File file1 = new File("/usr/share/nginx/www/log/optin_java.log");
          FileWriter writer1;
          writer1 = new FileWriter(file1, true);
             PrintWriter printer1 = new PrintWriter(writer1);
             printer1.append("Pass "+pageCounter+"\n");
             printer1.close();*/
        } catch (Exception e) {
          try {
            // localhost// File file = new
            // File("/home/samuel/workspace/tmp/optin_java_exception.log");
            // Beta// File file = new File("/usr/share/nginx/www/log/optin_java_exception.log");
            File file = new File("/usr/share/nginx/log/optin_java_exception.log"); // enterprise
            FileWriter writer;
            writer = new FileWriter(file, true);
            PrintWriter printer = new PrintWriter(writer);
            printer.append(e.getMessage() + "\n StackTrace:\n" + e.getStackTrace() + "\n---------");
            printer.close();
            Thread.sleep(3000);
            rawJSONArray = request.post(strTaskInfo);
            contactListSent.add(rawJSONArray);
          } catch (Exception e1) {
            logger.error(ExceptionUtils.getStackTrace(e1));
          }
        }

        offset += increment;
        limit += increment;
        pageCounter += 1;
        contactListSent.add(rawJSONArray);

        sentLog.addAll(contactListSent.getJSONArray(0));

      } while (pageCounter <= totalPages);
      // System.out.println("threads: " + (pageCounter - 1));

      taskinfo.put("log", sentLog);
      saveSentLogToTask(taskinfo);

      CouchUtilities.setTaskAsClosed(taskID);
      String UserInfoURL = UpdentityConstants.REST_URL + "?action=get_user&uid=" + userID;
      CouchConnect userRequest = new CouchConnect(UserInfoURL);

      JSONObject userData = JSONObject.fromObject(userRequest.get());

      // System.out.println(userData);
      String user_nicename =
          userData.getString("first_name") + " " + userData.getString("last_name");
      String title = "Opt-in messages sent";

      String txtMessage =
          "Hi, " + user_nicename + ",\n\n Your opt-in email task has finished running!\n\n";

      String message = "<p>Hi " + user_nicename + ",</p>\n";
      message +=
          "<h3 style='color:#707070;margin:20px 0px 20px 0px'>Your opt-in email task has finished running!</h3>";

      UserDao.sendEmailNotification(
          userID,
          "Your opt-in invites have been sent!",
          txtMessage,
          EmailTemplates.getStandardTemplate(title, message),
          UpdentityUtil.isProductionServer());
    } catch (MalformedURLException e) {
      try {
        CouchUtilities.setTaskAsFailed(taskID);
      } catch (IOException e1) {
        e1.printStackTrace();
      } catch (JSONException e1) {
        e1.printStackTrace();
      }
      e.printStackTrace();
    } catch (IOException e) {
      try {
        CouchUtilities.setTaskAsFailed(taskID);
      } catch (IOException e1) {
        e1.printStackTrace();
      } catch (JSONException e1) {
        e1.printStackTrace();
      }
      e.printStackTrace();
    } catch (Exception e) {
      try {
        CouchUtilities.setTaskAsFailed(taskID);
      } catch (IOException e1) {
        e1.printStackTrace();
      } catch (JSONException e1) {
        e1.printStackTrace();
      }
      e.printStackTrace();
    } finally {
      try {
        // Set the contact list status as not running
        CouchUtilities.removeTaskFromContactListQueue(taskID, contactListLink);

        // Suggest garbage collection
        Utilities.collectGarbage();

        // Get the next task in queue, if any
        taskID = SchedularUtilities.getNextTaskInQueue(contactListID);

        if (!taskID.equals("")) {
          SchedularUtilities schedulerUtils = new SchedularUtilities();
          schedulerUtils.defineJob(taskID);
        }
      } catch (IOException e) {
        e.printStackTrace();
      } catch (InterruptedException e) {
        e.printStackTrace();
      } catch (SchedulerException e) {
        e.printStackTrace();
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
  }
예제 #11
0
  private JSONArray createDayColum(
      List<StatisticsAAContext> dataList, JSONArray TopGroup, JSONArray secondGroup) {

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    JSONArray dayColumArr = new JSONArray();

    Map<String, String> map = new HashMap<String, String>();

    for (StatisticsAAContext sEty : dataList) {
      String statDate = df.format(sEty.getStatisticsTime());

      // 头不能重复
      if (map.containsKey(statDate)) continue;
      map.put(statDate, statDate);

      StringBuffer sb = new StringBuffer();
      sb.append("[");
      sb.append(
          "{header :'曝光', dataIndex:'brandImpression_"
              + statDate
              + "', sortable:false, menuDisabled:true, align:'center'},");
      sb.append(
          "{header :'点击', dataIndex:'brandClick_"
              + statDate
              + "', sortable:false, menuDisabled:true, align:'center'},");
      sb.append(
          "{header :'AA-展示量', dataIndex:'aaDisplayCount_"
              + statDate
              + "', sortable:false, menuDisabled:true, align:'center'},");
      sb.append(
          "{header :'点击', dataIndex:'aaClick_"
              + statDate
              + "', sortable:false, menuDisabled:true, align:'center'},");
      sb.append(
          "{header :'测试', dataIndex:'aaTest_"
              + statDate
              + "', sortable:false, menuDisabled:true, align:'center'},");
      sb.append(
          "{header :'VV', dataIndex:'vv_"
              + statDate
              + "', sortable:false, menuDisabled:true, align:'center'},");
      sb.append(
          "{header :'CV', dataIndex:'cv_"
              + statDate
              + "', sortable:false, menuDisabled:true, align:'center'},");
      sb.append(
          "{header :'正常结束', dataIndex:'normalOverCount_"
              + statDate
              + "', sortable:false, menuDisabled:true, align:'center'},");
      sb.append(
          "{header :'暂停次数', dataIndex:'suspendCount_"
              + statDate
              + "', sortable:false, menuDisabled:true, align:'center'}");
      sb.append("]");

      JSONArray adayArr = JSONArray.fromObject(sb.toString());
      dayColumArr.addAll(adayArr);

      JSONObject jobj = new JSONObject();
      jobj.put("header", statDate);
      jobj.put("colspan", 9);
      jobj.put("align", "center");
      TopGroup.add(jobj);

      jobj = new JSONObject();
      jobj.put("header", "品牌");
      jobj.put("colspan", 2);
      jobj.put("align", "center");
      secondGroup.add(jobj);

      jobj = new JSONObject();
      jobj.put("header", "AA");
      jobj.put("colspan", 3);
      jobj.put("align", "center");
      secondGroup.add(jobj);

      jobj = new JSONObject();
      jobj.put("header", "播放量");
      jobj.put("colspan", 4);
      jobj.put("align", "center");
      secondGroup.add(jobj);
    }

    return dayColumArr;
  }