Skip to content

Commit

Permalink
[UPDATE] 新增消息管理相关接口
Browse files Browse the repository at this point in the history
新增 MulticastMessage 管理相关接口

Signed-off-by: Alan Yeh <[email protected]>
  • Loading branch information
alan-yeh committed Nov 9, 2024
1 parent f08e10f commit e80f7d1
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@

import central.bean.Page;
import central.data.multicast.MulticastBroadcaster;
import central.data.multicast.MulticastMessage;
import central.starter.web.param.IdsParams;
import central.starter.web.query.IdQuery;
import central.studio.dashboard.controller.multicast.param.BroadcasterParams;
import central.studio.dashboard.controller.multicast.query.BroadcasterPageQuery;
import central.studio.dashboard.controller.multicast.query.MessagePageQuery;
import central.studio.dashboard.logic.multicast.MulticastLogic;
import central.validation.group.Insert;
import central.validation.group.Update;
Expand Down Expand Up @@ -120,4 +122,29 @@ public MulticastBroadcaster update(@RequestBody @Validated({Update.class, Defaul
public long delete(@Validated IdsParams params, @RequestAttribute String accountId, @RequestHeader(XForwardedHeaders.TENANT) String tenant) {
return this.logic.deleteByIds(params.getIds(), accountId, tenant);
}

/**
* 按条件分页查询消息列表
*
* @param query 查询
* @param tenant 租户标识
* @return 列表结果
*/
@GetMapping("/messages/page")
public Page<MulticastMessage> pageMessages(@Validated MessagePageQuery query, @RequestHeader(XForwardedHeaders.TENANT) String tenant) {
return this.logic.pageMessages(query.getPageIndex(), query.getPageSize(), query.build(), null, tenant);
}

/**
* 根据主键删除消息数据
*
* @param params 待删除主键列表
* @param accountId 当前登录帐号
* @param tenant 租户标识
* @return 受影响数据行数
*/
@DeleteMapping("/messages")
public long deleteMessages(@Validated IdsParams params, @RequestAttribute String accountId, @RequestHeader(XForwardedHeaders.TENANT) String tenant) {
return this.logic.deleteMessagesByIds(params.getIds(), accountId, tenant);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* MIT License
*
* Copyright (c) 2022-present Alan Yeh <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package central.studio.dashboard.controller.multicast.query;

import central.data.multicast.MulticastMessage;
import central.lang.Stringx;
import central.sql.query.Conditions;
import central.starter.web.query.PageQuery;
import central.validation.Label;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;

/**
* Multicast Message Page Query
* <p>
* 消息分页查询
*
* @author Alan Yeh
* @since 2024/11/09
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class MessagePageQuery extends PageQuery<MulticastMessage> {

Check warning on line 49 in central-dashboard/src/main/java/central/studio/dashboard/controller/multicast/query/MessagePageQuery.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Non-serializable class with 'serialVersionUID'

Non-serializable class `MessagePageQuery` defines a 'serialVersionUID' field
@Serial
private static final long serialVersionUID = 3554744502321204801L;

@Label("广播器主键")
@NotBlank
@Size(min = 1, max = 32)
private String broadcasterId;

@Label("消息体")
private String body;

@Label("消息状态")
private String status;

@Override
public Conditions<MulticastMessage> build() {
var conditions = Conditions.of(MulticastMessage.class).eq(MulticastMessage::getBroadcasterId, this.getBroadcasterId());

// 精确字段搜索
if (Stringx.isNotEmpty(this.getBody())) {
conditions.like(MulticastMessage::getBody, this.getBody());
}
if (this.getStatus() != null) {
conditions.eq(MulticastMessage::getStatus, this.getStatus());
}

// 模糊搜索
for (var keyword : this.getKeywords()) {
conditions.and(filter -> filter.like(MulticastMessage::getBody, keyword));
}

return conditions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import central.sql.query.Conditions;
import central.starter.web.query.PageQuery;
import central.validation.Label;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand All @@ -49,6 +51,8 @@ public class ObjectPageQuery extends PageQuery<StorageObject> {
private static final long serialVersionUID = 7917881061907979327L;

@Label("存储桶主键")
@NotBlank
@Size(min = 1, max = 32)
private String bucketId;

@Label("文件名称")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import central.bean.Page;
import central.data.multicast.MulticastBroadcaster;
import central.data.multicast.MulticastBroadcasterInput;
import central.data.multicast.MulticastMessage;
import central.lang.Stringx;
import central.provider.graphql.multicast.MulticastBroadcasterProvider;
import central.provider.graphql.multicast.MulticastMessageProvider;
import central.provider.scheduled.DataContext;
import central.provider.scheduled.fetcher.DataFetcherType;
import central.provider.scheduled.fetcher.saas.SaasContainer;
Expand Down Expand Up @@ -61,6 +63,9 @@ public class MulticastLogic {
@Setter(onMethod_ = @Autowired)
private MulticastBroadcasterProvider broadcasterProvider;

@Setter(onMethod_ = @Autowired)
private MulticastMessageProvider messageProvider;

@Setter(onMethod_ = @Autowired)
private DataContext context;

Expand All @@ -73,11 +78,23 @@ private SaasContainer getSaasContainer() {
*
* @param orders 用户指定的排序条件
*/
private Orders<MulticastBroadcaster> getDefaultOrders(@Nullable Orders<MulticastBroadcaster> orders) {
private Orders<MulticastBroadcaster> getBroadcasterDefaultOrders(@Nullable Orders<MulticastBroadcaster> orders) {
if (Collectionx.isNullOrEmpty(orders)) {
return orders;
}
return Orders.of(MulticastBroadcaster.class).asc(MulticastBroadcaster::getCode);
return Orders.of(MulticastBroadcaster.class).asc(MulticastBroadcaster::getCode).asc(MulticastBroadcaster::getName);
}

/**
* 如用用户没有指定排序条件,则构建默认的排序条件
*
* @param orders 用户指定的排序条件
*/
private Orders<MulticastMessage> getMessageDefaultOrders(@Nullable Orders<MulticastMessage> orders) {
if (Collectionx.isNullOrEmpty(orders)) {
return orders;
}
return Orders.of(MulticastMessage.class).desc(MulticastMessage::getCreateDate);
}

/**
Expand All @@ -91,7 +108,7 @@ private Orders<MulticastBroadcaster> getDefaultOrders(@Nullable Orders<Multicast
* @return 分页数据
*/
public Page<MulticastBroadcaster> pageBy(@Nonnull Long pageIndex, @Nonnull Long pageSize, @Nullable Conditions<MulticastBroadcaster> conditions, @Nullable Orders<MulticastBroadcaster> orders, @Nonnull String tenant) {
orders = this.getDefaultOrders(orders);
orders = this.getBroadcasterDefaultOrders(orders);
return this.broadcasterProvider.pageBy(pageIndex, pageSize, conditions, orders, tenant);
}

Expand Down Expand Up @@ -150,4 +167,29 @@ public long deleteByIds(@Nullable List<String> ids, @Nonnull String accountId, @
return this.broadcasterProvider.deleteByIds(ids, tenant);
}

/**
* 分页查询
*
* @param pageIndex 分页下标
* @param pageSize 分页大小
* @param conditions 筛选条件
* @param orders 排序条件
* @param tenant 租户标识
* @return 分页数据
*/
public Page<MulticastMessage> pageMessages(@Nonnull Long pageIndex, @Nonnull Long pageSize, @Nullable Conditions<MulticastMessage> conditions, @Nullable Orders<MulticastMessage> orders, @Nonnull String tenant) {
return this.messageProvider.pageBy(pageIndex, pageSize, conditions, this.getMessageDefaultOrders(orders), tenant);
}

/**
* 根据主键删除数据
*
* @param ids 主键
* @param accountId 操作帐号主键
* @param tenant 租户标识
* @return 受影响数据行数
*/
public long deleteMessagesByIds(@Nullable List<String> ids, @Nonnull String accountId, @Nonnull String tenant) {
return this.messageProvider.deleteByIds(ids, tenant);
}
}

0 comments on commit e80f7d1

Please sign in to comment.