private void changeMapToPB(
        HashMap<Long, HashMap<String, HashMap<Integer, ActType>>> detailMap,
        Builder mergeValueBuilder) {
      Long time = System.currentTimeMillis() / 1000;

      ArrayList<Long> sortList = new ArrayList<Long>(detailMap.keySet());

      Collections.sort(
          sortList,
          new Comparator<Long>() {
            @Override
            public int compare(Long arg0, Long arg1) {
              if (arg1.longValue() > arg0.longValue()) {
                return 1;
              } else {
                return -1;
              }
            }
          });

      for (Long timeId : sortList) {
        if (timeId < Utils.getDateByTime(time - dataExpireTime)) {
          continue;
        }

        Recommend.UserActiveDetail.TimeSegment.Builder timeBuilder =
            Recommend.UserActiveDetail.TimeSegment.newBuilder();
        timeBuilder.setTimeId(timeId);
        int count = 0;
        for (String item : detailMap.get(timeId).keySet()) {
          count++;
          if (count > topNum) {
            break;
          }

          Recommend.UserActiveDetail.TimeSegment.ItemInfo.Builder itemBuilder =
              Recommend.UserActiveDetail.TimeSegment.ItemInfo.newBuilder();
          itemBuilder.setItem(item);
          float maxWeight = 0;
          for (Integer act : detailMap.get(timeId).get(item).keySet()) {
            ActType actValue = detailMap.get(timeId).get(item).get(act);
            float actWeight = Utils.getActionWeight(actValue.getActType());
            if (actWeight > maxWeight) {
              maxWeight = actWeight;
            }
            itemBuilder.addActs(actValue);
          }
          if (maxWeight > 0) {
            timeBuilder.addItems(itemBuilder);
          }
        }
        mergeValueBuilder.addTsegs(timeBuilder.build());
      }
    }
    private void mergeNewRecordsToMap(
        Long timeId,
        String itemId,
        ActiveRecord activeRecord,
        HashMap<Long, HashMap<String, HashMap<Integer, ActType>>> detailMap) {

      HashMap<String, HashMap<Integer, ActType>> itemMap;
      if (detailMap.containsKey(timeId)) {
        itemMap = detailMap.get(timeId);
      } else {
        itemMap = new HashMap<String, HashMap<Integer, ActType>>();
      }

      HashMap<Integer, ActType> actMap;
      if (itemMap.containsKey(itemId)) {
        actMap = itemMap.get(itemId);
      } else {
        actMap = new HashMap<Integer, ActType>();
      }

      long count = 1L;
      if (actMap.containsKey(activeRecord.getActType())) {
        count = count + actMap.get(activeRecord.getActType()).getCount();
      }
      ActType newActInfo =
          ActType.newBuilder()
              .setActType(activeRecord.getActType())
              .setCount(count)
              .setLastUpdateTime(activeRecord.getActTime())
              .build();

      actMap.put(activeRecord.getActType(), newActInfo);
      itemMap.put(itemId, actMap);
      detailMap.put(timeId, itemMap);
    }
    private void mergeOldToMap(
        UserActiveDetail oldValList,
        HashMap<Long, HashMap<String, HashMap<Integer, ActType>>> detailMap) {
      if (oldValList == null || oldValList.getTsegsCount() <= 0) {
        return;
      }

      for (UserActiveDetail.TimeSegment tsegs : oldValList.getTsegsList()) {
        HashMap<String, HashMap<Integer, ActType>> itemMap;
        if (detailMap.containsKey(tsegs.getTimeId())) {
          itemMap = detailMap.get(tsegs.getTimeId());
        } else {
          itemMap = new HashMap<String, HashMap<Integer, ActType>>();
        }

        for (UserActiveDetail.TimeSegment.ItemInfo item : tsegs.getItemsList()) {
          HashMap<Integer, ActType> actMap;
          if (itemMap.containsKey(item.getItem())) {
            actMap = itemMap.get(item.getItem());
          } else {
            actMap = new HashMap<Integer, ActType>();
          }

          for (UserActiveDetail.TimeSegment.ItemInfo.ActType act : item.getActsList()) {
            Long count = act.getCount();
            if (actMap.containsKey(act.getActType())) {
              count = count + actMap.get(act.getActType()).getCount();
            }
            ActType newActInfo =
                ActType.newBuilder()
                    .setActType(act.getActType())
                    .setCount(count)
                    .setLastUpdateTime(act.getLastUpdateTime())
                    .build();

            actMap.put(act.getActType(), newActInfo);
          }
          itemMap.put(item.getItem(), actMap);
        }
        detailMap.put(tsegs.getTimeId(), itemMap);
      }
    }