Browse Source

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

master
gsd 1 month ago
parent
commit
e999e27236
  1. 11
      pom.xml
  2. 7
      src/main/java/app/controllers/user/MessagesController.java
  3. 11
      src/main/java/app/controllers/user/PublicController.java
  4. 6
      src/main/java/app/entities/SearchFilter.java
  5. 8
      src/main/java/app/entities/db/ban/BanSearchFilter.java
  6. 9
      src/main/java/app/repositories/BanRepository.java
  7. 3
      src/main/java/app/repositories/MessageRepository.java

11
pom.xml

@ -13,23 +13,24 @@
<maven.compiler.source>18</maven.compiler.source> <maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target> <maven.compiler.target>18</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.0.2</spring.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<version>3.0.2</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>
<version>3.0.2</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId> <artifactId>spring-boot-starter-websocket</artifactId>
<version>3.0.2</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
@ -50,7 +51,7 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
<version>3.0.2</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
@ -61,7 +62,7 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
<version>3.0.2</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.ibasco.agql</groupId> <groupId>com.ibasco.agql</groupId>

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

@ -21,6 +21,8 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* котроллер для пользователя, чтоб смотреть сообщения * котроллер для пользователя, чтоб смотреть сообщения
*/ */
@ -65,9 +67,12 @@ public class MessagesController {
public Page<Message> getMessagesWithFilters(Pageable pageable, public Page<Message> getMessagesWithFilters(Pageable pageable,
@RequestBody(required = false) MessageSearchFilter filter) { @RequestBody(required = false) MessageSearchFilter filter) {
if (filter == null) filter = new MessageSearchFilter(); if (filter == null) filter = new MessageSearchFilter();
List<Long> account_ids = filter.getAccounts(profileService);
Page<Message> messages = messageRepository.getMessages( Page<Message> messages = messageRepository.getMessages(
pageable, pageable,
filter.getAccounts(profileService), account_ids.isEmpty(),
account_ids,
filter.getBeginUnixTime(), filter.getBeginUnixTime(),
filter.getEndUnixTime(), filter.getEndUnixTime(),
filter.getMessage(), filter.getMessage(),

11
src/main/java/app/controllers/user/PublicController.java

@ -19,6 +19,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
/** /**
* контролллер для просмотра всякой хуйни, например банлиста (нахуя он отдельный, незнаю, захотел) * контролллер для просмотра всякой хуйни, например банлиста (нахуя он отдельный, незнаю, захотел)
@ -64,14 +65,18 @@ public class PublicController {
public ResponseEntity<Page<Ban>> getBanListWithFilters(Pageable pageable, @RequestBody(required = false) BanSearchFilter banSearchFilter) { public ResponseEntity<Page<Ban>> getBanListWithFilters(Pageable pageable, @RequestBody(required = false) BanSearchFilter banSearchFilter) {
if (banSearchFilter == null) banSearchFilter = new BanSearchFilter(); if (banSearchFilter == null) banSearchFilter = new BanSearchFilter();
List<Long> ban_ids = banSearchFilter.getBan_ids();
List<Long> account_ids = banSearchFilter.getAccounts(profileService);
List<String> admin_ids = banSearchFilter.getAdminIds(profileService);
return new ResponseEntity<>( return new ResponseEntity<>(
banRepository.getBans(pageable, banRepository.getBans(pageable,
banSearchFilter.getBan_ids(), ban_ids.isEmpty(), ban_ids,
banSearchFilter.getAccounts(profileService), account_ids.isEmpty(), account_ids,
banSearchFilter.getBeginUnixTime(), banSearchFilter.getBeginUnixTime(),
banSearchFilter.getEndUnixTime(), banSearchFilter.getEndUnixTime(),
banSearchFilter.getActive(), banSearchFilter.getActive(),
banSearchFilter.getAdminIds(profileService)) admin_ids.isEmpty(), admin_ids)
, HttpStatus.OK); , HttpStatus.OK);
} }
} }

6
src/main/java/app/entities/SearchFilter.java

@ -6,6 +6,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -19,14 +20,13 @@ public abstract class SearchFilter {
private String serverId = null; private String serverId = null;
public List<Long> getAccounts(ProfileService profileService) { public List<Long> getAccounts(ProfileService profileService) {
if (accounts == null || accounts.isEmpty()) return null; if (accounts == null || accounts.isEmpty()) return new ArrayList<>();
List<Long> filtered = accounts.stream() return accounts.stream()
.map(profileService::GetSteamIDFromAnyData) .map(profileService::GetSteamIDFromAnyData)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(sId -> sId.account_id) .map(sId -> sId.account_id)
.toList(); .toList();
return filtered.isEmpty()?null:filtered;
} }
public Long getBeginUnixTime() { public Long getBeginUnixTime() {

8
src/main/java/app/entities/db/ban/BanSearchFilter.java

@ -4,6 +4,7 @@ import app.entities.SearchFilter;
import app.services.ProfileService; import app.services.ProfileService;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -17,7 +18,7 @@ public class BanSearchFilter extends SearchFilter {
} }
public List<Long> getBan_ids() { public List<Long> getBan_ids() {
return ban_ids == null || ban_ids.isEmpty() ? null : ban_ids; return ban_ids == null ? new ArrayList<>() : ban_ids;
} }
public Boolean getActive() { public Boolean getActive() {
@ -25,13 +26,12 @@ public class BanSearchFilter extends SearchFilter {
} }
public List<String> getAdminIds(ProfileService profileService) { public List<String> getAdminIds(ProfileService profileService) {
if (admin_ids == null || admin_ids.isEmpty()) return null; if (admin_ids == null || admin_ids.isEmpty()) return new ArrayList<>();
List<String> filtered = admin_ids.stream() return admin_ids.stream()
.map(profileService::GetSteamIDFromAnyData) .map(profileService::GetSteamIDFromAnyData)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(sId -> sId.steam3) .map(sId -> sId.steam3)
.toList(); .toList();
return filtered.isEmpty() ? null : filtered;
} }
} }

9
src/main/java/app/repositories/BanRepository.java

@ -13,17 +13,20 @@ import java.util.List;
public interface BanRepository extends PagingAndSortingRepository<Ban, Long> { public interface BanRepository extends PagingAndSortingRepository<Ban, Long> {
@Query(value = "select b from Ban b where " + @Query(value = "select b from Ban b where " +
"(:ban_ids is null or b.id in :ban_ids) and " + "(:ban_ids_non_exists = true or b.id in :ban_ids) and " +
"(:account_ids is null or b.account_id in :account_ids) and " + "(:account_ids_non_exists = true or b.account_id in :account_ids) and " +
"(:begin_date is null or DATE_PART('EPOCH', b.timestamp) >= :begin_date) and " + "(:begin_date is null or DATE_PART('EPOCH', b.timestamp) >= :begin_date) and " +
"(:end_date is null or :end_date <= DATE_PART('EPOCH', b.timestamp)) and " + "(:end_date is null or :end_date <= DATE_PART('EPOCH', b.timestamp)) and " +
"(:active is null or b.active = :active) and " + "(:active is null or b.active = :active) and " +
"(:admin_ids is null or b.unbanned_by_id in :admin_ids) order by b.id desc") "(:admin_ids_non_exists = true or b.unbanned_by_id in :admin_ids) order by b.id desc")
Page<Ban> getBans(Pageable pageable, Page<Ban> getBans(Pageable pageable,
@Param(value = "ban_ids_non_exists") Boolean ban_ids_non_exists,
@Param(value = "ban_ids") Iterable<Long> ban_ids, @Param(value = "ban_ids") Iterable<Long> ban_ids,
@Param(value = "account_ids_non_exists") Boolean account_ids_non_exists,
@Param(value = "account_ids") Iterable<Long> account_ids, @Param(value = "account_ids") Iterable<Long> account_ids,
@Param(value = "begin_date") Long begin_date, @Param(value = "begin_date") Long begin_date,
@Param(value = "end_date") Long end_date, @Param(value = "end_date") Long end_date,
@Param(value = "active") Boolean active, @Param(value = "active") Boolean active,
@Param(value = "admin_ids_non_exists") Boolean admin_ids_non_exists,
@Param(value = "admin_ids") Iterable<String> admin_ids); @Param(value = "admin_ids") Iterable<String> admin_ids);
} }

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

@ -10,12 +10,13 @@ import org.springframework.data.repository.query.Param;
public interface MessageRepository extends PagingAndSortingRepository<Message, Long> { public interface MessageRepository extends PagingAndSortingRepository<Message, Long> {
@Query(value = "select m from Message m where " + @Query(value = "select m from Message m where " +
"(:account_ids is null or m.account_id in :account_ids) and " + "(:account_ids_non_exists = true or m.account_id in :account_ids) and " +
"(:begin_date is null or m.utime >= :begin_date) and " + "(:begin_date is null or m.utime >= :begin_date) and " +
"(:end_date is null or :end_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 " + "(:message_contain is null or m.message like :message_contain) and " +
"(:server_id is null or m.server_id like :server_id) order by m.id desc ") "(:server_id is null or m.server_id like :server_id) order by m.id desc ")
Page<Message> getMessages(Pageable pageable, Page<Message> getMessages(Pageable pageable,
@Param(value = "account_ids_non_exists") Boolean account_ids_non_exists,
@Param(value = "account_ids") Iterable<Long> account_ids, @Param(value = "account_ids") Iterable<Long> account_ids,
@Param(value = "begin_date") Long begin_date, @Param(value = "begin_date") Long begin_date,
@Param(value = "end_date") Long end_date, @Param(value = "end_date") Long end_date,

Loading…
Cancel
Save