package com.mydreamjob.salarycalculator; import jakarta.annotation.PostConstruct; import java.util.LinkedHashMap; import java.util.Map; import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; /** 发布白名单为空时失败关闭;enabled/dataLevel 不表示政策已核验。 */ @Getter @Setter @Component @ConfigurationProperties(prefix = "app.salary-publication") public class SalaryPolicyPublicationProperties { private Map approvedPolicies = new LinkedHashMap<>(); @PostConstruct void validate() { if (approvedPolicies == null || approvedPolicies.entrySet().stream().anyMatch(entry -> entry.getKey() == null || !entry.getKey().matches("[0-9]{6}") || entry.getValue() == null || entry.getValue().isBlank() || !entry.getValue().equals(entry.getValue().trim()))) { throw new IllegalStateException("invalid salary publication allowlist"); } } public boolean isPublished(String cityCode, String policyVersion) { return cityCode != null && policyVersion != null && approvedPolicies != null && policyVersion.equals(approvedPolicies.get(cityCode)); } }