Showing
4 changed files
with
66 additions
and
12 deletions
@@ -33,7 +33,6 @@ import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | @@ -33,7 +33,6 @@ import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | ||
33 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 33 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
34 | import org.thingsboard.server.common.msg.queue.ServiceQueue; | 34 | import org.thingsboard.server.common.msg.queue.ServiceQueue; |
35 | import org.thingsboard.server.controller.BaseController; | 35 | import org.thingsboard.server.controller.BaseController; |
36 | -import org.thingsboard.server.dao.yunteng.service.TkDeviceScriptService; | ||
37 | import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService; | 36 | import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService; |
38 | import org.thingsboard.server.service.security.permission.Operation; | 37 | import org.thingsboard.server.service.security.permission.Operation; |
39 | 38 | ||
@@ -48,8 +47,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. | @@ -48,8 +47,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. | ||
48 | @RequestMapping("api/yt/device_profile") | 47 | @RequestMapping("api/yt/device_profile") |
49 | @Api(tags = {"设备配置管理"}) | 48 | @Api(tags = {"设备配置管理"}) |
50 | public class TkDeviceProfileController extends BaseController { | 49 | public class TkDeviceProfileController extends BaseController { |
51 | - private final TkDeviceProfileService ytDeviceProfileService; | ||
52 | - private final TkDeviceScriptService javaScriptService; | 50 | + private final TkDeviceProfileService tkDeviceProfileService; |
53 | 51 | ||
54 | @PostMapping() | 52 | @PostMapping() |
55 | @PreAuthorize( | 53 | @PreAuthorize( |
@@ -67,7 +65,7 @@ public class TkDeviceProfileController extends BaseController { | @@ -67,7 +65,7 @@ public class TkDeviceProfileController extends BaseController { | ||
67 | 65 | ||
68 | DeviceProfile saveDeviceProfile = updateTbDeviceProfile(tbDeviceProfile, created); | 66 | DeviceProfile saveDeviceProfile = updateTbDeviceProfile(tbDeviceProfile, created); |
69 | deviceProfileDTO.setTbProfileId(saveDeviceProfile.getId().toString()); | 67 | deviceProfileDTO.setTbProfileId(saveDeviceProfile.getId().toString()); |
70 | - ytDeviceProfileService.insertOrUpdate(deviceProfileDTO); | 68 | + tkDeviceProfileService.insertOrUpdate(deviceProfileDTO); |
71 | 69 | ||
72 | return ResponseEntity.ok(deviceProfileDTO); | 70 | return ResponseEntity.ok(deviceProfileDTO); |
73 | } | 71 | } |
@@ -131,7 +129,7 @@ public class TkDeviceProfileController extends BaseController { | @@ -131,7 +129,7 @@ public class TkDeviceProfileController extends BaseController { | ||
131 | public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id) | 129 | public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id) |
132 | throws ThingsboardException { | 130 | throws ThingsboardException { |
133 | return ResponseEntity.ok( | 131 | return ResponseEntity.ok( |
134 | - ytDeviceProfileService.getDeviceProfile(getCurrentUser().getCurrentTenantId(), id)); | 132 | + tkDeviceProfileService.getDeviceProfile(getCurrentUser().getCurrentTenantId(), id)); |
135 | } | 133 | } |
136 | 134 | ||
137 | @GetMapping(params = {PAGE_SIZE, PAGE}) | 135 | @GetMapping(params = {PAGE_SIZE, PAGE}) |
@@ -154,7 +152,7 @@ public class TkDeviceProfileController extends BaseController { | @@ -154,7 +152,7 @@ public class TkDeviceProfileController extends BaseController { | ||
154 | queryMap.put("transportType", transportType); | 152 | queryMap.put("transportType", transportType); |
155 | queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId()); | 153 | queryMap.put(TENANT_ID, getCurrentUser().getCurrentTenantId()); |
156 | queryMap.put(CUSTOMER_ID, getCurrentUser().getCustomerId().toString()); | 154 | queryMap.put(CUSTOMER_ID, getCurrentUser().getCustomerId().toString()); |
157 | - return ytDeviceProfileService.page(queryMap, getCurrentUser().isTenantAdmin()); | 155 | + return tkDeviceProfileService.page(queryMap, getCurrentUser().isTenantAdmin()); |
158 | } | 156 | } |
159 | 157 | ||
160 | @GetMapping("/me/list") | 158 | @GetMapping("/me/list") |
@@ -167,10 +165,10 @@ public class TkDeviceProfileController extends BaseController { | @@ -167,10 +165,10 @@ public class TkDeviceProfileController extends BaseController { | ||
167 | List<DeviceProfileDTO> results; | 165 | List<DeviceProfileDTO> results; |
168 | String tenantId = getCurrentUser().getCurrentTenantId(); | 166 | String tenantId = getCurrentUser().getCurrentTenantId(); |
169 | if (getCurrentUser().isTenantAdmin()) { | 167 | if (getCurrentUser().isTenantAdmin()) { |
170 | - results = ytDeviceProfileService.findDeviceProfile(tenantId, null,deviceType); | 168 | + results = tkDeviceProfileService.findDeviceProfile(tenantId, null,deviceType); |
171 | } else { | 169 | } else { |
172 | results = | 170 | results = |
173 | - ytDeviceProfileService.findCustomerDeviceProfiles( | 171 | + tkDeviceProfileService.findCustomerDeviceProfiles( |
174 | tenantId, getCurrentUser().getCustomerId(),deviceType); | 172 | tenantId, getCurrentUser().getCustomerId(),deviceType); |
175 | } | 173 | } |
176 | 174 | ||
@@ -183,18 +181,18 @@ public class TkDeviceProfileController extends BaseController { | @@ -183,18 +181,18 @@ public class TkDeviceProfileController extends BaseController { | ||
183 | public void deleteDeviceProfiles(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) | 181 | public void deleteDeviceProfiles(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) |
184 | throws ThingsboardException { | 182 | throws ThingsboardException { |
185 | String tenantId = getCurrentUser().getCurrentTenantId(); | 183 | String tenantId = getCurrentUser().getCurrentTenantId(); |
186 | - ytDeviceProfileService.checkDeviceProfiles(tenantId, deleteDTO.getIds()); | 184 | + tkDeviceProfileService.checkDeviceProfiles(tenantId, deleteDTO.getIds()); |
187 | 185 | ||
188 | 186 | ||
189 | for (String id : deleteDTO.getIds()) { | 187 | for (String id : deleteDTO.getIds()) { |
190 | deleteTbDeviceProfile(id); | 188 | deleteTbDeviceProfile(id); |
191 | } | 189 | } |
192 | - ytDeviceProfileService.deleteDeviceProfiles(tenantId, deleteDTO.getIds()); | 190 | + tkDeviceProfileService.deleteDeviceProfiles(tenantId, deleteDTO.getIds()); |
193 | } | 191 | } |
194 | 192 | ||
195 | private void deleteTbDeviceProfile(String profileId) throws ThingsboardException { | 193 | private void deleteTbDeviceProfile(String profileId) throws ThingsboardException { |
196 | DeviceProfileDTO dto = | 194 | DeviceProfileDTO dto = |
197 | - ytDeviceProfileService.findDeviceProfileById( | 195 | + tkDeviceProfileService.findDeviceProfileById( |
198 | getCurrentUser().getCurrentTenantId(), profileId); | 196 | getCurrentUser().getCurrentTenantId(), profileId); |
199 | if (null != dto) { | 197 | if (null != dto) { |
200 | DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(dto.getTbProfileId())); | 198 | DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(dto.getTbProfileId())); |
@@ -248,7 +246,7 @@ public class TkDeviceProfileController extends BaseController { | @@ -248,7 +246,7 @@ public class TkDeviceProfileController extends BaseController { | ||
248 | DeviceProfile tbDeviceProfile = new DeviceProfile(); | 246 | DeviceProfile tbDeviceProfile = new DeviceProfile(); |
249 | if (StringUtils.isNotBlank(deviceProfileDTO.getId())) { | 247 | if (StringUtils.isNotBlank(deviceProfileDTO.getId())) { |
250 | DeviceProfileDTO findDeviceProfile = | 248 | DeviceProfileDTO findDeviceProfile = |
251 | - ytDeviceProfileService.findDeviceProfileById( | 249 | + tkDeviceProfileService.findDeviceProfileById( |
252 | getCurrentUser().getCurrentTenantId(), deviceProfileDTO.getId()); | 250 | getCurrentUser().getCurrentTenantId(), deviceProfileDTO.getId()); |
253 | if (StringUtils.isNotEmpty(findDeviceProfile.getTbProfileId())) { | 251 | if (StringUtils.isNotEmpty(findDeviceProfile.getTbProfileId())) { |
254 | UUID profileId = UUID.fromString(findDeviceProfile.getTbProfileId()); | 252 | UUID profileId = UUID.fromString(findDeviceProfile.getTbProfileId()); |
@@ -4,12 +4,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | @@ -4,12 +4,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
5 | import com.baomidou.mybatisplus.core.metadata.IPage; | 5 | import com.baomidou.mybatisplus.core.metadata.IPage; |
6 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 6 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
7 | +import com.fasterxml.jackson.databind.JsonNode; | ||
7 | import lombok.RequiredArgsConstructor; | 8 | import lombok.RequiredArgsConstructor; |
8 | import lombok.extern.slf4j.Slf4j; | 9 | import lombok.extern.slf4j.Slf4j; |
9 | import org.apache.commons.lang3.StringUtils; | 10 | import org.apache.commons.lang3.StringUtils; |
10 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
11 | import org.springframework.transaction.annotation.Transactional; | 12 | import org.springframework.transaction.annotation.Transactional; |
12 | import org.thingsboard.server.common.data.DeviceProfile; | 13 | import org.thingsboard.server.common.data.DeviceProfile; |
14 | +import org.thingsboard.server.common.data.DeviceTransportType; | ||
15 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration; | ||
13 | import org.thingsboard.server.common.data.id.CustomerId; | 16 | import org.thingsboard.server.common.data.id.CustomerId; |
14 | import org.thingsboard.server.common.data.id.TenantId; | 17 | import org.thingsboard.server.common.data.id.TenantId; |
15 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | 18 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
@@ -20,6 +23,7 @@ import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | @@ -20,6 +23,7 @@ import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
20 | import org.thingsboard.server.common.data.yunteng.dto.*; | 23 | import org.thingsboard.server.common.data.yunteng.dto.*; |
21 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | 24 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
22 | import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; | 25 | import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; |
26 | +import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; | ||
23 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 27 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
24 | import org.thingsboard.server.dao.yunteng.entities.*; | 28 | import org.thingsboard.server.dao.yunteng.entities.*; |
25 | import org.thingsboard.server.dao.yunteng.jpa.dao.TkJpaDeviceProfileDao; | 29 | import org.thingsboard.server.dao.yunteng.jpa.dao.TkJpaDeviceProfileDao; |
@@ -85,6 +89,19 @@ public class TkDeviceProfileServiceImpl | @@ -85,6 +89,19 @@ public class TkDeviceProfileServiceImpl | ||
85 | } | 89 | } |
86 | 90 | ||
87 | @Override | 91 | @Override |
92 | + public List<DeviceProfileDTO> findDeviceProfileByScriptId(String tenantId, String scriptId) { | ||
93 | + if(StringUtils.isEmpty(tenantId) || StringUtils.isEmpty(scriptId)){ | ||
94 | + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
95 | + } | ||
96 | + List<TkDeviceProfileEntity> entities = baseMapper.selectList(new LambdaQueryWrapper<TkDeviceProfileEntity>() | ||
97 | + .eq(TkDeviceProfileEntity::getTenantId,tenantId).like(TkDeviceProfileEntity::getScriptId,scriptId)); | ||
98 | + if(null != entities && !entities.isEmpty()){ | ||
99 | + return entities.stream().map(entity->entity.getDTO(DeviceProfileDTO.class)).collect(Collectors.toList()); | ||
100 | + } | ||
101 | + return null; | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
88 | @Transactional | 105 | @Transactional |
89 | public DeviceProfileDTO insertOrUpdate(DeviceProfileDTO deviceDTO) { | 106 | public DeviceProfileDTO insertOrUpdate(DeviceProfileDTO deviceDTO) { |
90 | if (StringUtils.isBlank(deviceDTO.getId())) { | 107 | if (StringUtils.isBlank(deviceDTO.getId())) { |
@@ -97,6 +114,9 @@ public class TkDeviceProfileServiceImpl | @@ -97,6 +114,9 @@ public class TkDeviceProfileServiceImpl | ||
97 | private DeviceProfileDTO insert(DeviceProfileDTO deviceDTO) { | 114 | private DeviceProfileDTO insert(DeviceProfileDTO deviceDTO) { |
98 | 115 | ||
99 | TkDeviceProfileEntity profile = new TkDeviceProfileEntity(); | 116 | TkDeviceProfileEntity profile = new TkDeviceProfileEntity(); |
117 | + if (Objects.equals(deviceDTO.getTransportType(), DeviceTransportType.TCP.name())) { | ||
118 | + setDeviceScriptId(profile,deviceDTO.getProfileData().getTransportConfiguration()); | ||
119 | + } | ||
100 | deviceDTO.copyToEntity( | 120 | deviceDTO.copyToEntity( |
101 | profile, | 121 | profile, |
102 | ModelConstants.TablePropertyMapping.ACTIVE_TIME, | 122 | ModelConstants.TablePropertyMapping.ACTIVE_TIME, |
@@ -113,6 +133,9 @@ public class TkDeviceProfileServiceImpl | @@ -113,6 +133,9 @@ public class TkDeviceProfileServiceImpl | ||
113 | 133 | ||
114 | private DeviceProfileDTO update(DeviceProfileDTO deviceDTO) { | 134 | private DeviceProfileDTO update(DeviceProfileDTO deviceDTO) { |
115 | TkDeviceProfileEntity device = new TkDeviceProfileEntity(); | 135 | TkDeviceProfileEntity device = new TkDeviceProfileEntity(); |
136 | + if (Objects.equals(deviceDTO.getTransportType(), DeviceTransportType.TCP.name())) { | ||
137 | + setDeviceScriptId(device,deviceDTO.getProfileData().getTransportConfiguration()); | ||
138 | + } | ||
116 | deviceDTO.copyToEntity( | 139 | deviceDTO.copyToEntity( |
117 | device, | 140 | device, |
118 | ModelConstants.TablePropertyMapping.ACTIVE_TIME, | 141 | ModelConstants.TablePropertyMapping.ACTIVE_TIME, |
@@ -127,6 +150,23 @@ public class TkDeviceProfileServiceImpl | @@ -127,6 +150,23 @@ public class TkDeviceProfileServiceImpl | ||
127 | baseMapper.updateById(device); | 150 | baseMapper.updateById(device); |
128 | return device.getDTO(DeviceProfileDTO.class); | 151 | return device.getDTO(DeviceProfileDTO.class); |
129 | } | 152 | } |
153 | + private void setDeviceScriptId(TkDeviceProfileEntity profile, DeviceProfileTransportConfiguration transportConfiguration) | ||
154 | + { | ||
155 | + JsonNode jsonNode = JacksonUtil.convertValue(transportConfiguration, JsonNode.class); | ||
156 | + if(null != jsonNode) | ||
157 | + { | ||
158 | + String authScriptId = String.valueOf(jsonNode.get("authScriptId")); | ||
159 | + String upScriptId = String.valueOf(jsonNode.get("upScriptId")); | ||
160 | + List<String> list = List.of(authScriptId,upScriptId); | ||
161 | + if(null != list && !list.isEmpty()){ | ||
162 | + String scriptId = list.get(FastIotConstants.MagicNumber.ZERO); | ||
163 | + if(list.size()>FastIotConstants.MagicNumber.ONE){ | ||
164 | + scriptId = StringUtils.join(list,","); | ||
165 | + } | ||
166 | + profile.setScriptId(scriptId); | ||
167 | + } | ||
168 | + } | ||
169 | + } | ||
130 | 170 | ||
131 | @Override | 171 | @Override |
132 | @Transactional | 172 | @Transactional |
@@ -97,6 +97,14 @@ public class TkDeviceScriptServiceImpl | @@ -97,6 +97,14 @@ public class TkDeviceScriptServiceImpl | ||
97 | if (!entity.getTenantId().equals(tenantId)) { | 97 | if (!entity.getTenantId().equals(tenantId)) { |
98 | throw new TkDataValidationException(ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); | 98 | throw new TkDataValidationException(ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); |
99 | } | 99 | } |
100 | + if(Objects.equals(status,StatusEnum.DISABLE.getIndex())){ | ||
101 | + List<DeviceProfileDTO> profileList = tkDeviceProfileService.findDeviceProfileByScriptId(tenantId,id); | ||
102 | + if(null != profileList && !profileList.isEmpty()){ | ||
103 | + | ||
104 | + throw new TkDataValidationException(String.format(ErrorMessage.CURRENT_DATA_IN_USE.getMessage(), | ||
105 | + profileList.get(0).getName())); | ||
106 | + } | ||
107 | + } | ||
100 | entity.setStatus(status); | 108 | entity.setStatus(status); |
101 | return baseMapper.updateById(entity) > FastIotConstants.MagicNumber.ZERO; | 109 | return baseMapper.updateById(entity) > FastIotConstants.MagicNumber.ZERO; |
102 | } | 110 | } |
@@ -53,4 +53,12 @@ public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntit | @@ -53,4 +53,12 @@ public interface TkDeviceProfileService extends BaseService<TkDeviceProfileEntit | ||
53 | * @return 设备配置信息 | 53 | * @return 设备配置信息 |
54 | */ | 54 | */ |
55 | DeviceProfileDTO findByTbDeviceProfileId(String tenantId, String tbProfileId); | 55 | DeviceProfileDTO findByTbDeviceProfileId(String tenantId, String tbProfileId); |
56 | + | ||
57 | + /** | ||
58 | + * 根据脚本ID查询,使用的产品 | ||
59 | + * @param tenantId 租户ID | ||
60 | + * @param scriptId 脚本ID | ||
61 | + * @return 产品列表 | ||
62 | + */ | ||
63 | + List<DeviceProfileDTO> findDeviceProfileByScriptId(String tenantId,String scriptId); | ||
56 | } | 64 | } |