Refactoring stuff x2
This commit is contained in:
parent
d442b1e159
commit
cc55257cd4
@ -1,31 +0,0 @@
|
|||||||
package com.alterdekim.javabot.bot;
|
|
||||||
|
|
||||||
import com.alterdekim.javabot.Constants;
|
|
||||||
import com.alterdekim.javabot.util.HashUtils;
|
|
||||||
|
|
||||||
public enum BioButtons {
|
|
||||||
HOBBY(Constants.HOBBY_BTN),
|
|
||||||
WORK(Constants.WORK_BTN),
|
|
||||||
HEALTH(Constants.HEALTH_BTN),
|
|
||||||
AGE(Constants.AGE_BTN),
|
|
||||||
GENDER(Constants.GENDER_BTN),
|
|
||||||
LUGGAGE(Constants.LUGG_BTN),
|
|
||||||
UNKNOWN("");
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
BioButtons(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHash() {
|
|
||||||
return HashUtils.getCRC32(this.name.getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BioButtons fromHash( String hash ) {
|
|
||||||
for( BioButtons b : values() ) {
|
|
||||||
if( b.getHash().equals(hash) ) return b;
|
|
||||||
}
|
|
||||||
return UNKNOWN;
|
|
||||||
}
|
|
||||||
}
|
|
12
src/main/java/com/alterdekim/javabot/bot/InfoSection.java
Normal file
12
src/main/java/com/alterdekim/javabot/bot/InfoSection.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package com.alterdekim.javabot.bot;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@ToString
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class InfoSection {
|
||||||
|
private SectionType type;
|
||||||
|
}
|
@ -1,26 +1,30 @@
|
|||||||
package com.alterdekim.javabot.bot;
|
package com.alterdekim.javabot.bot;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
public class InfoSections {
|
public class InfoSections {
|
||||||
private Boolean isGenderShowed;
|
private final List<InfoSection> sections;
|
||||||
private Boolean isAgeShowed;
|
|
||||||
private Boolean isWorkShowed;
|
|
||||||
private Boolean isLuggageShowed;
|
|
||||||
private Boolean isHobbyShowed;
|
|
||||||
private Boolean isHealthShowed;
|
|
||||||
|
|
||||||
public InfoSections() {
|
public InfoSections() {
|
||||||
this.isAgeShowed = false;
|
this.sections = new ArrayList<>();
|
||||||
this.isLuggageShowed = false;
|
}
|
||||||
this.isGenderShowed = false;
|
|
||||||
this.isWorkShowed = false;
|
public boolean isShowed(SectionType type) {
|
||||||
this.isHealthShowed = false;
|
return this.sections.stream().anyMatch(p -> p.getType() == type);
|
||||||
this.isHobbyShowed = false;
|
}
|
||||||
|
|
||||||
|
public void pushShowedState(SectionType type) {
|
||||||
|
if(this.isShowed(type)) return;
|
||||||
|
this.sections.add(new InfoSection(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
this.sections.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.alterdekim.javabot.bot;
|
package com.alterdekim.javabot.bot;
|
||||||
|
|
||||||
import com.alterdekim.javabot.entities.ColumnType;
|
|
||||||
import com.alterdekim.javabot.entities.Synergy;
|
import com.alterdekim.javabot.entities.Synergy;
|
||||||
import com.alterdekim.javabot.util.Clamp;
|
import com.alterdekim.javabot.util.Clamp;
|
||||||
|
|
||||||
@ -37,26 +36,15 @@ public class LiveFormula {
|
|||||||
return Clamp.clamp(i * 1.2d, 0, 1);
|
return Clamp.clamp(i * 1.2d, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean entity(List<Player> players, ColumnType ct, Long eid) {
|
private static Boolean entity(List<Player> players, SectionType ct, Long eid) {
|
||||||
Boolean fb = false;
|
return switch (ct) {
|
||||||
switch (ct) {
|
case GENDER -> LiveFormula.searchForBio(players, eid);
|
||||||
case Bio:
|
case WORK -> LiveFormula.searchForWork(players, eid);
|
||||||
fb = LiveFormula.searchForBio(players, eid);
|
case HOBBY -> LiveFormula.searchForHobby(players, eid);
|
||||||
break;
|
case HEALTH -> LiveFormula.searchForHealth(players, eid);
|
||||||
case Work:
|
case LUGGAGE -> LiveFormula.searchForLuggage(players, eid);
|
||||||
fb = LiveFormula.searchForWork(players, eid);
|
default -> false;
|
||||||
break;
|
};
|
||||||
case Hobby:
|
|
||||||
fb = LiveFormula.searchForHobby(players, eid);
|
|
||||||
break;
|
|
||||||
case Health:
|
|
||||||
fb = LiveFormula.searchForHealth(players, eid);
|
|
||||||
break;
|
|
||||||
case Luggage:
|
|
||||||
fb = LiveFormula.searchForLuggage(players, eid);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return fb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean searchForBio(List<Player> players, Long id) {
|
private static Boolean searchForBio(List<Player> players, Long id) {
|
||||||
|
33
src/main/java/com/alterdekim/javabot/bot/SectionType.java
Normal file
33
src/main/java/com/alterdekim/javabot/bot/SectionType.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.alterdekim.javabot.bot;
|
||||||
|
|
||||||
|
import com.alterdekim.javabot.Constants;
|
||||||
|
import com.alterdekim.javabot.util.HashUtils;
|
||||||
|
|
||||||
|
public enum SectionType {
|
||||||
|
GENDER(Constants.GENDER_BTN, true), // Also called "bio" in some cases
|
||||||
|
HEALTH(Constants.HEALTH_BTN, true),
|
||||||
|
HOBBY(Constants.HOBBY_BTN, true),
|
||||||
|
LUGGAGE(Constants.LUGG_BTN, true),
|
||||||
|
WORK(Constants.WORK_BTN, true),
|
||||||
|
AGE(Constants.AGE_BTN, false),
|
||||||
|
UNKNOWN("", false);
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final Boolean dbAppearance;
|
||||||
|
|
||||||
|
SectionType(String name, Boolean dbAppearance) {
|
||||||
|
this.name = name;
|
||||||
|
this.dbAppearance = dbAppearance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHash() {
|
||||||
|
return HashUtils.getCRC32(this.name.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SectionType fromHash( String hash ) {
|
||||||
|
for( SectionType b : values() ) {
|
||||||
|
if( b.getHash().equals(hash) ) return b;
|
||||||
|
}
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
@ -235,11 +235,10 @@ public class BunkerBot extends TelegramLongPollingBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setScriptMessageId(Player p, Integer messageId) {
|
private void setScriptMessageId(Player p, Integer messageId) {
|
||||||
IntStream.range(0, players.size()).forEach(i -> {
|
IntStream.range(0, players.size())
|
||||||
if( players.get(i).getTelegramId().longValue() == p.getTelegramId().longValue() ) {
|
.boxed()
|
||||||
players.get(i).setScriptMessageId(messageId);
|
.filter(i -> players.get(i).getTelegramId().longValue() == p.getTelegramId().longValue())
|
||||||
}
|
.forEach(i -> players.get(i).setScriptMessageId(messageId));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getStringById(Long id) {
|
private String getStringById(Long id) {
|
||||||
@ -281,46 +280,42 @@ public class BunkerBot extends TelegramLongPollingBot {
|
|||||||
!getPlayerById(callbackQuery.getFrom().getId()).getIsAnswered() ) {
|
!getPlayerById(callbackQuery.getFrom().getId()).getIsAnswered() ) {
|
||||||
Player p = getPlayerById(callbackQuery.getFrom().getId());
|
Player p = getPlayerById(callbackQuery.getFrom().getId());
|
||||||
InfoSections ins = p.getInfoSections();
|
InfoSections ins = p.getInfoSections();
|
||||||
switch(BioButtons.fromHash(callbackQuery.getData())) {
|
SectionType curSection = SectionType.fromHash(callbackQuery.getData());
|
||||||
|
switch(curSection) {
|
||||||
case GENDER:
|
case GENDER:
|
||||||
dayNightFields.appendMessage(String.format(Constants.GENDER_MESAGE, callbackQuery.getFrom().getFirstName(), getStringById(p.getGender().getGenderTextId()),
|
dayNightFields.appendMessage(String.format(Constants.GENDER_MESAGE, callbackQuery.getFrom().getFirstName(), getStringById(p.getGender().getGenderTextId()),
|
||||||
p.getGender().getCanDie() ? Constants.TRUE : Constants.FALSE,
|
p.getGender().getCanDie() ? Constants.TRUE : Constants.FALSE,
|
||||||
p.getGender().getIsMale() ? Constants.TRUE : Constants.FALSE,
|
p.getGender().getIsMale() ? Constants.TRUE : Constants.FALSE,
|
||||||
p.getGender().getIsFemale() ? Constants.TRUE : Constants.FALSE) + "\n");
|
p.getGender().getIsFemale() ? Constants.TRUE : Constants.FALSE) + "\n");
|
||||||
ins.setIsGenderShowed(true);
|
|
||||||
break;
|
break;
|
||||||
case HEALTH:
|
case HEALTH:
|
||||||
dayNightFields.appendMessage(String.format(Constants.HEALTH_MESSAGE, callbackQuery.getFrom().getFirstName(), getStringById(p.getHealth().getTextNameId()),
|
dayNightFields.appendMessage(String.format(Constants.HEALTH_MESSAGE, callbackQuery.getFrom().getFirstName(), getStringById(p.getHealth().getTextNameId()),
|
||||||
getStringById(p.getHealth().getTextDescId()),
|
getStringById(p.getHealth().getTextDescId()),
|
||||||
(int) (p.getHealth().getHealth_index()*100f),
|
(int) (p.getHealth().getHealth_index()*100f),
|
||||||
p.getHealth().getIsChildfree() ? Constants.TRUE : Constants.FALSE) + "\n");
|
p.getHealth().getIsChildfree() ? Constants.TRUE : Constants.FALSE) + "\n");
|
||||||
ins.setIsHealthShowed(true);
|
|
||||||
break;
|
break;
|
||||||
case AGE:
|
case AGE:
|
||||||
dayNightFields.appendMessage(String.format(Constants.AGE_MESSAGE, callbackQuery.getFrom().getFirstName(), p.getAge()) + "\n");
|
dayNightFields.appendMessage(String.format(Constants.AGE_MESSAGE, callbackQuery.getFrom().getFirstName(), p.getAge()) + "\n");
|
||||||
ins.setIsAgeShowed(true);
|
|
||||||
break;
|
break;
|
||||||
case HOBBY:
|
case HOBBY:
|
||||||
dayNightFields.appendMessage(String.format(Constants.HOBBY_MESSAGE, callbackQuery.getFrom().getFirstName(),
|
dayNightFields.appendMessage(String.format(Constants.HOBBY_MESSAGE, callbackQuery.getFrom().getFirstName(),
|
||||||
getStringById(p.getHobby().getTextDescId())) + "\n");
|
getStringById(p.getHobby().getTextDescId())) + "\n");
|
||||||
ins.setIsHobbyShowed(true);
|
|
||||||
break;
|
break;
|
||||||
case LUGGAGE:
|
case LUGGAGE:
|
||||||
dayNightFields.appendMessage(String.format(Constants.LUGG_MESSAGE, callbackQuery.getFrom().getFirstName(),
|
dayNightFields.appendMessage(String.format(Constants.LUGG_MESSAGE, callbackQuery.getFrom().getFirstName(),
|
||||||
getStringById(p.getLuggage().getTextNameId()),
|
getStringById(p.getLuggage().getTextNameId()),
|
||||||
getStringById(p.getLuggage().getTextDescId())) + "\n");
|
getStringById(p.getLuggage().getTextDescId())) + "\n");
|
||||||
ins.setIsLuggageShowed(true);
|
|
||||||
break;
|
break;
|
||||||
case WORK:
|
case WORK:
|
||||||
dayNightFields.appendMessage(String.format(Constants.WORK_MESSAGE, callbackQuery.getFrom().getFirstName(),
|
dayNightFields.appendMessage(String.format(Constants.WORK_MESSAGE, callbackQuery.getFrom().getFirstName(),
|
||||||
getStringById(p.getWork().getTextNameId()),
|
getStringById(p.getWork().getTextNameId()),
|
||||||
getStringById(p.getWork().getTextDescId())) + "\n");
|
getStringById(p.getWork().getTextDescId())) + "\n");
|
||||||
ins.setIsWorkShowed(true);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
processNightScriptButton(p, callbackQuery, callbackQuery.getData());
|
processNightScriptButton(p, callbackQuery, callbackQuery.getData());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ins.pushShowedState(curSection);
|
||||||
setIsAnswered(callbackQuery.getFrom().getId());
|
setIsAnswered(callbackQuery.getFrom().getId());
|
||||||
updateInfoSections(p, ins);
|
updateInfoSections(p, ins);
|
||||||
sendApi(new SendMessage(callbackQuery.getMessage().getChatId()+"", Constants.THANK_YOU));
|
sendApi(new SendMessage(callbackQuery.getMessage().getChatId()+"", Constants.THANK_YOU));
|
||||||
@ -404,41 +399,28 @@ public class BunkerBot extends TelegramLongPollingBot {
|
|||||||
message.append(p.getFirstName());
|
message.append(p.getFirstName());
|
||||||
message.append(":\n");
|
message.append(":\n");
|
||||||
InfoSections s = p.getInfoSections();
|
InfoSections s = p.getInfoSections();
|
||||||
if(s.getIsGenderShowed()) {
|
s.getSections().forEach(s1 -> {
|
||||||
message.append(String.format(Constants.GENDER_MESAGE, p.getFirstName(), getStringById(p.getGender().getGenderTextId()),
|
switch (s1.getType()) {
|
||||||
p.getGender().getCanDie() ? Constants.TRUE : Constants.FALSE,
|
case GENDER -> message.append(String.format(Constants.GENDER_MESAGE, p.getFirstName(), getStringById(p.getGender().getGenderTextId()),
|
||||||
p.getGender().getIsMale() ? Constants.TRUE : Constants.FALSE,
|
p.getGender().getCanDie() ? Constants.TRUE : Constants.FALSE,
|
||||||
p.getGender().getIsFemale() ? Constants.TRUE : Constants.FALSE));
|
p.getGender().getIsMale() ? Constants.TRUE : Constants.FALSE,
|
||||||
|
p.getGender().getIsFemale() ? Constants.TRUE : Constants.FALSE));
|
||||||
|
case AGE -> message.append(String.format(Constants.AGE_MESSAGE, p.getFirstName(), p.getAge()));
|
||||||
|
case LUGGAGE -> message.append(String.format(Constants.LUGG_MESSAGE, p.getFirstName(),
|
||||||
|
getStringById(p.getLuggage().getTextNameId()),
|
||||||
|
getStringById(p.getLuggage().getTextDescId())));
|
||||||
|
case HEALTH -> message.append(String.format(Constants.HEALTH_MESSAGE, p.getFirstName(), getStringById(p.getHealth().getTextNameId()),
|
||||||
|
getStringById(p.getHealth().getTextDescId()),
|
||||||
|
(int) (p.getHealth().getHealth_index()*100f),
|
||||||
|
p.getHealth().getIsChildfree() ? Constants.TRUE : Constants.FALSE));
|
||||||
|
case WORK -> message.append(String.format(Constants.WORK_MESSAGE, p.getFirstName(),
|
||||||
|
getStringById(p.getWork().getTextNameId()),
|
||||||
|
getStringById(p.getWork().getTextDescId())));
|
||||||
|
case HOBBY -> message.append(String.format(Constants.HOBBY_MESSAGE, p.getFirstName(),
|
||||||
|
getStringById(p.getHobby().getTextDescId())));
|
||||||
|
}
|
||||||
message.append("\n");
|
message.append("\n");
|
||||||
}
|
});
|
||||||
if(s.getIsAgeShowed()) {
|
|
||||||
message.append(String.format(Constants.AGE_MESSAGE, p.getFirstName(), p.getAge()));
|
|
||||||
message.append("\n");
|
|
||||||
}
|
|
||||||
if(s.getIsLuggageShowed()) {
|
|
||||||
message.append(String.format(Constants.LUGG_MESSAGE, p.getFirstName(),
|
|
||||||
getStringById(p.getLuggage().getTextNameId()),
|
|
||||||
getStringById(p.getLuggage().getTextDescId())));
|
|
||||||
message.append("\n");
|
|
||||||
}
|
|
||||||
if(s.getIsHealthShowed()) {
|
|
||||||
message.append(String.format(Constants.HEALTH_MESSAGE, p.getFirstName(), getStringById(p.getHealth().getTextNameId()),
|
|
||||||
getStringById(p.getHealth().getTextDescId()),
|
|
||||||
(int) (p.getHealth().getHealth_index()*100f),
|
|
||||||
p.getHealth().getIsChildfree() ? Constants.TRUE : Constants.FALSE));
|
|
||||||
message.append("\n");
|
|
||||||
}
|
|
||||||
if(s.getIsWorkShowed()) {
|
|
||||||
message.append(String.format(Constants.WORK_MESSAGE, p.getFirstName(),
|
|
||||||
getStringById(p.getWork().getTextNameId()),
|
|
||||||
getStringById(p.getWork().getTextDescId())));
|
|
||||||
message.append("\n");
|
|
||||||
}
|
|
||||||
if(s.getIsHobbyShowed()) {
|
|
||||||
message.append(String.format(Constants.HOBBY_MESSAGE, p.getFirstName(),
|
|
||||||
getStringById(p.getHobby().getTextDescId())));
|
|
||||||
message.append("\n");
|
|
||||||
}
|
|
||||||
message.append("\n");
|
message.append("\n");
|
||||||
}
|
}
|
||||||
sendApi(new SendMessage(groupId, message.toString()));
|
sendApi(new SendMessage(groupId, message.toString()));
|
||||||
@ -539,6 +521,7 @@ public class BunkerBot extends TelegramLongPollingBot {
|
|||||||
|
|
||||||
String chatId = update.getMessage().getChatId()+"";
|
String chatId = update.getMessage().getChatId()+"";
|
||||||
|
|
||||||
|
// TODO: state-based refactoring (reduce IF count)
|
||||||
if( ( update.getMessage().getText().equals(Commands.SET_GROUP + "@" + getBotUsername()) ||
|
if( ( update.getMessage().getText().equals(Commands.SET_GROUP + "@" + getBotUsername()) ||
|
||||||
update.getMessage().getText().equals(Commands.SET_GROUP)) &&
|
update.getMessage().getText().equals(Commands.SET_GROUP)) &&
|
||||||
update.getMessage().getFrom().getId().equals(getMasterId()) && gameState == GameState.NONE) {
|
update.getMessage().getFrom().getId().equals(getMasterId()) && gameState == GameState.NONE) {
|
||||||
@ -548,6 +531,7 @@ public class BunkerBot extends TelegramLongPollingBot {
|
|||||||
|
|
||||||
if( !chatId.equals(groupId) ) return;
|
if( !chatId.equals(groupId) ) return;
|
||||||
|
|
||||||
|
// TODO: state-based refactoring (reduce IF count)
|
||||||
if ( (update.getMessage().getText().equals(Commands.START_GAME + "@" + getBotUsername()) ||
|
if ( (update.getMessage().getText().equals(Commands.START_GAME + "@" + getBotUsername()) ||
|
||||||
update.getMessage().getText().equals(Commands.START_GAME) ) &&
|
update.getMessage().getText().equals(Commands.START_GAME) ) &&
|
||||||
gameState == GameState.NONE) {
|
gameState == GameState.NONE) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.alterdekim.javabot.controller;
|
package com.alterdekim.javabot.controller;
|
||||||
|
|
||||||
|
import com.alterdekim.javabot.bot.SectionType;
|
||||||
import com.alterdekim.javabot.dto.SynergyResult;
|
import com.alterdekim.javabot.dto.SynergyResult;
|
||||||
import com.alterdekim.javabot.entities.*;
|
import com.alterdekim.javabot.entities.*;
|
||||||
import com.alterdekim.javabot.service.*;
|
import com.alterdekim.javabot.service.*;
|
||||||
@ -115,7 +116,7 @@ public class DatabaseController {
|
|||||||
|
|
||||||
@PostMapping("/api/remove_synergy")
|
@PostMapping("/api/remove_synergy")
|
||||||
public String remove_synergy(@RequestParam Map<String, String> params) {
|
public String remove_synergy(@RequestParam Map<String, String> params) {
|
||||||
Long id = Long.parseLong(params.get("synergy_id"));
|
long id = Long.parseLong(params.get("synergy_id"));
|
||||||
synergyService.removeById(id);
|
synergyService.removeById(id);
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
@ -123,9 +124,9 @@ public class DatabaseController {
|
|||||||
@PostMapping("/api/add_synergy")
|
@PostMapping("/api/add_synergy")
|
||||||
public String add_synergy(@RequestParam Map<String, String> params) {
|
public String add_synergy(@RequestParam Map<String, String> params) {
|
||||||
Long feid = Long.parseLong(params.get("first_entity_id"));
|
Long feid = Long.parseLong(params.get("first_entity_id"));
|
||||||
ColumnType fetype = ColumnType.values()[Integer.parseInt(params.get("first_entity_type"))];
|
SectionType fetype = SectionType.values()[Integer.parseInt(params.get("first_entity_type"))];
|
||||||
Long seid = Long.parseLong(params.get("second_entity_id"));
|
Long seid = Long.parseLong(params.get("second_entity_id"));
|
||||||
ColumnType setype = ColumnType.values()[Integer.parseInt(params.get("second_entity_type"))];
|
SectionType setype = SectionType.values()[Integer.parseInt(params.get("second_entity_type"))];
|
||||||
Float probability = Float.parseFloat(params.get("probability"));
|
Float probability = Float.parseFloat(params.get("probability"));
|
||||||
|
|
||||||
synergyService.saveSynergy(new Synergy(feid, fetype, seid, setype, probability));
|
synergyService.saveSynergy(new Synergy(feid, fetype, seid, setype, probability));
|
||||||
@ -139,24 +140,14 @@ public class DatabaseController {
|
|||||||
String section = params.get("entity_type");
|
String section = params.get("entity_type");
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
try {
|
try {
|
||||||
List<Synergy> synergyList = new ArrayList<>();
|
List<Synergy> synergyList = switch (section) {
|
||||||
switch (section) {
|
case "agge" -> bioService.getSynergies(id);
|
||||||
case "agge":
|
case "lugg" -> luggageService.getSynergies(id);
|
||||||
synergyList = bioService.getSynergies(id);
|
case "prof" -> workService.getSynergies(id);
|
||||||
break;
|
case "heal" -> healthService.getSynergies(id);
|
||||||
case "lugg":
|
case "hobb" -> hobbyService.getSynergies(id);
|
||||||
synergyList = luggageService.getSynergies(id);
|
default -> new ArrayList<>();
|
||||||
break;
|
};
|
||||||
case "prof":
|
|
||||||
synergyList = workService.getSynergies(id);
|
|
||||||
break;
|
|
||||||
case "heal":
|
|
||||||
synergyList = healthService.getSynergies(id);
|
|
||||||
break;
|
|
||||||
case "hobb":
|
|
||||||
synergyList = hobbyService.getSynergies(id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
List<SynergyResult> results = new ArrayList<>();
|
List<SynergyResult> results = new ArrayList<>();
|
||||||
for( Synergy s : synergyList ) {
|
for( Synergy s : synergyList ) {
|
||||||
String textFirst = getText(s.getFirstType(), s.getFirstEntityId());
|
String textFirst = getText(s.getFirstType(), s.getFirstEntityId());
|
||||||
@ -170,20 +161,15 @@ public class DatabaseController {
|
|||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getText(ColumnType type, Long feid) {
|
private String getText(SectionType type, Long feid) {
|
||||||
switch (type) {
|
return switch (type) {
|
||||||
case Bio:
|
case GENDER -> textDataValService.getTextDataValById(bioService.getBioById(feid).getGenderTextId()).getText();
|
||||||
return textDataValService.getTextDataValById(bioService.getBioById(feid).getGenderTextId()).getText();
|
case HEALTH -> textDataValService.getTextDataValById(healthService.getHealthById(feid).getTextNameId()).getText();
|
||||||
case Health:
|
case HOBBY -> textDataValService.getTextDataValById(hobbyService.getHobbyById(feid).getTextDescId()).getText();
|
||||||
return textDataValService.getTextDataValById(healthService.getHealthById(feid).getTextNameId()).getText();
|
case LUGGAGE -> textDataValService.getTextDataValById(luggageService.getLuggageById(feid).getTextNameId()).getText();
|
||||||
case Hobby:
|
case WORK -> textDataValService.getTextDataValById(workService.getWorkById(feid).getTextNameId()).getText();
|
||||||
return textDataValService.getTextDataValById(hobbyService.getHobbyById(feid).getTextDescId()).getText();
|
default -> "";
|
||||||
case Luggage:
|
};
|
||||||
return textDataValService.getTextDataValById(luggageService.getLuggageById(feid).getTextNameId()).getText();
|
|
||||||
case Work:
|
|
||||||
return textDataValService.getTextDataValById(workService.getWorkById(feid).getTextNameId()).getText();
|
|
||||||
}
|
|
||||||
return "-";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/api/add_entry")
|
@PostMapping("/api/add_entry")
|
||||||
@ -191,30 +177,13 @@ public class DatabaseController {
|
|||||||
/* additional data, disasters */
|
/* additional data, disasters */
|
||||||
String section = params.get("section");
|
String section = params.get("section");
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case "agge":
|
case "agge" -> saveGender(params);
|
||||||
saveGender(params);
|
case "lugg" -> saveLuggage(params);
|
||||||
break;
|
case "prof" -> saveWork(params);
|
||||||
case "lugg":
|
case "heal" -> saveHealth(params);
|
||||||
saveLuggage(params);
|
case "hobb" -> saveHobby(params);
|
||||||
break;
|
case "actions" -> saveAction(params);
|
||||||
case "prof":
|
default -> saveDiss(params);
|
||||||
saveWork(params);
|
|
||||||
break;
|
|
||||||
case "heal":
|
|
||||||
saveHealth(params);
|
|
||||||
break;
|
|
||||||
case "hobb":
|
|
||||||
saveHobby(params);
|
|
||||||
break;
|
|
||||||
case "diss":
|
|
||||||
saveDiss(params);
|
|
||||||
break;
|
|
||||||
case "actions":
|
|
||||||
saveAction(params);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
saveDiss(params);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
@ -224,30 +193,13 @@ public class DatabaseController {
|
|||||||
String section = params.get("section");
|
String section = params.get("section");
|
||||||
long entry_id = Long.parseLong(params.get("entry_id"));
|
long entry_id = Long.parseLong(params.get("entry_id"));
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case "agge":
|
case "agge" -> bioService.removeById(entry_id);
|
||||||
bioService.removeById(entry_id);
|
case "hobb" -> hobbyService.removeById(entry_id);
|
||||||
break;
|
case "lugg" -> luggageService.removeById(entry_id);
|
||||||
case "hobb":
|
case "heal" -> healthService.removeById(entry_id);
|
||||||
hobbyService.removeById(entry_id);
|
case "prof" -> workService.removeById(entry_id);
|
||||||
break;
|
case "actions" -> actionService.removeById(entry_id);
|
||||||
case "lugg":
|
default -> disasterService.removeById(entry_id);
|
||||||
luggageService.removeById(entry_id);
|
|
||||||
break;
|
|
||||||
case "heal":
|
|
||||||
healthService.removeById(entry_id);
|
|
||||||
break;
|
|
||||||
case "prof":
|
|
||||||
workService.removeById(entry_id);
|
|
||||||
break;
|
|
||||||
case "diss":
|
|
||||||
disasterService.removeById(entry_id);
|
|
||||||
break;
|
|
||||||
case "actions":
|
|
||||||
actionService.removeById(entry_id);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
disasterService.removeById(entry_id);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
@ -262,24 +214,15 @@ public class DatabaseController {
|
|||||||
public String getEntries(@RequestParam Map<String, String> params) {
|
public String getEntries(@RequestParam Map<String, String> params) {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
try {
|
try {
|
||||||
switch (params.get("section")) {
|
return switch (params.get("section")) {
|
||||||
case "agge":
|
case "agge" -> mapper.writeValueAsString(bioService.getAllBios());
|
||||||
return mapper.writeValueAsString(bioService.getAllBios());
|
case "hobb" -> mapper.writeValueAsString(hobbyService.getAllHobbies());
|
||||||
case "hobb":
|
case "prof" -> mapper.writeValueAsString(workService.getAllWorks());
|
||||||
return mapper.writeValueAsString(hobbyService.getAllHobbies());
|
case "heal" -> mapper.writeValueAsString(healthService.getAllHealth());
|
||||||
case "prof":
|
case "lugg" -> mapper.writeValueAsString(luggageService.getAllLuggages());
|
||||||
return mapper.writeValueAsString(workService.getAllWorks());
|
case "actions" -> mapper.writeValueAsString(actionService.getAllActionScripts());
|
||||||
case "heal":
|
default -> mapper.writeValueAsString(disasterService.getAllDisasters());
|
||||||
return mapper.writeValueAsString(healthService.getAllHealth());
|
};
|
||||||
case "lugg":
|
|
||||||
return mapper.writeValueAsString(luggageService.getAllLuggages());
|
|
||||||
case "diss":
|
|
||||||
return mapper.writeValueAsString(disasterService.getAllDisasters());
|
|
||||||
case "actions":
|
|
||||||
return mapper.writeValueAsString(actionService.getAllActionScripts());
|
|
||||||
default:
|
|
||||||
return mapper.writeValueAsString(disasterService.getAllDisasters());
|
|
||||||
}
|
|
||||||
} catch (JacksonException e) {
|
} catch (JacksonException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
@ -291,24 +234,15 @@ public class DatabaseController {
|
|||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
long l = Long.parseLong(params.get("entry_id"));
|
long l = Long.parseLong(params.get("entry_id"));
|
||||||
try {
|
try {
|
||||||
switch (params.get("section")) {
|
return switch (params.get("section")) {
|
||||||
case "agge":
|
case "agge" -> mapper.writeValueAsString(bioService.getBioById(l));
|
||||||
return mapper.writeValueAsString(bioService.getBioById(l));
|
case "hobb" -> mapper.writeValueAsString(hobbyService.getHobbyById(l));
|
||||||
case "hobb":
|
case "prof" -> mapper.writeValueAsString(workService.getWorkById(l));
|
||||||
return mapper.writeValueAsString(hobbyService.getHobbyById(l));
|
case "heal" -> mapper.writeValueAsString(healthService.getHealthById(l));
|
||||||
case "prof":
|
case "lugg" -> mapper.writeValueAsString(luggageService.getLuggageById(l));
|
||||||
return mapper.writeValueAsString(workService.getWorkById(l));
|
case "actions" -> mapper.writeValueAsString(actionService.getActionScriptById(l));
|
||||||
case "heal":
|
default -> mapper.writeValueAsString(disasterService.getDisasterById(l));
|
||||||
return mapper.writeValueAsString(healthService.getHealthById(l));
|
};
|
||||||
case "lugg":
|
|
||||||
return mapper.writeValueAsString(luggageService.getLuggageById(l));
|
|
||||||
case "diss":
|
|
||||||
return mapper.writeValueAsString(disasterService.getDisasterById(l));
|
|
||||||
case "actions":
|
|
||||||
return mapper.writeValueAsString(actionService.getActionScriptById(l));
|
|
||||||
default:
|
|
||||||
return mapper.writeValueAsString(disasterService.getDisasterById(l));
|
|
||||||
}
|
|
||||||
} catch (JacksonException e) {
|
} catch (JacksonException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.alterdekim.javabot.dto;
|
package com.alterdekim.javabot.dto;
|
||||||
|
|
||||||
import com.alterdekim.javabot.entities.ColumnType;
|
import com.alterdekim.javabot.bot.SectionType;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -12,7 +12,7 @@ public class SynergyResult {
|
|||||||
private Long id;
|
private Long id;
|
||||||
private String firstEntityText;
|
private String firstEntityText;
|
||||||
private String secondEntityText;
|
private String secondEntityText;
|
||||||
private ColumnType firstType;
|
private SectionType firstType;
|
||||||
private ColumnType secondType;
|
private SectionType secondType;
|
||||||
private Float probabilityValue;
|
private Float probabilityValue;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package com.alterdekim.javabot.entities;
|
|
||||||
|
|
||||||
public enum ColumnType {
|
|
||||||
Bio,
|
|
||||||
Health,
|
|
||||||
Hobby,
|
|
||||||
Luggage,
|
|
||||||
Work
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
package com.alterdekim.javabot.entities;
|
package com.alterdekim.javabot.entities;
|
||||||
|
|
||||||
|
import com.alterdekim.javabot.bot.SectionType;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -21,18 +22,18 @@ public class Synergy {
|
|||||||
private Long firstEntityId;
|
private Long firstEntityId;
|
||||||
|
|
||||||
@Enumerated(EnumType.ORDINAL)
|
@Enumerated(EnumType.ORDINAL)
|
||||||
private ColumnType firstType;
|
private SectionType firstType;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Long secondEntityId;
|
private Long secondEntityId;
|
||||||
|
|
||||||
@Enumerated(EnumType.ORDINAL)
|
@Enumerated(EnumType.ORDINAL)
|
||||||
private ColumnType secondType;
|
private SectionType secondType;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Float probabilityValue;
|
private Float probabilityValue;
|
||||||
|
|
||||||
public Synergy(Long firstEntityId, ColumnType firstType, Long secondEntityId, ColumnType secondType, Float probabilityValue) {
|
public Synergy(Long firstEntityId, SectionType firstType, Long secondEntityId, SectionType secondType, Float probabilityValue) {
|
||||||
this.firstEntityId = firstEntityId;
|
this.firstEntityId = firstEntityId;
|
||||||
this.firstType = firstType;
|
this.firstType = firstType;
|
||||||
this.secondEntityId = secondEntityId;
|
this.secondEntityId = secondEntityId;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user