feat: 新建消息通知后端部分的
新建根据websocket的后端部分代码.其中包含sql数据库文件
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package com.youlai.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 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-27 10:31
|
||||
*/
|
||||
@Tag(name = "通知公告接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/notices")
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeController {
|
||||
|
||||
private final NoticeService noticeService;
|
||||
|
||||
@Operation(summary = "通知公告分页列表")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:query')")
|
||||
public PageResult<NoticeVO> getNoticePage(NoticeQuery queryParams ) {
|
||||
IPage<NoticeVO> result = noticeService.getNoticePage(queryParams);
|
||||
return PageResult.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增通知公告")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:add')")
|
||||
public Result saveNotice(@RequestBody @Valid NoticeForm formData ) {
|
||||
boolean result = noticeService.saveNotice(formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取通知公告表单数据")
|
||||
@GetMapping("/{id}/form")
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:edit')")
|
||||
public Result<NoticeForm> getNoticeForm(
|
||||
@Parameter(description = "通知公告ID") @PathVariable Long id
|
||||
) {
|
||||
NoticeForm formData = noticeService.getNoticeFormData(id);
|
||||
return Result.success(formData);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改通知公告")
|
||||
@PutMapping(value = "/{id}")
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:edit')")
|
||||
public Result updateNotice(
|
||||
@Parameter(description = "通知公告ID") @PathVariable Long id,
|
||||
@RequestBody @Validated NoticeForm formData
|
||||
) {
|
||||
boolean result = noticeService.updateNotice(id, formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除通知公告")
|
||||
@DeleteMapping("/{ids}")
|
||||
@PreAuthorize("@ss.hasPerm('system:notice:delete')")
|
||||
public Result deleteNotices(
|
||||
@Parameter(description = "通知公告ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean result = noticeService.deleteNotices(ids);
|
||||
return Result.judge(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
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-27 09:53
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public class WebsocketController {
|
||||
private final SimpMessagingTemplate messagingTemplate;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 广播发送消息
|
||||
*
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
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-27 09:53
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface NoticeStatusConverter{
|
||||
|
||||
NoticeStatusForm toForm(NoticeStatus entity);
|
||||
|
||||
NoticeStatus toEntity(NoticeStatusForm formData);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.youlai.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 org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户公告状态Mapper接口
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 09:53
|
||||
*/
|
||||
@Mapper
|
||||
public interface NoticeStatusMapper extends BaseMapper<NoticeStatus> {
|
||||
|
||||
/**
|
||||
* 获取用户公告状态分页数据
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
*/
|
||||
Page<NoticeStatusVO> getNoticeStatusPage(Page<NoticeStatusVO> page, NoticeStatusQuery queryParams);
|
||||
|
||||
}
|
||||
73
src/main/java/com/youlai/system/model/entity/Notice.java
Normal file
73
src/main/java/com/youlai/system/model/entity/Notice.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package com.youlai.system.model.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* 通知公告实体对象
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 10:31
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("sys_notice")
|
||||
public class Notice extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 通知标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 通知内容
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 通知类型
|
||||
*/
|
||||
private Integer noticeType;
|
||||
/**
|
||||
* 发布人
|
||||
*/
|
||||
private Long releaseBy;
|
||||
/**
|
||||
* 优先级(0-低 1-中 2-高)
|
||||
*/
|
||||
private Integer priority;
|
||||
/**
|
||||
* 目标类型(0-全体 1-指定)
|
||||
*/
|
||||
private Integer tarType;
|
||||
/**
|
||||
* 发布状态(0-未发布 1已发布 2已撤回)
|
||||
*/
|
||||
private Integer sendStatus;
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime sendTime;
|
||||
/**
|
||||
* 撤回时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime recallTime;
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private Long createBy;
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
private Long updateBy;
|
||||
/**
|
||||
* 逻辑删除标识(0-未删除 1-已删除)
|
||||
*/
|
||||
private Integer isDelete;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.youlai.system.model.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* 用户公告状态实体对象
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 09:53
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("sys_notice_status")
|
||||
public class NoticeStatus extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 公共通知id
|
||||
*/
|
||||
private Long noticeId;
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Integer userId;
|
||||
/**
|
||||
* 读取状态,0未读,1已读取
|
||||
*/
|
||||
private Long readStatus;
|
||||
/**
|
||||
* 用户阅读时间
|
||||
*/
|
||||
private LocalDateTime readTiem;
|
||||
}
|
||||
66
src/main/java/com/youlai/system/model/form/NoticeForm.java
Normal file
66
src/main/java/com/youlai/system/model/form/NoticeForm.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.youlai.system.model.form;
|
||||
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* 通知公告表单对象
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 10:31
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "通知公告表单对象")
|
||||
public class NoticeForm implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "通知标题")
|
||||
@NotBlank(message = "通知标题不能为空")
|
||||
@Size(max=50, message="通知标题长度不能超过50个字符")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "通知内容")
|
||||
@NotBlank(message = "通知内容不能为空")
|
||||
@Size(max=65535, message="通知内容长度不能超过65535个字符")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "通知类型")
|
||||
private Integer noticeType;
|
||||
|
||||
@Schema(description = "发布人")
|
||||
@NotNull(message = "发布人不能为空")
|
||||
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;
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.youlai.system.model.form;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* 用户公告状态表单对象
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 09:53
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "用户公告状态表单对象")
|
||||
public class NoticeStatusForm implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
}
|
||||
41
src/main/java/com/youlai/system/model/query/NoticeQuery.java
Normal file
41
src/main/java/com/youlai/system/model/query/NoticeQuery.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.youlai.system.model.query;
|
||||
|
||||
import com.youlai.system.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;
|
||||
|
||||
/**
|
||||
* 通知公告分页查询对象
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 10:31
|
||||
*/
|
||||
@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;
|
||||
@Schema(description = "发布时间")
|
||||
private List<String> sendTime;
|
||||
@Schema(description = "撤回时间")
|
||||
private List<String> recallTime;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.youlai.system.model.query;
|
||||
|
||||
import com.youlai.system.common.base.BasePageQuery;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户公告状态分页查询对象
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 09:53
|
||||
*/
|
||||
@Schema(description ="用户公告状态查询对象")
|
||||
@Getter
|
||||
@Setter
|
||||
public class NoticeStatusQuery extends BasePageQuery {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
25
src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java
Normal file
25
src/main/java/com/youlai/system/model/vo/NoticeStatusVO.java
Normal file
@@ -0,0 +1,25 @@
|
||||
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-27 09:53
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema( description = "用户公告状态视图对象")
|
||||
public class NoticeStatusVO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
48
src/main/java/com/youlai/system/model/vo/NoticeVO.java
Normal file
48
src/main/java/com/youlai/system/model/vo/NoticeVO.java
Normal file
@@ -0,0 +1,48 @@
|
||||
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-27 10:31
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema( description = "通知公告视图对象")
|
||||
public class NoticeVO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
@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;
|
||||
@Schema(description = "发布时间")
|
||||
private LocalDateTime sendTime;
|
||||
@Schema(description = "撤回时间")
|
||||
private LocalDateTime recallTime;
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
58
src/main/java/com/youlai/system/service/NoticeService.java
Normal file
58
src/main/java/com/youlai/system/service/NoticeService.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.youlai.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;
|
||||
|
||||
/**
|
||||
* 通知公告服务类
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 10:31
|
||||
*/
|
||||
public interface NoticeService extends IService<Notice> {
|
||||
|
||||
/**
|
||||
*通知公告分页列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IPage<NoticeVO> getNoticePage(NoticeQuery queryParams);
|
||||
|
||||
/**
|
||||
* 获取通知公告表单数据
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @return
|
||||
*/
|
||||
NoticeForm getNoticeFormData(Long id);
|
||||
|
||||
/**
|
||||
* 新增通知公告
|
||||
*
|
||||
* @param formData 通知公告表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean saveNotice(NoticeForm formData);
|
||||
|
||||
/**
|
||||
* 修改通知公告
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @param formData 通知公告表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean updateNotice(Long id, NoticeForm formData);
|
||||
|
||||
/**
|
||||
* 删除通知公告
|
||||
*
|
||||
* @param ids 通知公告ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
*/
|
||||
boolean deleteNotices(String ids);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.youlai.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;
|
||||
|
||||
/**
|
||||
* 用户公告状态服务类
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 09:53
|
||||
*/
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -6,4 +6,9 @@ public interface WebsocketService {
|
||||
|
||||
void removeUser(String username) ;
|
||||
|
||||
/**
|
||||
* 发送消息到前端
|
||||
* @param message
|
||||
*/
|
||||
void sendStringToFrontend(String message);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.youlai.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.google.gson.*;
|
||||
import com.youlai.system.security.util.SecurityUtils;
|
||||
import com.youlai.system.service.WebsocketService;
|
||||
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 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;
|
||||
|
||||
/**
|
||||
* 通知公告服务实现类
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 10:31
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
|
||||
|
||||
private final NoticeConverter noticeConverter;
|
||||
|
||||
private final WebsocketService webSocketServer;
|
||||
private final Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(LocalDateTime.class, (JsonSerializer<LocalDateTime>) (localDateTime, type, jsonSerializationContext) ->
|
||||
new JsonPrimitive(localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)))
|
||||
.registerTypeAdapter(LocalDateTime.class, (JsonDeserializer<LocalDateTime>) (jsonElement, type, jsonDeserializationContext) ->
|
||||
LocalDateTime.parse(jsonElement.getAsString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME))
|
||||
.create();
|
||||
|
||||
private void sendWebSocketMsg(Notice notice) {
|
||||
if(notice.getSendStatus() > 0){
|
||||
String jsonNotice = gson.toJson(noticeConverter.toVO(notice));
|
||||
webSocketServer.sendStringToFrontend(jsonNotice);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通知公告分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link IPage<NoticeVO>} 通知公告分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<NoticeVO> getNoticePage(NoticeQuery queryParams) {
|
||||
Page<NoticeVO> pageVO = this.baseMapper.getNoticePage(
|
||||
new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
|
||||
queryParams
|
||||
);
|
||||
return pageVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通知公告表单数据
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public NoticeForm getNoticeFormData(Long id) {
|
||||
Notice entity = this.getById(id);
|
||||
return noticeConverter.toForm(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增通知公告
|
||||
*
|
||||
* @param formData 通知公告表单对象
|
||||
* @return
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新通知公告
|
||||
*
|
||||
* @param id 通知公告ID
|
||||
* @param formData 通知公告表单对象
|
||||
* @return
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除通知公告
|
||||
*
|
||||
* @param ids 通知公告ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteNotices(String ids) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的通知公告数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> idList = Arrays.stream(ids.split(","))
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
LambdaUpdateWrapper<Notice> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.in(Notice::getId, idList).set(Notice::getIsDelete, 1);
|
||||
return this.update(wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.youlai.system.service.impl;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 用户公告状态服务实现类
|
||||
*
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 09:53
|
||||
*/
|
||||
@Service
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,4 +49,10 @@ public class WebsocketServiceImpl implements WebsocketService {
|
||||
public void sendOnlineUserCount() {
|
||||
messagingTemplate.convertAndSend("/topic/onlineUserCount", onlineUsers.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStringToFrontend(String message) {
|
||||
messagingTemplate.convertAndSend("/topic/chat", message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user