From 9cf5d1f1b817df5387a0abab7d1bd17fd1d57e4c Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Tue, 16 Nov 2021 16:21:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E5=85=BC=E5=AE=B9ht?= =?UTF-8?q?tp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DataSetServiceImpl.java | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/service/impl/DataSetServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/service/impl/DataSetServiceImpl.java index d6ef6248..481bbc83 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/service/impl/DataSetServiceImpl.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/service/impl/DataSetServiceImpl.java @@ -8,6 +8,7 @@ import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper; import com.anji.plus.gaea.exception.BusinessExceptionBuilder; import com.anji.plus.gaea.utils.GaeaBeanUtils; import com.anjiplus.template.gaea.business.code.ResponseCode; +import com.anjiplus.template.gaea.business.enums.SetTypeEnum; import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.OriginalDataDto; import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.DataSetDto; import com.anjiplus.template.gaea.business.modules.dataset.dao.DataSetMapper; @@ -22,6 +23,7 @@ import com.anjiplus.template.gaea.business.modules.datasettransform.service.Data import com.anjiplus.template.gaea.business.modules.datasource.controller.dto.DataSourceDto; import com.anjiplus.template.gaea.business.modules.datasource.dao.entity.DataSource; import com.anjiplus.template.gaea.business.modules.datasource.service.DataSourceService; +import com.anjiplus.template.gaea.business.util.JdbcConstants; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -218,12 +220,30 @@ public class DataSetServiceImpl implements DataSetService { */ @Override public OriginalDataDto getData(DataSetDto dto) { + String dynSentence = dto.getDynSentence(); + OriginalDataDto originalDataDto = new OriginalDataDto(); String setCode = dto.getSetCode(); //1.获取数据集、参数替换、数据转换 DataSetDto dataSetDto = detailSet(setCode); //2.获取数据源 - DataSource dataSource = dataSourceService.selectOne("source_code", dataSetDto.getSourceCode()); + DataSource dataSource; + if (dto.getSetType().equals(SetTypeEnum.HTTP.getCodeValue())) { + //http不需要数据源,兼容已有的逻辑,将http所需要的数据塞进DataSource + dataSource = new DataSource(); + dataSource.setSourceConfig(dynSentence); + dataSource.setSourceType(JdbcConstants.HTTP); + String body = JSONObject.parseObject(dynSentence).getString("body"); + if (StringUtils.isNotBlank(body)) { + dynSentence = body; + }else { + dynSentence = "{}"; + } + + }else { + dataSource = dataSourceService.selectOne("source_code", dataSetDto.getSourceCode()); + } + //3.参数替换 //3.1参数校验 log.debug("参数校验替换前:{}", dto.getContextData()); @@ -231,7 +251,7 @@ public class DataSetServiceImpl implements DataSetService { if (!verification) { throw BusinessExceptionBuilder.build(ResponseCode.RULE_FIELDS_CHECK_ERROR); } - String dynSentence = dataSetParamService.transform(dto.getContextData(), dataSetDto.getDynSentence()); + dynSentence = dataSetParamService.transform(dto.getContextData(), dynSentence); log.debug("参数校验替换后:{}", dto.getContextData()); //4.获取数据 DataSourceDto dataSourceDto = new DataSourceDto(); @@ -258,10 +278,28 @@ public class DataSetServiceImpl implements DataSetService { */ @Override public OriginalDataDto testTransform(DataSetDto dto) { + String dynSentence = dto.getDynSentence(); + OriginalDataDto originalDataDto = new OriginalDataDto(); String sourceCode = dto.getSourceCode(); //1.获取数据源 - DataSource dataSource = dataSourceService.selectOne("source_code", sourceCode); + DataSource dataSource; + if (dto.getSetType().equals(SetTypeEnum.HTTP.getCodeValue())) { + //http不需要数据源,兼容已有的逻辑,将http所需要的数据塞进DataSource + dataSource = new DataSource(); + dataSource.setSourceConfig(dynSentence); + dataSource.setSourceType(JdbcConstants.HTTP); + String body = JSONObject.parseObject(dynSentence).getString("body"); + if (StringUtils.isNotBlank(body)) { + dynSentence = body; + }else { + dynSentence = "{}"; + } + + }else { + dataSource = dataSourceService.selectOne("source_code", sourceCode); + } + //3.参数替换 //3.1参数校验 boolean verification = dataSetParamService.verification(dto.getDataSetParamDtoList(), null); @@ -269,7 +307,7 @@ public class DataSetServiceImpl implements DataSetService { throw BusinessExceptionBuilder.build(ResponseCode.RULE_FIELDS_CHECK_ERROR); } - String dynSentence = dataSetParamService.transform(dto.getDataSetParamDtoList(), dto.getDynSentence()); + dynSentence = dataSetParamService.transform(dto.getDataSetParamDtoList(), dynSentence); //4.获取数据 DataSourceDto dataSourceDto = new DataSourceDto(); BeanUtils.copyProperties(dataSource, dataSourceDto);