From bc50b41f9f2cddfafb18332b7e12cd3e4bb025c2 Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 1 Apr 2025 22:55:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D0=BB=D1=8C=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=8C=20=D0=B0=D0=BF=D0=B4=D0=B5=D0=B9=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/configurations/DbRwConfigurarion.java | 15 +++-- .../controllers/user/MessagesController.java | 32 ++++++--- .../java/app/entities/{db => }/Killfeed.java | 2 +- src/main/java/app/entities/PlayerProfile.java | 3 - src/main/java/app/entities/db/AdminInfo.java | 21 ++++++ src/main/java/app/entities/db/Ban.java | 41 +++++++++++- .../app/entities/db/CollectableStatistic.java | 29 +++++++- src/main/java/app/entities/db/DonateStat.java | 32 ++++++++- src/main/java/app/entities/db/ErrorDb.java | 37 ++++++++-- src/main/java/app/entities/db/Permition.java | 30 ++++++++- src/main/java/app/entities/db/PromoCode.java | 27 ++++++++ .../db/converter/SteamIdSteam64Converter.java | 17 +++++ .../java/app/entities/messages/Message.java | 67 +++++++++++++++++++ .../app/entities/messages/MessageSearch.java | 47 +++++++++++++ .../app/repositories/MessageRepository.java | 26 +++++++ .../java/app/services/ProfileService.java | 5 +- .../java/app/services/db/MessageService.java | 45 +------------ 17 files changed, 396 insertions(+), 80 deletions(-) rename src/main/java/app/entities/{db => }/Killfeed.java (94%) create mode 100644 src/main/java/app/entities/db/converter/SteamIdSteam64Converter.java create mode 100644 src/main/java/app/entities/messages/Message.java create mode 100644 src/main/java/app/entities/messages/MessageSearch.java create mode 100644 src/main/java/app/repositories/MessageRepository.java diff --git a/src/main/java/app/configurations/DbRwConfigurarion.java b/src/main/java/app/configurations/DbRwConfigurarion.java index 3f91074..0cfd8b2 100644 --- a/src/main/java/app/configurations/DbRwConfigurarion.java +++ b/src/main/java/app/configurations/DbRwConfigurarion.java @@ -4,15 +4,14 @@ import com.zaxxer.hikari.HikariDataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.*; import org.springframework.core.env.Environment; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.orm.hibernate5.LocalSessionFactoryBean; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; @@ -25,7 +24,7 @@ import java.util.HashMap; * конфигурация которая используется для создание ждбсТеплейта который будет доступен как для чтения так и для записи */ @Configuration -@EnableJpaRepositories(basePackages = "app.entities.dummy.rw", entityManagerFactoryRef = "RwEntityManager", transactionManagerRef = "RwTransactionManager") +@EnableJpaRepositories(basePackages = "app", entityManagerFactoryRef = "RwEntityManager", transactionManagerRef = "RwTransactionManager") public class DbRwConfigurarion implements DbConfiguration{ @Autowired @@ -36,12 +35,14 @@ public class DbRwConfigurarion implements DbConfiguration{ @Bean(name = "RwDataSourceProperties") @Scope(value = "singleton") @ConfigurationProperties(prefix = "backend.db.rw") + @Primary public DataSourceProperties DataSourceProperties() { return new DataSourceProperties(); } @Bean(name = "RwDataSource") @Scope(value = "singleton") + @Primary public DataSource DataSource() { HikariDataSource dataSource = DataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); dataSource.setReadOnly(false); @@ -50,10 +51,11 @@ public class DbRwConfigurarion implements DbConfiguration{ @Bean(name = "RwEntityManager") @Scope(value = "singleton") + @Primary public LocalContainerEntityManagerFactoryBean EntityManager() { LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean(); entityManager.setDataSource(DataSource()); - entityManager.setPackagesToScan("app.entities.dummy.rw"); + entityManager.setPackagesToScan("app"); HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); entityManager.setJpaVendorAdapter(vendorAdapter); HashMap properties = new HashMap<>(); @@ -64,6 +66,7 @@ public class DbRwConfigurarion implements DbConfiguration{ @Bean(name = "RwTransactionManager") @Scope(value = "singleton") + @Primary public PlatformTransactionManager TransactionManager() { JpaTransactionManager transactionManager = new JpaTransactionManager(); transactionManager.setEntityManagerFactory(EntityManager().getObject()); diff --git a/src/main/java/app/controllers/user/MessagesController.java b/src/main/java/app/controllers/user/MessagesController.java index a36b658..cb5a5bb 100644 --- a/src/main/java/app/controllers/user/MessagesController.java +++ b/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.CollectStatistic; import app.annotations.interfaces.WaitAfterNext; +import app.entities.messages.Message; +import app.entities.messages.MessageSearch; import app.entities.other.SteamID; +import app.repositories.MessageRepository; +import app.services.ProfileService; import app.services.db.MessageService; import app.utils.SteamIDConverter; import jakarta.servlet.http.HttpServletRequest; @@ -26,11 +30,18 @@ import java.util.Map; @RestController @RequestMapping("/api/profile/messages") public class MessagesController { + private MessageService messageService; + private MessageRepository messageRepository; + + private ProfileService profileService; + @Autowired - MessagesController(MessageService messageService) { + public MessagesController(MessageService messageService, MessageRepository messageRepository, ProfileService profileService) { this.messageService = messageService; + this.messageRepository = messageRepository; + this.profileService = profileService; } @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE}) @@ -51,15 +62,16 @@ public class MessagesController { @CheckWebAccess(auth_method = AuthMethod.STEAM64) @WaitAfterNext(order = "messages") @CollectStatistic - public ResponseEntity> getMessagesWithFilters(Pageable pageable, - @RequestBody(required = false) Payload filter, - @RequestParam(required = false) String srv) { - if (pageable.getPageSize() > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); - - Map result = messageService.getAllMessages(srv, filter==null?null:filter.getMessage(), pageable.getOffset(), pageable.getPageSize()); - return new ResponseEntity<>( - new PageImpl((List) result.get("result"), pageable, (Long) result.get("count")), - HttpStatus.OK + public Page getMessagesWithFilters(Pageable pageable, + @RequestBody(required = false) MessageSearch filter) { + if (filter == null) filter = new MessageSearch(); + return messageRepository.getMessages( + pageable, + filter.getAccounts(profileService), + filter.getBegin(), + filter.getEnd(), + filter.getMessage(), + filter.getServerId() ); } diff --git a/src/main/java/app/entities/db/Killfeed.java b/src/main/java/app/entities/Killfeed.java similarity index 94% rename from src/main/java/app/entities/db/Killfeed.java rename to src/main/java/app/entities/Killfeed.java index ced5191..e99b548 100644 --- a/src/main/java/app/entities/db/Killfeed.java +++ b/src/main/java/app/entities/Killfeed.java @@ -1,4 +1,4 @@ -package app.entities.db; +package app.entities; import lombok.Data; diff --git a/src/main/java/app/entities/PlayerProfile.java b/src/main/java/app/entities/PlayerProfile.java index 82c2a5c..77ee045 100644 --- a/src/main/java/app/entities/PlayerProfile.java +++ b/src/main/java/app/entities/PlayerProfile.java @@ -2,14 +2,11 @@ package app.entities; import app.entities.db.Ban; import app.entities.db.DonateStat; -import app.entities.db.Killfeed; import app.entities.db.Permition; import app.entities.other.SteamID; import app.entities.report.ReportCount; import app.entities.server.PlayOn; import app.entities.steam.SteamData; -import com.fasterxml.jackson.annotation.JsonIgnore; -import lombok.Builder; import lombok.Data; import java.math.BigDecimal; diff --git a/src/main/java/app/entities/db/AdminInfo.java b/src/main/java/app/entities/db/AdminInfo.java index e13c7b6..830d9e0 100644 --- a/src/main/java/app/entities/db/AdminInfo.java +++ b/src/main/java/app/entities/db/AdminInfo.java @@ -2,6 +2,10 @@ package app.entities.db; import app.utils.SteamIDConverter; 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 java.sql.ResultSet; @@ -18,16 +22,29 @@ CREATE TABLE `bot_admins` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; */ @Data +@Entity +@Table(name = "bot_admins", schema = "tf2_facti13") public class AdminInfo { @JsonIgnore + @Id + @Column(name = "id") int id; + + @Column(name = "vk_id", nullable = false) int vk_id; + + @Column(name = "discord_id", nullable = false) long discord_id; + + @Column(name = "discord_name", nullable = false) String discord_name; + + @Column(name = "steam3", nullable = false) @JsonIgnore String steam3; String steam_url; @JsonIgnore + @Column(name = "permition", nullable = false) int permition; public AdminInfo(Object[] obj) { @@ -49,4 +66,8 @@ public class AdminInfo { permition = resultSet.getInt("permition"); steam_url = SteamIDConverter.getSteamID(steam3).community_url; } + + public AdminInfo() { + + } } diff --git a/src/main/java/app/entities/db/Ban.java b/src/main/java/app/entities/db/Ban.java index 7a3680b..0f485bb 100644 --- a/src/main/java/app/entities/db/Ban.java +++ b/src/main/java/app/entities/db/Ban.java @@ -5,6 +5,7 @@ import app.services.db.PermitionService; import app.utils.CryptedCookie; import app.utils.SteamIDConverter; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; import lombok.Data; import java.sql.ResultSet; @@ -30,23 +31,47 @@ CREATE TABLE `light_bans` ( */ @Data +@Entity +@Table(schema = "tf2_facti13", name = "light_bans") public class Ban { + @Id + @Column(name = "id") int id; + @Column(name = "steam_id", length = 32) String steam_id; + @Column(name = "account_id") Long account_id; + @Column(name = "player_name", length = 65) String player_name; + @Column(name = "ban_length") int ban_length; - long ban_length_seconds; + @Transient + Long ban_length_seconds; + @Column(name = "ban_reason", length = 100) String ban_reason; + @Column(name = "banned_by", length = 100) String banned_by; + @Column(name = "banned_by_id") String banned_by_id; + @Column(name = "ip", length = 15) String ip; + @Column(name = "timestamp") Timestamp timestamp; - long ban_utime; + @Transient + Long ban_utime; + @Column(name = "active") boolean active; + @Column(name = "unbanned_by_id", length = 32) String unbanned_by_id; + @Column(name = "unbanned_timestamp") Timestamp unbanned_timestamp; + + @ManyToOne + @JoinColumn(name = "banned_by_id", referencedColumnName = "steam3", insertable=false, updatable=false) AdminInfo admin_info; + + @ManyToOne + @JoinColumn(name = "unbanned_by_id", referencedColumnName = "steam3", nullable = true, insertable=false, updatable=false) AdminInfo unbanned_admin_info; 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) { if (ip != null && !ip.isEmpty()) { ip = cryptedCookie.Hashed(ip); diff --git a/src/main/java/app/entities/db/CollectableStatistic.java b/src/main/java/app/entities/db/CollectableStatistic.java index f1cac37..b7414af 100644 --- a/src/main/java/app/entities/db/CollectableStatistic.java +++ b/src/main/java/app/entities/db/CollectableStatistic.java @@ -1,5 +1,9 @@ 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 lombok.AllArgsConstructor; import lombok.Data; @@ -9,17 +13,32 @@ import java.time.Instant; import java.util.Arrays; @Data +@Entity +@Table(schema = "tf2_facti13", name = "web_statistic") public class CollectableStatistic { + @Id + @Column(name="id") Long id; + + @Column(name = "time") Timestamp timestamp; - /// + + @Column(name = "client_ip", length = 64) String client_ip; + + @Column(name = "steam64", length = 64) String steam64; - /// + + @Column(name = "method", length = 16) String method; + + @Column(name = "path", length = 512) String path; + + @Column(name = "query", length = 512) String query; - /// + + @Column(name = "useragent", length = 512) String useragent; public CollectableStatistic(HttpServletRequest request) { @@ -33,6 +52,10 @@ public class CollectableStatistic { this.timestamp = Timestamp.from(Instant.now()); } + public CollectableStatistic() { + + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/app/entities/db/DonateStat.java b/src/main/java/app/entities/db/DonateStat.java index 579a407..5b3adf7 100644 --- a/src/main/java/app/entities/db/DonateStat.java +++ b/src/main/java/app/entities/db/DonateStat.java @@ -2,10 +2,12 @@ package app.entities.db; import app.entities.VipGiveMethod; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; import lombok.Data; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; /* CREATE TABLE `gived_vip` ( @@ -21,19 +23,39 @@ CREATE TABLE `gived_vip` ( */ @Data +@Entity +@Table(schema = "tf2_facti13", name = "gived_vip") public class DonateStat { @JsonIgnore + @Id + @Column(name = "id") int id; + @JsonIgnore + @Column(name = "steam2") String steam2; + + @Column(name = "amount") int amount; + + @Column(name = "givemethod") + @Enumerated(value = EnumType.ORDINAL) @JsonIgnore VipGiveMethod giveMethod; + @JsonIgnore + @Column(name = "reserved", length = 65) String reserved; + @JsonIgnore + @Column(name = "extend") boolean extended; - long utime; + + @Transient + Long utime; + + @Column(name = "timestamp") + Timestamp timestamp; public DonateStat(Object[] obj) { 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() { if (this.giveMethod == VipGiveMethod.QIWI || this.giveMethod == VipGiveMethod.DONATIONALERTS) return Integer.valueOf(this.reserved.split(";")[0].split("=")[1]); return 0; diff --git a/src/main/java/app/entities/db/ErrorDb.java b/src/main/java/app/entities/db/ErrorDb.java index 1a99086..f5b0fa8 100644 --- a/src/main/java/app/entities/db/ErrorDb.java +++ b/src/main/java/app/entities/db/ErrorDb.java @@ -1,20 +1,39 @@ package app.entities.db; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; import jakarta.servlet.http.HttpServletRequest; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.time.Instant; import java.util.Arrays; import java.util.stream.Collectors; +@Entity +@Table(schema = "tf2_facti13", name = "backend_errors") public class ErrorDb { - private final Integer id; - private final Long timestamp; - private final String message; - private final String trace; - private final String query; + @Id + @Column(name = "id") + private Integer id; + + @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; public ErrorDb(ResultSet rs) throws SQLException { @@ -37,6 +56,10 @@ public class ErrorDb { this.e = e; } + public ErrorDb() { + + } + public static String Request2Query(HttpServletRequest request) { if (request == null) return null; @@ -66,6 +89,10 @@ public class ErrorDb { return query; } + public Timestamp getErr_timestamp() { + return err_timestamp; + } + @JsonIgnore public Throwable getE() { return e; diff --git a/src/main/java/app/entities/db/Permition.java b/src/main/java/app/entities/db/Permition.java index 11601c3..574a18b 100644 --- a/src/main/java/app/entities/db/Permition.java +++ b/src/main/java/app/entities/db/Permition.java @@ -1,20 +1,40 @@ package app.entities.db; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; import lombok.Data; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; //id, flags, immunity, status, amount, UNIX_TIMESTAMP(`reg_date`) @Data +@Entity +@Table(schema = "tf2_facti13", name = "sm_admins") public class Permition { @JsonIgnore + @Id + @Column(name = "id") int id; + + @Column(name = "flags", length = 30) String flags; - long u_timestamp; + + @Transient + Long u_timestamp; + + @Column(name = "reg_date") + Timestamp timestamp; + + + @Column(name = "amount") int amount; + + @Column(name = "immunity") int immunity; + + @Column(name = "status") String status; public Permition(Object[] objects) { @@ -34,4 +54,12 @@ public class Permition { amount = resultSet.getInt("amount"); u_timestamp = resultSet.getLong("utime"); } + + public Permition() { + + } + + public Long getU_timestamp() { + return u_timestamp == null ? timestamp.getTime()/1000:u_timestamp; + } } diff --git a/src/main/java/app/entities/db/PromoCode.java b/src/main/java/app/entities/db/PromoCode.java index eeeb98c..c22b4af 100644 --- a/src/main/java/app/entities/db/PromoCode.java +++ b/src/main/java/app/entities/db/PromoCode.java @@ -1,23 +1,46 @@ package app.entities.db; import app.entities.PromoCodeStatus; +import app.entities.db.converter.SteamIdSteam64Converter; import app.entities.other.SteamID; import app.utils.SteamIDConverter; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +@Entity +@Table(schema = "tf2_facti13", name = "gived_promocode") public class PromoCode { @JsonIgnore + @Id + @Column(name = "id") int id; + + @Column(name = "created_timestamp") Timestamp created_timestamp; + + @Column(name = "code", length = 256) String code; + + @Column(name = "creator_steam64", length = 128, nullable = false) + @Convert(converter = SteamIdSteam64Converter.class) SteamID creator; + + @Column(name = "accepted_steam64", length = 128) + @Convert(converter = SteamIdSteam64Converter.class) SteamID accept; + + @Column(name = "accepted_timestamp") Timestamp accepted_timestamp; + + @Column(name = "status") + @Enumerated(value = EnumType.ORDINAL) PromoCodeStatus status; + + @Column(name = "action") String action; public PromoCode(ResultSet resultSet) throws SQLException { @@ -31,6 +54,10 @@ public class PromoCode { action = resultSet.getString("action"); } + public PromoCode() { + + } + public int getId() { return id; } diff --git a/src/main/java/app/entities/db/converter/SteamIdSteam64Converter.java b/src/main/java/app/entities/db/converter/SteamIdSteam64Converter.java new file mode 100644 index 0000000..66accf1 --- /dev/null +++ b/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 { + @Override + public String convertToDatabaseColumn(SteamID steamID) { + return Long.toString(steamID.steam64); + } + + @Override + public SteamID convertToEntityAttribute(String s) { + return SteamIDConverter.getSteamID(s); + } +} diff --git a/src/main/java/app/entities/messages/Message.java b/src/main/java/app/entities/messages/Message.java new file mode 100644 index 0000000..bbf1103 --- /dev/null +++ b/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 ""; + } +} \ No newline at end of file diff --git a/src/main/java/app/entities/messages/MessageSearch.java b/src/main/java/app/entities/messages/MessageSearch.java new file mode 100644 index 0000000..0aaa3ad --- /dev/null +++ b/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 accounts; + private LocalDateTime begin; + private LocalDateTime end; + private String message; + private String serverId; + + public MessageSearch() { + } + + public List getAccounts(ProfileService profileService) { + if (accounts == null) return null; + + List 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; + } +} diff --git a/src/main/java/app/repositories/MessageRepository.java b/src/main/java/app/repositories/MessageRepository.java new file mode 100644 index 0000000..b793a86 --- /dev/null +++ b/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 { + + @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 getMessages(Pageable pageable, + @Param(value = "account_ids") List 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); +} diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index bd58b49..bd19126 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -1,9 +1,8 @@ package app.services; import app.entities.PlayerProfile; -import app.entities.Stats; import app.entities.db.Ban; -import app.entities.db.Killfeed; +import app.entities.Killfeed; import app.entities.other.SteamID; import app.entities.report.ReportCount; import app.exceptions.BaseWebException; @@ -20,10 +19,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.Callable; -import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.function.Consumer; import java.util.function.Supplier; @Service diff --git a/src/main/java/app/services/db/MessageService.java b/src/main/java/app/services/db/MessageService.java index 5de3ba9..7087470 100644 --- a/src/main/java/app/services/db/MessageService.java +++ b/src/main/java/app/services/db/MessageService.java @@ -1,17 +1,14 @@ package app.services.db; +import app.entities.messages.Message; import app.entities.StatisticRange; import app.entities.Stats; import app.entities.other.SteamID; -import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Service; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.List; import java.util.Map; @@ -107,44 +104,4 @@ public class MessageService { new Object[]{StatisticRange.cast(statisticRange), 15}, (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); - } - } }