Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
data-acquisition
Project
Project
Details
Activity
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
竹天卫
data-acquisition
Commits
0e5f860c
Commit
0e5f860c
authored
Apr 20, 2021
by
竹天卫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录接口
parent
c1b30fbc
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
150 additions
and
178 deletions
+150
-178
AcquisitionApplication.java
...va/cn/wise/sc/cement/business/AcquisitionApplication.java
+1
-0
LoginController.java
...n/wise/sc/cement/business/controller/LoginController.java
+49
-0
SysUserController.java
...wise/sc/cement/business/controller/SysUserController.java
+1
-1
WeiXinController.java
.../wise/sc/cement/business/controller/WeiXinController.java
+0
-124
SysUser.java
.../main/java/cn/wise/sc/cement/business/entity/SysUser.java
+6
-3
UserQuery.java
...ava/cn/wise/sc/cement/business/model/query/UserQuery.java
+3
-3
LoginService.java
...cn/wise/sc/cement/business/service/impl/LoginService.java
+25
-46
UserServiceImpl.java
...wise/sc/cement/business/service/impl/UserServiceImpl.java
+3
-1
MD5Util.java
...rc/main/java/cn/wise/sc/cement/business/util/MD5Util.java
+61
-0
application-dev.yml
acquisition-business/src/main/resources/application-dev.yml
+1
-0
No files found.
acquisition-business/src/main/java/cn/wise/sc/cement/business/AcquisitionApplication.java
View file @
0e5f860c
...
@@ -30,4 +30,5 @@ public class AcquisitionApplication {
...
@@ -30,4 +30,5 @@ public class AcquisitionApplication {
return
new
RestTemplate
();
return
new
RestTemplate
();
}
}
}
}
acquisition-business/src/main/java/cn/wise/sc/cement/business/controller/LoginController.java
0 → 100644
View file @
0e5f860c
package
cn
.
wise
.
sc
.
cement
.
business
.
controller
;
import
cn.wise.sc.cement.business.model.BaseResponse
;
import
cn.wise.sc.cement.business.service.impl.LoginService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@Api
(
tags
=
"登录接口"
)
@RestController
@RequestMapping
(
"/login"
)
public
class
LoginController
{
//
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
"LoginController"
);
@Autowired
private
LoginService
loginService
;
@ApiOperation
(
value
=
"登录"
)
@GetMapping
(
"/getToken"
)
public
BaseResponse
getToken
(
String
userName
,
String
password
)
{
try
{
//测试服务器
return
loginService
.
login
(
userName
,
password
);
}
catch
(
Exception
e
)
{
log
.
debug
(
"获取登录token{}"
,
e
);
}
return
BaseResponse
.
errorMsg
(
"失败!"
);
}
@ApiOperation
(
value
=
"当前登录用户"
)
@GetMapping
(
"/getLoginUser"
)
public
BaseResponse
getLoginUser
()
{
try
{
return
loginService
.
getLoginUser
();
}
catch
(
Exception
e
)
{
log
.
debug
(
"当前登录用户{}"
,
e
);
}
return
BaseResponse
.
errorMsg
(
"失败!"
);
}
}
acquisition-business/src/main/java/cn/wise/sc/cement/business/controller/SysUserController.java
View file @
0e5f860c
...
@@ -53,7 +53,7 @@ public class SysUserController {
...
@@ -53,7 +53,7 @@ public class SysUserController {
return
BaseResponse
.
errorMsg
(
"失败!"
);
return
BaseResponse
.
errorMsg
(
"失败!"
);
}
}
@ApiOperation
(
value
=
"新增人员"
)
@ApiOperation
(
value
=
"新增人员"
,
notes
=
"默认密码与用户名相同"
)
@PostMapping
(
"/create"
)
@PostMapping
(
"/create"
)
public
BaseResponse
create
(
@RequestBody
UserQuery
query
)
{
public
BaseResponse
create
(
@RequestBody
UserQuery
query
)
{
try
{
try
{
...
...
acquisition-business/src/main/java/cn/wise/sc/cement/business/controller/WeiXinController.java
deleted
100644 → 0
View file @
c1b30fbc
package
cn
.
wise
.
sc
.
cement
.
business
.
controller
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.URLUtil
;
import
cn.wise.sc.cement.business.model.BaseResponse
;
import
cn.wise.sc.cement.business.service.impl.WeiXinService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Api
(
tags
=
"登录接口"
)
@RestController
@RequestMapping
(
"/tcdri/weixin"
)
public
class
WeiXinController
{
//
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
"WeiXinController"
);
@Autowired
private
WeiXinService
weiXinService
;
@Value
(
"${spring.profiles.active}"
)
private
String
active
;
@ApiOperation
(
value
=
"获取登录token-小程序端"
)
@GetMapping
(
"/getToken"
)
public
BaseResponse
getToken
(
String
code
)
{
log
.
debug
(
"============================================"
);
log
.
debug
(
"code: {}"
,
code
);
log
.
debug
(
"============================================="
);
try
{
if
(
active
.
equals
(
"dev"
)){
//测试服务器
return
weiXinService
.
getTestToken
(
code
);
}
else
{
//正式服务器
// return weiXinService.getToken(code, "APP");
}
}
catch
(
Exception
e
)
{
log
.
debug
(
"获取登录token{}"
,
e
);
}
return
BaseResponse
.
errorMsg
(
"失败!"
);
}
@ApiOperation
(
value
=
"获取登录token-管理端"
)
@GetMapping
(
"/getPCToken"
)
public
BaseResponse
getPCToken
(
String
code
)
{
try
{
if
(
active
.
equals
(
"dev"
)){
//测试服务器
return
weiXinService
.
getTestToken
(
code
);
}
else
{
//正式服务器
// return weiXinService.getToken(code, "PC");
}
}
catch
(
Exception
e
)
{
log
.
debug
(
"获取登录token{}"
,
e
);
}
return
BaseResponse
.
errorMsg
(
"失败!"
);
}
@ApiOperation
(
value
=
"当前登录用户"
)
@GetMapping
(
"/getLoginUser"
)
public
BaseResponse
getLoginUser
()
{
try
{
return
weiXinService
.
getLoginUser
();
}
catch
(
Exception
e
)
{
log
.
debug
(
"当前登录用户{}"
,
e
);
}
return
BaseResponse
.
errorMsg
(
"失败!"
);
}
/**
* 将字节数组转换为十六进制字符串
*
* @param byteArray
* @return
*/
private
static
String
byteToStr
(
byte
[]
byteArray
)
{
String
strDigest
=
""
;
for
(
int
i
=
0
;
i
<
byteArray
.
length
;
i
++)
{
strDigest
+=
byteToHexStr
(
byteArray
[
i
]);
}
return
strDigest
;
}
/**
* 将字节转换为十六进制字符串
*
* @param mByte
* @return
*/
private
static
String
byteToHexStr
(
byte
mByte
)
{
char
[]
Digit
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
char
[]
tempArr
=
new
char
[
2
];
tempArr
[
0
]
=
Digit
[(
mByte
>>>
4
)
&
0X0F
];
tempArr
[
1
]
=
Digit
[
mByte
&
0X0F
];
String
s
=
new
String
(
tempArr
);
return
s
;
}
}
acquisition-business/src/main/java/cn/wise/sc/cement/business/entity/SysUser.java
View file @
0e5f860c
...
@@ -29,12 +29,15 @@ public class SysUser implements Serializable {
...
@@ -29,12 +29,15 @@ public class SysUser implements Serializable {
@TableId
(
value
=
"id"
,
type
=
IdType
.
AUTO
)
@TableId
(
value
=
"id"
,
type
=
IdType
.
AUTO
)
private
Integer
id
;
private
Integer
id
;
@ApiModelProperty
(
"用户账号"
)
private
String
username
;
@ApiModelProperty
(
"真实姓名"
)
@ApiModelProperty
(
"真实姓名"
)
private
String
name
;
private
String
name
;
@ApiModelProperty
(
"用户账号"
)
private
String
userName
;
@ApiModelProperty
(
"密码"
)
private
String
passWord
;
@ApiModelProperty
(
"性别0女1男"
)
@ApiModelProperty
(
"性别0女1男"
)
private
Integer
sex
;
private
Integer
sex
;
...
...
acquisition-business/src/main/java/cn/wise/sc/cement/business/model/query/UserQuery.java
View file @
0e5f860c
...
@@ -20,12 +20,12 @@ public class UserQuery {
...
@@ -20,12 +20,12 @@ public class UserQuery {
private
Integer
id
;
private
Integer
id
;
@ApiModelProperty
(
"用户账号"
)
private
String
username
;
@ApiModelProperty
(
"真实姓名"
)
@ApiModelProperty
(
"真实姓名"
)
private
String
name
;
private
String
name
;
@ApiModelProperty
(
"用户账号"
)
private
String
userName
;
@ApiModelProperty
(
"性别0女1男"
)
@ApiModelProperty
(
"性别0女1男"
)
private
Integer
sex
;
private
Integer
sex
;
...
...
acquisition-business/src/main/java/cn/wise/sc/cement/business/service/impl/
WeiX
inService.java
→
acquisition-business/src/main/java/cn/wise/sc/cement/business/service/impl/
Log
inService.java
View file @
0e5f860c
package
cn
.
wise
.
sc
.
cement
.
business
.
service
.
impl
;
package
cn
.
wise
.
sc
.
cement
.
business
.
service
.
impl
;
import
cn.hutool.core.util.NumberUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.URLUtil
;
import
cn.wise.sc.cement.business.entity.SysUser
;
import
cn.wise.sc.cement.business.entity.SysUser
;
import
cn.wise.sc.cement.business.model.BaseResponse
;
import
cn.wise.sc.cement.business.model.BaseResponse
;
import
cn.wise.sc.cement.business.model.LoginUser
;
import
cn.wise.sc.cement.business.model.LoginUser
;
import
cn.wise.sc.cement.business.model.query.UserQuery
;
import
cn.wise.sc.cement.business.service.ISysUserService
;
import
cn.wise.sc.cement.business.service.ISysUserService
;
import
cn.wise.sc.cement.business.util.JwtUtil
;
import
cn.wise.sc.cement.business.util.JwtUtil
;
import
cn.wise.sc.cement.business.util.MD5Util
;
import
cn.wise.sc.cement.business.util.RedisUtil
;
import
cn.wise.sc.cement.business.util.RedisUtil
;
import
cn.wise.sc.cement.business.util.weixin.Global
;
import
cn.wise.sc.cement.business.util.weixin.WeiXinUtil
;
import
cn.wise.sc.cement.business.util.weixin.WeixinInterfaceUtil
;
import
cn.wise.sc.cement.business.util.weixin.message.send.BaseMessage
;
import
cn.wise.sc.cement.business.util.weixin.message.send.Text
;
import
cn.wise.sc.cement.business.util.weixin.message.send.TextMessage
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.google.common.base.Strings
;
import
com.google.gson.Gson
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
java.math.BigDecimal
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Service
@Service
public
class
WeiX
inService
{
public
class
Log
inService
{
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
WeiXinService
.
class
);
@Autowired
@Autowired
private
ISysUserService
userService
;
private
ISysUserService
userService
;
@Autowired
@Autowired
RedisUtil
redisUtil
;
RedisUtil
redisUtil
;
/**
/**
*
获取登录token 测试服务器部署
*
登录
*
*
@param userName
* @param
code
* @param
password
* @return
* @return
*/
*/
public
BaseResponse
<
String
>
getTestToken
(
String
code
)
{
public
BaseResponse
<
String
>
login
(
String
userName
,
String
password
)
{
if
(
StrUtil
.
isEmpty
(
cod
e
))
{
if
(
StrUtil
.
isEmpty
(
userNam
e
))
{
return
BaseResponse
.
errorMsg
(
"
code
为必填项!"
);
return
BaseResponse
.
errorMsg
(
"
用户名
为必填项!"
);
}
}
System
.
out
.
println
(
"==================code==================="
);
if
(
StrUtil
.
isEmpty
(
password
))
{
System
.
out
.
println
(
code
);
return
BaseResponse
.
errorMsg
(
"密码为必填项!"
);
}
System
.
out
.
println
(
"=========userName==========password========="
);
System
.
out
.
println
(
userName
+
"\n"
+
password
);
try
{
try
{
QueryWrapper
<
SysUser
>
wrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
SysUser
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"
phone"
,
code
);
//暂时用手机号代替code
wrapper
.
eq
(
"
user_name"
,
userName
);
SysUser
sysUser
=
userService
.
getOne
(
wrapper
);
SysUser
sysUser
=
userService
.
getOne
(
wrapper
);
if
(
sysUser
==
null
)
{
if
(
sysUser
==
null
)
{
return
BaseResponse
.
errorMsg
(
"非系统用户不允许登录!"
);
return
BaseResponse
.
errorMsg
(
"非系统用户不允许登录!"
);
...
@@ -70,9 +50,13 @@ public class WeiXinService {
...
@@ -70,9 +50,13 @@ public class WeiXinService {
if
(
sysUser
.
getIsDelete
()
==
0
)
{
if
(
sysUser
.
getIsDelete
()
==
0
)
{
return
BaseResponse
.
errorMsg
(
"用户被删除!"
);
return
BaseResponse
.
errorMsg
(
"用户被删除!"
);
}
}
String
loginPassWd
=
MD5Util
.
MD5Encode
(
password
,
"UTF-8"
);
if
(!
sysUser
.
getPassWord
().
equals
(
loginPassWd
))
{
return
BaseResponse
.
errorMsg
(
"密码错误"
);
}
//生成token,存入redis
//生成token,存入redis
String
token
=
JwtUtil
.
createToken
(
sysUser
.
getId
(),
sysUser
.
getUser
n
ame
(),
String
token
=
JwtUtil
.
createToken
(
sysUser
.
getId
(),
sysUser
.
getUser
N
ame
(),
sysUser
.
getName
(),
sysUser
.
getPhone
());
sysUser
.
getName
(),
sysUser
.
getPhone
());
System
.
out
.
println
(
token
);
System
.
out
.
println
(
token
);
redisUtil
.
setString
(
sysUser
.
getId
().
toString
(),
token
,
3600
);
redisUtil
.
setString
(
sysUser
.
getId
().
toString
(),
token
,
3600
);
...
@@ -83,11 +67,15 @@ public class WeiXinService {
...
@@ -83,11 +67,15 @@ public class WeiXinService {
}
}
public
static
void
main
(
String
args
[]){
String
loginPassWd
=
MD5Util
.
MD5Encode
(
"123456"
,
"UTF-8"
);
System
.
out
.
println
(
loginPassWd
);
}
/**
/**
* 当前登录用户
* 当前登录用户
*
* @return
* @return
*/
*/
public
BaseResponse
<
LoginUser
>
getLoginUser
()
{
public
BaseResponse
<
LoginUser
>
getLoginUser
()
{
...
@@ -99,13 +87,4 @@ public class WeiXinService {
...
@@ -99,13 +87,4 @@ public class WeiXinService {
}
}
acquisition-business/src/main/java/cn/wise/sc/cement/business/service/impl/UserServiceImpl.java
View file @
0e5f860c
...
@@ -14,6 +14,7 @@ import cn.wise.sc.cement.business.model.query.UserQuery;
...
@@ -14,6 +14,7 @@ import cn.wise.sc.cement.business.model.query.UserQuery;
import
cn.wise.sc.cement.business.model.vo.UserVo
;
import
cn.wise.sc.cement.business.model.vo.UserVo
;
import
cn.wise.sc.cement.business.service.ISysUserService
;
import
cn.wise.sc.cement.business.service.ISysUserService
;
import
cn.wise.sc.cement.business.util.JwtUtil
;
import
cn.wise.sc.cement.business.util.JwtUtil
;
import
cn.wise.sc.cement.business.util.MD5Util
;
import
cn.wise.sc.cement.business.util.RedisUtil
;
import
cn.wise.sc.cement.business.util.RedisUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
...
@@ -128,7 +129,8 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
...
@@ -128,7 +129,8 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
}
}
SysUser
user
=
new
SysUser
();
SysUser
user
=
new
SysUser
();
BeanUtils
.
copyProperties
(
query
,
user
);
BeanUtils
.
copyProperties
(
query
,
user
);
user
.
setStatus
(
1
).
setIsDelete
(
1
).
setCreateTime
(
LocalDateTime
.
now
());
user
.
setPassWord
(
MD5Util
.
MD5Encode
(
query
.
getUserName
(),
"UTF-8"
))
.
setStatus
(
1
).
setIsDelete
(
1
).
setCreateTime
(
LocalDateTime
.
now
());
userMapper
.
insert
(
user
);
userMapper
.
insert
(
user
);
saveUserRoles
(
user
.
getId
(),
query
.
getRoleId
());
saveUserRoles
(
user
.
getId
(),
query
.
getRoleId
());
...
...
acquisition-business/src/main/java/cn/wise/sc/cement/business/util/MD5Util.java
0 → 100644
View file @
0e5f860c
package
cn
.
wise
.
sc
.
cement
.
business
.
util
;
import
java.security.MessageDigest
;
public
class
MD5Util
{
private
static
String
byteArrayToHexString
(
byte
b
[])
{
StringBuffer
resultSb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
b
.
length
;
i
++){
resultSb
.
append
(
byteToHexString
(
b
[
i
]));
}
return
resultSb
.
toString
();
}
private
static
String
byteToHexString
(
byte
b
)
{
int
n
=
b
;
if
(
n
<
0
){
n
+=
256
;
}
int
d1
=
n
/
16
;
int
d2
=
n
%
16
;
return
hexDigits
[
d1
]
+
hexDigits
[
d2
];
}
/**
* 返回大小写MD5
*
* @param origin
* @param charsetname
* @return
*/
public
static
String
MD5Encode
(
String
origin
,
String
charsetname
)
{
String
resultString
=
null
;
try
{
resultString
=
new
String
(
origin
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
if
(
charsetname
==
null
||
""
.
equals
(
charsetname
)){
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
()));
}
else
{
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
(
charsetname
)));
}
}
catch
(
Exception
exception
)
{
}
// return resultString.toUpperCase();
return
resultString
.
toLowerCase
();
}
private
static
final
String
hexDigits
[]
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
};
public
static
void
main
(
String
[]
args
){
String
str
=
MD5Encode
(
"lourongqing"
,
"utf-8"
);
System
.
out
.
println
(
str
);
}
}
acquisition-business/src/main/resources/application-dev.yml
View file @
0e5f860c
...
@@ -20,6 +20,7 @@ spring:
...
@@ -20,6 +20,7 @@ spring:
redis
:
redis
:
port
:
6379
port
:
6379
host
:
192.168.110.85
host
:
192.168.110.85
database
:
2
# password: Wise_@123456
# password: Wise_@123456
servlet
:
servlet
:
multipart
:
multipart
:
...
...
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