Skip to content

Commit

Permalink
Merge pull request #25 from Bull-BCLS/dev
Browse files Browse the repository at this point in the history
feat: 新增系统管理/消息管理(列表、查看详情、标记已读、全部已读、删除)
  • Loading branch information
Charles7c authored Oct 30, 2023
2 parents 4d70bc8 + 9217166 commit 4cf9ef6
Show file tree
Hide file tree
Showing 30 changed files with 1,633 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,26 @@ public List<V> list(Q query, SortQuery sortQuery) {
protected <E> List<E> list(Q query, SortQuery sortQuery, Class<E> targetClass) {
QueryWrapper<T> queryWrapper = QueryHelper.build(query);
// 设置排序
this.sort(queryWrapper, sortQuery);
List<T> entityList = baseMapper.selectList(queryWrapper);
return BeanUtil.copyToList(entityList, targetClass);
}

/**
* 设置排序
*
* @param queryWrapper
* 查询 Wrapper
* @param sortQuery
* 排序查询条件
*/
protected void sort(QueryWrapper<T> queryWrapper, SortQuery sortQuery) {
Sort sort = Opt.ofNullable(sortQuery).orElseGet(SortQuery::new).getSort();
for (Sort.Order order : sort) {
if (null != order) {
queryWrapper.orderBy(true, order.isAscending(), StrUtil.toUnderlineCase(order.getProperty()));
}
}
List<T> entityList = baseMapper.selectList(queryWrapper);
return BeanUtil.copyToList(entityList, targetClass);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public class SysConsts {
* VO 描述类字段后缀
*/
public static final String VO_DESCRIPTION_FIELD_SUFFIX = "String";

/**
* 系统消息类型
*/
public static final String SYSTEM_MESSAGE_TYPE = "1";
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.ReUtil;
Expand All @@ -38,6 +39,7 @@
import top.charles7c.cnadmin.auth.service.LoginService;
import top.charles7c.cnadmin.auth.service.PermissionService;
import top.charles7c.cnadmin.common.annotation.TreeField;
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;
import top.charles7c.cnadmin.common.constant.RegexConsts;
import top.charles7c.cnadmin.common.constant.SysConsts;
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
Expand All @@ -48,9 +50,11 @@
import top.charles7c.cnadmin.common.util.TreeUtils;
import top.charles7c.cnadmin.common.util.helper.LoginHelper;
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
import top.charles7c.cnadmin.system.enums.MessageTemplateEnum;
import top.charles7c.cnadmin.system.model.entity.RoleDO;
import top.charles7c.cnadmin.system.model.entity.UserDO;
import top.charles7c.cnadmin.system.model.entity.UserSocialDO;
import top.charles7c.cnadmin.system.model.request.MessageRequest;
import top.charles7c.cnadmin.system.model.vo.DeptDetailVO;
import top.charles7c.cnadmin.system.model.vo.MenuVO;
import top.charles7c.cnadmin.system.service.*;
Expand All @@ -74,6 +78,8 @@ public class LoginServiceImpl implements LoginService {
private final PermissionService permissionService;
private final UserRoleService userRoleService;
private final UserSocialService userSocialService;
private final MessageService messageService;
private final ProjectProperties projectProperties;

@Override
public String accountLogin(String username, String password) {
Expand Down Expand Up @@ -131,6 +137,7 @@ public String socialLogin(AuthUser authUser) {
userSocial.setUserId(userId);
userSocial.setSource(source);
userSocial.setOpenId(openId);
this.sendMsg(user);
} else {
user = BeanUtil.toBean(userService.get(userSocial.getUserId()), UserDO.class);
}
Expand Down Expand Up @@ -180,7 +187,7 @@ public List<RouteVO> buildRouteTree(Long userId) {

/**
* 登录并缓存用户信息
*
*
* @param user
* 用户信息
* @return 令牌
Expand All @@ -205,4 +212,22 @@ private void checkUserStatus(UserDO user) {
DeptDetailVO deptDetailVO = deptService.get(user.getDeptId());
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, deptDetailVO.getStatus(), "此账号所属部门已被禁用,如有疑问,请联系管理员");
}

/**
* 发送消息
*
* @param user
* 用户信息
*/
private void sendMsg(UserDO user) {
MessageRequest request = new MessageRequest();
MessageTemplateEnum socialRegister = MessageTemplateEnum.SOCIAL_REGISTER;
request.setTitle(socialRegister.getTitle());
Map<String, Object> contentMap = MapUtil.newHashMap(2);
contentMap.put("nickname", user.getNickname());
contentMap.put("projectName", projectProperties.getName());
request.setContent(socialRegister.getContent(), contentMap);
request.setType(SysConsts.SYSTEM_MESSAGE_TYPE);
messageService.add(request, CollUtil.toList(user.getId()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package top.charles7c.cnadmin.system.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
* 消息模板枚举
*
* @author BULL_BCLS
* @since 2023/10/15 19:51
*/
@Getter
@RequiredArgsConstructor
public enum MessageTemplateEnum {

/**
* 第三方登录
*/
SOCIAL_REGISTER("欢迎注册 {projectName}", "尊敬的 {nickname},欢迎注册使用,请及时配置您的密码。");

private final String title;
private final String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package top.charles7c.cnadmin.system.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;

import top.charles7c.cnadmin.common.base.BaseMapper;
import top.charles7c.cnadmin.system.model.entity.MessageDO;
import top.charles7c.cnadmin.system.model.vo.MessageVO;

/**
* 消息 Mapper
*
* @author BULL_BCLS
* @since 2023/10/15 19:05
*/
public interface MessageMapper extends BaseMapper<MessageDO> {
/**
* 分页查询列表
*
* @param queryWrapper
* 查询条件
* @param page
* 分页查询条件
* @return 分页信息
*/
IPage<MessageVO> selectVoPage(@Param("page") IPage<Object> page,
@Param(Constants.WRAPPER) QueryWrapper<MessageDO> queryWrapper);

/**
* 查询列表
*
* @param queryWrapper
* 查询条件
* @return 列表信息
*/
List<MessageVO> selectVoList(@Param(Constants.WRAPPER) QueryWrapper<MessageDO> queryWrapper);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package top.charles7c.cnadmin.system.mapper;

import top.charles7c.cnadmin.common.base.BaseMapper;
import top.charles7c.cnadmin.system.model.entity.MessageUserDO;

/**
* 消息和用户关联 Mapper
*
* @author BULL_BCLS
* @since 2023/10/15 20:25
*/
public interface MessageUserMapper extends BaseMapper<MessageUserDO> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package top.charles7c.cnadmin.system.model.entity;

import lombok.Data;

import com.baomidou.mybatisplus.annotation.TableName;

import top.charles7c.cnadmin.common.base.BaseDO;

/**
* 消息实体
*
* @author BULL_BCLS
* @since 2023/10/15 19:05
*/
@Data
@TableName("sys_message")
public class MessageDO extends BaseDO {

private static final long serialVersionUID = 1L;

/**
* 消息ID
*/
private Long id;

/**
* 主题
*/
private String title;

/**
* 内容
*/
private String content;

/**
* 类型(取值于字典 message_type)
*/
private String type;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package top.charles7c.cnadmin.system.model.entity;

import java.time.LocalDateTime;

import lombok.Data;

import com.baomidou.mybatisplus.annotation.TableName;

import top.charles7c.cnadmin.common.base.BaseDO;

/**
* 消息和用户关联实体
*
* @author BULL_BCLS
* @since 2023/10/15 20:25
*/
@Data
@TableName("sys_message_user")
public class MessageUserDO extends BaseDO {

private static final long serialVersionUID = 1L;

/**
* 消息ID
*/
private Long messageId;

/**
* 用户ID
*/
private Long userId;

/**
* 读取状态 (0未读 1已读)
*/
private Boolean readStatus;

/**
* 读取时间
*/
private LocalDateTime readTime;
}
Loading

0 comments on commit 4cf9ef6

Please sign in to comment.