|
@@ -9,6 +9,9 @@ import lombok.extern.slf4j.Slf4j; |
|
@@ -9,6 +9,9 @@ import lombok.extern.slf4j.Slf4j; |
9
|
import org.apache.commons.lang3.StringUtils;
|
9
|
import org.apache.commons.lang3.StringUtils;
|
10
|
import org.springframework.stereotype.Service;
|
10
|
import org.springframework.stereotype.Service;
|
11
|
import org.springframework.transaction.annotation.Transactional;
|
11
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
12
|
+import org.thingsboard.server.common.data.DeviceProfile;
|
|
|
13
|
+import org.thingsboard.server.common.data.id.TenantId;
|
|
|
14
|
+import org.thingsboard.server.common.data.security.DeviceCredentials;
|
12
|
import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
|
15
|
import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
|
13
|
import org.thingsboard.server.common.data.yunteng.constant.ModelConstants;
|
16
|
import org.thingsboard.server.common.data.yunteng.constant.ModelConstants;
|
14
|
import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException;
|
17
|
import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException;
|
|
@@ -19,11 +22,11 @@ import org.thingsboard.server.common.data.yunteng.enums.DeviceState; |
|
@@ -19,11 +22,11 @@ import org.thingsboard.server.common.data.yunteng.enums.DeviceState; |
19
|
import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
|
22
|
import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
|
20
|
import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils;
|
23
|
import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils;
|
21
|
import org.thingsboard.server.common.data.yunteng.utils.tools.PageData;
|
24
|
import org.thingsboard.server.common.data.yunteng.utils.tools.PageData;
|
|
|
25
|
+import org.thingsboard.server.dao.device.DeviceCredentialsDao;
|
|
|
26
|
+import org.thingsboard.server.dao.device.DeviceProfileDao;
|
22
|
import org.thingsboard.server.dao.yunteng.entities.Organization;
|
27
|
import org.thingsboard.server.dao.yunteng.entities.Organization;
|
23
|
import org.thingsboard.server.dao.yunteng.entities.YtDevice;
|
28
|
import org.thingsboard.server.dao.yunteng.entities.YtDevice;
|
24
|
-import org.thingsboard.server.dao.yunteng.entities.YtDeviceProfile;
|
|
|
25
|
import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper;
|
29
|
import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper;
|
26
|
-import org.thingsboard.server.dao.yunteng.mapper.DeviceProfileMapper;
|
|
|
27
|
import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper;
|
30
|
import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper;
|
28
|
import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
|
31
|
import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
|
29
|
import org.thingsboard.server.dao.yunteng.service.YtDeviceService;
|
32
|
import org.thingsboard.server.dao.yunteng.service.YtDeviceService;
|
|
@@ -40,77 +43,28 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
|
@@ -40,77 +43,28 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
40
|
// private final TBConfig tbConfig;
|
43
|
// private final TBConfig tbConfig;
|
41
|
// private final TBConnectService tbConnectService;
|
44
|
// private final TBConnectService tbConnectService;
|
42
|
// private final TbDBService tbDBService;
|
45
|
// private final TbDBService tbDBService;
|
43
|
- private final DeviceProfileMapper deviceProfileMapper;
|
|
|
44
|
- private final OrganizationMapper organizationMapper;
|
46
|
+ private final DeviceProfileDao deviceProfileDao;
|
|
|
47
|
+ private final DeviceCredentialsDao deviceCredentialsDao;
|
|
|
48
|
+
|
45
|
|
49
|
|
|
|
50
|
+ private final OrganizationMapper organizationMapper;
|
46
|
@Override
|
51
|
@Override
|
47
|
// @Transactional
|
52
|
// @Transactional
|
48
|
// 事务会导致 tbDBService 多数据源失效
|
53
|
// 事务会导致 tbDBService 多数据源失效
|
49
|
public DeviceDTO insertOrUpdate(String tenantId,DeviceDTO deviceDTO) {
|
54
|
public DeviceDTO insertOrUpdate(String tenantId,DeviceDTO deviceDTO) {
|
|
|
55
|
+
|
50
|
if (StringUtils.isBlank(deviceDTO.getId())) {
|
56
|
if (StringUtils.isBlank(deviceDTO.getId())) {
|
51
|
- return insert(tenantId,deviceDTO);
|
57
|
+ return insert(deviceDTO);
|
52
|
} else {
|
58
|
} else {
|
53
|
return update(tenantId,deviceDTO);
|
59
|
return update(tenantId,deviceDTO);
|
54
|
}
|
60
|
}
|
55
|
}
|
61
|
}
|
56
|
|
62
|
|
57
|
private DeviceDTO update(String tenantId,DeviceDTO deviceDTO) {
|
63
|
private DeviceDTO update(String tenantId,DeviceDTO deviceDTO) {
|
58
|
- YtDevice device = baseMapper.selectById(deviceDTO.getId());
|
|
|
59
|
- if (!device.getTenantId().equals(tenantId)) {
|
|
|
60
|
- return null;
|
|
|
61
|
- }
|
|
|
62
|
- validateDeviceDTO(tenantId,deviceDTO, false);
|
|
|
63
|
- List<YtDevice> devices =
|
|
|
64
|
- baseMapper.selectList(
|
|
|
65
|
- new QueryWrapper<YtDevice>()
|
|
|
66
|
- .lambda()
|
|
|
67
|
-// .eq(YtDevice::getDeviceToken, deviceDTO.getDeviceToken())
|
|
|
68
|
- );
|
|
|
69
|
- if (!devices.isEmpty()) {
|
|
|
70
|
- // 如果device token已经存在,那么必定只有一个,不会有多个
|
|
|
71
|
- YtDevice deviceExistWithSameToken = devices.get(0);
|
|
|
72
|
- if (!deviceExistWithSameToken.getId().equals(deviceDTO.getId())) {
|
|
|
73
|
- throw new DataValidationException("设备Device Token已经存在!");
|
|
|
74
|
- }
|
|
|
75
|
- }
|
|
|
76
|
- // 首先update tb, 需要更新的字段有
|
|
|
77
|
- // name, tbDeviceProfileId, label, isGateway, deviceToken
|
|
|
78
|
- /*if (tbConfig.isEnabled()) {
|
|
|
79
|
- validateUpdate(deviceDTO);
|
|
|
80
|
- deviceDTO.setTbDeviceId(device.getTbDeviceId());
|
|
|
81
|
- // 判断name, tbDeviceProfileId, label, isGateway是否有更新
|
|
|
82
|
- boolean changed = detectDeviceChange(deviceDTO, device);
|
|
|
83
|
- if (changed) {
|
|
|
84
|
- Device tbDevice = buildTbDeviceFromDeviceDTO(deviceDTO);
|
|
|
85
|
- try {
|
|
|
86
|
- tbConnectService.saveDevice(tbDevice, deviceDTO.getDeviceToken()).get();
|
|
|
87
|
- } catch (InterruptedException | ExecutionException e) {
|
|
|
88
|
- log.error("update device to tb error:{}", e.getMessage());
|
|
|
89
|
- throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR);
|
|
|
90
|
- }
|
|
|
91
|
- }
|
|
|
92
|
- // update deviceToken
|
|
|
93
|
- if (!deviceDTO.getDeviceToken().equals(device.getDeviceToken())) {
|
|
|
94
|
- CredentialEntity credentialEntity =
|
|
|
95
|
- tbDBService.findDeviceCredentialsByDeviceId(deviceDTO.getTbDeviceId());
|
|
|
96
|
- if (credentialEntity == null) {
|
|
|
97
|
- log.error("tb 无此设备信息->tbDeviceId[{}]", deviceDTO.getTbDeviceId());
|
|
|
98
|
- throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR.setMessage("tb 无此设备信息"));
|
|
|
99
|
- }
|
|
|
100
|
- credentialEntity.setCredentialsId(deviceDTO.getDeviceToken());
|
|
|
101
|
- TBCredential tbCredential = buildTBCredential(credentialEntity);
|
|
|
102
|
- try {
|
|
|
103
|
- TBCredential newTbCredentials = tbConnectService.saveDeviceCredential(tbCredential).get();
|
|
|
104
|
- if (newTbCredentials == null) {
|
|
|
105
|
- throw new FastIotException(
|
|
|
106
|
- ErrorMessage.CONNECT_TO_TB_ERROR.setMessage("update tb credentials error"));
|
|
|
107
|
- }
|
|
|
108
|
- } catch (InterruptedException | ExecutionException e) {
|
|
|
109
|
- log.error("update device to tb error:{}", e.getMessage());
|
|
|
110
|
- throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR);
|
|
|
111
|
- }
|
|
|
112
|
- }
|
|
|
113
|
- }*/
|
64
|
+
|
|
|
65
|
+ validateUpdate(deviceDTO);
|
|
|
66
|
+
|
|
|
67
|
+ YtDevice device = new YtDevice();
|
114
|
deviceDTO.copyToEntity(
|
68
|
deviceDTO.copyToEntity(
|
115
|
device,
|
69
|
device,
|
116
|
ModelConstants.TablePropertyMapping.ACTIVE_TIME,
|
70
|
ModelConstants.TablePropertyMapping.ACTIVE_TIME,
|
|
@@ -126,22 +80,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
|
@@ -126,22 +80,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
126
|
return device.getDTO(DeviceDTO.class);
|
80
|
return device.getDTO(DeviceDTO.class);
|
127
|
}
|
81
|
}
|
128
|
|
82
|
|
129
|
-// private TBCredential buildTBCredential(CredentialEntity credentialEntity) {
|
|
|
130
|
-// Assert.notNull(credentialEntity, "credentialEntity cannot be null");
|
|
|
131
|
-// TBCredential tbCredential = new TBCredential();
|
|
|
132
|
-// tbCredential.setCredentialsId(credentialEntity.getCredentialsId());
|
|
|
133
|
-// tbCredential.setCredentialsType(credentialEntity.getCredentialsType());
|
|
|
134
|
-// tbCredential.setCreateTime(credentialEntity.getCreatedTime());
|
|
|
135
|
-// tbCredential.setCredentialsValue(credentialEntity.getCredentialsValue());
|
|
|
136
|
-// Id deviceId = new Id();
|
|
|
137
|
-// deviceId.setEntityType(EntityType.DEVICE);
|
|
|
138
|
-// deviceId.setId(credentialEntity.getDeviceId());
|
|
|
139
|
-// tbCredential.setDeviceId(deviceId);
|
|
|
140
|
-// Id id = new Id();
|
|
|
141
|
-// id.setId(credentialEntity.getId());
|
|
|
142
|
-// tbCredential.setId(id);
|
|
|
143
|
-// return tbCredential;
|
|
|
144
|
-// }
|
83
|
+
|
145
|
|
84
|
|
146
|
private void validateUpdate(DeviceDTO deviceDTO) {
|
85
|
private void validateUpdate(DeviceDTO deviceDTO) {
|
147
|
if (StringUtils.isAllBlank(deviceDTO.getName())) {
|
86
|
if (StringUtils.isAllBlank(deviceDTO.getName())) {
|
|
@@ -188,16 +127,19 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
|
@@ -188,16 +127,19 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
188
|
return changed;
|
127
|
return changed;
|
189
|
}
|
128
|
}
|
190
|
|
129
|
|
191
|
- private void validateDeviceDTO(String tenantId,DeviceDTO deviceDTO, boolean insert) {
|
130
|
+ @Override
|
|
|
131
|
+ public boolean validateFormdata(DeviceDTO deviceDTO) {
|
|
|
132
|
+ boolean insert = StringUtils.isBlank(deviceDTO.getId());
|
|
|
133
|
+ String tenantId = deviceDTO.getTenantId();
|
192
|
if (StringUtils.isBlank(deviceDTO.getName())) {
|
134
|
if (StringUtils.isBlank(deviceDTO.getName())) {
|
193
|
- throw new DataValidationException("device name cannot be black");
|
135
|
+ throw new DataValidationException("device name cannot be blank");
|
194
|
}
|
136
|
}
|
195
|
// validate IOT DB
|
137
|
// validate IOT DB
|
196
|
if (StringUtils.isBlank(deviceDTO.getProfileId())) {
|
138
|
if (StringUtils.isBlank(deviceDTO.getProfileId())) {
|
197
|
- throw new DataValidationException("device profile cannot be black");
|
139
|
+ throw new DataValidationException("device profile cannot be blank");
|
198
|
}
|
140
|
}
|
199
|
if (StringUtils.isBlank(deviceDTO.getDeviceToken()) && !insert) {
|
141
|
if (StringUtils.isBlank(deviceDTO.getDeviceToken()) && !insert) {
|
200
|
- throw new DataValidationException("device token cannot be black");
|
142
|
+ throw new DataValidationException("device token cannot be blank");
|
201
|
}
|
143
|
}
|
202
|
// 验证设备名称是否已经存在 如果此处直接使用deviceDTO 将有误
|
144
|
// 验证设备名称是否已经存在 如果此处直接使用deviceDTO 将有误
|
203
|
if (insert) {
|
145
|
if (insert) {
|
|
@@ -206,68 +148,59 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
|
@@ -206,68 +148,59 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
206
|
if (findDeviceInfo(tenantId,check).size() > 0) {
|
148
|
if (findDeviceInfo(tenantId,check).size() > 0) {
|
207
|
throw new DataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage());
|
149
|
throw new DataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage());
|
208
|
}
|
150
|
}
|
|
|
151
|
+
|
|
|
152
|
+ if (StringUtils.isNotBlank(deviceDTO.getDeviceToken())) {
|
|
|
153
|
+ List<YtDevice> devices =
|
|
|
154
|
+ baseMapper.selectList(
|
|
|
155
|
+ new QueryWrapper<YtDevice>()
|
|
|
156
|
+ .lambda()
|
|
|
157
|
+ .eq(YtDevice::getDeviceToken, deviceDTO.getDeviceToken()));
|
|
|
158
|
+ if (!devices.isEmpty()) {
|
|
|
159
|
+ throw new DataValidationException("设备Device Token已经存在!");
|
|
|
160
|
+ }
|
|
|
161
|
+ }
|
|
|
162
|
+ }else{
|
|
|
163
|
+ YtDevice device = baseMapper.selectById(deviceDTO.getId());
|
|
|
164
|
+ if (!device.getTenantId().equals(tenantId)) {
|
|
|
165
|
+ return false;
|
|
|
166
|
+ }
|
209
|
}
|
167
|
}
|
210
|
// 验证数据profileId的正确性
|
168
|
// 验证数据profileId的正确性
|
211
|
- YtDeviceProfile deviceProfile = deviceProfileMapper.selectById(deviceDTO.getProfileId());
|
169
|
+ TenantId tenant = new TenantId(UUID.fromString(tenantId));
|
|
|
170
|
+ DeviceProfile deviceProfile = deviceProfileDao.findById(tenant,UUID.fromString(deviceDTO.getProfileId()));
|
212
|
Organization organization = organizationMapper.selectById(deviceDTO.getOrganizationId());
|
171
|
Organization organization = organizationMapper.selectById(deviceDTO.getOrganizationId());
|
213
|
if (null == deviceProfile || null == organization) {
|
172
|
if (null == deviceProfile || null == organization) {
|
214
|
throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
173
|
throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
215
|
-// } else if (StringUtils.isEmpty(deviceProfile.getTbProfileId())) {
|
|
|
216
|
-// throw new DataValidationException("tb_device profile is nonexistent");
|
|
|
217
|
- } else if (!deviceProfile
|
|
|
218
|
- .getTenantId()
|
|
|
219
|
- .equals(tenantId)
|
|
|
220
|
- || !organization.getTenantId().equals(tenantId)) {
|
174
|
+ } else if (!organization.getTenantId().equals(tenantId)) {
|
221
|
throw new DataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
|
175
|
throw new DataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage());
|
222
|
}
|
176
|
}
|
|
|
177
|
+ return true;
|
223
|
}
|
178
|
}
|
224
|
|
179
|
|
225
|
- private DeviceDTO insert(String tenantId,DeviceDTO deviceDTO) {
|
|
|
226
|
- validateDeviceDTO(tenantId,deviceDTO, true);
|
|
|
227
|
- if (StringUtils.isNotBlank(deviceDTO.getDeviceToken())) {
|
|
|
228
|
- List<YtDevice> devices =
|
|
|
229
|
- baseMapper.selectList(
|
|
|
230
|
- new QueryWrapper<YtDevice>()
|
|
|
231
|
- .lambda()
|
|
|
232
|
- .eq(YtDevice::getDeviceToken, deviceDTO.getDeviceToken()));
|
|
|
233
|
- if (!devices.isEmpty()) {
|
|
|
234
|
- throw new DataValidationException("设备Device Token已经存在!");
|
|
|
235
|
- }
|
|
|
236
|
- }
|
180
|
+
|
|
|
181
|
+
|
|
|
182
|
+
|
|
|
183
|
+ private DeviceDTO insert(DeviceDTO deviceDTO) {
|
|
|
184
|
+
|
237
|
YtDevice device = new YtDevice();
|
185
|
YtDevice device = new YtDevice();
|
238
|
deviceDTO.copyToEntity(
|
186
|
deviceDTO.copyToEntity(
|
239
|
device,
|
187
|
device,
|
240
|
ModelConstants.TablePropertyMapping.ACTIVE_TIME,
|
188
|
ModelConstants.TablePropertyMapping.ACTIVE_TIME,
|
241
|
ModelConstants.TablePropertyMapping.DEVICE_STATE,
|
189
|
ModelConstants.TablePropertyMapping.DEVICE_STATE,
|
242
|
- ModelConstants.TablePropertyMapping.TB_DEVICE_ID,
|
|
|
243
|
- ModelConstants.TablePropertyMapping.TENANT_CODE,
|
|
|
244
|
ModelConstants.TablePropertyMapping.CREATOR,
|
190
|
ModelConstants.TablePropertyMapping.CREATOR,
|
245
|
ModelConstants.TablePropertyMapping.UPDATER,
|
191
|
ModelConstants.TablePropertyMapping.UPDATER,
|
246
|
ModelConstants.TablePropertyMapping.CREATE_TIME,
|
192
|
ModelConstants.TablePropertyMapping.CREATE_TIME,
|
247
|
ModelConstants.TablePropertyMapping.UPDATE,
|
193
|
ModelConstants.TablePropertyMapping.UPDATE,
|
248
|
ModelConstants.TablePropertyMapping.UPDATE_TIME);
|
194
|
ModelConstants.TablePropertyMapping.UPDATE_TIME);
|
249
|
- device.setTenantId(tenantId);
|
|
|
250
|
- // First insert into TB
|
|
|
251
|
-// if (tbConfig.isEnabled()) {
|
|
|
252
|
-// Device tbDevice = buildTbDeviceFromDeviceDTO(deviceDTO);
|
|
|
253
|
-// try {
|
|
|
254
|
-// Device insertedTbDevice =
|
|
|
255
|
-// tbConnectService.saveDevice(tbDevice, deviceDTO.getDeviceToken()).get();
|
|
|
256
|
-// if (insertedTbDevice == null) {
|
|
|
257
|
-// throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR);
|
|
|
258
|
-// }
|
|
|
259
|
-// // 判断插入的DTO是否设置了deviceToken,如果不存在,获取Tb的deviceToken存入DB
|
|
|
260
|
-// if (StringUtils.isAllBlank(device.getDeviceToken())) {
|
|
|
261
|
-// String deviceTokenFromDB =
|
|
|
262
|
-// tbDBService.getDeviceTokenFromDB(insertedTbDevice.getId().getId());
|
|
|
263
|
-// device.setDeviceToken(deviceTokenFromDB);
|
|
|
264
|
-// }
|
|
|
265
|
-// device.setTbDeviceId(insertedTbDevice.getId().getId());
|
|
|
266
|
-// } catch (InterruptedException | ExecutionException e) {
|
|
|
267
|
-// log.error("insert device into tb error:{}", e.getMessage());
|
|
|
268
|
-// throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR);
|
|
|
269
|
-// }
|
|
|
270
|
-// }
|
195
|
+
|
|
|
196
|
+ // 判断插入的DTO是否设置了deviceToken,如果不存在,获取Tb的deviceToken存入DB
|
|
|
197
|
+ if (StringUtils.isAllBlank(device.getDeviceToken())) {
|
|
|
198
|
+ TenantId tenantId = new TenantId(UUID.fromString(deviceDTO.getTenantId()));
|
|
|
199
|
+ UUID credentialsId = UUID.fromString(deviceDTO.getTbDeviceId());
|
|
|
200
|
+ DeviceCredentials deviceTokenFromDB = deviceCredentialsDao.findById(tenantId,credentialsId);
|
|
|
201
|
+ device.setDeviceToken(deviceTokenFromDB.getCredentialsId());
|
|
|
202
|
+ }
|
|
|
203
|
+
|
271
|
device.setAlarmStatus(0);
|
204
|
device.setAlarmStatus(0);
|
272
|
/** 默认待激活状态 */
|
205
|
/** 默认待激活状态 */
|
273
|
device.setDeviceState(DeviceState.INACTIVE);
|
206
|
device.setDeviceState(DeviceState.INACTIVE);
|
|
@@ -275,40 +208,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
|
@@ -275,40 +208,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
275
|
return device.getDTO(DeviceDTO.class);
|
208
|
return device.getDTO(DeviceDTO.class);
|
276
|
}
|
209
|
}
|
277
|
|
210
|
|
278
|
-// private Device buildTbDeviceFromDeviceDTO(DeviceDTO deviceDTO) {
|
|
|
279
|
-// Device tbDevice = new Device();
|
|
|
280
|
-// if (StringUtils.isNotBlank(deviceDTO.getTbDeviceId())) {
|
|
|
281
|
-// Id id = new Id();
|
|
|
282
|
-// id.setId(deviceDTO.getTbDeviceId());
|
|
|
283
|
-// id.setEntityType(EntityType.DEVICE);
|
|
|
284
|
-// tbDevice.setId(id);
|
|
|
285
|
-// }
|
|
|
286
|
-// Device.AdditionalInfo additionalInfo = new Device.AdditionalInfo();
|
|
|
287
|
-// additionalInfo.setGateway(
|
|
|
288
|
-// Optional.ofNullable(deviceDTO.getDeviceType())
|
|
|
289
|
-// .map(deviceType -> deviceType.equals(DeviceTypeEnum.GATEWAY))
|
|
|
290
|
-// .orElse(false));
|
|
|
291
|
-//
|
|
|
292
|
-// additionalInfo.setDescription(
|
|
|
293
|
-// Optional.ofNullable(deviceDTO.getDeviceInfo())
|
|
|
294
|
-// .map(deviceInfo -> deviceInfo.get("description"))
|
|
|
295
|
-// .map(JsonNode::asText)
|
|
|
296
|
-// .orElse(""));
|
|
|
297
|
-// additionalInfo.setOverwriteActivityTime(false);
|
|
|
298
|
-//
|
|
|
299
|
-// Id deviceProfileId = new Id();
|
|
|
300
|
-// deviceProfileId.setEntityType(EntityType.DEVICE_PROFILE);
|
|
|
301
|
-// DeviceProfile deviceProfile = deviceProfileMapper.selectById(deviceDTO.getProfileId());
|
|
|
302
|
-// deviceProfileId.setId(deviceProfile != null ? deviceProfile.getTbProfileId() : null);
|
|
|
303
|
-//
|
|
|
304
|
-// tbDevice.setAdditionalInfo(additionalInfo);
|
|
|
305
|
-// tbDevice.setCustomerId(null);
|
|
|
306
|
-// tbDevice.setDeviceProfileId(deviceProfileId);
|
|
|
307
|
-// tbDevice.setLabel(deviceDTO.getLabel());
|
|
|
308
|
-// tbDevice.setName(deviceDTO.getName());
|
|
|
309
|
-// tbDevice.setCreatedTime(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli());
|
|
|
310
|
-// return tbDevice;
|
|
|
311
|
-// }
|
211
|
+
|
312
|
|
212
|
|
313
|
@Override
|
213
|
@Override
|
314
|
@Transactional
|
214
|
@Transactional
|
|
@@ -375,7 +275,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
|
@@ -375,7 +275,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
375
|
YtDevice::getDeviceToken,
|
275
|
YtDevice::getDeviceToken,
|
376
|
deviceDTO.getDeviceToken())
|
276
|
deviceDTO.getDeviceToken())
|
377
|
.eq(true, YtDevice::getTenantId, tenantId)
|
277
|
.eq(true, YtDevice::getTenantId, tenantId)
|
378
|
- .like(
|
278
|
+ .eq(
|
379
|
StringUtils.isNotBlank(deviceDTO.getName()),
|
279
|
StringUtils.isNotBlank(deviceDTO.getName()),
|
380
|
YtDevice::getName,
|
280
|
YtDevice::getName,
|
381
|
deviceDTO.getName()));
|
281
|
deviceDTO.getName()));
|