|
@@ -12,6 +12,7 @@ import cn.com.qmth.examcloud.core.oe.admin.service.bean.NotifyUrlInfo;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -27,12 +28,8 @@ import java.util.List;
|
|
|
@Api(tags = "定时发送获取分数通知接口")
|
|
|
@RestController
|
|
|
@RequestMapping("${$rmp.cloud.oe}/examScoreNoticeQueue")
|
|
|
-public class ExamScoreNoticeQueueCloudServiceProvider extends ControllerSupport
|
|
|
- implements ExamScoreNoticeQueueCloudService {
|
|
|
+public class ExamScoreNoticeQueueCloudServiceProvider extends ControllerSupport implements ExamScoreNoticeQueueCloudService {
|
|
|
|
|
|
- /**
|
|
|
- *
|
|
|
- */
|
|
|
private static final long serialVersionUID = -2622841462905285211L;
|
|
|
|
|
|
@Autowired
|
|
@@ -51,58 +48,55 @@ public class ExamScoreNoticeQueueCloudServiceProvider extends ControllerSupport
|
|
|
@PostMapping("/sendObtainScoreNotice")
|
|
|
@Override
|
|
|
public void sendObtainScoreNotice() {
|
|
|
- LOGGER.info("开始执行sendObtainScoreNotice");
|
|
|
// 获取所有的通知队列
|
|
|
List<ExamScoreNoticeQueueEntity> examScoreNoticeQueueList = examScoreNoticeQueueRepo.findAll();
|
|
|
- if (examScoreNoticeQueueList == null || examScoreNoticeQueueList.size() == 0) {
|
|
|
+ if (CollectionUtils.isEmpty(examScoreNoticeQueueList)) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
for (ExamScoreNoticeQueueEntity noticeEntity : examScoreNoticeQueueList) {
|
|
|
// 获取当前组织机构的通知对象
|
|
|
NotifyUrlInfo notifyUrlInfo = examScoreObtainQueueService.getNotifyUrlInfo(noticeEntity.getRootOrgId());
|
|
|
+
|
|
|
// 只有配置了通知接口的才发送通知
|
|
|
- if (StringUtils.isNotBlank(notifyUrlInfo.getNotifyUrl())) {
|
|
|
- try {
|
|
|
- OKHttpUtil.call(notifyUrlInfo.getHttpMethod(), notifyUrlInfo.getNotifyUrl());
|
|
|
- // 发送通知没有问题,则清除通知队列中数据
|
|
|
- examScoreNoticeQueueRepo.deleteById(noticeEntity.getRootOrgId());
|
|
|
- } catch (Exception e) {
|
|
|
- if (e instanceof UnknownHostException || e instanceof SocketException) {
|
|
|
- try {
|
|
|
- // 如果是由于连接超时,或者读取数据超时导致异常,需要对发送通知失败次数进行累加
|
|
|
- long failTimes = noticeEntity.getFailTimes() == null ? 0
|
|
|
- : noticeEntity.getFailTimes().longValue();
|
|
|
- noticeEntity.setFailTimes(failTimes + 1);
|
|
|
- noticeEntity.setUpdateTime(new Date());
|
|
|
- examScoreNoticeQueueRepo.save(noticeEntity);
|
|
|
- } catch (Exception e1) {
|
|
|
- LOGGER.error("examScoreNoticeQueueRepo.save exception:" + e1.getMessage(), e1);
|
|
|
- }
|
|
|
- }
|
|
|
- LOGGER.error("OeExamScoreNoticeQueueCloudServiceProvider-sendObtainScoreNotice:" + e.getMessage(), e);
|
|
|
+ if (StringUtils.isBlank(notifyUrlInfo.getNotifyUrl())) {
|
|
|
+ // 未配置推送地址的则清理掉
|
|
|
+ examScoreNoticeQueueRepo.deleteById(noticeEntity.getRootOrgId());
|
|
|
+ LOGGER.warn("通知学校获取成绩,尚未配置学校的推送地址!rootOrgId:{}", noticeEntity.getRootOrgId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ OKHttpUtil.call(notifyUrlInfo.getHttpMethod(), notifyUrlInfo.getNotifyUrl());
|
|
|
+
|
|
|
+ noticeEntity.setFailTimes(0L);
|
|
|
+ noticeEntity.setUpdateTime(new Date());
|
|
|
+ examScoreNoticeQueueRepo.save(noticeEntity);
|
|
|
+
|
|
|
+ LOGGER.warn("通知学校获取成绩成功!rootOrgId:{} notifyUrl:{}", noticeEntity.getRootOrgId(), notifyUrlInfo.getNotifyUrl());
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (e instanceof UnknownHostException || e instanceof SocketException) {
|
|
|
+ // 如果是由于连接超时,或者读取数据超时导致异常,需要对发送通知失败次数进行累加
|
|
|
+ long failTimes = noticeEntity.getFailTimes() == null ? 0 : noticeEntity.getFailTimes();
|
|
|
+ noticeEntity.setFailTimes(failTimes + 1);
|
|
|
+ noticeEntity.setUpdateTime(new Date());
|
|
|
+ examScoreNoticeQueueRepo.save(noticeEntity);
|
|
|
}
|
|
|
+ LOGGER.error("通知学校获取成绩失败!rootOrgId:{} notifyUrl:{} err:{}",
|
|
|
+ noticeEntity.getRootOrgId(), notifyUrlInfo.getNotifyUrl(), e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- LOGGER.info("结束执行sendObtainScoreNotice");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加成绩通知队列
|
|
|
- *
|
|
|
- * @param req
|
|
|
- * @return
|
|
|
*/
|
|
|
@ApiOperation(value = "添加成绩通知队列")
|
|
|
@PostMapping("/addExamScoreNoticeQueue")
|
|
|
@Override
|
|
|
public AddExamScoreNoticeQueueResp addExamScoreNoticeQueue(@RequestBody AddExamScoreNoticeQueueReq req) {
|
|
|
-
|
|
|
-
|
|
|
//如果不存在则添加通知队列,否则不做任何处理
|
|
|
- if (!examScoreNoticeQueueService.isExistExamScoreNoticeQueue(req.getRootOrgId())) {
|
|
|
- examScoreNoticeQueueService.addExamScoreNoticeQueue(req.getRootOrgId());
|
|
|
- }
|
|
|
-
|
|
|
+ examScoreNoticeQueueService.addExamScoreNoticeQueue(req.getRootOrgId());
|
|
|
return new AddExamScoreNoticeQueueResp();
|
|
|
}
|
|
|
|