Commit c358eb9a by wqc

大屏库里查询sql优化

parent 127a9e77
...@@ -3,9 +3,13 @@ package com.zq.datacollect; ...@@ -3,9 +3,13 @@ package com.zq.datacollect;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication @EnableScheduling
@MapperScan({"com.zq.datacollect.mapper"}) @MapperScan({"com.zq.datacollect.mapper"})
@EnableDiscoveryClient
@SpringBootApplication
public class DataCollectApplication { public class DataCollectApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -37,8 +37,7 @@ import java.io.IOException; ...@@ -37,8 +37,7 @@ import java.io.IOException;
* @author / * @author /
*/ */
@Slf4j @Slf4j
public class public class TokenFilter extends GenericFilterBean {
TokenFilter extends GenericFilterBean {
private final TokenProvider tokenProvider; private final TokenProvider tokenProvider;
private RedisUtils redisUtils; private RedisUtils redisUtils;
......
package com.zq.datacollect.controller; package com.zq.datacollect.controller;
import com.zq.common.annotation.AnonymousAccess;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.datacollect.service.BigScreenService; import com.zq.datacollect.service.BigScreenService;
import com.zq.datacollect.service.DataCollecSiteService; import com.zq.datacollect.service.DataCollecSiteService;
...@@ -9,6 +10,7 @@ import io.swagger.annotations.ApiParam; ...@@ -9,6 +10,7 @@ import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.sql.SQLException;
@RestController @RestController
@Api(tags = "大屏数据显示") @Api(tags = "大屏数据显示")
...@@ -29,31 +31,32 @@ public class BigScreenController { ...@@ -29,31 +31,32 @@ public class BigScreenController {
@ApiOperation("获取检察院数据统计") @ApiOperation("获取检察院数据统计")
@GetMapping(value = "/getAllCount") @GetMapping(value = "/getAllCount")
public ResultVo getAllCount() { public ResultVo getAllCount() throws SQLException {
return ResultVo.success(bigScreenService.getAllCount()); return ResultVo.success(bigScreenService.getAllCount());
} }
@ApiOperation("获取模型类型数据统计") @ApiOperation("获取模型类型数据统计")
@GetMapping(value = "/getModelTypeCount") @GetMapping(value = "/getModelTypeCount")
public ResultVo getModelTypeCount() { @AnonymousAccess
public ResultVo getModelTypeCount() throws SQLException {
return ResultVo.success(bigScreenService.getModelTypeCount()); return ResultVo.success(bigScreenService.getModelTypeCount());
} }
@ApiOperation("获取模型地区数据统计") @ApiOperation("获取模型地区数据统计")
@GetMapping(value = "/getModelCityCount") @GetMapping(value = "/getModelCityCount")
public ResultVo getModelCityCount() { public ResultVo getModelCityCount() throws SQLException {
return ResultVo.success(bigScreenService.getModelCityCount()); return ResultVo.success(bigScreenService.getModelCityCount());
} }
@ApiOperation("获取业务类型数据统计") @ApiOperation("获取业务类型数据统计")
@GetMapping(value = "/getYwuType") @GetMapping(value = "/getYwuType")
public ResultVo getYwuType() { public ResultVo getYwuType() throws SQLException {
return ResultVo.success(bigScreenService.getYwuType()); return ResultVo.success(bigScreenService.getYwuType());
} }
@ApiOperation("获取市内各地区线索数据统计") @ApiOperation("获取市内各地区线索数据统计")
@GetMapping(value = "/getCluesNum") @GetMapping(value = "/getCluesNum")
public ResultVo getCluesNum() { public ResultVo getCluesNum() throws SQLException {
return ResultVo.success(bigScreenService.getCluesNum()); return ResultVo.success(bigScreenService.getCluesNum());
} }
...@@ -89,31 +92,31 @@ public class BigScreenController { ...@@ -89,31 +92,31 @@ public class BigScreenController {
@ApiOperation("办案成效数据") @ApiOperation("办案成效数据")
@GetMapping(value = "/bacxData") @GetMapping(value = "/bacxData")
public ResultVo getBacxData() { public ResultVo getBacxData() throws SQLException {
return ResultVo.success(bigScreenService.getBacxData()); return ResultVo.success(bigScreenService.getBacxData());
} }
@ApiOperation("模型应用成效") @ApiOperation("模型应用成效")
@GetMapping(value = "/modelEffect") @GetMapping(value = "/modelEffect")
public ResultVo getModelEffect(@RequestParam String shiyuan) { public ResultVo getModelEffect(@RequestParam String shiyuan) throws SQLException {
return ResultVo.success(bigScreenService.getModelEffect(shiyuan)); return ResultVo.success(bigScreenService.getModelEffect(shiyuan));
} }
@ApiOperation("办案总量") @ApiOperation("办案总量")
@GetMapping(value = "/getBazlNums") @GetMapping(value = "/getBazlNums")
public ResultVo getbazlNums() { public ResultVo getbazlNums() throws SQLException {
return ResultVo.success(bigScreenService.getbazlNums()); return ResultVo.success(bigScreenService.getbazlNums());
} }
@ApiOperation("取保候审案件长期未结列表") @ApiOperation("取保候审案件长期未结列表")
@GetMapping(value = "/getQbhsajcqwjList") @GetMapping(value = "/getQbhsajcqwjList")
public ResultVo getQbhsajcqwjList() { public ResultVo getQbhsajcqwjList() throws SQLException {
return ResultVo.success(bigScreenService.getQbhsajcqwjList()); return ResultVo.success(bigScreenService.getQbhsajcqwjList());
} }
@ApiOperation("模型类型") @ApiOperation("模型类型")
@GetMapping(value = "/getProxyType") @GetMapping(value = "/getProxyType")
public ResultVo getProxyType() { public ResultVo getProxyType() throws SQLException {
return ResultVo.success(bigScreenService.getProxyType()); return ResultVo.success(bigScreenService.getProxyType());
} }
...@@ -126,22 +129,27 @@ public class BigScreenController { ...@@ -126,22 +129,27 @@ public class BigScreenController {
@ApiOperation("平台成果") @ApiOperation("平台成果")
@GetMapping(value = "/getPingTaiData") @GetMapping(value = "/getPingTaiData")
public ResultVo getPingTaiData() { public ResultVo getPingTaiData() throws SQLException {
return ResultVo.success(bigScreenService.getPingTaiData()); return ResultVo.success(bigScreenService.getPingTaiData());
} }
@ApiOperation("质量指标") @ApiOperation("质量指标")
@GetMapping(value = "/getZhiBiaoData") @GetMapping(value = "/getZhiBiaoData")
public ResultVo getZhiBiaoData(@RequestParam String diqu,String type) { public ResultVo getZhiBiaoData(@RequestParam String diqu,String type) throws SQLException {
return ResultVo.success(bigScreenService.getZhiBiaoData(diqu,type)); return ResultVo.success(bigScreenService.getZhiBiaoData(diqu,type));
} }
@ApiOperation("法律监督") @ApiOperation("法律监督")
@GetMapping(value = "/getJianDuData") @GetMapping(value = "/getJianDuData")
public ResultVo getJianDuData(@RequestParam String diqu,String type) { public ResultVo getJianDuData(@RequestParam String diqu,String type) throws SQLException {
return ResultVo.success(bigScreenService.getJianDuData(diqu,type)); return ResultVo.success(bigScreenService.getJianDuData(diqu,type));
} }
@ApiOperation("重大敏感案件跟踪情况")
@GetMapping(value = "/getZdmgajData")
public ResultVo getZdmgajData(@RequestParam String diqu) throws SQLException {
return ResultVo.success(bigScreenService.getZdmgajData(diqu));
}
} }
package com.zq.datacollect.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "common_query_setting")
public class CommonQuerySettings {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 查询数据源id
*/
private Long queryDbId;
/**
* 查询名称
*/
private String queryName;
/**
* 查询显示的字段(元数据的名称)
*/
private String showFlied;
/**
* 查询的where条件,包含需要条件的参数
*/
private String queryWhere;
/**
* 查询SQL
*/
private String querySql;
/**
* createTime
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* updateTime
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
package com.zq.datacollect.holder;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import com.zq.common.exception.BusinessException;
import com.zq.datacollect.entity.QueryDb;
import com.zq.datacollect.service.CommonQuerysService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class ConnectDB implements ApplicationRunner {
@Resource
private CommonQuerysService service;
private Map<Integer, DruidPooledConnection> connectionMap = new HashMap<>();
@Override
public void run(ApplicationArguments args) throws SQLException {
List<QueryDb> datasource = service.getDatasource();
for (QueryDb ds : datasource) {
DruidDataSource druidDataSource = DruidDataSourceBuilder.create().build();
String url = "";
String className = "";
switch (ds.getDbType()) {
case 1:
className = "com.mysql.cj.jdbc.Driver";
url = "jdbc:mysql://" + ds.getDbIp() + ":" + ds.getDbPort() + "/" + ds.getDbName() + "?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&useOldAliasMetadataBehavior=true";
break;
case 2:
className = "oracle.jdbc.driver.OracleDriver";
url = "jdbc:oracle:thin:@//" + ds.getDbIp() + ":" + ds.getDbPort() + "/" + ds.getDbName();
break;
case 3:
className = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
url = "jdbc:sqlserver://" + ds.getDbIp() + ":" + ds.getDbPort() + "/" + ds.getDbName();
break;
default:
throw new BusinessException("不支持的数据库");
}
druidDataSource.setDriverClassName(className);
druidDataSource.setUrl(url);
druidDataSource.setUsername(ds.getUsername());
druidDataSource.setPassword(ds.getPassword());
druidDataSource.init();
DruidPooledConnection connection = druidDataSource.getConnection();
connectionMap.put(ds.getId(), connection);
}
log.info("成功加载数据库:" + connectionMap.size());
}
@Bean
public ConnectionHolder getConnectionHolder(){
return new ConnectionHolder(connectionMap);
}
@PreDestroy
public void onClose(){
for (DruidPooledConnection connection : connectionMap.values()) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
package com.zq.datacollect.holder;
import com.alibaba.druid.pool.DruidPooledConnection;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
public class ConnectionHolder {
private Map<Integer, DruidPooledConnection> connectionMap = new HashMap<>();
public ConnectionHolder(Map<Integer, DruidPooledConnection> connectionMap) {
this.connectionMap = connectionMap;
}
public DruidPooledConnection get(Integer id){
return connectionMap.get(id);
}
}
...@@ -5,8 +5,6 @@ import com.zq.common.exception.BusinessException; ...@@ -5,8 +5,6 @@ import com.zq.common.exception.BusinessException;
import com.zq.datacollect.entity.QueryDb; import com.zq.datacollect.entity.QueryDb;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -25,7 +23,7 @@ public class DatabaseHolder { ...@@ -25,7 +23,7 @@ public class DatabaseHolder {
switch (dbType) { switch (dbType) {
case 1: case 1:
className = "com.mysql.cj.jdbc.Driver"; className = "com.mysql.cj.jdbc.Driver";
url = "jdbc:mysql://" + dbIp + ":" + dbPort + "/" + dbName + "?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&autoReconnect=true"; url = "jdbc:mysql://" + dbIp + ":" + dbPort + "/" + dbName + "?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&autoReconnect=true&useOldAliasMetadataBehavior=true";
break; break;
case 2: case 2:
className = "oracle.jdbc.driver.OracleDriver"; className = "oracle.jdbc.driver.OracleDriver";
...@@ -53,4 +51,4 @@ public class DatabaseHolder { ...@@ -53,4 +51,4 @@ public class DatabaseHolder {
((DruidDataSource)jdbcTemplateMap.get(id).getDataSource()).close(); ((DruidDataSource)jdbcTemplateMap.get(id).getDataSource()).close();
jdbcTemplateMap.remove(id); jdbcTemplateMap.remove(id);
} }
} }
\ No newline at end of file
package com.zq.datacollect.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zq.datacollect.entity.CommonQuerySettings;
public interface CommonQuerySettingsDao extends BaseMapper<CommonQuerySettings> {
}
package com.zq.datacollect.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.datacollect.entity.CommonQuerySettings;
import com.zq.datacollect.entity.QueryDb;
import com.zq.datacollect.mapper.CommonQuerySettingsDao;
import com.zq.datacollect.mapper.QueryDbMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class CommonQuerysService extends ServiceImpl<CommonQuerySettingsDao, CommonQuerySettings> {
@Resource
private QueryDbMapper queryDbDao;
public List<QueryDb> getDatasource() {
return queryDbDao.selectList(new QueryWrapper<>());
}
}
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