增加消息通知接口

This commit is contained in:
menxipeng
2025-08-24 00:24:39 +08:00
parent f30ab86f2d
commit 66dc8ce2bf
13 changed files with 1933 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
package com.ruoyi.system.mapper;
import com.ruoyi.common.core.domain.entity.NotificationRecords;
import java.util.List;
/**
* 【请填写功能名称】Mapper接口
*
* @author ruoyi
* @date 2025-08-23
*/
public interface NotificationRecordsMapper
{
/**
* 查询【请填写功能名称】
*
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
public NotificationRecords selectNotificationRecordsById(Long id);
/**
* 查询【请填写功能名称】列表
*
* @param notificationRecords 【请填写功能名称】
* @return 【请填写功能名称】集合
*/
public List<NotificationRecords> selectNotificationRecordsList(NotificationRecords notificationRecords);
/**
* 新增【请填写功能名称】
*
* @param notificationRecords 【请填写功能名称】
* @return 结果
*/
public int insertNotificationRecords(NotificationRecords notificationRecords);
/**
* 修改【请填写功能名称】
*
* @param notificationRecords 【请填写功能名称】
* @return 结果
*/
public int updateNotificationRecords(NotificationRecords notificationRecords);
/**
* 删除【请填写功能名称】
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
public int deleteNotificationRecordsById(Long id);
/**
* 批量删除【请填写功能名称】
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteNotificationRecordsByIds(Long[] ids);
/**
* 批量新增通知记录
*
* @param list 通知记录列表
* @return 结果
*/
public int batchInsertNotificationRecords(List<NotificationRecords> list);
}

View File

@@ -0,0 +1,62 @@
package com.ruoyi.system.mapper;
import com.ruoyi.common.core.domain.entity.Notifications;
import java.util.List;
/**
* 【请填写功能名称】Mapper接口
*
* @author ruoyi
* @date 2025-08-23
*/
public interface NotificationsMapper
{
/**
* 查询【请填写功能名称】
*
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
public Notifications selectNotificationsById(Long id);
/**
* 查询【请填写功能名称】列表
*
* @param notifications 【请填写功能名称】
* @return 【请填写功能名称】集合
*/
public List<Notifications> selectNotificationsList(Notifications notifications);
/**
* 新增【请填写功能名称】
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
public int insertNotifications(Notifications notifications);
/**
* 修改【请填写功能名称】
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
public int updateNotifications(Notifications notifications);
/**
* 删除【请填写功能名称】
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
public int deleteNotificationsById(Long id);
/**
* 批量删除【请填写功能名称】
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteNotificationsByIds(Long[] ids);
}

View File

@@ -0,0 +1,80 @@
package com.ruoyi.system.service;
import com.ruoyi.common.core.domain.entity.NotificationRecords;
import com.ruoyi.common.core.domain.entity.Notifications;
import com.ruoyi.common.core.domain.entity.ShopUser;
import java.util.List;
/**
* 【请填写功能名称】Service接口
*
* @author ruoyi
* @date 2025-08-23
*/
public interface INotificationRecordsService
{
/**
* 绑定用户到通知记录
*
* @param id 通知ID
* @param shopUsers 用户列表
*/
public void bind(Long id, List<ShopUser> shopUsers);
/**
* 获取通知已绑定的用户列表
*
* @param notificationId 通知ID
* @return 用户列表
*/
public List<ShopUser> getBindUsers(Long notificationId);
/**
* 查询【请填写功能名称】
*
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
public NotificationRecords selectNotificationRecordsById(Long id);
/**
* 查询【请填写功能名称】列表
*
* @param notificationRecords 【请填写功能名称】
* @return 【请填写功能名称】集合
*/
public List<NotificationRecords> selectNotificationRecordsList(NotificationRecords notificationRecords);
/**
* 新增【请填写功能名称】
*
* @param notificationRecords 【请填写功能名称】
* @return 结果
*/
public int insertNotificationRecords(NotificationRecords notificationRecords);
/**
* 修改【请填写功能名称】
*
* @param notificationRecords 【请填写功能名称】
* @return 结果
*/
public int updateNotificationRecords(NotificationRecords notificationRecords);
/**
* 批量删除【请填写功能名称】
*
* @param ids 需要删除的【请填写功能名称】主键集合
* @return 结果
*/
public int deleteNotificationRecordsByIds(Long[] ids);
/**
* 删除【请填写功能名称】信息
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
public int deleteNotificationRecordsById(Long id);
}

View File

@@ -0,0 +1,71 @@
package com.ruoyi.system.service;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.Notifications;
import java.util.List;
/**
* 【请填写功能名称】Service接口
*
* @author ruoyi
* @date 2025-08-23
*/
public interface INotificationsService
{
/**
* 查询【请填写功能名称】
*
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
public Notifications selectNotificationsById(Long id);
/**
* 查询【请填写功能名称】列表
*
* @param notifications 【请填写功能名称】
* @return 【请填写功能名称】集合
*/
public List<Notifications> selectNotificationsList(Notifications notifications);
/**
* 新增【请填写功能名称】
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
public int insertNotifications(Notifications notifications);
/**
* 修改【请填写功能名称】
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
public int updateNotifications(Notifications notifications);
/**
* 批量删除【请填写功能名称】
*
* @param ids 需要删除的【请填写功能名称】主键集合
* @return 结果
*/
public int deleteNotificationsByIds(Long[] ids);
/**
* 删除【请填写功能名称】信息
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
public int deleteNotificationsById(Long id);
/**
* 发布通知
*
* @param id 通知ID
* @return 结果
*/
public AjaxResult publishNotification(Long id);
}

View File

@@ -0,0 +1,245 @@
package com.ruoyi.system.service.impl;
import com.ruoyi.common.core.domain.entity.NotificationRecords;
import com.ruoyi.common.core.domain.entity.Notifications;
import com.ruoyi.common.core.domain.entity.ShopUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.NotificationRecordsMapper;
import com.ruoyi.system.service.INotificationRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* 【请填写功能名称】Service业务层处理
*
* @author ruoyi
* @date 2025-08-23
*/
@Transactional
@Service
public class NotificationRecordsServiceImpl implements INotificationRecordsService
{
@Autowired
private NotificationRecordsMapper notificationRecordsMapper;
/**
* 查询【请填写功能名称】
*
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
@Override
public NotificationRecords selectNotificationRecordsById(Long id)
{
return notificationRecordsMapper.selectNotificationRecordsById(id);
}
/**
* 查询【请填写功能名称】列表
*
* @param notificationRecords 【请填写功能名称】
* @return 【请填写功能名称】
*/
@Override
public List<NotificationRecords> selectNotificationRecordsList(NotificationRecords notificationRecords)
{
return notificationRecordsMapper.selectNotificationRecordsList(notificationRecords);
}
/**
* 新增【请填写功能名称】
*
* @param notificationRecords 【请填写功能名称】
* @return 结果
*/
@Override
public int insertNotificationRecords(NotificationRecords notificationRecords)
{
notificationRecords.setCreateTime(DateUtils.getNowDate());
return notificationRecordsMapper.insertNotificationRecords(notificationRecords);
}
/**
* 修改【请填写功能名称】
*
* @param notificationRecords 【请填写功能名称】
* @return 结果
*/
@Override
public int updateNotificationRecords(NotificationRecords notificationRecords)
{
notificationRecords.setUpdateTime(DateUtils.getNowDate());
return notificationRecordsMapper.updateNotificationRecords(notificationRecords);
}
/**
* 批量删除【请填写功能名称】
*
* @param ids 需要删除的【请填写功能名称】主键
* @return 结果
*/
@Override
public int deleteNotificationRecordsByIds(Long[] ids)
{
return notificationRecordsMapper.deleteNotificationRecordsByIds(ids);
}
/**
* 删除【请填写功能名称】信息
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
@Override
public int deleteNotificationRecordsById(Long id)
{
return notificationRecordsMapper.deleteNotificationRecordsById(id);
}
/**
* 绑定用户到通知记录
*
* @param id 通知ID
* @param shopUsers 用户列表
*/
@Override
@Transactional
public void bind(Long id, List<ShopUser> shopUsers) {
System.out.println("开始绑定用户通知ID: " + id + ", 用户数量: " + (shopUsers != null ? shopUsers.size() : 0));
if (id == null || shopUsers == null || shopUsers.isEmpty()) {
System.out.println("通知ID为空或用户列表为空无法绑定");
return;
}
// 打印用户列表信息
System.out.println("用户列表详情:");
for (ShopUser user : shopUsers) {
System.out.println("用户ID: " + (user != null ? user.getUserId() : "null") +
", 类型: " + (user != null && user.getUserId() != null ? user.getUserId().getClass().getName() : "null"));
}
// 获取当前时间
Date now = DateUtils.getNowDate();
// 查询该通知已经绑定的用户ID列表
NotificationRecords query = new NotificationRecords();
query.setNotificationId(id);
List<NotificationRecords> existingRecords = notificationRecordsMapper.selectNotificationRecordsList(query);
Set<Long> existingUserIds = existingRecords.stream()
.map(NotificationRecords::getUserId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
System.out.println("已绑定用户数量: " + existingUserIds.size());
// 创建通知记录列表
List<NotificationRecords> recordsList = new ArrayList<>();
// 遍历用户列表,为每个用户创建通知记录(排除已绑定的用户)
int validUserCount = 0;
int invalidUserCount = 0;
int duplicateUserCount = 0;
for (ShopUser user : shopUsers) {
try {
// 验证用户ID是否有效
if (user == null || user.getUserId() == null) {
System.out.println("用户或用户ID为空跳过");
invalidUserCount++;
continue;
}
if (existingUserIds.contains(user.getUserId())) {
System.out.println("用户ID: " + user.getUserId() + " 已绑定,跳过");
duplicateUserCount++;
continue;
}
// 创建通知记录
NotificationRecords record = new NotificationRecords();
record.setUserId(user.getUserId());
// 默认设置为in-app渠道
record.setChannel("in-app");
// 设置状态为待发送
record.setStatus("pending");
record.setCreateTime(now);
record.setNotificationId(id);
recordsList.add(record);
validUserCount++;
System.out.println("添加用户ID: " + user.getUserId() + " 到待绑定列表");
} catch (Exception e) {
// 记录错误日志,但继续处理其他用户
System.err.println("处理用户ID时出错: " + (user != null ? user.getUserId() : "null") + ", 错误: " + e.getMessage());
e.printStackTrace();
invalidUserCount++;
}
}
System.out.println("有效用户数: " + validUserCount + ", 无效用户数: " + invalidUserCount + ", 重复用户数: " + duplicateUserCount);
System.out.println("待插入记录数: " + recordsList.size());
// 批量插入通知记录
if (!recordsList.isEmpty()) {
try {
int insertCount = notificationRecordsMapper.batchInsertNotificationRecords(recordsList);
System.out.println("成功插入记录数: " + insertCount);
} catch (Exception e) {
System.err.println("批量插入通知记录失败: " + e.getMessage());
e.printStackTrace();
throw new RuntimeException("批量插入通知记录失败: " + e.getMessage(), e);
}
} else {
System.out.println("没有需要插入的记录");
}
}
/**
* 获取通知已绑定的用户列表
*
* @param notificationId 通知ID
* @return 用户列表
*/
@Override
public List<ShopUser> getBindUsers(Long notificationId) {
if (notificationId == null) {
return new ArrayList<>();
}
// 创建查询条件
NotificationRecords query = new NotificationRecords();
query.setNotificationId(notificationId);
// 查询通知记录
List<NotificationRecords> records = notificationRecordsMapper.selectNotificationRecordsList(query);
// 提取用户ID列表
List<Long> userIds = records.stream()
.map(NotificationRecords::getUserId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
// 如果没有绑定用户,返回空列表
if (userIds.isEmpty()) {
return new ArrayList<>();
}
// 查询用户信息
// 这里需要调用ShopUserMapper来查询用户信息
// 由于没有提供ShopUserMapper这里简单处理将用户ID封装成ShopUser对象返回
List<ShopUser> users = new ArrayList<>();
for (Long userId : userIds) {
ShopUser user = new ShopUser();
user.setUserId(userId);
users.add(user);
}
return users;
}
}

View File

@@ -0,0 +1,221 @@
package com.ruoyi.system.service.impl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.NotificationRecords;
import com.ruoyi.common.core.domain.entity.Notifications;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.NotificationRecordsMapper;
import com.ruoyi.system.mapper.NotificationsMapper;
import com.ruoyi.system.service.INotificationsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* 【请填写功能名称】Service业务层处理
*
* @author ruoyi
* @date 2025-08-23
*/
@Service
public class NotificationsServiceImpl implements INotificationsService
{
private static final Logger log = LoggerFactory.getLogger(NotificationsServiceImpl.class);
@Autowired
private NotificationsMapper notificationsMapper;
@Autowired
private NotificationRecordsMapper notificationRecordsMapper;
/**
* 查询【请填写功能名称】
*
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
@Override
public Notifications selectNotificationsById(Long id)
{
return notificationsMapper.selectNotificationsById(id);
}
/**
* 查询【请填写功能名称】列表
*
* @param notifications 【请填写功能名称】
* @return 【请填写功能名称】
*/
@Override
public List<Notifications> selectNotificationsList(Notifications notifications)
{
return notificationsMapper.selectNotificationsList(notifications);
}
/**
* 新增【请填写功能名称】
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
@Override
public int insertNotifications(Notifications notifications)
{
notifications.setCreateTime(DateUtils.getNowDate());
return notificationsMapper.insertNotifications(notifications);
}
/**
* 修改【请填写功能名称】
*
* @param notifications 【请填写功能名称】
* @return 结果
*/
@Override
public int updateNotifications(Notifications notifications)
{
return notificationsMapper.updateNotifications(notifications);
}
/**
* 批量删除【请填写功能名称】
*
* @param ids 需要删除的【请填写功能名称】主键
* @return 结果
*/
@Override
public int deleteNotificationsByIds(Long[] ids)
{
return notificationsMapper.deleteNotificationsByIds(ids);
}
/**
* 删除【请填写功能名称】信息
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
@Override
public int deleteNotificationsById(Long id)
{
return notificationsMapper.deleteNotificationsById(id);
}
/**
* 发布通知
*
* @param id 通知ID
* @return 结果
*/
@Override
@Transactional
public AjaxResult publishNotification(Long id)
{
// 查询通知信息
Notifications notification = notificationsMapper.selectNotificationsById(id);
if (notification == null)
{
return AjaxResult.error("通知不存在");
}
// 查询该通知的所有记录
NotificationRecords query = new NotificationRecords();
query.setNotificationId(id);
List<NotificationRecords> records = notificationRecordsMapper.selectNotificationRecordsList(query);
if (records.isEmpty())
{
return AjaxResult.error("该通知没有绑定任何用户,请先绑定用户");
}
// 当前时间
Date now = DateUtils.getNowDate();
int successCount = 0;
int failCount = 0;
// 遍历所有记录,进行发布
for (NotificationRecords record : records)
{
// 如果记录已经发送过,则不再创建新记录,只更新状态
if ("sent".equals(record.getStatus()))
{
// 调用第三方接口发送通知
boolean sendResult = sendNotificationToThirdParty(notification, record);
if (sendResult)
{
successCount++;
}
else
{
failCount++;
// 更新失败原因
record.setFailureReason("重新发送失败");
notificationRecordsMapper.updateNotificationRecords(record);
}
}
else
{
// 调用第三方接口发送通知
boolean sendResult = sendNotificationToThirdParty(notification, record);
if (sendResult)
{
// 更新记录状态为已发送
record.setStatus("sent");
record.setSentTime(now);
record.setUpdateTime(now);
notificationRecordsMapper.updateNotificationRecords(record);
successCount++;
}
else
{
// 更新记录状态为发送失败
record.setStatus("failed");
record.setFailureReason("发送失败");
record.setUpdateTime(now);
notificationRecordsMapper.updateNotificationRecords(record);
failCount++;
}
}
}
// 更新通知状态为已发布
// notification.setStatus("published");
// notification.setPublishTime(now);
notificationsMapper.updateNotifications(notification);
return AjaxResult.success("通知发布完成,成功:" + successCount + ",失败:" + failCount);
}
/**
* 调用第三方接口发送通知
*
* @param notification 通知信息
* @param record 通知记录
* @return 发送结果
*/
private boolean sendNotificationToThirdParty(Notifications notification, NotificationRecords record)
{
try
{
// TODO: 实现调用第三方接口发送通知的逻辑
// 这里是模拟实现,实际项目中需要根据具体的第三方接口进行调用
log.info("发送通知通知ID={}, 用户ID={}, 标题={}, 内容={}",
notification.getId(), record.getUserId(), notification.getTitle(), notification.getContent());
// 模拟发送成功
return true;
}
catch (Exception e)
{
log.error("发送通知失败:", e);
return false;
}
}
}

View File

@@ -0,0 +1,113 @@
<?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.NotificationRecordsMapper">
<resultMap type="NotificationRecords" id="NotificationRecordsResult">
<result property="id" column="id" />
<result property="notificationId" column="notification_id" />
<result property="userId" column="user_id" />
<result property="channel" column="channel" />
<result property="status" column="status" />
<result property="sentTime" column="sent_time" />
<result property="readTime" column="read_time" />
<result property="failureReason" column="failure_reason" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectNotificationRecordsVo">
select id, notification_id, user_id, channel, status, sent_time, read_time, failure_reason, create_time, update_time from notification_records
</sql>
<select id="selectNotificationRecordsList" parameterType="NotificationRecords" resultMap="NotificationRecordsResult">
<include refid="selectNotificationRecordsVo"/>
<where>
<if test="notificationId != null "> and notification_id = #{notificationId}</if>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="channel != null and channel != ''"> and channel = #{channel}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="sentTime != null "> and sent_time = #{sentTime}</if>
<if test="readTime != null "> and read_time = #{readTime}</if>
<if test="failureReason != null and failureReason != ''"> and failure_reason = #{failureReason}</if>
</where>
</select>
<select id="selectNotificationRecordsById" parameterType="Long" resultMap="NotificationRecordsResult">
<include refid="selectNotificationRecordsVo"/>
where id = #{id}
</select>
<insert id="insertNotificationRecords" parameterType="NotificationRecords" useGeneratedKeys="true" keyProperty="id">
insert into notification_records
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="notificationId != null">notification_id,</if>
<if test="userId != null">user_id,</if>
<if test="channel != null">channel,</if>
<if test="status != null">status,</if>
<if test="sentTime != null">sent_time,</if>
<if test="readTime != null">read_time,</if>
<if test="failureReason != null">failure_reason,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="notificationId != null">#{notificationId},</if>
<if test="userId != null">#{userId},</if>
<if test="channel != null">#{channel},</if>
<if test="status != null">#{status},</if>
<if test="sentTime != null">#{sentTime},</if>
<if test="readTime != null">#{readTime},</if>
<if test="failureReason != null">#{failureReason},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateNotificationRecords" parameterType="NotificationRecords">
update notification_records
<trim prefix="SET" suffixOverrides=",">
<if test="notificationId != null">notification_id = #{notificationId},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="channel != null">channel = #{channel},</if>
<if test="status != null">status = #{status},</if>
<if test="sentTime != null">sent_time = #{sentTime},</if>
<if test="readTime != null">read_time = #{readTime},</if>
<if test="failureReason != null">failure_reason = #{failureReason},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteNotificationRecordsById" parameterType="Long">
delete from notification_records where id = #{id}
</delete>
<delete id="deleteNotificationRecordsByIds" parameterType="String">
delete from notification_records where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<insert id="batchInsertNotificationRecords" parameterType="java.util.List">
insert into notification_records
(notification_id, user_id, channel, status, sent_time, read_time, failure_reason, create_time, update_time)
values
<foreach collection="list" item="item" separator=",">
(
#{item.notificationId},
#{item.userId},
#{item.channel},
#{item.status},
#{item.sentTime},
#{item.readTime},
#{item.failureReason},
#{item.createTime},
#{item.updateTime}
)
</foreach>
</insert>
</mapper>

View File

@@ -0,0 +1,90 @@
<?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.NotificationsMapper">
<resultMap type="Notifications" id="NotificationsResult">
<result property="id" column="id" />
<result property="title" column="title" />
<result property="content" column="content" />
<result property="notificationType" column="notification_type" />
<result property="extraData" column="extra_data" />
<result property="creator" column="creator" />
<result property="createTime" column="create_time" />
<result property="updatedTime" column="updated_time" />
<result property="sendTime" column="send_time" />
</resultMap>
<sql id="selectNotificationsVo">
select id, title, content, notification_type, extra_data, creator, create_time, updated_time, send_time from notifications
</sql>
<select id="selectNotificationsList" parameterType="Notifications" resultMap="NotificationsResult">
<include refid="selectNotificationsVo"/>
<where>
<if test="title != null and title != ''"> and title = #{title}</if>
<if test="content != null and content != ''"> and content = #{content}</if>
<if test="notificationType != null and notificationType != ''"> and notification_type = #{notificationType}</if>
<if test="extraData != null and extraData != ''"> and extra_data = #{extraData}</if>
<if test="creator != null and creator != ''"> and creator = #{creator}</if>
<if test="updatedTime != null "> and updated_time = #{updatedTime}</if>
<if test="sendTime != null "> and send_time = #{sendTime}</if>
</where>
</select>
<select id="selectNotificationsById" parameterType="Long" resultMap="NotificationsResult">
<include refid="selectNotificationsVo"/>
where id = #{id}
</select>
<insert id="insertNotifications" parameterType="Notifications" useGeneratedKeys="true" keyProperty="id">
insert into notifications
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null and title != ''">title,</if>
<if test="content != null and content != ''">content,</if>
<if test="notificationType != null">notification_type,</if>
<if test="extraData != null">extra_data,</if>
<if test="creator != null">creator,</if>
<if test="createTime != null">create_time,</if>
<if test="updatedTime != null">updated_time,</if>
<if test="sendTime != null">send_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null and title != ''">#{title},</if>
<if test="content != null and content != ''">#{content},</if>
<if test="notificationType != null">#{notificationType},</if>
<if test="extraData != null">#{extraData},</if>
<if test="creator != null">#{creator},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updatedTime != null">#{updatedTime},</if>
<if test="sendTime != null">#{sendTime},</if>
</trim>
</insert>
<update id="updateNotifications" parameterType="Notifications">
update notifications
<trim prefix="SET" suffixOverrides=",">
<if test="title != null and title != ''">title = #{title},</if>
<if test="content != null and content != ''">content = #{content},</if>
<if test="notificationType != null">notification_type = #{notificationType},</if>
<if test="extraData != null">extra_data = #{extraData},</if>
<if test="creator != null">creator = #{creator},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updatedTime != null">updated_time = #{updatedTime},</if>
<if test="sendTime != null">send_time = #{sendTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteNotificationsById" parameterType="Long">
delete from notifications where id = #{id}
</delete>
<delete id="deleteNotificationsByIds" parameterType="String">
delete from notifications where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>