提交 2382fceb 编写于 作者: sq3536's avatar sq3536

modify

上级 4cf81844
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.extensions.domain.BaseRequest;
import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.rule.domain.ExecLog;
import cn.ibizlab.util.errors.BadRequestAlertException;
......@@ -12,6 +13,6 @@ import java.sql.Timestamp;
public interface BaseEntityService {
void reset(String keyContainer);
ExecLog processAll(BadRequestAlertException msg);
void saveResult(ModelObj param, String RULECODE, String RULENAME, String RU_EXECRESULTNAME, String BUSINESSCAT, Integer RETVALUE, String KEYVALUEFIELD, String DOMAINSFIELD, Double METRICFIELD, Timestamp TIMEFIELD, String EXT1FIELD, String EXT2FIELD);
ExecLog processAll(BaseRequest msg);
void saveResult(ModelObj param, String RULECODE, String RULENAME, String RU_EXECRESULTNAME, String BUSINESSCAT, Integer RETVALUE, Object KEYVALUEFIELD, Object DOMAINSFIELD,Object DIMFIELD, Object METRICFIELD, Timestamp TIMEFIELD, Object EXT1FIELD, Object EXT2FIELD);
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.extensions.domain.BaseRequest;
import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.rule.domain.ExecLog;
import cn.ibizlab.core.rule.domain.ExecResult;
import cn.ibizlab.core.rule.service.IExecLogService;
import cn.ibizlab.core.rule.service.IExecResultService;
import cn.ibizlab.util.errors.BadRequestAlertException;
......@@ -24,6 +25,8 @@ import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Hashtable;
......@@ -35,7 +38,7 @@ import java.util.List;
@Service
@Primary
@Slf4j
public class BaseEntityServiceImpl
public class BaseEntityServiceImpl implements BaseEntityService
{
public BaseEntityServiceImpl()
......@@ -46,10 +49,76 @@ public class BaseEntityServiceImpl
}
public void saveResult(ModelObj param, String RULECODE, String RULENAME, String RU_EXECRESULTNAME, String BUSINESSCAT, Integer RETVALUE, String KEYVALUEFIELD, String DOMAINSFIELD, Double METRICFIELD,
Timestamp TIMEFIELD, String EXT1FIELD, String EXT2FIELD)
public void saveResult(ModelObj param, String RULECODE, String RULENAME, String RU_EXECRESULTNAME, String BUSINESSCAT, Integer RETVALUE,
Object KEYVALUEFIELD, Object DOMAINSFIELD,Object DIMFIELD, Object METRICFIELD, Timestamp TIMEFIELD, Object EXT1FIELD, Object EXT2FIELD)
{
ExecResult result=new ExecResult();
result.setRuleId(RULECODE);
result.setRuleName(RULENAME);
result.setName(RU_EXECRESULTNAME);
result.setBusinessCat(BUSINESSCAT);
result.setRetValue(RETVALUE);
if(KEYVALUEFIELD==null)
{
result.setKeyValueField(param.getRowKey());
}
else
{
result.setKeyValueField(KEYVALUEFIELD.toString());
}
if(METRICFIELD!=null) {
Object val = METRICFIELD;
if ( (val instanceof BigDecimal))
result.setMetricField(((BigDecimal) val));
else if ( (val instanceof BigInteger))
result.setMetricField(new BigDecimal((BigInteger) val));
else if ( (val instanceof Double))
result.setMetricField(new BigDecimal((Double) val));
else if ( (val instanceof Float))
result.setMetricField(new BigDecimal(((Float) val).doubleValue()));
else if ( (val instanceof Long))
result.setMetricField(new BigDecimal((Long) val));
else if ( (val instanceof Integer))
result.setMetricField(new BigDecimal((int)val));
else
result.setMetricField(new BigDecimal(1));
}
else
result.setMetricField(new BigDecimal(0));
if(DOMAINSFIELD!=null)
{
result.setDomainsField(DOMAINSFIELD.toString());
}
else
{
result.setDomainsField(KEYVALUEFIELD.toString());
}
if(DIMFIELD!=null)
{
result.setDimField(DIMFIELD.toString());
}
else
{
result.setDimField(KEYVALUEFIELD.toString());
}
if(TIMEFIELD!=null&&TIMEFIELD instanceof Timestamp)
result.setTimeField((Timestamp)TIMEFIELD);
if(EXT1FIELD!=null)
result.setExt1Field(EXT1FIELD.toString());
if(EXT2FIELD!=null)
result.setExt2Field(EXT2FIELD.toString());
result.setId(result.getDefaultKey(true).toString());
if(result.getRetValue()==1)
{
ruExecResultService.save(result);
}
else
{
ruExecResultService.remove(result.getId());
}
}
@Autowired
......
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.extensions.domain.BaseRequest;
import cn.ibizlab.core.lite.extensions.service.DbEntityService;
import cn.ibizlab.core.rule.domain.ExecLog;
import cn.ibizlab.core.rule.domain.RuleItem;
import cn.ibizlab.core.rule.filter.RuleItemSearchContext;
import cn.ibizlab.core.rule.service.IRuleItemService;
import cn.ibizlab.core.rule.service.impl.RuleEngineServiceImpl;
import cn.ibizlab.util.helper.CachedBeanCopier;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.core.rule.domain.RuleEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary;
import org.springframework.util.StringUtils;
import java.io.File;
import java.util.*;
/**
......@@ -21,6 +35,17 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
}
@Autowired
private DbEntityService dbEntityService;
@Autowired
private IRuleItemService ruleItemService;
@Autowired
private BaseEntityService baseEntityService;
@Value("${ibiz.rulepath:/app/file/rules/}")
private String rulePath;
/**
* [Run:运行] 行为扩展
* @param et
......@@ -29,6 +54,45 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
@Override
@Transactional
public RuleEngine run(RuleEngine et) {
if(!StringUtils.isEmpty(et.getEngineId()))
{
CachedBeanCopier.copy(get(et.getEngineId()), et);
if(!StringUtils.isEmpty(et.getModelId()))
{
BaseRequest msg=new BaseRequest();
msg.setId(IdWorker.getIdStr());
msg.setModel(et.getModelName());
java.sql.Timestamp starttime = new java.sql.Timestamp(System.currentTimeMillis());
msg.setDatas(dbEntityService.getModelObjs(et.getModelId(),et.getLastRuntime()));
List<String> rules = new ArrayList<>();
ruleItemService.list(Wrappers.<RuleItem>lambdaQuery()
.select(RuleItem::getRuleId).eq(RuleItem::getModelId,et.getModelId()).ne(RuleItem::getGroup,"REP").like(RuleItem::getGroup,et.getGroup()))
.forEach(ruleItem -> {
String path=rulePath + et.getGroup() + File.separator + ruleItem.getRuleId() + ".drl";
File file=new File(path);
if(file.exists())
{
rules.add(path);
}
});
msg.setRules(rules);
ExecLog execlog = baseEntityService.processAll(msg);
if (execlog.getRetCode() != 0)
return et;
et.setLastRuntime(starttime);
this.update(et);
}
}
return super.run(et);
}
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册