消息推送功能

This commit is contained in:
yinjinlu-pc\尹金路 2023-03-08 11:12:56 +08:00
parent 2ae38c75a3
commit 55d5be8b79
20 changed files with 1345 additions and 20 deletions

View File

@ -899,6 +899,7 @@ create table wm_barcode_config (
content_formart varchar(255) not null comment '内容格式', content_formart varchar(255) not null comment '内容格式',
content_example varchar(255) comment '内容样例', content_example varchar(255) comment '内容样例',
auto_gen_flag char(1) default 'Y' comment '是否自动生成', auto_gen_flag char(1) default 'Y' comment '是否自动生成',
default_template varchar(255) comment '默认的打印模板',
enable_flag char(1) default 'Y' comment '是否生效', enable_flag char(1) default 'Y' comment '是否生效',
remark varchar(500) default '' comment '备注', remark varchar(500) default '' comment '备注',
attr1 varchar(64) default null comment '预留字段1', attr1 varchar(64) default null comment '预留字段1',

View File

@ -110,3 +110,34 @@ create table sys_attachment (
) engine=innodb auto_increment=200 comment = '附件表'; ) engine=innodb auto_increment=200 comment = '附件表';
-- ----------------------------
-- 5、消息表
-- ----------------------------
drop table if exists sys_messsage;
create table sys_message (
message_id bigint(20) not null auto_increment comment '附件ID',
message_type varchar(64) not null comment '消息类型',
message_level varchar(64) not null comment '消息级别',
message_title varchar(64) comment '标题',
message_content longblob comment '内容',
sender_id bigint(20) comment '发送人ID',
sender_name varchar(64) comment '发送人名称',
sender_nick varchar(64) comment '发送人昵称',
recipient_id bigint(20) not null comment '接收人ID',
recipient_name varchar(64) comment '接收人名称',
recipient_nick varchar(64) comment '接收人昵称',
process_time datetime comment '处理时间',
call_back varchar(255) comment '回调地址',
status varchar(64) not null default 'UNREAD' comment '状态',
deleted_flag char(1) not null default 'N' comment '是否删除',
remark varchar(500) default '' comment '备注',
attr1 varchar(64) default null comment '预留字段1',
attr2 varchar(255) default null comment '预留字段2',
attr3 int(11) default 0 comment '预留字段3',
attr4 int(11) default 0 comment '预留字段4',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
primary key (message_id)
) engine=innodb auto_increment=200 comment = '消息表';

View File

@ -0,0 +1,121 @@
package com.ktg.web.controller.system;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.core.domain.entity.SysUser;
import com.ktg.common.utils.StringUtils;
import com.ktg.framework.message.MessageProvider;
import com.ktg.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.enums.BusinessType;
import com.ktg.system.domain.SysMessage;
import com.ktg.system.service.ISysMessageService;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;
/**
* 消息Controller
*
* @author yinjinlu
* @date 2023-03-06
*/
@RestController
@RequestMapping("/system/message")
public class SysMessageController extends BaseController
{
@Autowired
private ISysMessageService sysMessageService;
@Autowired
private ISysUserService sysUserService;
@Autowired
private MessageProvider messageProvider;
/**
* 查询消息列表
*/
@PreAuthorize("@ss.hasPermi('system:message:list')")
@GetMapping("/list")
public TableDataInfo list(SysMessage sysMessage)
{
startPage();
List<SysMessage> list = sysMessageService.selectSysMessageList(sysMessage);
return getDataTable(list);
}
/**
* 导出消息列表
*/
@PreAuthorize("@ss.hasPermi('system:message:export')")
@Log(title = "消息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SysMessage sysMessage)
{
List<SysMessage> list = sysMessageService.selectSysMessageList(sysMessage);
ExcelUtil<SysMessage> util = new ExcelUtil<SysMessage>(SysMessage.class);
util.exportExcel(response, list, "消息数据");
}
/**
* 获取消息详细信息
*/
@PreAuthorize("@ss.hasPermi('system:message:query')")
@GetMapping(value = "/{messageId}")
public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
{
return AjaxResult.success(sysMessageService.selectSysMessageByMessageId(messageId));
}
/**
* 新增消息
*/
@PreAuthorize("@ss.hasPermi('system:message:add')")
@Log(title = "消息", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody SysMessage sysMessage)
{
messageProvider.sendMessage(sysMessage);
return AjaxResult.success();
}
/**
* 修改消息
*/
@PreAuthorize("@ss.hasPermi('system:message:edit')")
@Log(title = "消息", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SysMessage sysMessage)
{
return toAjax(sysMessageService.updateSysMessage(sysMessage));
}
/**
* 删除消息
*/
@PreAuthorize("@ss.hasPermi('system:message:remove')")
@Log(title = "消息", businessType = BusinessType.DELETE)
@DeleteMapping("/{messageIds}")
public AjaxResult remove(@PathVariable Long[] messageIds)
{
for (Long messageId: messageIds
) {
SysMessage sysMessage = sysMessageService.selectSysMessageByMessageId(messageId);
sysMessage.setDeletedFlag(UserConstants.YES);
sysMessageService.updateSysMessage(sysMessage);
}
return AjaxResult.success();
}
}

View File

@ -0,0 +1,38 @@
package com.ktg.web.controller.system;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.entity.SysUser;
import com.ktg.common.core.page.TableDataInfo;
import com.ktg.common.utils.SecurityUtils;
import com.ktg.system.domain.SysMessage;
import com.ktg.system.service.ISysMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/mobile/system/message")
public class SysMessageMobController extends BaseController {
@Autowired
private ISysMessageService sysMessageService;
/**
* 查询当前人的消息
*/
@PreAuthorize("@ss.hasPermi('system:message:list')")
@GetMapping("/getMyMessage")
public TableDataInfo list(SysMessage sysMessage)
{
SysUser user = SecurityUtils.getLoginUser().getUser();
startPage();
sysMessage.setRecipientId(user.getUserId());
List<SysMessage> list = sysMessageService.selectSysMessageList(sysMessage);
return getDataTable(list);
}
}

View File

@ -1,5 +1,7 @@
package com.ktg.common.constant; package com.ktg.common.constant;
import org.omg.CORBA.PUBLIC_MEMBER;
/** /**
* 用户常量信息 * 用户常量信息
* *
@ -36,6 +38,8 @@ public class UserConstants
/** 是否为系统默认(是) */ /** 是否为系统默认(是) */
public static final String YES = "Y"; public static final String YES = "Y";
public static final String NO = "N";
/** 是否菜单外链(是) */ /** 是否菜单外链(是) */
public static final String YES_FRAME = "0"; public static final String YES_FRAME = "0";
@ -210,4 +214,11 @@ public class UserConstants
public static final String BARCODE_TYPE_VENDOR = "VENDOR"; //供应商 public static final String BARCODE_TYPE_VENDOR = "VENDOR"; //供应商
public static final String BARCODE_TYPE_SN = "SN"; public static final String BARCODE_TYPE_SN = "SN";
/**
* 消息状态
*/
public static final String MESSAGE_STATUS_UNREAD = "UNREAD"; //未读
public static final String MESSAGE_STATUS_READ = "READ";//已读
public static final String MESSAGE_STATUS_PROCEED = "PROCEED";//已处理
} }

View File

@ -47,6 +47,12 @@
</exclusions> </exclusions>
</dependency> </dependency>
<!-- WebSocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<!-- 获取系统信息 --> <!-- 获取系统信息 -->
<dependency> <dependency>
<groupId>com.github.oshi</groupId> <groupId>com.github.oshi</groupId>

View File

@ -114,6 +114,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
.antMatchers("/webjars/**").anonymous() .antMatchers("/webjars/**").anonymous()
.antMatchers("/*/api-docs").anonymous() .antMatchers("/*/api-docs").anonymous()
.antMatchers("/druid/**").anonymous() .antMatchers("/druid/**").anonymous()
.antMatchers("/websocket/**").anonymous()
.antMatchers("/system/autocode/get/**").permitAll() .antMatchers("/system/autocode/get/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证 // 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated() .anyRequest().authenticated()

View File

@ -0,0 +1,41 @@
package com.ktg.framework.message;
import com.alibaba.fastjson.JSON;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.core.domain.entity.SysUser;
import com.ktg.common.utils.StringUtils;
import com.ktg.framework.websocket.WebSocketUsers;
import com.ktg.system.domain.SysMessage;
import com.ktg.system.service.ISysMessageService;
import com.ktg.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Component
public class MessageProvider {
@Autowired
private ISysMessageService sysMessageService;
@Autowired
private ISysUserService sysUserService;
@Transactional
public void sendMessage(SysMessage message){
message.setStatus(UserConstants.MESSAGE_STATUS_UNREAD);
if(StringUtils.isNotNull(message.getRecipientId())){
SysUser recipient = sysUserService.selectUserById(message.getRecipientId());
message.setRecipientName(recipient.getUserName());
message.setRecipientNick(recipient.getNickName());
}
if(StringUtils.isNotNull(message.getSenderId())){
SysUser sender = sysUserService.selectUserById(message.getSenderId());
message.setRecipientName(sender.getUserName());
message.setRecipientNick(sender.getNickName());
}
message.setDeletedFlag(UserConstants.NO);
WebSocketUsers.sendMesssageToUserByName(message.getRecipientName(), JSON.toJSONString(message));
sysMessageService.insertSysMessage(message);
}
}

View File

@ -222,4 +222,28 @@ public class TokenService
{ {
return Constants.LOGIN_TOKEN_KEY + uuid; return Constants.LOGIN_TOKEN_KEY + uuid;
} }
/**
* 根据Token获取对应的用户
* @param token
* @return
*/
public LoginUser getUserByToken(String token){
if (StringUtils.isNotEmpty(token))
{
try
{
Claims claims = parseToken(token);
// 解析对应的权限以及用户信息
String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid);
LoginUser user = redisCache.getCacheObject(userKey);
return user;
}
catch (Exception e)
{
}
}
return null;
}
} }

View File

@ -0,0 +1,58 @@
package com.ktg.framework.websocket;
import java.util.concurrent.Semaphore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 信号量相关处理
*
* @author ruoyi
*/
public class SemaphoreUtils
{
/**
* SemaphoreUtils 日志控制器
*/
private static final Logger LOGGER = LoggerFactory.getLogger(SemaphoreUtils.class);
/**
* 获取信号量
*
* @param semaphore
* @return
*/
public static boolean tryAcquire(Semaphore semaphore)
{
boolean flag = false;
try
{
flag = semaphore.tryAcquire();
}
catch (Exception e)
{
LOGGER.error("获取信号量异常", e);
}
return flag;
}
/**
* 释放信号量
*
* @param semaphore
*/
public static void release(Semaphore semaphore)
{
try
{
semaphore.release();
}
catch (Exception e)
{
LOGGER.error("释放信号量异常", e);
}
}
}

View File

@ -0,0 +1,20 @@
package com.ktg.framework.websocket;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* websocket 配置
*
* @author ruoyi
*/
@Configuration
public class WebSocketConfig
{
@Bean
public ServerEndpointExporter serverEndpointExporter()
{
return new ServerEndpointExporter();
}
}

View File

@ -0,0 +1,138 @@
package com.ktg.framework.websocket;
import java.util.concurrent.Semaphore;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.ktg.common.core.domain.entity.SysUser;
import com.ktg.common.core.domain.model.LoginUser;
import com.ktg.common.utils.StringUtils;
import com.ktg.common.utils.spring.SpringUtils;
import com.ktg.framework.web.service.TokenService;
import com.ktg.system.domain.SysMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* websocket 消息处理
*
* @author ruoyi
*/
@Component
@ServerEndpoint("/websocket/message/{token}")
public class WebSocketServer
{
/**
* WebSocketServer 日志控制器
*/
private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketServer.class);
/**
* 默认最多允许同时在线人数100
*/
public static int socketMaxOnlineCount = 100;
private static Semaphore socketSemaphore = new Semaphore(socketMaxOnlineCount);
/**
* 连接建立成功调用的方法
*/
@OnOpen
public void onOpen(Session session,@PathParam("token") String token) throws Exception
{
boolean semaphoreFlag = false;
//身份验证
if(!StringUtils.isNotNull(token)){
session.close();
return;
}
TokenService tokenService = SpringUtils.getBean(TokenService.class);
LoginUser user = tokenService.getUserByToken(token);
if(!StringUtils.isNotNull(user)){
session.close();
return;
}
// 尝试获取信号量
semaphoreFlag = SemaphoreUtils.tryAcquire(socketSemaphore);
if (!semaphoreFlag)
{
// 未获取到信号量
LOGGER.error("\n 当前在线人数超过限制数- {}", socketMaxOnlineCount);
WebSocketUsers.sendMessageToUserByText(session, "当前在线人数超过限制数:" + socketMaxOnlineCount);
session.close();
}
else
{
// 添加用户
WebSocketUsers.put(user.getUsername(), session);
LOGGER.info("\n 建立连接 - {}", session);
LOGGER.info("\n 当前人数 - {}", WebSocketUsers.getUsers().size());
WebSocketUsers.sendMessageToUserByText(session, "连接成功");
}
}
/**
* 连接关闭时处理
*/
@OnClose
public void onClose(Session session)
{
LOGGER.info("\n 关闭连接 - {}", session);
// 移除用户
WebSocketUsers.remove(session);
// 获取到信号量则需释放
SemaphoreUtils.release(socketSemaphore);
}
/**
* 抛出异常时处理
*/
@OnError
public void onError(Session session, Throwable exception) throws Exception
{
if (session.isOpen())
{
// 关闭连接
session.close();
}
String sessionId = session.getId();
LOGGER.info("\n 连接异常 - {}", sessionId);
LOGGER.info("\n 异常信息 - {}", exception);
// 移出用户
WebSocketUsers.remove(session);
// 获取到信号量则需释放
SemaphoreUtils.release(socketSemaphore);
}
/**
* 服务器接收到客户端消息时调用的方法
*/
@OnMessage
public void onMessage(String message, Session session)
{
try{
SysMessage msg = JSON.parseObject(message, new TypeReference<SysMessage>(){});
if(StringUtils.isNotNull(msg.getRecipientName())){
//这里必须传递username
WebSocketUsers.sendMesssageToUserByName(msg.getRecipientName(),message);
}
}catch (Exception e){
LOGGER.error("\n 错误的websocket信息格式 - {}", message);
}
}
}

View File

@ -0,0 +1,156 @@
package com.ktg.framework.websocket;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.websocket.Session;
import com.ktg.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* websocket 客户端用户集
*
* @author ruoyi
*/
public class WebSocketUsers
{
/**
* WebSocketUsers 日志控制器
*/
private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketUsers.class);
/**
* 用户集
*/
private static Map<String, Session> USERS = new ConcurrentHashMap<String, Session>();
/**
* 存储用户
*
* @param key 唯一键
* @param session 用户信息
*/
public static void put(String key, Session session)
{
USERS.put(key, session);
}
/**
* 移除用户
*
* @param session 用户信息
*
* @return 移除结果
*/
public static boolean remove(Session session)
{
String key = null;
boolean flag = USERS.containsValue(session);
if (flag)
{
Set<Map.Entry<String, Session>> entries = USERS.entrySet();
for (Map.Entry<String, Session> entry : entries)
{
Session value = entry.getValue();
if (value.equals(session))
{
key = entry.getKey();
break;
}
}
}
else
{
return true;
}
return remove(key);
}
/**
* 移出用户
*
* @param key
*/
public static boolean remove(String key)
{
LOGGER.info("\n 正在移出用户 - {}", key);
Session remove = USERS.remove(key);
if (remove != null)
{
boolean containsValue = USERS.containsValue(remove);
LOGGER.info("\n 移出结果 - {}", containsValue ? "失败" : "成功");
return containsValue;
}
else
{
return true;
}
}
/**
* 获取在线用户列表
*
* @return 返回用户集合
*/
public static Map<String, Session> getUsers()
{
return USERS;
}
/**
* 群发消息文本消息
*
* @param message 消息内容
*/
public static void sendMessageToUsersByText(String message)
{
Collection<Session> values = USERS.values();
for (Session value : values)
{
sendMessageToUserByText(value, message);
}
}
/**
* 发送文本消息
*
* @param session 自己的用户名
* @param message 消息内容
*/
public static void sendMessageToUserByText(Session session, String message)
{
if (session != null)
{
try
{
session.getBasicRemote().sendText(message);
}
catch (IOException e)
{
LOGGER.error("\n[发送消息异常]", e);
}
}
else
{
LOGGER.info("\n[你已离线]");
}
}
public static void sendMesssageToUserByName(String username,String message){
Session session = USERS.get(username);
if(StringUtils.isNotNull(session)){
try
{
session.getBasicRemote().sendText(message);
}
catch (IOException e)
{
LOGGER.error("\n[发送消息异常]", e);
}
}
}
}

View File

@ -38,6 +38,9 @@ public class WmBarcodeConfig extends BaseEntity
@Excel(name = "是否自动生成") @Excel(name = "是否自动生成")
private String autoGenFlag; private String autoGenFlag;
/** 默认的打印模板 **/
private String defaultTemplate;
/** 是否生效 */ /** 是否生效 */
@Excel(name = "是否生效") @Excel(name = "是否生效")
private String enableFlag; private String enableFlag;
@ -112,7 +115,14 @@ public class WmBarcodeConfig extends BaseEntity
{ {
return autoGenFlag; return autoGenFlag;
} }
public void setEnableFlag(String enableFlag) public String getDefaultTemplate() {
return defaultTemplate;
}
public void setDefaultTemplate(String defaultTemplate) {
this.defaultTemplate = defaultTemplate;
}
public void setEnableFlag(String enableFlag)
{ {
this.enableFlag = enableFlag; this.enableFlag = enableFlag;
} }
@ -160,23 +170,19 @@ public class WmBarcodeConfig extends BaseEntity
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return "WmBarcodeConfig{" +
.append("configId", getConfigId()) "configId=" + configId +
.append("barcodeFormart", getBarcodeFormart()) ", barcodeFormart='" + barcodeFormart + '\'' +
.append("barcodeType", getBarcodeType()) ", barcodeType='" + barcodeType + '\'' +
.append("contentFormart", getContentFormart()) ", contentFormart='" + contentFormart + '\'' +
.append("contentExample", getContentExample()) ", contentExample='" + contentExample + '\'' +
.append("autoGenFlag", getAutoGenFlag()) ", autoGenFlag='" + autoGenFlag + '\'' +
.append("enableFlag", getEnableFlag()) ", defaultTemplate='" + defaultTemplate + '\'' +
.append("remark", getRemark()) ", enableFlag='" + enableFlag + '\'' +
.append("attr1", getAttr1()) ", attr1='" + attr1 + '\'' +
.append("attr2", getAttr2()) ", attr2='" + attr2 + '\'' +
.append("attr3", getAttr3()) ", attr3=" + attr3 +
.append("attr4", getAttr4()) ", attr4=" + attr4 +
.append("createBy", getCreateBy()) '}';
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.toString();
} }
} }

View File

@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="contentFormart" column="content_formart" /> <result property="contentFormart" column="content_formart" />
<result property="contentExample" column="content_example" /> <result property="contentExample" column="content_example" />
<result property="autoGenFlag" column="auto_gen_flag" /> <result property="autoGenFlag" column="auto_gen_flag" />
<result property="defaultTemplate" column="default_template" />
<result property="enableFlag" column="enable_flag" /> <result property="enableFlag" column="enable_flag" />
<result property="remark" column="remark" /> <result property="remark" column="remark" />
<result property="attr1" column="attr1" /> <result property="attr1" column="attr1" />
@ -24,7 +25,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectWmBarcodeConfigVo"> <sql id="selectWmBarcodeConfigVo">
select config_id, barcode_formart, barcode_type, content_formart, content_example, auto_gen_flag, enable_flag, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from wm_barcode_config select config_id, barcode_formart, barcode_type, content_formart, content_example, auto_gen_flag,default_template, enable_flag, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from wm_barcode_config
</sql> </sql>
<select id="selectWmBarcodeConfigList" parameterType="WmBarcodeConfig" resultMap="WmBarcodeConfigResult"> <select id="selectWmBarcodeConfigList" parameterType="WmBarcodeConfig" resultMap="WmBarcodeConfigResult">
@ -56,6 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="contentFormart != null and contentFormart != ''">content_formart,</if> <if test="contentFormart != null and contentFormart != ''">content_formart,</if>
<if test="contentExample != null">content_example,</if> <if test="contentExample != null">content_example,</if>
<if test="autoGenFlag != null">auto_gen_flag,</if> <if test="autoGenFlag != null">auto_gen_flag,</if>
<if test="defaultTemplate !=null">default_template,</if>
<if test="enableFlag != null">enable_flag,</if> <if test="enableFlag != null">enable_flag,</if>
<if test="remark != null">remark,</if> <if test="remark != null">remark,</if>
<if test="attr1 != null">attr1,</if> <if test="attr1 != null">attr1,</if>
@ -73,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="contentFormart != null and contentFormart != ''">#{contentFormart},</if> <if test="contentFormart != null and contentFormart != ''">#{contentFormart},</if>
<if test="contentExample != null">#{contentExample},</if> <if test="contentExample != null">#{contentExample},</if>
<if test="autoGenFlag != null">#{autoGenFlag},</if> <if test="autoGenFlag != null">#{autoGenFlag},</if>
<if test="defaultTemplate !=null">#{defaultTemplate},</if>
<if test="enableFlag != null">#{enableFlag},</if> <if test="enableFlag != null">#{enableFlag},</if>
<if test="remark != null">#{remark},</if> <if test="remark != null">#{remark},</if>
<if test="attr1 != null">#{attr1},</if> <if test="attr1 != null">#{attr1},</if>
@ -94,6 +97,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="contentFormart != null and contentFormart != ''">content_formart = #{contentFormart},</if> <if test="contentFormart != null and contentFormart != ''">content_formart = #{contentFormart},</if>
<if test="contentExample != null">content_example = #{contentExample},</if> <if test="contentExample != null">content_example = #{contentExample},</if>
<if test="autoGenFlag != null">auto_gen_flag = #{autoGenFlag},</if> <if test="autoGenFlag != null">auto_gen_flag = #{autoGenFlag},</if>
<if test="defaultTemplate !=null">default_template = #{defaultTemplate},</if>
<if test="enableFlag != null">enable_flag = #{enableFlag},</if> <if test="enableFlag != null">enable_flag = #{enableFlag},</if>
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
<if test="attr1 != null">attr1 = #{attr1},</if> <if test="attr1 != null">attr1 = #{attr1},</if>

View File

@ -0,0 +1,293 @@
package com.ktg.system.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ktg.common.annotation.Excel;
import com.ktg.common.core.domain.BaseEntity;
/**
* 消息对象 sys_message
*
* @author yinjinlu
* @date 2023-03-06
*/
public class SysMessage extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 附件ID */
private Long messageId;
/** 消息类型 */
@Excel(name = "消息类型")
private String messageType;
/** 消息级别 */
@Excel(name = "消息级别")
private String messageLevel;
/** 标题 */
@Excel(name = "标题")
private String messageTitle;
/** 内容 */
@Excel(name = "内容")
private String messageContent;
/** 发送人ID */
@Excel(name = "发送人ID")
private Long senderId;
/** 发送人名称 */
@Excel(name = "发送人名称")
private String senderName;
/** 发送人昵称 */
@Excel(name = "发送人昵称")
private String senderNick;
/** 接收人ID */
@Excel(name = "接收人ID")
private Long recipientId;
/** 接收人名称 */
@Excel(name = "接收人名称")
private String recipientName;
/** 接收人昵称 */
@Excel(name = "接收人昵称")
private String recipientNick;
/** 处理时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "处理时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date processTime;
/** 回调地址 */
@Excel(name = "回调地址")
private String callBack;
/** 状态 */
@Excel(name = "状态")
private String status;
/** 是否删除 */
@Excel(name = "是否删除")
private String deletedFlag;
/** 预留字段1 */
private String attr1;
/** 预留字段2 */
private String attr2;
/** 预留字段3 */
private Long attr3;
/** 预留字段4 */
private Long attr4;
public void setMessageId(Long messageId)
{
this.messageId = messageId;
}
public Long getMessageId()
{
return messageId;
}
public void setMessageType(String messageType)
{
this.messageType = messageType;
}
public String getMessageType()
{
return messageType;
}
public void setMessageLevel(String messageLevel)
{
this.messageLevel = messageLevel;
}
public String getMessageLevel()
{
return messageLevel;
}
public void setMessageTitle(String messageTitle)
{
this.messageTitle = messageTitle;
}
public String getMessageTitle()
{
return messageTitle;
}
public void setMessageContent(String messageContent)
{
this.messageContent = messageContent;
}
public String getMessageContent()
{
return messageContent;
}
public void setSenderId(Long senderId)
{
this.senderId = senderId;
}
public Long getSenderId()
{
return senderId;
}
public void setSenderName(String senderName)
{
this.senderName = senderName;
}
public String getSenderName()
{
return senderName;
}
public void setSenderNick(String senderNick)
{
this.senderNick = senderNick;
}
public String getSenderNick()
{
return senderNick;
}
public void setRecipientId(Long recipientId)
{
this.recipientId = recipientId;
}
public Long getRecipientId()
{
return recipientId;
}
public void setRecipientName(String recipientName)
{
this.recipientName = recipientName;
}
public String getRecipientName()
{
return recipientName;
}
public void setRecipientNick(String recipientNick)
{
this.recipientNick = recipientNick;
}
public String getRecipientNick()
{
return recipientNick;
}
public void setProcessTime(Date processTime)
{
this.processTime = processTime;
}
public Date getProcessTime()
{
return processTime;
}
public void setCallBack(String callBack)
{
this.callBack = callBack;
}
public String getCallBack()
{
return callBack;
}
public void setStatus(String status)
{
this.status = status;
}
public String getStatus()
{
return status;
}
public void setDeletedFlag(String deletedFlag)
{
this.deletedFlag = deletedFlag;
}
public String getDeletedFlag()
{
return deletedFlag;
}
public void setAttr1(String attr1)
{
this.attr1 = attr1;
}
public String getAttr1()
{
return attr1;
}
public void setAttr2(String attr2)
{
this.attr2 = attr2;
}
public String getAttr2()
{
return attr2;
}
public void setAttr3(Long attr3)
{
this.attr3 = attr3;
}
public Long getAttr3()
{
return attr3;
}
public void setAttr4(Long attr4)
{
this.attr4 = attr4;
}
public Long getAttr4()
{
return attr4;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("messageId", getMessageId())
.append("messageType", getMessageType())
.append("messageLevel", getMessageLevel())
.append("messageTitle", getMessageTitle())
.append("messageContent", getMessageContent())
.append("senderId", getSenderId())
.append("senderName", getSenderName())
.append("senderNick", getSenderNick())
.append("recipientId", getRecipientId())
.append("recipientName", getRecipientName())
.append("recipientNick", getRecipientNick())
.append("processTime", getProcessTime())
.append("callBack", getCallBack())
.append("status", getStatus())
.append("deletedFlag", getDeletedFlag())
.append("remark", getRemark())
.append("attr1", getAttr1())
.append("attr2", getAttr2())
.append("attr3", getAttr3())
.append("attr4", getAttr4())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.toString();
}
}

View File

@ -0,0 +1,61 @@
package com.ktg.system.mapper;
import java.util.List;
import com.ktg.system.domain.SysMessage;
/**
* 消息Mapper接口
*
* @author yinjinlu
* @date 2023-03-06
*/
public interface SysMessageMapper
{
/**
* 查询消息
*
* @param messageId 消息主键
* @return 消息
*/
public SysMessage selectSysMessageByMessageId(Long messageId);
/**
* 查询消息列表
*
* @param sysMessage 消息
* @return 消息集合
*/
public List<SysMessage> selectSysMessageList(SysMessage sysMessage);
/**
* 新增消息
*
* @param sysMessage 消息
* @return 结果
*/
public int insertSysMessage(SysMessage sysMessage);
/**
* 修改消息
*
* @param sysMessage 消息
* @return 结果
*/
public int updateSysMessage(SysMessage sysMessage);
/**
* 删除消息
*
* @param messageId 消息主键
* @return 结果
*/
public int deleteSysMessageByMessageId(Long messageId);
/**
* 批量删除消息
*
* @param messageIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteSysMessageByMessageIds(Long[] messageIds);
}

View File

@ -0,0 +1,61 @@
package com.ktg.system.service;
import java.util.List;
import com.ktg.system.domain.SysMessage;
/**
* 消息Service接口
*
* @author yinjinlu
* @date 2023-03-06
*/
public interface ISysMessageService
{
/**
* 查询消息
*
* @param messageId 消息主键
* @return 消息
*/
public SysMessage selectSysMessageByMessageId(Long messageId);
/**
* 查询消息列表
*
* @param sysMessage 消息
* @return 消息集合
*/
public List<SysMessage> selectSysMessageList(SysMessage sysMessage);
/**
* 新增消息
*
* @param sysMessage 消息
* @return 结果
*/
public int insertSysMessage(SysMessage sysMessage);
/**
* 修改消息
*
* @param sysMessage 消息
* @return 结果
*/
public int updateSysMessage(SysMessage sysMessage);
/**
* 批量删除消息
*
* @param messageIds 需要删除的消息主键集合
* @return 结果
*/
public int deleteSysMessageByMessageIds(Long[] messageIds);
/**
* 删除消息信息
*
* @param messageId 消息主键
* @return 结果
*/
public int deleteSysMessageByMessageId(Long messageId);
}

View File

@ -0,0 +1,96 @@
package com.ktg.system.service.impl;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.system.mapper.SysMessageMapper;
import com.ktg.system.domain.SysMessage;
import com.ktg.system.service.ISysMessageService;
/**
* 消息Service业务层处理
*
* @author yinjinlu
* @date 2023-03-06
*/
@Service
public class SysMessageServiceImpl implements ISysMessageService
{
@Autowired
private SysMessageMapper sysMessageMapper;
/**
* 查询消息
*
* @param messageId 消息主键
* @return 消息
*/
@Override
public SysMessage selectSysMessageByMessageId(Long messageId)
{
return sysMessageMapper.selectSysMessageByMessageId(messageId);
}
/**
* 查询消息列表
*
* @param sysMessage 消息
* @return 消息
*/
@Override
public List<SysMessage> selectSysMessageList(SysMessage sysMessage)
{
return sysMessageMapper.selectSysMessageList(sysMessage);
}
/**
* 新增消息
*
* @param sysMessage 消息
* @return 结果
*/
@Override
public int insertSysMessage(SysMessage sysMessage)
{
sysMessage.setCreateTime(DateUtils.getNowDate());
return sysMessageMapper.insertSysMessage(sysMessage);
}
/**
* 修改消息
*
* @param sysMessage 消息
* @return 结果
*/
@Override
public int updateSysMessage(SysMessage sysMessage)
{
sysMessage.setUpdateTime(DateUtils.getNowDate());
return sysMessageMapper.updateSysMessage(sysMessage);
}
/**
* 批量删除消息
*
* @param messageIds 需要删除的消息主键
* @return 结果
*/
@Override
public int deleteSysMessageByMessageIds(Long[] messageIds)
{
return sysMessageMapper.deleteSysMessageByMessageIds(messageIds);
}
/**
* 删除消息信息
*
* @param messageId 消息主键
* @return 结果
*/
@Override
public int deleteSysMessageByMessageId(Long messageId)
{
return sysMessageMapper.deleteSysMessageByMessageId(messageId);
}
}

View File

@ -0,0 +1,158 @@
<?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.ktg.system.mapper.SysMessageMapper">
<resultMap type="SysMessage" id="SysMessageResult">
<result property="messageId" column="message_id" />
<result property="messageType" column="message_type" />
<result property="messageLevel" column="message_level" />
<result property="messageTitle" column="message_title" />
<result property="messageContent" column="message_content" />
<result property="senderId" column="sender_id" />
<result property="senderName" column="sender_name" />
<result property="senderNick" column="sender_nick" />
<result property="recipientId" column="recipient_id" />
<result property="recipientName" column="recipient_name" />
<result property="recipientNick" column="recipient_nick" />
<result property="processTime" column="process_time" />
<result property="callBack" column="call_back" />
<result property="status" column="status" />
<result property="deletedFlag" column="deleted_flag" />
<result property="remark" column="remark" />
<result property="attr1" column="attr1" />
<result property="attr2" column="attr2" />
<result property="attr3" column="attr3" />
<result property="attr4" column="attr4" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectSysMessageVo">
select message_id, message_type, message_level, message_title, message_content, sender_id, sender_name, sender_nick, recipient_id, recipient_name, recipient_nick, process_time, call_back, status, deleted_flag, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from sys_message
</sql>
<select id="selectSysMessageList" parameterType="SysMessage" resultMap="SysMessageResult">
<include refid="selectSysMessageVo"/>
<where>
<if test="messageType != null and messageType != ''"> and message_type = #{messageType}</if>
<if test="messageLevel != null and messageLevel != ''"> and message_level = #{messageLevel}</if>
<if test="messageTitle != null and messageTitle != ''"> and message_title = #{messageTitle}</if>
<if test="messageContent != null and messageContent != ''"> and message_content = #{messageContent}</if>
<if test="senderId != null "> and sender_id = #{senderId}</if>
<if test="senderName != null and senderName != ''"> and sender_name like concat('%', #{senderName}, '%')</if>
<if test="senderNick != null and senderNick != ''"> and sender_nick = #{senderNick}</if>
<if test="recipientId != null "> and recipient_id = #{recipientId}</if>
<if test="recipientName != null and recipientName != ''"> and recipient_name like concat('%', #{recipientName}, '%')</if>
<if test="recipientNick != null and recipientNick != ''"> and recipient_nick = #{recipientNick}</if>
<if test="processTime != null "> and process_time = #{processTime}</if>
<if test="callBack != null and callBack != ''"> and call_back = #{callBack}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
and deleted_flag = 'N'
</where>
order by create_time desc
</select>
<select id="selectSysMessageByMessageId" parameterType="Long" resultMap="SysMessageResult">
<include refid="selectSysMessageVo"/>
where message_id = #{messageId}
</select>
<insert id="insertSysMessage" parameterType="SysMessage" useGeneratedKeys="true" keyProperty="messageId">
insert into sys_message
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="messageType != null and messageType != ''">message_type,</if>
<if test="messageLevel != null and messageLevel != ''">message_level,</if>
<if test="messageTitle != null">message_title,</if>
<if test="messageContent != null">message_content,</if>
<if test="senderId != null">sender_id,</if>
<if test="senderName != null">sender_name,</if>
<if test="senderNick != null">sender_nick,</if>
<if test="recipientId != null">recipient_id,</if>
<if test="recipientName != null">recipient_name,</if>
<if test="recipientNick != null">recipient_nick,</if>
<if test="processTime != null">process_time,</if>
<if test="callBack != null">call_back,</if>
<if test="status != null and status != ''">status,</if>
<if test="deletedFlag != null and deletedFlag != ''">deleted_flag,</if>
<if test="remark != null">remark,</if>
<if test="attr1 != null">attr1,</if>
<if test="attr2 != null">attr2,</if>
<if test="attr3 != null">attr3,</if>
<if test="attr4 != null">attr4,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="messageType != null and messageType != ''">#{messageType},</if>
<if test="messageLevel != null and messageLevel != ''">#{messageLevel},</if>
<if test="messageTitle != null">#{messageTitle},</if>
<if test="messageContent != null">#{messageContent},</if>
<if test="senderId != null">#{senderId},</if>
<if test="senderName != null">#{senderName},</if>
<if test="senderNick != null">#{senderNick},</if>
<if test="recipientId != null">#{recipientId},</if>
<if test="recipientName != null">#{recipientName},</if>
<if test="recipientNick != null">#{recipientNick},</if>
<if test="processTime != null">#{processTime},</if>
<if test="callBack != null">#{callBack},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="deletedFlag != null and deletedFlag != ''">#{deletedFlag},</if>
<if test="remark != null">#{remark},</if>
<if test="attr1 != null">#{attr1},</if>
<if test="attr2 != null">#{attr2},</if>
<if test="attr3 != null">#{attr3},</if>
<if test="attr4 != null">#{attr4},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateSysMessage" parameterType="SysMessage">
update sys_message
<trim prefix="SET" suffixOverrides=",">
<if test="messageType != null and messageType != ''">message_type = #{messageType},</if>
<if test="messageLevel != null and messageLevel != ''">message_level = #{messageLevel},</if>
<if test="messageTitle != null">message_title = #{messageTitle},</if>
<if test="messageContent != null">message_content = #{messageContent},</if>
<if test="senderId != null">sender_id = #{senderId},</if>
<if test="senderName != null">sender_name = #{senderName},</if>
<if test="senderNick != null">sender_nick = #{senderNick},</if>
<if test="recipientId != null">recipient_id = #{recipientId},</if>
<if test="recipientName != null">recipient_name = #{recipientName},</if>
<if test="recipientNick != null">recipient_nick = #{recipientNick},</if>
<if test="processTime != null">process_time = #{processTime},</if>
<if test="callBack != null">call_back = #{callBack},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="deletedFlag != null and deletedFlag != ''">deleted_flag = #{deletedFlag},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="attr1 != null">attr1 = #{attr1},</if>
<if test="attr2 != null">attr2 = #{attr2},</if>
<if test="attr3 != null">attr3 = #{attr3},</if>
<if test="attr4 != null">attr4 = #{attr4},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where message_id = #{messageId}
</update>
<delete id="deleteSysMessageByMessageId" parameterType="Long">
delete from sys_message where message_id = #{messageId}
</delete>
<delete id="deleteSysMessageByMessageIds" parameterType="String">
delete from sys_message where message_id in
<foreach item="messageId" collection="array" open="(" separator="," close=")">
#{messageId}
</foreach>
</delete>
</mapper>