package com.tofly.watermeter.config;

import cn.hutool.core.date.DateUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Date;

@Slf4j
@Data
@Component
@Configuration
public class ForeignConfig {

    @Value("${xrty.meter.foreign.url}")
    private String url;


    @Value("${xrty.meter.redisQueue.key}")
    private String queueKey;

    @Value("${xrty.meter.redisQueue.qydkey}")
    private String qyQdKey;

    @Value("${xrty.meter.redisQueue.pop.timeout}")
    private Long popTimeout;

    /**服务名称*/
    @Value("${spring.application.name}")
    private String serviceName;


    /**雪花算法机器编号*/
    private long workerId;

    /**起始时间*/
    private Date date;
    /**
     * nacos 服务信息
     */
    @Autowired
    private DiscoveryClient discoveryClient;
    @PostConstruct
    private void worker(){
        this.workerId = discoveryClient.getInstances(serviceName).size();
        this.date = DateUtil.parse(ComConstans.SNOWFLAKE_BEGIN_TIME);
        log.info("-------------------------------------------->"+workerId);
    }

}
