RtMallDynamicProperty.java 4.7 KB
package com.diligrp.cashier.mall.property;

import com.diligrp.cashier.mall.exception.RtMartMallException;
import com.diligrp.cashier.mall.type.RtMarkErrorCode;
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 = "rtmall.sign")
public class RtMallDynamicProperty {
    @Value("${domain:}")
    private String domain;

    private List<AppSecretDynamicProperty> appSecrets;

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

        @Value("${orderType:3}")
        private Integer orderType;

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

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

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

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

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

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

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

        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 String getCashierResultUrl() {
            return cashierResultUrl;
        }

        public void setCashierResultUrl(String cashierResultUrl) {
            this.cashierResultUrl = cashierResultUrl;
        }

        public Integer getOrderType() {
            return orderType;
        }

        public void setOrderType(Integer orderType) {
            this.orderType = orderType;
        }

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }

        public String getCompanyCode() {
            return companyCode;
        }

        public void setCompanyCode(String companyCode) {
            this.companyCode = companyCode;
        }

        public String getCallbackDomain() {
            return callbackDomain;
        }

        public void setCallbackDomain(String callbackDomain) {
            this.callbackDomain = callbackDomain;
        }
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    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);
    }

    /**
     * getBySource
     *
     */
    public AppSecretDynamicProperty getBySourceAndType(Integer source, Integer orderType) {
        return Optional.ofNullable(appSecrets)
                .orElse(Collections.emptyList())
                .stream()
                .filter(item -> item.getSource().equals(source) && item.getOrderType().equals(orderType))
                .findFirst()
                .orElseThrow(() -> new RtMartMallException(RtMarkErrorCode.E5002));
    }

    /**
     * getBySource
     *
     */
    public AppSecretDynamicProperty getByAppKey(String appKey) {
        return Optional.ofNullable(appSecrets)
                .orElse(Collections.emptyList())
                .stream()
                .filter(item -> item.getAppKey().equals(appKey))
                .findFirst()
                .orElse(null);
    }
}