haungxing
5 months ago
32 changed files with 294 additions and 52 deletions
@ -0,0 +1,26 @@
|
||||
package com.hnac.hzims.bigmodel.datasource.controller; |
||||
|
||||
import com.hnac.hzims.bigmodel.datasource.service.DataSourceService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/28 14:07 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/dataSource/execute") |
||||
@AllArgsConstructor |
||||
public class DataSourceExecuteController { |
||||
|
||||
private final DataSourceService dataSourceService; |
||||
|
||||
@GetMapping("/executeQuery") |
||||
public R executeQuery(String sql,String dataSourceName) { |
||||
return R.data(dataSourceService.queryListOnSpecificDataSource(sql,dataSourceName)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,51 @@
|
||||
package com.hnac.hzims.bigmodel.datasource.service; |
||||
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.jdbc.core.JdbcTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/28 15:24 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
@Slf4j |
||||
public class DataSourceService { |
||||
|
||||
private final JdbcTemplate jdbcTemplate; |
||||
|
||||
/** |
||||
* 指定 |
||||
* @param sql |
||||
* @param dataSourceName |
||||
* @return |
||||
*/ |
||||
public List<Map<String, Object>> queryListOnSpecificDataSource(String sql,String dataSourceName) { |
||||
// 切换到指定的数据源
|
||||
DynamicDataSourceContextHolder.push(dataSourceName); |
||||
try { |
||||
return jdbcTemplate.queryForList(sql); |
||||
} finally { |
||||
// 清除,恢复默认数据源
|
||||
DynamicDataSourceContextHolder.clear(); |
||||
} |
||||
} |
||||
|
||||
public Integer updateOnSpecificDataSource(String sql,String dataSourceName) { |
||||
// 切换到指定的数据源
|
||||
DynamicDataSourceContextHolder.push(dataSourceName); |
||||
try { |
||||
return jdbcTemplate.update(sql); |
||||
} finally { |
||||
// 清除,恢复默认数据源
|
||||
DynamicDataSourceContextHolder.clear(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.hnac.hzims.bigmodel.datasource.service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/06/28 14:22 |
||||
*/ |
||||
public interface IDataSourceService { |
||||
|
||||
List<Map<String,Object>> queryList(String sql); |
||||
|
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.hnac.hzims.bigmodel.interactive.constants; |
||||
|
||||
/** |
||||
* @Author: huangxing |
||||
* @Date: 2024/07/01 14:26 |
||||
* @Describe: 参数key管理 |
||||
*/ |
||||
public interface ParamKeyConstants { |
||||
|
||||
/**实时画面host**/ |
||||
String CANVAS_HOST = "hzims:bigModel:canvas:host"; |
||||
/**实时画面v3路径 {context}&stationNum={stationNum}&projectId={projectId}**/ |
||||
String CANVAS_V3_PATH = "hzims:bigModel:canvas:v3:path"; |
||||
/**实时画面v4路径 other/v4/canvas/index.html?hzinfowebkit=true&taskId={taskId}&stationNum={stationNum}&projectId={projectId}&source=app&picName={context}&name={name}**/ |
||||
String CANVAS_V4_PATH = "hzims:bigModel:canvas:v4:path"; |
||||
/**实时画面云组态路径 hzinfo-data-scada/view/{projectId}/{id}?source=app**/ |
||||
String CANVAS_YZT_PATH = "hzims:bigModel:canvas:yzt:path"; |
||||
|
||||
} |
Loading…
Reference in new issue