Commit bd4b3f4707085ec68b08ac2965b644552d8a8351
Merge branch '20221201' into 'master'
20221201 See merge request huang/thingsboard3.3.2!145
Showing
7 changed files
with
38 additions
and
19 deletions
@@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.yunteng.dto.TkDeviceScriptDTO; | @@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.yunteng.dto.TkDeviceScriptDTO; | ||
38 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 38 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
39 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 39 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
40 | import org.thingsboard.server.common.msg.queue.ServiceQueue; | 40 | import org.thingsboard.server.common.msg.queue.ServiceQueue; |
41 | +import org.thingsboard.server.common.yunteng.script.YtScriptFactory; | ||
41 | import org.thingsboard.server.common.yunteng.script.YtScriptInvokeService; | 42 | import org.thingsboard.server.common.yunteng.script.YtScriptInvokeService; |
42 | import org.thingsboard.server.common.yunteng.script.YtScriptType; | 43 | import org.thingsboard.server.common.yunteng.script.YtScriptType; |
43 | import org.thingsboard.server.controller.BaseController; | 44 | import org.thingsboard.server.controller.BaseController; |
@@ -73,16 +74,7 @@ public class TkDeviceScriptController extends BaseController { | @@ -73,16 +74,7 @@ public class TkDeviceScriptController extends BaseController { | ||
73 | String tenantId = getCurrentUser().getCurrentTenantId(); | 74 | String tenantId = getCurrentUser().getCurrentTenantId(); |
74 | scriptDTO.setTenantId(tenantId); | 75 | scriptDTO.setTenantId(tenantId); |
75 | scriptService.validateFormdata(scriptDTO, created); | 76 | scriptService.validateFormdata(scriptDTO, created); |
76 | - /** 业务流程 1/3.编辑时同步刷新相关的设备配置 2/3.处理TB业务逻辑 3/3.处理业务平台的业务逻辑 */ | ||
77 | - if (!created) { | ||
78 | - List<DeviceProfileDTO> usedProfiles = ytDeviceProfileService.findDeviceProfile(tenantId, id); | ||
79 | - for (DeviceProfileDTO profile : usedProfiles) { | ||
80 | - DeviceProfile tbDeviceProfile = | ||
81 | - buildTbDeviceProfileFromDeviceProfileDTO( | ||
82 | - profile, scriptDTO.getTenantId(), scriptDTO.getConvertJs()); | ||
83 | - updateTbDeviceProfile(tbDeviceProfile); | ||
84 | - } | ||
85 | - } | 77 | + |
86 | 78 | ||
87 | String creator = getCurrentUser().getCurrentUserId(); | 79 | String creator = getCurrentUser().getCurrentUserId(); |
88 | scriptDTO.setCreator(creator); | 80 | scriptDTO.setCreator(creator); |
@@ -96,9 +88,30 @@ public class TkDeviceScriptController extends BaseController { | @@ -96,9 +88,30 @@ public class TkDeviceScriptController extends BaseController { | ||
96 | public ResponseEntity<Boolean> updateScriptStatus( | 88 | public ResponseEntity<Boolean> updateScriptStatus( |
97 | @PathVariable("id") String id, @PathVariable("status") Integer status) | 89 | @PathVariable("id") String id, @PathVariable("status") Integer status) |
98 | throws ThingsboardException { | 90 | throws ThingsboardException { |
91 | + /** 业务流程 1/3.编辑时同步刷新相关的设备配置 2/3.处理TB业务逻辑 3/3.处理业务平台的业务逻辑 */ | ||
92 | + String tenantId = getCurrentUser().getCurrentTenantId(); | ||
93 | + TkDeviceScriptDTO scriptDTO = scriptService.getDeviceScript(tenantId,id).get(); | ||
94 | + if(scriptDTO ==null || scriptDTO.getStatus().equals(status)){ | ||
95 | + return ResponseEntity.ok(false); | ||
96 | + } | ||
97 | + String convertJs = YtScriptFactory.INCLUD_ORIGINAL_DATA; | ||
99 | 98 | ||
100 | - return ResponseEntity.ok( | ||
101 | - scriptService.updateScriptStatus(getCurrentUser().getCurrentTenantId(), id, status)); | 99 | + if(1 == status){ |
100 | + if(scriptDTO.isSaveOriginalData()){ | ||
101 | + convertJs += scriptDTO.getConvertJs(); | ||
102 | + }else{ | ||
103 | + convertJs = scriptDTO.getConvertJs(); | ||
104 | + } | ||
105 | + } | ||
106 | + List<DeviceProfileDTO> usedProfiles = ytDeviceProfileService.findDeviceProfile(tenantId, id); | ||
107 | + for (DeviceProfileDTO profile : usedProfiles) { | ||
108 | + DeviceProfile tbDeviceProfile = | ||
109 | + buildTbDeviceProfileFromDeviceProfileDTO( | ||
110 | + profile, tenantId, convertJs); | ||
111 | + updateTbDeviceProfile(tbDeviceProfile); | ||
112 | + } | ||
113 | + scriptService.updateScriptStatus(tenantId, id, status); | ||
114 | + return ResponseEntity.ok(true); | ||
102 | } | 115 | } |
103 | 116 | ||
104 | /** | 117 | /** |
@@ -98,6 +98,7 @@ import org.thingsboard.server.queue.common.TbProtoQueueMsg; | @@ -98,6 +98,7 @@ import org.thingsboard.server.queue.common.TbProtoQueueMsg; | ||
98 | import org.thingsboard.server.queue.util.TbCoreComponent; | 98 | import org.thingsboard.server.queue.util.TbCoreComponent; |
99 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; | 99 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; |
100 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; | 100 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
101 | +import org.thingsboard.server.service.install.DefaultSystemDataLoaderService; | ||
101 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 102 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
102 | import org.thingsboard.server.service.resource.TbResourceService; | 103 | import org.thingsboard.server.service.resource.TbResourceService; |
103 | 104 | ||
@@ -303,7 +304,7 @@ public class DefaultTransportApiService implements TransportApiService { | @@ -303,7 +304,7 @@ public class DefaultTransportApiService implements TransportApiService { | ||
303 | device.setName(requestMsg.getDeviceName()); | 304 | device.setName(requestMsg.getDeviceName()); |
304 | device.setType(requestMsg.getDeviceType()); | 305 | device.setType(requestMsg.getDeviceType()); |
305 | device.setCustomerId(gateway.getCustomerId()); | 306 | device.setCustomerId(gateway.getCustomerId()); |
306 | - DeviceProfile deviceProfile = deviceProfileCache.findOrCreateDeviceProfile(gateway.getTenantId(), requestMsg.getDeviceType()); | 307 | + DeviceProfile deviceProfile = deviceProfileCache.findOrCreateDeviceProfile(gateway.getTenantId(), DefaultSystemDataLoaderService.DEFAULT_DEVICE_TYPE); |
307 | device.setDeviceProfileId(deviceProfile.getId()); | 308 | device.setDeviceProfileId(deviceProfile.getId()); |
308 | ObjectNode additionalInfo = JacksonUtil.newObjectNode(); | 309 | ObjectNode additionalInfo = JacksonUtil.newObjectNode(); |
309 | additionalInfo.put(DataConstants.LAST_CONNECTED_GATEWAY, gatewayId.toString()); | 310 | additionalInfo.put(DataConstants.LAST_CONNECTED_GATEWAY, gatewayId.toString()); |
@@ -312,7 +313,7 @@ public class DefaultTransportApiService implements TransportApiService { | @@ -312,7 +313,7 @@ public class DefaultTransportApiService implements TransportApiService { | ||
312 | 313 | ||
313 | 314 | ||
314 | //Thingskit function | 315 | //Thingskit function |
315 | - ytDeviceService.saveSlaveDevice(savedDevice.getId().getId().toString(), savedDevice.getName(), gateway.getId().getId().toString(),gateway.getCreatedTime()); | 316 | + ytDeviceService.saveSlaveDevice(savedDevice.getId().getId().toString(), savedDevice.getName(),deviceProfile.getId().getId().toString(), gateway.getId().getId().toString(),gateway.getCreatedTime()); |
316 | 317 | ||
317 | 318 | ||
318 | tbClusterService.onDeviceUpdated(savedDevice, null); | 319 | tbClusterService.onDeviceUpdated(savedDevice, null); |
@@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | @@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
26 | import org.thingsboard.server.common.data.yunteng.enums.TcpDataTypeEnum; | 26 | import org.thingsboard.server.common.data.yunteng.enums.TcpDataTypeEnum; |
27 | import org.thingsboard.server.common.transport.auth.TransportDeviceInfo; | 27 | import org.thingsboard.server.common.transport.auth.TransportDeviceInfo; |
28 | import org.thingsboard.server.common.transport.session.DeviceAwareSessionContext; | 28 | import org.thingsboard.server.common.transport.session.DeviceAwareSessionContext; |
29 | +import org.thingsboard.server.common.yunteng.script.YtScriptFactory; | ||
29 | import org.thingsboard.server.gen.transport.TransportProtos; | 30 | import org.thingsboard.server.gen.transport.TransportProtos; |
30 | import org.thingsboard.server.transport.tcp.TcpTransportContext; | 31 | import org.thingsboard.server.transport.tcp.TcpTransportContext; |
31 | import org.thingsboard.server.transport.tcp.adaptors.TcpTransportAdaptor; | 32 | import org.thingsboard.server.transport.tcp.adaptors.TcpTransportAdaptor; |
@@ -122,7 +123,7 @@ public abstract class TcpDeviceWareSessionContext extends DeviceAwareSessionCont | @@ -122,7 +123,7 @@ public abstract class TcpDeviceWareSessionContext extends DeviceAwareSessionCont | ||
122 | this.toDeviceRpcResponseTopicFilter = tcpConfiguration.getRpcTopic(); | 123 | this.toDeviceRpcResponseTopicFilter = tcpConfiguration.getRpcTopic(); |
123 | String scriptBody = tcpConfiguration.getScriptText(); | 124 | String scriptBody = tcpConfiguration.getScriptText(); |
124 | try { | 125 | try { |
125 | - this.scriptId = this.adaptor.getJsScriptEngineFunctionId(scriptBody); | 126 | + this.scriptId = this.adaptor.getJsScriptEngineFunctionId(scriptBody==null? YtScriptFactory.INCLUD_ORIGINAL_DATA:scriptBody); |
126 | } catch (ExecutionException e) { | 127 | } catch (ExecutionException e) { |
127 | log.warn("设备配置【{}】的脚本【{}】解析异常",deviceProfile.getSearchText(),scriptBody); | 128 | log.warn("设备配置【{}】的脚本【{}】解析异常",deviceProfile.getSearchText(),scriptBody); |
128 | throw new RuntimeException(e); | 129 | throw new RuntimeException(e); |
@@ -21,6 +21,7 @@ public class YtScriptFactory { | @@ -21,6 +21,7 @@ public class YtScriptFactory { | ||
21 | 21 | ||
22 | public static final String RULE_NODE_FUNCTION_NAME = "tcpTransportFunc"; | 22 | public static final String RULE_NODE_FUNCTION_NAME = "tcpTransportFunc"; |
23 | 23 | ||
24 | + public static final String INCLUD_ORIGINAL_DATA = "out.source=params;"; | ||
24 | private static final String JS_WRAPPER_PREFIX_TEMPLATE = "function %s(params) { " + | 25 | private static final String JS_WRAPPER_PREFIX_TEMPLATE = "function %s(params) { " + |
25 | " var out = new Object(); " + | 26 | " var out = new Object(); " + |
26 | " return JSON.stringify(%s(params));" + | 27 | " return JSON.stringify(%s(params));" + |
@@ -83,7 +83,7 @@ public class TkDeviceScriptServiceImpl | @@ -83,7 +83,7 @@ public class TkDeviceScriptServiceImpl | ||
83 | @Override | 83 | @Override |
84 | @Transactional | 84 | @Transactional |
85 | public boolean updateScriptStatus(String tenantId, String id, Integer status) { | 85 | public boolean updateScriptStatus(String tenantId, String id, Integer status) { |
86 | - if (StringUtils.isEmpty(tenantId) || StringUtils.isEmpty(id) || null != status) { | 86 | + if (StringUtils.isEmpty(tenantId) || StringUtils.isEmpty(id) || null == status) { |
87 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 87 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
88 | } | 88 | } |
89 | TkDeviceScriptEntity entity = baseMapper.selectById(id); | 89 | TkDeviceScriptEntity entity = baseMapper.selectById(id); |
@@ -44,6 +44,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | @@ -44,6 +44,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | ||
44 | implements TkDeviceService { | 44 | implements TkDeviceService { |
45 | 45 | ||
46 | private final DeviceProfileDao deviceProfileDao; | 46 | private final DeviceProfileDao deviceProfileDao; |
47 | + private final TkDeviceProfileMapper tkProfileMapper; | ||
47 | 48 | ||
48 | private final OrganizationMapper tkOrganizationMapper; | 49 | private final OrganizationMapper tkOrganizationMapper; |
49 | private final SceneLinkageMapper sceneLinkageMapper; | 50 | private final SceneLinkageMapper sceneLinkageMapper; |
@@ -491,7 +492,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | @@ -491,7 +492,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | ||
491 | 492 | ||
492 | @Override | 493 | @Override |
493 | public boolean saveSlaveDevice( | 494 | public boolean saveSlaveDevice( |
494 | - String slaveId, String slaveName, String gatewayId, Long createTime) { | 495 | + String slaveId, String slaveName, String tbProfileId, String gatewayId, Long createTime) { |
495 | LambdaQueryWrapper<TkDeviceEntity> deviceFilter = | 496 | LambdaQueryWrapper<TkDeviceEntity> deviceFilter = |
496 | new QueryWrapper<TkDeviceEntity>().lambda().eq(TkDeviceEntity::getTbDeviceId, gatewayId); | 497 | new QueryWrapper<TkDeviceEntity>().lambda().eq(TkDeviceEntity::getTbDeviceId, gatewayId); |
497 | TkDeviceEntity gateway = baseMapper.selectOne(deviceFilter); | 498 | TkDeviceEntity gateway = baseMapper.selectOne(deviceFilter); |
@@ -505,7 +506,9 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | @@ -505,7 +506,9 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | ||
505 | JacksonUtil.toJsonNode( | 506 | JacksonUtil.toJsonNode( |
506 | "{\"avatar\": \"\",\"longitude\": \"\",\"latitude\": \"\",\"address\": \"\"}")); | 507 | "{\"avatar\": \"\",\"longitude\": \"\",\"latitude\": \"\",\"address\": \"\"}")); |
507 | 508 | ||
508 | - slaveDevice.setProfileId(gateway.getProfileId()); | 509 | + DeviceProfileDTO profileDTO = tkProfileMapper.selectDetail(gateway.getTenantId(),tbProfileId); |
510 | + slaveDevice.setProfileId(profileDTO.getTbProfileId()); | ||
511 | + slaveDevice.setDeviceProfileId(profileDTO.getId()); | ||
509 | slaveDevice.setGatewayId(gateway.getId()); | 512 | slaveDevice.setGatewayId(gateway.getId()); |
510 | slaveDevice.setOrganizationId(gateway.getOrganizationId()); | 513 | slaveDevice.setOrganizationId(gateway.getOrganizationId()); |
511 | slaveDevice.setTenantId(gateway.getTenantId()); | 514 | slaveDevice.setTenantId(gateway.getTenantId()); |
@@ -156,7 +156,7 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> { | @@ -156,7 +156,7 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> { | ||
156 | * @param gatewayId 网关设备TB平台的ID | 156 | * @param gatewayId 网关设备TB平台的ID |
157 | * @return | 157 | * @return |
158 | */ | 158 | */ |
159 | - boolean saveSlaveDevice(String slaveId, String slaveName, String gatewayId, Long createTime); | 159 | + boolean saveSlaveDevice(String slaveId, String slaveName, String tbProfileId,String gatewayId, Long createTime); |
160 | 160 | ||
161 | /** | 161 | /** |
162 | * 通过设备ids查询设备信息列表 | 162 | * 通过设备ids查询设备信息列表 |