Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
e5e0feb4
Commit
e5e0feb4
authored
Mar 01, 2017
by
lee_mingzhu
Committed by
minminyan
Apr 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
继承motan rpc
parent
46092b41
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
298 additions
and
1 deletion
+298
-1
pom.xml
pom.xml
+55
-0
Bootstrap.java
src/main/java/cn/quantgroup/xyqb/Bootstrap.java
+4
-0
MotanConfig.java
...ain/java/cn/quantgroup/xyqb/config/motan/MotanConfig.java
+60
-0
MotanUserServiceImpl.java
.../xyqb/controller/external/motan/MotanUserServiceImpl.java
+178
-0
application.properties
src/main/resources/config/dev/application.properties
+1
-1
No files found.
pom.xml
View file @
e5e0feb4
...
...
@@ -40,6 +40,12 @@
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jdbc
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
log4j-over-slf4j
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -207,6 +213,55 @@
<artifactId>
quantgroup-config-sdk
</artifactId>
<version>
1.0.3-SNAPSHOT
</version>
</dependency>
<!-- motan -->
<dependency>
<groupId>
com.weibo
</groupId>
<artifactId>
motan-core
</artifactId>
<version>
0.2.2
</version>
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-log4j12
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
com.weibo
</groupId>
<artifactId>
motan-transport-netty
</artifactId>
<version>
0.2.2
</version>
</dependency>
<!-- only needed for spring-based features -->
<dependency>
<groupId>
com.weibo
</groupId>
<artifactId>
motan-springsupport
</artifactId>
<version>
0.2.2
</version>
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-log4j12
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
motan-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
com.weibo
</groupId>
<artifactId>
motan-registry-zookeeper
</artifactId>
<version>
0.2.1
</version>
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-log4j12
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
...
...
src/main/java/cn/quantgroup/xyqb/Bootstrap.java
View file @
e5e0feb4
package
cn
.
quantgroup
.
xyqb
;
import
com.weibo.api.motan.common.MotanConstants
;
import
com.weibo.api.motan.util.MotanSwitcherUtil
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
@@ -22,5 +24,7 @@ public class Bootstrap {
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
Bootstrap
.
class
,
args
);
MotanSwitcherUtil
.
setSwitcherValue
(
MotanConstants
.
REGISTRY_HEARTBEAT_SWITCHER
,
true
);
System
.
out
.
println
(
"server start..."
);
}
}
src/main/java/cn/quantgroup/xyqb/config/motan/MotanConfig.java
0 → 100644
View file @
e5e0feb4
package
cn
.
quantgroup
.
xyqb
.
config
.
motan
;
import
com.weibo.api.motan.config.springsupport.AnnotationBean
;
import
com.weibo.api.motan.config.springsupport.BasicServiceConfigBean
;
import
com.weibo.api.motan.config.springsupport.ProtocolConfigBean
;
import
com.weibo.api.motan.config.springsupport.RegistryConfigBean
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
/**
* Created by 11 on 2017/2/27.
*/
@EnableAutoConfiguration
@SpringBootApplication
public
class
MotanConfig
{
@Bean
public
AnnotationBean
motanAnnotationBean
()
{
AnnotationBean
motanAnnotationBean
=
new
AnnotationBean
();
motanAnnotationBean
.
setPackage
(
"cn.quantgroup.xyqb.controller.external.motan"
);
return
motanAnnotationBean
;
}
@Bean
(
name
=
"demoMotan"
)
public
ProtocolConfigBean
protocolConfig1
()
{
ProtocolConfigBean
config
=
new
ProtocolConfigBean
();
config
.
setDefault
(
true
);
config
.
setName
(
"motan"
);
config
.
setMaxContentLength
(
1048576
);
return
config
;
}
@Bean
(
name
=
"registryConfig"
)
public
RegistryConfigBean
registryConfig
()
{
RegistryConfigBean
config
=
new
RegistryConfigBean
();
config
.
setRegProtocol
(
"zookeeper"
);
config
.
setAddress
(
"127.0.0.1:2181"
);
return
config
;
}
/*@Bean(name = "registryConfig1")
public RegistryConfigBean registryConfig() {
RegistryConfigBean config = new RegistryConfigBean();
config.setRegProtocol("zookeeper");
return config;
}*/
@Bean
public
BasicServiceConfigBean
baseServiceConfig
()
{
BasicServiceConfigBean
config
=
new
BasicServiceConfigBean
();
config
.
setExport
(
"demoMotan:8002"
);
config
.
setGroup
(
"testgroup"
);
config
.
setAccessLog
(
false
);
config
.
setShareChannel
(
true
);
config
.
setModule
(
"motan-demo-rpc"
);
config
.
setApplication
(
"myMotanDemo"
);
config
.
setRegistry
(
"registryConfig"
);
return
config
;
}
}
src/main/java/cn/quantgroup/xyqb/controller/external/motan/MotanUserServiceImpl.java
0 → 100644
View file @
e5e0feb4
package
cn
.
quantgroup
.
xyqb
.
controller
.
external
.
motan
;
import
cn.quantgroup.service.*
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.UserDetail
;
import
cn.quantgroup.xyqb.model.IdType
;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.weibo.api.motan.config.springsupport.annotation.MotanService
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
/**
* Created by 11 on 2017/2/27.
*/
@MotanService
(
export
=
"demoMotan:8002"
,
registry
=
"registryConfig"
)
public
class
MotanUserServiceImpl
implements
UserMotanService
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
MotanUserServiceImpl
.
class
);
private
static
final
ObjectMapper
MAPPER
=
new
ObjectMapper
();
static
{
MAPPER
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
}
@Autowired
private
IIdCardService
idCardService
;
@Autowired
private
IUserService
userService
;
@Autowired
private
IUserDetailService
userDetailService
;
@Override
public
UserSysResult
<
XUser
>
findUserByPhoneNo
(
String
phoneNo
)
{
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
XUser
xUser
=
convertObject
(
JSON
.
toJSONString
(
user
),
new
TypeReference
<
XUser
>()
{});
return
returnValue
(
xUser
,
""
);
}
@Override
public
UserSysResult
<
XUser
>
findUserByUuid
(
String
uuid
)
{
User
user
=
userService
.
findByUuidInDb
(
uuid
);
XUser
xUser
=
convertObject
(
JSON
.
toJSONString
(
user
),
new
TypeReference
<
XUser
>()
{});
return
returnValue
(
xUser
,
""
);
}
@Override
public
UserSysResult
<
XUser
>
saveUser
(
UserBean
userBean
)
{
UserSysResult
<
XUser
>
result
=
new
UserSysResult
<>();
if
(
null
==
userBean
)
{
result
.
setCode
(
"0001"
);
result
.
setBusinessCode
(
"0001"
);
result
.
setMsg
(
"要保存的用户对象不能为null"
);
result
.
setData
(
null
);
return
result
;
}
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
User
user
=
new
User
();
user
.
setCreatedAt
(
now
);
user
.
setUpdatedAt
(
now
);
user
.
setUuid
(
userBean
.
getUuid
());
user
.
setPhoneNo
(
userBean
.
getPhoneNo
());
user
.
setEnable
(
true
);
user
.
setPassword
(
userBean
.
getPassword
());
user
.
setRegisteredFrom
(
userBean
.
getRegisteredFrom
());
User
saveUser
=
userService
.
saveUser
(
user
);
XUser
xUser
=
convertObject
(
JSON
.
toJSONString
(
saveUser
),
new
TypeReference
<
XUser
>()
{});
return
returnValue
(
xUser
,
""
);
}
@Override
public
UserSysResult
<
XUserDetail
>
findUserDetailByUserId
(
Long
userId
)
{
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
userId
);
XUserDetail
xUserDetail
=
convertObject
(
JSON
.
toJSONString
(
userDetail
),
new
TypeReference
<
XUser
>()
{});
return
returnValue
(
xUserDetail
,
""
);
}
@Override
public
UserSysResult
<
XUser
>
findUserByUserId
(
Long
id
)
{
User
user
=
userService
.
findById
(
id
);
XUser
xUser
=
convertObject
(
JSON
.
toJSONString
(
user
),
new
TypeReference
<
XUser
>()
{});
return
returnValue
(
xUser
,
""
);
}
@Override
public
UserSysResult
<
XUserDetail
>
findUserDetailByPhone
(
String
phoneNo
)
{
UserDetail
userDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
XUserDetail
xUserDetail
=
convertObject
(
JSON
.
toJSONString
(
userDetail
),
new
TypeReference
<
XUserDetail
>()
{});
return
returnValue
(
xUserDetail
,
""
);
}
@Override
public
UserSysResult
<
XUserDetail
>
saveUserDetail
(
UserDetailUpdateBean
userDetailUpdateBean
)
{
UserSysResult
<
XUserDetail
>
result
=
new
UserSysResult
<>();
result
.
setCode
(
"0001"
);
result
.
setBusinessCode
(
"0001"
);
if
(
null
==
userDetailUpdateBean
)
{
result
.
setMsg
(
"要保存的用户详情对象不能为null"
);
result
.
setData
(
null
);
return
result
;
}
UserDetail
userDetail
=
new
UserDetail
();
if
(
null
!=
userDetailUpdateBean
.
getId
()
&&
userDetailUpdateBean
.
getId
()
>
0L
)
{
userDetail
.
setId
(
userDetailUpdateBean
.
getId
());
}
userDetail
.
setUserId
(
userDetailUpdateBean
.
getUserId
());
userDetail
.
setName
(
userDetailUpdateBean
.
getName
());
userDetail
.
setPhoneNo
(
userDetailUpdateBean
.
getPhoneNo
());
userDetail
.
setIdNo
(
userDetailUpdateBean
.
getIdNo
());
Timestamp
time
=
new
Timestamp
(
System
.
currentTimeMillis
());
userDetail
.
setCreatedAt
(
time
);
userDetail
.
setUpdatedAt
(
time
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
try
{
userDetail
.
setGender
(
idCardService
.
getIdCardInfo
(
userDetailUpdateBean
.
getIdNo
()).
getGender
());
}
catch
(
ParseException
e
)
{
LOGGER
.
error
(
"根据身份证获取性别出错,错误信息:"
+
e
);
result
.
setMsg
(
"根据身份证获取性别出错."
);
return
result
;
}
userDetail
.
setEmail
(
userDetailUpdateBean
.
getEmail
());
userDetail
=
userDetailService
.
saveUserDetail
(
userDetail
);
if
(
userDetail
!=
null
){
XUserDetail
xUserDetail
=
convertObject
(
JSON
.
toJSONString
(
userDetail
),
new
TypeReference
<
XUserDetail
>()
{});
return
returnValue
(
xUserDetail
,
""
);
}
result
.
setMsg
(
""
);
return
result
;
}
private
<
T
>
T
convertObject
(
String
json
,
TypeReference
typeReference
)
{
try
{
if
(
StringUtils
.
isEmpty
(
json
))
{
return
null
;
}
return
MAPPER
.
readValue
(
json
,
typeReference
);
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"用户信息转换出错,错误信息{}"
,
ex
);
return
null
;
}
}
/**
* 封装返回结果.
* @param t
* @param message
* @param <T>
* @return
*/
private
<
T
>
UserSysResult
<
T
>
returnValue
(
T
t
,
String
message
)
{
UserSysResult
<
T
>
userSysResult
=
new
UserSysResult
();
userSysResult
.
setMsg
(
message
);
/**
* 无返回结果时,返回的code和BusinessCode均是0001
*/
if
(
null
==
t
)
{
userSysResult
.
setData
(
null
);
userSysResult
.
setBusinessCode
(
"0001"
);
userSysResult
.
setCode
(
"0001"
);
}
else
{
userSysResult
.
setData
(
t
);
userSysResult
.
setBusinessCode
(
"0000"
);
userSysResult
.
setCode
(
"0000"
);
}
return
userSysResult
;
}
}
src/main/resources/config/dev/application.properties
View file @
e5e0feb4
server.port
=
808
0
server.port
=
808
8
security.sessions
=
if_required
...
...
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