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,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; | ||
4 | import io.swagger.annotations.Api; | 4 | import io.swagger.annotations.Api; |
5 | import io.swagger.annotations.ApiOperation; | 5 | import io.swagger.annotations.ApiOperation; |
6 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
7 | +import org.apache.commons.lang3.StringUtils; | ||
7 | import org.springframework.http.ResponseEntity; | 8 | import org.springframework.http.ResponseEntity; |
8 | import org.springframework.validation.annotation.Validated; | 9 | import org.springframework.validation.annotation.Validated; |
9 | import org.springframework.web.bind.annotation.*; | 10 | import org.springframework.web.bind.annotation.*; |
@@ -18,6 +19,7 @@ import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | @@ -18,6 +19,7 @@ import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | ||
18 | import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO; | 19 | import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO; |
19 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; | 20 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
20 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 21 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
22 | +import org.thingsboard.server.common.data.yunteng.enums.StatusEnum; | ||
21 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 23 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
22 | import org.thingsboard.server.controller.BaseController; | 24 | import org.thingsboard.server.controller.BaseController; |
23 | import org.thingsboard.server.dao.yunteng.service.ThingsModelService; | 25 | import org.thingsboard.server.dao.yunteng.service.ThingsModelService; |
@@ -97,6 +99,20 @@ public class ThingsModelController extends BaseController { | @@ -97,6 +99,20 @@ public class ThingsModelController extends BaseController { | ||
97 | functionType, getCurrentUser().getCurrentTenantId(), deviceProfileId)); | 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 | private ThingsModelDTO saveOrUpdate(ThingsModelDTO thingsModelDTO) throws ThingsboardException { | 116 | private ThingsModelDTO saveOrUpdate(ThingsModelDTO thingsModelDTO) throws ThingsboardException { |
101 | 117 | ||
102 | String tenantId = getCurrentUser().getCurrentTenantId(); | 118 | String tenantId = getCurrentUser().getCurrentTenantId(); |
@@ -7,6 +7,8 @@ import lombok.Data; | @@ -7,6 +7,8 @@ import lombok.Data; | ||
7 | import lombok.EqualsAndHashCode; | 7 | import lombok.EqualsAndHashCode; |
8 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; | 8 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
9 | import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | 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 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; | 12 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
11 | 13 | ||
12 | import javax.validation.constraints.NotEmpty; | 14 | import javax.validation.constraints.NotEmpty; |
@@ -34,12 +36,24 @@ public class ThingsModelDTO extends TenantDTO { | @@ -34,12 +36,24 @@ public class ThingsModelDTO extends TenantDTO { | ||
34 | @ApiModelProperty("功能标识") | 36 | @ApiModelProperty("功能标识") |
35 | private String identifier; | 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 | @ApiModelProperty("功能json") | 48 | @ApiModelProperty("功能json") |
38 | @NotNull( | 49 | @NotNull( |
39 | message = "功能json不能为空", | 50 | message = "功能json不能为空", |
40 | groups = {AddGroup.class}) | 51 | groups = {AddGroup.class}) |
41 | private JsonNode functionJson; | 52 | private JsonNode functionJson; |
42 | 53 | ||
54 | + @ApiModelProperty("状态:0待发布 1发布") | ||
55 | + private Integer status; | ||
56 | + | ||
43 | @ApiModelProperty("设备配置ID") | 57 | @ApiModelProperty("设备配置ID") |
44 | @NotEmpty( | 58 | @NotEmpty( |
45 | message = "设备配置ID不能为空或空字符串", | 59 | message = "设备配置ID不能为空或空字符串", |
@@ -8,6 +8,8 @@ import lombok.Data; | @@ -8,6 +8,8 @@ import lombok.Data; | ||
8 | import lombok.EqualsAndHashCode; | 8 | import lombok.EqualsAndHashCode; |
9 | import org.apache.ibatis.type.EnumTypeHandler; | 9 | import org.apache.ibatis.type.EnumTypeHandler; |
10 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | 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 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; | 13 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
12 | 14 | ||
13 | @Data | 15 | @Data |
@@ -19,10 +21,14 @@ public class TkThingsModelEntity extends TenantBaseEntity { | @@ -19,10 +21,14 @@ public class TkThingsModelEntity extends TenantBaseEntity { | ||
19 | 21 | ||
20 | @TableField(typeHandler = EnumTypeHandler.class) | 22 | @TableField(typeHandler = EnumTypeHandler.class) |
21 | private FunctionTypeEnum functionType; | 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 | private String functionName; | 29 | private String functionName; |
24 | private String identifier; | 30 | private String identifier; |
25 | - | 31 | + private Integer status; |
26 | @TableField(typeHandler = JacksonTypeHandler.class) | 32 | @TableField(typeHandler = JacksonTypeHandler.class) |
27 | private JsonNode functionJson; | 33 | private JsonNode functionJson; |
28 | 34 |
@@ -17,6 +17,7 @@ import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO; | @@ -17,6 +17,7 @@ import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO; | ||
17 | import org.thingsboard.server.common.data.yunteng.enums.DataTypeEnum; | 17 | import org.thingsboard.server.common.data.yunteng.enums.DataTypeEnum; |
18 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | 18 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
19 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; | 19 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
20 | +import org.thingsboard.server.common.data.yunteng.enums.StatusEnum; | ||
20 | import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; | 21 | import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; |
21 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 22 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
22 | import org.thingsboard.server.dao.yunteng.entities.TkThingsModelEntity; | 23 | import org.thingsboard.server.dao.yunteng.entities.TkThingsModelEntity; |
@@ -70,6 +71,7 @@ public class ThingsModelServiceImpl | @@ -70,6 +71,7 @@ public class ThingsModelServiceImpl | ||
70 | } | 71 | } |
71 | TkThingsModelEntity entity = thingsModelDTO.getEntity(TkThingsModelEntity.class); | 72 | TkThingsModelEntity entity = thingsModelDTO.getEntity(TkThingsModelEntity.class); |
72 | if (isAdd) { | 73 | if (isAdd) { |
74 | + entity.setStatus(StatusEnum.DISABLE.getIndex()); | ||
73 | baseMapper.insert(entity); | 75 | baseMapper.insert(entity); |
74 | thingsModelDTO.setId(entity.getId()); | 76 | thingsModelDTO.setId(entity.getId()); |
75 | } else { | 77 | } else { |
@@ -132,9 +134,10 @@ public class ThingsModelServiceImpl | @@ -132,9 +134,10 @@ public class ThingsModelServiceImpl | ||
132 | new LambdaQueryWrapper<TkThingsModelEntity>() | 134 | new LambdaQueryWrapper<TkThingsModelEntity>() |
133 | .eq(TkThingsModelEntity::getTenantId, tenantId) | 135 | .eq(TkThingsModelEntity::getTenantId, tenantId) |
134 | .eq(TkThingsModelEntity::getDeviceProfileId, deviceProfileId) | 136 | .eq(TkThingsModelEntity::getDeviceProfileId, deviceProfileId) |
135 | - .eq(TkThingsModelEntity::getFunctionType, typeEnum)); | 137 | + .eq(TkThingsModelEntity::getFunctionType, typeEnum) |
138 | + .eq(TkThingsModelEntity::getStatus, StatusEnum.ENABLE.getIndex())); | ||
136 | if (entityList.isEmpty()) { | 139 | if (entityList.isEmpty()) { |
137 | - throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 140 | + return null; |
138 | } | 141 | } |
139 | return entityList.stream() | 142 | return entityList.stream() |
140 | .map(obj -> obj.getDTO(ThingsModelDTO.class)) | 143 | .map(obj -> obj.getDTO(ThingsModelDTO.class)) |
@@ -154,12 +157,18 @@ public class ThingsModelServiceImpl | @@ -154,12 +157,18 @@ public class ThingsModelServiceImpl | ||
154 | DeviceTypeEnum deviceType = deviceProfileDTO.getDeviceType(); | 157 | DeviceTypeEnum deviceType = deviceProfileDTO.getDeviceType(); |
155 | jsonNode = getAttributeTSL(thingsModelDTOS, deviceType); | 158 | jsonNode = getAttributeTSL(thingsModelDTOS, deviceType); |
156 | } else if (typeEnum.equals(FunctionTypeEnum.services)) { | 159 | } else if (typeEnum.equals(FunctionTypeEnum.services)) { |
157 | - | 160 | + // TODO 服务 |
158 | } | 161 | } |
159 | 162 | ||
160 | return jsonNode; | 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 | private JsonNode getAttributeTSL( | 172 | private JsonNode getAttributeTSL( |
164 | List<ThingsModelDTO> thingsModelDTOS, DeviceTypeEnum deviceType) { | 173 | List<ThingsModelDTO> thingsModelDTOS, DeviceTypeEnum deviceType) { |
165 | Map<String, List<ObjectNode>> attributeMap = new HashMap<>(); | 174 | Map<String, List<ObjectNode>> attributeMap = new HashMap<>(); |
@@ -167,25 +176,33 @@ public class ThingsModelServiceImpl | @@ -167,25 +176,33 @@ public class ThingsModelServiceImpl | ||
167 | List<ObjectNode> list = new ArrayList<>(); | 176 | List<ObjectNode> list = new ArrayList<>(); |
168 | for (ThingsModelDTO model : thingsModelDTOS) { | 177 | for (ThingsModelDTO model : thingsModelDTOS) { |
169 | ObjectNode objectNode = JacksonUtil.newObjectNode(); | 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 | list.add(objectNode); | 207 | list.add(objectNode); |
191 | } | 208 | } |
@@ -536,11 +536,11 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | @@ -536,11 +536,11 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev | ||
536 | .map( | 536 | .map( |
537 | obj -> { | 537 | obj -> { |
538 | if (obj.getProfileId().equals(tbProfileId)) { | 538 | if (obj.getProfileId().equals(tbProfileId)) { |
539 | - JsonNode jsonNode = null; | 539 | + JsonNode jsonNode = JacksonUtil.newObjectNode(); |
540 | List<ThingsModelDTO> thingsModel = | 540 | List<ThingsModelDTO> thingsModel = |
541 | thingsModelService.selectByDeviceProfileId( | 541 | thingsModelService.selectByDeviceProfileId( |
542 | FunctionTypeEnum.properties, tenantId, profileId); | 542 | FunctionTypeEnum.properties, tenantId, profileId); |
543 | - if (!thingsModel.isEmpty()) { | 543 | + if (null !=thingsModel && !thingsModel.isEmpty()) { |
544 | List<Map<String, Object>> attributes = new ArrayList<>(); | 544 | List<Map<String, Object>> attributes = new ArrayList<>(); |
545 | for (ThingsModelDTO dto : thingsModel) { | 545 | for (ThingsModelDTO dto : thingsModel) { |
546 | Map<String, Object> attribute = new HashMap<>(); | 546 | Map<String, Object> attribute = new HashMap<>(); |
@@ -2,7 +2,13 @@ package org.thingsboard.server.dao.yunteng.mapper; | @@ -2,7 +2,13 @@ package org.thingsboard.server.dao.yunteng.mapper; | ||
2 | 2 | ||
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
4 | import org.apache.ibatis.annotations.Mapper; | 4 | import org.apache.ibatis.annotations.Mapper; |
5 | +import org.apache.ibatis.annotations.Param; | ||
5 | import org.thingsboard.server.dao.yunteng.entities.TkThingsModelEntity; | 6 | import org.thingsboard.server.dao.yunteng.entities.TkThingsModelEntity; |
6 | 7 | ||
7 | @Mapper | 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,4 +24,6 @@ public interface ThingsModelService { | ||
24 | FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId); | 24 | FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId); |
25 | 25 | ||
26 | JsonNode getTingsModelTSL(FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId); | 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> |