Commit ab89bc98 by fz

1.代码整理

2.添加小程序根据userId获取分享钥匙列表
1 parent 60a56c73
package com.glsx.smart.controller; package com.glsx.smart.controller;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import com.glsx.smart.pojo.request.SmartCarKeyReceiveRequest; import com.glsx.smart.pojo.request.*;
import com.glsx.smart.pojo.request.SmartCarKeyShareLogRequest;
import com.glsx.smart.pojo.request.SmartShareKeyEditReq;
import com.glsx.smart.service.AiLockingKeyShareService; import com.glsx.smart.service.AiLockingKeyShareService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -28,6 +26,12 @@ public class AiLockingkeyShareController { ...@@ -28,6 +26,12 @@ public class AiLockingkeyShareController {
return aiLockingKeyShareService.isTokenValid(token); return aiLockingKeyShareService.isTokenValid(token);
} }
//根据userId获取分享车钥匙列表
@GetMapping(value = "/getShareKeyListByUser")
public R getShareKeyListByUser(@RequestParam(value="userId")Long userId) {
return aiLockingKeyShareService.getShareKeyListByUser(userId);
}
//领取钥匙接口 //领取钥匙接口
@PostMapping(value = "/receive") @PostMapping(value = "/receive")
public R receiveKey(@RequestBody SmartCarKeyReceiveRequest request) { public R receiveKey(@RequestBody SmartCarKeyReceiveRequest request) {
......
...@@ -91,7 +91,7 @@ public class SmartVehicleBlueKey { ...@@ -91,7 +91,7 @@ public class SmartVehicleBlueKey {
private String mobileBlueMac; private String mobileBlueMac;
/** /**
* 分享状态 0:打开 1:关闭 * 分享状态 0:关闭 1:打开
* 默认打开 * 默认打开
*/ */
private Integer shareStatus; private Integer shareStatus;
......
...@@ -58,7 +58,7 @@ public class SmartVehicleBlueShareKey implements Comparable<SmartVehicleBlueShar ...@@ -58,7 +58,7 @@ public class SmartVehicleBlueShareKey implements Comparable<SmartVehicleBlueShar
private Date pickTime; private Date pickTime;
/** /**
* 分享状态 1:打开 0:关闭 * 分享状态 0:关闭 1:打开
*/ */
private Integer shareStatus; private Integer shareStatus;
......
...@@ -17,4 +17,7 @@ public class SmartCarKeyCommandRequest{ ...@@ -17,4 +17,7 @@ public class SmartCarKeyCommandRequest{
//用户id //用户id
private String userId; private String userId;
//上报时间 yyyy-MM-dd
private String logDate;
} }
...@@ -11,4 +11,7 @@ public class SmartCarKeyShareLogRequest { ...@@ -11,4 +11,7 @@ public class SmartCarKeyShareLogRequest {
//分享车钥匙id //分享车钥匙id
private String shareKeyId; private String shareKeyId;
//上报时间 yyyy-MM-dd
private String logDate;
} }
...@@ -12,7 +12,7 @@ public class SmartKeyPrimaryShareEditReq { ...@@ -12,7 +12,7 @@ public class SmartKeyPrimaryShareEditReq {
private String userId; private String userId;
/** /**
* 分享状态 0:打开 1:关闭 * 分享状态 0:关闭 1:打开
* 默认打开 * 默认打开
*/ */
private Integer shareStatus; private Integer shareStatus;
......
...@@ -77,7 +77,7 @@ public class SmartCarKeyResponse implements Serializable { ...@@ -77,7 +77,7 @@ public class SmartCarKeyResponse implements Serializable {
private String peripheralUuid; private String peripheralUuid;
/** /**
* 分享状态 0:打开 1:关闭 * 分享状态 0:关闭 1:打开
* 默认打开 * 默认打开
*/ */
private Integer shareStatus; private Integer shareStatus;
......
...@@ -18,4 +18,6 @@ public interface AiLockingKeyShareService { ...@@ -18,4 +18,6 @@ public interface AiLockingKeyShareService {
R getShareLockingKey(String keyId); R getShareLockingKey(String keyId);
R isTokenValid(String token); R isTokenValid(String token);
R getShareKeyListByUser(Long userId);
} }
...@@ -35,5 +35,7 @@ public interface SmartVehicleBlueShareKeyService { ...@@ -35,5 +35,7 @@ public interface SmartVehicleBlueShareKeyService {
SmartVehicleBlueShareKeyExample getBlueKeyShareExampleByID(Long id); SmartVehicleBlueShareKeyExample getBlueKeyShareExampleByID(Long id);
int updateShareStatusByIds(List<Long> ids); int updateShareStatusByIds(List<Long> ids);
List<SmartVehicleBlueShareKey> getShareKeyListByUserId(Long userId);
} }
...@@ -93,31 +93,13 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -93,31 +93,13 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
String crepCode = carkey.getCrepCode(); String crepCode = carkey.getCrepCode();
//如果车钥匙有数据,但是crep为空字符串 //如果车钥匙有数据,但是crep为空字符串
if (StringUtils.isEmpty(crepCode)) if(StringUtils.isEmpty(crepCode)){
throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_10); throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_10);
}
//如果车钥匙有对应的crep,返回钥匙信息 //如果车钥匙有对应的crep,返回钥匙信息
buildCarKeyData(response, carkey, crepCode, true); buildCarKeyData(response, carkey, crepCode, true);
return R.ok().data(response); return R.ok().data(response);
/*else {
//如果车钥匙没有对应的crep,生成只含有crep钥匙更新并返回钥匙信息
//雪花算法生成crep,对称加密
String crep = getCrepCode();
//更新,crep用明文存储
carkey.setSn(request.getSn());
carkey.setUserId(Long.valueOf(request.getUserId()));
carkey.setCrepCode(crep);
carkey.setCreateTime(new Date());
carkey.setAutoSenseStatus(0);
carkey.setIsDelete(0);
carkey.setMobileCode("0");
smartVehicleBlueKeyService.updateByPrimaryKey(carkey);
buldCarKeyData(response, carkey, crep, false);
return R.ok().data(response);
}*/
} }
} }
...@@ -168,7 +150,7 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -168,7 +150,7 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//明文存储crep //明文存储crep
logData.setCrepCode(crep); logData.setCrepCode(crep);
logData.setKeyCommand(carKeyCommandRequest.getKeyCommand()); logData.setKeyCommand(carKeyCommandRequest.getKeyCommand());
logData.setCreateTime(new Date()); logData.setCreateTime(DateUtil.parse(carKeyCommandRequest.getLogDate(),"yyyy-MM-dd"));
smartKeyCommandLogService.insert(logData); smartKeyCommandLogService.insert(logData);
return R.ok(); return R.ok();
} }
...@@ -195,7 +177,6 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -195,7 +177,6 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
List<SmartVehicleBlueKey> keyList = smartVehicleBlueKeyService.selectByExample(example); List<SmartVehicleBlueKey> keyList = smartVehicleBlueKeyService.selectByExample(example);
if (CollectionUtils.isNotEmpty(keyList)) { if (CollectionUtils.isNotEmpty(keyList)) {
//判断用户下是否已经存在同名的设备 //判断用户下是否已经存在同名的设备
boolean IfExist = keyList.stream().anyMatch(key -> { boolean IfExist = keyList.stream().anyMatch(key -> {
//数据库中存在的sn //数据库中存在的sn
...@@ -235,8 +216,10 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -235,8 +216,10 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//查询该车钥匙是否存在 //查询该车钥匙是否存在
List<SmartVehicleBlueKey> blueKeys = smartVehicleBlueKeyService.selectByUserAndSn(userId, sn); List<SmartVehicleBlueKey> blueKeys = smartVehicleBlueKeyService.selectByUserAndSn(userId, sn);
if (CollectionUtils.isEmpty(blueKeys)) if (CollectionUtils.isEmpty(blueKeys)){
return R.error("车钥匙不存在"); return R.error("车钥匙不存在");
}
SmartVehicleBlueKey blueKey = blueKeys.get(0); SmartVehicleBlueKey blueKey = blueKeys.get(0);
long carKeyId = blueKey.getId(); long carKeyId = blueKey.getId();
...@@ -298,8 +281,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -298,8 +281,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
String secretKey_db = key.getSecretKey(); String secretKey_db = key.getSecretKey();
try { try {
if (StringUtils.isNotEmpty(secretKey_db)) if (StringUtils.isNotEmpty(secretKey_db)){
secretKey = aesEncryptUtils.decryptSecret(secretKey_db); secretKey = aesEncryptUtils.decryptSecret(secretKey_db);
}
} catch (Exception e) { } catch (Exception e) {
throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_12); throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_12);
} }
...@@ -310,8 +294,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -310,8 +294,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
String secret_key_encrypt = ""; String secret_key_encrypt = "";
try { try {
crep_encrypt = aesEncryptUtils.encrypt(crepCode); crep_encrypt = aesEncryptUtils.encrypt(crepCode);
if (StringUtils.isNotEmpty(secretKey)) if (StringUtils.isNotEmpty(secretKey)){
secret_key_encrypt = aesEncryptUtils.encrypt(secretKey); secret_key_encrypt = aesEncryptUtils.encrypt(secretKey);
}
} catch (Exception e) { } catch (Exception e) {
throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_13); throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_13);
} }
...@@ -381,8 +366,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -381,8 +366,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//查询钥匙 //查询钥匙
List<SmartVehicleBlueKey> keys = smartVehicleBlueKeyService.selectByUserAndSn(userId, sn); List<SmartVehicleBlueKey> keys = smartVehicleBlueKeyService.selectByUserAndSn(userId, sn);
if (CollectionUtils.isEmpty(keys)) if (CollectionUtils.isEmpty(keys)){
return R.ok().data(""); return R.ok().data(keys);
}
//根据钥匙id查蓝牙信息 //根据钥匙id查蓝牙信息
long carKeyId = keys.get(0).getId(); long carKeyId = keys.get(0).getId();
...@@ -424,15 +410,17 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -424,15 +410,17 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
List<SmartVehicleBlueKey> smartVehicleBlueKeyList = smartVehicleBlueKeyService.selectByExample(example); List<SmartVehicleBlueKey> smartVehicleBlueKeyList = smartVehicleBlueKeyService.selectByExample(example);
//车钥匙不存在 //车钥匙不存在
if (CollectionUtils.isEmpty(smartVehicleBlueKeyList)) if (CollectionUtils.isEmpty(smartVehicleBlueKeyList)){
throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_3); throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_3);
}
SmartVehicleBlueKey smartVehicleBlueKey = smartVehicleBlueKeyList.get(0); SmartVehicleBlueKey smartVehicleBlueKey = smartVehicleBlueKeyList.get(0);
String mobileMac = request.getMobileMac(); String mobileMac = request.getMobileMac();
if (StringUtils.isBlank(mobileMac)) if (StringUtils.isBlank(mobileMac)){
return R.error("手机蓝牙不能为空"); return R.error("手机蓝牙不能为空");
}
try { try {
//查询该钥匙下手机mac是否存在 //查询该钥匙下手机mac是否存在
...@@ -534,8 +522,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -534,8 +522,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
String secret_key_encrypt = ""; String secret_key_encrypt = "";
try { try {
crep_encrypt = aesEncryptUtils.encrypt(crepCode); crep_encrypt = aesEncryptUtils.encrypt(crepCode);
if (StringUtils.isNotEmpty(secretKey)) if (StringUtils.isNotEmpty(secretKey)){
secret_key_encrypt = aesEncryptUtils.encrypt(secretKey); secret_key_encrypt = aesEncryptUtils.encrypt(secretKey);
}
} catch (Exception e) { } catch (Exception e) {
String error_msg = "智能车钥匙查询加密异常,crep存在:" + crepExist + ",crep:" + crepCode; String error_msg = "智能车钥匙查询加密异常,crep存在:" + crepExist + ",crep:" + crepCode;
log.info(error_msg); log.info(error_msg);
...@@ -550,8 +539,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -550,8 +539,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
//CarKeyID查询关联的手机蓝牙mac,自动感应状态 //CarKeyID查询关联的手机蓝牙mac,自动感应状态
SmartKeyBlueSense smartKeyBlueSense = smartKeyBlueSenseService.getRecentBlueSenseByCarKeyID(carkey.getId()); SmartKeyBlueSense smartKeyBlueSense = smartKeyBlueSenseService.getRecentBlueSenseByCarKeyID(carkey.getId());
if (null == smartKeyBlueSense) if (null == smartKeyBlueSense){
return; return;
}
response.setMobileBlueMac(smartKeyBlueSense.getMobileBlueMac()); response.setMobileBlueMac(smartKeyBlueSense.getMobileBlueMac());
response.setAutoSenseStatus(smartKeyBlueSense.getAutoSenseStatus()); response.setAutoSenseStatus(smartKeyBlueSense.getAutoSenseStatus());
...@@ -562,11 +552,14 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -562,11 +552,14 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
String snowId = Long.toHexString(snowflakeWorker.nextId()); String snowId = Long.toHexString(snowflakeWorker.nextId());
int len = snowId.length(); int len = snowId.length();
//如果长度为16直接返回 //如果长度为16直接返回
if (len == 16) if (len == 16){
return snowId; return snowId;
}
//如果长度大于16,截取 //如果长度大于16,截取
if (len > 16) if (len > 16){
return snowId.substring(len - 16, len); return snowId.substring(len - 16, len);
}
//长度不足的,前面补0 //长度不足的,前面补0
int count = 16 - len; int count = 16 - len;
...@@ -589,8 +582,10 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -589,8 +582,10 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
SmartVehicleBlueKeyExample example = smartVehicleBlueKeyService.getBlueKeyExampleByUserAndSn(Long.valueOf(request.getUserId()), request.getSn()); SmartVehicleBlueKeyExample example = smartVehicleBlueKeyService.getBlueKeyExampleByUserAndSn(Long.valueOf(request.getUserId()), request.getSn());
List<SmartVehicleBlueKey> smartVehicleBlueKeys =smartVehicleBlueKeyService.selectByExample(example); List<SmartVehicleBlueKey> smartVehicleBlueKeys =smartVehicleBlueKeyService.selectByExample(example);
if(CollectionUtils.isEmpty(smartVehicleBlueKeys)) if(CollectionUtils.isEmpty(smartVehicleBlueKeys)){
return R.error("车钥匙不存在"); return R.error("车钥匙不存在");
}
//逻辑删除蓝牙车钥匙设备 //逻辑删除蓝牙车钥匙设备
SmartVehicleBlueKey smartVehicleBlueKey = smartVehicleBlueKeys.get(0); SmartVehicleBlueKey smartVehicleBlueKey = smartVehicleBlueKeys.get(0);
...@@ -622,8 +617,10 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -622,8 +617,10 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
String expireTime = request.getExpireTime(); String expireTime = request.getExpireTime();
List<SmartVehicleBlueKey> keys = smartVehicleBlueKeyService.selectByUserAndSn(userId, sn); List<SmartVehicleBlueKey> keys = smartVehicleBlueKeyService.selectByUserAndSn(userId, sn);
if (CollectionUtils.isEmpty(keys)) if (CollectionUtils.isEmpty(keys)){
return R.error("车钥匙不存在"); return R.error("车钥匙不存在");
}
long keyId = keys.get(0).getId(); long keyId = keys.get(0).getId();
...@@ -657,8 +654,10 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -657,8 +654,10 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
long userId = Long.valueOf(request.getUserId()); long userId = Long.valueOf(request.getUserId());
String sn = request.getSn(); String sn = request.getSn();
List<SmartVehicleBlueKey> keys = smartVehicleBlueKeyService.selectByUserAndSn(userId, sn); List<SmartVehicleBlueKey> keys = smartVehicleBlueKeyService.selectByUserAndSn(userId, sn);
if (CollectionUtils.isEmpty(keys)) if (CollectionUtils.isEmpty(keys)){
return R.ok().data(PageInfo.of(null)); return R.ok().data(PageInfo.of(null));
}
//根据钥匙查询分享钥匙列表 //根据钥匙查询分享钥匙列表
SmartVehicleBlueKey keyId = keys.get(0); SmartVehicleBlueKey keyId = keys.get(0);
...@@ -675,8 +674,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService { ...@@ -675,8 +674,9 @@ public class AiLockingKeyServiceImpl implements AiLockingKeyService {
SmartVehicleBlueShareKeyExample shareKeyExample = smartVehicleBlueShareKeyService.getBlueKeyShareExampleByCarKeyID(keyId.getId()); SmartVehicleBlueShareKeyExample shareKeyExample = smartVehicleBlueShareKeyService.getBlueKeyShareExampleByCarKeyID(keyId.getId());
List<SmartVehicleBlueShareKey> shareKeyList = smartVehicleBlueShareKeyService.selectByExample(shareKeyExample); List<SmartVehicleBlueShareKey> shareKeyList = smartVehicleBlueShareKeyService.selectByExample(shareKeyExample);
if (CollectionUtils.isEmpty(shareKeyList)) if (CollectionUtils.isEmpty(shareKeyList)){
return R.ok().data(PageInfo.of(shareKeyList)); return R.ok().data(PageInfo.of(shareKeyList));
}
//校验过期时间 //校验过期时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
......
package com.glsx.smart.service.impl; package com.glsx.smart.service.impl;
import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import com.glsx.smart.dao.entity.*; import com.glsx.smart.dao.entity.*;
import com.glsx.smart.exception.BusinessException; import com.glsx.smart.exception.BusinessException;
...@@ -17,14 +20,13 @@ import io.jsonwebtoken.Claims; ...@@ -17,14 +20,13 @@ import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.ExpiredJwtException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.dubbo.common.utils.Assert;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.*;
import java.util.HashMap; import java.util.stream.Collectors;
import java.util.List;
import java.util.Map;
/** /**
* <p>Description:智能车钥匙service * <p>Description:智能车钥匙service
...@@ -62,15 +64,19 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService { ...@@ -62,15 +64,19 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService {
boolean isReceive = isKeyReceive(keyShareID); boolean isReceive = isKeyReceive(keyShareID);
if(isReceive) if(isReceive){
return R.error("钥匙已领取"); return R.error("钥匙已领取");
}
SmartVehicleBlueKey key = null; SmartVehicleBlueKey key = null;
//主钥匙 //主钥匙
List<SmartVehicleBlueKey> keyList = blueKeyService.selectById(keyid); List<SmartVehicleBlueKey> keyList = blueKeyService.selectById(keyid);
if(CollectionUtils.isNotEmpty(keyList)) if(CollectionUtils.isNotEmpty(keyList)){
key = keyList.get(0); key = keyList.get(0);
}
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("key", key); map.put("key", key);
...@@ -89,8 +95,10 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService { ...@@ -89,8 +95,10 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService {
//setnx,只允许一个人领取钥匙 //setnx,只允许一个人领取钥匙
boolean res = redisService.setnx("receive_share_key:"+token,userId); boolean res = redisService.setnx("receive_share_key:"+token,userId);
if(!res) if(!res){
throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_14); throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_14);
}
//已领取 //已领取
shareKey.setSharePickStatus(1); shareKey.setSharePickStatus(1);
//领取用户 //领取用户
...@@ -121,13 +129,11 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService { ...@@ -121,13 +129,11 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService {
public R logShareLockingKeyCommand(SmartCarKeyShareLogRequest request) { public R logShareLockingKeyCommand(SmartCarKeyShareLogRequest request) {
long keyId = Long.valueOf(request.getShareKeyId()); long keyId = Long.valueOf(request.getShareKeyId());
String command = request.getKeyCommand(); String command = request.getKeyCommand();
SmartKeyCommandShareLog logData = new SmartKeyCommandShareLog(); SmartKeyCommandShareLog logData = new SmartKeyCommandShareLog();
logData.setKeyCommand(command); logData.setKeyCommand(command);
logData.setShareCarKeyId(keyId); logData.setShareCarKeyId(keyId);
logData.setCreateTime(new Date()); logData.setCreateTime(DateUtil.parse(request.getLogDate(),"yyyy-MM-dd"));
shareLogService.insert(logData); shareLogService.insert(logData);
return R.ok(); return R.ok();
} }
...@@ -184,12 +190,60 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService { ...@@ -184,12 +190,60 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService {
return R.ok().data(keyList.get(0)); return R.ok().data(keyList.get(0));
} }
//判断令牌是否有效
@Override @Override
public R isTokenValid(String token) { public R isTokenValid(String token) {
checkToeknValid(token); checkToeknValid(token);
return R.ok(); return R.ok();
} }
//根据userId获取分享车钥匙列表
@Override
public R getShareKeyListByUser(Long userId) {
Assert.notNull(userId,"用户id不能为空");
List<SmartVehicleBlueShareKey> keys = shareKeyService.getShareKeyListByUserId(userId);
if (CollectionUtils.isEmpty(keys)){
return R.ok().data(keys);
}
//校验过期时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String nowTime = sdf.format(new Date());
Date nowDate = null;
try {
nowDate = sdf.parse(nowTime);
} catch (ParseException e) {
e.printStackTrace();
return R.error("时间格式不对:yyyy-MM-dd");
}
List<SmartVehicleBlueShareKey> responseList = new ArrayList<>();
List<Long> expireList = new ArrayList<>();
//过期数据分类
Date finalNowDate = nowDate;
keys.stream().forEach(key -> {
Date expireDate = key.getExpireTime();
if (finalNowDate.after(expireDate)) {
expireList.add(key.getId());
//过期关闭
key.setShareStatus(0);
key.setExpireTime(new Date());
}else {
responseList.add(key);
}
});
//如果当前时间已经超过过期时间,更新数据
if (CollectionUtils.isNotEmpty(expireList)) {
shareKeyService.updateShareStatusByIds(expireList);
}
return R.ok().data(responseList);
}
private SmartVehicleBlueShareKey checkToeknValid(String token) { private SmartVehicleBlueShareKey checkToeknValid(String token) {
Claims claims = praseToken(token); Claims claims = praseToken(token);
...@@ -197,8 +251,10 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService { ...@@ -197,8 +251,10 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService {
boolean isReceive = isKeyReceive(keyShareID); boolean isReceive = isKeyReceive(keyShareID);
if(isReceive) if(isReceive){
throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_14); throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_14);
}
//校验过期时间 //校验过期时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
...@@ -206,8 +262,10 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService { ...@@ -206,8 +262,10 @@ public class AiLockingKeyShareServiceImpl implements AiLockingKeyShareService {
SmartVehicleBlueShareKey shareKey=shareKeyService.selectByPrimaryKey(keyShareID); SmartVehicleBlueShareKey shareKey=shareKeyService.selectByPrimaryKey(keyShareID);
if(null == shareKey) if(null == shareKey){
throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_15); throw new BusinessException(ResultEnum.CAR_KEY_EXCEP_15);
}
Date expireDate = shareKey.getExpireTime(); Date expireDate = shareKey.getExpireTime();
Date nowDate = null; Date nowDate = null;
......
...@@ -99,5 +99,15 @@ public class SmartVehicleBlueShareKeyServiceImpl implements SmartVehicleBlueShar ...@@ -99,5 +99,15 @@ public class SmartVehicleBlueShareKeyServiceImpl implements SmartVehicleBlueShar
public int updateShareStatusByIds(List<Long> ids) { public int updateShareStatusByIds(List<Long> ids) {
return smartVehicleBlueShareKeyMapper.updateShareStatusByIds(ids); return smartVehicleBlueShareKeyMapper.updateShareStatusByIds(ids);
} }
@Override
public List<SmartVehicleBlueShareKey> getShareKeyListByUserId(Long userId) {
SmartVehicleBlueShareKeyExample example = new SmartVehicleBlueShareKeyExample();
example.createCriteria()
.andPickUserIdEqualTo(userId)
.andSharePickStatusEqualTo(1)
.andShareStatusEqualTo(1);
return smartVehicleBlueShareKeyMapper.selectByExample(example);
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!