update:
编码生成redis设置key有效期为当天,次日凌晨失效重新开始计数
This commit is contained in:
		@@ -11,10 +11,8 @@ import org.springframework.stereotype.Component;
 | 
			
		||||
import javax.annotation.PostConstruct;
 | 
			
		||||
import java.text.DecimalFormat;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * id生成器,使用redis自增接口实现
 | 
			
		||||
@@ -153,6 +151,12 @@ public class IDGenerator {
 | 
			
		||||
        }
 | 
			
		||||
        if (!isEmpty(sequenceName)) {
 | 
			
		||||
            long sequence = gen(sequenceName);
 | 
			
		||||
            //设置key有效期为当天,次日凌晨失效
 | 
			
		||||
            Calendar curDate = Calendar.getInstance();
 | 
			
		||||
            Calendar tomorrowDate = new GregorianCalendar(curDate.get(Calendar.YEAR), curDate.get(Calendar.MONTH), curDate.get(Calendar.DATE) + 1, 0, 0, 0);
 | 
			
		||||
            int second = (int)(tomorrowDate.getTimeInMillis() - curDate.getTimeInMillis()) / 1000;
 | 
			
		||||
            idGenerator.redisTemplate.opsForValue().set(KEY_PREFIX_SEQUENCE + sequenceName, sequence, second, TimeUnit.SECONDS);
 | 
			
		||||
            idGenerator.redisTemplate.opsForValue().getOperations();
 | 
			
		||||
            if (sequenceLength > 0) {
 | 
			
		||||
                if (sequenceLength > MAX_SEQUENCE_LENGTH) {
 | 
			
		||||
                    sequenceLength = MAX_SEQUENCE_LENGTH;
 | 
			
		||||
 
 | 
			
		||||
@@ -1221,7 +1221,7 @@ public class AsynRunTaskService extends BaseService {
 | 
			
		||||
                currTask.setStoveCode(stoveCode);
 | 
			
		||||
                currTaskServiceBiz.updateById(currTask);
 | 
			
		||||
            }else {
 | 
			
		||||
                logger.info(currTask.getId()+"任务为多步骤任务且第一步为清洗,不生产清洗炉炉号.");
 | 
			
		||||
                logger.info(currTask.getId()+"任务为多步骤任务且第一步为清洗,不生成洗炉炉号.");
 | 
			
		||||
            }
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user