feat: 待办消息发送及删除

new
chenqp 1 year ago
parent da163dddb7
commit aee06975df

@ -91,6 +91,8 @@ public class ExpenseApplyServiceImpl extends MPJBaseServiceImpl<ExpenseApplyMapp
if (expenseApply.getStatus().equals(ExpenseApplyStatusEnum.PROCESS.getValue())) {
Map<String, Object> variables = new HashMap<>();
variables.put("billType", expenseApply.getBillType());
variables.put("billId", expenseApply.getId());
variables.put("billName", BillTypeEnum.getNameByValue(expenseApply.getBillType()));
variables.put("amount", expenseApply.getAmount());
variables.put("deptId", expenseApply.getDeptId());
String processInstanceId = processInstanceApi.createProcessInstance(expenseApply.getUserId(),

@ -104,6 +104,8 @@ public class ExpenseClaimServiceImpl extends MPJBaseServiceImpl<ExpenseClaimMapp
if (expenseClaim.getStatus().equals(ExpenseApplyStatusEnum.PROCESS.getValue())) {
Map<String, Object> variables = new HashMap<>();
variables.put("billType", expenseClaim.getBillType());
variables.put("billId", expenseClaim.getId());
variables.put("billName", BillTypeEnum.getNameByValue(expenseClaim.getBillType()));
variables.put("amount", expenseClaim.getAmount());
variables.put("deptId", expenseClaim.getDeptId());
String processInstanceId = processInstanceApi.createProcessInstance(expenseClaim.getUserId(),

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenProcess
import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO;
import javax.validation.Valid;
import java.util.Map;
/**
* BPM Service
@ -26,8 +27,9 @@ public interface BpmMessageService {
*
*
* @param reqDTO
* @param variables
*/
void sendMessageWhenProcessInstanceReject(@Valid BpmMessageSendWhenProcessInstanceRejectReqDTO reqDTO);
void sendMessageWhenProcessInstanceReject(@Valid BpmMessageSendWhenProcessInstanceRejectReqDTO reqDTO, Map<String, Object> variables);
/**
*

@ -1,18 +1,19 @@
package cn.iocoder.yudao.module.bpm.service.message;
import cn.iocoder.yudao.framework.web.config.WebProperties;
import cn.iocoder.yudao.module.bpm.convert.message.BpmMessageConvert;
import cn.iocoder.yudao.module.bpm.enums.message.BpmMessageEnum;
import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenProcessInstanceApproveReqDTO;
import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenProcessInstanceRejectReqDTO;
import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO;
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
import cn.iocoder.yudao.module.system.api.sms.SmsSendApi;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.RuntimeService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/**
@ -30,9 +31,15 @@ public class BpmMessageServiceImpl implements BpmMessageService {
@Resource
private WebProperties webProperties;
@Resource
@Lazy
private NotifyMessageSendApi notifyMessageSendApi;
@Resource
@Lazy
private RuntimeService runtimeService;
@Override
public void sendMessageWhenProcessInstanceApprove(BpmMessageSendWhenProcessInstanceApproveReqDTO reqDTO) {
sendNotifyMessage(reqDTO.getProcessInstanceId(), reqDTO.getStartUserId(), "_PASS", null);
// Map<String, Object> templateParams = new HashMap<>();
// templateParams.put("processInstanceName", reqDTO.getProcessInstanceName());
// templateParams.put("detailUrl", getProcessInstanceDetailUrl(reqDTO.getProcessInstanceId()));
@ -41,7 +48,8 @@ public class BpmMessageServiceImpl implements BpmMessageService {
}
@Override
public void sendMessageWhenProcessInstanceReject(BpmMessageSendWhenProcessInstanceRejectReqDTO reqDTO) {
public void sendMessageWhenProcessInstanceReject(BpmMessageSendWhenProcessInstanceRejectReqDTO reqDTO, Map<String, Object> variables) {
sendNotifyMessage(reqDTO.getProcessInstanceId(), reqDTO.getStartUserId(), "_NOPASS",variables);
// Map<String, Object> templateParams = new HashMap<>();
// templateParams.put("processInstanceName", reqDTO.getProcessInstanceName());
// templateParams.put("reason", reqDTO.getReason());
@ -52,6 +60,7 @@ public class BpmMessageServiceImpl implements BpmMessageService {
@Override
public void sendMessageWhenTaskAssigned(BpmMessageSendWhenTaskCreatedReqDTO reqDTO) {
sendNotifyMessage(reqDTO.getProcessInstanceId(), reqDTO.getStartUserId(), "_UNDEAL", null);
// Map<String, Object> templateParams = new HashMap<>();
// templateParams.put("processInstanceName", reqDTO.getProcessInstanceName());
// templateParams.put("taskName", reqDTO.getTaskName());
@ -61,6 +70,23 @@ public class BpmMessageServiceImpl implements BpmMessageService {
// BpmMessageEnum.TASK_ASSIGNED.getSmsTemplateCode(), templateParams));
}
private void sendNotifyMessage(String reqDTO, Long reqDTO1, String type, Map<String, Object> variables) {
if (variables == null) {
variables = runtimeService.getVariables(reqDTO);
}
if (variables.containsKey("billType")) {
String billType = variables.get("billType").toString();
NotifySendSingleToUserReqDTO notifyReq = new NotifySendSingleToUserReqDTO();
notifyReq.setUserId(reqDTO1);
notifyReq.setTemplateCode(billType+ type);
notifyReq.setTemplateParams(variables);
notifyReq.setBillType(billType);
notifyReq.setExtraData(variables);
notifyReq.setJumpFlag("1");
notifyMessageSendApi.sendSingleMessageToAdmin(notifyReq);
}
}
private String getProcessInstanceDetailUrl(String taskId) {
return webProperties.getAdminUi().getUrl() + "/bpm/process-instance/detail?id=" + taskId;
}

@ -31,5 +31,12 @@ public enum BillTypeEnum {
*/
private final String name;
public static String getNameByValue(String targetValue) {
for (BillTypeEnum billTypeEnum : BillTypeEnum.values()) {
if (billTypeEnum.getValue().equals(targetValue)) {
return billTypeEnum.getName();
}
}
return null;
}
}

@ -30,4 +30,18 @@ public class NotifySendSingleToUserReqDTO {
*
*/
private Map<String, Object> templateParams;
/**
*
*/
private String billType;
/**
* ,ID
*/
private Map<String, Object> extraData;
/**
*
*/
private String jumpFlag = "0";
}

@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.system.api.notify;
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService;
import cn.iocoder.yudao.module.system.service.notify.NotifySendService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
/**
* API
@ -21,7 +21,7 @@ public class NotifyMessageSendApiImpl implements NotifyMessageSendApi {
@Override
public Long sendSingleMessageToAdmin(NotifySendSingleToUserReqDTO reqDTO) {
return notifySendService.sendSingleNotifyToAdmin(reqDTO.getUserId(),
reqDTO.getTemplateCode(), reqDTO.getTemplateParams());
reqDTO.getTemplateCode(), reqDTO.getTemplateParams(), reqDTO.getBillType(), reqDTO.getExtraData(), reqDTO.getJumpFlag());
}
@Override

@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 站内信模版")
@ -77,7 +79,7 @@ public class NotifyTemplateController {
@PreAuthorize("@ss.hasPermission('system:notify-template:send-notify')")
public CommonResult<Long> sendNotify(@Valid @RequestBody NotifyTemplateSendReqVO sendReqVO) {
return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(),
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams(), null, new HashMap<String, Object>(), "0"));
}
}

@ -57,4 +57,20 @@ public class NotifyMessageBaseVO {
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime readTime;
/**
*
*/
private String billType;
/**
* ID
*/
private Long billId;
/**
* ,ID
*/
private Map<String, Object> extraData;
/**
*
*/
private String jumpFlag;
}

@ -97,5 +97,30 @@ public class NotifyMessageDO extends BaseDO {
*
*/
private LocalDateTime readTime;
/**
*
*/
private LocalDateTime startTime;
/**
*
*/
private LocalDateTime endTime;
/**
*
*/
private String billType;
/**
* ID
*/
private Long billId;
/**
* ,ID
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private Map<String, Object> extraData;
/**
*
*/
private String jumpFlag;
}

@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -25,10 +26,13 @@ public interface NotifyMessageService {
* @param template
* @param templateContent
* @param templateParams
* @param billType
* @param extraData
* @param jumpFlag
* @return
*/
Long createNotifyMessage(Long userId, Integer userType,
NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams);
NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams, String billType, Map<String, Object> extraData, String jumpFlag);
/**
*

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.system.service.notify;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageMyPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
@ -11,6 +13,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -30,12 +33,24 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
@Override
public Long createNotifyMessage(Long userId, Integer userType,
NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams) {
NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams, String billType, Map<String, Object> extraData, String jumpFlag) {
NotifyMessageDO message = new NotifyMessageDO().setUserId(userId).setUserType(userType)
.setTemplateId(template.getId()).setTemplateCode(template.getCode())
.setTemplateType(template.getType()).setTemplateNickname(template.getNickname())
.setTemplateContent(templateContent).setTemplateParams(templateParams).setReadStatus(false);
.setTemplateContent(templateContent).setTemplateParams(templateParams).setReadStatus(false).setBillType(billType).setExtraData(extraData).setJumpFlag(jumpFlag);
if (extraData.containsKey("billId")) {
message.setBillId(Long.valueOf(extraData.get("billId").toString()));
}
notifyMessageMapper.insert(message);
if (billType != null && (template.getCode().contains("_PASS") || template.getCode().contains("_NOPASS"))) {
//如果同意和驳回需要将先前的待办删除
if (extraData.containsKey("billId")) {
LambdaQueryWrapperX<NotifyMessageDO> queryWrapperX = new LambdaQueryWrapperX<>();
queryWrapperX.eqIfPresent(NotifyMessageDO::getBillId, Long.valueOf(extraData.get("billId").toString()));
queryWrapperX.eqIfPresent(NotifyMessageDO::getTemplateCode, billType + "_UNDEAL");
notifyMessageMapper.delete(queryWrapperX);
}
}
return message.getId();
}

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.service.notify;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -18,10 +19,13 @@ public interface NotifySendService {
* @param userId
* @param templateCode
* @param templateParams
* @param billType
* @param extraData
* @param jumpFlag
* @return
*/
Long sendSingleNotifyToAdmin(Long userId,
String templateCode, Map<String, Object> templateParams);
String templateCode, Map<String, Object> templateParams, String billType, Map<String, Object> extraData, String jumpFlag);
/**
* APP
*
@ -42,10 +46,13 @@ public interface NotifySendService {
* @param userType
* @param templateCode
* @param templateParams
* @param billType
* @param extraData
* @param jumpFlag
* @return
*/
Long sendSingleNotify(Long userId, Integer userType,
String templateCode, Map<String, Object> templateParams);
String templateCode, Map<String, Object> templateParams, String billType, Map<String, Object> extraData, String jumpFlag);
default void sendBatchNotify(List<String> mobiles, List<Long> userIds, Integer userType,
String templateCode, Map<String, Object> templateParams) {

@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@ -32,17 +33,16 @@ public class NotifySendServiceImpl implements NotifySendService {
private NotifyMessageService notifyMessageService;
@Override
public Long sendSingleNotifyToAdmin(Long userId, String templateCode, Map<String, Object> templateParams) {
return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams);
public Long sendSingleNotifyToAdmin(Long userId, String templateCode, Map<String, Object> templateParams, String billType, Map<String, Object> extraData, String jumpFlag) {
return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams, billType, extraData, jumpFlag);
}
@Override
public Long sendSingleNotifyToMember(Long userId, String templateCode, Map<String, Object> templateParams) {
return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams);
return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams, null, new HashMap<String, Object>(), "0");
}
@Override
public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map<String, Object> templateParams) {
public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map<String, Object> templateParams, String billType, Map<String, Object> extraData, String jumpFlag) {
// 校验模版
NotifyTemplateDO template = validateNotifyTemplate(templateCode);
if (Objects.equals(template.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
@ -54,7 +54,7 @@ public class NotifySendServiceImpl implements NotifySendService {
// 发送站内信
String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams);
return notifyMessageService.createNotifyMessage(userId, userType, template, content, templateParams);
return notifyMessageService.createNotifyMessage(userId, userType, template, content, templateParams, billType, extraData, jumpFlag);
}
@VisibleForTesting

@ -15,10 +15,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import static cn.hutool.core.util.RandomUtil.randomEle;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
@ -54,7 +51,7 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest {
// 调用
Long messageId = notifyMessageService.createNotifyMessage(userId, userType,
template, templateContent, templateParams);
template, templateContent, templateParams, "xx", new HashMap<String, Object>(), "xxx");
// 断言
NotifyMessageDO message = notifyMessageMapper.selectById(messageId);
assertNotNull(message);

@ -53,10 +53,10 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest {
// mock NotifyMessageService 的方法
Long messageId = randomLongId();
when(notifyMessageService.createNotifyMessage(eq(userId), eq(UserTypeEnum.ADMIN.getValue()),
eq(template), eq(content), eq(templateParams))).thenReturn(messageId);
eq(template), eq(content), eq(templateParams), "xx", new HashMap<String, Object>(), "xxx")).thenReturn(messageId);
// 调用
Long resultMessageId = notifySendService.sendSingleNotifyToAdmin(userId, templateCode, templateParams);
Long resultMessageId = notifySendService.sendSingleNotifyToAdmin(userId, templateCode, templateParams, null, new HashMap<String, Object>(), "0");
// 断言
assertEquals(messageId, resultMessageId);
}
@ -81,7 +81,7 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest {
// mock NotifyMessageService 的方法
Long messageId = randomLongId();
when(notifyMessageService.createNotifyMessage(eq(userId), eq(UserTypeEnum.MEMBER.getValue()),
eq(template), eq(content), eq(templateParams))).thenReturn(messageId);
eq(template), eq(content), eq(templateParams), "xx", new HashMap<String, Object>(), "xxx")).thenReturn(messageId);
// 调用
Long resultMessageId = notifySendService.sendSingleNotifyToMember(userId, templateCode, templateParams);
@ -113,10 +113,10 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest {
// mock NotifyMessageService 的方法
Long messageId = randomLongId();
when(notifyMessageService.createNotifyMessage(eq(userId), eq(userType),
eq(template), eq(content), eq(templateParams))).thenReturn(messageId);
eq(template), eq(content), eq(templateParams), "xx", new HashMap<String, Object>(), "xxx")).thenReturn(messageId);
// 调用
Long resultMessageId = notifySendService.sendSingleNotify(userId, userType, templateCode, templateParams);
Long resultMessageId = notifySendService.sendSingleNotify(userId, userType, templateCode, templateParams, "xx", new HashMap<String, Object>(), "xxx");
// 断言
assertEquals(messageId, resultMessageId);
}
@ -141,11 +141,11 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest {
when(notifyTemplateService.getNotifyTemplateByCodeFromCache(eq(templateCode))).thenReturn(template);
// 调用
Long resultMessageId = notifySendService.sendSingleNotify(userId, userType, templateCode, templateParams);
Long resultMessageId = notifySendService.sendSingleNotify(userId, userType, templateCode, templateParams, "xx", new HashMap<String, Object>(), "xxx");
// 断言
assertNull(resultMessageId);
verify(notifyTemplateService, never()).formatNotifyTemplateContent(anyString(), anyMap());
verify(notifyMessageService, never()).createNotifyMessage(anyLong(), anyInt(), any(), anyString(), anyMap());
verify(notifyMessageService, never()).createNotifyMessage(anyLong(), anyInt(), any(), anyString(), anyMap(), "xx", new HashMap<String, Object>(), "xxx");
}
@Test

Loading…
Cancel
Save