Commit 4a7ea6af by wqc

关联表通用查询

parent 4190cf2d
...@@ -104,6 +104,12 @@ public class CommonQueryController { ...@@ -104,6 +104,12 @@ public class CommonQueryController {
return ResultVo.success(commonQueryService.runSelect(body)); return ResultVo.success(commonQueryService.runSelect(body));
} }
@ApiOperation("自定义sql查询")
@PostMapping("/customSelect")
public ResultVo customSelect(@RequestBody Map<String, Object> body) throws Exception {
return ResultVo.success(commonQueryService.customSelect(body));
}
@ApiOperation("获取库下的所有表") @ApiOperation("获取库下的所有表")
@PostMapping("/showTables") @PostMapping("/showTables")
public ResultVo showTables(@RequestBody Map<String, Object> body) throws Exception { public ResultVo showTables(@RequestBody Map<String, Object> body) throws Exception {
......
...@@ -120,6 +120,24 @@ public class CommonQueryService extends ServiceImpl<CommonQuerySettingDao, Commo ...@@ -120,6 +120,24 @@ public class CommonQueryService extends ServiceImpl<CommonQuerySettingDao, Commo
return commonQuery(sql, queryDbId); return commonQuery(sql, queryDbId);
} }
public List<Map<String, Object>> customSelect(Map<String, Object> body) throws Exception {
JSONObject jsonObject = JSONUtil.parseObj(body);
Integer queryDbId = Integer.valueOf(jsonObject.get("queryDbId").toString());
String tableOne = jsonObject.get("tableOne").toString();
String tableTwo = jsonObject.get("tableTwo").toString();
String pkMetaOne = jsonObject.get("pkMetaOne").toString();
String pkMetaTwo = jsonObject.get("pkMetaTwo").toString();
String querySql = jsonObject.get("querySql").toString();
if (StringUtils.isBlank(tableTwo)||StringUtils.isBlank(pkMetaTwo)){
String sql = "SELECT * FROM " + tableOne +" "+querySql;
return commonQuery(sql,queryDbId);
}else{
String leftSql="SELECT * FROM "+tableOne +" t LEFT JOIN "+tableTwo+" h ON t."+pkMetaOne+" = h."+pkMetaTwo+" "+querySql;
return commonQuery(leftSql,queryDbId);
}
}
public Object showTables(@RequestBody Map<String, Object> body) throws Exception { public Object showTables(@RequestBody Map<String, Object> body) throws Exception {
JSONObject jsonObject = JSONUtil.parseObj(body); JSONObject jsonObject = JSONUtil.parseObj(body);
int page = (int) jsonObject.get("page"); int page = (int) jsonObject.get("page");
......
...@@ -40,7 +40,7 @@ public class DataCleanRecordService extends ServiceImpl<DataCleanRecordDao, Data ...@@ -40,7 +40,7 @@ public class DataCleanRecordService extends ServiceImpl<DataCleanRecordDao, Data
QueryDb queryDb = queryDbDao.selectById(dataCleanRecord.getQueryDbId()); QueryDb queryDb = queryDbDao.selectById(dataCleanRecord.getQueryDbId());
AssertUtils.notNull(queryDb, "无连接表ID"); AssertUtils.notNull(queryDb, "无连接表ID");
LambdaQueryWrapper<DataCollectSetting> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DataCollectSetting> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DataCollectSetting::getToDbId, queryDb.getId()).eq(DataCollectSetting::getToDbId, 1);//数据库类型 wrapper.eq(DataCollectSetting::getToDbId, queryDb.getId()).eq(DataCollectSetting::getDataType, 1);//数据库类型
List<DataCollectSetting> dataCollectSettings = dataCollectMapper.selectList(wrapper); List<DataCollectSetting> dataCollectSettings = dataCollectMapper.selectList(wrapper);
Integer collectSettingId = null; Integer collectSettingId = null;
for (DataCollectSetting collectSetting : dataCollectSettings) { for (DataCollectSetting collectSetting : dataCollectSettings) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment