2026-01-30 12:52:16 +07:00
|
|
|
package ru.soune.nocopy.service.tariff;
|
|
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
2026-02-02 12:19:34 +07:00
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2026-01-30 12:52:16 +07:00
|
|
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
|
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import ru.soune.nocopy.entity.tarif.Tariff;
|
|
|
|
|
import ru.soune.nocopy.entity.tarif.TariffType;
|
|
|
|
|
import ru.soune.nocopy.repository.TariffRepository;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class TariffInitializationService {
|
|
|
|
|
|
2026-02-02 12:19:34 +07:00
|
|
|
@Value("${tarif.demo-price}")
|
|
|
|
|
private long demoPrice;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.demo-tokens}")
|
|
|
|
|
private int demoTokens;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.demo-user-count}")
|
|
|
|
|
private long demoUserCount;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.demo-max-files-count}")
|
|
|
|
|
private int demoMaxFileCount;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.start-price}")
|
|
|
|
|
private long startPrice;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.start-tokens}")
|
|
|
|
|
private int startTokens;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.start-max-files-count}")
|
|
|
|
|
private int startMaxFileCount;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.start-user-count}")
|
|
|
|
|
private long startUserCount;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.basic-price}")
|
|
|
|
|
private long basicPrice;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.basic-tokens}")
|
|
|
|
|
private int basicTokens;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.basic-max-files-count}")
|
|
|
|
|
private int basicMaxFileCount;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.basic-user-count}")
|
|
|
|
|
private long basicUserCount;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.pro-price}")
|
|
|
|
|
private long proPrice;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.pro-tokens}")
|
|
|
|
|
private int proTokens;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.pro-max-files-count}")
|
|
|
|
|
private int proMaxFileCount;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.pro-user-count}")
|
|
|
|
|
private long proUserCount;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.enterprice-price}")
|
|
|
|
|
private long enterpricePrice;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.enterprice-tokens}")
|
|
|
|
|
private int enterpriceTokens;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.enterprice-max-files-count}")
|
|
|
|
|
private int enterpriceMaxFileCount;
|
|
|
|
|
|
|
|
|
|
@Value("${tarif.enterprice-user-count}")
|
|
|
|
|
private long enterpriceUserCount;
|
|
|
|
|
|
2026-01-30 12:52:16 +07:00
|
|
|
private final TariffRepository tariffRepository;
|
|
|
|
|
|
|
|
|
|
@EventListener(ApplicationReadyEvent.class)
|
|
|
|
|
@Transactional
|
|
|
|
|
public void initializeDefaultTariffs() {
|
|
|
|
|
List<Tariff> existingTariffs = tariffRepository.findAll();
|
|
|
|
|
|
|
|
|
|
if (existingTariffs.isEmpty()) {
|
|
|
|
|
createDefaultTariffs();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createDefaultTariffs() {
|
|
|
|
|
Arrays.stream(TariffType.values())
|
|
|
|
|
.forEach(this::createDefaultTariff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createDefaultTariff(TariffType type) {
|
|
|
|
|
Tariff tariff = new Tariff();
|
|
|
|
|
tariff.setType(type.name());
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
2026-02-09 17:16:08 +07:00
|
|
|
case FREE:
|
|
|
|
|
tariff.setName("free");
|
|
|
|
|
tariff.setPrice(0);
|
|
|
|
|
tariff.setTokens(30);
|
|
|
|
|
tariff.setMaxFilesCount(10);
|
2026-01-30 12:52:16 +07:00
|
|
|
tariff.setDiskSize(1024L * 1024 * 100);
|
2026-02-09 17:16:08 +07:00
|
|
|
tariff.setMaxUsers(1L);
|
|
|
|
|
tariff.setTariffAccountType("b2c");
|
2026-01-30 12:52:16 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case START:
|
2026-02-03 16:01:32 +07:00
|
|
|
tariff.setName("start");
|
2026-02-09 17:16:08 +07:00
|
|
|
tariff.setPrice(1200);
|
|
|
|
|
tariff.setTokens(300);
|
|
|
|
|
tariff.setMaxFilesCount(80);
|
2026-01-30 12:52:16 +07:00
|
|
|
tariff.setDiskSize(1024L * 1024 * 500);
|
2026-02-09 17:16:08 +07:00
|
|
|
tariff.setMaxUsers(1L);
|
|
|
|
|
tariff.setTariffAccountType("b2c");
|
2026-01-30 12:52:16 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PRO:
|
2026-02-03 16:01:32 +07:00
|
|
|
tariff.setName("pro");
|
2026-02-09 17:16:08 +07:00
|
|
|
tariff.setPrice(4250);
|
|
|
|
|
tariff.setTokens(900);
|
|
|
|
|
tariff.setMaxFilesCount(300);
|
2026-01-30 12:52:16 +07:00
|
|
|
tariff.setDiskSize(1024L * 1024 * 1024 * 10L);
|
2026-02-09 17:16:08 +07:00
|
|
|
tariff.setMaxUsers(1L);
|
|
|
|
|
tariff.setTariffAccountType("b2c");
|
2026-01-30 12:52:16 +07:00
|
|
|
break;
|
|
|
|
|
|
2026-02-09 17:16:08 +07:00
|
|
|
case STUDIO:
|
|
|
|
|
tariff.setName("studio");
|
|
|
|
|
tariff.setPrice(9750);
|
|
|
|
|
tariff.setTokens(3000);
|
|
|
|
|
tariff.setMaxFilesCount(1000);
|
2026-01-30 12:52:16 +07:00
|
|
|
tariff.setDiskSize(1024L * 1024 * 1024 * 50L);
|
2026-02-09 17:16:08 +07:00
|
|
|
tariff.setMaxUsers(2L);
|
|
|
|
|
tariff.setTariffAccountType("b2c");
|
2026-01-30 12:52:16 +07:00
|
|
|
break;
|
2026-02-04 12:50:35 +07:00
|
|
|
|
|
|
|
|
case BASIC:
|
|
|
|
|
tariff.setName("basic");
|
|
|
|
|
tariff.setPrice(basicPrice);
|
|
|
|
|
tariff.setTokens(basicTokens);
|
|
|
|
|
tariff.setMaxFilesCount(enterpriceMaxFileCount);
|
|
|
|
|
tariff.setDiskSize(1024L * 1024 * 1024 * 50L);
|
|
|
|
|
tariff.setMaxUsers(basicUserCount);
|
2026-02-09 17:16:08 +07:00
|
|
|
tariff.setTariffAccountType("b2c");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ENTERPRISE:
|
|
|
|
|
tariff.setName("enterprise");
|
|
|
|
|
tariff.setPrice(200000);
|
|
|
|
|
tariff.setTokens(30000);
|
|
|
|
|
tariff.setMaxFilesCount(100000);
|
|
|
|
|
tariff.setDiskSize(1024L * 1024 * 1024 * 10L);
|
|
|
|
|
tariff.setMaxUsers(10L);
|
|
|
|
|
tariff.setTariffAccountType("b2b");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BUISNES:
|
|
|
|
|
tariff.setName("buisnes");
|
|
|
|
|
tariff.setPrice(29000);
|
|
|
|
|
tariff.setTokens(5000);
|
|
|
|
|
tariff.setMaxFilesCount(5000);
|
|
|
|
|
tariff.setDiskSize(1024L * 1024 * 1024 * 50L);
|
|
|
|
|
tariff.setMaxUsers(5L);
|
|
|
|
|
tariff.setTariffAccountType("b2b");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CORPORAT:
|
|
|
|
|
tariff.setName("corporat");
|
|
|
|
|
tariff.setPrice(99000);
|
|
|
|
|
tariff.setTokens(20000);
|
|
|
|
|
tariff.setMaxFilesCount(50000);
|
|
|
|
|
tariff.setDiskSize(1024L * 1024 * 1024 * 50L);
|
|
|
|
|
tariff.setMaxUsers(10L);
|
|
|
|
|
tariff.setTariffAccountType("b2b");
|
2026-02-04 12:50:35 +07:00
|
|
|
break;
|
2026-02-19 14:15:59 +07:00
|
|
|
|
|
|
|
|
case TOKEN_100:
|
|
|
|
|
tariff.setName("token_100");
|
|
|
|
|
tariff.setPrice(299);
|
|
|
|
|
tariff.setTokens(100);
|
|
|
|
|
tariff.setMaxFilesCount(0);
|
|
|
|
|
tariff.setDiskSize(0L);
|
|
|
|
|
tariff.setMaxUsers(0L);
|
|
|
|
|
tariff.setTariffAccountType("token");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TOKEN_500:
|
|
|
|
|
tariff.setName("token_500");
|
|
|
|
|
tariff.setPrice(1299);
|
|
|
|
|
tariff.setTokens(500);
|
|
|
|
|
tariff.setMaxFilesCount(0);
|
|
|
|
|
tariff.setDiskSize(0L);
|
|
|
|
|
tariff.setMaxUsers(0L);
|
|
|
|
|
tariff.setTariffAccountType("token");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TOKEN_1000:
|
|
|
|
|
tariff.setName("token_1000");
|
|
|
|
|
tariff.setPrice(2399);
|
|
|
|
|
tariff.setTokens(1000);
|
|
|
|
|
tariff.setMaxFilesCount(0);
|
|
|
|
|
tariff.setDiskSize(0L);
|
|
|
|
|
tariff.setMaxUsers(0L);
|
|
|
|
|
tariff.setTariffAccountType("token");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TOKEN_5000:
|
|
|
|
|
tariff.setName("token_5000");
|
|
|
|
|
tariff.setPrice(9999);
|
|
|
|
|
tariff.setTokens(5000);
|
|
|
|
|
tariff.setMaxFilesCount(0);
|
|
|
|
|
tariff.setDiskSize(0L);
|
|
|
|
|
tariff.setMaxUsers(0L);
|
|
|
|
|
tariff.setTariffAccountType("token");
|
|
|
|
|
break;
|
2026-02-27 17:57:55 +07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
case MONITORING_DAILY:
|
|
|
|
|
tariff.setName("monitoring_daily");
|
|
|
|
|
tariff.setPrice(0);
|
|
|
|
|
tariff.setTokens(10);
|
|
|
|
|
tariff.setMaxFilesCount(0);
|
|
|
|
|
tariff.setDiskSize(0L);
|
|
|
|
|
tariff.setMaxUsers(0L);
|
|
|
|
|
tariff.setTariffAccountType("monitoring");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MONITORING_WEEKLY:
|
|
|
|
|
tariff.setName("monitoring_weekly");
|
|
|
|
|
tariff.setPrice(0);
|
|
|
|
|
tariff.setTokens(25);
|
|
|
|
|
tariff.setMaxFilesCount(0);
|
|
|
|
|
tariff.setDiskSize(0L);
|
|
|
|
|
tariff.setMaxUsers(0L);
|
|
|
|
|
tariff.setTariffAccountType("monitoring");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MONITORING_MONTHLY:
|
|
|
|
|
tariff.setName("monitoring_monthly");
|
|
|
|
|
tariff.setPrice(0);
|
|
|
|
|
tariff.setTokens(50);
|
|
|
|
|
tariff.setMaxFilesCount(0);
|
|
|
|
|
tariff.setDiskSize(0L);
|
|
|
|
|
tariff.setMaxUsers(0L);
|
|
|
|
|
tariff.setTariffAccountType("monitoring");
|
|
|
|
|
break;
|
2026-01-30 12:52:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tariffRepository.save(tariff);
|
|
|
|
|
}
|
|
|
|
|
}
|