Commit d5be870a authored by yzc's avatar yzc

feat: 新增发送系统自定义消息内部接口

parent 65f21964
package com.ssy.lingxi.message.api.constant;
/**
* 消息标题
* @author yzc
* @version 2.0.0
* @date 2021/7/23
*/
public interface MessageTitle {
String confirm_demand_quotation = "确认报价";
}
......@@ -3,6 +3,7 @@ package com.ssy.lingxi.message.api.fallback;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.message.api.feign.SystemMessageControllerFeign;
import com.ssy.lingxi.message.api.vo.request.SystemMessageCustomRequest;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import org.springframework.stereotype.Component;
......@@ -12,12 +13,17 @@ import java.util.List;
public class SystemMessageControllerFeignFallback implements SystemMessageControllerFeign {
@Override
public Wrapper sendSystemMessage(SystemMessageRequest request) {
public Wrapper<Void> sendSystemMessage(SystemMessageRequest request) {
return Wrapper.fail(ResponseCode.SERVICE_MESSAGE_ERROR);
}
@Override
public Wrapper batchSendSystemMessage(List<SystemMessageRequest> request) {
public Wrapper<Void> batchSendSystemMessage(List<SystemMessageRequest> request) {
return Wrapper.fail(ResponseCode.SERVICE_MESSAGE_ERROR);
}
@Override
public Wrapper<Void> sendCustomMessage(SystemMessageCustomRequest request) {
return Wrapper.fail(ResponseCode.SERVICE_MESSAGE_ERROR);
}
}
package com.ssy.lingxi.message.api.feign;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.message.api.vo.request.SystemMessageCustomRequest;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -20,18 +21,26 @@ public interface SystemMessageControllerFeign {
/**
* 发送系统消息
* @param request
* @return
* @param request 接口参数
* @return 返回结果
*/
@PostMapping("/message/systemMessage/feign/send")
Wrapper sendSystemMessage(@RequestBody SystemMessageRequest request);
Wrapper<Void> sendSystemMessage(@RequestBody SystemMessageRequest request);
/**
* 发送系统消息(批量)
* @param request
* @return
* @param request 接口参数
* @return 返回结果
*/
@PostMapping("/message/systemMessage/feign/batchSend")
Wrapper batchSendSystemMessage(@RequestBody List<SystemMessageRequest> request);
Wrapper<Void> batchSendSystemMessage(@RequestBody List<SystemMessageRequest> request);
/**
* 发送系统消息
* @param request 接口参数
* @return 返回结果
*/
@PostMapping("/message/systemMessage/feign/custom")
Wrapper<Void> sendCustomMessage(@RequestBody SystemMessageCustomRequest request);
}
package com.ssy.lingxi.message.api.vo.request;
import java.io.Serializable;
/**
* 系统自定义消息
* @author yzc
* @version 2.0.0
* @date 2020/11/30
*/
public class SystemMessageCustomRequest implements Serializable {
private static final long serialVersionUID = 6965770140466930623L;
/**
* 接收会员id
*/
private Long memberId;
/**
* 接收角色id
*/
private Long roleId;
/**
* 接收用户id
*/
private Long userId;
/**
* 消息标题
*/
private String title;
/**
* 消息内容
*/
private String content;
public Long getMemberId() {
return memberId;
}
public void setMemberId(Long memberId) {
this.memberId = memberId;
}
public Long getRoleId() {
return roleId;
}
public void setRoleId(Long roleId) {
this.roleId = roleId;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
......@@ -2,6 +2,7 @@ package com.ssy.lingxi.message.controller.inner;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.message.api.vo.request.SystemMessageCustomRequest;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import com.ssy.lingxi.message.service.IMemberMessageService;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -46,4 +47,15 @@ public class SystemMessageController extends BaseController {
messageService.batchSendSystemMessage(request);
return Wrapper.success();
}
/**
* 发送系统消息
* @param request
* @return
*/
@PostMapping("/custom")
Wrapper sendCustomMessage(@RequestBody SystemMessageCustomRequest request) {
messageService.sendCustomMessage(request);
return Wrapper.success();
}
}
......@@ -7,6 +7,7 @@ import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.message.api.vo.request.MessageIdRequest;
import com.ssy.lingxi.message.api.vo.request.MessageIdsRequest;
import com.ssy.lingxi.message.api.vo.request.SystemMessageCustomRequest;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import com.ssy.lingxi.message.api.vo.response.MessageResponse;
......@@ -92,5 +93,11 @@ public interface IMemberMessageService {
* @param request 请求参数
*/
void batchSendSystemMessage(List<SystemMessageRequest> request);
/**
* 发送系统消息
* @param request 请求参数
*/
void sendCustomMessage(SystemMessageCustomRequest request);
}
......@@ -9,6 +9,7 @@ import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.message.api.vo.request.MessageIdRequest;
import com.ssy.lingxi.message.api.vo.request.MessageIdsRequest;
import com.ssy.lingxi.message.api.vo.request.SystemMessageCustomRequest;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import com.ssy.lingxi.message.api.vo.response.MessageResponse;
import com.ssy.lingxi.message.constant.MessageConstants;
......@@ -289,7 +290,7 @@ public class MemberMessageServiceImpl implements IMemberMessageService {
// 推送未读消息数
memberMessageList.forEach(memberMessage -> {
messageEventService.onMessage(systemMessageRequest.getMemberId(), systemMessageRequest.getRoleId(), memberMessage.getRecUserId());
messageEventService.onMessage(memberMessage.getRecMemberId(), memberMessage.getRecRoleId(), memberMessage.getRecUserId());
if (Arrays.stream(MessageBusinessTypeEnum.values()).anyMatch(e -> e.getCode().equals(messageNotice.getBusinessType()))) {
List<PushDevice> pushDeviceList = pushDeviceRepository.findAllByMemberIdAndRoleId(systemMessageRequest.getMemberId(), systemMessageRequest.getRoleId());
......@@ -348,4 +349,59 @@ public class MemberMessageServiceImpl implements IMemberMessageService {
sendSystemMessage(systemMessageRequest);
}
}
@Override
public void sendCustomMessage(SystemMessageCustomRequest request) {
if (Objects.isNull(request.getMemberId()) || Objects.isNull(request.getRoleId())) {
return;
}
List<MemberMessage> memberMessageList = new ArrayList<>();
if (Objects.isNull(request.getUserId())) {
List<Long> userIds = memberFeignService.getUserByMemberIds(request.getMemberId());
memberMessageList = userIds.stream().map(userId -> {
MemberMessage memberMessage = new MemberMessage();
memberMessage.setSendMemberId(0L);
memberMessage.setSendRoleId(0L);
memberMessage.setRecMemberId(request.getMemberId());
memberMessage.setRecRoleId(request.getRoleId());
memberMessage.setRecUserId(userId);
memberMessage.setTitle(request.getTitle());
memberMessage.setContent(request.getContent());
memberMessage.setUrl("");
memberMessage.setAppUrl("");
memberMessage.setDeleted(CommonBooleanEnum.NO.getCode());
memberMessage.setStatus(CommonBooleanEnum.NO.getCode());
memberMessage.setType(MessageTypeEnum.SYSTEM.getCode());
memberMessage.setSendTime(System.currentTimeMillis());
memberMessage.setCreateTime(System.currentTimeMillis());
return memberMessage;
}).collect(Collectors.toList());
} else {
// 指定发送到会员下的用户
MemberMessage memberMessage = new MemberMessage();
memberMessage.setSendMemberId(0L);
memberMessage.setSendRoleId(0L);
memberMessage.setRecMemberId(request.getMemberId());
memberMessage.setRecRoleId(request.getRoleId());
memberMessage.setRecUserId(request.getUserId());
memberMessage.setTitle(request.getTitle());
memberMessage.setContent(request.getContent());
memberMessage.setUrl("");
memberMessage.setAppUrl("");
memberMessage.setDeleted(CommonBooleanEnum.NO.getCode());
memberMessage.setStatus(CommonBooleanEnum.NO.getCode());
memberMessage.setType(MessageTypeEnum.SYSTEM.getCode());
memberMessage.setSendTime(System.currentTimeMillis());
memberMessage.setCreateTime(System.currentTimeMillis());
}
memberMessageRepository.saveAll(memberMessageList);
// 推送未读消息数
memberMessageList.forEach(memberMessage -> {
messageEventService.onMessage(memberMessage.getRecMemberId(), memberMessage.getRecRoleId(), memberMessage.getRecUserId());
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment