This commit is contained in:
@@ -85,7 +85,7 @@ public class UserController {
|
||||
}
|
||||
|
||||
if (user.canManageCompanySettings() || user.canLogin() && user.getCompany() == null) {
|
||||
userDTO.setTariffs(tariffService.getAllTariffs());
|
||||
userDTO.setTariffs(tariffService.getTariffByAccountType(user));
|
||||
|
||||
Long fileOnDisk = user.canManageCompanySettings() ?
|
||||
fileStatsService.calculateCompanyFileSize(user.getId()):
|
||||
|
||||
@@ -46,4 +46,7 @@ public class TariffRequest {
|
||||
|
||||
@JsonProperty("action")
|
||||
private String action;
|
||||
|
||||
@JsonProperty("user_token")
|
||||
private String userToken;
|
||||
}
|
||||
@@ -37,4 +37,7 @@ public class Tariff {
|
||||
|
||||
@Column(name = "max_users")
|
||||
private Long maxUsers;
|
||||
|
||||
@Column(name = "tariffAccountType")
|
||||
private String tariffAccountType;
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ package ru.soune.nocopy.entity.tarif;
|
||||
|
||||
|
||||
public enum TariffType {
|
||||
START, BASIC, PRO, ENTERPRISE, DEMO;
|
||||
START, BASIC, PRO, ENTERPRISE, DEMO, BUISNES, CORPORAT, STUDIO, FREE;
|
||||
}
|
||||
@@ -10,6 +10,9 @@ import ru.soune.nocopy.dto.MessageCode;
|
||||
import ru.soune.nocopy.dto.tarriff.TariffDTO;
|
||||
import ru.soune.nocopy.dto.tarriff.TariffRequest;
|
||||
import ru.soune.nocopy.dto.tarriff.TariffResponse;
|
||||
import ru.soune.nocopy.entity.user.AuthToken;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.repository.AuthTokenRepository;
|
||||
import ru.soune.nocopy.service.tariff.TariffService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -24,6 +27,8 @@ public class TariffHandler implements RequestHandler {
|
||||
|
||||
private final TariffService tariffService;
|
||||
|
||||
private final AuthTokenRepository authTokenRepository;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||
try {
|
||||
@@ -113,7 +118,9 @@ public class TariffHandler implements RequestHandler {
|
||||
}
|
||||
|
||||
private BaseResponse handleGetTariffs(BaseRequest request, TariffRequest tariffRequest) {
|
||||
List<TariffDTO> allTariffs = tariffService.getAllTariffs();
|
||||
AuthToken authToken = authTokenRepository.findByToken(tariffRequest.getUserToken()).orElseThrow();
|
||||
User user = authToken.getUser();
|
||||
List<TariffDTO> allTariffs = tariffService.getTariffByAccountType(user);
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(),
|
||||
|
||||
@@ -12,5 +12,6 @@ import java.util.Optional;
|
||||
public interface TariffRepository extends JpaRepository<Tariff, Long> {
|
||||
Optional<Tariff> findByType(String type);
|
||||
List<Tariff> findAllByOrderByPriceAsc();
|
||||
List<Tariff> findByTariffAccountType(String typeAccount);
|
||||
Tariff findByName(String name);
|
||||
}
|
||||
|
||||
@@ -101,40 +101,44 @@ public class TariffInitializationService {
|
||||
tariff.setType(type.name());
|
||||
|
||||
switch (type) {
|
||||
case DEMO:
|
||||
tariff.setName("demo");
|
||||
tariff.setPrice(demoPrice);
|
||||
tariff.setTokens(demoTokens);
|
||||
tariff.setMaxFilesCount(demoMaxFileCount);
|
||||
case FREE:
|
||||
tariff.setName("free");
|
||||
tariff.setPrice(0);
|
||||
tariff.setTokens(30);
|
||||
tariff.setMaxFilesCount(10);
|
||||
tariff.setDiskSize(1024L * 1024 * 100);
|
||||
tariff.setMaxUsers(demoUserCount);
|
||||
tariff.setMaxUsers(1L);
|
||||
tariff.setTariffAccountType("b2c");
|
||||
break;
|
||||
|
||||
case START:
|
||||
tariff.setName("start");
|
||||
tariff.setPrice(startPrice);
|
||||
tariff.setTokens(startTokens);
|
||||
tariff.setMaxFilesCount(startMaxFileCount);
|
||||
tariff.setPrice(1200);
|
||||
tariff.setTokens(300);
|
||||
tariff.setMaxFilesCount(80);
|
||||
tariff.setDiskSize(1024L * 1024 * 500);
|
||||
tariff.setMaxUsers(startUserCount);
|
||||
tariff.setMaxUsers(1L);
|
||||
tariff.setTariffAccountType("b2c");
|
||||
break;
|
||||
|
||||
case PRO:
|
||||
tariff.setName("pro");
|
||||
tariff.setPrice(proPrice);
|
||||
tariff.setTokens(proTokens);
|
||||
tariff.setMaxFilesCount(proMaxFileCount);
|
||||
tariff.setPrice(4250);
|
||||
tariff.setTokens(900);
|
||||
tariff.setMaxFilesCount(300);
|
||||
tariff.setDiskSize(1024L * 1024 * 1024 * 10L);
|
||||
tariff.setMaxUsers(proUserCount);
|
||||
tariff.setMaxUsers(1L);
|
||||
tariff.setTariffAccountType("b2c");
|
||||
break;
|
||||
|
||||
case ENTERPRISE:
|
||||
tariff.setName("premium");
|
||||
tariff.setPrice(enterpricePrice);
|
||||
tariff.setTokens(enterpriceTokens);
|
||||
tariff.setMaxFilesCount(enterpriceMaxFileCount);
|
||||
case STUDIO:
|
||||
tariff.setName("studio");
|
||||
tariff.setPrice(9750);
|
||||
tariff.setTokens(3000);
|
||||
tariff.setMaxFilesCount(1000);
|
||||
tariff.setDiskSize(1024L * 1024 * 1024 * 50L);
|
||||
tariff.setMaxUsers(enterpriceUserCount);
|
||||
tariff.setMaxUsers(2L);
|
||||
tariff.setTariffAccountType("b2c");
|
||||
break;
|
||||
|
||||
case BASIC:
|
||||
@@ -144,6 +148,37 @@ public class TariffInitializationService {
|
||||
tariff.setMaxFilesCount(enterpriceMaxFileCount);
|
||||
tariff.setDiskSize(1024L * 1024 * 1024 * 50L);
|
||||
tariff.setMaxUsers(basicUserCount);
|
||||
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");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.soune.nocopy.dto.tarriff.TariffDTO;
|
||||
import ru.soune.nocopy.entity.tarif.Tariff;
|
||||
import ru.soune.nocopy.entity.tarif.TariffType;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.exception.TariffNotFoundException;
|
||||
import ru.soune.nocopy.repository.TariffRepository;
|
||||
|
||||
@@ -32,6 +33,15 @@ public class TariffService {
|
||||
tariffRepository.save(tariff);
|
||||
}
|
||||
|
||||
public List<TariffDTO> getTariffByAccountType(User user) {
|
||||
String typeAccount = user.canManageCompanySettings() ? "b2b": "b2c";
|
||||
|
||||
return tariffRepository.findByTariffAccountType(typeAccount)
|
||||
.stream()
|
||||
.map(this::convertToDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<TariffDTO> getAllTariffs() {
|
||||
return tariffRepository.findAllByOrderByPriceAsc()
|
||||
.stream()
|
||||
|
||||
Reference in New Issue
Block a user