调整Reader获取数据的逻辑

This commit is contained in:
巴拉迪维 2021-09-09 10:20:55 +08:00
parent bc76220bc5
commit 837a2f7aba
8 changed files with 272 additions and 189 deletions

2
.gitignore vendored
View File

@ -90,3 +90,5 @@ target/
.env
/docker-data/
/logs/

View File

@ -1,6 +1,7 @@
package cn.org.gitlink.notification.model.dao.entity.vo;
import cn.org.gitlink.notification.model.dao.entity.SysNotification;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
@ -20,41 +21,24 @@ public class ReceiverNotificationListVo {
@JsonProperty("unread_atme")
private Integer unreadAtMeCount;
@JsonProperty("notification_list")
private List<SysNotification> notificationList;
@JsonProperty("records")
private List<SysNotification> records;
@JsonProperty("atme_list")
private List<SysNotification> atMeList;
@JsonProperty("records_count")
private long recordsCount;
@JsonProperty("page_num")
private long pageNum;
@JsonProperty("total_page_count")
private long totalPageCount;
@JsonProperty("page_size")
private long pageSize;
public ReceiverNotificationListVo() {
}
public ReceiverNotificationListVo(Integer receiver, Integer type, Integer totalUnreadNotifiationCount, Integer unreadNotificationCount, Integer unreadAtMeCount, List<SysNotification> notificationList, List<SysNotification> atMeList) {
this.receiver = receiver;
this.type = type;
this.totalUnreadNotifiationCount = totalUnreadNotifiationCount;
this.unreadNotificationCount = unreadNotificationCount;
this.unreadAtMeCount = unreadAtMeCount;
this.notificationList = notificationList;
this.atMeList = atMeList;
}
public Integer getTotalUnreadNotifiationCount() {
return totalUnreadNotifiationCount;
}
public void setTotalUnreadNotifiationCount(Integer totalUnreadNotifiationCount) {
this.totalUnreadNotifiationCount = totalUnreadNotifiationCount;
}
public List<SysNotification> getAtMeList() {
return atMeList;
}
public void setAtMeList(List<SysNotification> atMeList) {
this.atMeList = atMeList;
}
public Integer getReceiver() {
return receiver;
}
@ -71,6 +55,14 @@ public class ReceiverNotificationListVo {
this.type = type;
}
public Integer getTotalUnreadNotifiationCount() {
return totalUnreadNotifiationCount;
}
public void setTotalUnreadNotifiationCount(Integer totalUnreadNotifiationCount) {
this.totalUnreadNotifiationCount = totalUnreadNotifiationCount;
}
public Integer getUnreadNotificationCount() {
return unreadNotificationCount;
}
@ -87,11 +79,43 @@ public class ReceiverNotificationListVo {
this.unreadAtMeCount = unreadAtMeCount;
}
public List<SysNotification> getNotificationList() {
return notificationList;
public List<SysNotification> getRecords() {
return records;
}
public void setNotificationList(List<SysNotification> notificationList) {
this.notificationList = notificationList;
public void setRecords(List<SysNotification> records) {
this.records = records;
}
public long getRecordsCount() {
return recordsCount;
}
public void setRecordsCount(long recordsCount) {
this.recordsCount = recordsCount;
}
public long getPageNum() {
return pageNum;
}
public void setPageNum(long pageNum) {
this.pageNum = pageNum;
}
public long getTotalPageCount() {
return totalPageCount;
}
public void setTotalPageCount(long totalPageCount) {
this.totalPageCount = totalPageCount;
}
public long getPageSize() {
return pageSize;
}
public void setPageSize(long pageSize) {
this.pageSize = pageSize;
}
}

View File

@ -34,6 +34,7 @@ public interface SysNotificationMapper extends BaseMapper<SysNotification> {
@Param("type") Integer type);
List<SysNotification> getSysNotificationPageList(Page page, String orderBy,
@Param("type") int type,
@Param("platform") String platform,
@Param("receiver") Integer receiver);

View File

@ -10,17 +10,17 @@ import java.util.List;
public interface SysNotificationService extends IService<SysNotification> {
//给用户发送消息
boolean sendNotification(NewSysNotificationVo sysNotification);
boolean sendNotification(NewSysNotificationVo sysNotification) throws Exception;
/**
* 设置系统消息状态为
*
* @param platform 平台编号
* @param platform 平台编号
* @param notificationIds 消息编号列表中英文逗号隔开eg221,2323,4,111,23123
* @param status 1 未读 2已读
* @param status 1 未读 2已读
* @return
*/
int markNotificationAs(String platform, String notificationIds, Integer status);
int markNotificationAs(String platform, String notificationIds, Integer status) throws Exception;
/**
* 获取所有未读消息总数
@ -29,38 +29,39 @@ public interface SysNotificationService extends IService<SysNotification> {
* @param receiver 信息接收者
* @return
*/
int getUnreadNotificationCount(String platform, Integer receiver);
int getUnreadNotificationCount(String platform, Integer receiver) throws Exception;
/**
* 获取所有未读消息
*
* @param platform 平台编号
* @param receiver 消息接收者
* @param size 页大小
* @param type 1 系统消息 2 @我
* @param size 页大小
* @param type 1 系统消息 2 @我
* @return
*/
List<SysNotification> getUnreadNotificationByType(String platform, Integer receiver, Integer size, Integer type);
List<SysNotification> getUnreadNotificationByType(String platform, Integer receiver, Integer size, Integer type) throws Exception;
/**
*按分类获取未读消息总数
* 按分类获取未读消息总数
*
* @param type 1 系统消息 2 @我
* @param type 1 系统消息 2 @我
* @param platform 平台编号
* @param receiver 消息接收者
* @return
*/
int getUnreadNotificationByType(Integer type, String platform, Integer receiver);
int getUnreadNotificationByType(Integer type, String platform, Integer receiver) throws Exception;
/**
* 获取所有系统消息
*
* @param page 页码
* @param size 页大小
* @param orderBy 排序
* @param type 类型 -1 全部 1 系统消息2 @我
* @param page 页码
* @param size 页大小
* @param orderBy 排序
* @param platform 平台编号
* @param receiver 消息接收者
* @return
*/
Page<SysNotification> getNotification(int page, int size, String orderBy, String platform, Integer receiver);
Page<SysNotification> getNotification(int type, int page, int size, String orderBy, String platform, Integer receiver) throws Exception;
}

View File

@ -17,7 +17,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
@Override
@Transactional
public boolean sendNotification(NewSysNotificationVo newSysNotificationVo) {
public boolean sendNotification(NewSysNotificationVo newSysNotificationVo) throws Exception {
SysNotification sysNotification = new SysNotification();
sysNotification.setSender(newSysNotificationVo.getSender());
sysNotification.setContent(newSysNotificationVo.getContent());
@ -32,33 +32,33 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
}
@Override
public int markNotificationAs(String platform, String notificationIds, Integer status) {
public int markNotificationAs(String platform, String notificationIds, Integer status) throws Exception {
return baseMapper.updateStatusByNotificationId(platform, notificationIds, status);
}
@Override
public int getUnreadNotificationCount(String platform, Integer receiver) {
public int getUnreadNotificationCount(String platform, Integer receiver) throws Exception {
return baseMapper.getNewSysNotificationNumber(platform, receiver);
}
@Override
public List<SysNotification> getUnreadNotificationByType(String platform, Integer receiver, Integer size, Integer type) {
public List<SysNotification> getUnreadNotificationByType(String platform, Integer receiver, Integer size, Integer type) throws Exception {
List<SysNotification> sysNotificationList = baseMapper.getUnreadSysNotificationsList(platform, receiver, 1, size, type);
return sysNotificationList;
}
@Override
public int getUnreadNotificationByType(Integer type, String platform, Integer receiver) {
public int getUnreadNotificationByType(Integer type, String platform, Integer receiver) throws Exception {
return baseMapper.getSysNotificationNumberByType(platform, receiver, type);
}
@Override
public Page<SysNotification> getNotification(int curPage, int pageSize, String orderBy, String platform, Integer receiver) {
Page page = new Page<SysNotification>(curPage, pageSize);
public Page<SysNotification> getNotification(int type, int page, int size, String orderBy, String platform, Integer receiver) throws Exception {
Page pageItem = new Page<SysNotification>(page, size);
List<SysNotification> sysNotificationList = baseMapper.getSysNotificationPageList(
page, orderBy, platform, receiver
pageItem, orderBy, type, platform, receiver
);
page.setRecords(sysNotificationList);
return page;
pageItem.setRecords(sysNotificationList);
return pageItem;
}
}

View File

@ -1,162 +1,167 @@
<?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="cn.org.gitlink.notification.model.dao.mapper.SysNotificationMapper" >
<resultMap id="BaseResultMap" type="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="sender" property="sender" jdbcType="INTEGER" />
<result column="receiver" property="receiver" jdbcType="INTEGER" />
<result column="content" property="content" jdbcType="VARCHAR" />
<result column="notification_url" property="notificationUrl" jdbcType="VARCHAR" />
<result column="created_at" property="createdAt" jdbcType="TIMESTAMP" />
<result column="status" property="status" jdbcType="TINYINT" />
<result column="type" property="type" jdbcType="TINYINT" />
<result column="is_delete" property="isDelete" jdbcType="BIT" />
<mapper namespace="cn.org.gitlink.notification.model.dao.mapper.SysNotificationMapper">
<resultMap id="BaseResultMap" type="cn.org.gitlink.notification.model.dao.entity.SysNotification">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="sender" property="sender" jdbcType="INTEGER"/>
<result column="receiver" property="receiver" jdbcType="INTEGER"/>
<result column="content" property="content" jdbcType="VARCHAR"/>
<result column="notification_url" property="notificationUrl" jdbcType="VARCHAR"/>
<result column="created_at" property="createdAt" jdbcType="TIMESTAMP"/>
<result column="status" property="status" jdbcType="TINYINT"/>
<result column="type" property="type" jdbcType="TINYINT"/>
<result column="is_delete" property="isDelete" jdbcType="BIT"/>
</resultMap>
<sql id="Base_Column_List" >
id, sender, receiver, content, notification_url, created_at, status, type, is_delete
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
<sql id="Base_Column_List">
id, sender, receiver, content, notification_url, created_at, status, type, is_delete
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from ${platform}_sys_notification
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from ${platform}_sys_notification
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
insert into ${platform}_sys_notification (id, sender, receiver,
content, notification_url,
status, type)
values (#{record.id,jdbcType=INTEGER}, #{record.sender,jdbcType=INTEGER}, #{record.receiver,jdbcType=INTEGER},
#{record.content,jdbcType=VARCHAR}, #{record.notificationUrl,jdbcType=VARCHAR},
#{record.status,jdbcType=TINYINT}, #{record.type,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from ${platform}_sys_notification
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification">
insert into ${platform}_sys_notification (id, sender, receiver,
content, notification_url,
status, type)
values (#{record.id,jdbcType=INTEGER}, #{record.sender,jdbcType=INTEGER}, #{record.receiver,jdbcType=INTEGER},
#{record.content,jdbcType=VARCHAR}, #{record.notificationUrl,jdbcType=VARCHAR},
#{record.status,jdbcType=TINYINT}, #{record.type,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification">
insert into ${platform}_sys_notification
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="record.id != null" >
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="record.id != null">
id,
</if>
<if test="record.sender != null" >
<if test="record.sender != null">
sender,
</if>
<if test="record.receiver != null" >
<if test="record.receiver != null">
receiver,
</if>
<if test="record.content != null" >
<if test="record.content != null">
content,
</if>
<if test="record.notificationUrl != null" >
<if test="record.notificationUrl != null">
notification_url,
</if>
<if test="record.createdAt != null" >
<if test="record.createdAt != null">
created_at,
</if>
<if test="record.status != null" >
<if test="record.status != null">
status,
</if>
<if test="record.type != null" >
<if test="record.type != null">
type,
</if>
<if test="record.isDelete != null" >
<if test="record.isDelete != null">
is_delete,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="record.id != null" >
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="record.id != null">
#{record.id,jdbcType=INTEGER},
</if>
<if test="record.sender != null" >
<if test="record.sender != null">
#{record.sender,jdbcType=INTEGER},
</if>
<if test="record.receiver != null" >
<if test="record.receiver != null">
#{record.receiver,jdbcType=INTEGER},
</if>
<if test="record.content != null" >
<if test="record.content != null">
#{record.content,jdbcType=VARCHAR},
</if>
<if test="record.notificationUrl != null" >
<if test="record.notificationUrl != null">
#{record.notificationUrl,jdbcType=VARCHAR},
</if>
<if test="record.createdAt != null" >
<if test="record.createdAt != null">
#{record.createdAt,jdbcType=TIMESTAMP},
</if>
<if test="record.status != null" >
<if test="record.status != null">
#{record.status,jdbcType=TINYINT},
</if>
<if test="record.type != null" >
<if test="record.type != null">
#{record.type,jdbcType=TINYINT},
</if>
<if test="record.isDelete != null" >
<if test="record.isDelete != null">
#{record.isDelete,jdbcType=BIT},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
<update id="updateByPrimaryKeySelective"
parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification">
update ${platform}_sys_notification
<set >
<if test="record.sender != null" >
<set>
<if test="record.sender != null">
sender = #{record.sender,jdbcType=INTEGER},
</if>
<if test="record.receiver != null" >
<if test="record.receiver != null">
receiver = #{record.receiver,jdbcType=INTEGER},
</if>
<if test="record.content != null" >
<if test="record.content != null">
content = #{record.content,jdbcType=VARCHAR},
</if>
<if test="record.notificationUrl != null" >
<if test="record.notificationUrl != null">
notification_url = #{record.notificationUrl,jdbcType=VARCHAR},
</if>
<if test="record.createdAt != null" >
<if test="record.createdAt != null">
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
</if>
<if test="record.status != null" >
<if test="record.status != null">
status = #{record.status,jdbcType=TINYINT},
</if>
<if test="record.type != null" >
<if test="record.type != null">
status = #{record.type,jdbcType=TINYINT},
</if>
<if test="record.isDelete != null" >
<if test="record.isDelete != null">
is_delete = #{record.isDelete,jdbcType=BIT},
</if>
</set>
where id = #{record.id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
update ${platform}_sys_notification
set sender = #{sender,jdbcType=INTEGER},
receiver = #{receiver,jdbcType=INTEGER},
content = #{content,jdbcType=VARCHAR},
notification_url = #{notificationUrl,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
status = #{status,jdbcType=TINYINT},
type = #{type,jdbcType=TINYINT},
is_delete = #{isDelete,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification">
update ${platform}_sys_notification
set sender = #{sender,jdbcType=INTEGER},
receiver = #{receiver,jdbcType=INTEGER},
content = #{content,jdbcType=VARCHAR},
notification_url = #{notificationUrl,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
status = #{status,jdbcType=TINYINT},
type = #{type,jdbcType=TINYINT},
is_delete = #{isDelete,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateStatusByNotificationId">
update ${platform}_sys_notification set status = #{status} where id in (${notificationIds})
update ${platform}_sys_notification set status = #{status} where id in (${notificationIds})
</update>
<select id="getNewSysNotificationNumber" resultType="java.lang.Integer">
select count(`receiver`)
from ${platform}_sys_notification
where receiver = #{receiver} and status = 1 AND is_delete = -1
select count(`receiver`)
from ${platform}_sys_notification
where receiver = #{receiver} and status = 1 AND is_delete = -1
</select>
<select id="getSysNotificationNumberByType" resultType="java.lang.Integer">
select count(*)
from ${platform}_sys_notification
where receiver = #{receiver} and status = 1 and `type` = #{type} AND is_delete = -1
select count(*)
from ${platform}_sys_notification
where receiver = #{receiver} and status = 1 and `type` = #{type} AND is_delete = -1
</select>
<select id="getUnreadSysNotificationsList" resultMap="BaseResultMap">
select * FROM ${platform}_sys_notification
where receiver = #{receiver} AND status = #{status} AND `type` = #{type} AND is_delete = -1
ORDER BY id DESC limit #{notificationNumber}
select * FROM ${platform}_sys_notification
where receiver = #{receiver} AND status = #{status} AND `type` = #{type} AND is_delete = -1
ORDER BY id DESC limit #{notificationNumber}
</select>
<select id="getSysNotificationPageList" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" resultMap="BaseResultMap">
select * FROM ${platform}_sys_notification
where receiver = #{receiver} AND is_delete = -1
ORDER BY id DESC
<select id="getSysNotificationPageList" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification"
resultMap="BaseResultMap">
select * FROM ${platform}_sys_notification
where receiver = #{receiver} AND is_delete = -1
<if test="type != -1">
and type = #{type}
</if>
ORDER BY id DESC
</select>
</mapper>

View File

@ -29,21 +29,21 @@ public class ServiceTests {
@Test
public void testSysNotificationService() {
int i = sysNotificationService.getUnreadNotificationCount("gitlink", 234);
List<SysNotification> sysNotificationList = sysNotificationService.getUnreadNotificationByType("gitlink", 100, 20, 1);
Page<SysNotification> sysNotificationPage = sysNotificationService.getNotification(1, 10, "", "gitlink", 100);
NewSysNotificationVo newSysNotificationVo = new NewSysNotificationVo();
newSysNotificationVo.setSender((long) -1);
newSysNotificationVo.setReceivers("7,8");
newSysNotificationVo.setContent("baladiwei 在 gitlink-notification-system 修改ReadMe 文件的标题");
newSysNotificationVo.setNotification_url("www.baidu.com");
newSysNotificationVo.setPlatform("gitlink");
boolean j = sysNotificationService.sendNotification(newSysNotificationVo);
logger.info("insertResult:" + j);
int k = sysNotificationService.markNotificationAs("gitlink", "2,3", 2);
logger.info("updateStatus:" + k);
int l = sysNotificationService.getUnreadNotificationByType(1,"gitlink",1);
logger.info("SysNotificationNumber:" + l);
// int i = sysNotificationService.getUnreadNotificationCount("gitlink", 234);
// List<SysNotification> sysNotificationList = sysNotificationService.getUnreadNotificationByType("gitlink", 100, 20, 1);
// Page<SysNotification> sysNotificationPage = sysNotificationService.getNotification(1, 10, "", "gitlink", 100);
// NewSysNotificationVo newSysNotificationVo = new NewSysNotificationVo();
// newSysNotificationVo.setSender((long) -1);
// newSysNotificationVo.setReceivers("7,8");
// newSysNotificationVo.setContent("baladiwei 在 gitlink-notification-system 修改ReadMe 文件的标题");
// newSysNotificationVo.setNotification_url("www.baidu.com");
// newSysNotificationVo.setPlatform("gitlink");
// boolean j = sysNotificationService.sendNotification(newSysNotificationVo);
// logger.info("insertResult:" + j);
// int k = sysNotificationService.markNotificationAs("gitlink", "2,3", 2);
// logger.info("updateStatus:" + k);
// int l = sysNotificationService.getUnreadNotificationByType(1,"gitlink",1);
// logger.info("SysNotificationNumber:" + l);
}
@Test

View File

@ -3,18 +3,16 @@ package cn.org.gitlink.notification.reader.controller;
import cn.org.gitlink.notification.common.response.DataPacketUtil;
import cn.org.gitlink.notification.common.response.ResponseData;
import cn.org.gitlink.notification.common.utils.RedisUtil;
import cn.org.gitlink.notification.model.dao.entity.SysNotification;
import cn.org.gitlink.notification.model.dao.entity.vo.ReceiverNotificationCountVo;
import cn.org.gitlink.notification.model.dao.entity.vo.ReceiverNotificationListVo;
import cn.org.gitlink.notification.model.service.notification.SysNotificationService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/gns/notification")
public class NotificationController {
@ -27,6 +25,10 @@ public class NotificationController {
private static final Integer NOTIFICATION_TYPE_SYS = 1; //系统消息
private static final Integer NOTIFICATION_TYPE_ATME = 2; //@我的消息
//是否显示全部信息的判断
private static final Integer SHOW_OPTION_UNREAD = 1; //只显示固定数目的未读消息
private static final Integer SHOW_OPTION_ALL = 2; //显示所有消息
@Autowired
private RedisUtil redisUtil;
@ -39,16 +41,18 @@ public class NotificationController {
/**
* 获取系统消息列表
*
* @param platform 平台编码
* @param receiver 消息接收者
* @param pageNum 页码
* @param pageSize 页大小
* @param type 消息类型 1 系统消息 | 2 at我
* @param platform 平台
* @param receiver 消息接收者
* @param showOptions 显示选项1 只获取未读消息2 获取全部消息
* @param type 消息类型1 系统消息2 @我消息
* @param pageNum 页码只在 showOptions = 2 是生效
* @param pageSize 页大小只在 showOptions = 2 是生效
* @return
*/
@GetMapping(value = "/{platform}/list")
public ResponseData list(@PathVariable(name = "platform", required = true) String platform,
@RequestParam(name = "receiver", required = true) Integer receiver,
@RequestParam(name = "show", required = false, defaultValue = "1") Integer showOptions,
@RequestParam(name = "type", required = false, defaultValue = "-1") Integer type,
@RequestParam(name = "page", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(name = "size", required = false, defaultValue = "20") Integer pageSize) {
@ -63,22 +67,48 @@ public class NotificationController {
jsonFailResult = validatePageParams(pageNum, pageSize);
if (jsonFailResult != null) return jsonFailResult;
jsonFailResult = validateShowOption(showOptions);
if (jsonFailResult != null) return jsonFailResult;
ReceiverNotificationListVo notificationListVo = new ReceiverNotificationListVo();
notificationListVo.setReceiver(receiver);
notificationListVo.setType(type);
notificationListVo.setTotalUnreadNotifiationCount(notificationService.getUnreadNotificationCount(platform, receiver));
notificationListVo.setUnreadNotificationCount(notificationService.getUnreadNotificationByType(NOTIFICATION_TYPE_SYS, platform, receiver));
notificationListVo.setUnreadAtMeCount(notificationService.getUnreadNotificationByType(NOTIFICATION_TYPE_ATME, platform, receiver));
if (type == NOTIFICATION_TYPE_ALL) {
notificationListVo.setNotificationList(notificationService.getUnreadNotificationByType(platform, receiver, pageSize, NOTIFICATION_TYPE_SYS));
notificationListVo.setAtMeList(notificationService.getUnreadNotificationByType(platform, receiver, pageSize, NOTIFICATION_TYPE_ATME));
} else if (type == NOTIFICATION_TYPE_SYS) {
notificationListVo.setNotificationList(notificationService.getUnreadNotificationByType(platform, receiver, pageSize, NOTIFICATION_TYPE_SYS));
} else {
notificationListVo.setAtMeList(notificationService.getUnreadNotificationByType(platform, receiver, pageSize, NOTIFICATION_TYPE_ATME));
}
return DataPacketUtil.jsonSuccessResult(notificationListVo);
try {
//获取全部未读消息总数
notificationListVo.setTotalUnreadNotifiationCount(notificationService.getUnreadNotificationCount(platform, receiver));
//获取未读系统消息总数
notificationListVo.setUnreadNotificationCount(notificationService.getUnreadNotificationByType(NOTIFICATION_TYPE_SYS, platform, receiver));
//获取未读@我消息总数
notificationListVo.setUnreadAtMeCount(notificationService.getUnreadNotificationByType(NOTIFICATION_TYPE_ATME, platform, receiver));
if (showOptions == SHOW_OPTION_ALL) {
Page foundPage = notificationService.getNotification(type, pageNum, pageSize, "", platform, receiver);
if (foundPage != null) {
notificationListVo.setPageNum(foundPage.getCurrent());
notificationListVo.setPageSize(foundPage.getSize());
notificationListVo.setRecordsCount(foundPage.getTotal());
notificationListVo.setTotalPageCount(foundPage.getPages());
notificationListVo.setRecords(foundPage.getRecords());
}
return DataPacketUtil.jsonSuccessResult(notificationListVo);
}
if (type == NOTIFICATION_TYPE_ALL) {
Page foundPage = notificationService.getNotification(NOTIFICATION_TYPE_ALL, 1, pageSize, "", platform, receiver);
if (foundPage != null) {
notificationListVo.setRecords(foundPage.getRecords());
}
} else if (type == NOTIFICATION_TYPE_SYS) {
notificationListVo.setRecords(notificationService.getUnreadNotificationByType(platform, receiver, pageSize, NOTIFICATION_TYPE_SYS));
} else {
notificationListVo.setRecords(notificationService.getUnreadNotificationByType(platform, receiver, pageSize, NOTIFICATION_TYPE_ATME));
}
return DataPacketUtil.jsonSuccessResult(notificationListVo);
} catch (Exception e) {
logger.error(e);
return DataPacketUtil.jsonFailResult(e.getMessage());
}//end of try-catch
}//end of method
@ -102,18 +132,23 @@ public class NotificationController {
if (jsonFailResult != null) return jsonFailResult;
int unreadNotificationCount = -1;
if (type == NOTIFICATION_TYPE_ALL) {
unreadNotificationCount = notificationService.getUnreadNotificationCount(platform, receiver);
} else {
unreadNotificationCount = notificationService.getUnreadNotificationByType(type, platform, receiver);
}//end of if-else
try {
if (type == NOTIFICATION_TYPE_ALL) {
unreadNotificationCount = notificationService.getUnreadNotificationCount(platform, receiver);
} else {
unreadNotificationCount = notificationService.getUnreadNotificationByType(type, platform, receiver);
}//end of if-else
ReceiverNotificationCountVo countVo = new ReceiverNotificationCountVo();
countVo.setReceiver(receiver);
countVo.setType(type);
countVo.setUnreadNotification(unreadNotificationCount);
ReceiverNotificationCountVo countVo = new ReceiverNotificationCountVo();
countVo.setReceiver(receiver);
countVo.setType(type);
countVo.setUnreadNotification(unreadNotificationCount);
return DataPacketUtil.jsonSuccessResult(countVo);
return DataPacketUtil.jsonSuccessResult(countVo);
} catch (Exception e) {
logger.error(e);
return DataPacketUtil.jsonFailResult(e.getMessage());
}
}//end of method
@ -176,4 +211,19 @@ public class NotificationController {
return null;
}//end of method
/**
* 验证 showOption 参数
*
* @param showOption
* @return
*/
private ResponseData validateShowOption(Integer showOption) {
if (showOption != SHOW_OPTION_UNREAD && showOption != SHOW_OPTION_ALL) {
logger.debug("\t 输入参数 {showOption} 的值 {" + showOption + "} 超出约定范围");
return DataPacketUtil.jsonFailResult("{show} 参数非法");
}
return null;
}//end of method
}//end of class