Showing
4 changed files
with
19 additions
and
17 deletions
... | ... | @@ -17,6 +17,7 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; |
17 | 17 | import org.thingsboard.server.common.data.id.TenantId; |
18 | 18 | import org.thingsboard.server.common.data.id.UserId; |
19 | 19 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
20 | +import org.thingsboard.server.common.data.rule.RuleChain; | |
20 | 21 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
21 | 22 | import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; |
22 | 23 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
... | ... | @@ -25,11 +26,13 @@ import org.thingsboard.server.common.data.yunteng.dto.MenuDTO; |
25 | 26 | import org.thingsboard.server.common.data.yunteng.dto.TenantDTO; |
26 | 27 | import org.thingsboard.server.common.data.yunteng.dto.UserDTO; |
27 | 28 | import org.thingsboard.server.common.data.yunteng.dto.request.TenantReqDTO; |
29 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | |
28 | 30 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
29 | 31 | import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils; |
30 | 32 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
31 | 33 | import org.thingsboard.server.controller.BaseController; |
32 | 34 | import org.thingsboard.server.dao.exception.DataValidationException; |
35 | +import org.thingsboard.server.dao.rule.RuleChainService; | |
33 | 36 | import org.thingsboard.server.dao.tenant.TenantService; |
34 | 37 | import org.thingsboard.server.dao.yunteng.service.MenuService; |
35 | 38 | import org.thingsboard.server.dao.yunteng.service.TkTenantService; |
... | ... | @@ -65,6 +68,7 @@ public class TkAdminController extends BaseController { |
65 | 68 | private final InstallScripts installScripts; |
66 | 69 | private final TbUserService tbUserService; |
67 | 70 | private final TbTenantService tbTenantService; |
71 | + private final RuleChainService ruleChainService; | |
68 | 72 | |
69 | 73 | @PostMapping("/tenant") |
70 | 74 | @Deprecated |
... | ... | @@ -286,6 +290,11 @@ public class TkAdminController extends BaseController { |
286 | 290 | installScripts.createDefaultRuleChains(tbTenant.getId()); |
287 | 291 | installScripts.createDefaultEdgeRuleChains(tbTenant.getId()); |
288 | 292 | } |
293 | + //Thingskit function | |
294 | + RuleChain ruleChain =ruleChainService.getRootTenantRuleChain(tbTenant.getId()); | |
295 | + deviceProfileService.createDeviceProfile(tbTenant.getId(),"默认MQTT网关设备", DeviceTypeEnum.GATEWAY,ruleChain.getId()); | |
296 | + deviceProfileService.createDeviceProfile(tbTenant.getId(),"默认MQTT直连设备", DeviceTypeEnum.DIRECT_CONNECTION,ruleChain.getId()); | |
297 | + | |
289 | 298 | tenantProfileCache.evict(tbTenant.getId()); |
290 | 299 | tbClusterService.onTenantChange(tbTenant, null); |
291 | 300 | tbClusterService.broadcastEntityStateChangeEvent( | ... | ... |
... | ... | @@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.DeviceProfile; |
20 | 20 | import org.thingsboard.server.common.data.DeviceProfileInfo; |
21 | 21 | import org.thingsboard.server.common.data.EntityInfo; |
22 | 22 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
23 | +import org.thingsboard.server.common.data.id.RuleChainId; | |
23 | 24 | import org.thingsboard.server.common.data.id.TenantId; |
24 | 25 | import org.thingsboard.server.common.data.page.PageData; |
25 | 26 | import org.thingsboard.server.common.data.page.PageLink; |
... | ... | @@ -57,7 +58,7 @@ public interface DeviceProfileService extends EntityDaoService { |
57 | 58 | DeviceProfile createDefaultDeviceProfile(TenantId tenantId); |
58 | 59 | |
59 | 60 | //thingskit |
60 | - DeviceProfile createDeviceProfile(TenantId tenantId, String name, DeviceTypeEnum deviceType); | |
61 | + DeviceProfile createDeviceProfile(TenantId tenantId, String name, DeviceTypeEnum deviceType, RuleChainId ruleChainId); | |
61 | 62 | |
62 | 63 | ListenableFuture<List<DeviceProfile>> findByDataCombinationIsTrue(); |
63 | 64 | ... | ... |
... | ... | @@ -37,10 +37,7 @@ import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTra |
37 | 37 | import org.thingsboard.server.common.data.device.profile.DeviceProfileData; |
38 | 38 | import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration; |
39 | 39 | import org.thingsboard.server.common.data.device.profile.X509CertificateChainProvisionConfiguration; |
40 | -import org.thingsboard.server.common.data.id.DeviceProfileId; | |
41 | -import org.thingsboard.server.common.data.id.EntityId; | |
42 | -import org.thingsboard.server.common.data.id.HasId; | |
43 | -import org.thingsboard.server.common.data.id.TenantId; | |
40 | +import org.thingsboard.server.common.data.id.*; | |
44 | 41 | import org.thingsboard.server.common.data.page.PageData; |
45 | 42 | import org.thingsboard.server.common.data.page.PageLink; |
46 | 43 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
... | ... | @@ -277,7 +274,7 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device |
277 | 274 | DeviceProfile deviceProfile = findDeviceProfileByName(tenantId, name, false); |
278 | 275 | if (deviceProfile == null) { |
279 | 276 | try { |
280 | - deviceProfile = this.doCreateDefaultDeviceProfile(tenantId, name, name.equals("default"), DeviceTypeEnum.SENSOR); | |
277 | + deviceProfile = this.doCreateDefaultDeviceProfile(tenantId, name, name.equals("default"), DeviceTypeEnum.SENSOR,null); | |
281 | 278 | } catch (DataValidationException e) { |
282 | 279 | if (DEVICE_PROFILE_WITH_SUCH_NAME_ALREADY_EXISTS.equals(e.getMessage())) { |
283 | 280 | deviceProfile = findDeviceProfileByName(tenantId, name, false); |
... | ... | @@ -292,13 +289,13 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device |
292 | 289 | @Override |
293 | 290 | public DeviceProfile createDefaultDeviceProfile(TenantId tenantId) { |
294 | 291 | log.trace("Executing createDefaultDeviceProfile tenantId [{}]", tenantId); |
295 | - return doCreateDefaultDeviceProfile(tenantId, "default", true, DeviceTypeEnum.SENSOR); | |
292 | + return doCreateDefaultDeviceProfile(tenantId, "default", true, DeviceTypeEnum.SENSOR,null); | |
296 | 293 | } |
297 | 294 | //thingskit |
298 | 295 | @Override |
299 | - public DeviceProfile createDeviceProfile(TenantId tenantId, String name, DeviceTypeEnum deviceType) { | |
296 | + public DeviceProfile createDeviceProfile(TenantId tenantId, String name, DeviceTypeEnum deviceType, RuleChainId ruleChainId) { | |
300 | 297 | log.trace("Executing createDeviceProfile tenantId [{}]", tenantId); |
301 | - return doCreateDefaultDeviceProfile(tenantId, name, false,deviceType); | |
298 | + return doCreateDefaultDeviceProfile(tenantId, name, false,deviceType,ruleChainId); | |
302 | 299 | } |
303 | 300 | |
304 | 301 | @Override |
... | ... | @@ -306,7 +303,7 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device |
306 | 303 | return deviceProfileDao.findByDataCombinationIsTrue(); |
307 | 304 | } |
308 | 305 | |
309 | - private DeviceProfile doCreateDefaultDeviceProfile(TenantId tenantId, String profileName, boolean defaultProfile, DeviceTypeEnum deviceType) { | |
306 | + private DeviceProfile doCreateDefaultDeviceProfile(TenantId tenantId, String profileName, boolean defaultProfile, DeviceTypeEnum deviceType, RuleChainId ruleChainId) { | |
310 | 307 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
311 | 308 | DeviceProfile deviceProfile = new DeviceProfile(); |
312 | 309 | deviceProfile.setTenantId(tenantId); |
... | ... | @@ -319,6 +316,7 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device |
319 | 316 | |
320 | 317 | //thingsKit:begin |
321 | 318 | deviceProfile.setDeviceType(deviceType); |
319 | + deviceProfile.setDefaultRuleChainId(ruleChainId); | |
322 | 320 | //thingsKit:end |
323 | 321 | |
324 | 322 | DeviceProfileData deviceProfileData = new DeviceProfileData(); | ... | ... |
... | ... | @@ -184,7 +184,7 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten |
184 | 184 | |
185 | 185 | @Override |
186 | 186 | @Transactional |
187 | - public Tenant saveTenant(Tenant tenant) { | |
187 | + public Tenant saveTenant(Tenant tenant) { | |
188 | 188 | log.trace("Executing saveTenant [{}]", tenant); |
189 | 189 | tenant.setRegion(DEFAULT_TENANT_REGION); |
190 | 190 | if (tenant.getTenantProfileId() == null) { |
... | ... | @@ -199,12 +199,6 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten |
199 | 199 | if (tenant.getId() == null) { |
200 | 200 | deviceProfileService.createDefaultDeviceProfile(savedTenant.getId()); |
201 | 201 | assetProfileService.createDefaultAssetProfile(savedTenant.getId()); |
202 | - //Thingskit function | |
203 | - deviceProfileService.createDeviceProfile(savedTenant.getId(),"默认MQTT网关设备", DeviceTypeEnum.GATEWAY); | |
204 | - deviceProfileService.createDeviceProfile(savedTenant.getId(),"默认MQTT直连设备", DeviceTypeEnum.DIRECT_CONNECTION); | |
205 | - | |
206 | - | |
207 | - | |
208 | 202 | apiUsageStateService.createDefaultApiUsageState(savedTenant.getId(), null); |
209 | 203 | try { |
210 | 204 | notificationSettingsService.createDefaultNotificationConfigs(savedTenant.getId()); | ... | ... |