33import dev .vality .alerting .mayday .alerttemplate .dao .DawayDao ;
44import dev .vality .alerting .mayday .alerttemplate .model .alerttemplate .DictionaryType ;
55import dev .vality .alerting .mayday .alerttemplate .model .daway .*;
6+ import dev .vality .alerting .mayday .alerttemplate .model .dictionary .DictionaryData ;
67import lombok .RequiredArgsConstructor ;
78import lombok .extern .slf4j .Slf4j ;
89import org .springframework .stereotype .Service ;
@@ -19,7 +20,7 @@ public class DictionaryService {
1920
2021 private final DawayDao dawayDao ;
2122
22- public Map <String , String > getDictionary (DictionaryType type ) {
23+ public Map <String , DictionaryData > getDictionary (DictionaryType type ) {
2324 return switch (type ) {
2425 case TERMINALS -> convertTerminalsToDictionary (dawayDao .getAllTerminals ());
2526 case PAYMENT_TERMINALS -> convertTerminalsToDictionary (dawayDao .getPaymentTerminals ());
@@ -30,50 +31,64 @@ public Map<String, String> getDictionary(DictionaryType type) {
3031 case WALLETS -> convertWalletsToDictionary (dawayDao .getWallets ());
3132 case SHOPS -> convertShopsToDictionary (dawayDao .getShops ());
3233 case CURRENCIES -> convertCurrenciesToDictionary (dawayDao .getCurrencies ());
33- case PAYMENT_LIMIT_SCOPES -> Map .of ("Провайдер" , "provider" ,
34- "Провайдер + терминал" , "provider,terminal" ,
35- "Провайдер + терминал + магазин" , "provider,shop,terminal" ,
36- "Терминал" , "terminal" ,
37- "Магазин" , "shop" );
38- case PAYOUT_LIMIT_SCOPES -> Map .of ("Провайдер" , "provider" ,
39- "Провайдер + терминал" , "provider,terminal" ,
40- "Провайдер + терминал + кошелек" , "provider,terminal,wallet" ,
41- "Терминал" , "terminal" ,
42- "Кошелёк" , "wallet" );
43- case CONDITIONAL_BOUNDARIES -> Map .of ("Больше порогового значения" , ">" , "Меньше порогового значения" , "<" );
44- case TIME_INTERVAL_BOUNDARIES -> Map .of ("Да" , "unless" , "Нет" , "and" );
45- case AGGREGATION_INTERVALS -> Map .of ("5 минут" , "5m" , "15 минут" , "15m" , "30 минут" , "30m" ,
46- "1 час" , "1h" , "3 часа" , "3h" , "6 часов" , "6h" , "12 часов" , "12h" , "24 часа" , "24h" , "Текущий " +
47- "календарный день (MSK)" , "today_msk" );
34+ case PAYMENT_LIMIT_SCOPES -> Map .of (
35+ "Провайдер" , new DictionaryData ("provider" ),
36+ "Провайдер + терминал" , new DictionaryData ("provider,terminal" ),
37+ "Провайдер + терминал + магазин" , new DictionaryData ("provider,shop,terminal" ),
38+ "Терминал" , new DictionaryData ("terminal" ),
39+ "Магазин" , new DictionaryData ("shop" )
40+ );
41+ case PAYOUT_LIMIT_SCOPES -> Map .of (
42+ "Провайдер" , new DictionaryData ("provider" ),
43+ "Провайдер + терминал" , new DictionaryData ("provider,terminal" ),
44+ "Провайдер + терминал + кошелек" , new DictionaryData ("provider,terminal,wallet" ),
45+ "Терминал" , new DictionaryData ("terminal" ),
46+ "Кошелёк" , new DictionaryData ("wallet" )
47+ );
48+ case CONDITIONAL_BOUNDARIES -> Map .of (
49+ "Больше порогового значения" , new DictionaryData (">" ),
50+ "Меньше порогового значения" , new DictionaryData ("<" )
51+ );
52+ case TIME_INTERVAL_BOUNDARIES -> Map .of (
53+ "Да" , new DictionaryData ("unless" ),
54+ "Нет" , new DictionaryData ("and" )
55+ );
56+ case AGGREGATION_INTERVALS -> Map .of (
57+ "5 минут" , new DictionaryData ("5m" ),
58+ "15 минут" , new DictionaryData ("15m" ),
59+ "30 минут" , new DictionaryData ("30m" ),
60+ "1 час" , new DictionaryData ("1h" ),
61+ "3 часа" , new DictionaryData ("3h" ),
62+ "6 часов" , new DictionaryData ("6h" ),
63+ "12 часов" , new DictionaryData ("12h" ),
64+ "24 часа" , new DictionaryData ("24h" ),
65+ "Текущий календарный день (MSK)" , new DictionaryData ("today_msk" ));
4866 };
4967 }
5068
51- private Map <String , String > convertTerminalsToDictionary (List <Terminal > terminals ) {
69+ private Map <String , DictionaryData > convertTerminalsToDictionary (List <Terminal > terminals ) {
5270 return terminals .stream ()
53- .collect (Collectors .toMap (
54- terminal -> formatDictionaryKey (Integer .toString (terminal .getId ()), terminal .getName ()),
55- terminal -> Integer .toString (terminal .getId ())));
71+ .map (terminal -> createDictionaryData (terminal .getId (), terminal .getName ()))
72+ .collect (Collectors .toMap (DictionaryData ::getUserFriendlyValue , dictionaryData -> dictionaryData ));
5673 }
5774
58- private Map <String , String > convertProvidersToDictionary (List <Provider > providers ) {
75+ private Map <String , DictionaryData > convertProvidersToDictionary (List <Provider > providers ) {
5976 return providers .stream ()
60- .collect (Collectors .toMap (
61- provider -> formatDictionaryKey (Integer .toString (provider .getId ()), provider .getName ()),
62- provider -> Integer .toString (provider .getId ())));
77+ .map (provider -> createDictionaryData (provider .getId (), provider .getName ()))
78+ .collect (Collectors .toMap (DictionaryData ::getUserFriendlyValue , dictionaryData -> dictionaryData ));
6379 }
6480
65- private Map <String , String > convertWalletsToDictionary (List <Wallet > wallets ) {
81+ private Map <String , DictionaryData > convertWalletsToDictionary (List <Wallet > wallets ) {
6682 return wallets .stream ()
67- .collect (Collectors .toMap (
68- wallet -> formatDictionaryKey (wallet .getId (), wallet .getName ()),
69- Wallet ::getId ));
83+ .map (wallet -> createDictionaryData (wallet .getId (), wallet .getName ()))
84+ .collect (Collectors .toMap (DictionaryData ::getUserFriendlyValue , dictionaryData -> dictionaryData ));
7085 }
7186
72- private Map <String , String > convertShopsToDictionary (List <Shop > shops ) {
73- return shops .stream ()
74- . collect ( Collectors . toMap (
75- shop -> formatDictionaryKey ( formatShopId ( shop .getId ()) , shop .getName ()),
76- Shop :: getId ));
87+ private Map <String , DictionaryData > convertShopsToDictionary (List <Shop > shops ) {
88+ return shops .stream (). collect ( Collectors . toMap (
89+ shop -> formatDictionaryString ( formatShopId ( shop . getId ()), shop . getName ()),
90+ shop -> createDictionaryData ( shop .getId (), shop .getName ())
91+ ));
7792 }
7893
7994 // Возвращаем только часть UUID, т.к иначе строка выходит слишком длинной
@@ -87,15 +102,25 @@ private String formatShopId(String shopId) {
87102 }
88103 }
89104
90- private Map <String , String > convertCurrenciesToDictionary (List <Currency > currencies ) {
105+ private Map <String , DictionaryData > convertCurrenciesToDictionary (List <Currency > currencies ) {
91106 return currencies .stream ()
92- .collect (Collectors .toMap (
93- currency -> formatDictionaryKey (currency .getSymbolicCode (), currency .getName ()),
94- Currency ::getSymbolicCode ));
107+ .map (currency -> createDictionaryData (currency .getSymbolicCode (), currency .getName ()))
108+ .collect (Collectors .toMap (DictionaryData ::getUserFriendlyValue , dictionaryData -> dictionaryData ));
95109 }
96110
97- private String formatDictionaryKey (String id , String description ) {
111+ private String formatDictionaryString (String id , String description ) {
98112 return String .format ("(%s) %s" , id , description );
99113 }
100114
115+ private DictionaryData createDictionaryData (String id , String description ) {
116+ return DictionaryData .builder ()
117+ .value (id )
118+ .userFriendlyValue (formatDictionaryString (id , description ))
119+ .build ();
120+ }
121+
122+ private DictionaryData createDictionaryData (Integer id , String description ) {
123+ return createDictionaryData (Integer .toString (id ), description );
124+ }
125+
101126}
0 commit comments