|
@@ -14,16 +14,23 @@ package vip.xiaonuo.exam.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollStreamUtil;
|
|
import cn.hutool.core.collection.CollStreamUtil;
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.aliyun.oss.ServiceException;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import io.swagger.annotations.ApiModelProperty;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import vip.xiaonuo.common.enums.CommonSortOrderEnum;
|
|
import vip.xiaonuo.common.enums.CommonSortOrderEnum;
|
|
|
import vip.xiaonuo.common.exception.CommonException;
|
|
import vip.xiaonuo.common.exception.CommonException;
|
|
|
import vip.xiaonuo.common.page.CommonPageRequest;
|
|
import vip.xiaonuo.common.page.CommonPageRequest;
|
|
|
|
|
+import vip.xiaonuo.dev.api.DevJobApi;
|
|
|
import vip.xiaonuo.exam.domain.CourseChapterPaper;
|
|
import vip.xiaonuo.exam.domain.CourseChapterPaper;
|
|
|
import vip.xiaonuo.exam.domain.ExamPaper;
|
|
import vip.xiaonuo.exam.domain.ExamPaper;
|
|
|
import vip.xiaonuo.exam.domain.TExam;
|
|
import vip.xiaonuo.exam.domain.TExam;
|
|
@@ -38,7 +45,7 @@ import vip.xiaonuo.exam.service.ExamPaperService;
|
|
|
import vip.xiaonuo.exam.service.TExamService;
|
|
import vip.xiaonuo.exam.service.TExamService;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-
|
|
|
|
|
|
|
+import vip.xiaonuo.exam.utility.DateTimeUtil;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 考试表Service接口实现类
|
|
* 考试表Service接口实现类
|
|
@@ -46,6 +53,7 @@ import java.util.List;
|
|
|
* @author ZSS
|
|
* @author ZSS
|
|
|
* @date 2025/07/22 10:51
|
|
* @date 2025/07/22 10:51
|
|
|
**/
|
|
**/
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class TExamServiceImpl extends ServiceImpl<TExamMapper, TExam> implements TExamService {
|
|
public class TExamServiceImpl extends ServiceImpl<TExamMapper, TExam> implements TExamService {
|
|
|
|
|
|
|
@@ -55,6 +63,9 @@ public class TExamServiceImpl extends ServiceImpl<TExamMapper, TExam> implements
|
|
|
@Resource
|
|
@Resource
|
|
|
private CourseChapterPaperMapper courseChapterPaperMapper;
|
|
private CourseChapterPaperMapper courseChapterPaperMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private DevJobApi devJobApi;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Page<TExam> page(TExamPageParam tExamPageParam) {
|
|
public Page<TExam> page(TExamPageParam tExamPageParam) {
|
|
|
QueryWrapper<TExam> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<TExam> queryWrapper = new QueryWrapper<>();
|
|
@@ -103,6 +114,9 @@ public class TExamServiceImpl extends ServiceImpl<TExamMapper, TExam> implements
|
|
|
cp.setType("0"); // 章节测验
|
|
cp.setType("0"); // 章节测验
|
|
|
courseChapterPaperMapper.add(cp);
|
|
courseChapterPaperMapper.add(cp);
|
|
|
}
|
|
}
|
|
|
|
|
+ if(tExamAddParam.getStartTime() != null && tExamAddParam.getEndTime() != null){
|
|
|
|
|
+ this.addJob(tExam);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -119,14 +133,58 @@ public class TExamServiceImpl extends ServiceImpl<TExamMapper, TExam> implements
|
|
|
cp.setPaperId(tExamEditParam.getPaperId());
|
|
cp.setPaperId(tExamEditParam.getPaperId());
|
|
|
courseChapterPaperMapper.add(cp);
|
|
courseChapterPaperMapper.add(cp);
|
|
|
}
|
|
}
|
|
|
- BeanUtil.copyProperties(tExamEditParam, tExam);
|
|
|
|
|
|
|
+ boolean updateJob = false;
|
|
|
if(tExamEditParam.getPaperId() != null && !tExamEditParam.getPaperId().isEmpty()){
|
|
if(tExamEditParam.getPaperId() != null && !tExamEditParam.getPaperId().isEmpty()){
|
|
|
ExamPaper examPaper = examPaperService.selectById(Integer.parseInt(tExamEditParam.getPaperId()));
|
|
ExamPaper examPaper = examPaperService.selectById(Integer.parseInt(tExamEditParam.getPaperId()));
|
|
|
if(ExamPaperTypeEnum.TimeLimit.getCode() == examPaper.getPaperType()){
|
|
if(ExamPaperTypeEnum.TimeLimit.getCode() == examPaper.getPaperType()){
|
|
|
tExamEditParam.setStartTime(examPaper.getLimitStartTime());
|
|
tExamEditParam.setStartTime(examPaper.getLimitStartTime());
|
|
|
tExamEditParam.setEndTime(examPaper.getLimitEndTime());
|
|
tExamEditParam.setEndTime(examPaper.getLimitEndTime());
|
|
|
|
|
+ updateJob = true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if(tExamEditParam.getStartTime() !=null || tExamEditParam.getEndTime() !=null){
|
|
|
|
|
+ updateJob = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(updateJob){
|
|
|
|
|
+ // 修改定时任务
|
|
|
|
|
+ JSONObject jobQuery = devJobApi.queryEntity(tExamEditParam.getJobId());
|
|
|
|
|
+ if(jobQuery != null && jobQuery.getInteger("code") == 200){
|
|
|
|
|
+ JSONObject jobEntity = jobQuery.getJSONObject("data");
|
|
|
|
|
+ if(jobEntity != null && jobEntity.getString("jobStatus") != null && jobEntity.getString("jobStatus").equals("STOPPED")){
|
|
|
|
|
+ // 查的到任务已经结束了,删掉历史建新的
|
|
|
|
|
+ List<String> jobIds = CollectionUtil.newArrayList(tExam.getJobId());
|
|
|
|
|
+ JSONObject deleteJobResult = devJobApi.deleteJob(jobIds);
|
|
|
|
|
+ if(deleteJobResult != null && deleteJobResult.getInteger("code") == 200){
|
|
|
|
|
+ tExam = this.addJob(tExam);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ log.error("任务修改失败,删除过期任务异常。{}",deleteJobResult);
|
|
|
|
|
+ throw new CommonException("任务修改失败,删除过期任务异常。");
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ if(jobEntity == null || jobEntity.getString("jobStatus") == null){
|
|
|
|
|
+ tExam = this.addJob(tExam);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // 查的到任务未结束,修改任务
|
|
|
|
|
+ jobEntity.put("id", tExam.getJobId());
|
|
|
|
|
+ jobEntity.put("name", tExam.getId()+"-"+tExam.getExamName()+"-"+tExam.getPaperId());
|
|
|
|
|
+ String cronExpression = DateTimeUtil.generateCronExpression(tExam.getStartTime());
|
|
|
|
|
+ jobEntity.put("cronExpression", cronExpression);
|
|
|
|
|
+ jobEntity.put("sortCode", 99);
|
|
|
|
|
+ jobEntity.put("extJson", JSONObject.toJSONString(tExam));
|
|
|
|
|
+ JSONObject editJobResult = devJobApi.editJob(jobEntity);
|
|
|
|
|
+ if(editJobResult != null && editJobResult.getInteger("code") == 200){
|
|
|
|
|
+ tExam.setJobId(jobEntity.getString("id"));
|
|
|
|
|
+ }else{
|
|
|
|
|
+ throw new CommonException("任务修改失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // 任务不存在,创建任务
|
|
|
|
|
+ tExam = this.addJob(tExam);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ BeanUtil.copyProperties(tExamEditParam, tExam);
|
|
|
this.updateById(tExam);
|
|
this.updateById(tExam);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -151,4 +209,28 @@ public class TExamServiceImpl extends ServiceImpl<TExamMapper, TExam> implements
|
|
|
return tExam;
|
|
return tExam;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public TExam addJob(TExam tExam){
|
|
|
|
|
+ JSONObject jobParam = new JSONObject();
|
|
|
|
|
+ jobParam.put("name", tExam.getId()+"-"+tExam.getExamName()+"-"+tExam.getPaperId());
|
|
|
|
|
+ jobParam.put("category", "exam");
|
|
|
|
|
+ jobParam.put("actionClass", "vip.xiaonuo.exam.job.task.ExamJobTimerTaskRunner");
|
|
|
|
|
+ String cronExpression = DateTimeUtil.generateCronExpression(tExam.getStartTime());
|
|
|
|
|
+ jobParam.put("cronExpression", cronExpression);
|
|
|
|
|
+ jobParam.put("sortCode", 99);
|
|
|
|
|
+ jobParam.put("extJson", JSONObject.toJSONString(tExam));
|
|
|
|
|
+ JSONObject addJobResult = devJobApi.addJob(jobParam);
|
|
|
|
|
+ if(addJobResult != null && addJobResult.getInteger("code") != null && addJobResult.getIntValue("code") == 200){
|
|
|
|
|
+ tExam.setJobId(addJobResult.getString("data"));
|
|
|
|
|
+ this.save(tExam);
|
|
|
|
|
+ return tExam;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ String msg = "";
|
|
|
|
|
+ if(addJobResult != null && addJobResult.getString("msg") != null){
|
|
|
|
|
+ msg = addJobResult.getString("msg");
|
|
|
|
|
+ }
|
|
|
|
|
+ log.error("任务添加失败,{}",msg);
|
|
|
|
|
+ throw new CommonException("任务添加失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|