This commit is contained in:
ldrop 2025-01-13 16:12:45 +08:00
parent 4fc8b5ad9e
commit 02fe56d0ab
14 changed files with 141 additions and 555 deletions

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -19,14 +18,13 @@ import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.modelMessage.domain.MessageSystem; import com.ruoyi.modelMessage.domain.MessageSystem;
import com.ruoyi.modelMessage.domain.MessageTemplate;
import com.ruoyi.modelMessage.domain.vo.SysUserVo;
import com.ruoyi.modelMessage.service.IMessageSystemService; import com.ruoyi.modelMessage.service.IMessageSystemService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -97,6 +95,7 @@ public class MessageSystemController extends BaseController
public AjaxResult edit(@RequestBody MessageSystem messageSystem) public AjaxResult edit(@RequestBody MessageSystem messageSystem)
{ {
messageSystem.setUpdateBy(getUsername()); messageSystem.setUpdateBy(getUsername());
messageSystem.setUpdateTime(DateUtils.getNowDate());
return toAjax(messageSystemService.updateMessageSystem(messageSystem)); return toAjax(messageSystemService.updateMessageSystem(messageSystem));
} }
@ -121,32 +120,21 @@ public class MessageSystemController extends BaseController
@Transactional @Transactional
public AjaxResult batchAdd(@RequestBody List<MessageSystem> messageSystemList) { public AjaxResult batchAdd(@RequestBody List<MessageSystem> messageSystemList) {
try { try {
for (MessageSystem message : messageSystemList) { messageSystemList.forEach(messageSystemService::processMessageSystem);
messageSystemService.processMessageSystem(message); messageSystemService.batchInsertMessageSystem(messageSystemList);
}
if (messageSystemService.batchInsertMessageSystem(messageSystemList) <= 0) {
throw new ServiceException("消息发送失败!");
}
return AjaxResult.success("消息发送成功!"); return AjaxResult.success("消息发送成功!");
} catch (Exception e) { } catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return AjaxResult.error("消息发送失败", e);
return AjaxResult.error("消息发送失败!", e);
} }
} }
/** /**
* 用户点击标题之后已读信息 * 用户点击标题调整信息状态
*/ */
@Operation(summary = "用户点击标题调整信息状态") @Operation(summary = "用户点击标题调整信息状态")
@PostMapping("/{messageId}") @PostMapping("/{messageId}")
public AjaxResult update(@PathVariable Long messageId){ public AjaxResult update(@PathVariable Long messageId){
try{ return success(messageSystemService.updateState(messageId));
int state= messageSystemService.updateState(messageId);
return success(state);
}catch(Exception e){
e.printStackTrace();
return error();
}
} }
/** /**
@ -156,15 +144,17 @@ public class MessageSystemController extends BaseController
@GetMapping("/selectUser") @GetMapping("/selectUser")
public AjaxResult selectUser(@RequestParam(required = false) String sendMode) { public AjaxResult selectUser(@RequestParam(required = false) String sendMode) {
try { try {
List<SysUserVo> list; // 非空检查并提供默认值
if ("1".equals(sendMode)) { // 手机号 if (sendMode == null || sendMode.trim().isEmpty()) {
list = messageSystemService.getUsersFilteredBySendMode("phone"); sendMode = "default";
} else if ("2".equals(sendMode)) { // 邮箱
list = messageSystemService.getUsersFilteredBySendMode("email");
} else {
list = messageSystemService.selectUser();
} }
return AjaxResult.success(list); List<SysUser> list;
switch (sendMode) {
case "1": list = messageSystemService.getUsersFilteredBySendMode("phone"); break; // 短信
case "2": list = messageSystemService.getUsersFilteredBySendMode("email"); break;// 邮件
default: list = messageSystemService.selectUser(); break; //默认查询全部的用户
}
return success(list);
} catch (ServiceException e) { } catch (ServiceException e) {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
@ -194,11 +184,10 @@ public class MessageSystemController extends BaseController
* @param roleId 角色ID * @param roleId 角色ID
* @return 用户信息列表 * @return 用户信息列表
*/ */
@Operation(summary = "根据角色ID获取所有符合条件的用户信息") @Operation(summary = "根据角色Id查询所有符合条件的用户信息")
@GetMapping("/getUsersByRole/{roleId}") @GetMapping("/getUsersByRole/{roleId}")
public R<List<SysUserVo>> selectUsersByRoleId(@PathVariable Long roleId) { public AjaxResult selectUsersByRoleId(@PathVariable Long roleId) {
List<SysUserVo> users = messageSystemService.selectUsersByRoleId(roleId); return success(messageSystemService.selectUsersByRoleId(roleId));
return R.ok(users);
} }
/** /**
@ -207,11 +196,10 @@ public class MessageSystemController extends BaseController
* @param deptId 部门ID * @param deptId 部门ID
* @return 用户信息列表 * @return 用户信息列表
*/ */
@Operation(summary = "根据部门ID获取所有符合条件的用户信息") @Operation(summary = "根据部门Id查询所有符合条件的用户信息")
@GetMapping("/getUserNameByDeptId/{deptId}") @GetMapping("/getUserNameByDeptId/{deptId}")
public R<List<SysUserVo>> getUserNameByDeptId(@PathVariable Long deptId) { public AjaxResult getUserNameByDeptId(@PathVariable Long deptId) {
List<SysUserVo> depts= messageSystemService.getUserNameByDeptId(deptId); return success(messageSystemService.getUserNameByDeptId(deptId));
return R.ok(depts);
} }
/** /**
@ -220,8 +208,7 @@ public class MessageSystemController extends BaseController
*/ */
@Operation(summary = "查询模版签名") @Operation(summary = "查询模版签名")
@GetMapping("/selecTemplates") @GetMapping("/selecTemplates")
public R selecTemplates() { public AjaxResult selecTemplates() {
List<MessageTemplate> templates= messageSystemService.selecTemplates(); return success(messageSystemService.selecTemplates());
return R.ok(templates);
} }
} }

View File

@ -14,16 +14,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.modelMessage.domain.MessageVariable; import com.ruoyi.modelMessage.domain.MessageVariable;
import com.ruoyi.modelMessage.service.IMessageVariableService; import com.ruoyi.modelMessage.service.IMessageVariableService;
import com.ruoyi.modelMessage.utils.MessageSystemUtils;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -43,6 +42,9 @@ public class MessageVariableController extends BaseController
@Autowired @Autowired
private IMessageVariableService messageVariableService; private IMessageVariableService messageVariableService;
@Autowired
private MessageSystemUtils messageVariableUtils;
/** /**
* 查询变量管理列表 * 查询变量管理列表
*/ */
@ -114,26 +116,14 @@ public class MessageVariableController extends BaseController
@DeleteMapping("/{variableIds}") @DeleteMapping("/{variableIds}")
public AjaxResult remove(@PathVariable( name = "variableIds" ) Long[] variableIds) public AjaxResult remove(@PathVariable( name = "variableIds" ) Long[] variableIds)
{ {
for (Long variableId : variableIds) {
// 获取变量信息
MessageVariable variable = messageVariableService.selectMessageVariableByVariableId(variableId);
if (variable == null) {
throw new ServiceException("变量不存在!");
}
// 检查变量是否被模板使用
if (messageVariableService.selectTemplateByVariableId(variable.getVariableName())) {
throw new ServiceException("该变量已被模版使用,不能删除!");
}
}
return toAjax(messageVariableService.deleteMessageVariableByVariableIds(variableIds)); return toAjax(messageVariableService.deleteMessageVariableByVariableIds(variableIds));
} }
/** /**
* 查询角色信息 * 查询变量
*/ */
@Operation(summary = "查询变量") @Operation(summary = "查询变量")
@GetMapping("/selectMessageVariable") @GetMapping("/selectMessageVariable")
@Anonymous
public AjaxResult selectMessageVariable() { public AjaxResult selectMessageVariable() {
return success(messageVariableService.selectMessageVariable()); return success(messageVariableService.selectMessageVariable());
} }
@ -141,14 +131,9 @@ public class MessageVariableController extends BaseController
/** /**
* 根据变量类型生成不同的变量内容 * 根据变量类型生成不同的变量内容
*/ */
@Operation(summary = "根据变量类型生成不同变量内容") @Operation(summary = "根据内置变量生成不同内容")
@GetMapping("/generate") @GetMapping("/generate")
public AjaxResult generateVariableContent(@RequestParam String variableType) { public AjaxResult generateVariableContent(@RequestParam String variableContent) {
try { return success(messageVariableUtils.generateVariableContent(variableContent));
Object content = messageVariableService.generateVariableContent(variableType);
return AjaxResult.success(content);
} catch (Exception e) {
return AjaxResult.error("生成变量内容失败!");
}
} }
} }

View File

@ -1,220 +0,0 @@
package com.ruoyi.modelMessage.domain.vo;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
/**
* 部门表 sys_dept
*
* @author ruoyi
*/
@Schema(title = "部门")
public class SysDeptVo extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 部门ID */
@Schema(title = "部门ID")
private Long deptId;
/** 父部门ID */
@Schema(title = "父部门ID")
private Long parentId;
/** 祖级列表 */
@Schema(title = "祖级列表")
private String ancestors;
/** 部门名称 */
@Schema(title = "部门名称")
private String deptName;
/** 显示顺序 */
@Schema(title = "显示顺序")
private Integer orderNum;
/** 负责人 */
@Schema(title = "负责人")
private String leader;
/** 联系电话 */
@Schema(title = "联系电话")
private String phone;
/** 邮箱 */
@Schema(title = "邮箱")
private String email;
/** 部门状态:0正常,1停用 */
@Schema(title = "部门表",description = "0正常,1停用")
private String status;
/** 删除标志0代表存在 2代表删除 */
@Schema(title = "删除标志",description = "0代表存在 2代表删除")
private String delFlag;
/** 父部门名称 */
@Schema(title = "父部门名称")
private String parentName;
/** 子部门 */
@Schema(title = "子部门")
private List<SysDeptVo> children = new ArrayList<SysDeptVo>();
public Long getDeptId()
{
return deptId;
}
public void setDeptId(Long deptId)
{
this.deptId = deptId;
}
public Long getParentId()
{
return parentId;
}
public void setParentId(Long parentId)
{
this.parentId = parentId;
}
public String getAncestors()
{
return ancestors;
}
public void setAncestors(String ancestors)
{
this.ancestors = ancestors;
}
@NotBlank(message = "部门名称不能为空")
@Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
public String getDeptName()
{
return deptName;
}
public void setDeptName(String deptName)
{
this.deptName = deptName;
}
@NotNull(message = "显示顺序不能为空")
public Integer getOrderNum()
{
return orderNum;
}
public void setOrderNum(Integer orderNum)
{
this.orderNum = orderNum;
}
public String getLeader()
{
return leader;
}
public void setLeader(String leader)
{
this.leader = leader;
}
@Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
@Email(message = "邮箱格式不正确")
@Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public String getStatus()
{
return status;
}
public void setStatus(String status)
{
this.status = status;
}
public String getDelFlag()
{
return delFlag;
}
public void setDelFlag(String delFlag)
{
this.delFlag = delFlag;
}
public String getParentName()
{
return parentName;
}
public void setParentName(String parentName)
{
this.parentName = parentName;
}
public List<SysDeptVo> getChildren()
{
return children;
}
public void setChildren(List<SysDeptVo> children)
{
this.children = children;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("deptId", getDeptId())
.append("parentId", getParentId())
.append("ancestors", getAncestors())
.append("deptName", getDeptName())
.append("orderNum", getOrderNum())
.append("leader", getLeader())
.append("phone", getPhone())
.append("email", getEmail())
.append("status", getStatus())
.append("delFlag", getDelFlag())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.toString();
}
}

View File

@ -1,55 +0,0 @@
package com.ruoyi.modelMessage.domain.vo;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import io.swagger.v3.oas.annotations.media.Schema;
/**
* 角色表 sys_role
*
* @author ruoyi
*/
@Schema(title = "角色表")
public class SysRoleVo
{
/** 角色ID */
@Schema(title = "角色ID")
@Excel(name = "角色序号", cellType = ColumnType.NUMERIC)
private Long roleId;
/** 角色名称 */
@Schema(title = "角色名称")
@Excel(name = "角色名称")
private String roleName;
public Long getRoleId() {
return roleId;
}
public void setRoleId(Long roleId) {
this.roleId = roleId;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("roleId", getRoleId())
.append("roleName", getRoleName())
.toString();
}
}

View File

@ -1,96 +0,0 @@
package com.ruoyi.modelMessage.domain.vo;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.Type;
import io.swagger.v3.oas.annotations.media.Schema;
/**
* 用户对象 sys_user
*
* @author ruoyi
*/
@Schema(title = "用户")
public class SysUserVo
{
private static final long serialVersionUID = 1L;
/** 用户ID */
@Schema(title = "用户编号")
@Excel(name = "用户编号")
private Long userId;
/** 部门ID */
@Schema(title = "部门编号")
@Excel(name = "部门编号", type = Type.IMPORT)
private Long deptId;
/** 用户账号 */
@Schema(title = "登录名称")
@Excel(name = "登录名称")
private String userName;
/** 用户邮箱 */
@Schema(title = "用户邮箱")
@Excel(name = "用户邮箱")
private String email;
/** 手机号码 */
@Schema(title = "手机号码")
@Excel(name = "手机号码")
private String phonenumber;
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getDeptId() {
return deptId;
}
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("userId", getUserId())
.append("deptId", getDeptId())
.append("userName", getUserName())
.append("email", getEmail())
.append("phonenumber", getPhonenumber())
.toString();
}
}

View File

@ -5,11 +5,11 @@ import java.util.List;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.modelMessage.domain.MessageSystem; import com.ruoyi.modelMessage.domain.MessageSystem;
import com.ruoyi.modelMessage.domain.MessageTemplate; import com.ruoyi.modelMessage.domain.MessageTemplate;
import com.ruoyi.modelMessage.domain.vo.SysDeptVo;
import com.ruoyi.modelMessage.domain.vo.SysRoleVo;
import com.ruoyi.modelMessage.domain.vo.SysUserVo;
/** /**
* 消息管理Mapper接口 * 消息管理Mapper接口
@ -68,26 +68,26 @@ public interface MessageSystemMapper
public int deleteMessageSystemByMessageIds(Long[] messageIds); public int deleteMessageSystemByMessageIds(Long[] messageIds);
//查询平台系统资源收件人用户信息 //查询平台系统资源收件人用户信息
@Select("SELECT * FROM `sys_user`") @Select("SELECT user_id, dept_id, user_name, phonenumber, email FROM `sys_user`")
public List<SysUserVo> selectUser(); public List<SysUser> selectUser();
//查询角色信息 然后根据角色把消息发给某角色 //查询角色信息 然后根据角色把消息发给某角色
@Select("SELECT * FROM `sys_role`") @Select("SELECT role_id, role_name FROM `sys_role`")
public List<SysRoleVo> selectRole(); public List<SysRole> selectRole();
//查询部门信息 然后根据部门把消息发给某部门 //查询部门信息 然后根据部门把消息发给某部门
@Select("SELECT * FROM `sys_dept`") @Select("SELECT dept_id, parent_id, dept_name FROM `sys_dept`")
public List<SysDeptVo> selectDept(); public List<SysDept> selectDept();
// 根据发送方式过滤用户 (短信或邮箱) // 根据发送方式过滤用户 (短信或邮箱)
@Select("<script>" + @Select("<script>" +
"SELECT * FROM `sys_user`" + "SELECT user_id, dept_id, user_name, phonenumber, email FROM `sys_user`" +
"<where>" + "<where>" +
"<if test='filterType == \"phone\"'>AND phonenumber IS NOT NULL AND phonenumber != ''</if>" + "<if test='filterType == \"phone\"'>AND phonenumber IS NOT NULL AND phonenumber != ''</if>" +
"<if test='filterType == \"email\"'>AND email IS NOT NULL AND email != ''</if>" + "<if test='filterType == \"email\"'>AND email IS NOT NULL AND email != ''</if>" +
"</where>" + "</where>" +
"</script>") "</script>")
List<SysUserVo> selectUserBySendMode(String filterType); List<SysUser> selectUserBySendMode(String filterType);
//将信息状态未读信息变为已读 //将信息状态未读信息变为已读
@Update("update message_system set message_status = 1 where message_id = #{messageId} and message_recipient = #{userName}") @Update("update message_system set message_status = 1 where message_id = #{messageId} and message_recipient = #{userName}")
@ -100,8 +100,8 @@ public interface MessageSystemMapper
* @param deptId 部门ID * @param deptId 部门ID
* @return 用户信息列表 * @return 用户信息列表
*/ */
@Select("SELECT u.* FROM sys_user u JOIN sys_dept d ON u.dept_id = d.dept_id WHERE d.dept_id = #{deptId}") @Select("SELECT u.user_name FROM sys_user u JOIN sys_dept d ON u.dept_id = d.dept_id WHERE d.dept_id = #{deptId}")
public List<SysUserVo> getUserNameByDeptId(Long roleId); public List<SysUser> getUserNameByDeptId(Long deptId);
/** /**
* 根据角色ID查询用户列表 * 根据角色ID查询用户列表
@ -109,11 +109,11 @@ public interface MessageSystemMapper
* @param roleId 角色ID * @param roleId 角色ID
* @return 用户列表 * @return 用户列表
*/ */
@Select("SELECT u.* FROM sys_user u JOIN sys_user_role ur ON u.user_id = ur.user_id WHERE ur.role_id = #{roleId}") @Select("SELECT u.user_name FROM sys_user u JOIN sys_user_role ur ON u.user_id = ur.user_id WHERE ur.role_id = #{roleId}")
public List<SysUserVo> selectUsersByRoleId(Long roleId); public List<SysUser> selectUsersByRoleId(Long roleId);
//查询模版签名 //查询模版签名
@Select("SELECT template_id,template_code,template_variable FROM `message_template`") @Select("SELECT template_id,template_code FROM `message_template`")
public List<MessageTemplate> selecTemplates(); public List<MessageTemplate> selecTemplates();
//批量发送信息 //批量发送信息

View File

@ -68,6 +68,6 @@ public interface MessageTemplateMapper
* @param templateCode 模版编码 * @param templateCode 模版编码
* @return 模版对象 * @return 模版对象
*/ */
@Select("SELECT * FROM message_template WHERE template_code = #{templateCode}") @Select("SELECT template_code,template_variable,template_content FROM `message_template` WHERE template_code = #{templateCode}")
public MessageTemplate selectMessageTemplateByTemplateCode(String templateCode); public MessageTemplate selectMessageTemplateByTemplateCode(String templateCode);
} }

View File

@ -62,14 +62,14 @@ public interface MessageVariableMapper
*/ */
public int deleteMessageVariableByVariableIds(Long[] variableIds); public int deleteMessageVariableByVariableIds(Long[] variableIds);
//删除变量之前检查一下有没有模版使用
@Select("SELECT COUNT(*) > 0 FROM message_template WHERE template_variable = #{templateVariable}")
public boolean selectTemplateByVariableId(String templateVariable);
//查询变量 //查询变量
@Select("SELECT * FROM message_variable") @Select("SELECT variable_id, variable_name, variable_type, variable_content FROM message_variable")
public List<MessageVariable> selectMessageVariable(); public List<MessageVariable> selectMessageVariable();
//查询在使用模版签名时用到了那些变量一一赋值 //查询在使用模版签名时用到了那些变量一一赋值
public List<MessageVariable> selectMessageVariables(List<String> variableNames); public List<MessageVariable> selectMessageVariables(List<String> variableNames);
//查询模版使用的变量
@Select("SELECT template_variable FROM message_template")
public List<String> selectAllTemplateVariables();
} }

View File

@ -2,11 +2,11 @@ package com.ruoyi.modelMessage.service;
import java.util.List; import java.util.List;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.modelMessage.domain.MessageSystem; import com.ruoyi.modelMessage.domain.MessageSystem;
import com.ruoyi.modelMessage.domain.MessageTemplate; import com.ruoyi.modelMessage.domain.MessageTemplate;
import com.ruoyi.modelMessage.domain.vo.SysDeptVo;
import com.ruoyi.modelMessage.domain.vo.SysRoleVo;
import com.ruoyi.modelMessage.domain.vo.SysUserVo;
/** /**
* 消息管理Service接口 * 消息管理Service接口
@ -65,7 +65,7 @@ public interface IMessageSystemService
public int deleteMessageSystemByMessageId(Long messageId); public int deleteMessageSystemByMessageId(Long messageId);
//查询系统资源用户信息 //查询系统资源用户信息
public List<SysUserVo> selectUser(); public List<SysUser> selectUser();
//将信息状态未读信息变为已读 //将信息状态未读信息变为已读
public int updateState(Long messageId); public int updateState(Long messageId);
@ -74,13 +74,13 @@ public interface IMessageSystemService
public void processMessageSystem(MessageSystem messageSystem); public void processMessageSystem(MessageSystem messageSystem);
// 根据发送方式过滤用户 (短信或邮箱) // 根据发送方式过滤用户 (短信或邮箱)
public List<SysUserVo> getUsersFilteredBySendMode(String filterType); public List<SysUser> getUsersFilteredBySendMode(String filterType);
//查询角色信息 然后根据角色把消息发给某角色 //查询角色信息 然后根据角色把消息发给某角色
public List<SysRoleVo> selectRole(); public List<SysRole> selectRole();
//查询部门信息 然后根据部门把消息发给某部门 //查询部门信息 然后根据部门把消息发给某部门
public List<SysDeptVo> selectDept(); public List<SysDept> selectDept();
/** /**
* 根据角色ID获取用户列表 * 根据角色ID获取用户列表
@ -89,7 +89,7 @@ public interface IMessageSystemService
* @return * @return
* *
* */ * */
public List<SysUserVo> selectUsersByRoleId(Long roleId); public List<SysUser> selectUsersByRoleId(Long roleId);
/** /**
* 根据部门ID获取用户列表 * 根据部门ID获取用户列表
@ -98,7 +98,7 @@ public interface IMessageSystemService
* @return * @return
* *
* */ * */
public List<SysUserVo> getUserNameByDeptId(Long deptId); public List<SysUser> getUserNameByDeptId(Long deptId);
// 查询模版签名 // 查询模版签名
public List<MessageTemplate> selecTemplates(); public List<MessageTemplate> selecTemplates();

View File

@ -60,12 +60,8 @@ public interface IMessageVariableService
*/ */
public int deleteMessageVariableByVariableId(Long variableId); public int deleteMessageVariableByVariableId(Long variableId);
// 查询全部变量 /**
* 查询全部变量
*/
public List<MessageVariable> selectMessageVariable(); public List<MessageVariable> selectMessageVariable();
// 删除变量之前检查一下有没有模版使用
public boolean selectTemplateByVariableId(String templateVariable);
// 根据类型生成不同的变量内容
public String generateVariableContent(String variableType);
} }

View File

@ -10,15 +10,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.modelMessage.domain.MessageSystem; import com.ruoyi.modelMessage.domain.MessageSystem;
import com.ruoyi.modelMessage.domain.MessageTemplate; import com.ruoyi.modelMessage.domain.MessageTemplate;
import com.ruoyi.modelMessage.domain.vo.SysDeptVo;
import com.ruoyi.modelMessage.domain.vo.SysRoleVo;
import com.ruoyi.modelMessage.domain.vo.SysUserVo;
import com.ruoyi.modelMessage.enums.SendMode; import com.ruoyi.modelMessage.enums.SendMode;
import com.ruoyi.modelMessage.mapper.MessageSystemMapper; import com.ruoyi.modelMessage.mapper.MessageSystemMapper;
import com.ruoyi.modelMessage.service.IMessageSystemService; import com.ruoyi.modelMessage.service.IMessageSystemService;
@ -116,31 +116,32 @@ public class MessageSystemServiceImpl implements IMessageSystemService {
// 查询系统资源用户信息 // 查询系统资源用户信息
@Override @Override
public List<SysUserVo> selectUser() { public List<SysUser> selectUser() {
return messageSystemMapper.selectUser(); return messageSystemMapper.selectUser();
} }
// 收件人为本人的话点击信息详情的时候然后把状态未读信息修改为已读 // 收件人为本人的话点击信息详情的时候然后把状态未读信息修改为已读
@Override @Override
public int updateState(Long messageId) { public int updateState(Long messageId) {
return messageSystemMapper.updateState(messageId, SecurityUtils.getUsername()); int result = messageSystemMapper.updateState(messageId, SecurityUtils.getUsername());
return result;
} }
// 根据发送方式过滤用户 (短信或邮箱) // 根据发送方式过滤用户 (短信或邮箱)
@Override @Override
public List<SysUserVo> getUsersFilteredBySendMode(String filterType) { public List<SysUser> getUsersFilteredBySendMode(String filterType) {
return messageSystemMapper.selectUserBySendMode(filterType); return messageSystemMapper.selectUserBySendMode(filterType);
} }
// 查询角色信息 然后根据角色把消息发给某角色 // 查询角色信息 然后根据角色把消息发给某角色
@Override @Override
public List<SysRoleVo> selectRole() { public List<SysRole> selectRole() {
return messageSystemMapper.selectRole(); return messageSystemMapper.selectRole();
} }
// 查询部门信息 然后根据部门把消息发给某部门 // 查询部门信息 然后根据部门把消息发给某部门
@Override @Override
public List<SysDeptVo> selectDept() { public List<SysDept> selectDept() {
return messageSystemMapper.selectDept(); return messageSystemMapper.selectDept();
} }
@ -151,8 +152,9 @@ public class MessageSystemServiceImpl implements IMessageSystemService {
* @return 符合条件的用户列表 * @return 符合条件的用户列表
*/ */
@Override @Override
public List<SysUserVo> selectUsersByRoleId(Long roleId) { public List<SysUser> selectUsersByRoleId(Long roleId) {
return messageSystemMapper.selectUsersByRoleId(roleId); List<SysUser> roleList = messageSystemMapper.selectUsersByRoleId(roleId);
return roleList;
} }
/** /**
@ -162,14 +164,16 @@ public class MessageSystemServiceImpl implements IMessageSystemService {
* @return 用户ID列表 * @return 用户ID列表
*/ */
@Override @Override
public List<SysUserVo> getUserNameByDeptId(Long deptId) { public List<SysUser> getUserNameByDeptId(Long deptId) {
return messageSystemMapper.getUserNameByDeptId(deptId); List<SysUser> depts= messageSystemMapper.getUserNameByDeptId(deptId);
return depts;
} }
// 查询模版签名 // 查询模版签名
@Override @Override
public List<MessageTemplate> selecTemplates() { public List<MessageTemplate> selecTemplates() {
return messageSystemMapper.selecTemplates(); List<MessageTemplate> templates= messageSystemMapper.selecTemplates();
return templates;
} }
/** /**
@ -186,7 +190,11 @@ public class MessageSystemServiceImpl implements IMessageSystemService {
messageSystem.setCreateTime(nowDate); messageSystem.setCreateTime(nowDate);
messageSystem.setUpdateTime(nowDate); messageSystem.setUpdateTime(nowDate);
} }
return messageSystemMapper.batchInsertMessageSystem(messageSystemList); int result = messageSystemMapper.batchInsertMessageSystem(messageSystemList);
if ( result <= 0) {
throw new ServiceException("消息发送失败!");
}
return result;
} }
/** /**
@ -227,7 +235,7 @@ public class MessageSystemServiceImpl implements IMessageSystemService {
try { try {
String filledMessage = notificationContent.startsWith("SMS_") ? String filledMessage = notificationContent.startsWith("SMS_") ?
messageSystemUtils.processTemplateMessage(messageSystem, notificationContent) : messageSystemUtils.processTemplateMessage(messageSystem, notificationContent) :
notificationContent; // 如果是自定义输入使用用户输入的内容 notificationContent; // 是自定义输入使用用户输入的内容
log.info("平台内容: {}", filledMessage); log.info("平台内容: {}", filledMessage);
messageSystem.setMessageContent(filledMessage); messageSystem.setMessageContent(filledMessage);
} catch (Exception e) { } catch (Exception e) {
@ -247,7 +255,7 @@ public class MessageSystemServiceImpl implements IMessageSystemService {
try { try {
String filledMessage = messageSystem.getMessageContent().startsWith("SMS_") ? String filledMessage = messageSystem.getMessageContent().startsWith("SMS_") ?
messageSystemUtils.processTemplateMessage(messageSystem, messageSystem.getMessageContent()) : messageSystemUtils.processTemplateMessage(messageSystem, messageSystem.getMessageContent()) :
messageSystem.getMessageContent(); // 如果是自定义输入则直接使用用户提供的内容 messageSystem.getMessageContent(); // 是自定义输入则直接使用用户提供的内容
log.info("邮件内容: {}", filledMessage); log.info("邮件内容: {}", filledMessage);
messageSystem.setMessageContent(filledMessage); messageSystem.setMessageContent(filledMessage);
EmailUtil.sendMessage(email, "通知", filledMessage); EmailUtil.sendMessage(email, "通知", filledMessage);
@ -260,6 +268,7 @@ public class MessageSystemServiceImpl implements IMessageSystemService {
/** /**
* 发送短信通知 * 发送短信通知
*/ */
@SuppressWarnings("unchecked")
public void sendNotificationMessage(MessageSystem messageSystem) { public void sendNotificationMessage(MessageSystem messageSystem) {
String phone = messageSystem.getCode(); String phone = messageSystem.getCode();
if (StringUtils.isEmpty(phone)) { if (StringUtils.isEmpty(phone)) {
@ -270,11 +279,12 @@ public class MessageSystemServiceImpl implements IMessageSystemService {
Map<String, Object> parsedParams = messageSystemUtils.parseInput(messageSystem.getMessageContent()); Map<String, Object> parsedParams = messageSystemUtils.parseInput(messageSystem.getMessageContent());
String templateCode = (String) parsedParams.get("templateCode"); String templateCode = (String) parsedParams.get("templateCode");
DySmsTemplate dySmsTemplate = null; DySmsTemplate dySmsTemplate = null;
if (templateCode != null) { if (templateCode != null) {
dySmsTemplate = DySmsTemplate.toEnum(templateCode); dySmsTemplate = DySmsTemplate.toEnum(templateCode);
@SuppressWarnings("unchecked")
Map<String, String> params = (Map<String, String>) parsedParams.get("params"); Map<String, String> params = (Map<String, String>) parsedParams.get("params");
// 提取模板中的变量名并填充内置变量
List<String> variableNames = (List<String>) parsedParams.get("variableNames");
messageSystemUtils.fillBuiltInVariables(params, messageSystem, variableNames);
String filledMessage = messageSystemUtils.fillTemplate((String) parsedParams.get("templateContent"), params); String filledMessage = messageSystemUtils.fillTemplate((String) parsedParams.get("templateContent"), params);
messageSystem.setMessageContent(filledMessage); messageSystem.setMessageContent(filledMessage);
JSONObject templateParamJson = new JSONObject(params); JSONObject templateParamJson = new JSONObject(params);
@ -287,5 +297,4 @@ public class MessageSystemServiceImpl implements IMessageSystemService {
throw new ServiceException("发送短信异常:" + e.getMessage()); throw new ServiceException("发送短信异常:" + e.getMessage());
} }
} }
} }

View File

@ -2,11 +2,10 @@ package com.ruoyi.modelMessage.service.impl;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.aliyun.oss.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.modelMessage.domain.MessageVariable; import com.ruoyi.modelMessage.domain.MessageVariable;
@ -22,7 +21,6 @@ import com.ruoyi.modelMessage.service.IMessageVariableService;
@Service @Service
public class MessageVariableServiceImpl implements IMessageVariableService public class MessageVariableServiceImpl implements IMessageVariableService
{ {
private static final int CODE_LENGTH = 6;
@Autowired @Autowired
private MessageVariableMapper messageVariableMapper; private MessageVariableMapper messageVariableMapper;
@ -90,6 +88,24 @@ public class MessageVariableServiceImpl implements IMessageVariableService
@Override @Override
public int deleteMessageVariableByVariableIds(Long[] variableIds) public int deleteMessageVariableByVariableIds(Long[] variableIds)
{ {
for (Long variableId : variableIds) {
// 获取变量信息
MessageVariable variable = messageVariableMapper.selectMessageVariableByVariableId(variableId);
if (variable == null) {
throw new ServiceException("未找到该变量信息!");
}
// 检查变量是否被模板使用
String variableName = variable.getVariableName();
List<String> variables = messageVariableMapper.selectAllTemplateVariables();
for (String templateVariable : variables) {
String[] templateParts = templateVariable.split("/");
for (String part : templateParts) {
if (part.equals(variableName)) {
throw new ServiceException("变量为 '" + variableName + "'' 已被模版使用,不能删除!");
}
}
}
}
return messageVariableMapper.deleteMessageVariableByVariableIds(variableIds); return messageVariableMapper.deleteMessageVariableByVariableIds(variableIds);
} }
@ -110,35 +126,4 @@ public class MessageVariableServiceImpl implements IMessageVariableService
public List<MessageVariable> selectMessageVariable() { public List<MessageVariable> selectMessageVariable() {
return messageVariableMapper.selectMessageVariable(); return messageVariableMapper.selectMessageVariable();
} }
//删除变量之前检查一下有没有模版使用
@Override
public boolean selectTemplateByVariableId(String templateVariable) {
return messageVariableMapper.selectTemplateByVariableId(templateVariable);
}
//根据类型生成不同的变量内容
@Override
public String generateVariableContent(String variableType) {
switch (variableType) {
case "time":
return DateUtils.dateTimeNow("HH:mm:ss");
case "date":
return DateUtils.dateTimeNow("yyyy-MM-dd");
case "datetime":
return DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss");
case "addresser":
return SecurityUtils.getUsername();
case "recipients":
return SecurityUtils.getUsername();
case "RandomnDigits":
return RandomStringUtils.randomNumeric(CODE_LENGTH);
case "RandomnCharacters":
return RandomStringUtils.randomAlphabetic(CODE_LENGTH);
case "RandomN-digitLetters":
return RandomStringUtils.randomAlphanumeric(CODE_LENGTH);
default:
throw new ServiceException("不明确的类型 " + variableType);
}
}
} }

View File

@ -10,7 +10,6 @@ import java.util.Random;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -26,7 +25,7 @@ import com.ruoyi.modelMessage.mapper.MessageVariableMapper;
@Component @Component
public class MessageSystemUtils { public class MessageSystemUtils {
private static final String NUMERIC_CHARACTERS = "0123456789"; private static final String NUMERIC_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static final int CODE_LENGTH = 6; private static final int CODE_LENGTH = 6;
@Autowired @Autowired
@ -79,7 +78,7 @@ public class MessageSystemUtils {
if (templateContent != null) { if (templateContent != null) {
for (String varName : variableNames) { for (String varName : variableNames) {
if (!params.containsKey(varName)) { if (!params.containsKey(varName)) {
params.put(varName, generateRandomCode(CODE_LENGTH)); params.put(varName, null); //默认先不传递 等自动填充值
} }
} }
} }
@ -88,23 +87,6 @@ public class MessageSystemUtils {
"variableNames", variableNames); "variableNames", variableNames);
} }
/**
* 生成指定长度的随机数字字符串
*
* @param length 长度
* @return 随机数字字符串
*/
public String generateRandomCode(int length) {
Random random = new Random();
StringBuilder codeBuilder = new StringBuilder(length);
for (int i = 0; i < length; i++) {
int index = random.nextInt(NUMERIC_CHARACTERS.length());
char randomChar = NUMERIC_CHARACTERS.charAt(index);
codeBuilder.append(randomChar);
}
return codeBuilder.toString();
}
/** /**
* 提取模板中的变量名 * 提取模板中的变量名
* *
@ -206,24 +188,37 @@ public class MessageSystemUtils {
public String generateVariableContent(String variableContent) { public String generateVariableContent(String variableContent) {
switch (variableContent) { switch (variableContent) {
case "time": case "time":
return DateUtils.dateTimeNow("HH:mm:ss"); return DateUtils.dateTimeNow("HH:mm:ss"); //发送时间
case "date": case "date":
return DateUtils.dateTimeNow("yyyy-MM-dd"); return DateUtils.dateTimeNow("yyyy-MM-dd"); //发送日期
case "datetime": case "datetime":
return DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"); return DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"); //发送日期+时间
case "addresser": case "addresser":
case "recipients": return SecurityUtils.getUsername(); //发件人
return SecurityUtils.getUsername();
case "code": case "code":
return generateRandomCode(CODE_LENGTH); // 确保这里生成随机验证码
case "RandomnDigits": case "RandomnDigits":
return RandomStringUtils.randomNumeric(CODE_LENGTH);
case "RandomnCharacters": case "RandomnCharacters":
return RandomStringUtils.randomAlphabetic(CODE_LENGTH);
case "RandomN-digitLetters": case "RandomN-digitLetters":
return RandomStringUtils.randomAlphanumeric(CODE_LENGTH); return generateRandomCode(CODE_LENGTH); //随机数字+英文
default: default:
throw new ServiceException("不明确的类型 " + variableContent); throw new ServiceException("不明确的类型 " + variableContent);
} }
} }
/**
* 生成指定长度的随机数字字符串 数字+英文
*
* @param length 长度
* @return 随机数字字符串
*/
public String generateRandomCode(int length) {
Random random = new Random();
StringBuilder codeBuilder = new StringBuilder(length);
for (int i = 0; i < length; i++) {
int index = random.nextInt(NUMERIC_CHARACTERS.length());
char randomChar = NUMERIC_CHARACTERS.charAt(index);
codeBuilder.append(randomChar);
}
return codeBuilder.toString();
}
} }

View File

@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 查询在使用模版签名时用到了那些变量一一赋值 --> <!-- 查询在使用模版签名时用到了那些变量一一赋值 -->
<select id="selectMessageVariables" parameterType="java.util.List" resultType="MessageVariable"> <select id="selectMessageVariables" parameterType="java.util.List" resultType="MessageVariable">
SELECT * FROM message_variable WHERE variable_content IN SELECT variable_id, variable_name, variable_type, variable_content FROM message_variable WHERE variable_content IN
<foreach item="item" index="index" collection="list" open="(" separator="," close=")"> <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item} #{item}
</foreach> </foreach>