固定token

This commit is contained in:
cwchen 2024-07-29 14:56:07 +08:00
parent 36a05ed605
commit 8b063afacb
10 changed files with 250 additions and 5 deletions

View File

@ -285,6 +285,12 @@
<artifactId>bcprov-jdk15on</artifactId>
<version>1.69</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.18.Final</version>
</dependency>
</dependencies>
<build>

View File

@ -1,6 +1,7 @@
package com.bonus.aqd.base.controller;
import com.bonus.aqd.base.entity.dto.ParamsDto;
import com.bonus.aqd.base.service.IndexService;
import com.bonus.aqd.manager.annotation.DecryptAndVerify;
import com.bonus.aqd.manager.core.entity.EncryptedReq;
import com.bonus.aqd.manager.webResult.ServerResponse;
@ -9,6 +10,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @className:IndexController
@ -22,9 +25,19 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
public class IndexController {
@PostMapping("getBuildingEnvByStorey")
@Resource(name = "IndexService")
private IndexService service;
/**
* 安全带设备列表
* @param dto
* @return ServerResponse
* @author cwchen
* @date 2024/7/29 14:32
*/
@PostMapping("getDevicesInfo")
@DecryptAndVerify(decryptedClass = ParamsDto.class)
public ServerResponse getBuildingEnvByStorey(EncryptedReq<ParamsDto> dto) {
return null;
public ServerResponse getDevicesInfo(EncryptedReq<ParamsDto> dto) {
return service.getDevicesInfo(dto.getData());
}
}

View File

@ -1,7 +1,11 @@
package com.bonus.aqd.base.dao;
import com.bonus.aqd.base.entity.dto.ParamsDto;
import com.bonus.aqd.base.entity.vo.DeviceInfoVo;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @className:IndexMapper
* @author:cwchen
@ -11,4 +15,12 @@ import org.springframework.stereotype.Repository;
*/
@Repository(value = "IndexMapper")
public interface IndexMapper {
/**
* 安全带设备列表
* @param dto
* @return List<DeviceInfoVo>
* @author cwchen
* @date 2024/7/29 14:37
*/
List<DeviceInfoVo> getDevicesInfo(ParamsDto dto);
}

View File

@ -1,7 +1,11 @@
package com.bonus.aqd.base.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Date;
/**
* @className:DeviceInfoVo
* @author:cwchen
@ -11,4 +15,53 @@ import lombok.Data;
*/
@Data
public class DeviceInfoVo {
/**
* id
*/
private Long id;
/**
* 设备名称
*/
private String devName;
/**
* 设备编码
*/
private String devCode;
/**
* 设备型号
*/
private String devModu;
/**
* A钩状态 0脱落 1正常
*/
private Integer devA;
/**
* B钩状态 0脱落 1正常
*/
private Integer devB;
/**
* 球机设备编码
*/
private String puid;
/**
* B钩脱落时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date devBTime;
/**
* A钩脱落时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date devATime;
/**
* 设备状态 1 在线 0离线
*/
private Long devStatus;
/**
* 数据检测时间
*/
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date devTime;
}

View File

@ -1,5 +1,8 @@
package com.bonus.aqd.base.service;
import com.bonus.aqd.base.entity.dto.ParamsDto;
import com.bonus.aqd.manager.webResult.ServerResponse;
/**
* @className:IndexService
* @author:cwchen
@ -8,4 +11,12 @@ package com.bonus.aqd.base.service;
* @description:首页-service
*/
public interface IndexService {
/**
* 安全带设备列表
* @param data
* @return ServerResponse
* @author cwchen
* @date 2024/7/29 14:34
*/
ServerResponse getDevicesInfo(ParamsDto data);
}

View File

@ -1,11 +1,17 @@
package com.bonus.aqd.base.service.impl;
import com.bonus.aqd.base.dao.IndexMapper;
import com.bonus.aqd.base.entity.dto.ParamsDto;
import com.bonus.aqd.base.entity.vo.DeviceInfoVo;
import com.bonus.aqd.base.service.IndexService;
import com.bonus.aqd.manager.advice.ValidatorsUtils;
import com.bonus.aqd.manager.webResult.ServerResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* @className:IndexServiceImpl
@ -20,4 +26,18 @@ public class IndexServiceImpl implements IndexService {
@Resource(name = "IndexMapper")
private IndexMapper mapper;
@Resource(name = "ValidatorsUtils")
private ValidatorsUtils validatorsUtils;
@Override
public ServerResponse getDevicesInfo(ParamsDto dto) {
List<DeviceInfoVo> list = new ArrayList<>();
try {
list = mapper.getDevicesInfo(dto);
} catch (Exception e) {
log.error(e.toString(),e);
}
return ServerResponse.createSuccess(list);
}
}

View File

@ -0,0 +1,100 @@
package com.bonus.aqd.manager.advice;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.List;
import java.util.Set;
/**
* @description: <br/>
* 通用Server validation方法
* <p>
* <br/>
* @author: Qz1997
* @create 2021/2/9 14:41
*/
@SuppressWarnings("unused")
@Component(value = "ValidatorsUtils")
public final class ValidatorsUtils {
@Resource
private Validator validator;
/**
* 验证实体
*
* @param obj 实体
* @param <T> 实体类类型
* @return 结果
*/
public <T> String valid(T obj) {
return this.valid(obj, new Class<?>[]{});
}
/**
* 验证实体
*
* @param obj 实体
* @param group 实体组
* @param <T> 实体类类型
* @return 结果
*/
public <T> String valid(T obj, Class<?>... group) {
Set<ConstraintViolation<T>> violations;
if (ArrayUtils.isEmpty(group)) {
violations = validator.validate(obj);
} else {
violations = validator.validate(obj, group);
}
if (CollectionUtils.isNotEmpty(violations)) {
for (ConstraintViolation<T> constraintViolation : violations) {
return constraintViolation.getMessage();
}
}
return null;
}
/**
* 校验list
*
* @param objList list
* @param <T> 实体类类型
* @return 结果
*/
public <T> String validList(List<T> objList) {
return this.validList(objList, new Class<?>[]{});
}
/**
* 校验list
*
* @param objList list
* @param group
* @param <T> 实体类类型
* @return 结果
*/
public <T> String validList(List<T> objList, Class<?>... group) {
if (CollectionUtils.isEmpty(objList)) {
return "对象空";
}
String result;
for (T t : objList) {
if (ArrayUtils.isEmpty(group)) {
result = this.valid(t);
} else {
result = this.valid(t, group);
}
if (!StringUtils.isBlank(result)) {
return result;
}
}
return null;
}
}

View File

@ -59,6 +59,16 @@ public class JWTTokenService {
return rspMap;
}
public static void main(String[] args) {
String token = IdUtils.fastUUID();
Map<String, Object> claimsMap = new HashMap<String, Object>();
claimsMap.put(SecurityConstants.USER_KEY, token);
claimsMap.put(SecurityConstants.DETAILS_USER_ID, 1);
claimsMap.put(SecurityConstants.DETAILS_USERNAME, "!Admin");
String jwtToken = JwtUtils.createToken(claimsMap);
System.err.println(jwtToken);
}
/**
* 获取用户身份信息
*

View File

@ -46,13 +46,16 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
ResultUtil.responseJson(response,ResultUtil.resultCode(401,"请先登录"));
return;
}
SelfUserEntity loginUser = tokenService.getLoginUser(request);
// SelfUserEntity loginUser = tokenService.getLoginUser(request);
SelfUserEntity loginUser = new SelfUserEntity();
loginUser.setUserId(1L);
loginUser.setUsername("!Admin");
if(Objects.isNull(loginUser)){
ResultUtil.responseJson(response,ResultUtil.resultCode(401,"登录过期,请重新登录"));
return;
}else{
// 验证令牌有效期相差不足10分钟自动刷新缓存
tokenService.verifyToken(loginUser);
// tokenService.verifyToken(loginUser);
//存入SecurityContextHolder
//TODO 获取权限信息封装到Authentication中
UsernamePasswordAuthenticationToken authenticationToken =

View File

@ -3,4 +3,21 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.aqd.base.dao.IndexMapper">
<!--安全带设备列表-->
<select id="getDevicesInfo" resultType="com.bonus.aqd.base.entity.vo.DeviceInfoVo">
SELECT id,
dev_name AS devName,
dev_code AS devCode,
dev_modu AS devModu,
dev_a AS devA,
dev_b AS devB,
dev_a_time AS devATime,
dev_b_time AS devBTime,
dev_status AS devStatus,
puid,
dev_time AS devTime
FROM tb_device
WHERE del_flag = 0
ORDER BY dev_time DESC
</select>
</mapper>