Initial commit - 2
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
package ru.kayashov.bar.bot.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface FilterTitle {
|
||||
String title();
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package ru.kayashov.bar.bot.domain;
|
||||
|
||||
import org.telegram.telegrambots.meta.api.objects.User;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
import ru.kayashov.bar.bot.domain.methods.AbstractDeleteMessage;
|
||||
import ru.kayashov.bar.bot.domain.methods.AbstractInlineKeyboard;
|
||||
import ru.kayashov.bar.bot.domain.methods.AbstractMethod;
|
||||
|
||||
@@ -2,32 +2,27 @@ package ru.kayashov.bar.bot.domain.command.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.telegram.telegrambots.meta.api.methods.GetUserProfilePhotos;
|
||||
import ru.kayashov.bar.bot.annotation.CommandData;
|
||||
import ru.kayashov.bar.bot.domain.command.api.Command;
|
||||
import ru.kayashov.bar.bot.domain.keyboards.reply.ReplyKeyboardMarker;
|
||||
import ru.kayashov.bar.bot.domain.methods.AbstractMethod;
|
||||
import ru.kayashov.bar.bot.domain.model.AbstractChat;
|
||||
import ru.kayashov.bar.bot.domain.model.AbstractUpdate;
|
||||
import ru.kayashov.bar.model.entity.Visitor;
|
||||
import ru.kayashov.bar.repository.VisitorsRepository;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import static ru.kayashov.bar.bot.domain.keyboards.reply.ReplyKeyboardMarker.getMainMenu;
|
||||
import static ru.kayashov.bar.bot.domain.utils.MethodUtils.sendKeyboardMessage;
|
||||
import static ru.kayashov.bar.bot.domain.utils.MethodUtils.sendMessage;
|
||||
|
||||
/**
|
||||
* Команда обработки запроса меню
|
||||
*
|
||||
* <p>
|
||||
* Реализация {@link }
|
||||
*/
|
||||
@Component
|
||||
@CommandData(name="/start")
|
||||
@CommandData(name = "/start")
|
||||
@RequiredArgsConstructor
|
||||
public class StartCommand implements Command {
|
||||
|
||||
@@ -40,7 +35,7 @@ public class StartCommand implements Command {
|
||||
Optional<Visitor> visitorOpt = visitorsRepository.findById(chat.getId());
|
||||
String message;
|
||||
Visitor visitor;
|
||||
if(visitorOpt.isPresent()) {
|
||||
if (visitorOpt.isPresent()) {
|
||||
visitor = visitorOpt.get();
|
||||
message = "С возвращением ";
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package ru.kayashov.bar.bot.domain.keyboards.reply;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.kayashov.bar.bot.domain.model.AbstractKeyboard;
|
||||
import ru.kayashov.bar.bot.domain.model.AbstractKeyboardButton;
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import ru.kayashov.bar.bot.domain.model.AbstractKeyboard;
|
||||
@Getter
|
||||
public class AbstractInlineKeyboard extends AbstractMethod {
|
||||
|
||||
private String message;
|
||||
private AbstractKeyboard keyboard;
|
||||
private final String message;
|
||||
private final AbstractKeyboard keyboard;
|
||||
|
||||
@Builder
|
||||
public AbstractInlineKeyboard(Long chatId, String message, AbstractKeyboard keyboard) {
|
||||
|
||||
@@ -9,7 +9,4 @@ public class AbstractUpdate {
|
||||
private AbstractCallbackQuery callbackQuery;
|
||||
private AbstractMessage message;
|
||||
|
||||
public boolean hasMessage() {
|
||||
return message != null && message.getMessage() != null && !message.getMessage().isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package ru.kayashov.bar.bot.domain.model.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonRootName(value = "Gen")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class CarGenerationDto extends FindServiceDto {
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package ru.kayashov.bar.bot.domain.model.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonRootName(value = "Mark")
|
||||
public class CarMarkDto extends FindServiceDto {
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package ru.kayashov.bar.bot.domain.model.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonRootName(value = "Model")
|
||||
public class CarModelDto extends FindServiceDto {
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package ru.kayashov.bar.bot.domain.model.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonRootName("Find")
|
||||
public class FindPageableDto {
|
||||
|
||||
@JsonProperty("l")
|
||||
private Long locationId;
|
||||
|
||||
@JsonProperty("g")
|
||||
private Long carGenerationId;
|
||||
|
||||
@JsonProperty("p")
|
||||
private Integer page;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package ru.kayashov.bar.bot.domain.model.pojo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class FindServiceDto extends PageableDto {
|
||||
private String name;
|
||||
private Long value;
|
||||
private Long old;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package ru.kayashov.bar.bot.domain.model.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonRootName("Loc")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class LocationDto extends PageableDto {
|
||||
private Long id;
|
||||
@JsonProperty("p")
|
||||
private Long parent;
|
||||
private String name;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package ru.kayashov.bar.bot.domain.model.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PageableDto {
|
||||
@JsonProperty(value = "pn")
|
||||
Integer page;
|
||||
}
|
||||
@@ -4,12 +4,10 @@ import io.jsonwebtoken.Claims;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.kayashov.bar.controller.dto.AuthRequestDto;
|
||||
import ru.kayashov.bar.controller.dto.AuthResponseDto;
|
||||
@@ -33,7 +31,7 @@ public class AuthController {
|
||||
|
||||
@PostMapping("/login")
|
||||
public AuthResponseDto checkTelegramChat(@RequestBody AuthRequestDto dto) {
|
||||
if(dto.getByLogin()) {
|
||||
if (dto.getByLogin()) {
|
||||
return checkLogin(dto.getLogin(), dto.getPassword());
|
||||
} else {
|
||||
return parseCode(dto.getCode());
|
||||
@@ -59,16 +57,16 @@ public class AuthController {
|
||||
}
|
||||
|
||||
private AuthResponseDto checkLogin(String login, String password) {
|
||||
if(login == null || login.isEmpty() || password == null || password.isEmpty()) {
|
||||
if (login == null || login.isEmpty() || password == null || password.isEmpty()) {
|
||||
return new AuthResponseDto(null, "Поля не могут быть пустые");
|
||||
}
|
||||
|
||||
Optional<Visitor> visitorOpt = visitorsRepository.findByLogin(login);
|
||||
if(visitorOpt.isEmpty()) {
|
||||
if (visitorOpt.isEmpty()) {
|
||||
return new AuthResponseDto(null, "Не найдет пользователь " + login);
|
||||
}
|
||||
Visitor visitor = visitorOpt.get();
|
||||
if(passwordEncoder.matches(password, visitor.getPassword())) {
|
||||
if (passwordEncoder.matches(password, visitor.getPassword())) {
|
||||
return new AuthResponseDto(jwtTokenProvider.generateToken(visitor), null);
|
||||
} else {
|
||||
return new AuthResponseDto(null, "Неверный логин или пароль");
|
||||
|
||||
@@ -3,11 +3,6 @@ package ru.kayashov.bar.controller.dto.cocktail;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import ru.kayashov.bar.model.entity.CocktailEntity;
|
||||
import ru.kayashov.bar.model.entity.IngredientEntity;
|
||||
import ru.kayashov.bar.model.entity.ReceiptEntity;
|
||||
import ru.kayashov.bar.model.entity.TagEntity;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
package ru.kayashov.bar.model.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@@ -33,7 +30,7 @@ public class IngredientEntity {
|
||||
private Boolean alcohol;
|
||||
private Integer abv;
|
||||
|
||||
@Column(columnDefinition="text")
|
||||
@Column(columnDefinition = "text")
|
||||
private String description;
|
||||
|
||||
@OneToMany(mappedBy = "ingredient")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package ru.kayashov.bar.model.entity;
|
||||
|
||||
public enum OrderStatus {
|
||||
NEW, PROCESS, DONE, CANCEL;
|
||||
NEW, PROCESS, DONE, CANCEL
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package ru.kayashov.bar.model.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@Entity
|
||||
@Table(name = "parser")
|
||||
@Getter
|
||||
@Setter
|
||||
public class ParserEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
private Long ingredientId;
|
||||
private Long cocktailId;
|
||||
private Long ingredientError;
|
||||
private Long cocktailError;
|
||||
}
|
||||
@@ -1,16 +1,14 @@
|
||||
package ru.kayashov.bar.model.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "receipt")
|
||||
|
||||
@@ -5,6 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UnitRepository extends JpaRepository<Unit, Long> {
|
||||
|
||||
Optional<Unit> findByName(String unit);
|
||||
}
|
||||
@@ -7,12 +7,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -7,6 +7,5 @@ import java.util.Optional;
|
||||
|
||||
public interface AlcoholicRepository extends JpaRepository<AlcoholicEntity, Integer> {
|
||||
|
||||
Optional<AlcoholicEntity> findByEnNameIgnoreCase(String enName);
|
||||
Optional<AlcoholicEntity> findByName(String name);
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
package ru.kayashov.bar.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.kayashov.bar.model.entity.AlcoholicEntity;
|
||||
import ru.kayashov.bar.model.entity.CategoryEntity;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CategoryRepository extends JpaRepository<CategoryEntity, Integer> {
|
||||
|
||||
Optional<CategoryEntity> findByEnNameIgnoreCase(String enName);
|
||||
Optional<CategoryEntity> findByNameIgnoreCase(String name);
|
||||
}
|
||||
@@ -3,8 +3,5 @@ package ru.kayashov.bar.repository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.kayashov.bar.model.entity.CocktailEntity;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface CocktailRepository extends JpaRepository<CocktailEntity, Long> {
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
package ru.kayashov.bar.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.kayashov.bar.model.entity.AlcoholicEntity;
|
||||
import ru.kayashov.bar.model.entity.GlassEntity;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface GlassRepository extends JpaRepository<GlassEntity, Integer> {
|
||||
|
||||
Optional<GlassEntity> findByEnNameIgnoreCase(String enName);
|
||||
Optional<GlassEntity> findByNameIgnoreCase(String enName);
|
||||
}
|
||||
@@ -1,18 +1,11 @@
|
||||
package ru.kayashov.bar.repository;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import ru.kayashov.bar.model.entity.IngredientEntity;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IngredientRepository extends JpaRepository<IngredientEntity, Long> {
|
||||
|
||||
Optional<IngredientEntity> findByEnNameIgnoreCase(String name);
|
||||
|
||||
@Query("select i from IngredientEntity i where upper(i.name) like upper(?1) or upper(i.enName) like upper(?1)")
|
||||
List<IngredientEntity> findAllByWord(String name, Pageable pageable);
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
package ru.kayashov.bar.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.kayashov.bar.model.entity.OrderStatus;
|
||||
import ru.kayashov.bar.model.entity.Pay;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface OrdersRepository extends JpaRepository<Pay, Long> {
|
||||
|
||||
List<Pay> findAllByStatusOrderById(OrderStatus status);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package ru.kayashov.bar.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.kayashov.bar.model.entity.ParserEntity;
|
||||
|
||||
public interface ParserEntityRepository extends JpaRepository<ParserEntity, Integer> {
|
||||
}
|
||||
@@ -6,6 +6,4 @@ import ru.kayashov.bar.model.entity.SessionEntity;
|
||||
import java.util.List;
|
||||
|
||||
public interface SessionRepository extends JpaRepository<SessionEntity, Long> {
|
||||
|
||||
List<SessionEntity> findAllByIsActiveTrue();
|
||||
}
|
||||
@@ -7,7 +7,5 @@ import java.util.Optional;
|
||||
|
||||
public interface TagRepository extends JpaRepository<TagEntity, Long> {
|
||||
|
||||
Optional<TagEntity> findByEnNameIgnoreCase(String name);
|
||||
|
||||
Optional<TagEntity> findByName(String names);
|
||||
}
|
||||
@@ -3,12 +3,9 @@ package ru.kayashov.bar.repository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.kayashov.bar.model.entity.Visitor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface VisitorsRepository extends JpaRepository<Visitor, Long> {
|
||||
|
||||
Optional<Visitor> findByCode(Integer code);
|
||||
|
||||
Optional<Visitor> findByLogin(String login);
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
package ru.kayashov.bar.schedule;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.kayashov.bar.model.api.translate.Translate;
|
||||
import ru.kayashov.bar.model.entity.CocktailEntity;
|
||||
import ru.kayashov.bar.model.entity.IngredientEntity;
|
||||
import ru.kayashov.bar.model.entity.ReceiptEntity;
|
||||
import ru.kayashov.bar.model.entity.TypeEntity;
|
||||
import ru.kayashov.bar.model.entity.Unit;
|
||||
import ru.kayashov.bar.model.entity.UnitRepository;
|
||||
import ru.kayashov.bar.repository.CocktailRepository;
|
||||
import ru.kayashov.bar.repository.IngredientRepository;
|
||||
import ru.kayashov.bar.repository.ReceiptRepository;
|
||||
import ru.kayashov.bar.repository.TypeRepository;
|
||||
import ru.kayashov.bar.service.integration.translate.TranslateService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static ru.kayashov.bar.service.integration.translate.TranslateService.translate;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class Repairer {
|
||||
|
||||
private final IngredientRepository ingredientRepository;
|
||||
private final TypeRepository tagRepository;
|
||||
private final CocktailRepository cocktailRepository;
|
||||
private final ReceiptRepository receiptRepository;
|
||||
private final UnitRepository unitRepository;
|
||||
|
||||
// @Transactional
|
||||
// @EventListener(ContextRefreshedEvent.class)
|
||||
public void repair() {
|
||||
unitRepository.findAll().stream()
|
||||
.peek(u -> u.setName(TranslateService.softTranslate(u.getName())))
|
||||
.forEach(unitRepository::save);
|
||||
|
||||
log.info("repaired");
|
||||
}
|
||||
|
||||
private Float convertValue(String value) {
|
||||
if (value.contains("-") || value.contains("/")) {
|
||||
float f;
|
||||
if (value.contains("-")) {
|
||||
f = average(value);
|
||||
} else if (value.contains("/")) {
|
||||
f = drob(value);
|
||||
} else {
|
||||
f = Float.parseFloat(value);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
try {
|
||||
return Float.parseFloat(value);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// @Transactional
|
||||
// @EventListener(ContextRefreshedEvent.class)
|
||||
public void repairAllowed() {
|
||||
List<CocktailEntity> cocktailEntities = cocktailRepository.findAll();
|
||||
|
||||
for (CocktailEntity cocktail : cocktailEntities) {
|
||||
List<ReceiptEntity> receipts = cocktail.getReceipt();
|
||||
// if(receipts.stream().allMatch(r -> r.getIngredient().getIsHave())) {
|
||||
// cocktail.setIsAllowed(true);
|
||||
// } else {
|
||||
// cocktail.setIsAllowed(false);
|
||||
// }
|
||||
cocktailRepository.save(cocktail);
|
||||
}
|
||||
log.info("Cocktails have been repaired");
|
||||
}
|
||||
|
||||
@Transactional
|
||||
// @EventListener(ContextRefreshedEvent.class)
|
||||
public void repairReceipts() {
|
||||
// List<ReceiptEntity> receipts = receiptRepository.findAll()
|
||||
// .stream()
|
||||
// .filter(r -> r.getMeasureText() != null && r.getMeasure() == null)
|
||||
// .filter(r -> r.getMeasureText().contains("Slice"))
|
||||
// .filter(r -> r.getMeasureText().split(" ").length == 2)
|
||||
// .toList();
|
||||
// for (ReceiptEntity receipt : receipts) {
|
||||
// String[] split = receipt.getMeasureText().split(" ");
|
||||
// if (split[1].equalsIgnoreCase("Slice")) {
|
||||
// receipt.setUnitText(split[1]);
|
||||
// } else {
|
||||
// continue;
|
||||
// }
|
||||
// log.info("convert {} - {}", receipt.getId(), receipt.getMeasureText());
|
||||
//
|
||||
// String measure = split[0];
|
||||
// Float f;
|
||||
// if (measure.contains("-")) {
|
||||
// f = average(measure);
|
||||
// } else if (measure.contains("/")) {
|
||||
// f = drob(measure);
|
||||
// } else {
|
||||
// f = Float.parseFloat(measure);
|
||||
// }
|
||||
//
|
||||
// receipt.setMeasure(f == 0 ? null : f);
|
||||
// receiptRepository.save(receipt);
|
||||
// }
|
||||
log.info("repaired");
|
||||
}
|
||||
|
||||
private Float average(String s) {
|
||||
String[] split = s.split("-");
|
||||
float sum = 0f;
|
||||
for (String str : split) {
|
||||
if (str.contains("/")) {
|
||||
sum += drob(str);
|
||||
} else {
|
||||
sum += Float.parseFloat(str);
|
||||
}
|
||||
}
|
||||
return sum / split.length;
|
||||
}
|
||||
|
||||
private Float drob(String s) {
|
||||
String[] split = s.split("/");
|
||||
return Float.parseFloat(split[0]) / Float.parseFloat(split[1]);
|
||||
}
|
||||
|
||||
// @Transactional
|
||||
// @EventListener(ContextRefreshedEvent.class)
|
||||
public void repairEnTag() {
|
||||
List<TypeEntity> tagEntities = tagRepository.findAll()
|
||||
.stream()
|
||||
.filter(t -> t.getName() == null)
|
||||
.toList();
|
||||
for (TypeEntity tagEntity : tagEntities) {
|
||||
tagEntity.setName(translate(tagEntity.getEnName()));
|
||||
tagRepository.save(tagEntity);
|
||||
log.info("tag {} saved", tagEntity.getName());
|
||||
}
|
||||
log.info("repaired");
|
||||
}
|
||||
|
||||
|
||||
public void repairEnIngredients() {
|
||||
List<IngredientEntity> ingredients = ingredientRepository.findAll().stream()
|
||||
.filter(i -> i.getName() == null)
|
||||
// .filter(i -> i.getDescription() == null && i.getEnDescription() != null && !i.getEnDescription().isEmpty())
|
||||
.toList();
|
||||
|
||||
for (IngredientEntity i : ingredients) {
|
||||
boolean needSave = false;
|
||||
if (i.getName() == null) {
|
||||
String s = translate(i.getEnName());
|
||||
i.setName(s);
|
||||
needSave = true;
|
||||
}
|
||||
if (i.getDescription() == null) {
|
||||
// String s = translate(i.getEnDescription());
|
||||
// i.setDescription(s);
|
||||
needSave = true;
|
||||
}
|
||||
if (needSave) {
|
||||
ingredientRepository.save(i);
|
||||
log.info("Ingredient {} saved", i.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package ru.kayashov.bar.security;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jws;
|
||||
import io.jsonwebtoken.JwtParser;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.io.Decoders;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package ru.kayashov.bar.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.kayashov.bar.model.entity.ParserEntity;
|
||||
import ru.kayashov.bar.repository.ParserEntityRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ParserQueueService {
|
||||
|
||||
private final ParserEntityRepository repository;
|
||||
|
||||
public Long getIngredientOffset() {
|
||||
return getEntity().getIngredientId();
|
||||
}
|
||||
|
||||
public Long getCocktailOffset() {
|
||||
return getEntity().getCocktailId();
|
||||
}
|
||||
|
||||
public void setStepIngredients(long id, int step) {
|
||||
ParserEntity entity = getEntity();
|
||||
entity.setIngredientId(id);
|
||||
entity.setIngredientError(entity.getIngredientError() + step);
|
||||
repository.save(entity);
|
||||
}
|
||||
|
||||
public void setStepCocktails(long id, int step) {
|
||||
ParserEntity entity = getEntity();
|
||||
entity.setCocktailId(id);
|
||||
entity.setCocktailError(entity.getCocktailError() + step);
|
||||
repository.save(entity);
|
||||
}
|
||||
|
||||
private ParserEntity getEntity() {
|
||||
List<ParserEntity> entities = repository.findAll();
|
||||
if(entities.isEmpty()) {
|
||||
ParserEntity entity = getNewEntity();
|
||||
return repository.save(entity);
|
||||
}
|
||||
return entities.get(0);
|
||||
}
|
||||
|
||||
private ParserEntity getNewEntity() {
|
||||
ParserEntity entity = new ParserEntity();
|
||||
entity.setIngredientId(1L);
|
||||
entity.setCocktailId(1L);
|
||||
entity.setCocktailError(0L);
|
||||
entity.setCocktailError(0L);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package ru.kayashov.bar;
|
||||
|
||||
class MyBarApplicationTests {
|
||||
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user