16 changed files with 485 additions and 3 deletions
@ -0,0 +1,11 @@ |
|||
package io.sc.engine.mv; |
|||
|
|||
/** |
|||
* 模型验证执行模式 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public enum ExecuteMode { |
|||
MANUAL, //手工执行
|
|||
BATCH; //自动跑批执行
|
|||
} |
@ -0,0 +1,50 @@ |
|||
package io.sc.engine.mv; |
|||
|
|||
import java.util.Locale; |
|||
|
|||
import io.sc.platform.core.support.ProgressInfo; |
|||
import org.springframework.core.Ordered; |
|||
|
|||
/** |
|||
* 模型验证执行者 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
public interface Executor extends Ordered,ProgressTracker{ |
|||
/** |
|||
* 获取执行器类名称 |
|||
* @return 执行器类名称 |
|||
*/ |
|||
public String getClassName(); |
|||
|
|||
/** |
|||
* 获取执行器名称的多语言消息Key |
|||
* @return 执行器名称的多语言消息Key |
|||
*/ |
|||
public String getNameI18nKey(); |
|||
|
|||
/** |
|||
* 获取执行器描述的多语言消息Key |
|||
* @return 执行器描述的多语言消息Key |
|||
*/ |
|||
public String getDescriptionI18nKey(); |
|||
|
|||
/** |
|||
* 获取是否可用 |
|||
* @return 是否可用 |
|||
*/ |
|||
public boolean isEnable(); |
|||
|
|||
/** |
|||
* 设置是否可用 |
|||
* @param enable 是否可用 |
|||
*/ |
|||
public void setEnable(boolean enable); |
|||
|
|||
/** |
|||
* 执行验证 |
|||
* @param runtimeContext 模型验证执行上下文对象 |
|||
* @param progressInfo 执行进度信息对象 |
|||
*/ |
|||
public void execute(RuntimeContext runtimeContext, ProgressInfo progressInfo); |
|||
} |
@ -0,0 +1,79 @@ |
|||
package io.sc.engine.mv; |
|||
|
|||
import io.sc.platform.core.support.OrderedItemRegister; |
|||
import io.sc.platform.core.support.ProgressInfo; |
|||
import io.sc.platform.jdbc.util.SqlUtil; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.List; |
|||
import java.util.Locale; |
|||
|
|||
/** |
|||
* 模型验证执行者管理器 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@Component("mvExecutorManager") |
|||
public class ExecutorManager extends OrderedItemRegister<Executor> { |
|||
private static final Logger log =LoggerFactory.getLogger(ExecutorManager.class); |
|||
@Autowired protected JdbcTemplate jdbcTemplate; |
|||
|
|||
public int getTotalWeight(){ |
|||
int totalExecuteTimeWeight =0; |
|||
List<Executor> executors =this.getItems(); |
|||
if(executors!=null && executors.size()>0){ |
|||
for(Executor executor : executors){ |
|||
if(executor.isEnable()){ |
|||
totalExecuteTimeWeight +=executor.getExecuteTimeWeight(); |
|||
} |
|||
} |
|||
} |
|||
return totalExecuteTimeWeight; |
|||
} |
|||
|
|||
public void execute(RuntimeContext runtimeContext, ProgressInfo progressInfo, Locale locale){ |
|||
checkConfiguration(runtimeContext); |
|||
List<Executor> executors =this.getItems(); |
|||
if(executors!=null && executors.size()>0){ |
|||
for(Executor executor : executors){ |
|||
if(executor.isEnable()){ |
|||
String name =executor.getNameI18nKey(); |
|||
String message ="开始执行模型验证[" + name + "]..."; |
|||
log.info(message); |
|||
progressInfo.setMessageKey(message); |
|||
executor.execute(runtimeContext,progressInfo); |
|||
message ="结束执行模型验证[" + name + "]"; |
|||
log.info(message); |
|||
progressInfo.setMessageKey(message); |
|||
progressInfo.addWeight(executor.getExecuteTimeWeight()); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 检查是否存在必须的配置 |
|||
* @return 是否通过检查 |
|||
*/ |
|||
private boolean checkConfiguration(RuntimeContext runtimeContext){ |
|||
return checkCutOffPointConfiguration(runtimeContext); |
|||
} |
|||
|
|||
/** |
|||
* 检查截断点是否已经配置 |
|||
* @return 是否通过检查 |
|||
*/ |
|||
private boolean checkCutOffPointConfiguration(RuntimeContext runtimeContext){ |
|||
String sql ="select count(*) count from MV_CFG_CUT_OFF_POINT"; |
|||
long count = SqlUtil.count(jdbcTemplate, "count", sql); |
|||
if(count>0){ |
|||
return true; |
|||
}else{ |
|||
throw new RuntimeException("未找到截断点配置信息,请通过“系统管理”菜单的“系统参数配置”菜单中的“模型验证参数配置”的“截断点配置”功能进行配置后,再重试."); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,115 @@ |
|||
package io.sc.engine.mv.controller; |
|||
|
|||
import java.util.Date; |
|||
import java.util.Locale; |
|||
|
|||
import io.sc.engine.mv.RuntimeContext; |
|||
import io.sc.engine.mv.Validator; |
|||
import io.sc.platform.core.support.ProgressInfo; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.context.MessageSource; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestMethod; |
|||
import org.springframework.web.bind.annotation.ResponseBody; |
|||
|
|||
/** |
|||
* 模型验证执行控制器 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
@Controller |
|||
@RequestMapping("/api/mv") |
|||
public class ExecuteValidatorWebController { |
|||
@Autowired private Validator validator; |
|||
@Autowired private MessageSource messageSource; |
|||
private ValidateThread thread =null; |
|||
|
|||
/** |
|||
* 菜单贡献项(手工执行模型验证) |
|||
* @return 视图名称 |
|||
* @throws Exception 违例 |
|||
*/ |
|||
@RequestMapping("execute.html") |
|||
public String execute() throws Exception{ |
|||
return "org/wsp/model/validator/view/execute.html"; |
|||
} |
|||
|
|||
/** |
|||
* 执行模型验证 |
|||
* @param runtimeContext 模型验证执行上下文对象 |
|||
* @param locale 区域 |
|||
* @throws Exception 违例 |
|||
*/ |
|||
@RequestMapping(value="execute",method=RequestMethod.POST) |
|||
@ResponseBody |
|||
public void execute(@RequestBody RuntimeContext runtimeContext, Locale locale) throws Exception{ |
|||
//检查有当前用户启动的执行线程是否正在运行
|
|||
if(thread!=null && thread.isAlive()){ |
|||
String message =messageSource.getMessage("org.wsp.model.validator.i18n.execute.exception.running", null, locale); |
|||
throw new Exception(message); |
|||
} |
|||
//启动新线程
|
|||
runtimeContext.setValidateDate(new Date()); |
|||
thread =new ValidateThread(runtimeContext,locale); |
|||
thread.start(); |
|||
} |
|||
|
|||
/** |
|||
* 查询模型验证执行进度 |
|||
* @param locale 区域 |
|||
* @return 模型验证执行进度 |
|||
* @throws Exception 违例 |
|||
*/ |
|||
@RequestMapping(value="traceExecuteProgress") |
|||
@ResponseBody |
|||
public ProgressInfo traceExecuteProgress(Locale locale) throws Exception{ |
|||
if(thread!=null){ |
|||
if(thread.getException()!=null){ |
|||
throw thread.getException(); |
|||
} |
|||
return thread.getProgressInfo(); |
|||
}else{ |
|||
String message =messageSource.getMessage("org.wsp.model.validator.i18n.execute.exception.notExsists", null, locale); |
|||
throw new Exception(message); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 模型验证执行线程 |
|||
* @author wangshaoping |
|||
* |
|||
*/ |
|||
class ValidateThread extends Thread{ |
|||
private Logger log =LoggerFactory.getLogger(ValidateThread.class); |
|||
private RuntimeContext runtimeContext; |
|||
private Locale locale; |
|||
private ProgressInfo progressInfo =new ProgressInfo(); |
|||
private Exception exception; |
|||
|
|||
public ValidateThread(RuntimeContext runtimeContext,Locale locale){ |
|||
this.runtimeContext =runtimeContext; |
|||
this.locale =locale; |
|||
} |
|||
@Override |
|||
public void run() { |
|||
if(validator!=null){ |
|||
try { |
|||
validator.validate(runtimeContext,progressInfo,locale); |
|||
} catch (Exception e) { |
|||
this.exception =e; |
|||
log.error("",e); |
|||
} |
|||
} |
|||
} |
|||
public ProgressInfo getProgressInfo(){ |
|||
return progressInfo; |
|||
} |
|||
public Exception getException() { |
|||
return exception; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
package io.sc.engine.mv.executor.support; |
|||
|
|||
import java.sql.ResultSet; |
|||
import java.sql.SQLException; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.jdbc.core.RowCallbackHandler; |
|||
|
|||
public class ExecutorUtil{ |
|||
public static Map<String,String> getAllModels(JdbcTemplate jdbcTemplate){ |
|||
final Map<String,String> result =new HashMap<String,String>(); |
|||
String sql ="" |
|||
+ " select" |
|||
+ " FD_MODEL_ID," |
|||
+ " max(FD_MODEL_NAME) FD_MODEL_NAME" |
|||
+ " from MV_GENERAL_SAMPLE" |
|||
+ " group by FD_MODEL_ID"; |
|||
jdbcTemplate.query(sql, new RowCallbackHandler() { |
|||
@Override |
|||
public void processRow(ResultSet rs) throws SQLException { |
|||
result.put(rs.getString("FD_MODEL_ID"), rs.getString("FD_MODEL_NAME")); |
|||
} |
|||
}); |
|||
return result; |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
package io.sc.engine.mv.executor.support; |
|||
|
|||
public class ExecutorWrapper { |
|||
private String clazz; |
|||
private String name; |
|||
private String description; |
|||
private Boolean enable; |
|||
private Integer order; |
|||
public String getClazz() { |
|||
return clazz; |
|||
} |
|||
public void setClazz(String clazz) { |
|||
this.clazz = clazz; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
public void setDescription(String description) { |
|||
this.description = description; |
|||
} |
|||
public Boolean getEnable() { |
|||
return enable; |
|||
} |
|||
public void setEnable(Boolean enable) { |
|||
this.enable = enable; |
|||
} |
|||
public Integer getOrder() { |
|||
return order; |
|||
} |
|||
public void setOrder(Integer order) { |
|||
this.order = order; |
|||
} |
|||
} |
@ -0,0 +1,2 @@ |
|||
io.sc.engine.mv.ModelType.IMPORT_FROM_SCORE_RECORD=Import From Score Record |
|||
io.sc.engine.mv.ModelType.MANUAL=Manual |
@ -0,0 +1,2 @@ |
|||
io.sc.engine.mv.ModelType.IMPORT_FROM_SCORE_RECORD=\u5F9E\u8A55\u5206\u8A18\u9304\u8868\u4E2D\u5C0E\u5165 |
|||
io.sc.engine.mv.ModelType.MANUAL=\u624B\u5DE5\u5275\u5EFA |
@ -0,0 +1,2 @@ |
|||
io.sc.engine.mv.ModelType.IMPORT_FROM_SCORE_RECORD=\u4ECE\u8BC4\u5206\u8BB0\u5F55\u8868\u4E2D\u5BFC\u5165 |
|||
io.sc.engine.mv.ModelType.MANUAL=\u624B\u5DE5\u521B\u5EFA |
@ -0,0 +1,49 @@ |
|||
package io.sc.platform.data.db; |
|||
|
|||
public class FieldMapper { |
|||
private String sourceName; |
|||
private Class<?> sourceType; |
|||
private String targetName; |
|||
private Class<?> targetType; |
|||
|
|||
public FieldMapper(){} |
|||
public FieldMapper(String sourceName,Class<?> sourceType,String targetName,Class<?> targetType){ |
|||
this.sourceName =sourceName; |
|||
this.sourceType =sourceType; |
|||
this.targetName =targetName; |
|||
this.targetType =targetType; |
|||
} |
|||
|
|||
|
|||
public String getSourceName() { |
|||
return sourceName; |
|||
} |
|||
|
|||
public void setSourceName(String sourceName) { |
|||
this.sourceName = sourceName; |
|||
} |
|||
|
|||
public Class<?> getSourceType() { |
|||
return sourceType; |
|||
} |
|||
|
|||
public void setSourceType(Class<?> sourceType) { |
|||
this.sourceType = sourceType; |
|||
} |
|||
|
|||
public String getTargetName() { |
|||
return targetName; |
|||
} |
|||
|
|||
public void setTargetName(String targetName) { |
|||
this.targetName = targetName; |
|||
} |
|||
|
|||
public Class<?> getTargetType() { |
|||
return targetType; |
|||
} |
|||
|
|||
public void setTargetType(Class<?> targetType) { |
|||
this.targetType = targetType; |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
package io.sc.platform.developer.wrapper.springboot; |
|||
|
|||
public class EnvironmentWrapper { |
|||
private String propertySourceName; |
|||
private String propertyName; |
|||
private String origin; |
|||
private Object value; |
|||
|
|||
public String getPropertySourceName() { |
|||
return propertySourceName; |
|||
} |
|||
public void setPropertySourceName(String propertySourceName) { |
|||
this.propertySourceName = propertySourceName; |
|||
} |
|||
public String getPropertyName() { |
|||
return propertyName; |
|||
} |
|||
public void setPropertyName(String propertyName) { |
|||
this.propertyName = propertyName; |
|||
} |
|||
public String getOrigin() { |
|||
return origin; |
|||
} |
|||
public void setOrigin(String origin) { |
|||
this.origin = origin; |
|||
} |
|||
public Object getValue() { |
|||
return value; |
|||
} |
|||
public void setValue(Object value) { |
|||
this.value = value; |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
package io.sc.platform.developer.wrapper.springboot; |
|||
|
|||
import io.sc.platform.core.util.StringUtil; |
|||
import org.springframework.boot.actuate.web.mappings.HandlerMethodDescription; |
|||
import org.springframework.boot.actuate.web.mappings.servlet.RequestMappingConditionsDescription.MediaTypeExpressionDescription; |
|||
import org.springframework.boot.actuate.web.mappings.servlet.RequestMappingConditionsDescription.NameValueExpressionDescription; |
|||
import org.springframework.web.bind.annotation.RequestMethod; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Collection; |
|||
import java.util.List; |
|||
import java.util.Set; |
|||
|
|||
public class FilterWrapper { |
|||
private String className; |
|||
private String patterns; |
|||
private String registeredName; |
|||
|
|||
public FilterWrapper(String registeredName,Collection<String> patterns,String className) { |
|||
this.registeredName = registeredName; |
|||
this.patterns = StringUtil.combine(",", patterns); |
|||
this.className = className; |
|||
} |
|||
|
|||
public String getClassName() { |
|||
return className; |
|||
} |
|||
|
|||
public void setClassName(String className) { |
|||
this.className = className; |
|||
} |
|||
|
|||
public String getPatterns() { |
|||
return patterns; |
|||
} |
|||
|
|||
public void setPatterns(String patterns) { |
|||
this.patterns = patterns; |
|||
} |
|||
|
|||
public String getRegisteredName() { |
|||
return registeredName; |
|||
} |
|||
|
|||
public void setRegisteredName(String registeredName) { |
|||
this.registeredName = registeredName; |
|||
} |
|||
} |
Loading…
Reference in new issue