Commit 5ea958f0 by shentao

Merge branch 'feature' into 'release'

2024/05/06 模板匹配修复、转移模板添加分布式锁

See merge request !98
parents 124c9504 f3bcd67a
...@@ -9,7 +9,8 @@ public enum TaskType { ...@@ -9,7 +9,8 @@ public enum TaskType {
TEMPLATE_RECORD("template_record", null, "模板特征值清除记录任务"), TEMPLATE_RECORD("template_record", null, "模板特征值清除记录任务"),
TEMPLATE_CLEAR_RETRY("template_clear_retry", null, "模板重置模板重试任务"), TEMPLATE_CLEAR_RETRY("template_clear_retry", null, "模板重置模板重试任务"),
TEMPLATE_LOST_RESET("template_lost_reset", null, "过期重置模板清除任务"), TEMPLATE_LOST_RESET("template_lost_reset", null, "过期重置模板清除任务"),
TEMPLATE_DAY_CLEAR("template_day_clear", null, "模板每日清除任务"); TEMPLATE_DAY_CLEAR("template_day_clear", null, "模板每日清除任务"),
TEMPLATE_LOST_REMOVE("template_lost_remove", null, "过期模板清除任务");
final String type; final String type;
......
...@@ -88,6 +88,8 @@ public class ScheduledMission { ...@@ -88,6 +88,8 @@ public class ScheduledMission {
AutoTask autoTask = new AutoTask(TaskType.TEMPLATE_DAY_CLEAR.getType(), project, startTime, endTime); AutoTask autoTask = new AutoTask(TaskType.TEMPLATE_DAY_CLEAR.getType(), project, startTime, endTime);
log.info("任务类型:{},项目:{},开始时间:{},结束时间:{}已创建", autoTask.getType(), autoTask.getGroup(),startTime, endTime); log.info("任务类型:{},项目:{},开始时间:{},结束时间:{}已创建", autoTask.getType(), autoTask.getGroup(),startTime, endTime);
TaskManager.getInstance().putTask(autoTask); TaskManager.getInstance().putTask(autoTask);
// 过期模板删除
TaskManager.getInstance().putTask(new AutoTask(TaskType.TEMPLATE_LOST_REMOVE.getType(), project));
} }
} catch (Exception e) { } catch (Exception e) {
log.error("模板每日清除任务构建失败", e); log.error("模板每日清除任务构建失败", e);
......
...@@ -20,6 +20,7 @@ import org.springframework.data.mongodb.core.query.Query; ...@@ -20,6 +20,7 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -27,6 +28,9 @@ public class TemplateTitleServiceImpl implements TemplateTitleService { ...@@ -27,6 +28,9 @@ public class TemplateTitleServiceImpl implements TemplateTitleService {
private static final Logger log = LogManager.getLogger(TemplateTitleServiceImpl.class); private static final Logger log = LogManager.getLogger(TemplateTitleServiceImpl.class);
private static final Pattern SYMBOL_PATTERN = Pattern
.compile("[\\p{P}+~$`^=丨|<>~`$^+=|<>¥×\\s\u200B\u200C\u200D\u00A0\u0020\u3000]");
private final RedissonUtil redissonUtil; private final RedissonUtil redissonUtil;
private final TemplateRecordDao templateRecordDao; private final TemplateRecordDao templateRecordDao;
...@@ -138,6 +142,7 @@ public class TemplateTitleServiceImpl implements TemplateTitleService { ...@@ -138,6 +142,7 @@ public class TemplateTitleServiceImpl implements TemplateTitleService {
res.put("errorMessage", "该项目组未有聚合集"); res.put("errorMessage", "该项目组未有聚合集");
return res; return res;
} }
title = filterSymbol(title);
TemplateTitleVo titleVo = null; TemplateTitleVo titleVo = null;
double similarity = 0.0; double similarity = 0.0;
for (Map.Entry<String, TemplateTitleVo> entry : templateTitleVoMap.entrySet()) { for (Map.Entry<String, TemplateTitleVo> entry : templateTitleVoMap.entrySet()) {
...@@ -190,4 +195,17 @@ public class TemplateTitleServiceImpl implements TemplateTitleService { ...@@ -190,4 +195,17 @@ public class TemplateTitleServiceImpl implements TemplateTitleService {
} }
return Tools.restoreTMap(mapValue, TemplateTitleVo.class); return Tools.restoreTMap(mapValue, TemplateTitleVo.class);
} }
/**
* 过滤掉标题里面的标点符号
*
* @param title 标题
* @return 去除特殊符号后的标题
*/
private String filterSymbol(String title) {
if (null != title) {
return SYMBOL_PATTERN.matcher(title).replaceAll("");
}
return null;
}
} }
...@@ -32,6 +32,6 @@ public class TaskPoolConfig { ...@@ -32,6 +32,6 @@ public class TaskPoolConfig {
@Bean("templateExecutor") @Bean("templateExecutor")
public ThreadPoolExecutorTimeout templateExecutor() { public ThreadPoolExecutorTimeout templateExecutor() {
return new ThreadPoolExecutorTimeout(1000L * 60 * 30, 32, 32,10000L, return new ThreadPoolExecutorTimeout(1000L * 60 * 30, 32, 32,10000L,
TimeUnit.MILLISECONDS, 400, "模板任务线程池"); TimeUnit.MILLISECONDS, 1000, "模板任务线程池");
} }
} }
...@@ -95,4 +95,10 @@ public interface TemplateTitleService { ...@@ -95,4 +95,10 @@ public interface TemplateTitleService {
* @param templateTitleVo 模板 * @param templateTitleVo 模板
*/ */
void transferTemplate(String group, TemplateTitleVo templateTitleVo); void transferTemplate(String group, TemplateTitleVo templateTitleVo);
/**
* 过期模板清除
* @param group 项目
*/
void lostTemplateRemove(String group);
} }
...@@ -188,6 +188,7 @@ public class TemplateTitleServiceImpl implements TemplateTitleService { ...@@ -188,6 +188,7 @@ public class TemplateTitleServiceImpl implements TemplateTitleService {
public void transferTemplate(String group, TemplateTitleVo templateTitleVo) { public void transferTemplate(String group, TemplateTitleVo templateTitleVo) {
String lockKey = Tools.assembleKey(GenericAttribute.LOCK, templateTitleVo.getTemplateTitle()); String lockKey = Tools.assembleKey(GenericAttribute.LOCK, templateTitleVo.getTemplateTitle());
try { try {
redissonUtil.tryLock(lockKey, 5, 5);
templateTitleVo.setDaySum(0L); templateTitleVo.setDaySum(0L);
redissonUtil.setMapValue(Tools.assembleKey(GenericAttribute.REDIS_MAP_LOSE_KEY, group), templateTitleVo.getTemplateTitle(), JSONObject.toJSONString(templateTitleVo)); redissonUtil.setMapValue(Tools.assembleKey(GenericAttribute.REDIS_MAP_LOSE_KEY, group), templateTitleVo.getTemplateTitle(), JSONObject.toJSONString(templateTitleVo));
redissonUtil.removeMapValue(Tools.assembleKey(GenericAttribute.REDIS_MAP_KEY, group), templateTitleVo.getTemplateTitle()); redissonUtil.removeMapValue(Tools.assembleKey(GenericAttribute.REDIS_MAP_KEY, group), templateTitleVo.getTemplateTitle());
...@@ -198,6 +199,19 @@ public class TemplateTitleServiceImpl implements TemplateTitleService { ...@@ -198,6 +199,19 @@ public class TemplateTitleServiceImpl implements TemplateTitleService {
} }
} }
@Override
public void lostTemplateRemove(String group) {
List<String> removeKey = new ArrayList<>();
for (Map.Entry<String, TemplateTitleVo> entry : getTemplateTitleByProjectLost(group).entrySet()) {
if (entry.getValue().getStatus().equals(TemplateStatus.待删除)) {
removeKey.add(entry.getKey());
}
}
for (String key : removeKey) {
redissonUtil.removeMapValue(Tools.assembleKey(GenericAttribute.REDIS_MAP_LOSE_KEY, group), key);
}
}
private void setTemplateValue(String group, String title, TemplateTitleVo templateTitleVo, String fixTag, Long daySum) { private void setTemplateValue(String group, String title, TemplateTitleVo templateTitleVo, String fixTag, Long daySum) {
String lockKey = Tools.assembleKey(GenericAttribute.LOCK, title); String lockKey = Tools.assembleKey(GenericAttribute.LOCK, title);
try { try {
......
...@@ -170,7 +170,7 @@ public class TaskServiceCommon extends BaseTaskTypePair<TaskServiceCommon.TaskCo ...@@ -170,7 +170,7 @@ public class TaskServiceCommon extends BaseTaskTypePair<TaskServiceCommon.TaskCo
try { try {
entry.getValue().setDaySum(0L); entry.getValue().setDaySum(0L);
} catch (Exception e) { } catch (Exception e) {
log.error("模板初始化失败:{},", entry, e); log.debug("模板初始化失败:{},", entry, e);
removeKey.add(entry.getKey()); removeKey.add(entry.getKey());
} }
} }
......
...@@ -74,6 +74,7 @@ public class TaskServiceTemplate extends BaseTaskTypePair<TaskServiceTemplate.Ta ...@@ -74,6 +74,7 @@ public class TaskServiceTemplate extends BaseTaskTypePair<TaskServiceTemplate.Ta
taskCache(TaskType.TEMPLATE_RECORD, this::templateRecordClean); taskCache(TaskType.TEMPLATE_RECORD, this::templateRecordClean);
taskCache(TaskType.TEMPLATE_LOST_RESET, this::templateLost); taskCache(TaskType.TEMPLATE_LOST_RESET, this::templateLost);
taskCache(TaskType.TEMPLATE_DAY_CLEAR, this::templateDayClear); taskCache(TaskType.TEMPLATE_DAY_CLEAR, this::templateDayClear);
taskCache(TaskType.TEMPLATE_LOST_REMOVE, this::templateLostRemove);
} }
@Override @Override
...@@ -166,6 +167,10 @@ public class TaskServiceTemplate extends BaseTaskTypePair<TaskServiceTemplate.Ta ...@@ -166,6 +167,10 @@ public class TaskServiceTemplate extends BaseTaskTypePair<TaskServiceTemplate.Ta
autoTask.getParamSource().getLong(GenericAttribute.START_PARAM), autoTask.getParamSource().getLong(GenericAttribute.END_PARAM)); autoTask.getParamSource().getLong(GenericAttribute.START_PARAM), autoTask.getParamSource().getLong(GenericAttribute.END_PARAM));
} }
private void templateLostRemove(AutoTask autoTask) {
templateTitleService.lostTemplateRemove(autoTask.getGroup());
}
/** /**
* 查询该项目 指定时间范围的数据 * 查询该项目 指定时间范围的数据
* @param mgroup 项目 * @param mgroup 项目
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment