wip: 通知公告开发
通知公告开发
This commit is contained in:
@@ -25,7 +25,7 @@ public class PageResult<T> implements Serializable {
|
||||
PageResult<T> result = new PageResult<>();
|
||||
result.setCode(ResultCode.SUCCESS.getCode());
|
||||
|
||||
Data data = new Data<T>();
|
||||
Data<T> data = new Data<>();
|
||||
data.setList(page.getRecords());
|
||||
data.setTotal(page.getTotal());
|
||||
|
||||
|
||||
@@ -78,21 +78,6 @@ public class SysUserDetails implements UserDetails {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
package com.youlai.boot.platform.websocket.service.impl;
|
||||
|
||||
import com.youlai.system.event.UserConnectionEvent;
|
||||
import com.youlai.system.model.dto.ChatMessage;
|
||||
import com.youlai.system.service.WebsocketService;
|
||||
import com.youlai.boot.platform.websocket.service.WebsocketService;
|
||||
import com.youlai.boot.system.event.UserConnectionEvent;
|
||||
import com.youlai.boot.system.model.dto.ChatMessage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.socket.messaging.SessionDisconnectEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -22,14 +20,8 @@ public class WebsocketServiceImpl implements WebsocketService {
|
||||
|
||||
private final SimpMessagingTemplate messagingTemplate;
|
||||
|
||||
// 在线用户
|
||||
private final Set<String> onlineUsers = ConcurrentHashMap.newKeySet();
|
||||
|
||||
// 离线消息
|
||||
private final Set<ChatMessage> offlineMessages = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private final Map<ChatMessage,Set<String>> messageReceiptStatus = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void addUser(String username) {
|
||||
onlineUsers.add(username);
|
||||
@@ -51,11 +43,6 @@ public class WebsocketServiceImpl implements WebsocketService {
|
||||
if (event.isConnected()) {
|
||||
onlineUsers.add(username);
|
||||
log.info("User connected: {}", username);
|
||||
// 发送离线消息
|
||||
offlineMessages.forEach(message -> {
|
||||
messagingTemplate.convertAndSendToUser(username, "/topic/chat", message);
|
||||
messageReceiptStatus.computeIfAbsent(message, k -> ConcurrentHashMap.newKeySet()).add(username);
|
||||
});
|
||||
} else {
|
||||
onlineUsers.remove(username);
|
||||
log.info("User disconnected: {}", username);
|
||||
@@ -64,12 +51,6 @@ public class WebsocketServiceImpl implements WebsocketService {
|
||||
messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size());
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handleSessionDisconnect(SessionDisconnectEvent event) {
|
||||
String username = event.getUser().getName();
|
||||
onlineUsers.remove(username);
|
||||
}
|
||||
|
||||
@Scheduled(fixedRate = 5000)
|
||||
public void sendOnlineUserCount() {
|
||||
messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size());
|
||||
@@ -78,17 +59,8 @@ public class WebsocketServiceImpl implements WebsocketService {
|
||||
@Override
|
||||
public void sendStringToFrontend(String sender, String message) {
|
||||
ChatMessage chatMessage = new ChatMessage(sender, message);
|
||||
offlineMessages.add(chatMessage);
|
||||
messageReceiptStatus.putIfAbsent(chatMessage, ConcurrentHashMap.newKeySet());
|
||||
onlineUsers.forEach(receiver -> {
|
||||
messagingTemplate.convertAndSendToUser(receiver, "/topic/chat", chatMessage);
|
||||
messageReceiptStatus.get(chatMessage).add(receiver);
|
||||
});
|
||||
if(messageReceiptStatus.get(chatMessage).size() == onlineUsers.size()) {
|
||||
//记录完成状态
|
||||
offlineMessages.remove(chatMessage);//从离线消息中移除已发送的消息
|
||||
messageReceiptStatus.remove(chatMessage);//从消息接收状态集合总移除已发送的消息
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package com.youlai.system.controller;
|
||||
package com.youlai.boot.system.controller;
|
||||
|
||||
import com.youlai.system.service.NoticeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.youlai.system.model.form.NoticeForm;
|
||||
import com.youlai.system.model.query.NoticeQuery;
|
||||
import com.youlai.system.model.vo.NoticeVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.youlai.system.common.result.PageResult;
|
||||
import com.youlai.system.common.result.Result;
|
||||
import com.youlai.boot.common.result.PageResult;
|
||||
import com.youlai.boot.common.result.Result;
|
||||
import com.youlai.boot.system.model.form.NoticeForm;
|
||||
import com.youlai.boot.system.model.query.NoticeQuery;
|
||||
import com.youlai.boot.system.model.vo.NoticeVO;
|
||||
import com.youlai.boot.system.service.NoticeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* 通知公告前端控制层
|
||||
@@ -43,7 +41,7 @@ public class NoticeController {
|
||||
@Operation(summary = "新增通知公告")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:add')")
|
||||
public Result saveNotice(@RequestBody @Valid NoticeForm formData ) {
|
||||
public Result<?> saveNotice(@RequestBody @Valid NoticeForm formData ) {
|
||||
boolean result = noticeService.saveNotice(formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
@@ -61,7 +59,7 @@ public class NoticeController {
|
||||
@Operation(summary = "修改通知公告")
|
||||
@PutMapping(value = "/{id}")
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:edit')")
|
||||
public Result updateNotice(
|
||||
public Result<?> updateNotice(
|
||||
@Parameter(description = "通知公告ID") @PathVariable Long id,
|
||||
@RequestBody @Validated NoticeForm formData
|
||||
) {
|
||||
@@ -69,10 +67,26 @@ public class NoticeController {
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "发布通知公告")
|
||||
@PatchMapping(value = "/release/{id}")
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:release')")
|
||||
public Result<?> releaseNotice(@Parameter(description = "通知公告ID") @PathVariable Long id) {
|
||||
boolean result = noticeService.releaseNotice(id);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "撤回通知公告")
|
||||
@PatchMapping(value = "/recall/{id}")
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:recall')")
|
||||
public Result<?> recallNotice(@Parameter(description = "通知公告ID") @PathVariable Long id) {
|
||||
boolean result = noticeService.recallNotice(id);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除通知公告")
|
||||
@DeleteMapping("/{ids}")
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:delete')")
|
||||
public Result deleteNotices(
|
||||
public Result<?> deleteNotices(
|
||||
@Parameter(description = "通知公告ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean result = noticeService.deleteNotices(ids);
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
package com.youlai.system.controller;
|
||||
|
||||
import com.youlai.system.service.NoticeStatusService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.youlai.system.model.form.NoticeStatusForm;
|
||||
import com.youlai.system.model.query.NoticeStatusQuery;
|
||||
import com.youlai.system.model.vo.NoticeStatusVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.youlai.system.common.result.PageResult;
|
||||
import com.youlai.system.common.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* 用户公告状态前端控制层
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-28 16:56
|
||||
*/
|
||||
@Tag(name = "用户公告状态接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/noticeStatuss")
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeStatusController {
|
||||
|
||||
private final NoticeStatusService noticeStatusService;
|
||||
|
||||
@Operation(summary = "用户公告状态分页列表")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@ss.hasPerm('system:noticeStatus:query')")
|
||||
public PageResult<NoticeStatusVO> getNoticeStatusPage(NoticeStatusQuery queryParams ) {
|
||||
IPage<NoticeStatusVO> result = noticeStatusService.getNoticeStatusPage(queryParams);
|
||||
return PageResult.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增用户公告状态")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('system:noticeStatus:add')")
|
||||
public Result saveNoticeStatus(@RequestBody @Valid NoticeStatusForm formData ) {
|
||||
boolean result = noticeStatusService.saveNoticeStatus(formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户公告状态表单数据")
|
||||
@GetMapping("/{id}/form")
|
||||
@PreAuthorize("@ss.hasPerm('system:noticeStatus:edit')")
|
||||
public Result<NoticeStatusForm> getNoticeStatusForm(
|
||||
@Parameter(description = "用户公告状态ID") @PathVariable Long id
|
||||
) {
|
||||
NoticeStatusForm formData = noticeStatusService.getNoticeStatusFormData(id);
|
||||
return Result.success(formData);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改用户公告状态")
|
||||
@PutMapping(value = "/{id}")
|
||||
@PreAuthorize("@ss.hasPerm('system:noticeStatus:edit')")
|
||||
public Result updateNoticeStatus(
|
||||
@Parameter(description = "用户公告状态ID") @PathVariable Long id,
|
||||
@RequestBody @Validated NoticeStatusForm formData
|
||||
) {
|
||||
boolean result = noticeStatusService.updateNoticeStatus(id, formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除用户公告状态")
|
||||
@DeleteMapping("/{ids}")
|
||||
@PreAuthorize("@ss.hasPerm('system:noticeStatus:delete')")
|
||||
public Result deleteNoticeStatuss(
|
||||
@Parameter(description = "用户公告状态ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean result = noticeStatusService.deleteNoticeStatuss(ids);
|
||||
return Result.judge(result);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.youlai.system.converter;
|
||||
package com.youlai.boot.system.converter;
|
||||
|
||||
import com.youlai.system.model.vo.NoticeVO;
|
||||
import com.youlai.boot.system.model.entity.Notice;
|
||||
import com.youlai.boot.system.model.form.NoticeForm;
|
||||
import com.youlai.boot.system.model.vo.NoticeVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.system.model.entity.Notice;
|
||||
import com.youlai.system.model.form.NoticeForm;
|
||||
|
||||
/**
|
||||
* 通知公告对象转换器
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.youlai.system.converter;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.system.model.entity.NoticeStatus;
|
||||
import com.youlai.system.model.form.NoticeStatusForm;
|
||||
|
||||
/**
|
||||
* 用户公告状态对象转换器
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-28 16:56
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface NoticeStatusConverter{
|
||||
|
||||
NoticeStatusForm toForm(NoticeStatus entity);
|
||||
|
||||
NoticeStatus toEntity(NoticeStatusForm formData);
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.youlai.system.mapper;
|
||||
package com.youlai.boot.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.youlai.system.model.entity.Notice;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.system.model.query.NoticeQuery;
|
||||
import com.youlai.system.model.vo.NoticeVO;
|
||||
import com.youlai.boot.system.model.entity.Notice;
|
||||
import com.youlai.boot.system.model.query.NoticeQuery;
|
||||
import com.youlai.boot.system.model.vo.NoticeVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 通知公告Mapper接口
|
||||
@@ -21,8 +22,8 @@ public interface NoticeMapper extends BaseMapper<Notice> {
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
* @return 通知公告分页数据
|
||||
*/
|
||||
Page<NoticeVO> getNoticePage(Page<NoticeVO> page, NoticeQuery queryParams);
|
||||
Page<NoticeVO> getNoticePage(Page<NoticeVO> page, @Param("queryParams") NoticeQuery queryParams);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.youlai.system.mapper;
|
||||
package com.youlai.boot.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.youlai.system.model.entity.NoticeStatus;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.system.model.query.NoticeStatusQuery;
|
||||
import com.youlai.system.model.vo.NoticeStatusVO;
|
||||
import com.youlai.boot.system.model.entity.NoticeStatus;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@@ -16,13 +13,4 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface NoticeStatusMapper extends BaseMapper<NoticeStatus> {
|
||||
|
||||
/**
|
||||
* 获取用户公告状态分页数据
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
*/
|
||||
Page<NoticeStatusVO> getNoticeStatusPage(Page<NoticeStatusVO> page, NoticeStatusQuery queryParams);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.youlai.boot.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 系统配置 实体
|
||||
@@ -11,9 +12,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
* @author Theo
|
||||
* @since 2024-07-29 11:17:26
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(description = "系统配置")
|
||||
@TableName("sys_config")
|
||||
@Data
|
||||
public class Config extends BaseEntity {
|
||||
|
||||
@Schema(description = "配置名称")
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.youlai.boot.system.model.entity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.youlai.boot.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 字典实体
|
||||
@@ -10,8 +11,9 @@ import lombok.Data;
|
||||
* @author haoxr
|
||||
* @since 2022/12/17
|
||||
*/
|
||||
@TableName("sys_dict")
|
||||
@Data
|
||||
@TableName("sys_dict")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Dict extends BaseEntity {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.youlai.system.model.entity;
|
||||
package com.youlai.boot.system.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.youlai.boot.common.base.BaseEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
/**
|
||||
* 通知公告实体对象
|
||||
*
|
||||
@@ -44,15 +47,19 @@ public class Notice extends BaseEntity {
|
||||
* 目标类型(0-全体 1-指定)
|
||||
*/
|
||||
private Integer tarType;
|
||||
/**
|
||||
* 目标ID
|
||||
*/
|
||||
private String tarIds;
|
||||
/**
|
||||
* 发布状态(0-未发布 1已发布 2已撤回)
|
||||
*/
|
||||
private Integer sendStatus;
|
||||
private Integer releaseStatus;
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime sendTime;
|
||||
private LocalDateTime releaseTime;
|
||||
/**
|
||||
* 撤回时间
|
||||
*/
|
||||
@@ -61,13 +68,16 @@ public class Notice extends BaseEntity {
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long createBy;
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private Long updateBy;
|
||||
/**
|
||||
* 逻辑删除标识(0-未删除 1-已删除)
|
||||
*/
|
||||
private Integer isDelete;
|
||||
@TableLogic(value = "0", delval = "1")
|
||||
private Integer isDeleted;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.youlai.system.model.entity;
|
||||
package com.youlai.boot.system.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* 用户公告状态实体对象
|
||||
@@ -38,11 +37,11 @@ public class NoticeStatus implements Serializable {
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 读取状态,0未读,1已读取
|
||||
* 读取状态,0未读,1已读
|
||||
*/
|
||||
private Long readStatus;
|
||||
private Integer readStatus;
|
||||
/**
|
||||
* 用户阅读时间
|
||||
*/
|
||||
private LocalDateTime readTiem;
|
||||
private LocalDateTime readTime;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.youlai.system.model.form;
|
||||
package com.youlai.boot.system.model.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
import jakarta.validation.constraints.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通知公告表单对象
|
||||
@@ -24,6 +25,7 @@ public class NoticeForm implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "通知ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "通知标题")
|
||||
@@ -39,28 +41,15 @@ public class NoticeForm implements Serializable {
|
||||
@Schema(description = "通知类型")
|
||||
private Integer noticeType;
|
||||
|
||||
@Schema(description = "发布人")
|
||||
@NotNull(message = "发布人不能为空")
|
||||
private Long releaseBy;
|
||||
|
||||
@Schema(description = "优先级(0-低 1-中 2-高)")
|
||||
@Range(min = 0, max = 2, message = "优先级取值范围[0,2]")
|
||||
private Integer priority;
|
||||
|
||||
@Schema(description = "目标类型(0-全体 1-指定)")
|
||||
@Range(min = 0, max = 1, message = "目标类型取值范围[0,1]")
|
||||
private Integer tarType;
|
||||
|
||||
@Schema(description = "发布状态(0-未发布 1已发布 2已撤回)")
|
||||
private Integer sendStatus;
|
||||
|
||||
@Schema(description = "发布时间")
|
||||
@NotNull(message = "发布时间不能为空")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime sendTime;
|
||||
|
||||
@Schema(description = "撤回时间")
|
||||
@NotNull(message = "撤回时间不能为空")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime recallTime;
|
||||
|
||||
@Schema(description = "接收人ID集合")
|
||||
private List<String> userIds;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ package com.youlai.boot.system.model.query;
|
||||
import com.youlai.boot.common.base.BasePageQuery;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Schema(description ="字典数据项分页查询对象")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(description ="字典数据项分页查询对象")
|
||||
public class DictPageQuery extends BasePageQuery {
|
||||
|
||||
@Schema(description="关键字(字典项名称)")
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.youlai.system.model.query;
|
||||
package com.youlai.boot.system.model.query;
|
||||
|
||||
import com.youlai.system.common.base.BasePageQuery;
|
||||
import com.youlai.boot.common.base.BasePageQuery;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -13,29 +13,19 @@ import java.util.List;
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 10:31
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(description ="通知公告查询对象")
|
||||
@Getter
|
||||
@Setter
|
||||
public class NoticeQuery extends BasePageQuery {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "通知标题")
|
||||
private String title;
|
||||
@Schema(description = "通知内容")
|
||||
private String content;
|
||||
@Schema(description = "通知类型")
|
||||
private Integer noticeType;
|
||||
@Schema(description = "发布人")
|
||||
private Long releaseBy;
|
||||
@Schema(description = "优先级(0-低 1-中 2-高)")
|
||||
private Integer priority;
|
||||
@Schema(description = "目标类型(0-全体 1-指定)")
|
||||
private Integer tarType;
|
||||
|
||||
@Schema(description = "发布状态(0-未发布 1已发布 2已撤回)")
|
||||
private Integer sendStatus;
|
||||
private Integer releaseStatus;
|
||||
|
||||
@Schema(description = "发布时间")
|
||||
private List<String> sendTime;
|
||||
@Schema(description = "撤回时间")
|
||||
private List<String> recallTime;
|
||||
private List<String> releaseTime;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.youlai.system.model.query;
|
||||
package com.youlai.boot.system.model.query;
|
||||
|
||||
import com.youlai.system.common.base.BasePageQuery;
|
||||
import com.youlai.boot.common.base.BasePageQuery;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -22,12 +21,16 @@ public class NoticeStatusQuery extends BasePageQuery {
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "公共通知id")
|
||||
private Long noticeId;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Integer userId;
|
||||
|
||||
@Schema(description = "读取状态,0未读,1已读取")
|
||||
private Long readStatus;
|
||||
|
||||
@Schema(description = "用户阅读时间")
|
||||
private List<String> readTiem;
|
||||
private List<String> readTime;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.youlai.boot.system.model.query;
|
||||
import com.youlai.boot.common.base.BasePageQuery;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 权限分页查询对象
|
||||
@@ -11,7 +12,8 @@ import lombok.Data;
|
||||
* @since 2022/1/14 22:22
|
||||
*/
|
||||
@Data
|
||||
@Schema
|
||||
@Schema
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PermPageQuery extends BasePageQuery {
|
||||
|
||||
@Schema(description="权限名称")
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.youlai.boot.system.model.query;
|
||||
import com.youlai.boot.common.base.BasePageQuery;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -12,8 +13,9 @@ import java.util.List;
|
||||
* @author haoxr
|
||||
* @since 2022/1/14
|
||||
*/
|
||||
@Schema(description ="用户分页查询对象")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(description ="用户分页查询对象")
|
||||
public class UserPageQuery extends BasePageQuery {
|
||||
|
||||
@Schema(description="关键字(用户名/昵称/手机号)")
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.youlai.system.model.vo;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户公告状态视图对象
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-28 16:56
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema( description = "用户公告状态视图对象")
|
||||
public class NoticeStatusVO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
@Schema(description = "公共通知id")
|
||||
private Long noticeId;
|
||||
@Schema(description = "用户id")
|
||||
private Integer userId;
|
||||
@Schema(description = "读取状态,0未读,1已读取")
|
||||
private Long readStatus;
|
||||
@Schema(description = "用户阅读时间")
|
||||
private LocalDateTime readTiem;
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.youlai.system.model.vo;
|
||||
package com.youlai.boot.system.model.vo;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@@ -25,24 +26,23 @@ public class NoticeVO implements Serializable {
|
||||
private Long id;
|
||||
@Schema(description = "通知标题")
|
||||
private String title;
|
||||
@Schema(description = "通知内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "通知类型")
|
||||
private Integer noticeType;
|
||||
|
||||
@Schema(description = "发布人")
|
||||
private Long releaseBy;
|
||||
private String releaseBy;
|
||||
|
||||
@Schema(description = "优先级(0-低 1-中 2-高)")
|
||||
private Integer priority;
|
||||
|
||||
@Schema(description = "目标类型(0-全体 1-指定)")
|
||||
private Integer tarType;
|
||||
|
||||
@Schema(description = "发布状态(0-未发布 1已发布 2已撤回)")
|
||||
private Integer sendStatus;
|
||||
private Integer releaseStatus;
|
||||
|
||||
@Schema(description = "发布时间")
|
||||
private LocalDateTime sendTime;
|
||||
@Schema(description = "撤回时间")
|
||||
private LocalDateTime recallTime;
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime releaseTime;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.youlai.system.service;
|
||||
package com.youlai.boot.system.service;
|
||||
|
||||
import com.youlai.system.model.entity.Notice;
|
||||
import com.youlai.system.model.form.NoticeForm;
|
||||
import com.youlai.system.model.query.NoticeQuery;
|
||||
import com.youlai.system.model.vo.NoticeVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.boot.system.model.entity.Notice;
|
||||
import com.youlai.boot.system.model.form.NoticeForm;
|
||||
import com.youlai.boot.system.model.query.NoticeQuery;
|
||||
import com.youlai.boot.system.model.vo.NoticeVO;
|
||||
|
||||
/**
|
||||
* 通知公告服务类
|
||||
@@ -18,7 +18,7 @@ public interface NoticeService extends IService<Notice> {
|
||||
/**
|
||||
*通知公告分页列表
|
||||
*
|
||||
* @return
|
||||
* @return 通知公告分页列表
|
||||
*/
|
||||
IPage<NoticeVO> getNoticePage(NoticeQuery queryParams);
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface NoticeService extends IService<Notice> {
|
||||
* 获取通知公告表单数据
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @return
|
||||
* @return 通知公告表单对象
|
||||
*/
|
||||
NoticeForm getNoticeFormData(Long id);
|
||||
|
||||
@@ -34,7 +34,7 @@ public interface NoticeService extends IService<Notice> {
|
||||
* 新增通知公告
|
||||
*
|
||||
* @param formData 通知公告表单对象
|
||||
* @return
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
boolean saveNotice(NoticeForm formData);
|
||||
|
||||
@@ -43,7 +43,7 @@ public interface NoticeService extends IService<Notice> {
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @param formData 通知公告表单对象
|
||||
* @return
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
boolean updateNotice(Long id, NoticeForm formData);
|
||||
|
||||
@@ -51,8 +51,23 @@ public interface NoticeService extends IService<Notice> {
|
||||
* 删除通知公告
|
||||
*
|
||||
* @param ids 通知公告ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean deleteNotices(String ids);
|
||||
|
||||
/**
|
||||
* 发布通知公告
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @return 是否发布成功
|
||||
*/
|
||||
boolean releaseNotice(Long id);
|
||||
|
||||
/**
|
||||
* 撤回通知公告
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @return 是否撤回成功
|
||||
*/
|
||||
boolean recallNotice(Long id);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.youlai.system.service;
|
||||
package com.youlai.boot.system.service;
|
||||
|
||||
import com.youlai.system.model.entity.NoticeStatus;
|
||||
import com.youlai.system.model.form.NoticeStatusForm;
|
||||
import com.youlai.system.model.query.NoticeStatusQuery;
|
||||
import com.youlai.system.model.vo.NoticeStatusVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.boot.system.model.entity.NoticeStatus;
|
||||
|
||||
/**
|
||||
* 用户公告状态服务类
|
||||
@@ -15,44 +11,4 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface NoticeStatusService extends IService<NoticeStatus> {
|
||||
|
||||
/**
|
||||
*用户公告状态分页列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IPage<NoticeStatusVO> getNoticeStatusPage(NoticeStatusQuery queryParams);
|
||||
|
||||
/**
|
||||
* 获取用户公告状态表单数据
|
||||
*
|
||||
* @param id 用户公告状态ID
|
||||
* @return
|
||||
*/
|
||||
NoticeStatusForm getNoticeStatusFormData(Long id);
|
||||
|
||||
/**
|
||||
* 新增用户公告状态
|
||||
*
|
||||
* @param formData 用户公告状态表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean saveNoticeStatus(NoticeStatusForm formData);
|
||||
|
||||
/**
|
||||
* 修改用户公告状态
|
||||
*
|
||||
* @param id 用户公告状态ID
|
||||
* @param formData 用户公告状态表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean updateNoticeStatus(Long id, NoticeStatusForm formData);
|
||||
|
||||
/**
|
||||
* 删除用户公告状态
|
||||
*
|
||||
* @param ids 用户公告状态ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
*/
|
||||
boolean deleteNoticeStatuss(String ids);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +1,34 @@
|
||||
package com.youlai.system.service.impl;
|
||||
package com.youlai.boot.system.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.google.gson.*;
|
||||
import com.youlai.system.model.entity.NoticeStatus;
|
||||
import com.youlai.system.model.entity.SysUser;
|
||||
import com.youlai.system.security.util.SecurityUtils;
|
||||
import com.youlai.system.service.NoticeStatusService;
|
||||
import com.youlai.system.service.SysUserService;
|
||||
import com.youlai.system.service.WebsocketService;
|
||||
import jodd.util.StringUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.system.mapper.NoticeMapper;
|
||||
import com.youlai.system.service.NoticeService;
|
||||
import com.youlai.system.model.entity.Notice;
|
||||
import com.youlai.system.model.form.NoticeForm;
|
||||
import com.youlai.system.model.query.NoticeQuery;
|
||||
import com.youlai.system.model.vo.NoticeVO;
|
||||
import com.youlai.system.converter.NoticeConverter;
|
||||
import com.google.gson.*;
|
||||
import com.youlai.boot.common.constant.SymbolConstant;
|
||||
import com.youlai.boot.core.security.util.SecurityUtils;
|
||||
import com.youlai.boot.platform.websocket.service.WebsocketService;
|
||||
import com.youlai.boot.system.converter.NoticeConverter;
|
||||
import com.youlai.boot.system.mapper.NoticeMapper;
|
||||
import com.youlai.boot.system.model.entity.Notice;
|
||||
import com.youlai.boot.system.model.entity.NoticeStatus;
|
||||
import com.youlai.boot.system.model.entity.User;
|
||||
import com.youlai.boot.system.model.form.NoticeForm;
|
||||
import com.youlai.boot.system.model.query.NoticeQuery;
|
||||
import com.youlai.boot.system.model.vo.NoticeVO;
|
||||
import com.youlai.boot.system.service.NoticeService;
|
||||
import com.youlai.boot.system.service.NoticeStatusService;
|
||||
import com.youlai.boot.system.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 通知公告服务实现类
|
||||
@@ -44,11 +42,11 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
|
||||
private final NoticeConverter noticeConverter;
|
||||
|
||||
private final WebsocketService webSocketServer;
|
||||
private final WebsocketService websocketService;
|
||||
|
||||
private final NoticeStatusService noticeStatusService;
|
||||
|
||||
private final SysUserService sysUserService;
|
||||
private final UserService userService;
|
||||
|
||||
private final Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(LocalDateTime.class, (JsonSerializer<LocalDateTime>) (localDateTime, type, jsonSerializationContext) ->
|
||||
@@ -58,44 +56,29 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
.create();
|
||||
|
||||
private void sendWebSocketMsg(Notice notice) {
|
||||
if (notice.getSendStatus() > 0) {
|
||||
String jsonNotice = gson.toJson(noticeConverter.toVO(notice));
|
||||
webSocketServer.sendStringToFrontend(SecurityUtils.getUsername(), jsonNotice);
|
||||
List<SysUser> list = sysUserService.list();
|
||||
for (SysUser sysUser : list) {
|
||||
NoticeStatus noticeStatus = noticeStatusService.getOne(new LambdaQueryWrapper<NoticeStatus>().eq(NoticeStatus::getUserId, sysUser.getId()).eq(NoticeStatus::getNoticeId, notice.getId()));
|
||||
if (noticeStatus == null) {
|
||||
noticeStatus = new NoticeStatus();
|
||||
noticeStatus.setUserId(sysUser.getId());
|
||||
noticeStatus.setNoticeId(notice.getId());
|
||||
noticeStatus.setReadStatus(0L);
|
||||
noticeStatusService.save(noticeStatus);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
String jsonNotice = gson.toJson(noticeConverter.toVO(notice));
|
||||
websocketService.sendStringToFrontend(SecurityUtils.getUsername(), jsonNotice);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通知公告分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link IPage<NoticeVO>} 通知公告分页列表
|
||||
* @return {@link IPage<NoticeVO>} 通知公告分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<NoticeVO> getNoticePage(NoticeQuery queryParams) {
|
||||
Page<NoticeVO> pageVO = this.baseMapper.getNoticePage(
|
||||
return this.baseMapper.getNoticePage(
|
||||
new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
|
||||
queryParams
|
||||
);
|
||||
return pageVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通知公告表单数据
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @return
|
||||
* @return {@link NoticeForm} 通知公告表单对象
|
||||
*/
|
||||
@Override
|
||||
public NoticeForm getNoticeFormData(Long id) {
|
||||
@@ -107,20 +90,15 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
* 新增通知公告
|
||||
*
|
||||
* @param formData 通知公告表单对象
|
||||
* @return
|
||||
* @return {@link Boolean} 是否新增成功
|
||||
*/
|
||||
@Override
|
||||
public boolean saveNotice(NoticeForm formData) {
|
||||
Notice entity = noticeConverter.toEntity(formData);
|
||||
entity.setCreateBy(SecurityUtils.getUserId());
|
||||
entity.setReleaseBy(SecurityUtils.getUserId());
|
||||
entity.setUpdateBy(SecurityUtils.getUserId());
|
||||
entity.setIsDelete(0);
|
||||
boolean result = this.save(entity);
|
||||
if (result) {
|
||||
sendWebSocketMsg(entity);
|
||||
if (entity.getTarType() == 1) {
|
||||
Assert.notBlank(entity.getTarIds(), "指定用户不能为空");
|
||||
}
|
||||
return result;
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,36 +106,99 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @param formData 通知公告表单对象
|
||||
* @return
|
||||
* @return {@link Boolean} 是否更新成功
|
||||
*/
|
||||
@Override
|
||||
public boolean updateNotice(Long id, NoticeForm formData) {
|
||||
Notice entity = noticeConverter.toEntity(formData);
|
||||
entity.setUpdateBy(SecurityUtils.getUserId());
|
||||
entity.setIsDelete(0);
|
||||
boolean result = this.updateById(entity);
|
||||
if (result) {
|
||||
sendWebSocketMsg(entity);
|
||||
if (entity.getTarType() == 1) {
|
||||
Assert.notBlank(entity.getTarIds(), "指定用户不能为空");
|
||||
}
|
||||
return result;
|
||||
return this.updateById(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除通知公告
|
||||
*
|
||||
* @param ids 通知公告ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
* @return {@link Boolean} 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteNotices(String ids) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的通知公告数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> idList = Arrays.stream(ids.split(","))
|
||||
List<Long> idList = Arrays.stream(ids.split(SymbolConstant.COMMA))
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
LambdaUpdateWrapper<Notice> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.in(Notice::getId, idList).set(Notice::getIsDelete, 1);
|
||||
return this.update(wrapper);
|
||||
boolean b = this.removeByIds(idList);
|
||||
if (b) {
|
||||
//删除通知公告的同时,需要删除通知公告对应的用户通知状态
|
||||
noticeStatusService.remove(new LambdaQueryWrapper<NoticeStatus>().in(NoticeStatus::getNoticeId, idList));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布通知公告
|
||||
* @param id 通知公告ID
|
||||
* @return 是否发布成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean releaseNotice(Long id) {
|
||||
Notice notice = this.getById(id);
|
||||
Assert.notNull(notice, "通知公告不存在");
|
||||
Assert.isTrue(notice.getReleaseStatus() == 0, "通知公告已发布");
|
||||
notice.setReleaseStatus(1);
|
||||
notice.setReleaseTime(LocalDateTime.now());
|
||||
this.updateById(notice);
|
||||
//发布通知公告的同时,需要将通知公告发送给目标用户
|
||||
//先删除掉该通知公告之前对应的用户信息
|
||||
noticeStatusService.remove(new LambdaQueryWrapper<NoticeStatus>().eq(NoticeStatus::getNoticeId, id));
|
||||
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (notice.getTarType() == 1) {
|
||||
Assert.notBlank(notice.getTarIds(), "指定用户不能为空");
|
||||
queryWrapper.in(User::getId, Arrays.asList(notice.getTarIds().split(SymbolConstant.COMMA)));
|
||||
}
|
||||
//查询出目标用户,增加用户通知状态
|
||||
List<User> list = userService.list(queryWrapper);
|
||||
List<NoticeStatus> needSaveList = list.stream().map(user -> {
|
||||
NoticeStatus noticeStatus = new NoticeStatus();
|
||||
noticeStatus.setNoticeId(id);
|
||||
noticeStatus.setUserId(user.getId());
|
||||
noticeStatus.setReadStatus(0);
|
||||
return noticeStatus;
|
||||
}).toList();
|
||||
if(needSaveList.size() > 0){
|
||||
noticeStatusService.saveBatch(needSaveList);
|
||||
}
|
||||
//最后,给当前在线的用户发送websocket消息
|
||||
//TODO: 通知公告的websocket消息发送
|
||||
return this.updateById(notice);
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤回通知公告
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @return 是否撤回成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean recallNotice(Long id) {
|
||||
Notice notice = this.getById(id);
|
||||
Assert.notNull(notice, "通知公告不存在");
|
||||
Assert.isTrue(notice.getReleaseStatus() == 1, "通知公告未发布");
|
||||
notice.setReleaseStatus(2);
|
||||
notice.setRecallTime(LocalDateTime.now());
|
||||
if (!this.updateById(notice)) {
|
||||
return false;
|
||||
}
|
||||
//先删除掉该通知公告之前对应的用户信息
|
||||
noticeStatusService.remove(new LambdaQueryWrapper<NoticeStatus>().eq(NoticeStatus::getNoticeId, id));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,11 @@
|
||||
package com.youlai.system.service.impl;
|
||||
package com.youlai.boot.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.boot.system.mapper.NoticeStatusMapper;
|
||||
import com.youlai.boot.system.model.entity.NoticeStatus;
|
||||
import com.youlai.boot.system.service.NoticeStatusService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.system.mapper.NoticeStatusMapper;
|
||||
import com.youlai.system.service.NoticeStatusService;
|
||||
import com.youlai.system.model.entity.NoticeStatus;
|
||||
import com.youlai.system.model.form.NoticeStatusForm;
|
||||
import com.youlai.system.model.query.NoticeStatusQuery;
|
||||
import com.youlai.system.model.vo.NoticeStatusVO;
|
||||
import com.youlai.system.converter.NoticeStatusConverter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 用户公告状态服务实现类
|
||||
@@ -30,74 +17,4 @@ import cn.hutool.core.util.StrUtil;
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeStatusServiceImpl extends ServiceImpl<NoticeStatusMapper, NoticeStatus> implements NoticeStatusService {
|
||||
|
||||
private final NoticeStatusConverter noticeStatusConverter;
|
||||
|
||||
/**
|
||||
* 获取用户公告状态分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link IPage<NoticeStatusVO>} 用户公告状态分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<NoticeStatusVO> getNoticeStatusPage(NoticeStatusQuery queryParams) {
|
||||
Page<NoticeStatusVO> pageVO = this.baseMapper.getNoticeStatusPage(
|
||||
new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
|
||||
queryParams
|
||||
);
|
||||
return pageVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户公告状态表单数据
|
||||
*
|
||||
* @param id 用户公告状态ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public NoticeStatusForm getNoticeStatusFormData(Long id) {
|
||||
NoticeStatus entity = this.getById(id);
|
||||
return noticeStatusConverter.toForm(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户公告状态
|
||||
*
|
||||
* @param formData 用户公告状态表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean saveNoticeStatus(NoticeStatusForm formData) {
|
||||
NoticeStatus entity = noticeStatusConverter.toEntity(formData);
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户公告状态
|
||||
*
|
||||
* @param id 用户公告状态ID
|
||||
* @param formData 用户公告状态表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean updateNoticeStatus(Long id,NoticeStatusForm formData) {
|
||||
NoticeStatus entity = noticeStatusConverter.toEntity(formData);
|
||||
return this.updateById(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户公告状态
|
||||
*
|
||||
* @param ids 用户公告状态ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteNoticeStatuss(String ids) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的用户公告状态数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> idList = Arrays.stream(ids.split(","))
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
return this.removeByIds(idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user