Commit d64433e1 authored by niuzhaodi's avatar niuzhaodi

Initial commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wafersystems</groupId>
<artifactId>accessTransit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>accessTransit</name>
<description>accessTransit</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.21.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 热部署,不用重启 ,这个在这里不需要-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- 阿里巴巴jar包 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.70</version>
</dependency>
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ucanaccess</groupId>
<artifactId>ucanaccess</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>nochump</groupId>
<artifactId>nochump</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
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;
}
}
package com.wafersystems.accessTransit.controller;
import com.wafersystems.accessTransit.model.UserCardInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Api(tags = "AccessDB数据库")
@RequestMapping("/access")
@RestController
public class AccessCtl {
private static String Driver = "net.ucanaccess.jdbc.UcanaccessDriver";
private static String UrlPre = "jdbc:ucanaccess://";
private static String Urlbacken = ";openExclusive=false";
@Value("${access.dir}")
private String dir;
@ApiOperation(value = "查询门禁用户表")
@GetMapping("queryConsumerT")
public Object queryC() {
log.info("--外部应用调用查询Access数据库接口[开始]--" + dir);
Map<String, Object> back = new HashMap<String, Object>();
back.put("status", 1);//1代表请求失败
try {
List<UserCardInfo> userCardInfoList = queryConsumerT();
back.put("data", userCardInfoList);
back.put("status", 0);//0代表请求成功
} catch (Exception ex) {
log.error("--外部应用调用查询Access数据库接口[异常]==>", ex);
} finally {
log.info("--外部应用调用查询Access数据库接口[结束]--");
return back;
}
}
private List<UserCardInfo> queryConsumerT() throws Exception {
List<UserCardInfo> userCardInfoList = null;
// access数据库文件所在路径
String access_dir = dir;
String url = UrlPre + access_dir + Urlbacken;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName(Driver);
conn = DriverManager.getConnection(url, "", "168168");
stmt = conn.createStatement();
String sql = "SELECT f_ConsumerNO, f_CardNO FROM t_b_Consumer";
rs = stmt.executeQuery(sql);
userCardInfoList = new ArrayList<UserCardInfo>();
while (rs.next()) {
String consumerNO = rs.getString("f_ConsumerNO");
consumerNO = consumerNO != null ? consumerNO.trim() : "";
String cardNO = rs.getString("f_CardNO");
cardNO = cardNO != null ? cardNO.trim() : "";
UserCardInfo userCardInfo = new UserCardInfo();
userCardInfo.setUserId(consumerNO);
userCardInfo.setCardNo(cardNO);
userCardInfoList.add(userCardInfo);
log.info("f_ConsumerNO =" + consumerNO + " f_CardNO =" + cardNO);
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
log.error("[查询Access数据库]异常==>", e);
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}
return userCardInfoList;
}
// 这里做数据查询
public static void main(String[] args) throws Exception {
// access数据库文件所在路径
String access_dir = "D:/iCCard3000.mdb";
String url = UrlPre + access_dir + Urlbacken;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName(Driver);
conn = DriverManager.getConnection(url, "", "168168");
stmt = conn.createStatement();
String sql = "select * from t_b_Consumer";
rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println(
"f_ConsumerNO =" + rs.getString("f_ConsumerNO") + " f_CardNO =" + rs
.getString("f_CardNO"));
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}
}
}
\ No newline at end of file
package com.wafersystems.accessTransit.model;
import lombok.Data;
import java.io.Serializable;
@Data
public class UserCardInfo implements Serializable {
private String userId;
private String CardNo;
}
package com.wafersystems.commonmodule.config;
/**
* 一些通用的常量
*/
public class Const {
public static final int STATUS_CODE_OK = 10000;//请求正常
public static final int STATUS_CODE_BAD_REQUEST = 40000;//请求异常
public static final int HOST_REACH_ERROR = 40001;//目标机器IP不通
public static final int PORT_REACH_ERROR = 40002;//目标机器IP可以连接,但是端口不通
public static final int CONN_ERROR = 40003;//数据库连接获取失败![DB 账号 密码 数据库名 称配置不正确]
public static final int AD_STATUS_CODE_OK = 40004;//AD配置正确,连接成功,但是没拉取到数据
public static final int AD_ERROR = 40005;//AD配置不正确
public static final int EWS_CONFIG_NULL_ERROR = 40006;//Exchange配置参数有空
public static final int EWS_CONFIG_ERROR = 40007;//Exchange配置不正确
public static final int EWS_FETCH_ERROR = 40008;//Exchange正向拉取数据失败
public static final int EWS_WRITE_ERROR = 40009;//Exchange反写失败
public static final int EWS_SERVICE_ERROR = 40010;//[Exchange配置不正确]Exchange的EWS认证没有拿到service对象
public static final int EWS_CONFIG_OTHER_ERROR = 40011;//Exchange的EWS认证[其他日历]循环时出错
public static String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
public static String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver";
}
package com.wafersystems.commonmodule.config;
import com.wafersystems.commonmodule.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import java.util.Objects;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
//对异常Exception类的统一捕捉
@ExceptionHandler(value = Exception.class)
public Result exceptionHandler(HttpServletRequest request, Exception e) {
Result returnEnum = null;
Throwable throwable = getBusinessException(e);
if (!Objects.isNull(throwable)) {
returnEnum = ((BizException) throwable).getResult();
if (((BizException) throwable).getResult() != null) {
return returnEnum;
}
}
return Result.ERROR();
}
/**
* 若有异常进行嵌套,打印出每个异常的堆栈信息,若包含自定义异常,返回最内部的BusinessException异常。
*
* @param e
* @return
*/
private Throwable getBusinessException(Throwable e) {
if (e == null) {
return null;
} else if (e instanceof BizException) {
if (((BizException) e).getResult() != null) {
log.info(((BizException) e).getResult().toString());
}
log.error(e.getMessage(), e);
Throwable temp = getBusinessException(e.getCause());
if (temp == null) {
return e;
} else {
return temp;
}
} else {
log.error(e.getMessage(), e);
return getBusinessException(e.getCause());
}
}
}
package com.wafersystems.commonmodule.config;
import com.alibaba.fastjson.JSON;
import java.io.Serializable;
import static com.wafersystems.commonmodule.config.Const.STATUS_CODE_BAD_REQUEST;
import static com.wafersystems.commonmodule.config.Const.STATUS_CODE_OK;
/**
* 请求返回结果
*/
public class Result implements Serializable {
private static final String SUCCESS_MESSAGE = "OK";
private static final String ERROR_MESSAGE = "ERROR";
private int code; //错误码
private String msg;//错误信息提示
private Object data;//返回数据
public Result() {
code = STATUS_CODE_OK;
msg = SUCCESS_MESSAGE;
}
public Result(int code, String message) {
this.code = code;
this.msg = message;
}
public Result(int code, String message, Object data) {
this.code = code;
this.msg = message;
this.data = data;
}
public int getCode() {
return code;
}
public Result setCode(int code) {
this.code = code;
return this;
}
public String getMsg() {
return msg;
}
public Result setMsg(String msg) {
this.msg = msg;
return this;
}
public Result setData(Object data) {
this.data = data;
return this;
}
public Object getData() {
return data;
}
@Override
public String toString() {
return JSON.toJSONString(this);
}
public static Result OK() {
return new Result(STATUS_CODE_OK, SUCCESS_MESSAGE);
}
public static Result OK(Object data) {
return new Result(STATUS_CODE_OK, SUCCESS_MESSAGE, data);
}
public static Result OK(String message, Object data) {
return new Result(STATUS_CODE_OK, message, data);
}
public static Result OK(int code, String message) {
return new Result(code, message);
}
public static Result ERROR(int code) {
return new Result(code, ERROR_MESSAGE);
}
public static Result ERROR(int code, String message) {
return new Result(code, message);
}
public static Result ERROR(String message) {
return new Result(STATUS_CODE_BAD_REQUEST, message);
}
public static Result ERROR() {
return new Result(STATUS_CODE_BAD_REQUEST, ERROR_MESSAGE);
}
}
package com.wafersystems.commonmodule.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* Swagger 相关配置
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket buildDocket() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.wafersystems")).paths(PathSelectors.any())
.build().pathMapping("/").useDefaultResponseMessages(false).apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("会议系统工具").description("").version("V4.8").build();
}
}
package com.wafersystems.commonmodule.exception;
import com.wafersystems.commonmodule.config.Result;
public class BizException extends RuntimeException {
private Integer code;
private String msg;
public BizException() {
super();
}
public BizException(Integer code, String msg) {
super();
this.code = code;
this.msg = msg;
}
public Result getResult() {
return new Result(code, msg);
}
}
server:
port: 18889
spring:
application:
name: accessTransit
jackson:
serialization:
write-dates-as-timestamps: true
# 日志文件
logging:
# file: ${user.dir}/logs/${spring.application.name}-${server.port}.log
level:
root: info
config: classpath:logging-config.xml
logback:
logdir: ./logs
appname: ${spring.application.name}
level: ${logging.level.root}
max-size: 50MB
info-history: 10
error-history: 10
access:
dir: D:/iCCard3000.mdb
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!--application.yml 传递参数,不能使用logback 自带的<property>标签 -->
<springProperty scope="context" name="appname"
source="logback.appname"/>
<springProperty scope="context" name="logdir" source="logback.logdir"/>
<springProperty scope="context" name="level" source="logback.level"/>
<springProperty scope="context" name="error-history" source="logback.error-history"/>
<springProperty scope="context" name="info-history" source="logback.info-history"/>
<springProperty scope="context" name="max-size" source="logback.max-size"/>
<contextName>${appname}</contextName>
<conversionRule conversionWord="clr"
converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
<!-- 彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="fileInfoLog"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--如果只是想要 Info 级别的日志,只是过滤 info 还是会输出 Error 日志,因为 Error 的级别高, 所以我们使用下面的策略,可以避免输出
Error 的日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!--过滤 Error -->
<level>ERROR</level>