|
@@ -38,7 +38,6 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -80,29 +79,45 @@ public class NoticeInfoServiceImpl extends ServiceImpl<NoticeInfoMapper, NoticeI
|
|
|
@Autowired
|
|
|
private AppInfoService appInfoService;
|
|
|
|
|
|
- @Value("${notice-secret:true}")
|
|
|
- private boolean noticeSecret;
|
|
|
-
|
|
|
@Override
|
|
|
public R send(NoticeInfoReq noticeInfoReq) {
|
|
|
- if (this.validate(noticeInfoReq)) {
|
|
|
- return R.ok(this.transferIds(noticeInfoReq));
|
|
|
+ // 120101510000 120000450200
|
|
|
+ // 120222197001010001 120222197001010002
|
|
|
+ boolean isSend;
|
|
|
+ Integer messageType = noticeInfoReq.getMessageType();
|
|
|
+ String scopeId = noticeInfoReq.getScopeId();
|
|
|
+ AppInfo appInfo = appInfoService.getOneByCode(scopeId);
|
|
|
+ if (Objects.isNull(appInfo)) {
|
|
|
+ throw new MessageInfoException(MessageInfoErrorEnums.Code.NOTICE_INFO_ERROR);
|
|
|
+ }
|
|
|
+ noticeInfoReq.setScopeName(appInfo.getSystemName());
|
|
|
+ Set<String> messageClientIds = getMessageClientIds(messageType, scopeId);
|
|
|
+ log.info("transferIds-scopeId-{}-{}", scopeId, messageClientIds);
|
|
|
+ if (CollUtil.isNotEmpty(messageClientIds)) {
|
|
|
+ NoticeInfoSend noticeInfoSend = doSaveNoticeInfo(noticeInfoReq, messageClientIds);
|
|
|
+ isSend = producer.send(BusinessConstants.TOPIC_PRE + scopeId, JSON.toJSONString(noticeInfoSend));
|
|
|
+ if (isSend) {
|
|
|
+ MsgRecord msgRecord = new MsgRecord();
|
|
|
+ msgRecord.setCreateBy(BusinessConstants.DEFAULT_ADMIN);
|
|
|
+ msgRecord.setCreateTime(LocalDateTime.now());
|
|
|
+ msgRecord.setReqContent(JSON.toJSONString(noticeInfoSend));
|
|
|
+ msgRecord.setType(MsgRecordTypeEnum.NOTICE.value());
|
|
|
+ msgRecordService.save(msgRecord);
|
|
|
+ }
|
|
|
}
|
|
|
- // 封装消息
|
|
|
- // 保存及推送mq
|
|
|
- return R.failed("发送消息验证失败");
|
|
|
+ return R.ok(true);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public NoticeInfoVO detail(Long id) {
|
|
|
- NoticeInfo noticeInfo = this.getById(id);
|
|
|
+ NoticeInfo noticeInfo = getById(id);
|
|
|
return noticeInfoVOConvert.toVo(noticeInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean update(NoticeInfoParam noticeInfoParam) {
|
|
|
NoticeInfo messageInfo = noticeInfoVOConvert.paramTo(noticeInfoParam);
|
|
|
- return this.updateById(messageInfo);
|
|
|
+ return updateById(messageInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -135,34 +150,6 @@ public class NoticeInfoServiceImpl extends ServiceImpl<NoticeInfoMapper, NoticeI
|
|
|
return queryPage;
|
|
|
}
|
|
|
|
|
|
- private boolean transferIds(NoticeInfoReq noticeInfoReq) {
|
|
|
- // 120101510000 120000450200
|
|
|
- // 120222197001010001 120222197001010002
|
|
|
- boolean isSend = false;
|
|
|
- Integer messageType = noticeInfoReq.getMessageType();
|
|
|
- String scopeId = noticeInfoReq.getScopeId();
|
|
|
- AppInfo appInfo = appInfoService.getOneByCode(noticeInfoReq.getScopeId());
|
|
|
- if (Objects.isNull(appInfo)) {
|
|
|
- throw new MessageInfoException(MessageInfoErrorEnums.Code.NOTICE_INFO_ERROR);
|
|
|
- }
|
|
|
- noticeInfoReq.setScopeName(appInfo.getSystemName());
|
|
|
- Set<String> messageClientIds = this.getMessageClientIds(messageType, scopeId);
|
|
|
- log.info("transferIds-scopeId-{}-{}", scopeId, messageClientIds);
|
|
|
- if (CollUtil.isNotEmpty(messageClientIds)) {
|
|
|
- NoticeInfoSend noticeInfoSend = this.doSaveNoticeInfo(noticeInfoReq, messageClientIds);
|
|
|
- isSend = producer.send(BusinessConstants.TOPIC_PRE + noticeInfoReq.getScopeId(), JSON.toJSONString(noticeInfoSend));
|
|
|
- if (isSend) {
|
|
|
- MsgRecord msgRecord = new MsgRecord();
|
|
|
- msgRecord.setCreateBy(BusinessConstants.DEFAULT_ADMIN);
|
|
|
- msgRecord.setCreateTime(LocalDateTime.now());
|
|
|
- msgRecord.setReqContent(JSON.toJSONString(noticeInfoSend));
|
|
|
- msgRecord.setType(MsgRecordTypeEnum.NOTICE.value());
|
|
|
- msgRecordService.save(msgRecord);
|
|
|
- }
|
|
|
- }
|
|
|
- return isSend;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @author huey China.
|
|
|
* @Description :
|
|
@@ -183,26 +170,9 @@ public class NoticeInfoServiceImpl extends ServiceImpl<NoticeInfoMapper, NoticeI
|
|
|
return messageClientIds;
|
|
|
}
|
|
|
|
|
|
- private boolean validate(NoticeInfoReq noticeInfoReq) {
|
|
|
-
|
|
|
- String id = noticeInfoReq.getClientId();
|
|
|
- Long t = noticeInfoReq.getT();
|
|
|
- String scopeId = noticeInfoReq.getScopeId();
|
|
|
- log.info("noticeInfoReq-validate-start-{}", noticeInfoReq.getClientId());
|
|
|
- if (noticeSecret) {
|
|
|
- String correctHash = DigestUtils.md5Hex(id + t);
|
|
|
- if (!correctHash.equalsIgnoreCase(noticeInfoReq.getK())) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("noticeInfoReq-validate-end-{}-{}", scopeId, id);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public NoticeInfoSend doSaveNoticeInfo(NoticeInfoReq noticeInfoReq, Set<String> messageClientIds) {
|
|
|
- log.info("doSaveNoticeInfo-start-{}-{}", noticeInfoReq.getClientId(), messageClientIds);
|
|
|
+ log.info("doSaveNoticeInfo-start-{}-{}", noticeInfoReq.getCreateIdCard(), messageClientIds);
|
|
|
Integer messageType = noticeInfoReq.getMessageType();
|
|
|
ScopeEnums scopeEnums = ScopeEnums.ofMessageType(messageType);
|
|
|
List<NoticeInfoScope> insertList = Lists.newArrayList();
|
|
@@ -210,24 +180,25 @@ public class NoticeInfoServiceImpl extends ServiceImpl<NoticeInfoMapper, NoticeI
|
|
|
noticeInfoSend.setNoticeInfoReq(noticeInfoReq);
|
|
|
noticeInfoSend.setClientIds(messageClientIds);
|
|
|
|
|
|
+ String scopeId = noticeInfoReq.getScopeId();
|
|
|
NoticeInfo noticeInfo = noticeReqConvert.reqToInfo(noticeInfoReq);
|
|
|
- noticeInfo.setCreateBy(noticeInfoReq.getClientId());
|
|
|
- noticeInfo.setCreateUser(noticeInfoReq.getClientName());
|
|
|
- noticeInfo.setCreateOrgCode(noticeInfoReq.getClientOrgCode());
|
|
|
- noticeInfo.setCreateOrgName(noticeInfoReq.getClientOrgName());
|
|
|
- noticeInfo.setScopeId(noticeInfoReq.getScopeId());
|
|
|
+ noticeInfo.setCreateBy(noticeInfoReq.getCreateIdCard());
|
|
|
+ noticeInfo.setCreateUser(noticeInfoReq.getCreateUserName());
|
|
|
+ noticeInfo.setCreateOrgCode(noticeInfoReq.getCreateOrgCode());
|
|
|
+ noticeInfo.setCreateOrgName(noticeInfoReq.getCreateOrgName());
|
|
|
+ noticeInfo.setScopeId(scopeId);
|
|
|
noticeInfo.setScopeUrl(noticeInfoReq.getScopeUrl());
|
|
|
noticeInfo.setScopeName(noticeInfoReq.getScopeName());
|
|
|
// 存储
|
|
|
boolean isSaveBatchSuccess = false;
|
|
|
try {
|
|
|
- isSaveBatchSuccess = this.save(noticeInfo);
|
|
|
+ isSaveBatchSuccess = save(noticeInfo);
|
|
|
noticeInfoSend.setNoticeInfo(noticeInfo);
|
|
|
|
|
|
messageClientIds.forEach(e -> {
|
|
|
NoticeInfoScope noticeInfoScope = new NoticeInfoScope();
|
|
|
noticeInfoScope.setNoticeInfoId(noticeInfo.getId());
|
|
|
- noticeInfoScope.setScopeId(noticeInfoReq.getScopeId());
|
|
|
+ noticeInfoScope.setScopeId(scopeId);
|
|
|
noticeInfoScope.setMemberId(e);
|
|
|
noticeInfoScope.setScopeType(scopeEnums.value());
|
|
|
// messageInfoScope.setScopeLevel("");
|
|
@@ -241,7 +212,7 @@ public class NoticeInfoServiceImpl extends ServiceImpl<NoticeInfoMapper, NoticeI
|
|
|
// 批量存储失败,则逐个存储
|
|
|
if (!isSaveBatchSuccess) {
|
|
|
try {
|
|
|
- this.save(noticeInfo);
|
|
|
+ save(noticeInfo);
|
|
|
insertList.forEach(e -> {
|
|
|
noticeInfoScopeService.save(e);
|
|
|
});
|
|
@@ -249,7 +220,7 @@ public class NoticeInfoServiceImpl extends ServiceImpl<NoticeInfoMapper, NoticeI
|
|
|
log.warn("消息中心 存储失败 {}", e);
|
|
|
}
|
|
|
}
|
|
|
- log.info("doSaveNoticeInfo-end-{}-{}", noticeInfoReq.getClientId(), messageClientIds);
|
|
|
+ log.info("doSaveNoticeInfo-end-{}-{}", noticeInfoReq.getCreateIdCard(), messageClientIds);
|
|
|
return noticeInfoSend;
|
|
|
}
|
|
|
|