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

commit

上级 d7aa2e7f
package cn.ibizlab.core.extensions.mapper;
import cn.ibizlab.core.lite.extensions.domain.EntityObj;
import cn.ibizlab.core.rule.domain.ExecResult;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExecResultExMapper extends BaseMapper<EntityObj>{
int replaceBatch(@Param("list") List<ExecResult> var1 , @Param("resultTableName") String tableName);
int replaceBatchByOracle(@Param("list") List<ExecResult> var1 , @Param("resultTableName") String tableName);
int clearBatch(@Param("list")List<ExecResult> var1, @Param("resultTableName") String tableName);
}
\ No newline at end of file
......@@ -48,34 +48,39 @@ public class DstDataSourceExService extends DstDataSourceServiceImpl {
@Transactional
public DstDataSource buildDS(DstDataSource dstDataSource) {
if(!(StringUtils.isEmpty(dstDataSource.getDsCfg())))
if(dstDataSource!=null&&(!StringUtils.isEmpty(dstDataSource.getDsCfg())))
{
synchronized (lock)
{
if (check.containsKey(dstDataSource.getDsName()))
return super.buildDS(dstDataSource);
DataSourceProperty dataSourceProperty = new DataSourceProperty();
DynamicRoutingDataSource ds = dataSource;
List<Setting> settings = JSONArray.parseArray(dstDataSource.getDsCfg(), Setting.class);
for (Setting setting : settings)
if(!"mongodb".equalsIgnoreCase(dstDataSource.getDsType()))
{
if (setting.getProperty().equalsIgnoreCase("driver-class-name"))
dataSourceProperty.setDriverClassName(setting.getValue());
else if (setting.getProperty().equalsIgnoreCase("username"))
dataSourceProperty.setUsername(setting.getValue());
else if (setting.getProperty().equalsIgnoreCase("password"))
dataSourceProperty.setPassword(setting.getValue());
else if (setting.getProperty().equalsIgnoreCase("url"))
dataSourceProperty.setUrl(setting.getValue());
else if (setting.getProperty().equalsIgnoreCase("defaultSchema"))
dataSourceProperty.setSchema(setting.getValue());
DataSourceProperty dataSourceProperty = new DataSourceProperty();
DynamicRoutingDataSource ds = dataSource;
List<Setting> settings = JSONArray.parseArray(dstDataSource.getDsCfg(), Setting.class);
for (Setting setting : settings)
{
if (setting.getProperty().equalsIgnoreCase("driver-class-name"))
dataSourceProperty.setDriverClassName(setting.getValue());
else if (setting.getProperty().equalsIgnoreCase("username"))
dataSourceProperty.setUsername(setting.getValue());
else if (setting.getProperty().equalsIgnoreCase("password"))
dataSourceProperty.setPassword(setting.getValue());
else if (setting.getProperty().equalsIgnoreCase("url"))
dataSourceProperty.setUrl(setting.getValue());
else if (setting.getProperty().equalsIgnoreCase("defaultSchema"))
dataSourceProperty.setSchema(setting.getValue());
}
dataSourceProperty.getDruid().setFilters("stat,log4j2");
DataSource dataSource = druidDataSourceCreator.createDataSource(dataSourceProperty);
ds.addDataSource(dstDataSource.getDsName(), dataSource);
}
dataSourceProperty.getDruid().setFilters("stat,log4j2");
DataSource dataSource = druidDataSourceCreator.createDataSource(dataSourceProperty);
ds.addDataSource(dstDataSource.getDsName(), dataSource);
check.put(dstDataSource.getDsName(), 1);
check.put(dstDataSource.getDsName(), StringUtils.isEmpty(dstDataSource.getDsType())?"mysql":dstDataSource.getDsType());
}
}
......@@ -91,25 +96,24 @@ public class DstDataSourceExService extends DstDataSourceServiceImpl {
private DataSourceCreator druidDataSourceCreator;
private HashMap<String,Integer> check=new HashMap<>();
private HashMap<String,String> check=new HashMap<>();
private Object lock=new Object();
public void initDataSource(String dsName)
public synchronized String initDataSource(String dsName)
{
DstDataSource dstDataSource=null;
synchronized (lock)
{
if (check.containsKey(dsName))
return;
return check.get(dsName);
dstDataSource=this.getOne(Wrappers.<DstDataSource>lambdaQuery().eq(DstDataSource::getDsId,dsName).or().eq(DstDataSource::getDsName,dsName),false);
if(dstDataSource!=null) dstDataSource.setDsName(dsName);
}
DstDataSource dstDataSource=this.getOne(Wrappers.<DstDataSource>lambdaQuery().eq(DstDataSource::getDsId,dsName).or().eq(DstDataSource::getDsName,dsName),false);
if(dstDataSource!=null)
buildDS(dstDataSource);
synchronized (lock)
{
dstDataSource.setDsName(dsName);
buildDS(dstDataSource);
return StringUtils.isEmpty(check.get(dsName))?"mysql":check.get(dsName);
}
}
@Override
......@@ -121,12 +125,14 @@ public class DstDataSourceExService extends DstDataSourceServiceImpl {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
if (check.containsKey(et.getDsId()))
{
ds.removeDataSource(et.getDsId());
if(!"mongodb".equalsIgnoreCase(check.get(et.getDsId())))
ds.removeDataSource(et.getDsId());
check.remove(et.getDsId());
}
if (check.containsKey(et.getDsName()))
{
ds.removeDataSource(et.getDsName());
if(!"mongodb".equalsIgnoreCase(check.get(et.getDsName())))
ds.removeDataSource(et.getDsName());
check.remove(et.getDsName());
}
}
......
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.lite.extensions.service.DbEntityService;
import cn.ibizlab.core.extensions.mapper.ExecResultExMapper;
import cn.ibizlab.core.rule.domain.ExecResult;
import cn.ibizlab.core.rule.service.IRuleEngineService;
import cn.ibizlab.core.rule.service.impl.ExecResultServiceImpl;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
......@@ -11,6 +14,9 @@ import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
import java.util.*;
/**
......@@ -21,8 +27,6 @@ import java.util.*;
@Service("ExecResultExService")
public class ExecResultExService extends ExecResultServiceImpl {
@Autowired
public DbEntityService dbEntityService;
@Autowired
@Lazy
......@@ -73,12 +77,12 @@ public class ExecResultExService extends ExecResultServiceImpl {
for (ExecResult execResult : execResults) {
tempExecResults.add(execResult);
if (tempExecResults.size() >= 500) {
dbEntityService.saveResultBatch(tempExecResults, idArray[1] , idArray[2]);
saveResultBatch(tempExecResults, idArray[1] , idArray[2]);
tempExecResults.clear();
}
}
if (tempExecResults.size() > 0) {
dbEntityService.saveResultBatch(tempExecResults, idArray[1] , idArray[2]);
saveResultBatch(tempExecResults, idArray[1] , idArray[2]);
tempExecResults.clear();
}
resultsSaveAsync.remove(execResultId);
......@@ -127,12 +131,12 @@ public class ExecResultExService extends ExecResultServiceImpl {
for (ExecResult execResult : execResults) {
tempExecResults.add(execResult);
if (tempExecResults.size() >= 500) {
dbEntityService.clearResultBatch(tempExecResults, idArray[1] , idArray[2]);
clearResultBatch(tempExecResults, idArray[1] , idArray[2]);
tempExecResults.clear();
}
}
if (tempExecResults.size() > 0) {
dbEntityService.clearResultBatch(tempExecResults, idArray[1] , idArray[2]);
clearResultBatch(tempExecResults, idArray[1] , idArray[2]);
tempExecResults.clear();
}
resultsDeleteAsync.remove(execResultId);
......@@ -172,5 +176,63 @@ public class ExecResultExService extends ExecResultServiceImpl {
}});
}
}
public static final String Default_ResultTableName = "IBZRULERESULT";
@Autowired
private DstDataSourceExService dstDataSourceService;
@Autowired
@Lazy
private DynamicRoutingDataSource dynamicRoutingDataSource;
@Autowired
private ExecResultExMapper execResultExMapper;
public int saveResultBatch(List<ExecResult> execResults, String dsName ,String tableName) {
int result = 0;
try {
if(!ObjectUtils.isEmpty(dsName) && !dsName.equalsIgnoreCase("null")){
dstDataSourceService.initDataSource(dsName);
DynamicDataSourceContextHolder.push(dsName);
}
if(StringUtils.isEmpty(tableName) || tableName.equalsIgnoreCase("null")){
tableName = Default_ResultTableName;
}
Map<String, DataSource> dynamicDSMap = dynamicRoutingDataSource.getCurrentDataSources();
if (!ObjectUtils.isEmpty(dynamicDSMap) && dynamicDSMap.containsKey(dsName)) {
DataSource ds = dynamicDSMap.get(dsName);
if (ds instanceof DruidDataSource) {
DruidDataSource druidDataSource = (DruidDataSource) dynamicDSMap.get(dsName);
if ("oracle".equals(druidDataSource.getDbType())) {
return execResultExMapper.replaceBatchByOracle(execResults, tableName);
}
}
}
result = execResultExMapper.replaceBatch(execResults, tableName);
} catch (Exception ex) {
log.error("存储规则结果发生异常,详细错误信息:" + ex.getMessage());
} finally {
DynamicDataSourceContextHolder.poll();
}
return result;
}
public int clearResultBatch(List<ExecResult> execResults, String dsName ,String tableName) {
int result = 0;
try {
dstDataSourceService.initDataSource(dsName);
DynamicDataSourceContextHolder.push(dsName);
result = execResultExMapper.clearBatch(execResults, tableName);
} catch (Exception ex) {
log.error("存储规则结果发生异常,详细错误信息:" + ex.getMessage());
} finally {
DynamicDataSourceContextHolder.poll();
}
return result;
}
}
......@@ -2,13 +2,11 @@ package cn.ibizlab.core.lite.extensions.service;
import cn.ibizlab.core.lite.extensions.domain.EntityModel;
import cn.ibizlab.core.lite.extensions.domain.EntityObj;
import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.rule.domain.ExecResult;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.util.filter.QueryFilter;
import java.sql.Timestamp;
import java.util.List;
import java.util.Set;
public interface CommonEntityService {
......@@ -20,13 +18,8 @@ public interface CommonEntityService {
List<EntityObj> search(String dsName, String sql, QueryFilter filter);
int saveResultBatch(List<ExecResult> var1);
int clearResultBatch(List<ExecResult> var1);
List<ModelObj> getModelObjs(String metaModelId, Set<String> fillPropertys, Timestamp lastModify);
ModelObj getModelObjs(String metaModelId, Set<String> fillPropertys, Object factKey);
ModelObj getModelObjs(String metaModelId, Set<String> fillPropertys, Object... factUniKey);
List<ModelObj> getModelObjs(String metaModelId, Set<String> fillPropertys, List<EntityObj> kEntityObjs);
void processList(DataModel dataModel, Timestamp lastModify, LiteDataCallback callback);
}
package cn.ibizlab.core.lite.extensions.service;
public interface LiteDataCallback<K> {
void total(Integer total);
boolean processData(K k);
}
package cn.ibizlab.core.lite.extensions.service;
import cn.ibizlab.core.extensions.domain.EngineMQMsg;
import cn.ibizlab.core.extensions.service.DstDataSourceExService;
import cn.ibizlab.core.lite.extensions.domain.EntityModel;
import cn.ibizlab.core.lite.extensions.domain.EntityObj;
import cn.ibizlab.core.lite.extensions.domain.FieldModel;
import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.lite.extensions.filter.DbEntitySearchContext;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.model.Property;
import cn.ibizlab.core.lite.service.IMetaModelService;
import cn.ibizlab.util.filter.QueryFilter;
import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.batch.MyBatisCursorItemReader;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.*;
@Slf4j
@Service
......@@ -14,5 +37,121 @@ public class LiteDataService {
@Autowired
private MongoEntityService mongoEntityService;
@Autowired
private IMetaModelService metaModelService;
@Autowired
@Lazy
private SqlSessionFactory sqlSessionFactory;
@Autowired
private DstDataSourceExService dstDataSourceService;
@Autowired
private LiteModelService liteModelService;
public CommonEntityService getEntityService(String dsId)
{
String dsType=dstDataSourceService.initDataSource(dsId);
if("mongodb".equalsIgnoreCase(dsType))
return mongoEntityService;
else
return dbEntityService;
}
public void processDataModel(String metaModelId,Timestamp lastModify,LiteDataCallback callback)
{
DataModel dataModel= JSON.toJavaObject(JSON.parseObject(metaModelService.get(metaModelId).getConfig()), DataModel.class);
EntityModel entityModel = dataModel.getFactEntityModel();
getEntityService(entityModel.getDsName()).processList(dataModel,lastModify,callback);
}
public ModelObj getModelObjs(String metaModelId, Set<String> fillPropertys, Object factKey) {
DataModel dataModel = liteModelService.getDataModel(metaModelId);
List<EntityObj> kEntityObjs = new ArrayList<>();
kEntityObjs.add(new EntityObj().set(dataModel.getFactEntityModel().getKeyField().getColumnName(), factKey));
List<ModelObj> list = getModelObjs(dataModel, fillPropertys, kEntityObjs);
if (list.size() > 0)
return list.get(0);
return null;
}
public ModelObj getModelObjs(String metaModelId, Set<String> fillPropertys, Object... factUniKey) {
DataModel dataModel = liteModelService.getDataModel(metaModelId);
List<EntityObj> kEntityObjs = new ArrayList<>();
EntityObj entityObj = new EntityObj();
List<FieldModel> uniKeys = dataModel.getFactEntityModel().getUnionKeyFields();
for (int i = 0; i < uniKeys.size(); i++)
entityObj.set(uniKeys.get(i).getColumnName(), factUniKey[i]);
kEntityObjs.add(entityObj);
List<ModelObj> list = getModelObjs(dataModel, fillPropertys, kEntityObjs);
if (list.size() > 0)
return list.get(0);
return null;
}
public List<ModelObj> getModelObjs(String metaModelId, Set<String> fillPropertys, List<EntityObj> kEntityObjs) {
DataModel dataModel = liteModelService.getDataModel(metaModelId);
return getModelObjs(dataModel, fillPropertys, kEntityObjs);
}
public List<ModelObj> getModelObjs(DataModel dataModel, Set<String> fillPropertys, List<EntityObj> kEntityObjs) {
EntityModel entityModel = dataModel.getFactEntityModel();
List<ModelObj> rt = new ArrayList<>();
List<EntityObj> factEntityList = new ArrayList<>();
if (fillPropertys == null || fillPropertys.size() == 0 || fillPropertys.contains(dataModel.getFactPorperty().getPropertyName()))
splitList(kEntityObjs, 1000).forEach(list -> factEntityList.addAll(getEntityService(entityModel.getDsName()).selectBase(entityModel, QueryFilter.createQuery().cust(dataModel.lookup(list)))));
factEntityList.forEach(entityObj ->
rt.add(new ModelObj().setDataModel(dataModel).setFactEntity(entityObj.setProperty(dataModel.getFactPorperty()))));
fillEntityObj(dataModel, fillPropertys, rt);
dataModel.getNestedDataModels().forEach(subModel ->
this.getModelObjs(subModel, fillPropertys, factEntityList).forEach(subObj -> subObj.findParent(rt)));
rt.forEach(modelObj -> modelObj.getTimestamp());
return rt;
}
public void fillEntityObj(DataModel dataModel, Set<String> fillPropertys, List<ModelObj> modelObjs) {
if (dataModel.getObjectProperties().size() > 1) {
for (Property property : dataModel.getObjectProperties()) {
if (property.getPropertyName().equals(dataModel.getFactPorperty().getPropertyName()))
continue;
EntityModel entityModel = property.getEntityModel();
List<EntityObj> entityObjs = new ArrayList<>();
if (fillPropertys == null || fillPropertys.size() == 0 || fillPropertys.contains(property.getPropertyName()))
splitList(modelObjs, 1000).forEach(list -> entityObjs.addAll(getEntityService(entityModel.getDsName()).selectBase(entityModel, QueryFilter.createQuery().cust(property.lookup(list)))));
entityObjs.forEach(entityObj -> {
entityObj.setProperty(property);
entityObj.findModel(modelObjs);
});
}
}
}
private <T> List<List<T>> splitList(List<T> list, int groupSize) {
int length = list.size();
// 计算可以分成多少组
int num = (length + groupSize - 1) / groupSize; // TODO
List<List<T>> newList = new ArrayList<>(num);
for (int i = 0; i < num; i++) {
// 开始位置
int fromIndex = i * groupSize;
// 结束位置
int toIndex = (i + 1) * groupSize < length ? (i + 1) * groupSize : length;
newList.add(list.subList(fromIndex, toIndex));
}
return newList;
}
}
......@@ -2,8 +2,7 @@ package cn.ibizlab.core.lite.extensions.service;
import cn.ibizlab.core.lite.extensions.domain.EntityModel;
import cn.ibizlab.core.lite.extensions.domain.EntityObj;
import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.rule.domain.ExecResult;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.util.filter.QueryFilter;
import org.springframework.stereotype.Service;
......@@ -40,35 +39,10 @@ public class MongoEntityService implements CommonEntityService{
return null;
}
@Override
public int saveResultBatch(List<ExecResult> var1)
{
return 0;
}
@Override
public int clearResultBatch(List<ExecResult> var1)
{
return 0;
}
@Override
public List<ModelObj> getModelObjs(String metaModelId, Set<String> fillPropertys, Timestamp lastModify) {
return null;
}
@Override
public ModelObj getModelObjs(String metaModelId, Set<String> fillPropertys, Object factKey) {
return null;
}
@Override
public ModelObj getModelObjs(String metaModelId, Set<String> fillPropertys, Object... factUniKey) {
return null;
}
public void processList(DataModel dataModel, Timestamp lastModify, LiteDataCallback callback) {
@Override
public List<ModelObj> getModelObjs(String metaModelId, Set<String> fillPropertys, List<EntityObj> kEntityObjs) {
return null;
}
}
......@@ -15,59 +15,5 @@
<if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
</select>
<insert id="replaceBatch" parameterType="java.util.List" databaseId="mysql">
<foreach collection="list" item="item" index="index" separator=";">
INSERT INTO ${resultTableName}
(ru_execresultid,ru_execresultname, createdate, updatedate, ruleid, rulename, retvalue, keyvaluefield,dimfield, metricfield,domainsfield,timefield,ext1field,ext2field, businesscat )
VALUES
(#{item.id}, #{item.name}, now(), now(), #{item.ruleId}, #{item.ruleName}, #{item.retValue}, #{item.keyValueField}, #{item.dimField}, #{item.metricField},
#{item.domainsField},#{item.timeField}, #{item.ext1Field}, #{item.ext2Field},#{item.businessCat} )
ON DUPLICATE KEY UPDATE
ru_execresultname=#{item.name}, createdate=now(), updatedate=now(), ruleid=#{item.ruleId}, rulename=#{item.ruleName},
retvalue=#{item.retValue}, keyvaluefield=#{item.keyValueField}, dimfield=#{item.dimField}, metricfield=#{item.metricField},domainsfield=#{item.domainsField},timefield=#{item.timeField},
ext1field=#{item.ext1Field},ext2field=#{item.ext2Field}, businesscat=#{item.businessCat}
</foreach>
</insert>
<!--t1.BUSINESSCAT, t1.CREATEDATE, t1.DIMFIELD, t1.DOMAINSFIELD, t1.EXT1FIELD, t1.EXT2FIELD, t1.KEYVALUEFIELD, t1.METRICFIELD,
t1.RETVALUE, t1.RULEID, t1.RULENAME, t1.RU_EXECRESULTID, t1.RU_EXECRESULTNAME, t1.SYSTEMID, t1.TIMEFIELD, t1.UPDATEDATE-->
<insert id="replaceBatch" parameterType="java.util.List" databaseId="oracle">
MERGE INTO ${resultTableName} A USING (
<foreach collection='list' item='item' index='index' separator='UNION ALL'>
select #{item.id} as ru_execresultid, #{item.name} as ru_execresultname, sysdate as createdate, sysdate as updatedate, #{item.ruleId} as ruleid, #{item.ruleName} as rulename,#{item.retValue} as retvalue, #{item.keyValueField} as keyvaluefield, #{item.dimField} as dimfield,
#{item.metricField} as metricfield,#{item.domainsField} as domainsfield,#{item.timeField} as timefield, #{item.ext1Field} as ext1field,#{item.ext2Field} as ext2field,#{item.businessCat} as businesscat from dual
</foreach>
) B ON (A.ru_execresultid = B.ru_execresultid) WHEN MATCHED THEN
UPDATE SET A.ru_execresultname=B.ru_execresultname, A.updatedate=B.updatedate, A.ruleid=B.ruleid, A.rulename=B.rulename, A.retvalue=B.retvalue, A.keyvaluefield=B.keyvaluefield,
A.dimfield=B.dimfield, A.metricfield=B.metricfield,A.domainsfield=B.domainsfield,A.timefield=B.timefield,A.ext1field=B.ext1field,A.ext2field=B.ext2field, A.businesscat=B.businesscat
WHEN NOT MATCHED THEN
INSERT ( ru_execresultid,ru_execresultname, createdate, updatedate, ruleid, rulename, retvalue, keyvaluefield,dimfield, metricfield,domainsfield,timefield,ext1field,ext2field, businesscat )
VALUES (B.ru_execresultid,B.ru_execresultname, B.createdate, B.updatedate, B.ruleid, B.rulename, B.retvalue, B.keyvaluefield,B.dimfield, B.metricfield,B.domainsfield,B.timefield,B.ext1field,B.ext2field, B.businesscat)
</insert>
<!--t1.BUSINESSCAT, t1.CREATEDATE, t1.DIMFIELD, t1.DOMAINSFIELD, t1.EXT1FIELD, t1.EXT2FIELD, t1.KEYVALUEFIELD, t1.METRICFIELD,
t1.RETVALUE, t1.RULEID, t1.RULENAME, t1.RU_EXECRESULTID, t1.RU_EXECRESULTNAME, t1.SYSTEMID, t1.TIMEFIELD, t1.UPDATEDATE-->
<insert id="replaceBatchByOracle" parameterType="java.util.List">
MERGE INTO ${resultTableName} A USING (
<foreach collection='list' item='item' index='index' separator='UNION ALL'>
select #{item.id} as ru_execresultid, #{item.name} as ru_execresultname, sysdate as createdate, sysdate as updatedate, #{item.ruleId} as ruleid, #{item.ruleName} as rulename,#{item.retValue} as retvalue, #{item.keyValueField} as keyvaluefield, #{item.dimField} as dimfield,
#{item.metricField} as metricfield,#{item.domainsField} as domainsfield,#{item.timeField} as timefield, #{item.ext1Field} as ext1field,#{item.ext2Field} as ext2field,#{item.businessCat} as businesscat from dual
</foreach>
) B ON (A.ru_execresultid = B.ru_execresultid) WHEN MATCHED THEN
UPDATE SET A.ru_execresultname=B.ru_execresultname, A.updatedate=B.updatedate, A.ruleid=B.ruleid, A.rulename=B.rulename, A.retvalue=B.retvalue, A.keyvaluefield=B.keyvaluefield,
A.dimfield=B.dimfield, A.metricfield=B.metricfield,A.domainsfield=B.domainsfield,A.timefield=B.timefield,A.ext1field=B.ext1field,A.ext2field=B.ext2field, A.businesscat=B.businesscat
WHEN NOT MATCHED THEN
INSERT ( ru_execresultid,ru_execresultname, createdate, updatedate, ruleid, rulename, retvalue, keyvaluefield,dimfield, metricfield,domainsfield,timefield,ext1field,ext2field, businesscat )
VALUES (B.ru_execresultid,B.ru_execresultname, B.createdate, B.updatedate, B.ruleid, B.rulename, B.retvalue, B.keyvaluefield,B.dimfield, B.metricfield,B.domainsfield,B.timefield,B.ext1field,B.ext2field, B.businesscat)
</insert>
<delete id="clearBatch" parameterType="java.util.List" >
delete from ${resultTableName} where (ru_execresultid) in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
(#{item.id})
</foreach>
</delete>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.ibizlab.core.extensions.mapper.ExecResultExMapper">
<insert id="replaceBatch" parameterType="java.util.List" databaseId="mysql">
<foreach collection="list" item="item" index="index" separator=";">
INSERT INTO ${resultTableName}
(ru_execresultid,ru_execresultname, createdate, updatedate, ruleid, rulename, retvalue, keyvaluefield,dimfield, metricfield,domainsfield,timefield,ext1field,ext2field, businesscat )
VALUES
(#{item.id}, #{item.name}, now(), now(), #{item.ruleId}, #{item.ruleName}, #{item.retValue}, #{item.keyValueField}, #{item.dimField}, #{item.metricField},
#{item.domainsField},#{item.timeField}, #{item.ext1Field}, #{item.ext2Field},#{item.businessCat} )
ON DUPLICATE KEY UPDATE
ru_execresultname=#{item.name}, createdate=now(), updatedate=now(), ruleid=#{item.ruleId}, rulename=#{item.ruleName},
retvalue=#{item.retValue}, keyvaluefield=#{item.keyValueField}, dimfield=#{item.dimField}, metricfield=#{item.metricField},domainsfield=#{item.domainsField},timefield=#{item.timeField},
ext1field=#{item.ext1Field},ext2field=#{item.ext2Field}, businesscat=#{item.businessCat}
</foreach>
</insert>
<!--t1.BUSINESSCAT, t1.CREATEDATE, t1.DIMFIELD, t1.DOMAINSFIELD, t1.EXT1FIELD, t1.EXT2FIELD, t1.KEYVALUEFIELD, t1.METRICFIELD,
t1.RETVALUE, t1.RULEID, t1.RULENAME, t1.RU_EXECRESULTID, t1.RU_EXECRESULTNAME, t1.SYSTEMID, t1.TIMEFIELD, t1.UPDATEDATE-->
<insert id="replaceBatch" parameterType="java.util.List" databaseId="oracle">
MERGE INTO ${resultTableName} A USING (
<foreach collection='list' item='item' index='index' separator='UNION ALL'>
select #{item.id} as ru_execresultid, #{item.name} as ru_execresultname, sysdate as createdate, sysdate as updatedate, #{item.ruleId} as ruleid, #{item.ruleName} as rulename,#{item.retValue} as retvalue, #{item.keyValueField} as keyvaluefield, #{item.dimField} as dimfield,
#{item.metricField} as metricfield,#{item.domainsField} as domainsfield,#{item.timeField} as timefield, #{item.ext1Field} as ext1field,#{item.ext2Field} as ext2field,#{item.businessCat} as businesscat from dual
</foreach>
) B ON (A.ru_execresultid = B.ru_execresultid) WHEN MATCHED THEN
UPDATE SET A.ru_execresultname=B.ru_execresultname, A.updatedate=B.updatedate, A.ruleid=B.ruleid, A.rulename=B.rulename, A.retvalue=B.retvalue, A.keyvaluefield=B.keyvaluefield,
A.dimfield=B.dimfield, A.metricfield=B.metricfield,A.domainsfield=B.domainsfield,A.timefield=B.timefield,A.ext1field=B.ext1field,A.ext2field=B.ext2field, A.businesscat=B.businesscat
WHEN NOT MATCHED THEN
INSERT ( ru_execresultid,ru_execresultname, createdate, updatedate, ruleid, rulename, retvalue, keyvaluefield,dimfield, metricfield,domainsfield,timefield,ext1field,ext2field, businesscat )
VALUES (B.ru_execresultid,B.ru_execresultname, B.createdate, B.updatedate, B.ruleid, B.rulename, B.retvalue, B.keyvaluefield,B.dimfield, B.metricfield,B.domainsfield,B.timefield,B.ext1field,B.ext2field, B.businesscat)
</insert>
<!--t1.BUSINESSCAT, t1.CREATEDATE, t1.DIMFIELD, t1.DOMAINSFIELD, t1.EXT1FIELD, t1.EXT2FIELD, t1.KEYVALUEFIELD, t1.METRICFIELD,
t1.RETVALUE, t1.RULEID, t1.RULENAME, t1.RU_EXECRESULTID, t1.RU_EXECRESULTNAME, t1.SYSTEMID, t1.TIMEFIELD, t1.UPDATEDATE-->
<insert id="replaceBatchByOracle" parameterType="java.util.List">
MERGE INTO ${resultTableName} A USING (
<foreach collection='list' item='item' index='index' separator='UNION ALL'>
select #{item.id} as ru_execresultid, #{item.name} as ru_execresultname, sysdate as createdate, sysdate as updatedate, #{item.ruleId} as ruleid, #{item.ruleName} as rulename,#{item.retValue} as retvalue, #{item.keyValueField} as keyvaluefield, #{item.dimField} as dimfield,
#{item.metricField} as metricfield,#{item.domainsField} as domainsfield,#{item.timeField} as timefield, #{item.ext1Field} as ext1field,#{item.ext2Field} as ext2field,#{item.businessCat} as businesscat from dual
</foreach>
) B ON (A.ru_execresultid = B.ru_execresultid) WHEN MATCHED THEN
UPDATE SET A.ru_execresultname=B.ru_execresultname, A.updatedate=B.updatedate, A.ruleid=B.ruleid, A.rulename=B.rulename, A.retvalue=B.retvalue, A.keyvaluefield=B.keyvaluefield,
A.dimfield=B.dimfield, A.metricfield=B.metricfield,A.domainsfield=B.domainsfield,A.timefield=B.timefield,A.ext1field=B.ext1field,A.ext2field=B.ext2field, A.businesscat=B.businesscat
WHEN NOT MATCHED THEN
INSERT ( ru_execresultid,ru_execresultname, createdate, updatedate, ruleid, rulename, retvalue, keyvaluefield,dimfield, metricfield,domainsfield,timefield,ext1field,ext2field, businesscat )
VALUES (B.ru_execresultid,B.ru_execresultname, B.createdate, B.updatedate, B.ruleid, B.rulename, B.retvalue, B.keyvaluefield,B.dimfield, B.metricfield,B.domainsfield,B.timefield,B.ext1field,B.ext2field, B.businesscat)
</insert>
<delete id="clearBatch" parameterType="java.util.List" >
delete from ${resultTableName} where (ru_execresultid) in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
(#{item.id})
</foreach>
</delete>
</mapper>
......@@ -6,6 +6,7 @@ import cn.ibizlab.core.lite.extensions.domain.*;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.model.Property;
import cn.ibizlab.core.lite.extensions.service.DbEntityService;
import cn.ibizlab.core.lite.extensions.service.LiteDataService;
import cn.ibizlab.core.lite.extensions.service.LiteModelService;
import cn.ibizlab.util.client.IBZDictFeignClient;
import cn.ibizlab.util.dict.CodeItem;
......@@ -38,18 +39,19 @@ public class DstCoreResource {
@Autowired
private LiteModelService liteModelService;
@Autowired
private LiteDataService liteDataService;
@Autowired
private DbEntityService dbEntityService;
@RequestMapping(method = RequestMethod.GET, value = "/dst/test/{modelid}")
public ResponseEntity<List<ModelObj>> getstr(@PathVariable(name="modelid",required = false) String modelid)
@RequestMapping(method = RequestMethod.GET, value = "/dst/test/{modelid}/data/{key}")
public ResponseEntity<ModelObj> getstr(@PathVariable(name="modelid",required = false) String modelid,@PathVariable(name="key",required = false) String key)
{
if(StringUtils.isEmpty(modelid))
modelid="dataModelff8080816a8b510c016a8c2f18b10001";
List<ModelObj> list=dbEntityService.getModelObjs(modelid, null,DataObject.getBeginDate());
return ResponseEntity.ok(list);
return ResponseEntity.ok(liteDataService.getModelObjs(modelid, null,key));
}
@RequestMapping(method = RequestMethod.GET, value = {"/dst/datamodels/{modelid}","/dst/datamodels/{modelid}/name/{modelname}"})
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册