Browse Source

пельмень апдейт

master
gsd 4 days ago
parent
commit
bc50b41f9f
  1. 15
      src/main/java/app/configurations/DbRwConfigurarion.java
  2. 32
      src/main/java/app/controllers/user/MessagesController.java
  3. 2
      src/main/java/app/entities/Killfeed.java
  4. 3
      src/main/java/app/entities/PlayerProfile.java
  5. 21
      src/main/java/app/entities/db/AdminInfo.java
  6. 41
      src/main/java/app/entities/db/Ban.java
  7. 29
      src/main/java/app/entities/db/CollectableStatistic.java
  8. 32
      src/main/java/app/entities/db/DonateStat.java
  9. 37
      src/main/java/app/entities/db/ErrorDb.java
  10. 30
      src/main/java/app/entities/db/Permition.java
  11. 27
      src/main/java/app/entities/db/PromoCode.java
  12. 17
      src/main/java/app/entities/db/converter/SteamIdSteam64Converter.java
  13. 67
      src/main/java/app/entities/messages/Message.java
  14. 47
      src/main/java/app/entities/messages/MessageSearch.java
  15. 26
      src/main/java/app/repositories/MessageRepository.java
  16. 5
      src/main/java/app/services/ProfileService.java
  17. 45
      src/main/java/app/services/db/MessageService.java

15
src/main/java/app/configurations/DbRwConfigurarion.java

@ -4,15 +4,14 @@ import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
@ -25,7 +24,7 @@ import java.util.HashMap;
* конфигурация которая используется для создание ждбсТеплейта который будет доступен как для чтения так и для записи * конфигурация которая используется для создание ждбсТеплейта который будет доступен как для чтения так и для записи
*/ */
@Configuration @Configuration
@EnableJpaRepositories(basePackages = "app.entities.dummy.rw", entityManagerFactoryRef = "RwEntityManager", transactionManagerRef = "RwTransactionManager") @EnableJpaRepositories(basePackages = "app", entityManagerFactoryRef = "RwEntityManager", transactionManagerRef = "RwTransactionManager")
public class DbRwConfigurarion implements DbConfiguration{ public class DbRwConfigurarion implements DbConfiguration{
@Autowired @Autowired
@ -36,12 +35,14 @@ public class DbRwConfigurarion implements DbConfiguration{
@Bean(name = "RwDataSourceProperties") @Bean(name = "RwDataSourceProperties")
@Scope(value = "singleton") @Scope(value = "singleton")
@ConfigurationProperties(prefix = "backend.db.rw") @ConfigurationProperties(prefix = "backend.db.rw")
@Primary
public DataSourceProperties DataSourceProperties() { public DataSourceProperties DataSourceProperties() {
return new DataSourceProperties(); return new DataSourceProperties();
} }
@Bean(name = "RwDataSource") @Bean(name = "RwDataSource")
@Scope(value = "singleton") @Scope(value = "singleton")
@Primary
public DataSource DataSource() { public DataSource DataSource() {
HikariDataSource dataSource = DataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); HikariDataSource dataSource = DataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
dataSource.setReadOnly(false); dataSource.setReadOnly(false);
@ -50,10 +51,11 @@ public class DbRwConfigurarion implements DbConfiguration{
@Bean(name = "RwEntityManager") @Bean(name = "RwEntityManager")
@Scope(value = "singleton") @Scope(value = "singleton")
@Primary
public LocalContainerEntityManagerFactoryBean EntityManager() { public LocalContainerEntityManagerFactoryBean EntityManager() {
LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean(); LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
entityManager.setDataSource(DataSource()); entityManager.setDataSource(DataSource());
entityManager.setPackagesToScan("app.entities.dummy.rw"); entityManager.setPackagesToScan("app");
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
entityManager.setJpaVendorAdapter(vendorAdapter); entityManager.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<>(); HashMap<String, Object> properties = new HashMap<>();
@ -64,6 +66,7 @@ public class DbRwConfigurarion implements DbConfiguration{
@Bean(name = "RwTransactionManager") @Bean(name = "RwTransactionManager")
@Scope(value = "singleton") @Scope(value = "singleton")
@Primary
public PlatformTransactionManager TransactionManager() { public PlatformTransactionManager TransactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager(); JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(EntityManager().getObject()); transactionManager.setEntityManagerFactory(EntityManager().getObject());

32
src/main/java/app/controllers/user/MessagesController.java

@ -4,7 +4,11 @@ import app.annotations.enums.AuthMethod;
import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CheckWebAccess;
import app.annotations.interfaces.CollectStatistic; import app.annotations.interfaces.CollectStatistic;
import app.annotations.interfaces.WaitAfterNext; import app.annotations.interfaces.WaitAfterNext;
import app.entities.messages.Message;
import app.entities.messages.MessageSearch;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.repositories.MessageRepository;
import app.services.ProfileService;
import app.services.db.MessageService; import app.services.db.MessageService;
import app.utils.SteamIDConverter; import app.utils.SteamIDConverter;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -26,11 +30,18 @@ import java.util.Map;
@RestController @RestController
@RequestMapping("/api/profile/messages") @RequestMapping("/api/profile/messages")
public class MessagesController { public class MessagesController {
private MessageService messageService; private MessageService messageService;
private MessageRepository messageRepository;
private ProfileService profileService;
@Autowired @Autowired
MessagesController(MessageService messageService) { public MessagesController(MessageService messageService, MessageRepository messageRepository, ProfileService profileService) {
this.messageService = messageService; this.messageService = messageService;
this.messageRepository = messageRepository;
this.profileService = profileService;
} }
@PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE}) @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE})
@ -51,15 +62,16 @@ public class MessagesController {
@CheckWebAccess(auth_method = AuthMethod.STEAM64) @CheckWebAccess(auth_method = AuthMethod.STEAM64)
@WaitAfterNext(order = "messages") @WaitAfterNext(order = "messages")
@CollectStatistic @CollectStatistic
public ResponseEntity<Page<MessageService.Message>> getMessagesWithFilters(Pageable pageable, public Page<Message> getMessagesWithFilters(Pageable pageable,
@RequestBody(required = false) Payload filter, @RequestBody(required = false) MessageSearch filter) {
@RequestParam(required = false) String srv) { if (filter == null) filter = new MessageSearch();
if (pageable.getPageSize() > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); return messageRepository.getMessages(
pageable,
Map result = messageService.getAllMessages(srv, filter==null?null:filter.getMessage(), pageable.getOffset(), pageable.getPageSize()); filter.getAccounts(profileService),
return new ResponseEntity<>( filter.getBegin(),
new PageImpl<MessageService.Message>((List<MessageService.Message>) result.get("result"), pageable, (Long) result.get("count")), filter.getEnd(),
HttpStatus.OK filter.getMessage(),
filter.getServerId()
); );
} }

2
src/main/java/app/entities/db/Killfeed.java → src/main/java/app/entities/Killfeed.java

@ -1,4 +1,4 @@
package app.entities.db; package app.entities;
import lombok.Data; import lombok.Data;

3
src/main/java/app/entities/PlayerProfile.java

@ -2,14 +2,11 @@ package app.entities;
import app.entities.db.Ban; import app.entities.db.Ban;
import app.entities.db.DonateStat; import app.entities.db.DonateStat;
import app.entities.db.Killfeed;
import app.entities.db.Permition; import app.entities.db.Permition;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.entities.report.ReportCount; import app.entities.report.ReportCount;
import app.entities.server.PlayOn; import app.entities.server.PlayOn;
import app.entities.steam.SteamData; import app.entities.steam.SteamData;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;

21
src/main/java/app/entities/db/AdminInfo.java

@ -2,6 +2,10 @@ package app.entities.db;
import app.utils.SteamIDConverter; import app.utils.SteamIDConverter;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -18,16 +22,29 @@ CREATE TABLE `bot_admins` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
*/ */
@Data @Data
@Entity
@Table(name = "bot_admins", schema = "tf2_facti13")
public class AdminInfo { public class AdminInfo {
@JsonIgnore @JsonIgnore
@Id
@Column(name = "id")
int id; int id;
@Column(name = "vk_id", nullable = false)
int vk_id; int vk_id;
@Column(name = "discord_id", nullable = false)
long discord_id; long discord_id;
@Column(name = "discord_name", nullable = false)
String discord_name; String discord_name;
@Column(name = "steam3", nullable = false)
@JsonIgnore @JsonIgnore
String steam3; String steam3;
String steam_url; String steam_url;
@JsonIgnore @JsonIgnore
@Column(name = "permition", nullable = false)
int permition; int permition;
public AdminInfo(Object[] obj) { public AdminInfo(Object[] obj) {
@ -49,4 +66,8 @@ public class AdminInfo {
permition = resultSet.getInt("permition"); permition = resultSet.getInt("permition");
steam_url = SteamIDConverter.getSteamID(steam3).community_url; steam_url = SteamIDConverter.getSteamID(steam3).community_url;
} }
public AdminInfo() {
}
} }

41
src/main/java/app/entities/db/Ban.java

@ -5,6 +5,7 @@ import app.services.db.PermitionService;
import app.utils.CryptedCookie; import app.utils.CryptedCookie;
import app.utils.SteamIDConverter; import app.utils.SteamIDConverter;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data; import lombok.Data;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -30,23 +31,47 @@ CREATE TABLE `light_bans` (
*/ */
@Data @Data
@Entity
@Table(schema = "tf2_facti13", name = "light_bans")
public class Ban { public class Ban {
@Id
@Column(name = "id")
int id; int id;
@Column(name = "steam_id", length = 32)
String steam_id; String steam_id;
@Column(name = "account_id")
Long account_id; Long account_id;
@Column(name = "player_name", length = 65)
String player_name; String player_name;
@Column(name = "ban_length")
int ban_length; int ban_length;
long ban_length_seconds; @Transient
Long ban_length_seconds;
@Column(name = "ban_reason", length = 100)
String ban_reason; String ban_reason;
@Column(name = "banned_by", length = 100)
String banned_by; String banned_by;
@Column(name = "banned_by_id")
String banned_by_id; String banned_by_id;
@Column(name = "ip", length = 15)
String ip; String ip;
@Column(name = "timestamp")
Timestamp timestamp; Timestamp timestamp;
long ban_utime; @Transient
Long ban_utime;
@Column(name = "active")
boolean active; boolean active;
@Column(name = "unbanned_by_id", length = 32)
String unbanned_by_id; String unbanned_by_id;
@Column(name = "unbanned_timestamp")
Timestamp unbanned_timestamp; Timestamp unbanned_timestamp;
@ManyToOne
@JoinColumn(name = "banned_by_id", referencedColumnName = "steam3", insertable=false, updatable=false)
AdminInfo admin_info; AdminInfo admin_info;
@ManyToOne
@JoinColumn(name = "unbanned_by_id", referencedColumnName = "steam3", nullable = true, insertable=false, updatable=false)
AdminInfo unbanned_admin_info; AdminInfo unbanned_admin_info;
public Ban(Object[] obj) { public Ban(Object[] obj) {
@ -86,6 +111,18 @@ public class Ban {
} }
public Ban() {
}
public Long getBan_length_seconds() {
return ban_length_seconds == null ? ban_length * 60L : ban_length_seconds;
}
public long getBan_utime() {
return ban_utime == null ? timestamp.getTime() / 1000 : ban_utime;
}
public void cryptIP(CryptedCookie cryptedCookie) { public void cryptIP(CryptedCookie cryptedCookie) {
if (ip != null && !ip.isEmpty()) { if (ip != null && !ip.isEmpty()) {
ip = cryptedCookie.Hashed(ip); ip = cryptedCookie.Hashed(ip);

29
src/main/java/app/entities/db/CollectableStatistic.java

@ -1,5 +1,9 @@
package app.entities.db; package app.entities.db;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -9,17 +13,32 @@ import java.time.Instant;
import java.util.Arrays; import java.util.Arrays;
@Data @Data
@Entity
@Table(schema = "tf2_facti13", name = "web_statistic")
public class CollectableStatistic { public class CollectableStatistic {
@Id
@Column(name="id")
Long id; Long id;
@Column(name = "time")
Timestamp timestamp; Timestamp timestamp;
///
@Column(name = "client_ip", length = 64)
String client_ip; String client_ip;
@Column(name = "steam64", length = 64)
String steam64; String steam64;
///
@Column(name = "method", length = 16)
String method; String method;
@Column(name = "path", length = 512)
String path; String path;
@Column(name = "query", length = 512)
String query; String query;
///
@Column(name = "useragent", length = 512)
String useragent; String useragent;
public CollectableStatistic(HttpServletRequest request) { public CollectableStatistic(HttpServletRequest request) {
@ -33,6 +52,10 @@ public class CollectableStatistic {
this.timestamp = Timestamp.from(Instant.now()); this.timestamp = Timestamp.from(Instant.now());
} }
public CollectableStatistic() {
}
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

32
src/main/java/app/entities/db/DonateStat.java

@ -2,10 +2,12 @@ package app.entities.db;
import app.entities.VipGiveMethod; import app.entities.VipGiveMethod;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data; import lombok.Data;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
/* /*
CREATE TABLE `gived_vip` ( CREATE TABLE `gived_vip` (
@ -21,19 +23,39 @@ CREATE TABLE `gived_vip` (
*/ */
@Data @Data
@Entity
@Table(schema = "tf2_facti13", name = "gived_vip")
public class DonateStat { public class DonateStat {
@JsonIgnore @JsonIgnore
@Id
@Column(name = "id")
int id; int id;
@JsonIgnore @JsonIgnore
@Column(name = "steam2")
String steam2; String steam2;
@Column(name = "amount")
int amount; int amount;
@Column(name = "givemethod")
@Enumerated(value = EnumType.ORDINAL)
@JsonIgnore @JsonIgnore
VipGiveMethod giveMethod; VipGiveMethod giveMethod;
@JsonIgnore @JsonIgnore
@Column(name = "reserved", length = 65)
String reserved; String reserved;
@JsonIgnore @JsonIgnore
@Column(name = "extend")
boolean extended; boolean extended;
long utime;
@Transient
Long utime;
@Column(name = "timestamp")
Timestamp timestamp;
public DonateStat(Object[] obj) { public DonateStat(Object[] obj) {
this.id = (int) obj[0]; this.id = (int) obj[0];
@ -59,6 +81,14 @@ public class DonateStat {
//потом бля //потом бля
} }
public DonateStat() {
}
public Long getUtime() {
return utime == null ? timestamp.getTime()/1000:utime;
}
public Integer getRubles() { public Integer getRubles() {
if (this.giveMethod == VipGiveMethod.QIWI || this.giveMethod == VipGiveMethod.DONATIONALERTS) return Integer.valueOf(this.reserved.split(";")[0].split("=")[1]); if (this.giveMethod == VipGiveMethod.QIWI || this.giveMethod == VipGiveMethod.DONATIONALERTS) return Integer.valueOf(this.reserved.split(";")[0].split("=")[1]);
return 0; return 0;

37
src/main/java/app/entities/db/ErrorDb.java

@ -1,20 +1,39 @@
package app.entities.db; package app.entities.db;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Entity
@Table(schema = "tf2_facti13", name = "backend_errors")
public class ErrorDb { public class ErrorDb {
private final Integer id; @Id
private final Long timestamp; @Column(name = "id")
private final String message; private Integer id;
private final String trace;
private final String query; @Transient
private Long timestamp;
@Column(name = "err_timestamp")
private Timestamp err_timestamp;
@Column(name = "err_message", length = 10000)
private String message;
@Column(name = "err_trace", length = 10000)
private String trace;
@Column(name = "err_query", length = 10000)
private String query;
@Transient
private Throwable e; private Throwable e;
public ErrorDb(ResultSet rs) throws SQLException { public ErrorDb(ResultSet rs) throws SQLException {
@ -37,6 +56,10 @@ public class ErrorDb {
this.e = e; this.e = e;
} }
public ErrorDb() {
}
public static String Request2Query(HttpServletRequest request) { public static String Request2Query(HttpServletRequest request) {
if (request == null) return null; if (request == null) return null;
@ -66,6 +89,10 @@ public class ErrorDb {
return query; return query;
} }
public Timestamp getErr_timestamp() {
return err_timestamp;
}
@JsonIgnore @JsonIgnore
public Throwable getE() { public Throwable getE() {
return e; return e;

30
src/main/java/app/entities/db/Permition.java

@ -1,20 +1,40 @@
package app.entities.db; package app.entities.db;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data; import lombok.Data;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
//id, flags, immunity, status, amount, UNIX_TIMESTAMP(`reg_date`) //id, flags, immunity, status, amount, UNIX_TIMESTAMP(`reg_date`)
@Data @Data
@Entity
@Table(schema = "tf2_facti13", name = "sm_admins")
public class Permition { public class Permition {
@JsonIgnore @JsonIgnore
@Id
@Column(name = "id")
int id; int id;
@Column(name = "flags", length = 30)
String flags; String flags;
long u_timestamp;
@Transient
Long u_timestamp;
@Column(name = "reg_date")
Timestamp timestamp;
@Column(name = "amount")
int amount; int amount;
@Column(name = "immunity")
int immunity; int immunity;
@Column(name = "status")
String status; String status;
public Permition(Object[] objects) { public Permition(Object[] objects) {
@ -34,4 +54,12 @@ public class Permition {
amount = resultSet.getInt("amount"); amount = resultSet.getInt("amount");
u_timestamp = resultSet.getLong("utime"); u_timestamp = resultSet.getLong("utime");
} }
public Permition() {
}
public Long getU_timestamp() {
return u_timestamp == null ? timestamp.getTime()/1000:u_timestamp;
}
} }

27
src/main/java/app/entities/db/PromoCode.java

@ -1,23 +1,46 @@
package app.entities.db; package app.entities.db;
import app.entities.PromoCodeStatus; import app.entities.PromoCodeStatus;
import app.entities.db.converter.SteamIdSteam64Converter;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.utils.SteamIDConverter; import app.utils.SteamIDConverter;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
@Entity
@Table(schema = "tf2_facti13", name = "gived_promocode")
public class PromoCode { public class PromoCode {
@JsonIgnore @JsonIgnore
@Id
@Column(name = "id")
int id; int id;
@Column(name = "created_timestamp")
Timestamp created_timestamp; Timestamp created_timestamp;
@Column(name = "code", length = 256)
String code; String code;
@Column(name = "creator_steam64", length = 128, nullable = false)
@Convert(converter = SteamIdSteam64Converter.class)
SteamID creator; SteamID creator;
@Column(name = "accepted_steam64", length = 128)
@Convert(converter = SteamIdSteam64Converter.class)
SteamID accept; SteamID accept;
@Column(name = "accepted_timestamp")
Timestamp accepted_timestamp; Timestamp accepted_timestamp;
@Column(name = "status")
@Enumerated(value = EnumType.ORDINAL)
PromoCodeStatus status; PromoCodeStatus status;
@Column(name = "action")
String action; String action;
public PromoCode(ResultSet resultSet) throws SQLException { public PromoCode(ResultSet resultSet) throws SQLException {
@ -31,6 +54,10 @@ public class PromoCode {
action = resultSet.getString("action"); action = resultSet.getString("action");
} }
public PromoCode() {
}
public int getId() { public int getId() {
return id; return id;
} }

17
src/main/java/app/entities/db/converter/SteamIdSteam64Converter.java

@ -0,0 +1,17 @@
package app.entities.db.converter;
import app.entities.other.SteamID;
import app.utils.SteamIDConverter;
import jakarta.persistence.AttributeConverter;
public class SteamIdSteam64Converter implements AttributeConverter<SteamID, String> {
@Override
public String convertToDatabaseColumn(SteamID steamID) {
return Long.toString(steamID.steam64);
}
@Override
public SteamID convertToEntityAttribute(String s) {
return SteamIDConverter.getSteamID(s);
}
}

67
src/main/java/app/entities/messages/Message.java

@ -0,0 +1,67 @@
package app.entities.messages;
import app.services.db.NicknameService;
import jakarta.persistence.*;
import lombok.Data;
import java.sql.ResultSet;
import java.sql.SQLException;
/*
CREATE TABLE user_messages (
id int(11) NOT NULL,
account_id int(11) NOT NULL,
utime bigint(20) NOT NULL,
message varchar(512) NOT NULL,
server_id varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
*/
@Data
@Entity
@Table(schema = "tf2_facti13", name = "user_messages")
public class Message {
@Id
@Column(name="id")
Long id;
@Column(name="account_id")
Long account_id;
@Column(name = "utime")
Long utime;
@Column(name = "message", length = 512)
String message;
@Column(name = "server_id", length = 32)
String server_id;
@Transient
String account_name;
public Message(Object obj) {
this.account_id = (long) ((Object[]) obj)[0];
this.utime = (long) ((Object[]) obj)[1];
this.message = (String) ((Object[]) obj)[2];
this.server_id = (String) ((Object[]) obj)[3];
}
public Message(ResultSet rs) throws SQLException {
account_id = rs.getLong("account_id");
utime = rs.getLong("utime");
message = rs.getString("message");
server_id = rs.getString("server_id");
}
public Message() {
}
public Message setAccount_name(NicknameService nicknameService) {
this.account_name = nicknameService.grabNickname(account_id.intValue(), server_id);
return this;
}
public String getAccount_name() {
return "";
}
}

47
src/main/java/app/entities/messages/MessageSearch.java

@ -0,0 +1,47 @@
package app.entities.messages;
import app.services.ProfileService;
import lombok.Getter;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
public class MessageSearch {
private List<String> accounts;
private LocalDateTime begin;
private LocalDateTime end;
private String message;
private String serverId;
public MessageSearch() {
}
public List<Long> getAccounts(ProfileService profileService) {
if (accounts == null) return null;
List<Long> filtered = accounts.stream()
.map(any -> profileService.GetSteamIDFromAnyData(any))
.map(sId -> sId.steam2)
.map(Long::parseLong)
.toList();
return filtered.isEmpty() ? null : filtered;
}
public Long getBegin() {
return begin == null ? null : begin.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
}
public Long getEnd() {
return end == null ? null : end.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
}
public String getMessage() {
return message;
}
public String getServerId() {
return serverId;
}
}

26
src/main/java/app/repositories/MessageRepository.java

@ -0,0 +1,26 @@
package app.repositories;
import app.entities.messages.Message;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface MessageRepository extends PagingAndSortingRepository<Message, Long> {
@Query(value = "select m from Message m where " +
"(:account_ids is null or m.account_id in :account_ids) and " +
"(:begin_date is null or :begin_date >= m.utime) and " +
"(:end_date is null or :end_date <= m.utime) and " +
"(:message_contain is null or m.message like :message_contain) and " +
"(:server_id is null or m.server_id like :server_id)")
Page<Message> getMessages(Pageable pageable,
@Param(value = "account_ids") List<Long> account_ids,
@Param(value = "begin_date") Long begin_date,
@Param(value = "end_date") Long end_date,
@Param(value = "message_contain") String message_contain,
@Param(value = "server_id") String message_id);
}

5
src/main/java/app/services/ProfileService.java

@ -1,9 +1,8 @@
package app.services; package app.services;
import app.entities.PlayerProfile; import app.entities.PlayerProfile;
import app.entities.Stats;
import app.entities.db.Ban; import app.entities.db.Ban;
import app.entities.db.Killfeed; import app.entities.Killfeed;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.entities.report.ReportCount; import app.entities.report.ReportCount;
import app.exceptions.BaseWebException; import app.exceptions.BaseWebException;
@ -20,10 +19,8 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
@Service @Service

45
src/main/java/app/services/db/MessageService.java

@ -1,17 +1,14 @@
package app.services.db; package app.services.db;
import app.entities.messages.Message;
import app.entities.StatisticRange; import app.entities.StatisticRange;
import app.entities.Stats; import app.entities.Stats;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -107,44 +104,4 @@ public class MessageService {
new Object[]{StatisticRange.cast(statisticRange), 15}, new Object[]{StatisticRange.cast(statisticRange), 15},
(rs, n) -> Map.of("message", rs.getString("message"), "count", rs.getLong("c"))); (rs, n) -> Map.of("message", rs.getString("message"), "count", rs.getLong("c")));
} }
/*
CREATE TABLE user_messages (
id int(11) NOT NULL,
account_id int(11) NOT NULL,
utime bigint(20) NOT NULL,
message varchar(512) NOT NULL,
server_id varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
*/
@Data
public class Message {
int account_id;
long utime;
String message;
String server_id;
String account_name;
Message(Object obj) {
this.account_id = (int) ((Object[]) obj)[0];
this.utime = (long) ((Object[]) obj)[1];
this.message = (String) ((Object[]) obj)[2];
this.server_id = (String) ((Object[]) obj)[3];
}
Message(ResultSet rs) throws SQLException {
account_id = rs.getInt("account_id");
utime = rs.getLong("utime");
message = rs.getString("message");
server_id = rs.getString("server_id");
}
public Message setAccount_name(NicknameService nicknameService) {
this.account_name = nicknameService.grabNickname(account_id, server_id);
return this;
}
public String getAccount_name() {
return nicknameService.grabNickname(account_id, server_id);
}
}
} }

Loading…
Cancel
Save