AiLockingKeyServiceImpl.java
6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.glsx.smart.service.impl;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.glsx.plat.common.utils.SnowFlake;
import com.glsx.smart.dao.entity.SmartKeyCommandLog;
import com.glsx.smart.dao.entity.SmartVehicleBlueKey;
import com.glsx.smart.dao.entity.SmartVehicleBlueKeyExample;
import com.glsx.smart.pojo.request.*;
import com.glsx.smart.pojo.response.SmartCarKeyOpreateResponse;
import com.glsx.smart.pojo.response.SmartCarKeyResponse;
import com.glsx.smart.service.AiLockingKeyService;
import com.glsx.smart.service.SmartKeyCommandLogService;
import com.glsx.smart.service.SmartVehicleBlueKeyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* <p>Description:智能车钥匙service
* <p>Project: chejia-smart
*
* @author fengzhi
* @date 2021-04-19
*/
@Service
@Slf4j
public class AiLockingKeyServiceImpl implements AiLockingKeyService {
@Autowired
private SmartKeyCommandLogService smartKeyCommandLogService;
@Autowired
private SmartVehicleBlueKeyService smartVehicleBlueKeyService;
//sn查询/新增车钥匙
@Override
public SmartCarKeyResponse getLockingKey(SmartCarKeyRequest request) {
SmartCarKeyResponse response = new SmartCarKeyResponse();
SmartVehicleBlueKeyExample example = new SmartVehicleBlueKeyExample();
example.createCriteria().andUserIdEqualTo(request.getUserId()).andSnEqualTo(request.getSn()).andIsDeleteEqualTo(0);
List<SmartVehicleBlueKey> smartVehicleBlueKeys = smartVehicleBlueKeyService.selectByExample(example);
if(CollectionUtils.isEmpty(smartVehicleBlueKeys)){
//如果sn,userid没有数据,生成只含有crep钥匙信息返回
SmartVehicleBlueKey newKey = new SmartVehicleBlueKey();
//todo 雪花算法生成crep,对称加密
long id = SnowFlake.nextId();
long userId = request.getUserId();
newKey.setCrepCode("");
newKey.setCreateTime(new Date());
smartVehicleBlueKeyService.insert(newKey);
BeanUtils.copyProperties(newKey,response);
return response;
}else {
SmartVehicleBlueKey carkey = smartVehicleBlueKeys.get(0);
String crepCode = carkey.getCrepCode();
if(StringUtils.isNotEmpty(crepCode)){
//如果sn,userid有对应的crep,返回钥匙信息
BeanUtils.copyProperties(carkey,response);
return response;
}else {
//如果sn,userid没有对应的crep。生成只含有crep钥匙信息返回
carkey.setCrepCode(request.getSn());
carkey.setCreateTime(new Date());
smartVehicleBlueKeyService.updateByPrimaryKey(carkey);
BeanUtils.copyProperties(carkey,response);
return response;
}
}
}
//智能车钥匙解绑
@Override
public SmartCarKeyOpreateResponse removeLockingKey(SmartCarKeyRmRequest request) {
SmartVehicleBlueKey smartVehicleBlueKey = new SmartVehicleBlueKey();
smartVehicleBlueKey.setIsDelete(1);
int conut = smartVehicleBlueKeyService.updateByExample(smartVehicleBlueKey, getExample(request.getUserId(), request.getCrep()));
return getOpreateResponse(conut);
}
//车钥匙操作指令上报
@Override
public SmartCarKeyOpreateResponse LogLockingKeyCommand(SmartCarKeyCommandRequest carKeyCommandRequest) {
SmartKeyCommandLog log = new SmartKeyCommandLog();
log.setUserId(carKeyCommandRequest.getUserId());
log.setCrep(carKeyCommandRequest.getCrepCode());
log.setKeyCommand(carKeyCommandRequest.getKeyCommond());
log.setCreateTime(new Date());
int conut = smartKeyCommandLogService.insert(log);
return getOpreateResponse(conut);
}
//车钥匙修改昵称
@Override
public SmartCarKeyOpreateResponse setLockingKeyName(SmartCarKeyNameRequest request) {
SmartVehicleBlueKey smartVehicleBlueKey = new SmartVehicleBlueKey();
smartVehicleBlueKey.setKeyName(request.getName());
int conut = smartVehicleBlueKeyService.updateByExample(smartVehicleBlueKey, getExample(request.getUserId(), request.getCrep()));
return getOpreateResponse(conut);
}
//车钥匙修改自动感应
@Override
public SmartCarKeyOpreateResponse setLockingKeyAutoSense(SmartCarKeyAutoSenseRequest request) {
SmartVehicleBlueKey smartVehicleBlueKey = new SmartVehicleBlueKey();
smartVehicleBlueKey.setAutoSenseStatus(request.getAutoSenseStatus());
int conut = smartVehicleBlueKeyService.updateByExample(smartVehicleBlueKey, getExample(request.getUserId(), request.getCrep()));
return getOpreateResponse(conut);
}
//智能车钥匙注册成功后的数据保存
@Override
public SmartCarKeyOpreateResponse saveLockingKeyRegisterInfo(SmartCarKeyRegisterRequest request) {
SmartVehicleBlueKey smartVehicleBlueKey = new SmartVehicleBlueKey();
smartVehicleBlueKey.setMobileBlueMac(request.getMobileMac());
smartVehicleBlueKey.setSmartLockMac(request.getSmartLockMac());
smartVehicleBlueKey.setSecretKey(request.getKeyLock());
int conut = smartVehicleBlueKeyService.updateByExample(smartVehicleBlueKey, getExample(request.getUserId(), request.getCrepCode()));
return getOpreateResponse(conut);
}
//查询车钥匙example,根据用户ID和crep查
private SmartVehicleBlueKeyExample getExample(Long userId, String crep) {
SmartVehicleBlueKeyExample example = new SmartVehicleBlueKeyExample();
example.createCriteria().andUserIdEqualTo(userId).andCrepCodeEqualTo(crep).andIsDeleteEqualTo(0);
return example;
}
private SmartCarKeyOpreateResponse getOpreateResponse(int conut) {
SmartCarKeyOpreateResponse response = new SmartCarKeyOpreateResponse();
response.setSuccess(conut > 0);
return response;
}
}