代码优化
This commit is contained in:
parent
ea8b9b3d37
commit
0e5fdb0243
|
|
@ -4,7 +4,8 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* 消息系统常量
|
||||
*
|
||||
* @author: wanjia
|
||||
* @time: 2021/9/9
|
||||
*/
|
||||
|
|
@ -18,4 +19,24 @@ public class NotificationSystemConstant {
|
|||
put("hehui", PLATFORM_CODE_HEHUI);
|
||||
}
|
||||
};
|
||||
|
||||
//邮件任务处理状态
|
||||
public static final Integer EMAIL_JOB_NOT_DISPATCHED = -1; //处理成功
|
||||
public static final Integer EMAIL_JOB_DISPATCHED_SUCCESS = 1; //处理成功
|
||||
public static final Integer EMAIL_JOB_DISPATCHED_FAIL = 2; //处理失败
|
||||
|
||||
//邮件发送记录状态
|
||||
public static final Integer EMAIL_UNSENT_RECORD = -1; //处理成功
|
||||
public static final Integer EMAIL_SENT_SUCCESS = 1; //处理成功
|
||||
public static final Integer EMAIL_SENT_FAIL = 2; //处理失败
|
||||
|
||||
//未读消息类型
|
||||
public static final Integer NOTIFICATION_TYPE_ALL = -1; //全部未读消息
|
||||
public static final Integer NOTIFICATION_TYPE_SYS = 1; //系统消息
|
||||
public static final Integer NOTIFICATION_TYPE_ATME = 2; //@我的消息
|
||||
|
||||
//是否已读状态
|
||||
public static final Integer STATUS_OPTION_ALL = -1; //所有信息类型,包括未读、已读
|
||||
public static final Integer STATUS_OPTION_UNREAD = 1; //未读信息
|
||||
public static final Integer STATUS_OPTION_READ = 2; //已读信息
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package cn.org.gitlink.notification.common.response;
|
|||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DataPacketUtil
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import java.util.stream.Collectors;
|
|||
* @date 2021-09-07
|
||||
*/
|
||||
|
||||
@Component
|
||||
@Component(value = "GitlinkKafkaUtil")
|
||||
public class KafkaUtil {
|
||||
|
||||
private Logger logger = LogManager.getLogger(KafkaUtil.class);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package cn.org.gitlink.notification.common.utils;
|
||||
|
||||
import cn.org.gitlink.notification.common.constant.NotificationSystemConstant;
|
||||
import cn.org.gitlink.notification.common.response.DataPacketUtil;
|
||||
import cn.org.gitlink.notification.common.response.ResponseData;
|
||||
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
|
||||
|
|
@ -21,4 +25,19 @@ public class ValidatorUtils {
|
|||
}
|
||||
return errorMessageMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 platform合法性
|
||||
*
|
||||
* @param platform
|
||||
* @return
|
||||
*/
|
||||
public static ResponseData validatePlatformCode(String platform) {
|
||||
|
||||
//验证 {platform} 参数合法性,以判断请求来源
|
||||
if (!NotificationSystemConstant.PLATFORM_CODE_MAP.containsKey(platform)) {
|
||||
return DataPacketUtil.jsonFailResult("{platform} 参数非法");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package cn.org.gitlink.notification.executor.service.email;
|
||||
|
||||
import cn.org.gitlink.notification.common.constant.NotificationSystemConstant;
|
||||
import cn.org.gitlink.notification.common.utils.EmailUtils;
|
||||
import cn.org.gitlink.notification.model.dao.entity.EmailJob;
|
||||
import cn.org.gitlink.notification.model.dao.entity.EmailSendRecord;
|
||||
|
|
@ -21,16 +22,6 @@ public class EmailService {
|
|||
|
||||
private Logger logger = LogManager.getLogger(EmailService.class);
|
||||
|
||||
//邮件任务处理状态
|
||||
private static final Integer EMAIL_JOB_NOT_DISPATCHED = -1; //处理成功
|
||||
private static final Integer EMAIL_JOB_DISPATCHED_SUCCESS = 1; //处理成功
|
||||
private static final Integer EMAIL_JOB_DISPATCHED_FAIL = 2; //处理失败
|
||||
|
||||
//邮件发送记录状态
|
||||
private static final Integer EMAIL_UNSENT_RECORD = -1; //处理成功
|
||||
private static final Integer EMAIL_SENT_SUCCESS = 1; //处理成功
|
||||
private static final Integer EMAIL_SENT_FAIL = 2; //处理失败
|
||||
|
||||
@Autowired
|
||||
private EmailJobsService emailJobsService;
|
||||
|
||||
|
|
@ -54,7 +45,7 @@ public class EmailService {
|
|||
//获取指定数量待处理列表
|
||||
List<EmailJob> emailJobList = new ArrayList<>();
|
||||
try {
|
||||
emailJobList = emailJobsService.getEmailJobsByDispatchedStatus(platform, EMAIL_JOB_NOT_DISPATCHED, dispatchNumber);
|
||||
emailJobList = emailJobsService.getEmailJobsByDispatchedStatus(platform, NotificationSystemConstant.EMAIL_JOB_NOT_DISPATCHED, dispatchNumber);
|
||||
} catch (Exception e) {
|
||||
logger.error("获取未处理邮件任务列表失败:\n" + e);
|
||||
}
|
||||
|
|
@ -63,13 +54,13 @@ public class EmailService {
|
|||
Boolean flag = null;
|
||||
for (EmailJob emailJob : emailJobList) {
|
||||
try {
|
||||
flag = emailSendRecordsService.newEmailSendRecords(platform, emailJob.getEmails(), emailJob.getId());
|
||||
flag = emailSendRecordsService.createEmailSendRecords(platform, emailJob.getEmails(), emailJob.getId());
|
||||
} catch (Exception e) {
|
||||
logger.error("处理EmailJob失败,email_job_id: " + emailJob.getId() + "\n" + e);
|
||||
}
|
||||
//EmailJob分配成功,更新状态
|
||||
try {
|
||||
emailJobsService.markEmailJobsAs(platform, emailJob.getId(), new Date(), flag ? EMAIL_JOB_DISPATCHED_SUCCESS : EMAIL_JOB_DISPATCHED_FAIL);
|
||||
emailJobsService.markEmailJobAs(platform, emailJob.getId(), new Date(), flag ? NotificationSystemConstant.EMAIL_JOB_DISPATCHED_SUCCESS : NotificationSystemConstant.EMAIL_JOB_DISPATCHED_FAIL);
|
||||
} catch (Exception e) {
|
||||
logger.error("更新EmailJob状态失败,email_job_id: " + emailJob.getId() + "\n" + e);
|
||||
}
|
||||
|
|
@ -90,7 +81,7 @@ public class EmailService {
|
|||
//获取待发送列表
|
||||
List<EmailSendRecord> emailSendRecordList = new ArrayList<>();
|
||||
try {
|
||||
emailSendRecordList = emailSendRecordsService.getRecordsByStatus(platform, EMAIL_UNSENT_RECORD, sentNumber);
|
||||
emailSendRecordList = emailSendRecordsService.getRecordsByStatus(platform, NotificationSystemConstant.EMAIL_UNSENT_RECORD, sentNumber);
|
||||
} catch (Exception e) {
|
||||
logger.error("获取未发送邮件列表失败:\n" + e);
|
||||
}
|
||||
|
|
@ -103,7 +94,7 @@ public class EmailService {
|
|||
emailUtils.sendMail(unSentEmailSendRecord.getSubject(), unSentEmailSendRecord.getEmail(), unSentEmailSendRecord.getContent());
|
||||
flag = true;
|
||||
unSentEmailSendRecord.setSentAt(new Date());
|
||||
unSentEmailSendRecord.setStatus(flag ? EMAIL_SENT_SUCCESS : EMAIL_SENT_FAIL);
|
||||
unSentEmailSendRecord.setStatus(flag ? NotificationSystemConstant.EMAIL_SENT_SUCCESS : NotificationSystemConstant.EMAIL_SENT_FAIL);
|
||||
} catch (MessagingException e) {
|
||||
logger.error("发送邮件失败,email: " + unSentEmailSendRecord.getEmail() + "\n" + e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import org.apache.kafka.clients.admin.NewTopic;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.kafka.annotation.KafkaHandler;
|
||||
|
|
@ -36,13 +37,14 @@ public class EmailJobsListener {
|
|||
private Short replicationFactor;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(value = "GitlinkKafkaUtil")
|
||||
private KafkaUtil kafkaUtil;
|
||||
|
||||
@KafkaHandler
|
||||
public void messageHandler(String message) {
|
||||
try {
|
||||
NewEmailJobVo newEmailJobVo = JSONObject.parseObject(message, NewEmailJobVo.class);
|
||||
Boolean flag = emailJobsService.sendEmail(newEmailJobVo);
|
||||
Boolean flag = emailJobsService.createEmailJob(newEmailJobVo);
|
||||
//if the message is inserted successfully, send a new email-job message to kafka
|
||||
if (flag){
|
||||
kafkaUtil.createTopic(Arrays.asList(new NewTopic(gitlinkNewEmailRemindTopic, partitions, replicationFactor)));
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public interface EmailJobsService extends IService<EmailJob> {
|
|||
* @Author: wanjia
|
||||
* @Date: 2021/9/13
|
||||
*/
|
||||
boolean sendEmail(NewEmailJobVo newEmailJobVo) throws Exception;
|
||||
boolean createEmailJob(NewEmailJobVo newEmailJobVo) throws Exception;
|
||||
|
||||
/**
|
||||
* 获取所有未处理邮件任务列表
|
||||
|
|
@ -42,6 +42,6 @@ public interface EmailJobsService extends IService<EmailJob> {
|
|||
* @Author: wanjia
|
||||
* @Date: 2021/9/13
|
||||
*/
|
||||
int markEmailJobsAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) throws Exception;
|
||||
int markEmailJobAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package cn.org.gitlink.notification.model.service.notification;
|
|||
import cn.org.gitlink.notification.model.dao.entity.EmailSendRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface EmailSendRecordsService extends IService<EmailSendRecord> {
|
||||
|
|
@ -17,7 +16,7 @@ public interface EmailSendRecordsService extends IService<EmailSendRecord> {
|
|||
* @Author: wanjia
|
||||
* @Date: 2021/9/13
|
||||
*/
|
||||
boolean newEmailSendRecords(String platform, String emails, Integer jobId) throws Exception;
|
||||
boolean createEmailSendRecords(String platform, String emails, Integer jobId) throws Exception;
|
||||
|
||||
/**
|
||||
* 获取发送记录列表
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ import org.springframework.stereotype.Service;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Service(value = "EmailJobsServiceImpl")
|
||||
public class EmailJobsServiceImpl extends ServiceImpl<EmailJobsMapper, EmailJob> implements EmailJobsService {
|
||||
|
||||
@Override
|
||||
public boolean sendEmail(NewEmailJobVo newEmailJobVo) {
|
||||
public boolean createEmailJob(NewEmailJobVo newEmailJobVo) {
|
||||
String platform = newEmailJobVo.getPlatform();
|
||||
EmailJob emailJob = new EmailJob();
|
||||
BeanUtils.copyProperties(newEmailJobVo, emailJob);
|
||||
|
|
@ -28,7 +28,7 @@ public class EmailJobsServiceImpl extends ServiceImpl<EmailJobsMapper, EmailJob>
|
|||
}
|
||||
|
||||
@Override
|
||||
public int markEmailJobsAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) throws Exception {
|
||||
public int markEmailJobAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) {
|
||||
EmailJob emailJob = new EmailJob();
|
||||
emailJob.setId(emailJobId);
|
||||
emailJob.setDispatchedAt(dispatchedAt);
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Service(value = "EmailSendRecordsServiceImpl")
|
||||
public class EmailSendRecordsServiceImpl extends ServiceImpl<EmailSendRecordsMapper, EmailSendRecord> implements EmailSendRecordsService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean newEmailSendRecords(String platform, String emails, Integer jobId) {
|
||||
public boolean createEmailSendRecords(String platform, String emails, Integer jobId) {
|
||||
List<String> list = Arrays.asList(emails.split(","));
|
||||
List<EmailSendRecord> emailSendRecordList = new ArrayList<EmailSendRecord>();
|
||||
for (String email : list){
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class EmailServiceTest {
|
|||
emailJobVo.setContent("contentTest");
|
||||
//添加发送邮件任务
|
||||
try {
|
||||
Assert.isTrue(emailJobsService.sendEmail(emailJobVo), "done");
|
||||
Assert.isTrue(emailJobsService.createEmailJob(emailJobVo), "done");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ public class EmailServiceTest {
|
|||
try {
|
||||
List<EmailJob> emailJobs = emailJobsService.getEmailJobsByDispatchedStatus("gitlink", -1, 10);
|
||||
for (EmailJob emailJob : emailJobs){
|
||||
emailSendRecordsService.newEmailSendRecords("gitlink", emailJob.getEmails(), emailJob.getId());
|
||||
emailSendRecordsService.createEmailSendRecords("gitlink", emailJob.getEmails(), emailJob.getId());
|
||||
}
|
||||
//发送邮件成功后,更新邮件发送记录
|
||||
// int count = emailSendRecordsService.markEmailSendRecordsAs("gitlink", 1, new Date(), 1);
|
||||
|
|
@ -58,7 +58,7 @@ public class EmailServiceTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
int count = emailJobsService.markEmailJobsAs("gitlink", 1, new Date(), 1);
|
||||
int count = emailJobsService.markEmailJobAs("gitlink", 1, new Date(), 1);
|
||||
Assert.isTrue(count > 0, "update status success");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import cn.org.gitlink.notification.common.constant.NotificationSystemConstant;
|
|||
import cn.org.gitlink.notification.common.response.DataPacketUtil;
|
||||
import cn.org.gitlink.notification.common.response.ResponseData;
|
||||
import cn.org.gitlink.notification.common.utils.RedisUtil;
|
||||
import cn.org.gitlink.notification.common.utils.ValidatorUtils;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.ReceiverNotificationCountVo;
|
||||
import cn.org.gitlink.notification.model.dao.entity.vo.ReceiverNotificationListVo;
|
||||
import cn.org.gitlink.notification.model.service.notification.SysNotificationService;
|
||||
|
|
@ -19,17 +20,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
@RestController
|
||||
@RequestMapping(value = "/gns/notification")
|
||||
public class NotificationController {
|
||||
|
||||
//未读消息类型
|
||||
private static final Integer NOTIFICATION_TYPE_ALL = -1; //全部未读消息
|
||||
private static final Integer NOTIFICATION_TYPE_SYS = 1; //系统消息
|
||||
private static final Integer NOTIFICATION_TYPE_ATME = 2; //@我的消息
|
||||
|
||||
//是否已读状态
|
||||
private static final Integer STATUS_OPTION_ALL = -1; //所有信息类型,包括未读、已读
|
||||
private static final Integer STATUS_OPTION_UNREAD = 1; //未读信息
|
||||
private static final Integer STATUS_OPTION_READ = 2; //已读信息
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
|
|
@ -69,7 +59,10 @@ public class NotificationController {
|
|||
@RequestParam(name = "size", required = false, defaultValue = "20") Integer size) {
|
||||
|
||||
//参数合法性验证
|
||||
ResponseData jsonFailResult = validatePlatformCodeAndReceiver(platform, receiver);
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
jsonFailResult = validateReceiver(receiver);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
jsonFailResult = validateNotificationType(type);
|
||||
|
|
@ -84,11 +77,11 @@ public class NotificationController {
|
|||
|
||||
try {
|
||||
//获取全部未读消息总数
|
||||
notificationListVo.setTotalUnreadNotifiationCount(notificationService.getNotificationCount(platform, receiver, NOTIFICATION_TYPE_ALL, STATUS_OPTION_UNREAD));
|
||||
notificationListVo.setTotalUnreadNotifiationCount(notificationService.getNotificationCount(platform, receiver, NotificationSystemConstant.NOTIFICATION_TYPE_ALL, NotificationSystemConstant.STATUS_OPTION_UNREAD));
|
||||
//获取未读系统消息总数
|
||||
notificationListVo.setUnreadNotificationCount(notificationService.getNotificationCount(platform, receiver, NOTIFICATION_TYPE_SYS, STATUS_OPTION_UNREAD));
|
||||
notificationListVo.setUnreadNotificationCount(notificationService.getNotificationCount(platform, receiver, NotificationSystemConstant.NOTIFICATION_TYPE_SYS, NotificationSystemConstant.STATUS_OPTION_UNREAD));
|
||||
//获取未读@我消息总数
|
||||
notificationListVo.setUnreadAtMeCount(notificationService.getNotificationCount(platform, receiver, NOTIFICATION_TYPE_ATME, STATUS_OPTION_UNREAD));
|
||||
notificationListVo.setUnreadAtMeCount(notificationService.getNotificationCount(platform, receiver, NotificationSystemConstant.NOTIFICATION_TYPE_ATME, NotificationSystemConstant.STATUS_OPTION_UNREAD));
|
||||
|
||||
if (page == -1) {
|
||||
page = 1;
|
||||
|
|
@ -130,7 +123,10 @@ public class NotificationController {
|
|||
@ApiParam(value = "消息类型:值为-1时,获取全部信息;值为1时,获取系统消息;值为2时,获取@我消息", defaultValue = "-1")
|
||||
@RequestParam(name = "type", required = false, defaultValue = "-1") Integer type) {
|
||||
|
||||
ResponseData jsonFailResult = validatePlatformCodeAndReceiver(platform, receiver);
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
jsonFailResult = validateReceiver(receiver);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
jsonFailResult = validateNotificationType(type);
|
||||
|
|
@ -140,7 +136,7 @@ public class NotificationController {
|
|||
ReceiverNotificationCountVo countVo = new ReceiverNotificationCountVo();
|
||||
countVo.setReceiver(receiver);
|
||||
countVo.setType(type);
|
||||
countVo.setUnreadNotification(notificationService.getNotificationCount(platform, receiver, type, STATUS_OPTION_UNREAD));
|
||||
countVo.setUnreadNotification(notificationService.getNotificationCount(platform, receiver, type, NotificationSystemConstant.STATUS_OPTION_UNREAD));
|
||||
return DataPacketUtil.jsonSuccessResult(countVo);
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
|
|
@ -154,18 +150,10 @@ public class NotificationController {
|
|||
/**
|
||||
* 验证 platform 和 receiver 的合法性
|
||||
*
|
||||
* @param platform
|
||||
* @param receiver
|
||||
* @return
|
||||
*/
|
||||
private ResponseData validatePlatformCodeAndReceiver(String platform, Integer receiver) {
|
||||
|
||||
//验证 {platform} 参数合法性,以判断请求来源
|
||||
if (!NotificationSystemConstant.PLATFORM_CODE_MAP.containsKey(platform)) {
|
||||
logger.debug("\t 输入参数 {platform} 的值 {" + platform + "} 无效");
|
||||
return DataPacketUtil.jsonFailResult("{platform} 参数非法");
|
||||
}
|
||||
|
||||
private ResponseData validateReceiver(Integer receiver) {
|
||||
//验证 {receiver} 参数合法性
|
||||
if (receiver <= 0 || receiver >= Integer.MAX_VALUE) {
|
||||
logger.debug("\t 输入参数 {receiver} 的值 {" + receiver + "} 超出约定范围");
|
||||
|
|
@ -182,7 +170,7 @@ public class NotificationController {
|
|||
* @return
|
||||
*/
|
||||
private ResponseData validateNotificationType(Integer type) {
|
||||
if (type == NOTIFICATION_TYPE_ALL || type == NOTIFICATION_TYPE_SYS || type == NOTIFICATION_TYPE_ATME) {
|
||||
if (type == NotificationSystemConstant.NOTIFICATION_TYPE_ALL || type == NotificationSystemConstant.NOTIFICATION_TYPE_SYS || type == NotificationSystemConstant.NOTIFICATION_TYPE_ATME) {
|
||||
return null;
|
||||
} else {
|
||||
logger.debug("\t 输入参数 {type} 的值 {" + type + "} 超出约定范围");
|
||||
|
|
@ -197,7 +185,7 @@ public class NotificationController {
|
|||
* @return
|
||||
*/
|
||||
private ResponseData validateStatusParams(Integer status) {
|
||||
if (status == STATUS_OPTION_ALL || status == STATUS_OPTION_READ || status == STATUS_OPTION_UNREAD) {
|
||||
if (status == NotificationSystemConstant.STATUS_OPTION_ALL || status == NotificationSystemConstant.STATUS_OPTION_READ || status == NotificationSystemConstant.STATUS_OPTION_UNREAD) {
|
||||
return null;
|
||||
} else {
|
||||
logger.debug("\t输入参数 {status} 的值 {" + status + "}超出约定范围");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package cn.org.gitlink.notification.writer.controller;
|
||||
|
||||
import cn.org.gitlink.notification.common.constant.NotificationSystemConstant;
|
||||
import cn.org.gitlink.notification.common.response.DataPacketUtil;
|
||||
import cn.org.gitlink.notification.common.response.ResponseData;
|
||||
import cn.org.gitlink.notification.common.utils.KafkaUtil;
|
||||
|
|
@ -16,8 +15,8 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -27,7 +26,6 @@ import java.util.Map;
|
|||
|
||||
@RestController
|
||||
@RequestMapping(value = "/gns/email")
|
||||
@Configuration
|
||||
public class EmailJobsController {
|
||||
|
||||
private Logger logger = LogManager.getLogger(EmailJobsController.class);
|
||||
|
|
@ -42,10 +40,11 @@ public class EmailJobsController {
|
|||
private Short replicationFactor;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(value = "GitlinkKafkaUtil")
|
||||
private KafkaUtil kafkaUtil;
|
||||
|
||||
@ApiOperation("发送邮件任务")
|
||||
@RequestMapping(path = "/{platform}", method = RequestMethod.POST)
|
||||
@PostMapping(path = "/{platform}")
|
||||
@ResponseBody
|
||||
public ResponseData sendEmail(@ApiParam(value = "平台编码", required = true)
|
||||
@PathVariable(name = "platform") String platform,
|
||||
|
|
@ -58,7 +57,7 @@ public class EmailJobsController {
|
|||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
//platform和NewEmailJobParamsVo拼装
|
||||
|
|
@ -80,21 +79,4 @@ public class EmailJobsController {
|
|||
return DataPacketUtil.jsonFailResult(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证 platform合法性
|
||||
*
|
||||
* @param platform
|
||||
* @return
|
||||
*/
|
||||
private ResponseData validatePlatformCode(String platform) {
|
||||
|
||||
//验证 {platform} 参数合法性,以判断请求来源
|
||||
if (!NotificationSystemConstant.PLATFORM_CODE_MAP.containsKey(platform)) {
|
||||
logger.debug("\t 输入参数 {platform} 的值 {" + platform + "} 无效");
|
||||
return DataPacketUtil.jsonFailResult("{platform} 参数非法");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package cn.org.gitlink.notification.writer.controller;
|
||||
|
||||
import cn.org.gitlink.notification.common.constant.NotificationSystemConstant;
|
||||
import cn.org.gitlink.notification.common.response.DataPacketUtil;
|
||||
import cn.org.gitlink.notification.common.response.ResponseData;
|
||||
import cn.org.gitlink.notification.common.utils.KafkaUtil;
|
||||
|
|
@ -19,8 +18,8 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -30,7 +29,6 @@ import java.util.Map;
|
|||
|
||||
@RestController
|
||||
@RequestMapping(value = "/gns/notification")
|
||||
@Configuration
|
||||
public class NotificationController {
|
||||
|
||||
@Value("${spring.kafka.producer.topic}")
|
||||
|
|
@ -43,15 +41,17 @@ public class NotificationController {
|
|||
private Short replicationFactor;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(value = "GitlinkKafkaUtil")
|
||||
private KafkaUtil kafkaUtil;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(value = "SysNotificationServiceImpl")
|
||||
private SysNotificationService sysNotificationService;
|
||||
|
||||
private Logger logger = LogManager.getLogger(NotificationController.class);
|
||||
|
||||
@ApiOperation("添加系统消息")
|
||||
@RequestMapping(path = "/{platform}", method = RequestMethod.POST)
|
||||
@PostMapping(path = "/{platform}")
|
||||
@ResponseBody
|
||||
public ResponseData sendNotification(@ApiParam(value = "平台编码", required = true)
|
||||
@PathVariable(name = "platform") String platform,
|
||||
|
|
@ -65,7 +65,7 @@ public class NotificationController {
|
|||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
//platform和NewSysNotificationParamsVo拼装
|
||||
|
|
@ -90,7 +90,7 @@ public class NotificationController {
|
|||
}
|
||||
|
||||
@ApiOperation("改变系统消息状态")
|
||||
@RequestMapping(path = "/{platform}", method = RequestMethod.PUT)
|
||||
@PutMapping(path = "/{platform}")
|
||||
@ResponseBody
|
||||
public ResponseData changeNotificationStatus(@ApiParam(value = "平台编码", required = true)
|
||||
@PathVariable(name = "platform") String platform,
|
||||
|
|
@ -104,7 +104,7 @@ public class NotificationController {
|
|||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
try {
|
||||
|
|
@ -135,7 +135,7 @@ public class NotificationController {
|
|||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
try {
|
||||
|
|
@ -146,21 +146,4 @@ public class NotificationController {
|
|||
return DataPacketUtil.jsonFailResult(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证 platform合法性
|
||||
*
|
||||
* @param platform
|
||||
* @return
|
||||
*/
|
||||
private ResponseData validatePlatformCode(String platform) {
|
||||
|
||||
//验证 {platform} 参数合法性,以判断请求来源
|
||||
if (!NotificationSystemConstant.PLATFORM_CODE_MAP.containsKey(platform)) {
|
||||
logger.debug("\t 输入参数 {platform} 的值 {" + platform + "} 无效");
|
||||
return DataPacketUtil.jsonFailResult("{platform} 参数非法");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue