|
@@ -5,9 +5,13 @@ import java.net.UnknownHostException;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.request.AddExamScoreNoticeQueueReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.response.AddExamScoreNoticeQueueResp;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.ExamScoreNoticeQueueService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
@@ -25,58 +29,80 @@ import io.swagger.annotations.ApiOperation;
|
|
|
@RestController
|
|
|
@RequestMapping("${$rmp.cloud.oe}/examScoreNoticeQueue")
|
|
|
public class ExamScoreNoticeQueueCloudServiceProvider extends ControllerSupport
|
|
|
- implements ExamScoreNoticeQueueCloudService {
|
|
|
+ implements ExamScoreNoticeQueueCloudService {
|
|
|
|
|
|
- /**
|
|
|
- *
|
|
|
- */
|
|
|
- private static final long serialVersionUID = -2622841462905285211L;
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private static final long serialVersionUID = -2622841462905285211L;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ExamScoreNoticeQueueRepo examScoreNoticeQueueRepo;
|
|
|
- @Autowired
|
|
|
- private ExamScoreObtainQueueService examScoreObtainQueueService;
|
|
|
+ @Autowired
|
|
|
+ private ExamScoreNoticeQueueRepo examScoreNoticeQueueRepo;
|
|
|
+ @Autowired
|
|
|
+ private ExamScoreObtainQueueService examScoreObtainQueueService;
|
|
|
+ @Autowired
|
|
|
+ private ExamScoreNoticeQueueService examScoreNoticeQueueService;
|
|
|
|
|
|
- /**
|
|
|
- * 定时发送分数获取通知 定时任务每5分钟发送一次
|
|
|
- */
|
|
|
- @ApiOperation(value = "定时发送获取分数通知接口")
|
|
|
- @PostMapping("/sendObtainScoreNotice")
|
|
|
- @Override
|
|
|
- public void sendObtainScoreNotice() {
|
|
|
- log.info("开始执行sendObtainScoreNotice");
|
|
|
- // 获取所有的通知队列
|
|
|
- List<ExamScoreNoticeQueueEntity> examScoreNoticeQueueList = examScoreNoticeQueueRepo.findAll();
|
|
|
- if (examScoreNoticeQueueList == null || examScoreNoticeQueueList.size() == 0) {
|
|
|
- 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) {
|
|
|
- log.error("examScoreNoticeQueueRepo.save exception:" + e1.getMessage(), e1);
|
|
|
- }
|
|
|
- }
|
|
|
- log.error("OeExamScoreNoticeQueueCloudServiceProvider-sendObtainScoreNotice:" + e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("结束执行sendObtainScoreNotice");
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 定时发送分数获取通知 定时任务每5分钟发送一次
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "定时发送获取分数通知接口")
|
|
|
+ @PostMapping("/sendObtainScoreNotice")
|
|
|
+ @Override
|
|
|
+ public void sendObtainScoreNotice() {
|
|
|
+ log.info("开始执行sendObtainScoreNotice");
|
|
|
+ // 获取所有的通知队列
|
|
|
+ List<ExamScoreNoticeQueueEntity> examScoreNoticeQueueList = examScoreNoticeQueueRepo.findAll();
|
|
|
+ if (examScoreNoticeQueueList == null || examScoreNoticeQueueList.size() == 0) {
|
|
|
+ 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) {
|
|
|
+ log.error("examScoreNoticeQueueRepo.save exception:" + e1.getMessage(), e1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.error("OeExamScoreNoticeQueueCloudServiceProvider-sendObtainScoreNotice:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.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());
|
|
|
+ }
|
|
|
+
|
|
|
+ return new AddExamScoreNoticeQueueResp();
|
|
|
+ }
|
|
|
|
|
|
}
|