Merge pull request '代码优化及校验异常全局处理' (#103) from wanjia9506/gitlink-notification-system:dev_gitlink_model into master
This commit is contained in:
commit
af3803495e
|
|
@ -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; //已读信息
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,16 @@ import cn.org.gitlink.notification.common.utils.CommonUtils;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* web请求异常全局处理类,在使用的模块内继承此类,然后加上ControllerAdvice注解,example:
|
||||
|
|
@ -39,4 +44,24 @@ public class ExceptionInterceptor {
|
|||
logger.error(logTemplate, request.getRequestURI(), e);
|
||||
return DataPacketUtil.jsonFailResult(e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* valid 异常处理
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ResponseData handlerValidException(MethodArgumentNotValidException e){
|
||||
Map<String, Object> errorMessageMap = new HashMap<>();
|
||||
// 获取所有错误信息
|
||||
List<FieldError> errList = e.getBindingResult().getFieldErrors();
|
||||
for (FieldError error : errList) {
|
||||
errorMessageMap.put(error.getField(), error.getDefaultMessage());
|
||||
}
|
||||
logger.error("data errors:{}", errorMessageMap);
|
||||
return DataPacketUtil.jsonFailResult(errorMessageMap);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ package cn.org.gitlink.notification.common.response;
|
|||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DataPacketUtil
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,7 +26,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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,16 @@ import cn.org.gitlink.notification.common.utils.KafkaUtil;
|
|||
import cn.org.gitlink.notification.model.dao.entity.vo.NewEmailJobVo;
|
||||
import cn.org.gitlink.notification.model.service.notification.EmailJobsService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Component
|
||||
@Configuration
|
||||
@KafkaListener(topics = "${spring.kafka.consumer.topic_email}", groupId = "${spring.kafka.consumer.group_id_email}")
|
||||
|
|
@ -30,13 +28,14 @@ public class EmailJobsListener {
|
|||
private String gitlinkNewEmailRemindTopic;
|
||||
|
||||
@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.sendMessage(gitlinkNewEmailRemindTopic, JSONObject.toJSONString(newEmailJobVo));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -15,8 +14,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.*;
|
||||
|
|
@ -25,7 +24,6 @@ import java.util.Map;
|
|||
|
||||
@RestController
|
||||
@RequestMapping(value = "/gns/email")
|
||||
@Configuration
|
||||
public class EmailJobsController {
|
||||
|
||||
private Logger logger = LogManager.getLogger(EmailJobsController.class);
|
||||
|
|
@ -34,23 +32,18 @@ public class EmailJobsController {
|
|||
private String gitlinkEmailTopic;
|
||||
|
||||
@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,
|
||||
|
||||
@Validated @RequestBody NewEmailJobParamsVo newEmailJobParamsVo,
|
||||
|
||||
BindingResult bindingResult){
|
||||
@Validated @RequestBody NewEmailJobParamsVo newEmailJobParamsVo){
|
||||
//参数合法性验证
|
||||
Map<String, String> errors = ValidatorUtils.buildValidationErrorMessageMap(bindingResult);
|
||||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
//platform和NewEmailJobParamsVo拼装
|
||||
|
|
@ -71,21 +64,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;
|
||||
|
|
@ -18,8 +17,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.*;
|
||||
|
|
@ -28,36 +27,31 @@ import java.util.Map;
|
|||
|
||||
@RestController
|
||||
@RequestMapping(value = "/gns/notification")
|
||||
@Configuration
|
||||
public class NotificationController {
|
||||
|
||||
@Value("${spring.kafka.producer.topic}")
|
||||
private String gitlinkNotificationTopic;
|
||||
|
||||
@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,
|
||||
|
||||
@Validated @RequestBody NewSysNotificationParamsVo newSysNotificationParamsVo,
|
||||
@Validated @RequestBody NewSysNotificationParamsVo newSysNotificationParamsVo) {
|
||||
|
||||
BindingResult bindingResult) {
|
||||
|
||||
//参数合法性验证
|
||||
Map<String, String> errors = ValidatorUtils.buildValidationErrorMessageMap(bindingResult);
|
||||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
//platform校验
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
//platform和NewSysNotificationParamsVo拼装
|
||||
|
|
@ -81,21 +75,15 @@ 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,
|
||||
|
||||
@Validated @RequestBody UpdateNotificationStatusParamsVo updateNotificationStatusParamsVo,
|
||||
|
||||
BindingResult bindingResult) {
|
||||
@Validated @RequestBody UpdateNotificationStatusParamsVo updateNotificationStatusParamsVo) {
|
||||
|
||||
//参数合法性验证
|
||||
Map<String, String> errors = ValidatorUtils.buildValidationErrorMessageMap(bindingResult);
|
||||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
try {
|
||||
|
|
@ -112,21 +100,15 @@ public class NotificationController {
|
|||
}
|
||||
|
||||
@ApiOperation("删除系统消息状态")
|
||||
@RequestMapping(path = "/{platform}", method = RequestMethod.DELETE)
|
||||
@DeleteMapping(path = "/{platform}")
|
||||
@ResponseBody
|
||||
public ResponseData changeNotificationStatus(@ApiParam(value = "平台编码", required = true)
|
||||
@PathVariable(name = "platform") String platform,
|
||||
|
||||
@Validated @RequestBody DeleteNotificationsVo deleteNotificationsVo,
|
||||
|
||||
BindingResult bindingResult) {
|
||||
@Validated @RequestBody DeleteNotificationsVo deleteNotificationsVo) {
|
||||
|
||||
//参数合法性验证
|
||||
Map<String, String> errors = ValidatorUtils.buildValidationErrorMessageMap(bindingResult);
|
||||
if (!errors.isEmpty()) {
|
||||
return DataPacketUtil.jsonFailResult(errors);
|
||||
}
|
||||
ResponseData jsonFailResult = validatePlatformCode(platform);
|
||||
ResponseData jsonFailResult = ValidatorUtils.validatePlatformCode(platform);
|
||||
if (jsonFailResult != null) return jsonFailResult;
|
||||
|
||||
try {
|
||||
|
|
@ -137,21 +119,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