MallDynamicProperty.java 2.24 KB
package com.diligrp.cashier.mall.property;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @author dengwei
 * @version 1.0.0
 * @ClassName MallDynamicProperty.java
 * @Description MallDynamicProperty
 */
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "sign")
public class MallDynamicProperty {

    private List<AppSecretDynamicProperty> appSecrets;

    public static class AppSecretDynamicProperty {
        @Value("${source:1}")
        private Integer source;

        @Value("${appKey:}")
        private String appKey;

        @Value("${appSecret:}")
        private String appSecret;

        @Value("${authUrl:https://hourh5-em-shop.feiniugo.com}")
        private String authUrl;

        public Integer getSource() {
            return source;
        }

        public void setSource(Integer source) {
            this.source = source;
        }

        public String getAppKey() {
            return appKey;
        }

        public void setAppKey(String appKey) {
            this.appKey = appKey;
        }

        public String getAppSecret() {
            return appSecret;
        }

        public void setAppSecret(String appSecret) {
            this.appSecret = appSecret;
        }

        public String getAuthUrl() {
            return authUrl;
        }

        public void setAuthUrl(String authUrl) {
            this.authUrl = authUrl;
        }
    }

    public List<AppSecretDynamicProperty> getAppSecrets() {
        return appSecrets;
    }

    public void setAppSecrets(List<AppSecretDynamicProperty> appSecrets) {
        this.appSecrets = appSecrets;
    }

    /**
     * getBySource
     *
     */
    public AppSecretDynamicProperty getBySource(Integer source) {
        return Optional.ofNullable(appSecrets)
                .orElse(Collections.emptyList())
                .stream()
                .filter(item -> item.getSource().equals(source))
                .findFirst()
                .orElse(null);
    }
}