|
@@ -24,6 +24,7 @@ import org.thingsboard.server.dao.yunteng.mapper.TkDeviceProfileMapper; |
|
@@ -24,6 +24,7 @@ import org.thingsboard.server.dao.yunteng.mapper.TkDeviceProfileMapper; |
24
|
import org.thingsboard.server.dao.yunteng.mapper.TkDeviceScriptMapper;
|
24
|
import org.thingsboard.server.dao.yunteng.mapper.TkDeviceScriptMapper;
|
25
|
import org.thingsboard.server.dao.yunteng.service.*;
|
25
|
import org.thingsboard.server.dao.yunteng.service.*;
|
26
|
|
26
|
|
|
|
27
|
+import java.time.LocalDateTime;
|
27
|
import java.util.*;
|
28
|
import java.util.*;
|
28
|
import java.util.stream.Collectors;
|
29
|
import java.util.stream.Collectors;
|
29
|
|
30
|
|
|
@@ -80,6 +81,23 @@ public class TkDeviceScriptServiceImpl |
|
@@ -80,6 +81,23 @@ public class TkDeviceScriptServiceImpl |
80
|
}
|
81
|
}
|
81
|
|
82
|
|
82
|
@Override
|
83
|
@Override
|
|
|
84
|
+ @Transactional
|
|
|
85
|
+ public boolean updateScriptStatus(String tenantId, String id, Integer status) {
|
|
|
86
|
+ if (StringUtils.isEmpty(tenantId) || StringUtils.isEmpty(id) || null != status) {
|
|
|
87
|
+ throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
|
|
88
|
+ }
|
|
|
89
|
+ TkDeviceScriptEntity entity = baseMapper.selectById(id);
|
|
|
90
|
+ if (null == entity) {
|
|
|
91
|
+ throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
|
|
92
|
+ }
|
|
|
93
|
+ if (!entity.getTenantId().equals(tenantId)) {
|
|
|
94
|
+ throw new YtDataValidationException(ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage());
|
|
|
95
|
+ }
|
|
|
96
|
+ entity.setStatus(status);
|
|
|
97
|
+ return baseMapper.updateById(entity) > FastIotConstants.MagicNumber.ZERO;
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ @Override
|
83
|
public String getScriptText(String tenantId, String scriptId) {
|
101
|
public String getScriptText(String tenantId, String scriptId) {
|
84
|
LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
|
102
|
LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
|
85
|
new QueryWrapper<TkDeviceScriptEntity>()
|
103
|
new QueryWrapper<TkDeviceScriptEntity>()
|
|
@@ -108,7 +126,7 @@ public class TkDeviceScriptServiceImpl |
|
@@ -108,7 +126,7 @@ public class TkDeviceScriptServiceImpl |
108
|
.lambda()
|
126
|
.lambda()
|
109
|
.in(TkDeviceProfileEntity::getScriptId, ids));
|
127
|
.in(TkDeviceProfileEntity::getScriptId, ids));
|
110
|
if (usedList != null && usedList.size() > 0) {
|
128
|
if (usedList != null && usedList.size() > 0) {
|
111
|
- List<String> names = usedList.stream().map(i -> i.getName()).collect(Collectors.toList());
|
129
|
+ List<String> names = usedList.stream().map(TkDeviceProfileEntity::getName).collect(Collectors.toList());
|
112
|
throw new YtDataValidationException(
|
130
|
throw new YtDataValidationException(
|
113
|
String.format(ErrorMessage.PROJECT_USED_SCRIPT.getMessage(), names));
|
131
|
String.format(ErrorMessage.PROJECT_USED_SCRIPT.getMessage(), names));
|
114
|
}
|
132
|
}
|
|
@@ -169,10 +187,7 @@ public class TkDeviceScriptServiceImpl |
|
@@ -169,10 +187,7 @@ public class TkDeviceScriptServiceImpl |
169
|
TkDeviceScriptEntity profile = baseMapper.selectOne(queryWrapper);
|
187
|
TkDeviceScriptEntity profile = baseMapper.selectOne(queryWrapper);
|
170
|
return Optional.ofNullable(profile)
|
188
|
return Optional.ofNullable(profile)
|
171
|
.map(
|
189
|
.map(
|
172
|
- entity -> {
|
|
|
173
|
- TkDeviceScriptDTO result = entity.getDTO(TkDeviceScriptDTO.class);
|
|
|
174
|
- return result;
|
|
|
175
|
- });
|
190
|
+ entity -> entity.getDTO(TkDeviceScriptDTO.class));
|
176
|
}
|
191
|
}
|
177
|
|
192
|
|
178
|
@Override
|
193
|
@Override
|
|
@@ -188,6 +203,11 @@ public class TkDeviceScriptServiceImpl |
|
@@ -188,6 +203,11 @@ public class TkDeviceScriptServiceImpl |
188
|
Optional.ofNullable(queryMap.get(QueryConstant.CUSTOMER_ID))
|
203
|
Optional.ofNullable(queryMap.get(QueryConstant.CUSTOMER_ID))
|
189
|
.map(Object::toString)
|
204
|
.map(Object::toString)
|
190
|
.orElse(null);
|
205
|
.orElse(null);
|
|
|
206
|
+ String name = Optional.ofNullable(queryMap.get("name")).map(Object::toString).orElse(null);
|
|
|
207
|
+ LocalDateTime startTime =
|
|
|
208
|
+ (LocalDateTime) Optional.ofNullable(queryMap.get("startTime")).orElse(null);
|
|
|
209
|
+ LocalDateTime endTime =
|
|
|
210
|
+ (LocalDateTime) Optional.ofNullable(queryMap.get("endTime")).orElse(null);
|
191
|
Set<String> scriptIds = null;
|
211
|
Set<String> scriptIds = null;
|
192
|
if (!isTenantAdmin && StringUtils.isNotEmpty(customerId)) {
|
212
|
if (!isTenantAdmin && StringUtils.isNotEmpty(customerId)) {
|
193
|
scriptIds = getCustomerScripts(customerId, tenantId);
|
213
|
scriptIds = getCustomerScripts(customerId, tenantId);
|
|
@@ -199,6 +219,12 @@ public class TkDeviceScriptServiceImpl |
|
@@ -199,6 +219,12 @@ public class TkDeviceScriptServiceImpl |
199
|
new QueryWrapper<TkDeviceScriptEntity>()
|
219
|
new QueryWrapper<TkDeviceScriptEntity>()
|
200
|
.lambda()
|
220
|
.lambda()
|
201
|
.eq(TkDeviceScriptEntity::getTenantId, tenantId)
|
221
|
.eq(TkDeviceScriptEntity::getTenantId, tenantId)
|
|
|
222
|
+ .like(StringUtils.isNotEmpty(name), TkDeviceScriptEntity::getName, name)
|
|
|
223
|
+ .and(
|
|
|
224
|
+ null != startTime && null != endTime,
|
|
|
225
|
+ qr ->
|
|
|
226
|
+ qr.ge(TkDeviceScriptEntity::getCreateTime, startTime)
|
|
|
227
|
+ .le(TkDeviceScriptEntity::getCreateTime, endTime))
|
202
|
.in(!isTenantAdmin, TkDeviceScriptEntity::getId, scriptIds);
|
228
|
.in(!isTenantAdmin, TkDeviceScriptEntity::getId, scriptIds);
|
203
|
|
229
|
|
204
|
IPage<TkDeviceScriptEntity> scripts = baseMapper.selectPage(currentPage, queryWrapper);
|
230
|
IPage<TkDeviceScriptEntity> scripts = baseMapper.selectPage(currentPage, queryWrapper);
|
|
@@ -215,11 +241,9 @@ public class TkDeviceScriptServiceImpl |
|
@@ -215,11 +241,9 @@ public class TkDeviceScriptServiceImpl |
215
|
new QueryWrapper<TkDeviceScriptEntity>()
|
241
|
new QueryWrapper<TkDeviceScriptEntity>()
|
216
|
.lambda()
|
242
|
.lambda()
|
217
|
.eq(TkDeviceScriptEntity::getTenantId, tenantId);
|
243
|
.eq(TkDeviceScriptEntity::getTenantId, tenantId);
|
218
|
- List<TkDeviceScriptDTO> results =
|
|
|
219
|
- baseMapper.selectList(queryWrapper).stream()
|
|
|
220
|
- .map(item -> item.getDTO(TkDeviceScriptDTO.class))
|
|
|
221
|
- .collect(Collectors.toList());
|
|
|
222
|
- return results;
|
244
|
+ return baseMapper.selectList(queryWrapper).stream()
|
|
|
245
|
+ .map(item -> item.getDTO(TkDeviceScriptDTO.class))
|
|
|
246
|
+ .collect(Collectors.toList());
|
223
|
}
|
247
|
}
|
224
|
|
248
|
|
225
|
private Set<String> getCustomerScripts(String customerId, String tenantId) {
|
249
|
private Set<String> getCustomerScripts(String customerId, String tenantId) {
|
|
@@ -227,9 +251,9 @@ public class TkDeviceScriptServiceImpl |
|
@@ -227,9 +251,9 @@ public class TkDeviceScriptServiceImpl |
227
|
List<TkCustomerDeviceDTO> list = tkCustomerDevice.getMappingByCustomerId(customerId);
|
251
|
List<TkCustomerDeviceDTO> list = tkCustomerDevice.getMappingByCustomerId(customerId);
|
228
|
if (null != list && !list.isEmpty()) {
|
252
|
if (null != list && !list.isEmpty()) {
|
229
|
Set<String> deviceIds =
|
253
|
Set<String> deviceIds =
|
230
|
- list.stream().map(obj -> obj.getDeviceId()).collect(Collectors.toSet());
|
254
|
+ list.stream().map(TkCustomerDeviceDTO::getDeviceId).collect(Collectors.toSet());
|
231
|
scriptIds =
|
255
|
scriptIds =
|
232
|
- Optional.ofNullable(deviceIds)
|
256
|
+ Optional.of(deviceIds)
|
233
|
.map(
|
257
|
.map(
|
234
|
ids -> {
|
258
|
ids -> {
|
235
|
List<DeviceDTO> deviceDTOS =
|
259
|
List<DeviceDTO> deviceDTOS =
|
|
@@ -237,7 +261,7 @@ public class TkDeviceScriptServiceImpl |
|
@@ -237,7 +261,7 @@ public class TkDeviceScriptServiceImpl |
237
|
if (null != deviceDTOS && !deviceDTOS.isEmpty()) {
|
261
|
if (null != deviceDTOS && !deviceDTOS.isEmpty()) {
|
238
|
List<String> deviceProfiles =
|
262
|
List<String> deviceProfiles =
|
239
|
deviceDTOS.stream()
|
263
|
deviceDTOS.stream()
|
240
|
- .map(obj -> obj.getDeviceProfileId())
|
264
|
+ .map(DeviceDTO::getDeviceProfileId)
|
241
|
.collect(Collectors.toList());
|
265
|
.collect(Collectors.toList());
|
242
|
List<DeviceProfileDTO> deviceProfileDTOList =
|
266
|
List<DeviceProfileDTO> deviceProfileDTOList =
|
243
|
tkDeviceProfileService.findDeviceProfileByIds(tenantId, deviceProfiles);
|
267
|
tkDeviceProfileService.findDeviceProfileByIds(tenantId, deviceProfiles);
|
|
@@ -245,7 +269,7 @@ public class TkDeviceScriptServiceImpl |
|
@@ -245,7 +269,7 @@ public class TkDeviceScriptServiceImpl |
245
|
.map(
|
269
|
.map(
|
246
|
deviceProfileDTOS ->
|
270
|
deviceProfileDTOS ->
|
247
|
deviceProfileDTOS.stream()
|
271
|
deviceProfileDTOS.stream()
|
248
|
- .map(obj -> obj.getScriptId())
|
272
|
+ .map(DeviceProfileDTO::getScriptId)
|
249
|
.collect(Collectors.toSet()))
|
273
|
.collect(Collectors.toSet()))
|
250
|
.orElse(null);
|
274
|
.orElse(null);
|
251
|
}
|
275
|
}
|