Commit 27db6e81 authored by niuzhaodi's avatar niuzhaodi

查询优化

parent d64433e1
......@@ -2,44 +2,12 @@ package com.wafersystems;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
/**
* @author wafer
* SpringBoot启动类
*/
@SpringBootApplication
public class AccessApplication {
public static void main(String[] args) {
SpringApplication.run(AccessApplication.class, args);
}
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
return new RestTemplate(factory);
}
@Bean
public SimpleClientHttpRequestFactory httpClientFactory() {
SimpleClientHttpRequestFactory httpRequestFactory = new SimpleClientHttpRequestFactory();
httpRequestFactory.setReadTimeout(35000);
httpRequestFactory.setConnectTimeout(6000);
SocketAddress address = new InetSocketAddress("127.0.0.1", 55859);
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
httpRequestFactory.setProxy(proxy);
// Authenticator.setDefault(new BasicAuthenticator(PROXY_USERNAME,PROXY_PASSWORD));
return httpRequestFactory;
}
public static void main(String[] args) {
SpringApplication.run(AccessApplication.class, args);
}
}
......@@ -29,14 +29,21 @@ public class AccessCtl {
@Value("${access.dir}")
private String dir;
@Value("${access.pwd}")
private String pwd;
@ApiOperation(value = "查询门禁用户表")
@GetMapping("queryConsumerT")
public Object queryC() {
log.info("--外部应用调用查询Access数据库接口[开始]--" + dir);
log.info("--外部应用调用查询Access数据库接口[开始]--");
log.info("--mdb数据库文件配置路径==>{}", dir);
log.info("--mdb数据库文件配置密码==>{}", pwd);
Map<String, Object> back = new HashMap<String, Object>();
back.put("status", 1);//1代表请求失败
try {
List<UserCardInfo> userCardInfoList = queryConsumerT();
int total = userCardInfoList !=null && userCardInfoList.size()>0 ? userCardInfoList.size():0;
log.info("--查询数据库记录总数==>{}条", total);
back.put("data", userCardInfoList);
back.put("status", 0);//0代表请求成功
} catch (Exception ex) {
......@@ -57,41 +64,60 @@ public class AccessCtl {
ResultSet rs = null;
try {
Class.forName(Driver);
conn = DriverManager.getConnection(url, "", "168168");
log.info("[JDBC]建立数据库连接==>[开始]");
conn = DriverManager.getConnection(url, "", pwd);
log.info("[JDBC]建立数据库连接==>[结束]{}", conn);
log.info("[JDBC]建立数据库连接Statement==>[开始]");
stmt = conn.createStatement();
String sql = "SELECT f_ConsumerNO, f_CardNO FROM t_b_Consumer";
rs = stmt.executeQuery(sql);
log.info("[JDBC]建立数据库连接Statement==>[结束]{}", stmt);
String sqlQ = "SELECT f_ConsumerName, f_ConsumerNO, f_CardNO FROM t_b_Consumer";
log.info("[JDBC]建立数据库连接SQL查询语句==>{}", sqlQ);
rs = stmt.executeQuery(sqlQ);
userCardInfoList = new ArrayList<UserCardInfo>();
while (rs.next()) {
String userName = rs.getString("f_ConsumerName");
userName = userName != null ? userName.trim() : "";
String consumerNO = rs.getString("f_ConsumerNO");
consumerNO = consumerNO != null ? consumerNO.trim() : "";
String cardNO = rs.getString("f_CardNO");
cardNO = cardNO != null ? cardNO.trim() : "";
log.info("userName =" + userName + " f_ConsumerNO =" + consumerNO + " f_CardNO =" + cardNO);
UserCardInfo userCardInfo = new UserCardInfo();
userCardInfo.setUserName(userName);
userCardInfo.setUserId(consumerNO);
userCardInfo.setCardNo(cardNO);
userCardInfoList.add(userCardInfo);
log.info("f_ConsumerNO =" + consumerNO + " f_CardNO =" + cardNO);
}
log.info("[JDBC]关闭ResultSet==>[开始]");
rs.close();
log.info("[JDBC]关闭ResultSet==>[结束]");
log.info("[JDBC]关闭Statement==>[开始]");
stmt.close();
log.info("[JDBC]关闭Statement==>[结束]");
log.info("[JDBC]关闭Connection==>[开始]");
conn.close();
log.info("[JDBC]关闭Connection==>[结束]");
} catch (Exception e) {
log.error("[查询Access数据库]异常==>", e);
if (rs != null) {
log.info("[异常][JDBC]关闭ResultSet==>[开始]");
rs.close();
log.info("[异常][JDBC]关闭ResultSet==>[结束]");
}
if (stmt != null) {
log.info("[异常][JDBC]关闭Statement==>[开始]");
stmt.close();
log.info("[异常][JDBC]关闭Statement==>[结束]");
}
if (conn != null) {
log.info("[异常][JDBC]关闭Connection==>[开始]");
conn.close();
log.info("[异常][JDBC]关闭Connection==>[结束]");
}
}
return userCardInfoList;
}
// 这里做数据查询
public static void main(String[] args) throws Exception {
// access数据库文件所在路径
String access_dir = "D:/iCCard3000.mdb";
......
......@@ -6,6 +6,7 @@ import java.io.Serializable;
@Data
public class UserCardInfo implements Serializable {
private String userId;
private String CardNo;
private String userName; //用户名称
private String userId; //用户userId
private String CardNo; //用户卡号
}
......@@ -26,7 +26,7 @@ public class SwaggerConfig {
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("会议系统工具").description("").version("V4.8").build();
return new ApiInfoBuilder().title("会议系统工具").description("").version("0.0.1").build();
}
}
......@@ -21,5 +21,9 @@ logback:
info-history: 10
error-history: 10
# access数据库配置
access:
# access数据库配置密码
pwd: 168168
# access数据库存储文件路径
dir: D:/iCCard3000.mdb
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