Showing
5 changed files
with
69 additions
and
71 deletions
... | ... | @@ -41,31 +41,13 @@ import org.thingsboard.server.common.data.edge.EdgeEventType; |
41 | 41 | import org.thingsboard.server.common.data.edge.EdgeInfo; |
42 | 42 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
43 | 43 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
44 | -import org.thingsboard.server.common.data.id.AlarmId; | |
45 | -import org.thingsboard.server.common.data.id.AssetId; | |
46 | -import org.thingsboard.server.common.data.id.CustomerId; | |
47 | -import org.thingsboard.server.common.data.id.DashboardId; | |
48 | -import org.thingsboard.server.common.data.id.DeviceId; | |
49 | -import org.thingsboard.server.common.data.id.DeviceProfileId; | |
50 | -import org.thingsboard.server.common.data.id.EdgeId; | |
51 | -import org.thingsboard.server.common.data.id.EntityId; | |
52 | -import org.thingsboard.server.common.data.id.EntityIdFactory; | |
53 | -import org.thingsboard.server.common.data.id.EntityViewId; | |
54 | -import org.thingsboard.server.common.data.id.OtaPackageId; | |
55 | -import org.thingsboard.server.common.data.id.RpcId; | |
56 | -import org.thingsboard.server.common.data.id.RuleChainId; | |
57 | -import org.thingsboard.server.common.data.id.RuleNodeId; | |
58 | -import org.thingsboard.server.common.data.id.TbResourceId; | |
59 | -import org.thingsboard.server.common.data.id.TenantId; | |
60 | -import org.thingsboard.server.common.data.id.TenantProfileId; | |
61 | -import org.thingsboard.server.common.data.id.UserId; | |
62 | -import org.thingsboard.server.common.data.id.WidgetTypeId; | |
63 | -import org.thingsboard.server.common.data.id.WidgetsBundleId; | |
44 | +import org.thingsboard.server.common.data.id.*; | |
64 | 45 | import org.thingsboard.server.common.data.page.PageDataIterableByTenantIdEntityId; |
65 | 46 | import org.thingsboard.server.common.data.page.PageLink; |
66 | 47 | import org.thingsboard.server.common.data.page.SortOrder; |
67 | 48 | import org.thingsboard.server.common.data.page.TimePageLink; |
68 | 49 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
50 | +import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | |
69 | 51 | import org.thingsboard.server.common.data.plugin.ComponentType; |
70 | 52 | import org.thingsboard.server.common.data.relation.EntityRelation; |
71 | 53 | import org.thingsboard.server.common.data.rpc.Rpc; |
... | ... | @@ -74,6 +56,9 @@ import org.thingsboard.server.common.data.rule.RuleChainType; |
74 | 56 | import org.thingsboard.server.common.data.rule.RuleNode; |
75 | 57 | import org.thingsboard.server.common.data.widget.WidgetTypeDetails; |
76 | 58 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
59 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
60 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
61 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
77 | 62 | import org.thingsboard.server.dao.asset.AssetService; |
78 | 63 | import org.thingsboard.server.dao.attributes.AttributesService; |
79 | 64 | import org.thingsboard.server.dao.audit.AuditLogService; |
... | ... | @@ -121,12 +106,7 @@ import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
121 | 106 | |
122 | 107 | import javax.mail.MessagingException; |
123 | 108 | import javax.servlet.http.HttpServletResponse; |
124 | -import java.util.ArrayList; | |
125 | -import java.util.Collections; | |
126 | -import java.util.List; | |
127 | -import java.util.Optional; | |
128 | -import java.util.Set; | |
129 | -import java.util.UUID; | |
109 | +import java.util.*; | |
130 | 110 | |
131 | 111 | import static org.thingsboard.server.controller.ControllerConstants.DEFAULT_PAGE_SIZE; |
132 | 112 | import static org.thingsboard.server.controller.ControllerConstants.INCORRECT_TENANT_ID; |
... | ... | @@ -929,4 +909,45 @@ public abstract class BaseController { |
929 | 909 | return deviceProfileData; |
930 | 910 | |
931 | 911 | } |
912 | + | |
913 | + | |
914 | + /** | |
915 | + * 更新thingsboard的设备配置信息 | |
916 | + * | |
917 | + * @param deviceProfile 设备配置 | |
918 | + * @throws ThingsboardException | |
919 | + */ | |
920 | + protected DeviceProfile updateTbDeviceProfile(DeviceProfile deviceProfile) | |
921 | + throws ThingsboardException { | |
922 | + boolean isFirmwareChanged = false; | |
923 | + boolean isSoftwareChanged = false; | |
924 | + | |
925 | + DeviceProfile oldDeviceProfile = | |
926 | + deviceProfileService.findDeviceProfileById(getTenantId(), deviceProfile.getId()); | |
927 | + if (!Objects.equals(deviceProfile.getFirmwareId(), oldDeviceProfile.getFirmwareId())) { | |
928 | + isFirmwareChanged = true; | |
929 | + } | |
930 | + if (!Objects.equals(deviceProfile.getSoftwareId(), oldDeviceProfile.getSoftwareId())) { | |
931 | + isSoftwareChanged = true; | |
932 | + } | |
933 | + if (FastIotConstants.ASSERT_DEFAULT_NAME.equals(oldDeviceProfile.getName()) | |
934 | + && !Objects.equals(deviceProfile.getName(), oldDeviceProfile.getName())) { | |
935 | + throw new TkDataValidationException(ErrorMessage.ASSERT_DEFAULT_NAME_NO_CHANGED.getMessage()); | |
936 | + } | |
937 | + | |
938 | + DeviceProfile savedDeviceProfile = | |
939 | + checkNotNull(deviceProfileService.saveDeviceProfile(deviceProfile)); | |
940 | + | |
941 | + tbClusterService.onDeviceProfileChange(savedDeviceProfile, null); | |
942 | + tbClusterService.broadcastEntityStateChangeEvent( | |
943 | + deviceProfile.getTenantId(), savedDeviceProfile.getId(), ComponentLifecycleEvent.UPDATED); | |
944 | + | |
945 | + logEntityAction(savedDeviceProfile.getId(), savedDeviceProfile, null, ActionType.UPDATED, null); | |
946 | + | |
947 | + otaPackageStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged); | |
948 | + | |
949 | + sendEntityNotificationMsg( | |
950 | + getTenantId(), savedDeviceProfile.getId(), EdgeEventActionType.UPDATED); | |
951 | + return savedDeviceProfile; | |
952 | + } | |
932 | 953 | } | ... | ... |
... | ... | @@ -9,6 +9,8 @@ import org.springframework.http.ResponseEntity; |
9 | 9 | import org.springframework.security.access.prepost.PreAuthorize; |
10 | 10 | import org.springframework.validation.annotation.Validated; |
11 | 11 | import org.springframework.web.bind.annotation.*; |
12 | +import org.thingsboard.server.common.data.DeviceProfile; | |
13 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileData; | |
12 | 14 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
13 | 15 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
14 | 16 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
... | ... | @@ -21,6 +23,7 @@ import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO; |
21 | 23 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
22 | 24 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
23 | 25 | import org.thingsboard.server.common.data.yunteng.enums.StatusEnum; |
26 | +import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; | |
24 | 27 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
25 | 28 | import org.thingsboard.server.controller.BaseController; |
26 | 29 | import org.thingsboard.server.dao.yunteng.service.ThingsModelService; |
... | ... | @@ -119,9 +122,12 @@ public class ThingsModelController extends BaseController { |
119 | 122 | if (null == dto) { |
120 | 123 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
121 | 124 | } |
122 | - return ResponseEntity.ok( | |
123 | - thingsModelService.changeTSLStatus( | |
124 | - deviceProfileId, tenantId, StatusEnum.ENABLE.getIndex())); | |
125 | + List<ThingsModelDTO> thingsModels = thingsModelService.changeTSLStatus(deviceProfileId, tenantId, StatusEnum.ENABLE.getIndex()); | |
126 | + DeviceProfileData profileData = dto.getProfileData(); | |
127 | + profileData.setThingsModel(thingsModels); | |
128 | + dto.setProfileData(profileData); | |
129 | + updateTbDeviceProfile(JacksonUtil.convertValue(dto, DeviceProfile.class)); | |
130 | + return ResponseEntity.ok(true); | |
125 | 131 | } |
126 | 132 | |
127 | 133 | @GetMapping("/get_services/{deviceProfileId}") | ... | ... |
... | ... | @@ -114,45 +114,6 @@ public class TkDeviceScriptController extends BaseController { |
114 | 114 | return ResponseEntity.ok(true); |
115 | 115 | } |
116 | 116 | |
117 | - /** | |
118 | - * 更新thingsboard的设备配置信息 | |
119 | - * | |
120 | - * @param deviceProfile 设备配置 | |
121 | - * @throws ThingsboardException | |
122 | - */ | |
123 | - private DeviceProfile updateTbDeviceProfile(DeviceProfile deviceProfile) | |
124 | - throws ThingsboardException { | |
125 | - boolean isFirmwareChanged = false; | |
126 | - boolean isSoftwareChanged = false; | |
127 | - | |
128 | - DeviceProfile oldDeviceProfile = | |
129 | - deviceProfileService.findDeviceProfileById(getTenantId(), deviceProfile.getId()); | |
130 | - if (!Objects.equals(deviceProfile.getFirmwareId(), oldDeviceProfile.getFirmwareId())) { | |
131 | - isFirmwareChanged = true; | |
132 | - } | |
133 | - if (!Objects.equals(deviceProfile.getSoftwareId(), oldDeviceProfile.getSoftwareId())) { | |
134 | - isSoftwareChanged = true; | |
135 | - } | |
136 | - if (FastIotConstants.ASSERT_DEFAULT_NAME.equals(oldDeviceProfile.getName()) | |
137 | - && !Objects.equals(deviceProfile.getName(), oldDeviceProfile.getName())) { | |
138 | - throw new TkDataValidationException(ErrorMessage.ASSERT_DEFAULT_NAME_NO_CHANGED.getMessage()); | |
139 | - } | |
140 | - | |
141 | - DeviceProfile savedDeviceProfile = | |
142 | - checkNotNull(deviceProfileService.saveDeviceProfile(deviceProfile)); | |
143 | - | |
144 | - tbClusterService.onDeviceProfileChange(savedDeviceProfile, null); | |
145 | - tbClusterService.broadcastEntityStateChangeEvent( | |
146 | - deviceProfile.getTenantId(), savedDeviceProfile.getId(), ComponentLifecycleEvent.UPDATED); | |
147 | - | |
148 | - logEntityAction(savedDeviceProfile.getId(), savedDeviceProfile, null, ActionType.UPDATED, null); | |
149 | - | |
150 | - otaPackageStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged); | |
151 | - | |
152 | - sendEntityNotificationMsg( | |
153 | - getTenantId(), savedDeviceProfile.getId(), EdgeEventActionType.UPDATED); | |
154 | - return savedDeviceProfile; | |
155 | - } | |
156 | 117 | |
157 | 118 | @GetMapping("{id}") |
158 | 119 | @ApiOperation("详情") | ... | ... |
... | ... | @@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils; |
8 | 8 | import org.springframework.beans.BeanUtils; |
9 | 9 | import org.springframework.stereotype.Service; |
10 | 10 | import org.springframework.transaction.annotation.Transactional; |
11 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileData; | |
11 | 12 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
12 | 13 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
13 | 14 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
... | ... | @@ -195,8 +196,16 @@ public class ThingsModelServiceImpl |
195 | 196 | |
196 | 197 | @Override |
197 | 198 | @Transactional |
198 | - public boolean changeTSLStatus(String deviceProfileId, String tenantId, Integer status) { | |
199 | - return baseMapper.changeTSLStatus(deviceProfileId, tenantId, status); | |
199 | + public List<ThingsModelDTO> changeTSLStatus(String deviceProfileId, String tenantId, Integer status) { | |
200 | + boolean result = baseMapper.changeTSLStatus(deviceProfileId, tenantId, status); | |
201 | + if(result){ | |
202 | + List<TkThingsModelEntity> entityList = baseMapper.selectList(new LambdaQueryWrapper<TkThingsModelEntity>().eq(TkThingsModelEntity::getDeviceProfileId,deviceProfileId)); | |
203 | + if (entityList.isEmpty()) { | |
204 | + return null; | |
205 | + } | |
206 | + return entityList.stream().map(en -> en.getDTO(ThingsModelDTO.class)).collect(Collectors.toList()); | |
207 | + } | |
208 | + return null; | |
200 | 209 | } |
201 | 210 | |
202 | 211 | private boolean checkIdentifier( | ... | ... |
... | ... | @@ -5,6 +5,7 @@ import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
5 | 5 | import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO; |
6 | 6 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
7 | 7 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
8 | +import org.thingsboard.server.dao.yunteng.entities.TkThingsModelEntity; | |
8 | 9 | |
9 | 10 | import java.util.List; |
10 | 11 | import java.util.Map; |
... | ... | @@ -26,5 +27,5 @@ public interface ThingsModelService { |
26 | 27 | |
27 | 28 | JsonNode getTingsModelTSL(FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId); |
28 | 29 | |
29 | - boolean changeTSLStatus(String deviceProfileId, String tenantId, Integer status); | |
30 | + List<ThingsModelDTO> changeTSLStatus(String deviceProfileId, String tenantId, Integer status); | |
30 | 31 | } | ... | ... |