From 02fe56d0abcc0909c2c03fe1aecd0e69cac304fe Mon Sep 17 00:00:00 2001 From: ldrop Date: Mon, 13 Jan 2025 16:12:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MessageSystemController.java | 65 +++--- .../controller/MessageVariableController.java | 31 +-- .../modelMessage/domain/vo/SysDeptVo.java | 220 ------------------ .../modelMessage/domain/vo/SysRoleVo.java | 55 ----- .../modelMessage/domain/vo/SysUserVo.java | 96 -------- .../mapper/MessageSystemMapper.java | 32 +-- .../mapper/MessageTemplateMapper.java | 2 +- .../mapper/MessageVariableMapper.java | 10 +- .../service/IMessageSystemService.java | 18 +- .../service/IMessageVariableService.java | 10 +- .../impl/MessageSystemServiceImpl.java | 47 ++-- .../impl/MessageVariableServiceImpl.java | 55 ++--- .../utils/MessageSystemUtils.java | 53 ++--- .../modelMessage/MessageVariableMapper.xml | 2 +- 14 files changed, 141 insertions(+), 555 deletions(-) delete mode 100644 ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysDeptVo.java delete mode 100644 ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysRoleVo.java delete mode 100644 ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysUserVo.java diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/controller/MessageSystemController.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/controller/MessageSystemController.java index 63f2819..9d9a9bf 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/controller/MessageSystemController.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/controller/MessageSystemController.java @@ -5,7 +5,6 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; 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.GetMapping; 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.core.controller.BaseController; 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.enums.BusinessType; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.poi.ExcelUtil; 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 io.swagger.v3.oas.annotations.Operation; @@ -97,6 +95,7 @@ public class MessageSystemController extends BaseController public AjaxResult edit(@RequestBody MessageSystem messageSystem) { messageSystem.setUpdateBy(getUsername()); + messageSystem.setUpdateTime(DateUtils.getNowDate()); return toAjax(messageSystemService.updateMessageSystem(messageSystem)); } @@ -121,32 +120,21 @@ public class MessageSystemController extends BaseController @Transactional public AjaxResult batchAdd(@RequestBody List messageSystemList) { try { - for (MessageSystem message : messageSystemList) { - messageSystemService.processMessageSystem(message); - } - if (messageSystemService.batchInsertMessageSystem(messageSystemList) <= 0) { - throw new ServiceException("消息发送失败!"); - } + messageSystemList.forEach(messageSystemService::processMessageSystem); + messageSystemService.batchInsertMessageSystem(messageSystemList); return AjaxResult.success("消息发送成功!"); } catch (Exception e) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - return AjaxResult.error("消息发送失败!", e); + return AjaxResult.error("消息发送失败", e); } } /** - * 用户点击标题之后已读信息 + * 用户点击标题调整信息状态 */ @Operation(summary = "用户点击标题调整信息状态") @PostMapping("/{messageId}") public AjaxResult update(@PathVariable Long messageId){ - try{ - int state= messageSystemService.updateState(messageId); - return success(state); - }catch(Exception e){ - e.printStackTrace(); - return error(); - } + return success(messageSystemService.updateState(messageId)); } /** @@ -156,15 +144,17 @@ public class MessageSystemController extends BaseController @GetMapping("/selectUser") public AjaxResult selectUser(@RequestParam(required = false) String sendMode) { try { - List list; - if ("1".equals(sendMode)) { // 手机号 - list = messageSystemService.getUsersFilteredBySendMode("phone"); - } else if ("2".equals(sendMode)) { // 邮箱 - list = messageSystemService.getUsersFilteredBySendMode("email"); - } else { - list = messageSystemService.selectUser(); + // 非空检查并提供默认值 + if (sendMode == null || sendMode.trim().isEmpty()) { + sendMode = "default"; + } + List list; + switch (sendMode) { + case "1": list = messageSystemService.getUsersFilteredBySendMode("phone"); break; // 短信 + case "2": list = messageSystemService.getUsersFilteredBySendMode("email"); break;// 邮件 + default: list = messageSystemService.selectUser(); break; //默认查询全部的用户 } - return AjaxResult.success(list); + return success(list); } catch (ServiceException e) { return AjaxResult.error(e.getMessage()); } @@ -194,11 +184,10 @@ public class MessageSystemController extends BaseController * @param roleId 角色ID * @return 用户信息列表 */ - @Operation(summary = "根据角色ID获取所有符合条件的用户信息") + @Operation(summary = "根据角色Id查询所有符合条件的用户信息") @GetMapping("/getUsersByRole/{roleId}") - public R> selectUsersByRoleId(@PathVariable Long roleId) { - List users = messageSystemService.selectUsersByRoleId(roleId); - return R.ok(users); + public AjaxResult selectUsersByRoleId(@PathVariable Long roleId) { + return success(messageSystemService.selectUsersByRoleId(roleId)); } /** @@ -207,11 +196,10 @@ public class MessageSystemController extends BaseController * @param deptId 部门ID * @return 用户信息列表 */ - @Operation(summary = "根据部门ID获取所有符合条件的用户信息") + @Operation(summary = "根据部门Id查询所有符合条件的用户信息") @GetMapping("/getUserNameByDeptId/{deptId}") - public R> getUserNameByDeptId(@PathVariable Long deptId) { - List depts= messageSystemService.getUserNameByDeptId(deptId); - return R.ok(depts); + public AjaxResult getUserNameByDeptId(@PathVariable Long deptId) { + return success(messageSystemService.getUserNameByDeptId(deptId)); } /** @@ -220,8 +208,7 @@ public class MessageSystemController extends BaseController */ @Operation(summary = "查询模版签名") @GetMapping("/selecTemplates") - public R selecTemplates() { - List templates= messageSystemService.selecTemplates(); - return R.ok(templates); + public AjaxResult selecTemplates() { + return success(messageSystemService.selecTemplates()); } } diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/controller/MessageVariableController.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/controller/MessageVariableController.java index e240fa6..a9f715a 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/controller/MessageVariableController.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/controller/MessageVariableController.java @@ -14,16 +14,15 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.modelMessage.domain.MessageVariable; 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.tags.Tag; @@ -43,6 +42,9 @@ public class MessageVariableController extends BaseController @Autowired private IMessageVariableService messageVariableService; + @Autowired + private MessageSystemUtils messageVariableUtils; + /** * 查询变量管理列表 */ @@ -114,26 +116,14 @@ public class MessageVariableController extends BaseController @DeleteMapping("/{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)); } /** - * 查询角色信息 + * 查询变量 */ @Operation(summary = "查询变量") @GetMapping("/selectMessageVariable") - @Anonymous public AjaxResult selectMessageVariable() { return success(messageVariableService.selectMessageVariable()); } @@ -141,14 +131,9 @@ public class MessageVariableController extends BaseController /** * 根据变量类型生成不同的变量内容 */ - @Operation(summary = "根据变量类型生成不同变量内容") + @Operation(summary = "根据内置变量生成不同内容") @GetMapping("/generate") - public AjaxResult generateVariableContent(@RequestParam String variableType) { - try { - Object content = messageVariableService.generateVariableContent(variableType); - return AjaxResult.success(content); - } catch (Exception e) { - return AjaxResult.error("生成变量内容失败!"); - } + public AjaxResult generateVariableContent(@RequestParam String variableContent) { + return success(messageVariableUtils.generateVariableContent(variableContent)); } } diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysDeptVo.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysDeptVo.java deleted file mode 100644 index d583bee..0000000 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysDeptVo.java +++ /dev/null @@ -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 children = new ArrayList(); - - 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 getChildren() - { - return children; - } - - public void setChildren(List 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(); - } -} diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysRoleVo.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysRoleVo.java deleted file mode 100644 index 2d0112c..0000000 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysRoleVo.java +++ /dev/null @@ -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(); - } -} diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysUserVo.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysUserVo.java deleted file mode 100644 index 377abe1..0000000 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/domain/vo/SysUserVo.java +++ /dev/null @@ -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(); - } -} diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageSystemMapper.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageSystemMapper.java index 0b8a196..cee9bf7 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageSystemMapper.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageSystemMapper.java @@ -5,11 +5,11 @@ import java.util.List; import org.apache.ibatis.annotations.Select; 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.MessageTemplate; -import com.ruoyi.modelMessage.domain.vo.SysDeptVo; -import com.ruoyi.modelMessage.domain.vo.SysRoleVo; -import com.ruoyi.modelMessage.domain.vo.SysUserVo; /** * 消息管理Mapper接口 @@ -68,26 +68,26 @@ public interface MessageSystemMapper public int deleteMessageSystemByMessageIds(Long[] messageIds); //查询平台系统资源收件人用户信息 - @Select("SELECT * FROM `sys_user`") - public List selectUser(); + @Select("SELECT user_id, dept_id, user_name, phonenumber, email FROM `sys_user`") + public List selectUser(); //查询角色信息 然后根据角色把消息发给某角色 - @Select("SELECT * FROM `sys_role`") - public List selectRole(); + @Select("SELECT role_id, role_name FROM `sys_role`") + public List selectRole(); //查询部门信息 然后根据部门把消息发给某部门 - @Select("SELECT * FROM `sys_dept`") - public List selectDept(); + @Select("SELECT dept_id, parent_id, dept_name FROM `sys_dept`") + public List selectDept(); // 根据发送方式过滤用户 (短信或邮箱) @Select("") - List selectUserBySendMode(String filterType); + List selectUserBySendMode(String filterType); //将信息状态未读信息变为已读 @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 * @return 用户信息列表 */ - @Select("SELECT u.* FROM sys_user u JOIN sys_dept d ON u.dept_id = d.dept_id WHERE d.dept_id = #{deptId}") - public List getUserNameByDeptId(Long roleId); + @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 getUserNameByDeptId(Long deptId); /** * 根据角色ID查询用户列表。 @@ -109,11 +109,11 @@ public interface MessageSystemMapper * @param roleId 角色ID * @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}") - public List selectUsersByRoleId(Long 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 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 selecTemplates(); //批量发送信息 diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageTemplateMapper.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageTemplateMapper.java index d1a25f4..31092e9 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageTemplateMapper.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageTemplateMapper.java @@ -68,6 +68,6 @@ public interface MessageTemplateMapper * @param templateCode 模版编码 * @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); } diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageVariableMapper.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageVariableMapper.java index 30fe358..8d3cf24 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageVariableMapper.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/mapper/MessageVariableMapper.java @@ -62,14 +62,14 @@ public interface MessageVariableMapper */ 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 selectMessageVariable(); //查询在使用模版签名时用到了那些变量一一赋值 public List selectMessageVariables(List variableNames); + + //查询模版使用的变量 + @Select("SELECT template_variable FROM message_template") + public List selectAllTemplateVariables(); } diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/IMessageSystemService.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/IMessageSystemService.java index 5b0a694..94763e3 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/IMessageSystemService.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/IMessageSystemService.java @@ -2,11 +2,11 @@ package com.ruoyi.modelMessage.service; 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.MessageTemplate; -import com.ruoyi.modelMessage.domain.vo.SysDeptVo; -import com.ruoyi.modelMessage.domain.vo.SysRoleVo; -import com.ruoyi.modelMessage.domain.vo.SysUserVo; /** * 消息管理Service接口 @@ -65,7 +65,7 @@ public interface IMessageSystemService public int deleteMessageSystemByMessageId(Long messageId); //查询系统资源用户信息 - public List selectUser(); + public List selectUser(); //将信息状态未读信息变为已读 public int updateState(Long messageId); @@ -74,13 +74,13 @@ public interface IMessageSystemService public void processMessageSystem(MessageSystem messageSystem); // 根据发送方式过滤用户 (短信或邮箱) - public List getUsersFilteredBySendMode(String filterType); + public List getUsersFilteredBySendMode(String filterType); //查询角色信息 然后根据角色把消息发给某角色 - public List selectRole(); + public List selectRole(); //查询部门信息 然后根据部门把消息发给某部门 - public List selectDept(); + public List selectDept(); /** * 根据角色ID获取用户列表。 @@ -89,7 +89,7 @@ public interface IMessageSystemService * @return * * */ - public List selectUsersByRoleId(Long roleId); + public List selectUsersByRoleId(Long roleId); /** * 根据部门ID获取用户列表。 @@ -98,7 +98,7 @@ public interface IMessageSystemService * @return * * */ - public List getUserNameByDeptId(Long deptId); + public List getUserNameByDeptId(Long deptId); // 查询模版签名 public List selecTemplates(); diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/IMessageVariableService.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/IMessageVariableService.java index 201aa91..1075bca 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/IMessageVariableService.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/IMessageVariableService.java @@ -60,12 +60,8 @@ public interface IMessageVariableService */ public int deleteMessageVariableByVariableId(Long variableId); - // 查询全部变量 + /** + * 查询全部变量 + */ public List selectMessageVariable(); - - // 删除变量之前检查一下有没有模版使用 - public boolean selectTemplateByVariableId(String templateVariable); - - // 根据类型生成不同的变量内容 - public String generateVariableContent(String variableType); } diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/impl/MessageSystemServiceImpl.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/impl/MessageSystemServiceImpl.java index 5bb0f79..0d2fea5 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/impl/MessageSystemServiceImpl.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/impl/MessageSystemServiceImpl.java @@ -10,15 +10,15 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; 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.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.modelMessage.domain.MessageSystem; 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.mapper.MessageSystemMapper; import com.ruoyi.modelMessage.service.IMessageSystemService; @@ -116,31 +116,32 @@ public class MessageSystemServiceImpl implements IMessageSystemService { // 查询系统资源用户信息 @Override - public List selectUser() { + public List selectUser() { return messageSystemMapper.selectUser(); } // 收件人为本人的话点击信息详情的时候然后把状态未读信息修改为已读 @Override public int updateState(Long messageId) { - return messageSystemMapper.updateState(messageId, SecurityUtils.getUsername()); + int result = messageSystemMapper.updateState(messageId, SecurityUtils.getUsername()); + return result; } // 根据发送方式过滤用户 (短信或邮箱) @Override - public List getUsersFilteredBySendMode(String filterType) { + public List getUsersFilteredBySendMode(String filterType) { return messageSystemMapper.selectUserBySendMode(filterType); } // 查询角色信息 然后根据角色把消息发给某角色 @Override - public List selectRole() { + public List selectRole() { return messageSystemMapper.selectRole(); } // 查询部门信息 然后根据部门把消息发给某部门 @Override - public List selectDept() { + public List selectDept() { return messageSystemMapper.selectDept(); } @@ -151,8 +152,9 @@ public class MessageSystemServiceImpl implements IMessageSystemService { * @return 符合条件的用户列表 */ @Override - public List selectUsersByRoleId(Long roleId) { - return messageSystemMapper.selectUsersByRoleId(roleId); + public List selectUsersByRoleId(Long roleId) { + List roleList = messageSystemMapper.selectUsersByRoleId(roleId); + return roleList; } /** @@ -162,14 +164,16 @@ public class MessageSystemServiceImpl implements IMessageSystemService { * @return 用户ID列表 */ @Override - public List getUserNameByDeptId(Long deptId) { - return messageSystemMapper.getUserNameByDeptId(deptId); + public List getUserNameByDeptId(Long deptId) { + List depts= messageSystemMapper.getUserNameByDeptId(deptId); + return depts; } // 查询模版签名 @Override public List selecTemplates() { - return messageSystemMapper.selecTemplates(); + List templates= messageSystemMapper.selecTemplates(); + return templates; } /** @@ -186,7 +190,11 @@ public class MessageSystemServiceImpl implements IMessageSystemService { messageSystem.setCreateTime(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 { String filledMessage = notificationContent.startsWith("SMS_") ? messageSystemUtils.processTemplateMessage(messageSystem, notificationContent) : - notificationContent; // 如果是自定义输入,使用用户输入的内容 + notificationContent; // 是自定义输入,使用用户输入的内容 log.info("平台内容: {}", filledMessage); messageSystem.setMessageContent(filledMessage); } catch (Exception e) { @@ -247,7 +255,7 @@ public class MessageSystemServiceImpl implements IMessageSystemService { try { String filledMessage = messageSystem.getMessageContent().startsWith("SMS_") ? messageSystemUtils.processTemplateMessage(messageSystem, messageSystem.getMessageContent()) : - messageSystem.getMessageContent(); // 如果是自定义输入,则直接使用用户提供的内容 + messageSystem.getMessageContent(); // 是自定义输入,则直接使用用户提供的内容 log.info("邮件内容: {}", filledMessage); messageSystem.setMessageContent(filledMessage); EmailUtil.sendMessage(email, "通知", filledMessage); @@ -260,6 +268,7 @@ public class MessageSystemServiceImpl implements IMessageSystemService { /** * 发送短信通知 */ + @SuppressWarnings("unchecked") public void sendNotificationMessage(MessageSystem messageSystem) { String phone = messageSystem.getCode(); if (StringUtils.isEmpty(phone)) { @@ -270,11 +279,12 @@ public class MessageSystemServiceImpl implements IMessageSystemService { Map parsedParams = messageSystemUtils.parseInput(messageSystem.getMessageContent()); String templateCode = (String) parsedParams.get("templateCode"); DySmsTemplate dySmsTemplate = null; - if (templateCode != null) { dySmsTemplate = DySmsTemplate.toEnum(templateCode); - @SuppressWarnings("unchecked") Map params = (Map) parsedParams.get("params"); + // 提取模板中的变量名并填充内置变量 + List variableNames = (List) parsedParams.get("variableNames"); + messageSystemUtils.fillBuiltInVariables(params, messageSystem, variableNames); String filledMessage = messageSystemUtils.fillTemplate((String) parsedParams.get("templateContent"), params); messageSystem.setMessageContent(filledMessage); JSONObject templateParamJson = new JSONObject(params); @@ -287,5 +297,4 @@ public class MessageSystemServiceImpl implements IMessageSystemService { throw new ServiceException("发送短信异常:" + e.getMessage()); } } - } diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/impl/MessageVariableServiceImpl.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/impl/MessageVariableServiceImpl.java index dc64b31..0cb87ba 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/impl/MessageVariableServiceImpl.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/service/impl/MessageVariableServiceImpl.java @@ -2,11 +2,10 @@ package com.ruoyi.modelMessage.service.impl; import java.util.List; -import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; 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.SecurityUtils; import com.ruoyi.modelMessage.domain.MessageVariable; @@ -22,7 +21,6 @@ import com.ruoyi.modelMessage.service.IMessageVariableService; @Service public class MessageVariableServiceImpl implements IMessageVariableService { - private static final int CODE_LENGTH = 6; @Autowired private MessageVariableMapper messageVariableMapper; @@ -90,6 +88,24 @@ public class MessageVariableServiceImpl implements IMessageVariableService @Override 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 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); } @@ -105,40 +121,9 @@ public class MessageVariableServiceImpl implements IMessageVariableService return messageVariableMapper.deleteMessageVariableByVariableId(variableId); } - //查询变量 + //查询变量 @Override public List 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); - } - } } diff --git a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/utils/MessageSystemUtils.java b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/utils/MessageSystemUtils.java index 00cde67..325c56f 100644 --- a/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/utils/MessageSystemUtils.java +++ b/ruoyi-models/ruoyi-message/src/main/java/com/ruoyi/modelMessage/utils/MessageSystemUtils.java @@ -10,7 +10,6 @@ import java.util.Random; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -26,7 +25,7 @@ import com.ruoyi.modelMessage.mapper.MessageVariableMapper; @Component public class MessageSystemUtils { - private static final String NUMERIC_CHARACTERS = "0123456789"; + private static final String NUMERIC_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; private static final int CODE_LENGTH = 6; @Autowired @@ -79,7 +78,7 @@ public class MessageSystemUtils { if (templateContent != null) { for (String varName : variableNames) { if (!params.containsKey(varName)) { - params.put(varName, generateRandomCode(CODE_LENGTH)); + params.put(varName, null); //默认先不传递 等自动填充值 } } } @@ -88,23 +87,6 @@ public class MessageSystemUtils { "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) { switch (variableContent) { case "time": - return DateUtils.dateTimeNow("HH:mm:ss"); + return DateUtils.dateTimeNow("HH:mm:ss"); //发送时间 case "date": - return DateUtils.dateTimeNow("yyyy-MM-dd"); + return DateUtils.dateTimeNow("yyyy-MM-dd"); //发送日期 case "datetime": - return DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"); + return DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"); //发送日期+时间 case "addresser": - case "recipients": - return SecurityUtils.getUsername(); + return SecurityUtils.getUsername(); //发件人 case "code": - return generateRandomCode(CODE_LENGTH); // 确保这里生成随机验证码 case "RandomnDigits": - return RandomStringUtils.randomNumeric(CODE_LENGTH); case "RandomnCharacters": - return RandomStringUtils.randomAlphabetic(CODE_LENGTH); case "RandomN-digitLetters": - return RandomStringUtils.randomAlphanumeric(CODE_LENGTH); + return generateRandomCode(CODE_LENGTH); //随机数字+英文 default: 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(); + } } diff --git a/ruoyi-models/ruoyi-message/src/main/resources/mapper/modelMessage/MessageVariableMapper.xml b/ruoyi-models/ruoyi-message/src/main/resources/mapper/modelMessage/MessageVariableMapper.xml index cea9959..ce95684 100644 --- a/ruoyi-models/ruoyi-message/src/main/resources/mapper/modelMessage/MessageVariableMapper.xml +++ b/ruoyi-models/ruoyi-message/src/main/resources/mapper/modelMessage/MessageVariableMapper.xml @@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"