|
@@ -1,10 +1,11 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.task.service.job;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.JsonMapper;
|
|
|
import cn.com.qmth.examcloud.support.CacheConstants;
|
|
|
import cn.com.qmth.examcloud.web.exception.SequenceLockException;
|
|
|
import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -55,26 +56,38 @@ public class ClearExpireDataJobHandler {
|
|
|
}
|
|
|
|
|
|
private void handler(String jobParam) {
|
|
|
- int days = 0;
|
|
|
- if (StringUtils.isNotBlank(jobParam)) {
|
|
|
- days = Integer.parseInt(jobParam.trim());
|
|
|
- }
|
|
|
+ // jobParam --> {"expireDays":30,"clearError":false}
|
|
|
+ int expireDays = 0;
|
|
|
+ boolean clearError = false;
|
|
|
+
|
|
|
+ JsonNode jsonParams = new JsonMapper().getNode(jobParam);
|
|
|
+ if (jsonParams != null) {
|
|
|
+ JsonNode expireDaysNode = jsonParams.get("expireDays");
|
|
|
+ if (expireDaysNode != null) {
|
|
|
+ expireDays = expireDaysNode.asInt();
|
|
|
+ }
|
|
|
|
|
|
- boolean ignoreStatus = (days == -1);
|
|
|
+ JsonNode clearErrorNode = jsonParams.get("clearError");
|
|
|
+ if (clearErrorNode != null) {
|
|
|
+ clearError = clearErrorNode.asBoolean();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 默认:最少30天
|
|
|
- days = Math.max(days, 30);
|
|
|
+ // 限制最少30天
|
|
|
+ expireDays = Math.max(expireDays, 30);
|
|
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
c.setTime(new Date());
|
|
|
- c.add(Calendar.DATE, -days);
|
|
|
+ c.add(Calendar.DATE, -expireDays);
|
|
|
String expireTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
|
|
|
|
|
|
// 获取总数
|
|
|
StringBuilder countSql = new StringBuilder();
|
|
|
countSql.append(" select count(1) from ec_oes_exam_record_data");
|
|
|
countSql.append(" where 1=1");
|
|
|
- if (!ignoreStatus) {
|
|
|
+ if (clearError) {
|
|
|
+ countSql.append(" and exam_record_status = 'EXAM_ERROR'");
|
|
|
+ } else {
|
|
|
countSql.append(" and sync_status = 'SYNCED'");
|
|
|
}
|
|
|
countSql.append(" and creation_time <= '").append(expireTime).append("'");
|
|
@@ -88,7 +101,9 @@ public class ClearExpireDataJobHandler {
|
|
|
StringBuilder querySql = new StringBuilder();
|
|
|
querySql.append(" select id from ec_oes_exam_record_data");
|
|
|
querySql.append(" where id > %s");
|
|
|
- if (!ignoreStatus) {
|
|
|
+ if (clearError) {
|
|
|
+ querySql.append(" and exam_record_status = 'EXAM_ERROR'");
|
|
|
+ } else {
|
|
|
querySql.append(" and sync_status = 'SYNCED'");
|
|
|
}
|
|
|
querySql.append(" and creation_time <= '").append(expireTime).append("'");
|