Commit a3ac0ee6d736fbb52833a6a8e8b8a9ba393bef15
1 parent
8ae8e53c
fix: add release TSL and fix thingsModel some bug
Showing
10 changed files
with
114 additions
and
27 deletions
... | ... | @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; |
4 | 4 | import io.swagger.annotations.Api; |
5 | 5 | import io.swagger.annotations.ApiOperation; |
6 | 6 | import lombok.RequiredArgsConstructor; |
7 | +import org.apache.commons.lang3.StringUtils; | |
7 | 8 | import org.springframework.http.ResponseEntity; |
8 | 9 | import org.springframework.validation.annotation.Validated; |
9 | 10 | import org.springframework.web.bind.annotation.*; |
... | ... | @@ -18,6 +19,7 @@ import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
18 | 19 | import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO; |
19 | 20 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
20 | 21 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
22 | +import org.thingsboard.server.common.data.yunteng.enums.StatusEnum; | |
21 | 23 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
22 | 24 | import org.thingsboard.server.controller.BaseController; |
23 | 25 | import org.thingsboard.server.dao.yunteng.service.ThingsModelService; |
... | ... | @@ -97,6 +99,20 @@ public class ThingsModelController extends BaseController { |
97 | 99 | functionType, getCurrentUser().getCurrentTenantId(), deviceProfileId)); |
98 | 100 | } |
99 | 101 | |
102 | + @PutMapping("/{deviceProfileId}") | |
103 | + @ApiOperation("物模型发布") | |
104 | + public ResponseEntity<Boolean> releaseTSL(@PathVariable("deviceProfileId") String deviceProfileId) | |
105 | + throws ThingsboardException { | |
106 | + String tenantId = getCurrentUser().getCurrentTenantId(); | |
107 | + DeviceProfileDTO dto = ytDeviceProfileService.findDeviceProfileById(tenantId, deviceProfileId); | |
108 | + if (null == dto) { | |
109 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
110 | + } | |
111 | + return ResponseEntity.ok( | |
112 | + thingsModelService.changeTSLStatus( | |
113 | + deviceProfileId, tenantId, StatusEnum.ENABLE.getIndex())); | |
114 | + } | |
115 | + | |
100 | 116 | private ThingsModelDTO saveOrUpdate(ThingsModelDTO thingsModelDTO) throws ThingsboardException { |
101 | 117 | |
102 | 118 | String tenantId = getCurrentUser().getCurrentTenantId(); | ... | ... |
... | ... | @@ -7,6 +7,8 @@ import lombok.Data; |
7 | 7 | import lombok.EqualsAndHashCode; |
8 | 8 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
9 | 9 | import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; |
10 | +import org.thingsboard.server.common.data.yunteng.enums.CallTypeEnum; | |
11 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceEventTypeEnum; | |
10 | 12 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
11 | 13 | |
12 | 14 | import javax.validation.constraints.NotEmpty; |
... | ... | @@ -34,12 +36,24 @@ public class ThingsModelDTO extends TenantDTO { |
34 | 36 | @ApiModelProperty("功能标识") |
35 | 37 | private String identifier; |
36 | 38 | |
39 | + @ApiModelProperty("调用方式:同步sync 异步async") | |
40 | + private CallTypeEnum callType; | |
41 | + | |
42 | + @ApiModelProperty("读写模式:读r 写w") | |
43 | + private String accessMode; | |
44 | + | |
45 | + @ApiModelProperty("事件类型:信息info 告警alert 故障error") | |
46 | + private DeviceEventTypeEnum eventType; | |
47 | + | |
37 | 48 | @ApiModelProperty("功能json") |
38 | 49 | @NotNull( |
39 | 50 | message = "功能json不能为空", |
40 | 51 | groups = {AddGroup.class}) |
41 | 52 | private JsonNode functionJson; |
42 | 53 | |
54 | + @ApiModelProperty("状态:0待发布 1发布") | |
55 | + private Integer status; | |
56 | + | |
43 | 57 | @ApiModelProperty("设备配置ID") |
44 | 58 | @NotEmpty( |
45 | 59 | message = "设备配置ID不能为空或空字符串", | ... | ... |
... | ... | @@ -8,6 +8,8 @@ import lombok.Data; |
8 | 8 | import lombok.EqualsAndHashCode; |
9 | 9 | import org.apache.ibatis.type.EnumTypeHandler; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
11 | +import org.thingsboard.server.common.data.yunteng.enums.CallTypeEnum; | |
12 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceEventTypeEnum; | |
11 | 13 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
12 | 14 | |
13 | 15 | @Data |
... | ... | @@ -19,10 +21,14 @@ public class TkThingsModelEntity extends TenantBaseEntity { |
19 | 21 | |
20 | 22 | @TableField(typeHandler = EnumTypeHandler.class) |
21 | 23 | private FunctionTypeEnum functionType; |
22 | - | |
24 | + @TableField(typeHandler = EnumTypeHandler.class) | |
25 | + private CallTypeEnum callType; | |
26 | + private String accessMode; | |
27 | + @TableField(typeHandler = EnumTypeHandler.class) | |
28 | + private DeviceEventTypeEnum eventType; | |
23 | 29 | private String functionName; |
24 | 30 | private String identifier; |
25 | - | |
31 | + private Integer status; | |
26 | 32 | @TableField(typeHandler = JacksonTypeHandler.class) |
27 | 33 | private JsonNode functionJson; |
28 | 34 | ... | ... |
... | ... | @@ -17,6 +17,7 @@ import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO; |
17 | 17 | import org.thingsboard.server.common.data.yunteng.enums.DataTypeEnum; |
18 | 18 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
19 | 19 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
20 | +import org.thingsboard.server.common.data.yunteng.enums.StatusEnum; | |
20 | 21 | import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; |
21 | 22 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
22 | 23 | import org.thingsboard.server.dao.yunteng.entities.TkThingsModelEntity; |
... | ... | @@ -70,6 +71,7 @@ public class ThingsModelServiceImpl |
70 | 71 | } |
71 | 72 | TkThingsModelEntity entity = thingsModelDTO.getEntity(TkThingsModelEntity.class); |
72 | 73 | if (isAdd) { |
74 | + entity.setStatus(StatusEnum.DISABLE.getIndex()); | |
73 | 75 | baseMapper.insert(entity); |
74 | 76 | thingsModelDTO.setId(entity.getId()); |
75 | 77 | } else { |
... | ... | @@ -132,9 +134,10 @@ public class ThingsModelServiceImpl |
132 | 134 | new LambdaQueryWrapper<TkThingsModelEntity>() |
133 | 135 | .eq(TkThingsModelEntity::getTenantId, tenantId) |
134 | 136 | .eq(TkThingsModelEntity::getDeviceProfileId, deviceProfileId) |
135 | - .eq(TkThingsModelEntity::getFunctionType, typeEnum)); | |
137 | + .eq(TkThingsModelEntity::getFunctionType, typeEnum) | |
138 | + .eq(TkThingsModelEntity::getStatus, StatusEnum.ENABLE.getIndex())); | |
136 | 139 | if (entityList.isEmpty()) { |
137 | - throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
140 | + return null; | |
138 | 141 | } |
139 | 142 | return entityList.stream() |
140 | 143 | .map(obj -> obj.getDTO(ThingsModelDTO.class)) |
... | ... | @@ -154,12 +157,18 @@ public class ThingsModelServiceImpl |
154 | 157 | DeviceTypeEnum deviceType = deviceProfileDTO.getDeviceType(); |
155 | 158 | jsonNode = getAttributeTSL(thingsModelDTOS, deviceType); |
156 | 159 | } else if (typeEnum.equals(FunctionTypeEnum.services)) { |
157 | - | |
160 | + // TODO 服务 | |
158 | 161 | } |
159 | 162 | |
160 | 163 | return jsonNode; |
161 | 164 | } |
162 | 165 | |
166 | + @Override | |
167 | + @Transactional | |
168 | + public boolean changeTSLStatus(String deviceProfileId, String tenantId, Integer status) { | |
169 | + return baseMapper.changeTSLStatus(deviceProfileId, tenantId, status); | |
170 | + } | |
171 | + | |
163 | 172 | private JsonNode getAttributeTSL( |
164 | 173 | List<ThingsModelDTO> thingsModelDTOS, DeviceTypeEnum deviceType) { |
165 | 174 | Map<String, List<ObjectNode>> attributeMap = new HashMap<>(); |
... | ... | @@ -167,25 +176,33 @@ public class ThingsModelServiceImpl |
167 | 176 | List<ObjectNode> list = new ArrayList<>(); |
168 | 177 | for (ThingsModelDTO model : thingsModelDTOS) { |
169 | 178 | ObjectNode objectNode = JacksonUtil.newObjectNode(); |
170 | - DataTypeEnum type = | |
171 | - model.getFunctionJson().get("type") != null | |
172 | - ? DataTypeEnum.valueOf(model.getFunctionJson().get("type").asText()) | |
173 | - : null; | |
174 | - String identifier = model.getIdentifier(); | |
175 | - switch (Objects.requireNonNull(type)) { | |
176 | - case INT: | |
177 | - objectNode.put(identifier, 0); | |
178 | - break; | |
179 | - case BOOL: | |
180 | - objectNode.put(identifier, "0"); | |
181 | - case DOUBLE: | |
182 | - objectNode.put(identifier, 0.00); | |
183 | - case TEXT: | |
184 | - objectNode.put(identifier, "text"); | |
185 | - case STRUCT: | |
186 | - objectNode.putPOJO(identifier, model.getFunctionJson().get("specs")); | |
187 | - default: | |
188 | - objectNode.put(identifier, "value"); | |
179 | + JsonNode dataType = model.getFunctionJson().get("dataType"); | |
180 | + if (null != dataType) { | |
181 | + DataTypeEnum type = | |
182 | + dataType.get("type") != null | |
183 | + ? DataTypeEnum.valueOf(dataType.get("type").asText()) | |
184 | + : null; | |
185 | + String identifier = model.getIdentifier(); | |
186 | + switch (Objects.requireNonNull(type)) { | |
187 | + case INT: | |
188 | + objectNode.put(identifier, 0); | |
189 | + break; | |
190 | + case BOOL: | |
191 | + objectNode.put(identifier, "0"); | |
192 | + break; | |
193 | + case DOUBLE: | |
194 | + objectNode.put(identifier, 0.00); | |
195 | + break; | |
196 | + case TEXT: | |
197 | + objectNode.put(identifier, "text"); | |
198 | + break; | |
199 | + case STRUCT: | |
200 | + objectNode.putPOJO(identifier, dataType.get("specs")); | |
201 | + break; | |
202 | + default: | |
203 | + objectNode.put(identifier, "value"); | |
204 | + break; | |
205 | + } | |
189 | 206 | } |
190 | 207 | list.add(objectNode); |
191 | 208 | } | ... | ... |
... | ... | @@ -536,11 +536,11 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev |
536 | 536 | .map( |
537 | 537 | obj -> { |
538 | 538 | if (obj.getProfileId().equals(tbProfileId)) { |
539 | - JsonNode jsonNode = null; | |
539 | + JsonNode jsonNode = JacksonUtil.newObjectNode(); | |
540 | 540 | List<ThingsModelDTO> thingsModel = |
541 | 541 | thingsModelService.selectByDeviceProfileId( |
542 | 542 | FunctionTypeEnum.properties, tenantId, profileId); |
543 | - if (!thingsModel.isEmpty()) { | |
543 | + if (null !=thingsModel && !thingsModel.isEmpty()) { | |
544 | 544 | List<Map<String, Object>> attributes = new ArrayList<>(); |
545 | 545 | for (ThingsModelDTO dto : thingsModel) { |
546 | 546 | Map<String, Object> attribute = new HashMap<>(); | ... | ... |
... | ... | @@ -2,7 +2,13 @@ package org.thingsboard.server.dao.yunteng.mapper; |
2 | 2 | |
3 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
4 | 4 | import org.apache.ibatis.annotations.Mapper; |
5 | +import org.apache.ibatis.annotations.Param; | |
5 | 6 | import org.thingsboard.server.dao.yunteng.entities.TkThingsModelEntity; |
6 | 7 | |
7 | 8 | @Mapper |
8 | -public interface ThingsModelMapper extends BaseMapper<TkThingsModelEntity> {} | |
9 | +public interface ThingsModelMapper extends BaseMapper<TkThingsModelEntity> { | |
10 | + boolean changeTSLStatus( | |
11 | + @Param("deviceProfileId") String deviceProfileId, | |
12 | + @Param("tenantId") String tenantId, | |
13 | + @Param("status") Integer status); | |
14 | +} | ... | ... |
... | ... | @@ -24,4 +24,6 @@ public interface ThingsModelService { |
24 | 24 | FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId); |
25 | 25 | |
26 | 26 | JsonNode getTingsModelTSL(FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId); |
27 | + | |
28 | + boolean changeTSLStatus(String deviceProfileId,String tenantId,Integer status); | |
27 | 29 | } | ... | ... |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
3 | + | |
4 | +<mapper namespace="org.thingsboard.server.dao.yunteng.mapper.ThingsModelMapper"> | |
5 | + <update id="changeTSLStatus"> | |
6 | + UPDATE tk_things_model | |
7 | + SET status =#{status} | |
8 | + <where> | |
9 | + tenant_id = #{tenantId} | |
10 | + AND device_profile_id = #{deviceProfileId} | |
11 | + </where> | |
12 | + </update> | |
13 | +</mapper> | ... | ... |