/**
   * 微学习 学员统计
   *
   * @author longjl
   */
  public void queryStudentStat() {
    System.out.println("-------------------------------------");
    try {
      // 昨天的时间
      String searchDate = DateUtil.addDays2(DateUtil.formatDate(new Date(), "yyyy-MM-dd"), -1);

      // String searchDate = getServletRequest().getParameter("date");
      // 来源 Integer[] froms = {1,2,3,4};
      Integer[] froms = queryFroms();
      if (froms == null || froms.length == 0) {
        return;
      }

      // 初始化
      queryEntranceCondition = new QueryEntranceCondition();
      // 初始化
      queryUserUseCondition = new QueryUserUseCondition();
      // 初始化
      queryUserStatLogCondition = getQueryUserStatLogCondition();

      // 注册/登录统计条件 2
      List<StudentStatDTO> registerList2 = new ArrayList<StudentStatDTO>();
      // 注册/登录统计条件 4
      List<StudentStatDTO> LoginList4 = new ArrayList<StudentStatDTO>();
      // 注册 登录的总人数
      List<StudentStatDTO> regLoginList24 = new ArrayList<StudentStatDTO>();

      for (Integer fs : froms) { // 循环来源
        // 页面流量统计条件
        queryEntranceCondition.setFromId(fs);
        queryEntranceCondition.setPubDate(searchDate);
        int pageFlowCount = studentStatService.getPageFlowCount(queryEntranceCondition);

        // 注册/登录统计条件
        queryUserUseCondition.setFromId(fs);
        queryUserUseCondition.setPubDate(searchDate);
        regLoginList24 = studentStatService.getStudentUseCount(queryUserUseCondition); // 注册 登录的总人数
        registerList2 = studentStatService.queryStudentUseRegister(queryUserUseCondition); // 注册人数
        LoginList4 = studentStatService.queryStudentUseLogin(queryUserUseCondition); // 登录人数

        studentStat = new StudentStat();
        studentStat.setFromId(fs); // 来源id
        studentStat.setPageFlow(pageFlowCount); // 页流量
        if (registerList2 != null && registerList2.size() > 0) {
          // registerCount 赋值
          studentStat.setRegisterCount(registerList2.size()); // 注册人数

          String registerIds = "";
          for (StudentStatDTO so : registerList2) {
            registerIds += so.getCusId() + ",";
          }
          // registerids 赋值
          studentStat.setRegisterIds(registerIds); // 注册用户id
        } else {
          studentStat.setRegisterCount(0);
          studentStat.setRegisterIds("");
        }

        if (LoginList4 != null && LoginList4.size() > 0) {
          studentStat.setLoginCount(LoginList4.size()); // 登录人数
          String LoginIds = "";
          for (StudentStatDTO so : LoginList4) {
            LoginIds += so.getCusId() + ",";
          }
          studentStat.setLoginIds(LoginIds);
        } else {
          studentStat.setLoginCount(0);
          studentStat.setLoginIds("");
        }

        // 订单用户
        String orderCusIds = "";

        // 跳出人数
        int outCount = pageFlowCount - (regLoginList24.size());
        studentStat.setOutCount(outCount);

        // 首次用户 非重复用户   重复用户 条件
        queryUserStatLogCondition.setFromId(fs);
        queryUserStatLogCondition.setPubDate(searchDate);

        // 到达微学习页的数量
        if (regLoginList24 != null && regLoginList24.size() > 0) {
          studentStat.setArriveWxxCount(regLoginList24.size());
          orderCusIds = getOrderCusIds(regLoginList24);
          studentStat.setArriveWxxIds(orderCusIds);
        } else {
          studentStat.setArriveWxxCount(0);
          orderCusIds = getOrderCusIds(regLoginList24);
          studentStat.setArriveWxxIds(orderCusIds);
        }

        Map<String, Object> cusIdsMap = new HashMap<String, Object>();
        if (regLoginList24 != null && regLoginList24.size() > 0) {
          cusIdsMap.put("idsMap", regLoginList24);
        }
        cusIdsMap.put("fromIds", fs);
        cusIdsMap.put("pubDate", searchDate);
        // 首次用户数
        List<StudentStatDTO> firstUserCusIdList = studentStatService.getFirstUserCount(cusIdsMap);
        // 非重复用户 数
        List<StudentStatDTO> nonRepeatUserCusIdList =
            studentStatService.getNonRepeatUserCount(cusIdsMap);
        // 重复用户数
        List<StudentStatDTO> repeatUserCusIdList = studentStatService.getRepeatUserCount(cusIdsMap);

        // 首次用户
        studentStat.setFirstUserCount(firstUserCusIdList.size());
        if (firstUserCusIdList != null && firstUserCusIdList.size() > 0) {
          String firstUserIds = "";
          for (StudentStatDTO so : firstUserCusIdList) {
            firstUserIds += so.getCusId() + ",";
          }
          studentStat.setFirstUserIds(firstUserIds);
        } else {
          studentStat.setFirstUserIds("");
        }
        // 不重复用户
        studentStat.setNonRepeatUserCount(nonRepeatUserCusIdList.size());
        if (nonRepeatUserCusIdList != null && nonRepeatUserCusIdList.size() > 0) {
          String nonRepeatUserIds = "";
          for (StudentStatDTO so : nonRepeatUserCusIdList) {
            nonRepeatUserIds += so.getCusId() + ",";
          }
          studentStat.setNonRepeatUserIds(nonRepeatUserIds);
        } else {
          studentStat.setNonRepeatUserIds("");
        }
        // 重复用户
        studentStat.setRepeatUserCount(repeatUserCusIdList.size());
        if (repeatUserCusIdList != null && repeatUserCusIdList.size() > 0) {
          String repeatUserIds = "";
          for (StudentStatDTO so : repeatUserCusIdList) {
            repeatUserIds += so.getCusId() + ",";
          }
          studentStat.setRepeatUserIds(repeatUserIds);
        } else {
          studentStat.setRepeatUserIds("");
        }

        // 订单数量
        int orderCount = studentStatService.queryOrderCount(cusIdsMap);
        studentStat.setOrderCount(orderCount);
        studentStat.setOrderIds(orderCusIds);

        if (cusIdsMap != null && !cusIdsMap.isEmpty()) {
          // 订单流水
          String money = studentStatService.getBringWater(cusIdsMap);
          if (money != null && money.length() > 0) {
            studentStat.setRunningWaterCount(Double.parseDouble(money)); // 钱
          } else {
            studentStat.setRunningWaterCount(0.0); // 钱
          }
        } else {
          studentStat.setRunningWaterCount(0.0); // 钱
        }
        studentStat.setSearchDate(searchDate); // 查询日期,表示,这条记录查询的时间点
        studentStat.setCreateTime(new Date());

        // 插入微学习 学员统计表
        studentStatService.addStudentStat(studentStat);
      }
    } catch (Exception e) {
      logger.error("糟糕!程序错误--->", e);
    }
  }