SpeedStatService.java
947 Bytes
package com.viontech.keliu.service;
import com.viontech.keliu.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class SpeedStatService {
@Autowired
private RedisTemplate redisTemplate;
public void stat(String key, long number) {
try {
LocalDateTime now = LocalDateTime.now();
key = key + ":" + DateUtil.formatYYYYMMDD(now);
String field = DateUtil.formatYYYYMMDDHHMM(now);
redisTemplate.opsForHash().increment(key, field, number);
redisTemplate.expire(key, 15L, TimeUnit.DAYS);
} catch (Exception e) {
log.error("统计处理速度异常:{}", e.getMessage(), e);
}
}
}