package org.xmx0632.deliciousfruit.service;
import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.xmx0632.deliciousfruit.utilities.date.DateUtil;
//Spring Bean的标识.
@Component
public class TransactionIDService {
private static Logger log = LoggerFactory
.getLogger(TransactionIDService.class);
private AtomicLong index = new AtomicLong(0);
private String pattern = "yyyy-MM-dd HH";
@Autowired
private DateUtil dateUtil;
public String getTransactionId() {
Date currentTime = dateUtil.getCurrentDate(pattern);
long time = currentTime.getTime();
String transactionId = "" + time + index.getAndIncrement();
log.debug("transactionId:{}", transactionId);
return transactionId;
}
}