0
点赞
收藏
分享

微信扫一扫

基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(五)


 更多ruoyi-nbcio功能请看演示系统

演示地址:RuoYi-Nbcio后台管理系统

1、下面提供给前端待办提醒消息的接口SysNoticeController,增加如下:

/**
	 * 补充用户数据,并返回系统消息
	 * @return
	 */
    @Log(title = "系统消息")
    @GetMapping("/listByUser")
    public R<Map<String, Object>> listByUser(@RequestParam(required = false, defaultValue = "5") Integer pageSize) {
    	LoginUser loginUser = commonService.getLoginUser();
		Long userId = loginUser.getUserId();
		// 1.将系统消息补充到用户通告阅读标记表中
		LambdaQueryWrapper<SysNotice> querySaWrapper = new LambdaQueryWrapper<SysNotice>();
		querySaWrapper.eq(SysNotice::getMsgType,Constants.MSG_TYPE_ALL); // 全部人员
		querySaWrapper.eq(SysNotice::getStatus,Constants.CLOSE_FLAG_0.toString());  // 未关闭
		querySaWrapper.eq(SysNotice::getSendStatus, Constants.HAS_SEND); //已发布
		//querySaWrapper.ge(SysNotice::getEndTime, loginUser.getCreateTime()); //新注册用户不看结束通知
		querySaWrapper.notInSql(SysNotice::getNoticeId,"select notice_id from sys_notice_send where user_id='"+userId+"'");
		List<SysNotice> notices = noticeService.list(querySaWrapper);
		if(notices.size()>0) {
			for(int i=0;i<notices.size();i++) {	
				//因为websocket没有判断是否存在这个用户,要是判断会出现问题,故在此判断逻辑
				LambdaQueryWrapper<SysNoticeSend> query = new LambdaQueryWrapper<>();
				query.eq(SysNoticeSend::getNoticeId,notices.get(i).getNoticeId());
				query.eq(SysNoticeSend::getUserId,userId);
				SysNoticeSend one = noticeSendService.getOne(query);
				if(null==one){
					SysNoticeSend noticeSend = new SysNoticeSend();
					noticeSend.setNoticeId(notices.get(i).getNoticeId());
					noticeSend.setUserId(userId);
					noticeSend.setReadFlag(Constants.NO_READ_FLAG);
					noticeSendService.save(noticeSend);
				}
			}
		}
		// 2.查询用户未读的系统消息
		Page<SysNotice> anntMsgList = new Page<SysNotice>(0, pageSize);
		anntMsgList = noticeService.querySysNoticePageByUserId(anntMsgList,userId,"1");//通知公告消息
		Page<SysNotice> sysMsgList = new Page<SysNotice>(0, pageSize);
		sysMsgList = noticeService.querySysNoticePageByUserId(sysMsgList,userId,"2");//系统消息
		Page<SysNotice> todealMsgList = new Page<SysNotice>(0, pageSize);
		todealMsgList = noticeService.querySysNoticePageByUserId(todealMsgList,userId,"3");//待办消息
		Map<String,Object> sysMsgMap = new HashMap<String, Object>();
		sysMsgMap.put("sysMsgList", sysMsgList.getRecords());
		sysMsgMap.put("sysMsgTotal", sysMsgList.getTotal());
		sysMsgMap.put("anntMsgList", anntMsgList.getRecords());
		sysMsgMap.put("anntMsgTotal", anntMsgList.getTotal());
		sysMsgMap.put("todealMsgList", todealMsgList.getRecords());
		sysMsgMap.put("todealMsgTotal", todealMsgList.getTotal());
		return R.ok(sysMsgMap);
    }

2、其中这里用到了querySysNoticePageByUserId方法

@Override
	public Page<SysNotice> querySysNoticePageByUserId(Page<SysNotice> page, Long userId, String msgCategory) {
		if (page.getSize() == -1) {
			return page.setRecords(baseMapper.querySysNoticeListByUserId(null, userId.toString(), msgCategory));
		} else {
			return page.setRecords(baseMapper.querySysNoticeListByUserId(page, userId.toString(), msgCategory));
		}
	}

3、上面又用到了sql 在SysNoticeMapper.xml里

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.SysNoticeMapper">

    <resultMap type="com.ruoyi.system.domain.SysNotice" id="SysNoticeResult">
        <result property="noticeId" column="notice_id"/>
        <result property="noticeTitle" column="notice_title"/>
        <result property="noticeType" column="notice_type"/>
        <result property="noticeContent" column="notice_content"/>
        <result property="status" column="status"/>
        <result property="sender" column="sender"/>
        <result property="priority" column="priority"/>
        <result property="msgType" column="msg_type"/>
        <result property="sendStatus" column="send_status"/>
        <result property="sendTime" column="send_time"/>
        <result property="cancelTime" column="cancel_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>
    
    <select id="querySysNoticeListByUserId" parameterType="String"  resultMap="SysNoticeResult">
	   select * from sys_notice
	   where send_status = '1' 
	   and status = '0' 
	   and notice_type = #{msgCategory} 
	   and notice_id IN ( select notice_id from sys_notice_send where user_id = CAST(#{userId} AS SIGNED INTEGER) and read_flag = '0')
	   order by create_time DESC
	</select>

</mapper>

至此,后端的代码基本上就这些了,下一节开始讲一下前端。

举报

相关推荐

0 条评论