package com.fy.camunda.back.service;
/**
* @ClassName TimerDefinitionProcess
* @author: maliang
* @Description 处理接口
* @date 2022/2/8 9:21
* @Version 1.0版本
*/
public interface TimerDefinitionProcess {
String Process(Integer value);
}
package com.fy.camunda.back.service.impl;
import com.fy.camunda.back.service.TimerDefinitionProcess;
/**
* @ClassName DefinitionTypeDate
* @author: maliang
* @Description 日期处理
* @date 2022/2/8 9:23
* @Version 1.0版本
*/
public class DefinitionDate implements TimerDefinitionProcess {
@Override
public String Process(Integer value) {
return "PD" + value + "S";
}
}
package com.fy.camunda.back.service.impl;
import com.fy.camunda.back.service.TimerDefinitionProcess;
/**
* @ClassName DefinitionDuration
* @author: maliang
* @Description 毫秒值处理
* @date 2022/2/8 9:23
* @Version 1.0版本
*/
public class DefinitionDuration implements TimerDefinitionProcess {
@Override
public String Process(Integer value) {
return "PT" + value + "S";
}
}
package com.fy.camunda.common.factory;
import com.fy.camunda.back.service.TimerDefinitionProcess;
import com.fy.camunda.back.service.impl.DefinitionDate;
import com.fy.camunda.back.service.impl.DefinitionDuration;
import java.util.HashMap;
import java.util.Map;
/**
* @ClassName TimerDefinitionFactory
* @author: maliang
* @Description 超时表达式处理工厂类
* @date 2022/2/8 9:20
* @Version 1.0版本
*/
public class TimerDefinitionFactory {
/**
* 缓存
*/
private static final Map<Integer, TimerDefinitionProcess> TIMER_DEFINITION_PROCESS_MAP = new HashMap<>(3);
private TimerDefinitionFactory() {
}
static {
TIMER_DEFINITION_PROCESS_MAP.put(1, new DefinitionDate());
TIMER_DEFINITION_PROCESS_MAP.put(2, new DefinitionDuration());
}
public static TimerDefinitionProcess getMethod(Integer type) {
return TIMER_DEFINITION_PROCESS_MAP.get(type);
}
}
package com.fy.camunda.common.utils;
import com.fy.camunda.back.service.TimerDefinitionProcess;
import com.fy.camunda.common.factory.TimerDefinitionFactory;
import org.springframework.stereotype.Component;
/**
* @ClassName TimerDefinitionContext
* @author: maliang
* @Description 用户使用类
* @date 2022/2/8 9:29
* @Version 1.0版本
*/
@Component
public class TimerDefinitionContext {
private TimerDefinitionProcess timerDefinitionProcess;
public String getDefinition(Integer value) {
return timerDefinitionProcess.Process(value);
}
public TimerDefinitionContext definitionMethod(Integer type) {
this.timerDefinitionProcess = TimerDefinitionFactory.getMethod(type);
return this;
}
}
使用时直接对TimerDefinitionContext @resouces就行
String definition = timerDefinitionContext.definitionMethod(reqTimer.getTimerDefinitionType()).getDefinition(reqTimer.getUserInput());