package com.dxhy.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.context.annotation.Configuration;

import com.dxhy.common.constant.RedisConstant;
import com.dxhy.common.util.redis.RedisUtils;

/**
 * @author jiaohongyang
 */
@Configuration
public class MatchNoUtils {
    @Resource
    private RedisUtils redisUtils;

    public String createSerialNum() {
        String result;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        result = sdf.format(new Date());
        Integer cou = redisUtils.get(RedisConstant.MATCH_NO_NUM, Integer.class);
        if (cou == null) {
            cou = 1;
        }
        // 不足8位补0
        String str = String.format("%8d", cou).replace(" ", "0");
        result += str;

        cou++;
        redisUtils.set(RedisConstant.MATCH_NO_NUM, cou, DateOrderUtil.getRemainSecondsOneDay(new Date()));
        return "match_" + result;
    }
}
