1、右上角新增消息中心提示

2、消息中心新增连接点击打开对应的详情页面
3、页面样式调整,关联附件新增前端分页
This commit is contained in:
pan 2024-09-06 19:59:46 +08:00
parent f90c8e0c6f
commit 7131d744a4
11 changed files with 145 additions and 9 deletions

View File

@ -2,6 +2,9 @@ package com.rzdata.web.controller.system;
import java.util.List;
import java.util.Set;
import com.rzdata.web.domain.TzMessage;
import com.rzdata.web.service.ITzMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -34,6 +37,10 @@ public class SysLoginController
@Autowired
private SysPermissionService permissionService;
/** 消息中心 **/
@Autowired
private ITzMessageService tzMessageService;
/**
* 登录方法
*
@ -64,9 +71,14 @@ public class SysLoginController
Set<String> roles = permissionService.getRolePermission(user);
// 权限集合
Set<String> permissions = permissionService.getMenuPermission(user);
/** 未读消息 **/
int unMsgNumber = tzMessageService.selectTzMessageByUserCount(String.valueOf(user.getUserId()));
AjaxResult ajax = AjaxResult.success();
ajax.put("user", user);
ajax.put("roles", roles);
ajax.put("unMsgNumber", unMsgNumber);
ajax.put("permissions", permissions);
return ajax;
}

View File

@ -108,4 +108,14 @@ public class TzMessageController extends BaseController
{
return toAjax(tzMessageService.allMarkedRead(tzMessage));
}
/**
* 获取用户统计
*/
@GetMapping(value = "/user/msg/count/{id}")
public AjaxResult getUserMessageCount(@PathVariable("id") String id)
{
return success(tzMessageService.selectTzMessageByUserCount(id));
}
}

View File

@ -30,6 +30,12 @@ public class TzMessage extends BaseEntity
@Excel(name = "消息推送内容")
private String content;
/** 业务id */
private String businessId;
/** 业务类型;doc:文档tool:工具) */
private String businessType;
/** 逻辑删除标记:1删除;0未删除 */
@Excel(name = "逻辑删除标记:1删除;0未删除")
private String deleted;

View File

@ -74,4 +74,9 @@ public interface TzMessageMapper
* @return
*/
public int batchInsert(@Param("tzMessageList") List<TzMessage> tzMessageList);
/**
* 消息中心未读消息数量查询
* **/
int selectTzMessageByUserCount(String userId);
}

View File

@ -64,4 +64,11 @@ public interface ITzMessageService
int allMarkedRead(TzMessage tzMessage);
public int batchInsert(List<TzMessage> tzMessageList);
/**
* 未读消息数量
* @param userId
* @return
*/
int selectTzMessageByUserCount(String userId);
}

View File

@ -7,19 +7,25 @@ import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.rzdata.common.annotation.DataScope;
import com.rzdata.common.constant.Constants;
import com.rzdata.common.core.domain.entity.SysDictData;
import com.rzdata.common.core.domain.entity.SysUser;
import com.rzdata.common.exception.ServiceException;
import com.rzdata.common.utils.DateUtils;
import com.rzdata.common.utils.SecurityUtils;
import com.rzdata.system.service.ISysDeptService;
import com.rzdata.system.service.ISysDictTypeService;
import com.rzdata.system.service.ISysUserService;
import com.rzdata.web.domain.Attachment;
import com.rzdata.web.domain.Document;
import com.rzdata.web.domain.Tool;
import com.rzdata.web.domain.TzMessage;
import com.rzdata.web.mapper.DocumentMapper;
import com.rzdata.web.service.IDocumentService;
import com.rzdata.web.service.IToolApplyService;
import com.rzdata.web.service.ITzMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -34,6 +40,7 @@ import java.util.stream.Collectors;
* @author ja
* @date 2024-07-09
*/
@Slf4j
@Service
public class DocumentServiceImpl implements IDocumentService
{
@ -57,6 +64,13 @@ public class DocumentServiceImpl implements IDocumentService
@Autowired
private Snowflake snowflake;
@Autowired
private ISysUserService iSysUserService;
@Autowired
private ITzMessageService tzMessageService;
/**
* 查询请填写功能名称
*
@ -71,6 +85,7 @@ public class DocumentServiceImpl implements IDocumentService
Tool tool = toolService.selectToolByToolId(document.getToolId());
document.setToolName(tool.getToolName());
}
document.setDocRespDeptName(sysDeptService.getDeptName(document.getDocRespDept()));
Attachment attachment = new Attachment();
attachment.setBusinessId(document.getDocId());
attachment.setDel(Constants.STR_ZERO);
@ -88,6 +103,7 @@ public class DocumentServiceImpl implements IDocumentService
* @return 请填写功能名称
*/
@Override
@DataScope(deptAlias = "sd")
public List<Document> selectDocumentList(Document document)
{
if (BooleanUtil.isTrue(document.getPermissionCheck())) {
@ -265,13 +281,68 @@ public class DocumentServiceImpl implements IDocumentService
*/
@Override
public int pushDoc(String[] ids) {
List<String> docIdList = Arrays.asList(ids);
if(CollUtil.isEmpty(docIdList)){
throw new ServiceException("请选择需发布的文档");
}
Document doc = new Document();
doc.setIds(Arrays.asList(ids));
doc.setIds(docIdList);
doc.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
doc.setUpdateById(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
doc.setDocStatus(Constants.DOC_STATUS_YFB);
doc.setUpdateTime(new Date());
return documentMapper.updatePushDoc(doc);
int result = documentMapper.updatePushDoc(doc);
//发送消息
Document document = new Document();
document.setDocIdList(docIdList);
List<Document> documents = documentMapper.selectDocumentList(document);
SysUser sysUser = new SysUser();
sysUser.setStatus("0");
sysUser.setDelFlag("0");
List<SysUser> sysUsers = iSysUserService.selectUserList(sysUser);
for (Document docItem : documents) {
sendTzMessage(docItem, sysUsers);
}
return result;
}
/**
* 给消息中心发送消息
*/
public void sendTzMessage(Document doc, List<SysUser> sysUsers) {
try{
String content = doc.getDocName() + "已发布";
List<TzMessage> addList = new ArrayList<>();
for (SysUser user : sysUsers) {
TzMessage tzMessage = new TzMessage();
//雪花
tzMessage.setId(String.valueOf(snowflake.nextId()));
tzMessage.setBusinessId(doc.getDocId());
tzMessage.setBusinessType(Constants.DOC_TYPE_DOC);
tzMessage.setReceiverId(String.valueOf(user.getUserId()));
tzMessage.setStates(1);
tzMessage.setContent(content);
tzMessage.setDeleted("0");
tzMessage.setCreateTime(DateUtils.getNowDate());
tzMessage.setCreateBy(SecurityUtils.getLoginUser().getUsername());
tzMessage.setCreateById(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
addList.add(tzMessage);
}
// 使用AtomicInteger来跟踪索引
AtomicInteger counter = new AtomicInteger(0);
// 使用Stream API进行分组
Map<Integer, List<TzMessage>> grouped = addList.stream()
.collect(Collectors.groupingBy(
e -> counter.getAndIncrement() / 500
));
// 对每个子列表进行批量插入
grouped.values().forEach(batch -> tzMessageService.batchInsert(batch));
}catch (Exception e){
log.error("UseApplyServiceImpl-->sendTzMessage--发送消息中心异常--e###", e);
}
}
/**

View File

@ -146,6 +146,8 @@ public class ToolApplyServiceImpl implements IToolApplyService
TzMessage tzMessage = new TzMessage();
//雪花
tzMessage.setId(String.valueOf(snowflake.nextId()));
tzMessage.setBusinessId(toolApply.getToolId());
tzMessage.setBusinessType(Constants.ATT_TYPE_TOOL);
tzMessage.setReceiverId(String.valueOf(sysUser.getUserId()));
tzMessage.setStates(1);
tzMessage.setContent(content);

View File

@ -256,6 +256,8 @@ public class ToolServiceImpl implements IToolService
TzMessage tzMessage = new TzMessage();
//雪花
tzMessage.setId(String.valueOf(snowflake.nextId()));
tzMessage.setBusinessId(tTool.getToolId());
tzMessage.setBusinessType(Constants.ATT_TYPE_TOOL);
tzMessage.setReceiverId(String.valueOf(user.getUserId()));
tzMessage.setStates(1);
tzMessage.setContent(content);

View File

@ -121,4 +121,9 @@ public class TzMessageServiceImpl implements ITzMessageService
public int batchInsert(List<TzMessage> tzMessageList) {
return tzMessageMapper.batchInsert(tzMessageList);
}
@Override
public int selectTzMessageByUserCount(String userId) {
return tzMessageMapper.selectTzMessageByUserCount(userId);
}
}

View File

@ -36,10 +36,10 @@
</sql>
<select id="selectDocumentList" parameterType="Document" resultMap="DocumentResult">
select td.*, t_tool.tool_name as tool_name,sys_dept.dept_name as doc_resp_dept_name
select td.*, t_tool.tool_name as tool_name,sd.dept_name as doc_resp_dept_name
from t_document td
left join t_tool on t_tool.tool_id = td.tool_id
left join sys_dept on sys_dept.dept_id = td.doc_resp_dept
left join sys_dept sd on sd.dept_id = td.doc_resp_dept
<where>
<if test="docCode != null and docCode != ''"> and td.doc_code like concat('%', #{docCode}, '%')</if>
<if test="docName != null and docName != ''"> and td.doc_name like concat('%', #{docName}, '%')</if>
@ -68,6 +68,7 @@
and td.is_deleted = '0'
</where>
${params.dataScope}
order by td.create_time desc
</select>

View File

@ -7,6 +7,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="TzMessage" id="TzMessageResult">
<result property="id" column="id" />
<result property="receiverId" column="receiver_id" />
<result property="businessId" column="business_id" />
<result property="businessType" column="business_type" />
<result property="states" column="states" />
<result property="content" column="content" />
<result property="deleted" column="deleted" />
@ -20,7 +22,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectTzMessageVo">
select id, receiver_id, states, content, deleted, create_by, create_time, update_by, update_time, remark,create_by_id,update_by_id from tz_message
select id, business_id, business_type, receiver_id, states, content, deleted, create_by,
create_time, update_by, update_time,
remark,create_by_id,update_by_id from tz_message
</sql>
<select id="selectTzMessageList" parameterType="TzMessage" resultMap="TzMessageResult">
@ -30,6 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="states != null "> and states = #{states}</if>
<if test="content != null and content != ''"> and content like concat('%', #{content}, '%')</if>
<if test="createById != null and deleted != ''"> and create_by_id = #{createById}</if>
<if test="businessType != null and businessType != ''"> and business_type = #{businessType}</if>
and deleted = '0'
</where>
</select>
@ -44,6 +49,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="receiverId != null">receiver_id,</if>
<if test="businessId != null">business_id,</if>
<if test="businessType != null">business_type,</if>
<if test="states != null">states,</if>
<if test="content != null and content != ''">content,</if>
<if test="deleted != null and deleted != ''">deleted,</if>
@ -58,6 +65,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="receiverId != null">#{receiverId},</if>
<if test="businessId != null">#{businessId},</if>
<if test="businessType != null">#{businessType},</if>
<if test="states != null">#{states},</if>
<if test="content != null and content != ''">#{content},</if>
<if test="deleted != null and deleted != ''">#{deleted},</if>
@ -66,8 +75,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
<if test="createById != null">#{create_by_id},</if>
<if test="updateById != null">#{update_by_id},</if>
<if test="createById != null">#{createById},</if>
<if test="updateById != null">#{updateById},</if>
</trim>
</insert>
@ -75,6 +84,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update tz_message
<trim prefix="SET" suffixOverrides=",">
<if test="receiverId != null">receiver_id = #{receiverId},</if>
<if test="businessId != null">business_id = #{businessId},</if>
<if test="businessType != null">business_type = #{businessType},</if>
<if test="states != null">states = #{states},</if>
<if test="content != null and content != ''">content = #{content},</if>
<if test="deleted != null and deleted != ''">deleted = #{deleted},</if>
@ -106,10 +117,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 批量插入 -->
<insert id="batchInsert" parameterType="java.util.List">
insert into tz_message (id, receiver_id, states, content, deleted, create_by, create_by_id, create_time)
insert into tz_message (id, business_id, business_type, receiver_id, states, content, deleted, create_by, create_by_id, create_time)
values
<foreach item="item" index="index" collection="tzMessageList" open="(" separator="),(" close=")">
#{item.id}, #{item.receiverId}, #{item.states}, #{item.content}, #{item.deleted}, #{item.createBy},#{item.createById}, #{item.createTime}
#{item.id}, #{item.businessId}, #{item.businessType}, #{item.receiverId}, #{item.states}, #{item.content}, #{item.deleted}, #{item.createBy},#{item.createById}, #{item.createTime}
</foreach>
</insert>
<select id="selectTzMessageByUserCount" resultType="java.lang.Integer">
select count(1) from tz_message where receiver_id = #{userId} and states = '1' and deleted = '0'
</select>
</mapper>