请假流程发送通知功能完善

This commit is contained in:
s1431_z_w
2025-08-31 19:11:44 +08:00
parent a9623e3d27
commit 0ee08e39fa
13 changed files with 1020 additions and 13 deletions

View File

@@ -0,0 +1,84 @@
package com.srs.flowable.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.srs.common.core.domain.BaseEntity;
import lombok.*;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("srs_notification")
public class NotificationManage extends BaseEntity {
private static final long serialVersionUID=1L;
/**
* 通知ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 通知标题
*/
@TableField("title")
private String title;
/**
* 通知内容
*/
@TableField("content")
private String content;
/**
* 年级ID列表以逗号分隔
*/
@TableField("grade_ids")
private String gradeIds;
/**
* 年级名称
*/
@TableField("gradeName")
private String gradeName;
/**
* 发送人用户ID
*/
@TableField("sender")
private Long sender;
/**
* 接收人用户ID用于cph_msg表
*/
@TableField("receiver")
private Long receiver;
/**
* 创建者
*/
@TableField("create_by")
private String createBy;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" )
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新者
*/
@TableField("update_by")
private String updateBy;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" )
@TableField(fill = FieldFill.UPDATE)
private Date updateTime;
}

View File

@@ -0,0 +1,136 @@
package com.srs.flowable.listener;
import com.srs.common.doman.vo.TeacherVo;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import com.srs.flowable.mapper.LeaveMapper;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
/**
* 二级学院书记审批或学生销假开始监听器
*/
@Component
@Slf4j
public class BoStartListener implements ExecutionListener {
@Override
public void notify(DelegateExecution delegateExecution) {
LeaveMapper leaveMapper = (LeaveMapper) SpringUtils.getBean("leaveMapper");
String deptId = delegateExecution.getVariable("deptId").toString();
// 二级学院书记审批结果
String approval = delegateExecution.getVariable("approval").toString();
// 获取流程ID
String leaveApplicationId = delegateExecution.getVariable("leaveApplicationId").toString();
// 获取请假信息
StuLeaveApplication stuLeaveApplication = leaveMapper.selectRtStuLeaveApplicationByLeaveApplicationId(leaveApplicationId);
// 获取校领导信息
List<TeacherVo> lingDataInfo = leaveMapper.getLingDataInfo(185362L);
// 设置流程变量
//delegateExecution.setVariable("approval", secondaryLeaderInfo.getUserId());
// todo 企业微信推送消息(邵政文)
log.info("请假信息:{}", stuLeaveApplication);
try {
log.info("二级学院书记审批或学生销假开始监听器");
// 步骤 3: 检查是否成功获取到 userName
//向系统发送通知
NotificationManage notificationManage = new NotificationManage();
notificationManage.setContent("您有一条【学工领导已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setReceiver(lingDataInfo.get(0).getUserId());
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userManage != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManage.getId());
log.info("删除成功{}", delRes);
//向学工领导添加通知信息
// 获取二级学院书记信息
List<TeacherVo> secondaryLeaderInfo = leaveMapper.getSecondaryLeaderInfo(deptId);
//由于这里查到了多个数据,由于时间原因,暂时还没有研究到工作流中多用户节点的同时进行(所以取了第一条数据用于发消息)
notificationManage.setContent("您有一条【二级学院书记已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setSender(secondaryLeaderInfo.get(0).getUserId()); // 发送方
notificationManage.setReceiver(Long.parseLong(approval)); // 接收方
NotificationManage userManages = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userManages == null) {
notificationManage.setCreateTime(DateUtils.getNowDate());
int res = leaveMapper.insertCphMsg(notificationManage);
log.info("添加成功{}", res);
//向企业微信发消息
TeacherVo updateDeptId = leaveMapper.getUpdateDeptId(approval);
// 步骤 2: 使用updateDeptId.getUserName()获取辅导员工号
String userName = "2023429227";
// 获取向企业微信发通知的工具类
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 构造包含超链接的消息内容
String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
// 步骤 4: 使用 userName 作为接收人发送消息
//weChatUtil.sendTextMessage(userName, content);
log.info("已成功向学工领导(userName:{})发送企业微信请假审批通知。", userName);
}
return;
}
// 获取请假人id
Long stuId = (Long) delegateExecution.getVariable("stuId");
// 查询辅导员工信息
TeacherVo teacherInfo = leaveMapper.getCounselorInfo(stuId);
//查询请假人用户信息
TeacherVo shenUserInfo = leaveMapper.getShenUserInfo(stuId);
notificationManage.setContent("您有一条【请假人已提交销假审批】需待处理"); // 消息内容
notificationManage.setReceiver(teacherInfo.getUserId());
NotificationManage userManages = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userManages != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManages.getId());
log.info("删除成功{}", delRes);
//向请假人添加通知信息
//由于这里查到了多个数据,由于时间原因,暂时还没有研究到工作流中多用户节点的同时进行(所以取了第一条数据用于发消息)
notificationManage.setContent("您有一条【请假申请审批已通过】需待处理"); // 消息内容
notificationManage.setSender(teacherInfo.getUserId()); // 发送方
notificationManage.setReceiver(shenUserInfo.getUserId()); // 接收方
NotificationManage userMsge = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userMsge == null) {
notificationManage.setCreateTime(DateUtils.getNowDate());
int res = leaveMapper.insertCphMsg(notificationManage);
log.info("添加成功{}", res);
//向企业微信发消息
// 步骤 2: 使用shenUserInfo.getUserName()获取辅导员工号
String userName = "2023429227";
// 获取向企业微信发通知的工具类
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 构造包含超链接的消息内容
String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
// 步骤 4: 使用 userName 作为接收人发送消息
//weChatUtil.sendTextMessage(userName, content);
log.info("已成功向请假人(userName:{})发送企业微信请假审批通知。", userName);
}
}
} catch (Exception e) {
// 捕获所有异常,仅记录日志,确保主流程不受影响
log.error("发送通知或处理通知时出现异常。错误详情: {}", e.getMessage(), e);
}
}
}

View File

@@ -3,6 +3,7 @@ package com.srs.flowable.listener;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import com.srs.flowable.mapper.LeaveMapper;
import lombok.extern.slf4j.Slf4j;
@@ -28,7 +29,6 @@ public class CancellationListener implements ExecutionListener {
// 拿到流程所有参数
String approved = delegateExecution.getVariable("approved").toString();
// 请假单id
// 报错信息
String leaveApplicationId = delegateExecution.getVariable("leaveApplicationId").toString();
@@ -45,5 +45,27 @@ public class CancellationListener implements ExecutionListener {
stuLeaveApplication.setUpdateTime(DateUtils.getNowDate());
leaveMapper.updateRtStuLeaveApplication(stuLeaveApplication);
// 推送消息(邵政文)
//查询指定用户的通知信息并且删除
log.info("辅导员处理销假审批");
log.info("接收人为{}",approval);
NotificationManage notificationManage = new NotificationManage();
notificationManage.setContent("您有一条【请假人已提交销假审批】需待处理"); // 消息内容
notificationManage.setReceiver(Long.parseLong(approval)); // 接收人
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
int delRes;
if(userManage != null) {
//删除指定通知信息
delRes = leaveMapper.deleteCphMsgById(userManage.getId());
if(delRes > 0) {
log.info("删除成功{}", delRes);
} else {
log.info("删除失败成功,没有要删除的消息");
}
}
else {
log.info("没有查到通知消息,请核实是否发起了请假申请");
}
}
}

View File

@@ -3,7 +3,9 @@ package com.srs.flowable.listener;
import com.srs.common.doman.vo.TeacherVo;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import com.srs.flowable.mapper.LeaveMapper;
import lombok.extern.slf4j.Slf4j;
@@ -22,11 +24,17 @@ public class CounselorListener implements ExecutionListener {
public void notify(DelegateExecution delegateExecution) {
LeaveMapper leaveMapper = (LeaveMapper) SpringUtils.getBean("leaveMapper");
// 审批结果
String approval = delegateExecution.getVariable("approval").toString();
// 获取请假人id
Long stuId = (Long) delegateExecution.getVariable("stuId");
TeacherVo teacherInfo = leaveMapper.getCounselorInfo(stuId);
//查询请假人用户信息
TeacherVo shenUserInfo = leaveMapper.getShenUserInfo(stuId);
// 把辅导员的userId放到approval中
delegateExecution.setVariable("approval", teacherInfo.getUserId());
@@ -45,10 +53,57 @@ public class CounselorListener implements ExecutionListener {
leaveMapper.updateRtStuLeaveApplication(stuLeaveApplication);
// todo 企业微信推送消息
// todo 企业微信推送消息(邵政文)
log.info("向辅导员发送企业微信销假通知。");
try {
// 步骤 2: 获取辅导员工号teacherInfo.getUserName()
log.info("查询辅导员信息:{}", teacherInfo.getUserName());
log.info("请假人id{}", stuId);
//辅导员工号teacherInfo.getUserName()
String userName = "2023429227";
// 步骤 3: 检查是否成功获取到 userName
if (userName != null && !userName.isEmpty()) {
//查询指定用户的通知信息并且删除
NotificationManage notificationManage = new NotificationManage();
notificationManage.setContent("请假申请审批"); // 消息内容
notificationManage.setReceiver(shenUserInfo.getUserId()); // 接收人
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
//删除指定通知信息
if(userManage != null) {
int delRes = leaveMapper.deleteCphMsgById(userManage.getId());
log.info("删除成功{}", delRes);
}
log.info("查询辅导员信息:{}", teacherInfo);
//向系统发送通知
notificationManage.setContent("您有一条【请假人已提交销假审批】需待处理"); // 消息内容
notificationManage.setSender(shenUserInfo.getUserId());
notificationManage.setReceiver(teacherInfo.getUserId());
NotificationManage userManages = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userManages == null) {
notificationManage.setCreateTime(DateUtils.getNowDate());
int res = leaveMapper.insertCphMsg(notificationManage);
log.info("添加成功{}", res);
}
// 获取向企业微信发通知的工具类
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 构造包含超链接的消息内容
String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
// 步骤 4: 使用 userName 作为接收人发送消息
//weChatUtil.sendTextMessage(userName, content);
log.info("已成功向辅导员(userName:{})发送企业微信销假通知。", userName);
} else {
// 如果找不到userName记录警告日志但流程继续
log.warn("没有找到对应审批人,无法发送通知。");
}
} catch (Exception e) {
// 捕获所有异常,仅记录日志,确保主流程不受影响
log.error("发送通知或处理通知时出现异常。错误详情: {}", e.getMessage(), e);
}
}
}

View File

@@ -1,17 +1,23 @@
package com.srs.flowable.listener;
import com.srs.common.doman.vo.TeacherVo;
import com.srs.common.enums.ApplicationStatus;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import com.srs.flowable.mapper.LeaveMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hpsf.Decimal;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
/**
* 领导审核
@@ -21,6 +27,7 @@ import java.math.BigDecimal;
@Slf4j
public class LeadAuditListener implements ExecutionListener {
@Override
public void notify(DelegateExecution delegateExecution) {
LeaveMapper leaveMapper = (LeaveMapper) SpringUtils.getBean("leaveMapper");
@@ -36,6 +43,8 @@ public class LeadAuditListener implements ExecutionListener {
// 获取请假天数
BigDecimal leaveDays = (BigDecimal) delegateExecution.getVariable("leaveDays");
// 获取请假人id
Long stuId = (Long) delegateExecution.getVariable("stuId");
// 请假单id
// 报错信息
@@ -43,6 +52,9 @@ public class LeadAuditListener implements ExecutionListener {
log.info("审批结果为:", approval);
//查询请假人用户信息
TeacherVo shenUserInfo = leaveMapper.getShenUserInfo(stuId);
StuLeaveApplication stuLeaveApplication = leaveMapper.selectRtStuLeaveApplicationByLeaveApplicationId(leaveApplicationId);
if (stuLeaveApplication != null) {
@@ -59,5 +71,91 @@ public class LeadAuditListener implements ExecutionListener {
leaveMapper.updateRtStuLeaveApplication(stuLeaveApplication);
log.info("审核成功");
//企业微信推送消息(邵政文)
try {
log.info("请假人");
log.info("请假人数据为:{}", stuLeaveApplication);
log.info("审批结果为:{}", approval);
// 步骤 2: 发送消息的接收人stuLeaveApplication.getCreateBy()
String userName = "2023429227";
// 步骤 3: 检查是否成功获取到 userName
if (userName != null && !userName.isEmpty()) {
//构建通知信息
NotificationManage notificationManage = new NotificationManage();
// 判断请假天数
int leaveDay = leaveDays.intValue();
// 向系统发送通知
if(leaveDay >= 4 && leaveDay <= 7) {
//查询指定用户的通知信息
notificationManage.setContent("您有一条【辅导员已提交请假审批】需待处理"); // 消息内容
notificationManage.setReceiver(Long.parseLong(approval)); //接收人
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if(userManage != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManage.getId());
log.info("删除成功{}", delRes);
}
//构建通知信息内容
notificationManage.setContent("您有一条【二级学院书记已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setSender(Long.parseLong(approval)); // 发送方
}
if(leaveDay >= 8 && leaveDay <= 14) {
//查询指定用户的通知信息
notificationManage.setContent("您有一条【二级学院书记已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setReceiver(Long.parseLong("185043")); //接收人需添加appvoval
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if(userManage != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManage.getId());
log.info("删除成功{}", delRes);
}
//构建通知信息内容
notificationManage.setContent("您有一条【学工领导已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setSender(Long.parseLong(approval)); // 发送方
}
if(leaveDay >= 15 && leaveDay <= 30) {
notificationManage.setContent("您有一条【学工领导已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setReceiver(185362L); //接收人
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if(userManage != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManage.getId());
log.info("删除成功{}", delRes);
}
//构建通知信息内容
notificationManage.setContent("您有一条【学院领导已提交请假申请审批】待处理"); // 消息内容
notificationManage.setSender(185362L); // 发送方
}
notificationManage.setReceiver(shenUserInfo.getUserId());
notificationManage.setCreateTime(DateUtils.getNowDate());
int res = leaveMapper.insertCphMsg(notificationManage);
log.info("添加成功{}", res);
//获取向企业微信发通知的工具类
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 构造包含超链接的消息内容
String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
// 步骤 4: 使用 userName 作为接收人发送消息
//weChatUtil.sendTextMessage(userName, content);
log.info("已成功向辅导员(userName:{})发送企业微信销假通知。", userName);
log.info("已成功向送企业微信销假通知。{}", stuLeaveApplication.getStuId());
} else {
// 如果找不到userName记录警告日志但流程继续
log.warn("没有找到对应审批人,无法发送通知。");
}
} catch (Exception e) {
// 捕获所有异常,仅记录日志,确保主流程不受影响
log.error("发送通知或处理通知时出现异常。错误详情: {}", e.getMessage(), e);
}
}
}

View File

@@ -0,0 +1,124 @@
package com.srs.flowable.listener;
import com.srs.common.doman.vo.TeacherVo;
import com.srs.common.enums.ApplicationStatus;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import com.srs.flowable.mapper.LeaveMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hpsf.Decimal;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
/**
* 领导审核
*/
@Component
@Slf4j
public class LeadEentListener implements ExecutionListener {
@Override
public void notify(DelegateExecution delegateExecution) {
LeaveMapper leaveMapper = (LeaveMapper) SpringUtils.getBean("leaveMapper");
log.info("任务流相关数据", delegateExecution);
// 学工审批结果
String approval = delegateExecution.getVariable("approval").toString();
// 拿到流程所有参数
String approved = delegateExecution.getVariable("approved").toString();
// 获取请假天数
BigDecimal leaveDays = (BigDecimal) delegateExecution.getVariable("leaveDays");
// 请假单id
// 报错信息
String leaveApplicationId = delegateExecution.getVariable("leaveApplicationId").toString();
log.info("审批结果为:", approval);
StuLeaveApplication stuLeaveApplication = leaveMapper.selectRtStuLeaveApplicationByLeaveApplicationId(leaveApplicationId);
// 获取校领导信息
//TeacherVo updateDeptId = leaveMapper.getUpdateDeptId(SecurityUtils.getUserId().toString());
List<TeacherVo> lingDataInfo = leaveMapper.getLingDataInfo(185362L);
if (stuLeaveApplication != null) {
// 同意
if ("true".equals(approved)) {
stuLeaveApplication.setStatus(ApplicationStatus.APPROVED.getCode());
}
}
stuLeaveApplication.setUpdateBy(SecurityUtils.getUsername());
stuLeaveApplication.setUpdateTime(DateUtils.getNowDate());
leaveMapper.updateRtStuLeaveApplication(stuLeaveApplication);
log.info("审核成功");
//企业微信推送消息(邵政文)
try {
log.info("学工审批结果");
log.info("请假人数据为:{}", stuLeaveApplication);
log.info("审批结果为:{}", approval);
log.info("校领导信息为:{}", lingDataInfo);
// 步骤 2: 使用lingDataInfo.get(0).getUserId()向校领导发送信息
String userName = "2023429227";
// 步骤 3: 检查是否成功获取到 userName
if (userName != null && !userName.isEmpty()) {
//查询指定用户的通知信息并且删除
NotificationManage notificationManage = new NotificationManage();
notificationManage.setContent("您有一条【二级学院书记已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setReceiver(Long.parseLong(approval));
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if(userManage != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManage.getId());
log.info("删除成功{}", delRes);
}
//向系统发送通知
notificationManage.setContent("您有一条【学工领导已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setSender(Long.parseLong(approval)); // 发送人
notificationManage.setReceiver(lingDataInfo.get(0).getUserId()); // 接收人
NotificationManage userManages = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userManages == null) {
notificationManage.setCreateTime(DateUtils.getNowDate());
int res = leaveMapper.insertCphMsg(notificationManage);
log.info("添加成功{}", res);
}
//获取向企业微信发通知的工具类
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 构造包含超链接的消息内容
String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
// 步骤 4: 使用 userName 作为接收人发送消息
//weChatUtil.sendTextMessage(userName, content);
log.info("已成功向辅导员(userName:{})发送企业微信销假通知。", userName);
log.info("已成功向送企业微信销假通知。{}", stuLeaveApplication.getStuId());
} else {
// 如果找不到userName记录警告日志但流程继续
log.warn("没有找到对应审批人,无法发送通知。");
}
} catch (Exception e) {
// 捕获所有异常,仅记录日志,确保主流程不受影响
log.error("发送通知或处理通知时出现异常。错误详情: {}", e.getMessage(), e);
}
}
}

View File

@@ -0,0 +1,100 @@
package com.srs.flowable.listener;
import com.srs.common.doman.vo.TeacherVo;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import com.srs.flowable.mapper.LeaveMapper;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
/**
* 获取该二级学院书记所在的学工信息
*/
@Component
@Slf4j
public class LeadStartListener implements ExecutionListener {
@Override
public void notify(DelegateExecution delegateExecution) {
LeaveMapper leaveMapper = (LeaveMapper) SpringUtils.getBean("leaveMapper");
// 二级学院书记审批结果
String approval = delegateExecution.getVariable("approval").toString();
// 获取请假天数
BigDecimal leaveDays = (BigDecimal) delegateExecution.getVariable("leaveDays");
// 获取流程ID
String leaveApplicationId = delegateExecution.getVariable("leaveApplicationId").toString();
// 获取请假信息
StuLeaveApplication stuLeaveApplication = leaveMapper.selectRtStuLeaveApplicationByLeaveApplicationId(leaveApplicationId);
// 获取学工信息
//TeacherVo updateDeptId = leaveMapper.getUpdateDeptId(approval);
List<TeacherVo> updateDeptIdInfo = leaveMapper.getUpdateDeptIdInfo(1045L);
// 设置流程变量
delegateExecution.setVariable("approval", updateDeptIdInfo.get(0).getUserId());
// todo 企业微信推送消息(邵政文)
log.info("请假信息:{}", stuLeaveApplication);
log.info("辅导员信息:{}", updateDeptIdInfo);
try {
log.info("学工收到二级学院书记发送过来的通知");
// 步骤 2: 使用updateDeptIdInfo.get(0).getUserId()获取学工工号
String userName = "2023429227";
// 步骤 3: 检查是否成功获取到 userName
if (userName != null && !userName.isEmpty()) {
//查询指定用户的通知信息
NotificationManage notificationManage = new NotificationManage();
notificationManage.setContent("您有一条【辅导员已提交请假审批】需待处理"); // 消息内容
notificationManage.setReceiver(Long.parseLong(approval));
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if(userManage != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManage.getId());
log.info("删除成功{}", delRes);
}
//向系统发送通知
notificationManage.setContent("您有一条【二级学院书记已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setSender(Long.parseLong(approval)); // 发送方
notificationManage.setReceiver(updateDeptIdInfo.get(0).getUserId()); // 接收方
NotificationManage userManages = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userManages == null) {
notificationManage.setCreateTime(DateUtils.getNowDate());
int res = leaveMapper.insertCphMsg(notificationManage);
log.info("添加成功{}", res);
}
// 获取向企业微信发通知的工具类
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 构造包含超链接的消息内容
String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
// 步骤 4: 使用 userName 作为接收人发送消息
//weChatUtil.sendTextMessage(userName, content);
log.info("已成功向辅导员(userName:{})发送企业微信请假审批通知。", userName);
log.info("已成功向送企业微信审批通知。{}", updateDeptIdInfo.get(0).getUserName());
} else {
// 如果找不到userName记录警告日志但流程继续
log.warn("没有找到对应审批人,无法发送通知。");
}
} catch (Exception e) {
// 捕获所有异常,仅记录日志,确保主流程不受影响
log.error("发送通知或处理通知时出现异常。错误详情: {}", e.getMessage(), e);
}
}
}

View File

@@ -3,14 +3,14 @@ package com.srs.flowable.listener;
import com.srs.common.enums.ApplicationStatus;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import com.srs.flowable.mapper.LeaveMapper;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
@@ -38,7 +38,6 @@ public class LeaveApproveListener implements ExecutionListener {
// 获取请假天数
BigDecimal leaveDays = (BigDecimal) delegateExecution.getVariable("leaveDays");
// 请假单id
// 报错信息
String leaveApplicationId = delegateExecution.getVariable("leaveApplicationId").toString();
@@ -66,6 +65,61 @@ public class LeaveApproveListener implements ExecutionListener {
log.info("审核成功");
//todo 推送消息,推送给辅导员,目的要拿到辅导员工号
//企业微信推送消息(邵政文)
try {
log.info("向请假人发送销假消息");
log.info("请假消息。{}", stuLeaveApplication);
log.info("创建人。{}", stuLeaveApplication.getCreateBy());
log.info("修改人。{}", stuLeaveApplication.getUpdateBy());
log.info("辅导员审批结果。{}", approval);
log.info("流程所有参数。{}", approved);
// 判断请假天数
int leaveDay = leaveDays.intValue();
if(leaveDay >= 1 && leaveDay <= 3) {
// 步骤 2: 使用stuLeaveApplication.getCreateBy()向请假人发送销假消息
String userName = "2023429227";
// 步骤 3: 检查是否成功获取到 userName
if (userName != null && !userName.isEmpty()) {
//查询指定用户的通知信息
NotificationManage notificationManage = new NotificationManage();
notificationManage.setContent("您有一条【请假人提交的请假申请】需待处理"); // 消息内容
notificationManage.setReceiver(Long.parseLong(approval));
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if(userManage != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManage.getId());
log.info("删除成功{}", delRes);
}
//向系统发送通知
notificationManage.setContent("您有一条【辅导员已提交请假审批】需待处理"); // 消息内容
notificationManage.setSender(Long.parseLong(approval)); // 发送人
notificationManage.setReceiver(stuLeaveApplication.getStuId()); // 接收人
notificationManage.setCreateTime(DateUtils.getNowDate());
int res = leaveMapper.insertCphMsg(notificationManage);
log.info("添加成功{}", res);
// 获取向企业微信发通知的工具类
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 构造包含超链接的消息内容
String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
// 步骤 4: 使用 userName 作为接收人发送消息
//weChatUtil.sendTextMessage(userName, content); // 发送消息的方法
log.info("已成功向请假人({})发送企业微信销假通知。", userName);
log.info("发件人id。{}", stuLeaveApplication.getStuId());
} else {
// 如果找不到userName记录警告日志但流程继续
log.warn("没有找到对应审批人,无法发送通知。");
}
}
} catch (Exception e) {
// 捕获所有异常,仅记录日志,确保主流程不受影响
log.error("发送通知或处理通知时出现异常。错误详情: {}", e.getMessage(), e);
}
}
}

View File

@@ -0,0 +1,100 @@
package com.srs.flowable.listener;
import com.srs.common.doman.vo.TeacherVo;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import com.srs.flowable.mapper.LeaveMapper;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
/**
* 获取该生所在辅导员信息
*/
@Component
@Slf4j
public class LeaveStartApproveListener implements ExecutionListener {
@Override
public void notify(DelegateExecution delegateExecution) {
LeaveMapper leaveMapper = (LeaveMapper) SpringUtils.getBean("leaveMapper");
String deptId = delegateExecution.getVariable("deptId").toString();
// 获取请假天数
BigDecimal leaveDays = (BigDecimal) delegateExecution.getVariable("leaveDays");
// 辅导员审批结果
String approval = delegateExecution.getVariable("approval").toString();
// 获取流程ID
String leaveApplicationId = delegateExecution.getVariable("leaveApplicationId").toString();
// 获取请假信息
StuLeaveApplication stuLeaveApplication = leaveMapper.selectRtStuLeaveApplicationByLeaveApplicationId(leaveApplicationId);
// 获取辅导员
TeacherVo secondaryLeaderInfo = leaveMapper.getCounselorInfo(stuLeaveApplication.getStuId());
// 设置流程变量
delegateExecution.setVariable("approval", secondaryLeaderInfo.getUserId());
// todo 企业微信推送消息(邵政文)
log.info("请假信息:{}", stuLeaveApplication);
log.info("辅导员信息:{}", secondaryLeaderInfo);
try {
log.info("辅导员收到请假人发送过来的通知");
// 步骤 2: 使用secondaryLeaderInfo.getUserName()获取辅导员工号
String userName = "2023429227";
// 步骤 3: 检查是否成功获取到 userName
if (userName != null && !userName.isEmpty()) {
//向系统发送通知
NotificationManage notificationManage = new NotificationManage();
notificationManage.setContent("您有一条【请假人提交的请假申请】需待处理"); // 消息内容
notificationManage.setSender(stuLeaveApplication.getStuId());
notificationManage.setReceiver(secondaryLeaderInfo.getUserId());
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userManage == null) {
notificationManage.setCreateTime(DateUtils.getNowDate());
int res = leaveMapper.insertCphMsg(notificationManage);
log.info("添加成功{}", res);
}
//新添地方
notificationManage.setContent("您有一条【辅导员已提交请假审批】需待处理"); // 消息内容
notificationManage.setReceiver(Long.parseLong(approval));
NotificationManage userManages = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userManages != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManages.getId());
log.info("删除成功{}", delRes);
}
// 获取向企业微信发通知的工具类
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 构造包含超链接的消息内容
String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
// 步骤 4: 使用 userName 作为接收人发送消息
//weChatUtil.sendTextMessage(userName, content);
log.info("已成功向辅导员(userName:{})发送企业微信请假审批通知。", userName);
log.info("已成功向送企业微信审批通知。{}", secondaryLeaderInfo.getUserName());
log.info("请假人id{}", stuLeaveApplication.getStuId());
} else {
// 如果找不到userName记录警告日志但流程继续
log.warn("没有找到对应审批人,无法发送通知。");
}
} catch (Exception e) {
// 捕获所有异常,仅记录日志,确保主流程不受影响
log.error("发送通知或处理通知时出现异常。错误详情: {}", e.getMessage(), e);
}
}
}

View File

@@ -1,7 +1,11 @@
package com.srs.flowable.listener;
import com.srs.common.doman.vo.TeacherVo;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import com.srs.flowable.mapper.LeaveMapper;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
@@ -10,6 +14,9 @@ import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
/**
* 获取该生所在二级学院领导信息
*/
@@ -23,10 +30,107 @@ public class SecondaryLeaderListener implements ExecutionListener {
String deptId = delegateExecution.getVariable("deptId").toString();
// 辅导员审批结果
String approval = delegateExecution.getVariable("approval").toString();
// 获取请假天数
BigDecimal leaveDays = (BigDecimal) delegateExecution.getVariable("leaveDays");
// 获取高辅导员
TeacherVo secondaryLeaderInfo = leaveMapper.getSecondaryLeaderInfo(deptId);
delegateExecution.setVariable("approval", secondaryLeaderInfo.getUserId());
// todo 企业微信推送消息
//TeacherVo secondaryLeaderInfo = leaveMapper.getSecondaryLeaderInfo(deptId);
//delegateExecution.setVariable("approval", secondaryLeaderInfo.getUserId());
List<TeacherVo> secondaryLeaderInfo = leaveMapper.getSecondaryLeaderInfo(deptId);
//由于这里查到了多个数据,由于时间原因,暂时还没有研究到工作流中多用户节点的同时进行(所以取了第一条数据用于发消息)
delegateExecution.setVariable("approval", secondaryLeaderInfo.get(0).getUserId());
// 获取请假申请ID
String leaveApplicationId = delegateExecution.getVariable("leaveApplicationId").toString();
// 获取请假信息
StuLeaveApplication stuLeaveApplication = leaveMapper.selectRtStuLeaveApplicationByLeaveApplicationId(leaveApplicationId);
// todo 企业微信推送消息(邵政文)
log.info("查询二级学院书记信息:{}", secondaryLeaderInfo);
try {
//int leaveDay = leaveDays.intValue();
// 步骤 2: 使用secondaryLeaderInfo.get(0).getUserName()获取二级学院书记工号
String userName = "2023429227";
// 步骤 3: 检查是否成功获取到 userName
if (userName != null && !userName.isEmpty()) {
//查询指定用户的通知信息
NotificationManage notificationManage = new NotificationManage();
notificationManage.setContent("您有一条【请假人提交的请假申请】需待处理"); // 消息内容
notificationManage.setReceiver(Long.parseLong(approval)); //接收人
NotificationManage userManage = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if(userManage != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userManage.getId());
log.info("删除成功{}", delRes);
}
//向多人发消息的逻辑如下:
// notificationManage.setSender(Long.parseLong(approval)); // 发送人
// notificationManage.setCreateTime(DateUtils.getNowDate()); // 创建时间
// for(TeacherVo teacherVo : secondaryLeaderInfo) {
// //向系统发送通知
// notificationManage.setContent("您有一条【辅导员已提交请假审批】需待处理"); // 消息内容
// notificationManage.setReceiver(teacherVo.getUserId()); // 接收人
// NotificationManage userManages = leaveMapper.selectCphMsgListForFlowable(notificationManage);
// if (userManages == null) {
// int res = leaveMapper.insertCphMsg(notificationManage);
// log.info("添加成功{}", res);
// }
//
// // 获取向企业微信发通知的工具类
// WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
//
// // 构造包含超链接的消息内容
// String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
//
// // 步骤 4: 使用 userName 作为接收人发送消息
// //weChatUtil.sendTextMessage(userName, content);
// log.info("已成功向二级学院书记(userName:{})发送企业微信请假审批通知。", userName);
// log.info("已成功向送企业微信审批通知。{}", teacherVo.getUserId());
// }
//向系统发送通知
notificationManage.setContent("您有一条【辅导员已提交请假审批】需待处理"); // 消息内容
notificationManage.setSender(Long.parseLong(approval)); // 发送人
notificationManage.setReceiver(secondaryLeaderInfo.get(0).getUserId()); // 接收人
NotificationManage userManages = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userManages == null) {
notificationManage.setCreateTime(DateUtils.getNowDate());
int res = leaveMapper.insertCphMsg(notificationManage);
log.info("添加成功{}", res);
}
//新添地方
notificationManage.setContent("您有一条【二级学院书记已提交请假申请审批】需待处理"); // 消息内容
notificationManage.setReceiver(Long.parseLong(approval)); // 接收人
NotificationManage userMsge = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (userMsge != null) {
//删除指定通知信息
int delRes = leaveMapper.deleteCphMsgById(userMsge.getId());
log.info("删除成功{}", delRes);
}
// 获取向企业微信发通知的工具类
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 构造包含超链接的消息内容
String content = "您有待处理任务,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>";
// 步骤 4: 使用 userName 作为接收人发送消息
//weChatUtil.sendTextMessage(userName, content);
log.info("已成功向二级学院书记(userName:{})发送企业微信请假审批通知。", userName);
log.info("已成功向此人{}送企业微信审批通知。", secondaryLeaderInfo.get(0).getUserName());
} else {
// 如果找不到userName记录警告日志但流程继续
log.warn("没有找到对应审批人,无法发送通知。");
}
} catch (Exception e) {
// 捕获所有异常,仅记录日志,确保主流程不受影响
log.error("发送企业微信通知时出现异常。错误详情: {}", e.getMessage(), e);
}
}
}

View File

@@ -2,8 +2,11 @@ package com.srs.flowable.mapper;
import com.srs.common.doman.vo.TeacherVo;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.domain.StuLeaveApplication;
import java.util.List;
/**
* 考勤mapper
*/
@@ -22,7 +25,8 @@ public interface LeaveMapper {
* @param deptId
* @return
*/
TeacherVo getSecondaryLeaderInfo(String deptId);
//TeacherVo getSecondaryLeaderInfo(String deptId);
List<TeacherVo> getSecondaryLeaderInfo(String deptId);
/**
* 查询学生请假申请
@@ -40,4 +44,62 @@ public interface LeaveMapper {
*/
int updateRtStuLeaveApplication(StuLeaveApplication rtStuLeaveApplication);
/**
* 新增消息
* @param notificationManage 消息
* @return 结果
* 邵政文
*/
int insertCphMsg(NotificationManage notificationManage);
/**
* 查询指定发送人所对应的消息
* @param notificationManage 消息
* @return 结果
* 邵政文
*/
NotificationManage selectCphMsgListForFlowable(NotificationManage notificationManage);
/**
* 根据id删除指定通知
*
* @param id
* @return 结果
* 邵政文
*/
int deleteCphMsgById(Long id);
/**
* 根据审批人工号查询部门id
*
* @param userId 审批人id
* @return 结果
* 邵政文
*/
TeacherVo getUpdateDeptId(String userId);
/**
* 获取学工信息
* @param deptId
* @return
* 邵政文
*/
List<TeacherVo> getUpdateDeptIdInfo(Long deptId);
/**
* 获取校领导信息
* @param userId
* @return
* 邵政文
*/
List<TeacherVo> getLingDataInfo(Long userId);
/**
* 获取请假申请人信息
* @param stuId
* @return
* 邵政文
*/
TeacherVo getShenUserInfo(Long stuId);
}