예제 #1
0
 public UserStats(String id, String userName, Double distance, Integer time, Double avgSpeed) {
   super(id);
   this.userName = userName;
   this.distance = distance;
   this.time = Util.getDurationString(time);
   this.avgSpeed = avgSpeed;
 }
  @Override
  @Transactional(readOnly = true)
  public List<Weight> result(String imei) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
    cal.set(Calendar.MONTH, Calendar.getInstance().getActualMinimum(Calendar.MONTH));
    cal.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().getActualMinimum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, Calendar.getInstance().getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, Calendar.getInstance().getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, Calendar.getInstance().getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, Calendar.getInstance().getActualMinimum(Calendar.MILLISECOND));

    long time = cal.getTimeInMillis();

    TypedQuery<WeightJpa> query =
        em.createQuery(
                "SELECT w FROM WeightJpa w WHERE w.userId = :imei AND w.timeStamp > :time ORDER BY w.timeStamp ASC",
                WeightJpa.class)
            .setParameter("imei", imei)
            .setParameter("time", time);

    return Util.getFilteredOnePerDayList(JpaUtils.toDomainList(query.getResultList()));
  }