Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
rx
Commits
ed36899f
Commit
ed36899f
authored
Aug 22, 2024
by
wujipeng
Browse files
根据设备id查询设备信息
parent
f816078b
Changes
8
Show whitespace changes
Inline
Side-by-side
src/main/java/com/ruzhoukj/rx/controller/EquipmentController.java
View file @
ed36899f
...
@@ -22,9 +22,16 @@ public class EquipmentController {
...
@@ -22,9 +22,16 @@ public class EquipmentController {
private
EquipmentService
equipmentService
;
private
EquipmentService
equipmentService
;
@ApiOperation
(
value
=
"根据设备id查询最新的一条设备上报信息"
)
@ApiOperation
(
value
=
"根据设备id查询最新的一条设备上报信息"
)
@GetMapping
(
"/{deviceId}"
)
@GetMapping
(
"/
report/
{deviceId}"
)
public
Result
getDeviceDataByDeviceId
(
@PathVariable
String
deviceId
)
{
public
Result
getDeviceDataByDeviceId
(
@PathVariable
String
deviceId
)
{
return
Result
.
success
(
equipmentService
.
getDeviceDataByDeviceId
(
deviceId
));
return
Result
.
success
(
equipmentService
.
getDeviceDataByDeviceId
(
deviceId
));
}
}
@ApiOperation
(
value
=
"根据设备id查询设备信息"
)
@GetMapping
(
"/info/{deviceId}"
)
public
Result
getDeviceInfoByDeviceId
(
@PathVariable
String
deviceId
)
{
return
Result
.
success
(
equipmentService
.
getDeviceInfoByDeviceId
(
deviceId
));
}
}
}
src/main/java/com/ruzhoukj/rx/controller/UserController.java
View file @
ed36899f
...
@@ -25,45 +25,45 @@ import java.util.HashMap;
...
@@ -25,45 +25,45 @@ import java.util.HashMap;
@CrossOrigin
@CrossOrigin
@RestController
@RestController
public
class
UserController
{
public
class
UserController
{
//
@Resource
@Resource
//
private UserService userService;
private
UserService
userService
;
//
@Resource
@Resource
//
private JwtUtil jwtUtil;
private
JwtUtil
jwtUtil
;
private
static
final
String
PW_PATTERN
=
"^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$"
;
private
static
final
String
PW_PATTERN
=
"^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$"
;
@PostMapping
(
"/Login"
)
@PostMapping
(
"/Login"
)
@ApiOperation
(
value
=
"用户登录"
,
notes
=
"调用方法传递对象过来"
)
@ApiOperation
(
value
=
"用户登录"
,
notes
=
"调用方法传递对象过来"
)
public
R
login
(
@RequestBody
User
user
,
HttpServletRequest
req
)
{
public
R
login
(
@RequestBody
User
user
,
HttpServletRequest
req
)
{
//
UserEntity users = userService.login(user.getUserName(), user.getPassword());
UserEntity
users
=
userService
.
login
(
user
.
getUserName
(),
user
.
getPassword
());
//
if (users == null) {
if
(
users
==
null
)
{
//
Integer isValid = (Integer) req.getSession().getAttribute(user.getUserName());
Integer
isValid
=
(
Integer
)
req
.
getSession
().
getAttribute
(
user
.
getUserName
());
//
if (isValid == null) {
if
(
isValid
==
null
)
{
//
req.getSession().setAttribute(user.getUserName(), 1);
req
.
getSession
().
setAttribute
(
user
.
getUserName
(),
1
);
//
return R.error(405, "用户名或密码错误,还有4次机会!");
return
R
.
error
(
405
,
"用户名或密码错误,还有4次机会!"
);
//
} else {
}
else
{
//
if (isValid >= 5) {
if
(
isValid
>=
5
)
{
//
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
QueryWrapper
<
UserEntity
>
queryWrapper
=
new
QueryWrapper
<>();
//
queryWrapper.eq("accountid", user.getUserName());
queryWrapper
.
eq
(
"accountid"
,
user
.
getUserName
());
//
UserEntity account = userService.getOne(queryWrapper);
UserEntity
account
=
userService
.
getOne
(
queryWrapper
);
//
account.setValid(0);
account
.
setValid
(
0
);
//
userService.updateById(account);
userService
.
updateById
(
account
);
//
return R.error(405, "用户已锁定!");
return
R
.
error
(
405
,
"用户已锁定!"
);
//
} else {
}
else
{
//
req.getSession().setAttribute(user.getUserName(), isValid + 1);
req
.
getSession
().
setAttribute
(
user
.
getUserName
(),
isValid
+
1
);
//
return R.error(405, "用户名或密码错误,还有" + (4 - isValid) + "次机会!");
return
R
.
error
(
405
,
"用户名或密码错误,还有"
+
(
4
-
isValid
)
+
"次机会!"
);
//
}
}
//
}
}
//
//
}
}
//
if (users.getValid() == 0) {
if
(
users
.
getValid
()
==
0
)
{
//
return R.error(405, "用户已停用,请联系管理员!");
return
R
.
error
(
405
,
"用户已停用,请联系管理员!"
);
//
}
}
//
String token = jwtUtil.createJWT(users.getId(), users.getUserName(), users.getPassword());
String
token
=
jwtUtil
.
createJWT
(
users
.
getId
(),
users
.
getUserName
(),
users
.
getPassword
());
//
req.getSession().setAttribute(user.getUserName(), null);
req
.
getSession
().
setAttribute
(
user
.
getUserName
(),
null
);
//
req.getSession().setAttribute("captcha", null);
req
.
getSession
().
setAttribute
(
"captcha"
,
null
);
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
//
map.put("token", token);
map
.
put
(
"token"
,
token
);
map
.
put
(
"backUrl"
,
null
);
map
.
put
(
"backUrl"
,
null
);
return
R
.
ok
(
1
,
"登录成功!"
,
map
,
true
,
null
);
return
R
.
ok
(
1
,
"登录成功!"
,
map
,
true
,
null
);
}
}
...
...
src/main/java/com/ruzhoukj/rx/dao/EquipmentDao.java
View file @
ed36899f
...
@@ -2,7 +2,9 @@ package com.ruzhoukj.rx.dao;
...
@@ -2,7 +2,9 @@ package com.ruzhoukj.rx.dao;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.ruzhoukj.rx.pojo.entity.EquipmentEntity
;
import
com.ruzhoukj.rx.pojo.entity.EquipmentEntity
;
import
com.ruzhoukj.rx.pojo.vo.EquipmentVO
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
/**
/**
* @author wujipeng
* @author wujipeng
...
@@ -11,4 +13,11 @@ import org.apache.ibatis.annotations.Mapper;
...
@@ -11,4 +13,11 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
@Mapper
public
interface
EquipmentDao
extends
BaseMapper
<
EquipmentEntity
>
{
public
interface
EquipmentDao
extends
BaseMapper
<
EquipmentEntity
>
{
/**
* 根据设备id查询设备信息
*
* @param deviceId 设备id
* @return EquipmentVO
*/
EquipmentVO
getDeviceInfoByDeviceId
(
@Param
(
"deviceId"
)
String
deviceId
);
}
}
src/main/java/com/ruzhoukj/rx/service/EquipmentService.java
View file @
ed36899f
...
@@ -3,6 +3,7 @@ package com.ruzhoukj.rx.service;
...
@@ -3,6 +3,7 @@ package com.ruzhoukj.rx.service;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.ruzhoukj.rx.pojo.entity.EquipmentEntity
;
import
com.ruzhoukj.rx.pojo.entity.EquipmentEntity
;
import
com.ruzhoukj.rx.pojo.vo.DeviceVO
;
import
com.ruzhoukj.rx.pojo.vo.DeviceVO
;
import
com.ruzhoukj.rx.pojo.vo.EquipmentVO
;
/**
/**
* @author wujipeng
* @author wujipeng
...
@@ -15,4 +16,10 @@ public interface EquipmentService extends IService<EquipmentEntity> {
...
@@ -15,4 +16,10 @@ public interface EquipmentService extends IService<EquipmentEntity> {
* @return DeviceVO
* @return DeviceVO
*/
*/
DeviceVO
getDeviceDataByDeviceId
(
String
deviceId
);
DeviceVO
getDeviceDataByDeviceId
(
String
deviceId
);
/**
* @param deviceId 设备id
* @return EquipmentVO
*/
EquipmentVO
getDeviceInfoByDeviceId
(
String
deviceId
);
}
}
src/main/java/com/ruzhoukj/rx/service/impl/EquipmentServiceImpl.java
View file @
ed36899f
...
@@ -5,6 +5,7 @@ import com.ruzhoukj.rx.dao.DeviceDao;
...
@@ -5,6 +5,7 @@ import com.ruzhoukj.rx.dao.DeviceDao;
import
com.ruzhoukj.rx.dao.EquipmentDao
;
import
com.ruzhoukj.rx.dao.EquipmentDao
;
import
com.ruzhoukj.rx.pojo.entity.EquipmentEntity
;
import
com.ruzhoukj.rx.pojo.entity.EquipmentEntity
;
import
com.ruzhoukj.rx.pojo.vo.DeviceVO
;
import
com.ruzhoukj.rx.pojo.vo.DeviceVO
;
import
com.ruzhoukj.rx.pojo.vo.EquipmentVO
;
import
com.ruzhoukj.rx.service.EquipmentService
;
import
com.ruzhoukj.rx.service.EquipmentService
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -25,4 +26,9 @@ public class EquipmentServiceImpl
...
@@ -25,4 +26,9 @@ public class EquipmentServiceImpl
public
DeviceVO
getDeviceDataByDeviceId
(
String
deviceId
)
{
public
DeviceVO
getDeviceDataByDeviceId
(
String
deviceId
)
{
return
deviceDao
.
findTopByDeviceIdOrderByTimestampDesc
(
deviceId
);
return
deviceDao
.
findTopByDeviceIdOrderByTimestampDesc
(
deviceId
);
}
}
@Override
public
EquipmentVO
getDeviceInfoByDeviceId
(
String
deviceId
)
{
return
baseMapper
.
getDeviceInfoByDeviceId
(
deviceId
);
}
}
}
src/main/java/com/ruzhoukj/rx/util/JwtUtil.java
View file @
ed36899f
package
com.ruzhoukj.rx.util
;
package
com.ruzhoukj.rx.util
;
//import io.jsonwebtoken.Claims;
//import io.jsonwebtoken.JwtBuilder;
//import io.jsonwebtoken.Jwts;
//import io.jsonwebtoken.SignatureAlgorithm;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.stereotype.Component;
import
cn.hutool.jwt.Claims
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.JwtBuilder
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
import
java.util.Date
;
/**
/**
* @author qianmo
* @author qianmo
*/
*/
//
@Component
@Component
//
@ConfigurationProperties("jwt.config")
@ConfigurationProperties
(
"jwt.config"
)
public
class
JwtUtil
{
public
class
JwtUtil
{
//
// private String key ;
private
String
key
;
//
// private long ttl ;//一个小时
private
long
ttl
;
//
// public String getKey() {
public
String
getKey
()
{
// return key;
return
key
;
// }
}
//
// public void setKey(String key) {
public
void
setKey
(
String
key
)
{
// this.key = key;
this
.
key
=
key
;
// }
}
//
// public long getTtl() {
public
long
getTtl
()
{
// return ttl;
return
ttl
;
// }
}
//
// public void setTtl(long ttl) {
public
void
setTtl
(
long
ttl
)
{
// this.ttl = ttl;
this
.
ttl
=
ttl
;
// }
}
//
// /**
/**
// * 生成JWT
* 生成JWT
// *
*
// * @param id
* @param id
// * @param subject
* @param subject
// * @return
* @return
// */
*/
// public String createJWT(String id, String subject, String password) {
public
String
createJWT
(
String
id
,
String
subject
,
String
password
)
{
// long nowMillis = System.currentTimeMillis();
long
nowMillis
=
System
.
currentTimeMillis
();
// Date now = new Date(nowMillis);
Date
now
=
new
Date
(
nowMillis
);
// JwtBuilder builder = Jwts.builder().setId(id)
JwtBuilder
builder
=
Jwts
.
builder
().
setId
(
id
)
// .setSubject(subject)
.
setSubject
(
subject
)
// .setIssuedAt(now)
.
setIssuedAt
(
now
)
// .signWith(SignatureAlgorithm.HS256, key).claim("password", password);
.
signWith
(
SignatureAlgorithm
.
HS256
,
key
).
claim
(
"password"
,
password
);
// if (ttl > 0) {
if
(
ttl
>
0
)
{
// builder.setExpiration( new Date( nowMillis + ttl));
builder
.
setExpiration
(
new
Date
(
nowMillis
+
ttl
));
// }
}
// return builder.compact();
return
builder
.
compact
();
// }
}
//
// /**
/**
// * 解析JWT
* 解析JWT
// * @param jwtStr
*
// * @return
* @param jwtStr
// */
* @return
// public Claims parseJWT(String jwtStr){
*/
// return Jwts.parser()
public
Claims
parseJWT
(
String
jwtStr
)
{
// .setSigningKey(key)
return
Jwts
.
parser
()
// .parseClaimsJws(jwtStr)
.
setSigningKey
(
key
)
// .getBody();
.
parseClaimsJws
(
jwtStr
)
// }
.
getBody
();
}
}
}
src/main/resources/mapper/com/ruzhoukj/rx/dao/DeviceDao.xml
View file @
ed36899f
...
@@ -2,12 +2,7 @@
...
@@ -2,12 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace=
"com.ruzhoukj.rx.dao.DeviceDao"
>
<mapper
namespace=
"com.ruzhoukj.rx.dao.DeviceDao"
>
<select
id=
"findTopByDeviceIdOrderByTimestampDesc"
resultType=
"com.ruzhoukj.rx.pojo.vo.DeviceVO"
>
<select
id=
"findTopByDeviceIdOrderByTimestampDesc"
resultType=
"com.ruzhoukj.rx.pojo.vo.DeviceVO"
>
SELECT deviceId
FROM gsd
WHERE deviceId = #{deviceId}
ORDER BY timestamp DESC
LIMIT 1
</select>
</select>
</mapper>
</mapper>
src/main/resources/mapper/com/ruzhoukj/rx/dao/EquipmentDao.xml
View file @
ed36899f
...
@@ -3,4 +3,21 @@
...
@@ -3,4 +3,21 @@
<mapper
namespace=
"com.ruzhoukj.rx.dao.EquipmentDao"
>
<mapper
namespace=
"com.ruzhoukj.rx.dao.EquipmentDao"
>
<select
id=
"getDeviceInfoByDeviceId"
resultType=
"com.ruzhoukj.rx.pojo.vo.EquipmentVO"
>
select
id,
sewage_plant_name as sewagePlantName,
sewage_plant_id as sewagePlantId,
device_name as deviceName,
device_id as deviceId,
serial_number as serialNumber,
longitude,
latitude,
type,
threshold_value as thresholdValue
from
equipment
where
device_id = #{deviceId};
</select>
</mapper>
</mapper>
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