feat: 消息功能完成
This commit is contained in:
parent
a427c38fcb
commit
a492aee703
|
@ -18,9 +18,9 @@ public class Knife4jConfig {
|
||||||
// 作者等信息
|
// 作者等信息
|
||||||
Contact contact = new Contact().name("Bunny").email("1319900154@qq.com").url("http://z-bunny.cn");
|
Contact contact = new Contact().name("Bunny").email("1319900154@qq.com").url("http://z-bunny.cn");
|
||||||
// 使用协议
|
// 使用协议
|
||||||
License license = new License().name("MIT").url("http://MUT.com");
|
License license = new License().name("MIT").url("https://MUT.com");
|
||||||
// 相关信息
|
// 相关信息
|
||||||
Info info = new Info().title("Bunny-Java-Template").description("Bunny的Java模板").version("v1.0.0").contact(contact).license(license).termsOfService("维护不易~求个start");
|
Info info = new Info().title("Bunny-Admin").description("权限管理模板").version("v1.0.0").contact(contact).license(license).termsOfService("MIT");
|
||||||
|
|
||||||
return new OpenAPI().info(info).externalDocs(new ExternalDocumentation());
|
return new OpenAPI().info(info).externalDocs(new ExternalDocumentation());
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ public class Knife4jConfig {
|
||||||
// 管理员相关分类接口
|
// 管理员相关分类接口
|
||||||
@Bean
|
@Bean
|
||||||
public GroupedOpenApi groupedOpenAdminApi() {
|
public GroupedOpenApi groupedOpenAdminApi() {
|
||||||
return GroupedOpenApi.builder().group("admin管理员接口请求").pathsToMatch("/admin/**").build();
|
return GroupedOpenApi.builder().group("默认请求接口").pathsToMatch("/admin/**").build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,13 @@ import lombok.NoArgsConstructor;
|
||||||
@Schema(name = "MessageUserDto对象", title = "用户消息查询内容", description = "用户消息查询内容")
|
@Schema(name = "MessageUserDto对象", title = "用户消息查询内容", description = "用户消息查询内容")
|
||||||
public class MessageUserDto {
|
public class MessageUserDto {
|
||||||
|
|
||||||
|
@Schema(name = "title", title = "消息标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
@Schema(name = "messageType", title = "消息类型")
|
@Schema(name = "messageType", title = "消息类型")
|
||||||
private String messageType;
|
private String messageType;
|
||||||
|
|
||||||
@Schema(name = "status", title = "0:未读 1:已读")
|
@Schema(name = "status", title = "0:未读 1:已读")
|
||||||
private Boolean status;
|
private Boolean status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class AssignRolesToRoutersDto {
|
||||||
|
|
||||||
@Schema(name = "routerId", title = "路由id")
|
@Schema(name = "routerId", title = "路由id")
|
||||||
@NotNull(message = "路由id不能为空")
|
@NotNull(message = "路由id不能为空")
|
||||||
|
@NotEmpty(message = "路由id不能为空")
|
||||||
private List<Long> routerIds;
|
private List<Long> routerIds;
|
||||||
|
|
||||||
@Schema(name = "roleIds", title = "角色id列表")
|
@Schema(name = "roleIds", title = "角色id列表")
|
||||||
|
|
|
@ -49,7 +49,6 @@ public class RouterUpdateDto {
|
||||||
|
|
||||||
@Schema(name = "routerRank", title = "等级")
|
@Schema(name = "routerRank", title = "等级")
|
||||||
@JsonProperty("rank")
|
@JsonProperty("rank")
|
||||||
@NotNull(message = "菜单排序不能为空")
|
|
||||||
@Max(value = 999, message = "不能超过999")
|
@Max(value = 999, message = "不能超过999")
|
||||||
private Integer routerRank;
|
private Integer routerRank;
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,26 @@
|
||||||
package cn.bunny.dao.vo.system.message;
|
package cn.bunny.dao.vo.system.message;
|
||||||
|
|
||||||
|
import cn.bunny.dao.common.vo.BaseVo;
|
||||||
import com.alibaba.fastjson2.annotation.JSONField;
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
@Schema(name = "MessageVo对象", title = "系统消息返回内容", description = "系统消息返回内容")
|
@Schema(name = "MessageVo对象", title = "系统消息返回内容", description = "系统消息返回内容")
|
||||||
public class MessageUserVo {
|
public class MessageUserVo extends BaseVo {
|
||||||
|
|
||||||
@Schema(name = "id", title = "主键")
|
@Schema(name = "id", title = "主键")
|
||||||
@JsonProperty("id")
|
@JsonProperty("id")
|
||||||
|
@ -41,4 +46,14 @@ public class MessageUserVo {
|
||||||
@Schema(name = "extra", title = "消息等级详情")
|
@Schema(name = "extra", title = "消息等级详情")
|
||||||
private String extra;
|
private String extra;
|
||||||
|
|
||||||
|
@Schema(name = "status", title = "消息状态")
|
||||||
|
private Boolean status;
|
||||||
|
|
||||||
|
@Schema(name = "updateTime", title = "更新时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||||
|
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||||
|
@JsonProperty("acceptanceTime")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,10 +85,24 @@ public class MessageController {
|
||||||
return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
|
return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "用户将消息标为已读", description = "用户将消息标为已读")
|
||||||
|
@PutMapping("/noManage/updateUserMarkAsRead")
|
||||||
|
public Mono<Result<String>> updateUserMarkAsRead(@Valid @RequestBody List<Long> ids) {
|
||||||
|
messageService.updateUserMarkAsRead(ids);
|
||||||
|
return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "删除系统消息", description = "删除系统消息")
|
@Operation(summary = "删除系统消息", description = "删除系统消息")
|
||||||
@DeleteMapping("deleteMessage")
|
@DeleteMapping("deleteMessage")
|
||||||
public Mono<Result<String>> deleteMessage(@RequestBody List<Long> ids) {
|
public Mono<Result<String>> deleteMessage(@RequestBody List<Long> ids) {
|
||||||
messageService.deleteMessage(ids);
|
messageService.deleteMessage(ids);
|
||||||
return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
|
return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "用户删除消息", description = "用户删除消息")
|
||||||
|
@DeleteMapping("/noManage/deleteUserMessageByIds")
|
||||||
|
public Mono<Result<String>> deleteUserMessageByIds(@RequestBody List<Long> ids) {
|
||||||
|
messageService.deleteUserMessageByIds(ids);
|
||||||
|
return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import cn.bunny.dao.pojo.result.Result;
|
||||||
import cn.bunny.dao.vo.system.message.MessageReceivedWithUserVo;
|
import cn.bunny.dao.vo.system.message.MessageReceivedWithUserVo;
|
||||||
import cn.bunny.services.service.MessageReceivedService;
|
import cn.bunny.services.service.MessageReceivedService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -20,6 +21,7 @@ import java.util.List;
|
||||||
* @author Bunny
|
* @author Bunny
|
||||||
* @since 2024-10-31
|
* @since 2024-10-31
|
||||||
*/
|
*/
|
||||||
|
@Tag(name = "消息接受关系", description = "消息接受关系相关接口")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/admin/messageReceived")
|
@RequestMapping("/admin/messageReceived")
|
||||||
public class MessageReceivedController {
|
public class MessageReceivedController {
|
||||||
|
|
|
@ -41,6 +41,13 @@ public class RouterRoleController {
|
||||||
return Mono.just(Result.success());
|
return Mono.just(Result.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "批量为菜单添加角色", description = "批量为菜单添加角色")
|
||||||
|
@PostMapping("assignAddBatchRolesToRouter")
|
||||||
|
public Mono<Result<String>> assignAddBatchRolesToRouter(@RequestBody AssignRolesToRoutersDto dto) {
|
||||||
|
routerRoleService.assignAddBatchRolesToRouter(dto);
|
||||||
|
return Mono.just(Result.success());
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "清除选中菜单所有角色", description = "清除选中菜单所有角色")
|
@Operation(summary = "清除选中菜单所有角色", description = "清除选中菜单所有角色")
|
||||||
@DeleteMapping("clearAllRolesSelect")
|
@DeleteMapping("clearAllRolesSelect")
|
||||||
public Mono<Result<String>> clearAllRolesSelect(@RequestBody List<Long> routerIds) {
|
public Mono<Result<String>> clearAllRolesSelect(@RequestBody List<Long> routerIds) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class UserController {
|
||||||
return Mono.just(Result.success(voList));
|
return Mono.just(Result.success(voList));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "更新用户信息", description = "更新用户信息后需要更新Redis中的内容")
|
@Operation(summary = "更新用户信息", description = "更新用户信息,需要更新Redis中的内容")
|
||||||
@PutMapping("updateAdminUser")
|
@PutMapping("updateAdminUser")
|
||||||
public Result<String> updateAdminUser(@Valid @RequestBody AdminUserUpdateDto dto) {
|
public Result<String> updateAdminUser(@Valid @RequestBody AdminUserUpdateDto dto) {
|
||||||
userService.updateAdminUser(dto);
|
userService.updateAdminUser(dto);
|
||||||
|
|
|
@ -55,4 +55,5 @@ public interface MessageMapper extends BaseMapper<Message> {
|
||||||
* @return 消息返回对象
|
* @return 消息返回对象
|
||||||
*/
|
*/
|
||||||
MessageVo selectMessageVoById(Long id);
|
MessageVo selectMessageVoById(Long id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,12 @@ public interface MessageReceivedMapper extends BaseMapper<MessageReceived> {
|
||||||
* @return 消息接收人用户名等信息
|
* @return 消息接收人用户名等信息
|
||||||
*/
|
*/
|
||||||
List<MessageReceivedWithUserVo> selectUserinfoListByMessageId(Long messageId);
|
List<MessageReceivedWithUserVo> selectUserinfoListByMessageId(Long messageId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据当前用户id删除消息接受表中数据
|
||||||
|
*
|
||||||
|
* @param ids 消息列表
|
||||||
|
* @param userId 用户id
|
||||||
|
*/
|
||||||
|
void deleteBatchIdsByMessageIdsAndUserIdWithPhysics(List<Long> ids, Long userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,4 +38,11 @@ public interface RouterRoleMapper extends BaseMapper<RouterRole> {
|
||||||
* @return 路由角色关系视图列表
|
* @return 路由角色关系视图列表
|
||||||
*/
|
*/
|
||||||
List<ViewRouterRole> viewRouterRolesWithAll();
|
List<ViewRouterRole> viewRouterRolesWithAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据Id列表物理删除路由角色关系表
|
||||||
|
*
|
||||||
|
* @param ids 路由角色关系表ids
|
||||||
|
*/
|
||||||
|
void deleteBatchIdsWithPhysics(List<Long> ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,4 +68,18 @@ public interface MessageService extends IService<Message> {
|
||||||
* @return 消息详情
|
* @return 消息详情
|
||||||
*/
|
*/
|
||||||
MessageVo getMessageDetailById(Long id);
|
MessageVo getMessageDetailById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户将消息标为已读
|
||||||
|
*
|
||||||
|
* @param ids 消息id列表
|
||||||
|
*/
|
||||||
|
void updateUserMarkAsRead(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户删除消息
|
||||||
|
*
|
||||||
|
* @param ids 消息Id列表
|
||||||
|
*/
|
||||||
|
void deleteUserMessageByIds(List<Long> ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,11 @@ public interface RouterRoleService extends IService<RouterRole> {
|
||||||
* @param routerIds 路由id
|
* @param routerIds 路由id
|
||||||
*/
|
*/
|
||||||
void clearAllRolesSelect(List<Long> routerIds);
|
void clearAllRolesSelect(List<Long> routerIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量为菜单添加角色
|
||||||
|
*
|
||||||
|
* @param dto 路由分配角色
|
||||||
|
*/
|
||||||
|
void assignAddBatchRolesToRouter(AssignRolesToRoutersDto dto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import cn.bunny.services.mapper.MessageReceivedMapper;
|
||||||
import cn.bunny.services.service.MessageReceivedService;
|
import cn.bunny.services.service.MessageReceivedService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ import java.util.List;
|
||||||
* @since 2024-10-31
|
* @since 2024-10-31
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class MessageReceivedServiceImpl extends ServiceImpl<MessageReceivedMapper, MessageReceived> implements MessageReceivedService {
|
public class MessageReceivedServiceImpl extends ServiceImpl<MessageReceivedMapper, MessageReceived> implements MessageReceivedService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,5 +47,4 @@ public class MessageReceivedServiceImpl extends ServiceImpl<MessageReceivedMappe
|
||||||
}
|
}
|
||||||
return baseMapper.selectUserinfoListByMessageId(messageId);
|
return baseMapper.selectUserinfoListByMessageId(messageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cn.bunny.services.service.impl;
|
package cn.bunny.services.service.impl;
|
||||||
|
|
||||||
import cn.bunny.common.service.context.BaseContext;
|
import cn.bunny.common.service.context.BaseContext;
|
||||||
|
import cn.bunny.common.service.exception.BunnyException;
|
||||||
import cn.bunny.dao.common.entity.BaseEntity;
|
import cn.bunny.dao.common.entity.BaseEntity;
|
||||||
import cn.bunny.dao.dto.system.message.MessageAddDto;
|
import cn.bunny.dao.dto.system.message.MessageAddDto;
|
||||||
import cn.bunny.dao.dto.system.message.MessageDto;
|
import cn.bunny.dao.dto.system.message.MessageDto;
|
||||||
|
@ -9,6 +10,7 @@ import cn.bunny.dao.dto.system.message.MessageUserDto;
|
||||||
import cn.bunny.dao.entity.system.Message;
|
import cn.bunny.dao.entity.system.Message;
|
||||||
import cn.bunny.dao.entity.system.MessageReceived;
|
import cn.bunny.dao.entity.system.MessageReceived;
|
||||||
import cn.bunny.dao.pojo.result.PageResult;
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
|
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
import cn.bunny.dao.vo.system.message.MessageUserVo;
|
import cn.bunny.dao.vo.system.message.MessageUserVo;
|
||||||
import cn.bunny.dao.vo.system.message.MessageVo;
|
import cn.bunny.dao.vo.system.message.MessageVo;
|
||||||
import cn.bunny.services.factory.UserFactory;
|
import cn.bunny.services.factory.UserFactory;
|
||||||
|
@ -27,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,6 +102,16 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
|
||||||
List<MessageReceived> messageReceivedList = messageReceivedMapper.selectList(Wrappers.<MessageReceived>lambdaQuery().eq(MessageReceived::getReceivedUserId, BaseContext.getUserId()));
|
List<MessageReceived> messageReceivedList = messageReceivedMapper.selectList(Wrappers.<MessageReceived>lambdaQuery().eq(MessageReceived::getReceivedUserId, BaseContext.getUserId()));
|
||||||
List<Long> messageIds = messageReceivedList.stream().map(MessageReceived::getMessageId).toList();
|
List<Long> messageIds = messageReceivedList.stream().map(MessageReceived::getMessageId).toList();
|
||||||
|
|
||||||
|
// 消息为空直接返回
|
||||||
|
if (messageIds.isEmpty()) {
|
||||||
|
return PageResult.<MessageUserVo>builder()
|
||||||
|
.list(new ArrayList<>())
|
||||||
|
.pageNo(pageParams.getCurrent())
|
||||||
|
.pageSize(pageParams.getSize())
|
||||||
|
.total(pageParams.getTotal())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
// 根据消息所有包含匹配当前消息Id的列表
|
// 根据消息所有包含匹配当前消息Id的列表
|
||||||
IPage<Message> page = baseMapper.selectListByPageWithMessageUserDto(pageParams, dto, messageIds);
|
IPage<Message> page = baseMapper.selectListByPageWithMessageUserDto(pageParams, dto, messageIds);
|
||||||
List<MessageUserVo> voList = page.getRecords().stream().map(messageVo -> {
|
List<MessageUserVo> voList = page.getRecords().stream().map(messageVo -> {
|
||||||
|
@ -111,6 +124,7 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
|
||||||
vo.setCover(cover);
|
vo.setCover(cover);
|
||||||
return vo;
|
return vo;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
return PageResult.<MessageUserVo>builder()
|
return PageResult.<MessageUserVo>builder()
|
||||||
.list(voList)
|
.list(voList)
|
||||||
.pageNo(page.getCurrent())
|
.pageNo(page.getCurrent())
|
||||||
|
@ -121,15 +135,67 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据消息id查询消息详情
|
* 根据消息id查询消息详情
|
||||||
|
* 请求消息内容后标为已读
|
||||||
*
|
*
|
||||||
* @param id 消息id
|
* @param id 消息id
|
||||||
* @return 消息详情
|
* @return 消息详情
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MessageVo getMessageDetailById(Long id) {
|
public MessageVo getMessageDetailById(Long id) {
|
||||||
|
// 将消息设为已读
|
||||||
|
Message message = new Message();
|
||||||
|
message.setId(id);
|
||||||
|
message.setStatus(true);
|
||||||
|
updateById(message);
|
||||||
|
|
||||||
|
// 返回详情内容给前端
|
||||||
return baseMapper.selectMessageVoById(id);
|
return baseMapper.selectMessageVoById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户将消息标为已读
|
||||||
|
* 将消息表中满足id条件全部标为已读
|
||||||
|
*
|
||||||
|
* @param ids 消息id列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateUserMarkAsRead(List<Long> ids) {
|
||||||
|
// 判断ids是否为空
|
||||||
|
if (ids.isEmpty()) {
|
||||||
|
throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新表中消息状态
|
||||||
|
List<Message> messageList = ids.stream().map(id -> {
|
||||||
|
Message message = new Message();
|
||||||
|
message.setId(id);
|
||||||
|
message.setStatus(true);
|
||||||
|
return message;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
updateBatchById(messageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户删除消息
|
||||||
|
*
|
||||||
|
* @param ids 消息Id列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteUserMessageByIds(List<Long> ids) {
|
||||||
|
// 判断ids是否为空
|
||||||
|
if (ids.isEmpty()) {
|
||||||
|
throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除消息表中数据
|
||||||
|
baseMapper.deleteBatchIdsWithPhysics(ids);
|
||||||
|
|
||||||
|
// 根据当前用户id删除消息接受表中数据
|
||||||
|
Long userId = BaseContext.getUserId();
|
||||||
|
messageReceivedMapper.deleteBatchIdsByMessageIdsAndUserIdWithPhysics(ids, userId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加系统消息
|
* 添加系统消息
|
||||||
* 判断发送消息的接收人是否为空,如果为空默认是所有用户都是接受者
|
* 判断发送消息的接收人是否为空,如果为空默认是所有用户都是接受者
|
||||||
|
|
|
@ -6,6 +6,7 @@ import cn.bunny.dao.entity.system.RouterRole;
|
||||||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
import cn.bunny.services.mapper.RouterRoleMapper;
|
import cn.bunny.services.mapper.RouterRoleMapper;
|
||||||
import cn.bunny.services.service.RouterRoleService;
|
import cn.bunny.services.service.RouterRoleService;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -79,4 +80,42 @@ public class RouterRoleServiceImpl extends ServiceImpl<RouterRoleMapper, RouterR
|
||||||
}
|
}
|
||||||
baseMapper.deleteBatchIdsByRouterIdsWithPhysics(routerIds);
|
baseMapper.deleteBatchIdsByRouterIdsWithPhysics(routerIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量为菜单添加角色
|
||||||
|
* 查询所有满足角色id列表的路由
|
||||||
|
* 将满足条件的路由提取出routerId列表
|
||||||
|
* 并删除所有routerIds
|
||||||
|
*
|
||||||
|
* @param dto 路由分配角色
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void assignAddBatchRolesToRouter(AssignRolesToRoutersDto dto) {
|
||||||
|
// 查询所有满足角色id和路由Id相关
|
||||||
|
LambdaQueryWrapper<RouterRole> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.in(RouterRole::getRoleId, dto.getRoleIds())
|
||||||
|
.and(qw -> qw.in(RouterRole::getRouterId, dto.getRouterIds()));
|
||||||
|
List<RouterRole> routerRoleList = list(wrapper);
|
||||||
|
|
||||||
|
// 根据Id列表物理删除路由角色关系表
|
||||||
|
List<Long> ids = routerRoleList.stream().map(RouterRole::getId).toList();
|
||||||
|
if (!ids.isEmpty()) {
|
||||||
|
baseMapper.deleteBatchIdsWithPhysics(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存分配好的角色信息
|
||||||
|
List<RouterRole> roleList = new ArrayList<>();
|
||||||
|
for (Long roleId : dto.getRoleIds()) {
|
||||||
|
List<RouterRole> list = dto.getRouterIds().stream().map(routerId -> {
|
||||||
|
RouterRole routerRole = new RouterRole();
|
||||||
|
routerRole.setRouterId(routerId);
|
||||||
|
routerRole.setRoleId(roleId);
|
||||||
|
return routerRole;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
roleList.addAll(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveBatch(roleList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,20 +74,28 @@
|
||||||
<!-- 根据消息所有包含匹配当前消息Id的列表 -->
|
<!-- 根据消息所有包含匹配当前消息Id的列表 -->
|
||||||
<select id="selectListByPageWithMessageUserDto" resultType="cn.bunny.dao.entity.system.Message">
|
<select id="selectListByPageWithMessageUserDto" resultType="cn.bunny.dao.entity.system.Message">
|
||||||
select
|
select
|
||||||
<include refid="Base_Column_List"/>
|
message.*,
|
||||||
from sys_message
|
create_user.username as create_username,
|
||||||
|
update_user.username as update_username
|
||||||
|
from sys_message message
|
||||||
|
left join sys_user create_user on create_user.id = message.create_user
|
||||||
|
left join sys_user update_user on update_user.id = message.update_user
|
||||||
<where>
|
<where>
|
||||||
<if test="messageIds != null">
|
message.is_deleted = 0
|
||||||
id in
|
<if test="messageIds != null ">
|
||||||
|
and message.id in
|
||||||
<foreach collection="messageIds" item="id" open="(" close=")" separator=",">
|
<foreach collection="messageIds" item="id" open="(" close=")" separator=",">
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
<if test="dto.status != null">
|
<if test="dto.status != null">
|
||||||
and status = #{dto.status}
|
and message.status = #{dto.status}
|
||||||
</if>
|
</if>
|
||||||
<if test="dto.messageType != null and dto.messageType != ''">
|
<if test="dto.messageType != null and dto.messageType != ''">
|
||||||
and message_type like CONCAT('%',#{dto.messageType},'%')
|
and message.message_type = #{dto.messageType}
|
||||||
|
</if>
|
||||||
|
<if test="dto.title != null and dto.title != ''">
|
||||||
|
and message.title like CONCAT('%',#{dto.title},'%')
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
@ -100,13 +108,14 @@
|
||||||
LEFT JOIN sys_user update_user ON update_user.id = message.update_user
|
LEFT JOIN sys_user update_user ON update_user.id = message.update_user
|
||||||
LEFT JOIN sys_user send_user ON send_user.id = message.send_user_id
|
LEFT JOIN sys_user send_user ON send_user.id = message.send_user_id
|
||||||
WHERE message.id = #{id}
|
WHERE message.id = #{id}
|
||||||
|
and message.is_deleted = 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 物理删除系统消息 -->
|
<!-- 物理删除系统消息 -->
|
||||||
<delete id="deleteBatchIdsWithPhysics">
|
<delete id="deleteBatchIdsWithPhysics">
|
||||||
delete
|
delete
|
||||||
from sys_message
|
from sys_message
|
||||||
where id in
|
where is_deleted=0 and id in
|
||||||
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
|
|
|
@ -34,6 +34,16 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<!-- 根据当前用户id删除消息接受表中数据 -->
|
||||||
|
<delete id="deleteBatchIdsByMessageIdsAndUserIdWithPhysics">
|
||||||
|
delete
|
||||||
|
from sys_message_received where
|
||||||
|
received_user_id = #{userId} and received_user_id in
|
||||||
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
<!-- 根据发送者id批量删除消息接受者 -->
|
<!-- 根据发送者id批量删除消息接受者 -->
|
||||||
<select id="selectUserinfoListByMessageId"
|
<select id="selectUserinfoListByMessageId"
|
||||||
resultType="cn.bunny.dao.vo.system.message.MessageReceivedWithUserVo">
|
resultType="cn.bunny.dao.vo.system.message.MessageReceivedWithUserVo">
|
||||||
|
|
|
@ -39,6 +39,16 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<!-- 根据Id列表物理删除路由角色关系表 -->
|
||||||
|
<delete id="deleteBatchIdsWithPhysics">
|
||||||
|
delete
|
||||||
|
from sys_router_role
|
||||||
|
where id in
|
||||||
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
<!-- 查看所有路由的角色 -->
|
<!-- 查看所有路由的角色 -->
|
||||||
<select id="viewRouterRolesWithAll" resultType="cn.bunny.dao.view.ViewRouterRole">
|
<select id="viewRouterRolesWithAll" resultType="cn.bunny.dao.view.ViewRouterRole">
|
||||||
SELECT rr.router_id,
|
SELECT rr.router_id,
|
||||||
|
|
Loading…
Reference in New Issue