Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
znks
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王夏晖
znks
Commits
a8302cf6
Commit
a8302cf6
authored
Sep 06, 2018
by
张大伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加新功能,删除无用代码
parent
9c42690c
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
381 additions
and
471 deletions
+381
-471
DruidDataSourceConfig.java
...in/java/com/adc/da/main/config/DruidDataSourceConfig.java
+0
-222
MybatisConfig.java
...n/src/main/java/com/adc/da/main/config/MybatisConfig.java
+39
-0
DataSourceContextHolder.java
...main/java/com/adc/da/main/ds/DataSourceContextHolder.java
+0
-31
DynamicDataSource.java
...n/src/main/java/com/adc/da/main/ds/DynamicDataSource.java
+0
-16
DynamicDataSourceAspect.java
...main/java/com/adc/da/main/ds/DynamicDataSourceAspect.java
+0
-56
BaseEOController.java
...ain/java/com/adc/da/znks/controller/BaseEOController.java
+0
-33
DeviceController.java
...ain/java/com/adc/da/znks/controller/DeviceController.java
+63
-0
GatewayController.java
...in/java/com/adc/da/znks/controller/GatewayController.java
+28
-3
UserController.java
.../main/java/com/adc/da/znks/controller/UserController.java
+10
-11
BaseEODao.java
adc-da-main/src/main/java/com/adc/da/znks/dao/BaseEODao.java
+0
-19
DeviceDao.java
adc-da-main/src/main/java/com/adc/da/znks/dao/DeviceDao.java
+22
-0
UserDao.java
adc-da-main/src/main/java/com/adc/da/znks/dao/UserDao.java
+1
-1
Device.java
adc-da-main/src/main/java/com/adc/da/znks/entity/Device.java
+89
-0
Gateway.java
...da-main/src/main/java/com/adc/da/znks/entity/Gateway.java
+16
-6
BaseEOService.java
.../src/main/java/com/adc/da/znks/service/BaseEOService.java
+0
-34
DeviceService.java
.../src/main/java/com/adc/da/znks/service/DeviceService.java
+32
-0
GatewayService.java
...src/main/java/com/adc/da/znks/service/GatewayService.java
+10
-3
UserService.java
...in/src/main/java/com/adc/da/znks/service/UserService.java
+15
-10
DeviceVO.java
adc-da-main/src/main/java/com/adc/da/znks/vo/DeviceVO.java
+16
-0
GatewayVO.java
adc-da-main/src/main/java/com/adc/da/znks/vo/GatewayVO.java
+16
-0
application.properties
adc-da-main/src/main/resources/application.properties
+3
-3
BaseEOMapper.xml
...n/src/main/resources/mybatis/mapper/znks/BaseEOMapper.xml
+0
-12
DeviceMapper.xml
...n/src/main/resources/mybatis/mapper/znks/DeviceMapper.xml
+19
-0
csrfWhite.txt
adc-da-main/src/main/resources/white/csrfWhite.txt
+1
-0
adc-da.iml
adc-da.iml
+1
-11
No files found.
adc-da-main/src/main/java/com/adc/da/main/config/DruidDataSourceConfig.java
deleted
100644 → 0
View file @
9c42690c
package
com
.
adc
.
da
.
main
.
config
;
import
com.adc.da.main.ds.DataSourceContextHolder
;
import
com.adc.da.main.ds.DynamicDataSource
;
import
com.alibaba.druid.filter.Filter
;
import
com.alibaba.druid.filter.logging.Slf4jLogFilter
;
import
com.alibaba.druid.filter.stat.StatFilter
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.support.http.StatViewServlet
;
import
com.alibaba.druid.support.http.WebStatFilter
;
import
com.alibaba.druid.support.spring.stat.DruidStatInterceptor
;
import
com.alibaba.druid.wall.WallConfig
;
import
com.alibaba.druid.wall.WallFilter
;
import
org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.Environment
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
javax.sql.DataSource
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* Druid的DataResource配置类
* 凡是被Spring管理的类,实现接口 EnvironmentAware 重写方法 setEnvironment 可以在工程启动时,
* 获取到系统环境变量和application配置文件中的变量。 还有一种方式是采用注解的方式获取 @value("${变量的key值}")
*/
@Configuration
@EnableTransactionManagement
public
class
DruidDataSourceConfig
implements
EnvironmentAware
{
private
RelaxedPropertyResolver
propertyResolver
;
private
RelaxedPropertyResolver
propertyResolver2
;
@Override
public
void
setEnvironment
(
Environment
env
)
{
this
.
propertyResolver
=
new
RelaxedPropertyResolver
(
env
,
"spring.datasource."
);
this
.
propertyResolver2
=
new
RelaxedPropertyResolver
(
env
,
"spring.datasource.ds2."
);
}
@Bean
(
name
=
"ds1"
)
public
DataSource
dataSource1
()
{
DruidDataSource
datasource
=
new
DruidDataSource
();
datasource
.
setUrl
(
propertyResolver
.
getProperty
(
"url"
));
datasource
.
setDriverClassName
(
propertyResolver
.
getProperty
(
"driver-class-name"
));
datasource
.
setUsername
(
propertyResolver
.
getProperty
(
"username"
));
datasource
.
setPassword
(
propertyResolver
.
getProperty
(
"password"
));
datasource
.
setInitialSize
(
Integer
.
valueOf
(
propertyResolver
.
getProperty
(
"initialSize"
)));
datasource
.
setMinIdle
(
Integer
.
valueOf
(
propertyResolver
.
getProperty
(
"minIdle"
)));
datasource
.
setMaxWait
(
Long
.
valueOf
(
propertyResolver
.
getProperty
(
"maxWait"
)));
datasource
.
setMaxActive
(
Integer
.
valueOf
(
propertyResolver
.
getProperty
(
"maxActive"
)));
datasource
.
setMinEvictableIdleTimeMillis
(
Long
.
valueOf
(
propertyResolver
.
getProperty
(
"minEvictableIdleTimeMillis"
)));
// try {
// datasource.setFilters("stat,wall");
// } catch (SQLException e) {
// e.printStackTrace();
// }
//filters和proxyFilters属性是组合关系的,不是替换的
List
<
Filter
>
filters
=
new
ArrayList
<
Filter
>();
filters
.
add
(
wallFilter
());
filters
.
add
(
statFilter
());
filters
.
add
(
slf4jLogFilter
());
datasource
.
setProxyFilters
(
filters
);
return
datasource
;
}
@Bean
(
name
=
"ds2"
)
public
DataSource
dataSource2
()
{
DruidDataSource
datasource
=
new
DruidDataSource
();
datasource
.
setUrl
(
propertyResolver2
.
getProperty
(
"url"
));
datasource
.
setDriverClassName
(
propertyResolver
.
getProperty
(
"driver-class-name"
));
datasource
.
setUsername
(
propertyResolver2
.
getProperty
(
"username"
));
datasource
.
setPassword
(
propertyResolver2
.
getProperty
(
"password"
));
datasource
.
setInitialSize
(
Integer
.
valueOf
(
propertyResolver
.
getProperty
(
"initialSize"
)));
datasource
.
setMinIdle
(
Integer
.
valueOf
(
propertyResolver
.
getProperty
(
"minIdle"
)));
datasource
.
setMaxWait
(
Long
.
valueOf
(
propertyResolver
.
getProperty
(
"maxWait"
)));
datasource
.
setMaxActive
(
Integer
.
valueOf
(
propertyResolver
.
getProperty
(
"maxActive"
)));
datasource
.
setMinEvictableIdleTimeMillis
(
Long
.
valueOf
(
propertyResolver
.
getProperty
(
"minEvictableIdleTimeMillis"
)));
// try {
// datasource.setFilters("stat,wall");
// } catch (SQLException e) {
// e.printStackTrace();
// }
//filters和proxyFilters属性是组合关系的,不是替换的
List
<
Filter
>
filters
=
new
ArrayList
<
Filter
>();
filters
.
add
(
wallFilter
());
filters
.
add
(
statFilter
());
filters
.
add
(
slf4jLogFilter
());
datasource
.
setProxyFilters
(
filters
);
return
datasource
;
}
/**
* 动态数据源: 通过AOP在不同数据源之间动态切换
* @return
*/
@Bean
(
name
=
"dynamicDS"
)
public
DataSource
dataSource
()
{
DynamicDataSource
dynamicDataSource
=
new
DynamicDataSource
();
DataSource
ds1
=
dataSource1
();
DataSource
ds2
=
dataSource2
();
// 默认数据源
dynamicDataSource
.
setDefaultTargetDataSource
(
ds1
);
// 配置多数据源
Map
<
Object
,
Object
>
dsMap
=
new
HashMap
(
5
);
dsMap
.
put
(
"ds1"
,
ds1
);
dsMap
.
put
(
"ds2"
,
ds2
);
dynamicDataSource
.
setTargetDataSources
(
dsMap
);
return
dynamicDataSource
;
}
@Bean
(
name
=
"transactionManager"
)
public
DataSourceTransactionManager
transactionManagers
()
{
return
new
DataSourceTransactionManager
(
dataSource
());
}
@Bean
public
StatFilter
statFilter
()
{
StatFilter
statFilter
=
new
StatFilter
();
// SQL合并配置
statFilter
.
setMergeSql
(
Boolean
.
valueOf
(
propertyResolver
.
getProperty
(
"mergeSql"
)));
// 慢SQL记录
// slowSqlMillis用来配置SQL慢的标准,执行时间超过slowSqlMillis的就是慢
statFilter
.
setSlowSqlMillis
(
Long
.
valueOf
(
propertyResolver
.
getProperty
(
"slowSqlMillis"
)));
// 通过日志输出执行慢的SQL
statFilter
.
setLogSlowSql
(
Boolean
.
valueOf
(
propertyResolver
.
getProperty
(
"logSlowSql"
)));
return
statFilter
;
}
@Bean
public
WallFilter
wallFilter
(){
WallFilter
wallFilter
=
new
WallFilter
();
//刚开始引入WallFilter的时候,把logViolation设置为true,而throwException设置为false。
//就可以观察是否存在违规的情况,同时不影响业务运行。
//对被认为是攻击的SQL进行LOG.error输出
wallFilter
.
setLogViolation
(
true
);
//对被认为是攻击的SQL抛出SQLExcepton
wallFilter
.
setThrowException
(
false
);
// 防止druid 在写批量更新的时候出现错误
wallFilter
.
setConfig
(
wallConfig
());
return
wallFilter
;
}
@Bean
public
WallConfig
wallConfig
(){
WallConfig
wallConfig
=
new
WallConfig
();
// 防止druid 在写批量更新的时候出现错误
wallConfig
.
setMultiStatementAllow
(
true
);
return
wallConfig
;
}
@Bean
public
Slf4jLogFilter
slf4jLogFilter
()
{
Slf4jLogFilter
slf4jLogFilter
=
new
Slf4jLogFilter
();
return
slf4jLogFilter
;
}
@Bean
public
ServletRegistrationBean
druidServlet
()
{
ServletRegistrationBean
servletRegistrationBean
=
new
ServletRegistrationBean
();
servletRegistrationBean
.
setServlet
(
new
StatViewServlet
());
servletRegistrationBean
.
addUrlMappings
(
"/druid/*"
);
Map
<
String
,
String
>
initParameters
=
new
HashMap
<
String
,
String
>();
// initParameters.put("loginUsername", "druid");// 用户名
// initParameters.put("loginPassword", "druid");// 密码
initParameters
.
put
(
"resetEnable"
,
"false"
);
// 禁用HTML页面上的“Reset All”功能
initParameters
.
put
(
"allow"
,
"127.0.0.1"
);
// IP白名单 (没有配置或者为空,则允许所有访问)
// initParameters.put("deny", "192.168.20.38");// IP黑名单
// (存在共同时,deny优先于allow)
servletRegistrationBean
.
setInitParameters
(
initParameters
);
return
servletRegistrationBean
;
}
@Bean
public
FilterRegistrationBean
filterRegistrationBean
()
{
FilterRegistrationBean
filterRegistrationBean
=
new
FilterRegistrationBean
();
filterRegistrationBean
.
setFilter
(
new
WebStatFilter
());
filterRegistrationBean
.
addUrlPatterns
(
"/*"
);
filterRegistrationBean
.
addInitParameter
(
"exclusions"
,
"*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
);
return
filterRegistrationBean
;
}
// 按照BeanId来拦截配置 用来bean的监控
@Bean
(
value
=
"druid-stat-interceptor"
)
public
DruidStatInterceptor
DruidStatInterceptor
()
{
DruidStatInterceptor
druidStatInterceptor
=
new
DruidStatInterceptor
();
return
druidStatInterceptor
;
}
@Bean
public
BeanNameAutoProxyCreator
beanNameAutoProxyCreator
()
{
BeanNameAutoProxyCreator
beanNameAutoProxyCreator
=
new
BeanNameAutoProxyCreator
();
beanNameAutoProxyCreator
.
setProxyTargetClass
(
true
);
// 设置要监控的bean的id
//beanNameAutoProxyCreator.setBeanNames("sysRoleMapper","loginController");
beanNameAutoProxyCreator
.
setInterceptorNames
(
"druid-stat-interceptor"
);
return
beanNameAutoProxyCreator
;
}
}
adc-da-main/src/main/java/com/adc/da/main/
ds
/MybatisConfig.java
→
adc-da-main/src/main/java/com/adc/da/main/
config
/MybatisConfig.java
View file @
a8302cf6
package
com
.
adc
.
da
.
main
.
ds
;
package
com
.
adc
.
da
.
main
.
config
;
import
javax.sql.DataSource
;
...
...
@@ -10,28 +10,30 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
@Configuration
@MapperScan
(
basePackages
=
{
"com.adc.nevpit.dao.**"
,
"com.adc.nevpit.dao"
,
"com.adc.da.**.dao"
},
sqlSessionFactoryRef
=
"sqlSessionFactory
"
)
@MapperScan
(
"com.adc.da.**.dao
"
)
public
class
MybatisConfig
{
@Autowired
@Qualifier
(
"dynamicDS
"
)
private
DataSource
dynamicDS
;
//
@Autowired
// @Qualifier("dataSource
")
// private DataSource dataSource
;
@Bean
public
SqlSessionFactory
sqlSessionFactory
()
throws
Exception
{
SqlSessionFactoryBean
factoryBean
=
new
SqlSessionFactoryBean
();
factoryBean
.
setDataSource
(
dynamicDS
);
factoryBean
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
"classpath*:mybatis/mapper/**/*.xml"
));
return
factoryBean
.
getObject
();
}
// @Bean
// public SqlSessionFactory sqlSessionFactory() throws Exception {
// SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
// factoryBean.setDataSource(dataSource);
// factoryBean.setMapperLocations(
// new PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/mapper/**/*.xml"));
// factoryBean.setConfigLocation(new ClassPathResource("mybatis/mybatis-config.xml"));
// return factoryBean.getObject();
// }
@Bean
public
SqlSessionTemplate
sqlSessionTemplate
()
throws
Exception
{
SqlSessionTemplate
template
=
new
SqlSessionTemplate
(
sqlSessionFactory
());
return
template
;
}
//
@Bean
//
public SqlSessionTemplate sqlSessionTemplate() throws Exception {
//
SqlSessionTemplate template = new SqlSessionTemplate(sqlSessionFactory());
//
return template;
//
}
}
adc-da-main/src/main/java/com/adc/da/main/ds/DataSourceContextHolder.java
deleted
100644 → 0
View file @
9c42690c
package
com
.
adc
.
da
.
main
.
ds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
DataSourceContextHolder
{
public
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
DataSourceContextHolder
.
class
);
/**
* 默认数据源
*/
public
static
final
String
DEFAULT_DS
=
"ds1"
;
private
static
final
ThreadLocal
<
String
>
contextHolder
=
new
ThreadLocal
<>();
// 设置数据源名
public
static
void
setDB
(
String
dbType
)
{
log
.
debug
(
"切换到{}数据源"
,
dbType
);
contextHolder
.
set
(
dbType
);
}
// 获取数据源名
public
static
String
getDB
()
{
return
(
contextHolder
.
get
());
}
// 清除数据源名
public
static
void
clearDB
()
{
contextHolder
.
remove
();
}
}
adc-da-main/src/main/java/com/adc/da/main/ds/DynamicDataSource.java
deleted
100644 → 0
View file @
9c42690c
package
com
.
adc
.
da
.
main
.
ds
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
;
public
class
DynamicDataSource
extends
AbstractRoutingDataSource
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
DynamicDataSource
.
class
);
@Override
protected
Object
determineCurrentLookupKey
()
{
log
.
debug
(
"数据源为{}"
,
DataSourceContextHolder
.
getDB
());
return
DataSourceContextHolder
.
getDB
();
}
}
\ No newline at end of file
adc-da-main/src/main/java/com/adc/da/main/ds/DynamicDataSourceAspect.java
deleted
100644 → 0
View file @
9c42690c
package
com
.
adc
.
da
.
main
.
ds
;
import
java.lang.reflect.Method
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.After
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
com.adc.da.util.annotation.DS
;
@Aspect
@Order
(
1
)
@Component
public
class
DynamicDataSourceAspect
{
@Before
(
"@annotation(com.adc.da.util.annotation.DS)"
)
public
void
beforeSwitchDS
(
JoinPoint
point
)
{
// 获得当前访问的class
Class
<?>
className
=
point
.
getTarget
().
getClass
();
// 获得访问的方法名
String
methodName
=
point
.
getSignature
().
getName
();
// 得到方法的参数的类型
Class
[]
argClass
=
((
MethodSignature
)
point
.
getSignature
()).
getParameterTypes
();
String
dataSource
=
DataSourceContextHolder
.
DEFAULT_DS
;
try
{
// 得到访问的方法对象
Method
method
=
className
.
getMethod
(
methodName
,
argClass
);
// 判断是否存在@DS注解
if
(
method
.
isAnnotationPresent
(
DS
.
class
))
{
DS
annotation
=
method
.
getAnnotation
(
DS
.
class
);
// 取出注解中的数据源名
dataSource
=
annotation
.
value
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
// 切换数据源
DataSourceContextHolder
.
setDB
(
dataSource
);
}
@After
(
"@annotation(com.adc.da.util.annotation.DS)"
)
public
void
afterSwitchDS
(
JoinPoint
point
)
{
DataSourceContextHolder
.
clearDB
();
}
}
adc-da-main/src/main/java/com/adc/da/znks/controller/BaseEOController.java
deleted
100644 → 0
View file @
9c42690c
package
com
.
adc
.
da
.
znks
.
controller
;
import
com.adc.da.base.web.BaseController
;
import
com.adc.da.util.http.ResponseMessage
;
import
com.adc.da.util.http.Result
;
import
com.adc.da.znks.service.BaseEOService
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @ClassName BaseEOController
* @Descroption TODO 基础信息服务接口
* @Author 王夏晖
* @Date 2018/8/15 0015 8:39
**/
@RestController
@RequestMapping
(
"/${restPath}/user"
)
public
class
BaseEOController
extends
BaseController
{
@Autowired
private
BaseEOService
baseEOService
;
@ApiOperation
(
value
=
"查询用户"
)
@PostMapping
(
"/queryUser"
)
public
ResponseMessage
queryUser
()
throws
Exception
{
return
Result
.
success
(
"1"
,
baseEOService
.
queryUser
());
}
}
adc-da-main/src/main/java/com/adc/da/znks/controller/DeviceController.java
0 → 100644
View file @
a8302cf6
package
com
.
adc
.
da
.
znks
.
controller
;
import
com.adc.da.base.web.BaseController
;
import
com.adc.da.util.utils.UUID
;
import
com.adc.da.znks.entity.Device
;
import
com.adc.da.znks.entity.ResponseEntity
;
import
com.adc.da.znks.entity.User
;
import
com.adc.da.znks.service.DeviceService
;
import
com.adc.da.znks.service.UserService
;
import
com.adc.da.znks.util.GenResponse
;
import
com.adc.da.znks.vo.DeviceVO
;
import
io.swagger.annotations.Api
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* @author David
*/
@RestController
@RequestMapping
(
"/api/device"
)
@Api
(
description
=
"| Device |"
)
public
class
DeviceController
extends
BaseController
<
Device
>
{
@Autowired
private
DeviceService
deviceService
;
@Autowired
private
UserService
userService
;
@PostMapping
(
"/save"
)
public
ResponseEntity
save
(
DeviceVO
deviceVO
)
{
User
user
=
userService
.
getByPhoneNumber
(
deviceVO
.
getPhoneNumber
());
try
{
deviceVO
.
setId
(
UUID
.
randomUUID
());
deviceVO
.
setUserId
(
user
.
getId
());
deviceService
.
insertSelective
(
deviceVO
);
return
GenResponse
.
success
();
}
catch
(
Exception
e
)
{
return
GenResponse
.
fail
(
"保存失败"
);
}
}
@GetMapping
(
"/getListByPhoneNumber"
)
public
ResponseEntity
<
List
<
Device
>>
getListByPhoneNumber
(
String
phoneNumber
)
{
List
<
Device
>
list
=
deviceService
.
listByPhoneNumber
(
phoneNumber
);
return
GenResponse
.
success
(
"1"
,
"查询成功"
,
list
);
}
@GetMapping
(
"/delete"
)
public
ResponseEntity
<
Boolean
>
delete
(
String
id
)
{
try
{
deviceService
.
deleteByPrimaryKey
(
id
);
return
GenResponse
.
success
();
}
catch
(
Exception
e
)
{
return
GenResponse
.
fail
(
"删除失败"
);
}
}
}
adc-da-main/src/main/java/com/adc/da/znks/controller/GatewayController.java
View file @
a8302cf6
package
com
.
adc
.
da
.
znks
.
controller
;
import
com.adc.da.base.web.BaseController
;
import
com.adc.da.util.utils.UUID
;
import
com.adc.da.znks.entity.Gateway
;
import
com.adc.da.znks.entity.ResponseEntity
;
import
com.adc.da.znks.entity.User
;
import
com.adc.da.znks.service.GatewayService
;
import
com.adc.da.znks.service.UserService
;
import
com.adc.da.znks.util.GenResponse
;
import
com.adc.da.znks.vo.GatewayVO
;
import
io.swagger.annotations.Api
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -22,10 +27,30 @@ public class GatewayController extends BaseController<Gateway> {
@Autowired
private
GatewayService
gatewayService
;
@PostMapping
(
""
)
public
ResponseEntity
addGateway
(
Gateway
gateway
)
{
@Autowired
private
UserService
userService
;
@PostMapping
(
"/save"
)
public
ResponseEntity
save
(
GatewayVO
gateway
)
{
User
user
=
userService
.
getByPhoneNumber
(
gateway
.
getPhoneNumber
());
try
{
gateway
.
setId
(
UUID
.
randomUUID
());
gateway
.
setUserId
(
user
.
getId
());
int
count
=
gatewayService
.
insertSelective
(
gateway
);
if
(
count
>
0
)
{
return
GenResponse
.
success
();
}
else
{
return
GenResponse
.
fail
(
"保存失败"
);
}
}
catch
(
Exception
e
)
{
return
GenResponse
.
fail
(
"保存失败"
);
}
}
return
GenResponse
.
success
();
@GetMapping
(
"/isHaveGateway"
)
public
ResponseEntity
<
Boolean
>
isHaveGateway
(
String
phoneNumber
)
{
boolean
flag
=
gatewayService
.
getByPhoneNumber
(
phoneNumber
);
return
GenResponse
.
success
(
"0"
,
""
,
flag
);
}
}
adc-da-main/src/main/java/com/adc/da/znks/controller/UserController.java
View file @
a8302cf6
...
...
@@ -14,11 +14,10 @@ import org.springframework.http.HttpStatus;
import
org.springframework.web.bind.annotation.*
;
@RestController
@RequestMapping
(
"/api/
entity/users
"
)
@RequestMapping
(
"/api/
user
"
)
@Api
(
description
=
"|User|"
)
public
class
UserController
extends
BaseController
<
User
>
{
@Autowired
private
UserService
userService
;
...
...
@@ -26,17 +25,17 @@ public class UserController extends BaseController<User> {
@ApiOperation
(
value
=
"|User|登录或者注册用户"
)
@PostMapping
(
value
=
{
"/loginOrRegisterUser"
})
public
ResponseEntity
<
String
>
loginOrRegisterUser
(
@RequestBody
User
user
)
throws
Exception
{
public
ResponseEntity
<
Boolean
>
loginOrRegisterUser
(
@RequestBody
User
user
)
{
log
.
info
(
"user: {}"
,
user
);
String
id
=
userService
.
loginOrRegister
(
user
.
getTemphone
(),
user
.
getPlainPassword
());
if
(
id
!=
null
)
{
return
GenResponse
.
success
(
String
.
valueOf
(
HttpStatus
.
OK
.
value
()),
"登录或者注册用户成功"
,
id
);
boolean
flag
=
userService
.
loginOrRegister
(
user
.
getTemphone
(),
user
.
getPlainPassword
());
if
(
flag
)
{
return
GenResponse
.
success
(
String
.
valueOf
(
HttpStatus
.
OK
.
value
()),
"登录或者注册用户成功"
,
flag
);
}
else
{
return
GenResponse
.
fail
(
"登录或者注册用户失败"
);
}
}
@ApiOperation
(
value
=
"|User|
登录或者注册用户
"
)
@ApiOperation
(
value
=
"|User|
查询当前手机号是否已经注册
"
)
@GetMapping
(
value
=
{
"/isRegister"
})
public
ResponseEntity
<
Boolean
>
isRegister
(
String
phoneNumber
)
{
boolean
flag
=
userService
.
getUserByPhoneNumber
(
phoneNumber
);
...
...
@@ -45,10 +44,10 @@ public class UserController extends BaseController<User> {
@ApiOperation
(
value
=
"|User|更新密码"
)
@PostMapping
(
"/updatePassword"
)
public
ResponseEntity
<
String
>
update
(
@RequestBody
User
user
)
throws
Exception
{
String
id
=
userService
.
updatePassword
(
user
);
if
(
id
!=
null
)
{
return
GenResponse
.
success
(
String
.
valueOf
(
HttpStatus
.
OK
.
value
()),
"更新密码成功"
,
id
);
public
ResponseEntity
<
Boolean
>
update
(
@RequestBody
User
user
)
{
boolean
flag
=
userService
.
updatePassword
(
user
);
if
(
flag
)
{
return
GenResponse
.
success
(
String
.
valueOf
(
HttpStatus
.
OK
.
value
()),
"更新密码成功"
,
flag
);
}
else
{
return
GenResponse
.
fail
(
"更新密码失败"
);
}
...
...
adc-da-main/src/main/java/com/adc/da/znks/dao/BaseEODao.java
deleted
100644 → 0
View file @
9c42690c
package
com
.
adc
.
da
.
znks
.
dao
;
import
com.adc.da.base.dao.BaseDao
;
import
java.util.List
;
import
java.util.Map
;
/**
* @ClassName BaseEODao
* @Descroption TODO
* @Author 王夏晖
* @Date 2018/8/15 0015 15:02
* 考虑实体变动,所有传参及数据接收均未使用
**/
public
interface
BaseEODao
extends
BaseDao
{
List
<
Map
<
String
,
Object
>>
queryUser
();
}
adc-da-main/src/main/java/com/adc/da/znks/dao/DeviceDao.java
0 → 100644
View file @
a8302cf6
package
com
.
adc
.
da
.
znks
.
dao
;
import
com.adc.da.base.dao.BaseDao
;
import
com.adc.da.znks.entity.Device
;
import
org.apache.ibatis.annotations.Mapper
;
import
java.util.List
;
/**
* @author David
*/
@Mapper
public
interface
DeviceDao
extends
BaseDao
<
Device
>
{
/**
* 根据手机号查询改手机号下的所有设备
* @param phoneNumber
* @return
*/
List
<
Device
>
listByPhoneNumber
(
String
phoneNumber
);
}
adc-da-main/src/main/java/com/adc/da/znks/dao/UserDao.java
View file @
a8302cf6
...
...
@@ -15,7 +15,7 @@ import org.apache.ibatis.annotations.Select;
@Mapper
public
interface
UserDao
extends
BaseDao
<
User
>
{
@Select
(
"SELECT * FROM tb_user WHERE temp
p
hone = #{phoneNumber}"
)
@Select
(
"SELECT * FROM tb_user WHERE temphone = #{phoneNumber}"
)
User
getUserByPhoneNumber
(
@Param
(
"phoneNumber"
)
String
phoneNumber
);
}
adc-da-main/src/main/java/com/adc/da/znks/entity/Device.java
0 → 100644
View file @
a8302cf6
package
com
.
adc
.
da
.
znks
.
entity
;
import
com.adc.da.base.entity.BaseEntity
;
/**
* @author David
*/
public
class
Device
extends
BaseEntity
{
private
String
id
;
private
String
userId
;
private
String
name
;
private
int
code
;
private
int
type
;
private
String
userName
;
private
String
userPassword
;
private
String
uid
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
public
int
getType
()
{
return
type
;
}
public
void
setType
(
int
type
)
{
this
.
type
=
type
;
}
public
String
getUserName
()
{
return
userName
;
}
public
void
setUserName
(
String
userName
)
{
this
.
userName
=
userName
;
}
public
String
getUserPassword
()
{
return
userPassword
;
}
public
void
setUserPassword
(
String
userPassword
)
{
this
.
userPassword
=
userPassword
;
}
public
String
getUid
()
{
return
uid
;
}
public
void
setUid
(
String
uid
)
{
this
.
uid
=
uid
;
}
}
adc-da-main/src/main/java/com/adc/da/znks/entity/Gateway.java
View file @
a8302cf6
...
...
@@ -7,22 +7,32 @@ import com.adc.da.base.entity.BaseEntity;
*/
public
class
Gateway
extends
BaseEntity
{
private
int
id
;
private
String
id
;
private
String
password
;
private
String
macAddress
;
private
String
ip
;
private
int
userId
;
private
String
userId
;
public
int
getId
()
{
public
String
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getMacAddress
()
{
return
macAddress
;
}
...
...
@@ -39,11 +49,11 @@ public class Gateway extends BaseEntity {
this
.
ip
=
ip
;
}
public
int
getUserId
()
{
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
int
userId
)
{
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
}
adc-da-main/src/main/java/com/adc/da/znks/service/BaseEOService.java
deleted
100644 → 0
View file @
9c42690c
package
com
.
adc
.
da
.
znks
.
service
;
import
com.adc.da.base.service.BaseService
;
import
com.adc.da.znks.dao.BaseEODao
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Map
;
/**
* @ClassName BaseEOService
* @Descroption TODO
* @Author 王夏晖
* Date 2018/8/16 0016 15:33
**/
@Service
(
"baseEOService"
)
public
class
BaseEOService
extends
BaseService
{
@Autowired
private
BaseEODao
baseEODao
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BaseEOService
.
class
);
public
BaseEODao
getDao
()
{
return
baseEODao
;
}
public
List
<
Map
<
String
,
Object
>>
queryUser
(){
return
baseEODao
.
queryUser
();
}
}
adc-da-main/src/main/java/com/adc/da/znks/service/DeviceService.java
0 → 100644
View file @
a8302cf6
package
com
.
adc
.
da
.
znks
.
service
;
import
com.adc.da.base.dao.BaseDao
;
import
com.adc.da.base.service.BaseService
;
import
com.adc.da.znks.dao.DeviceDao
;
import
com.adc.da.znks.entity.Device
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
/**
* @author David
*/
@Service
@Transactional
(
value
=
"transactionManager"
,
propagation
=
Propagation
.
REQUIRED
,
rollbackFor
=
Throwable
.
class
)
public
class
DeviceService
extends
BaseService
<
Device
,
String
>
{
@Autowired
(
required
=
false
)
private
DeviceDao
dao
;
@Override
public
BaseDao
<
Device
>
getDao
()
{
return
dao
;
}
public
List
<
Device
>
listByPhoneNumber
(
String
phoneNumber
)
{
return
dao
.
listByPhoneNumber
(
phoneNumber
);
}
}
adc-da-main/src/main/java/com/adc/da/znks/service/GatewayService.java
View file @
a8302cf6
...
...
@@ -14,9 +14,9 @@ import org.springframework.transaction.annotation.Transactional;
/**
* @author David
*/
@Service
(
"userService"
)
@Service
@Transactional
(
value
=
"transactionManager"
,
propagation
=
Propagation
.
REQUIRED
,
rollbackFor
=
Throwable
.
class
)
public
class
GatewayService
extends
BaseService
<
Gateway
,
Integer
>
{
public
class
GatewayService
extends
BaseService
<
Gateway
,
String
>
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
GatewayService
.
class
);
...
...
@@ -28,5 +28,12 @@ public class GatewayService extends BaseService<Gateway, Integer> {
return
dao
;
}
public
Boolean
getByPhoneNumber
(
String
phoneNumber
)
{
boolean
flag
=
false
;
Gateway
gateway
=
dao
.
getByPhoneNumber
(
phoneNumber
);
if
(
gateway
!=
null
)
{
flag
=
true
;
}
return
flag
;
}
}
adc-da-main/src/main/java/com/adc/da/znks/service/UserService.java
View file @
a8302cf6
...
...
@@ -26,7 +26,7 @@ import java.util.List;
*
* @author ley
*/
@Service
(
"userService"
)
@Service
@Transactional
(
value
=
"transactionManager"
,
propagation
=
Propagation
.
REQUIRED
,
rollbackFor
=
Throwable
.
class
)
public
class
UserService
extends
BaseService
<
User
,
String
>
{
...
...
@@ -49,10 +49,15 @@ public class UserService extends BaseService<User, String> {
return
flag
;
}
public
User
getByPhoneNumber
(
String
phoneNumber
)
{
return
dao
.
getUserByPhoneNumber
(
phoneNumber
);
}
/**
* update password
**/
public
String
updatePassword
(
User
user
)
{
public
boolean
updatePassword
(
User
user
)
{
List
<
String
>
encryptList
=
encryptList
(
user
.
getPlainPassword
());
Asserts
.
notNull
(
encryptList
,
"encrypt list must not be null."
);
user
.
setEncryptkey
(
encryptList
.
get
(
0
));
...
...
@@ -65,9 +70,9 @@ public class UserService extends BaseService<User, String> {
updateUser
.
setEncryptkey
(
encryptList
.
get
(
0
));
int
result
=
dao
.
updateByPrimaryKeySelective
(
updateUser
);
if
(
result
!=
0
)
{
return
user
.
getId
()
;
return
true
;
}
else
{
return
null
;
return
false
;
}
}
...
...
@@ -75,30 +80,30 @@ public class UserService extends BaseService<User, String> {
/**
* user login or register
**/
public
String
loginOrRegister
(
String
temphone
,
String
plainPassword
)
{
public
boolean
loginOrRegister
(
String
temphone
,
String
plainPassword
)
{
UserPage
userPage
=
new
UserPage
();
userPage
.
setTemphone
(
temphone
);
List
<
User
>
users
=
dao
.
queryByList
(
userPage
);
if
(
CollectionUtils
.
isEmpty
(
users
))
{
List
<
String
>
encryptList
=
encryptList
(
plainPassword
);
Asserts
.
notNull
(
encryptList
,
"encrypt list must not be null."
);
String
id
=
UUID
.
randomU
serId
();
String
id
=
UUID
.
randomU
UID
();
User
insertUser
=
new
User
(
id
,
temphone
,
encryptList
.
get
(
0
),
encryptList
.
get
(
1
));
logger
.
info
(
"insertUser: {}"
,
insertUser
);
int
result
=
dao
.
insertSelective
(
insertUser
);
if
(
result
!=
0
)
{
return
id
;
return
true
;
}
else
{
return
null
;
return
false
;
}
}
else
{
User
user
=
users
.
get
(
0
);
String
decryptPassword
=
SecurityUtils
.
decrypt
(
user
.
getEncryptkey
(),
user
.
getPassword
());
Asserts
.
notNull
(
plainPassword
,
"plainPassword must not be null."
);
if
(
plainPassword
.
equals
(
decryptPassword
))
{
return
user
.
getId
()
;
return
true
;
}
else
{
return
null
;
return
false
;
}
}
}
...
...
adc-da-main/src/main/java/com/adc/da/znks/vo/DeviceVO.java
0 → 100644
View file @
a8302cf6
package
com
.
adc
.
da
.
znks
.
vo
;
import
com.adc.da.znks.entity.Device
;
public
class
DeviceVO
extends
Device
{
private
String
phoneNumber
;
public
String
getPhoneNumber
()
{
return
phoneNumber
;
}
public
void
setPhoneNumber
(
String
phoneNumber
)
{
this
.
phoneNumber
=
phoneNumber
;
}
}
adc-da-main/src/main/java/com/adc/da/znks/vo/GatewayVO.java
0 → 100644
View file @
a8302cf6
package
com
.
adc
.
da
.
znks
.
vo
;
import
com.adc.da.znks.entity.Gateway
;
public
class
GatewayVO
extends
Gateway
{
private
String
phoneNumber
;
public
String
getPhoneNumber
()
{
return
phoneNumber
;
}
public
void
setPhoneNumber
(
String
phoneNumber
)
{
this
.
phoneNumber
=
phoneNumber
;
}
}
adc-da-main/src/main/resources/application.properties
View file @
a8302cf6
...
...
@@ -14,9 +14,9 @@
# ===============================
#spring.datasource.driverClassName = oracle.jdbc.OracleDriver
##数据库服务器外网ip221.239.111.146 内网10.10.0.3
spring.datasource.ds2.url
=
jdbc:oracle:thin:@60.30.69.61:1521:ADC
spring.datasource.ds2.username
=
cedet_baoxin
spring.datasource.ds2.password
=
cedet_baoxin
#
spring.datasource.ds2.url = jdbc:oracle:thin:@60.30.69.61:1521:ADC
#
spring.datasource.ds2.username = cedet_baoxin
#
spring.datasource.ds2.password = cedet_baoxin
spring.datasource.type
=
com.alibaba.druid.pool.DruidDataSource
# 下面为连接池的补充设置,应用到上面所有数据源中
...
...
adc-da-main/src/main/resources/mybatis/mapper/znks/BaseEOMapper.xml
deleted
100644 → 0
View file @
9c42690c
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.adc.da.znks.dao.BaseEODao"
>
<!-- 损伤情况中英文对照信息 -->
<select
id=
"queryUser"
resultType=
"java.util.Map"
>
select * from sys_user
</select>
</mapper>
adc-da-main/src/main/resources/mybatis/mapper/znks/DeviceMapper.xml
0 → 100644
View file @
a8302cf6
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.adc.da.znks.dao.DeviceDao"
>
<!-- Result Map-->
<resultMap
id=
"BaseResultMap"
type=
"com.adc.da.znks.entity.Device"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"name"
property=
"name"
/>
<result
column=
"code"
property=
"code"
/>
<result
column=
"type"
property=
"type"
/>
<result
column=
"user_name"
property=
"userName"
/>
<result
column=
"user_password"
property=
"userPassword"
/>
<result
column=
"uid"
property=
"uid"
/>
</resultMap>
<select
id=
"listByPhoneNumber"
resultType=
"com.adc.da.znks.entity.Device"
>
select * from tb_device,tb_user
where tb_device.user_id = tb_user.id
and tb_user.temphone = #{phoneNumber}
</select>
</mapper>
adc-da-main/src/main/resources/white/csrfWhite.txt
View file @
a8302cf6
127.0.0.1
192.168.1.109
localhost
index.html
\ No newline at end of file
adc-da.iml
View file @
a8302cf6
<?xml version="1.0" encoding="UTF-8"?>
<module
org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule=
"true"
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
LANGUAGE_LEVEL=
"JDK_1_7"
>
<output
url=
"file://$MODULE_DIR$/target/classes"
/>
<output-test
url=
"file://$MODULE_DIR$/target/test-classes"
/>
<content
url=
"file://$MODULE_DIR$"
>
<excludeFolder
url=
"file://$MODULE_DIR$/target"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
<module
org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule=
"true"
type=
"JAVA_MODULE"
version=
"4"
/>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment