Commit 71c6d65195c0151031a1f79179de828a1c77c1ef
Merge branch '2024-2-19' into 'master_dev'
feat:新增设备接入信息 See merge request yunteng/thingskit!341
Showing
9 changed files
with
325 additions
and
10 deletions
@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiOperation; | @@ -5,7 +5,6 @@ import io.swagger.annotations.ApiOperation; | ||
5 | import io.swagger.annotations.ApiParam; | 5 | import io.swagger.annotations.ApiParam; |
6 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
7 | import org.springframework.http.ResponseEntity; | 7 | import org.springframework.http.ResponseEntity; |
8 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
9 | import org.springframework.validation.annotation.Validated; | 8 | import org.springframework.validation.annotation.Validated; |
10 | import org.springframework.web.bind.annotation.*; | 9 | import org.springframework.web.bind.annotation.*; |
11 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 10 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
@@ -65,7 +64,6 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -65,7 +64,6 @@ public class TkDataViewInterfaceController extends BaseController { | ||
65 | 64 | ||
66 | @PostMapping | 65 | @PostMapping |
67 | @ApiOperation("新增") | 66 | @ApiOperation("新增") |
68 | - @PreAuthorize("@check.checkPermissions({},{})") | ||
69 | public ResponseEntity<TkDataViewInterfaceDTO> save( | 67 | public ResponseEntity<TkDataViewInterfaceDTO> save( |
70 | @Validated({AddGroup.class}) @RequestBody TkDataViewInterfaceDTO tkDataViewInterfaceDTO) | 68 | @Validated({AddGroup.class}) @RequestBody TkDataViewInterfaceDTO tkDataViewInterfaceDTO) |
71 | throws ThingsboardException { | 69 | throws ThingsboardException { |
@@ -77,7 +75,6 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -77,7 +75,6 @@ public class TkDataViewInterfaceController extends BaseController { | ||
77 | 75 | ||
78 | @PutMapping | 76 | @PutMapping |
79 | @ApiOperation("修改") | 77 | @ApiOperation("修改") |
80 | - @PreAuthorize("@check.checkPermissions({},{})") | ||
81 | public ResponseEntity<TkDataViewInterfaceDTO> update( | 78 | public ResponseEntity<TkDataViewInterfaceDTO> update( |
82 | @Validated({UpdateGroup.class}) @RequestBody TkDataViewInterfaceDTO TkDataViewInterfaceDTO) | 79 | @Validated({UpdateGroup.class}) @RequestBody TkDataViewInterfaceDTO TkDataViewInterfaceDTO) |
83 | throws ThingsboardException { | 80 | throws ThingsboardException { |
@@ -88,7 +85,6 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -88,7 +85,6 @@ public class TkDataViewInterfaceController extends BaseController { | ||
88 | 85 | ||
89 | @DeleteMapping | 86 | @DeleteMapping |
90 | @ApiOperation("删除") | 87 | @ApiOperation("删除") |
91 | - @PreAuthorize("@check.checkPermissions({},{})") | ||
92 | public ResponseEntity<Boolean> delete( | 88 | public ResponseEntity<Boolean> delete( |
93 | @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) | 89 | @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) |
94 | throws ThingsboardException { | 90 | throws ThingsboardException { |
@@ -98,7 +94,6 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -98,7 +94,6 @@ public class TkDataViewInterfaceController extends BaseController { | ||
98 | 94 | ||
99 | @GetMapping("/publish/{id}") | 95 | @GetMapping("/publish/{id}") |
100 | @ApiOperation("发布") | 96 | @ApiOperation("发布") |
101 | - @PreAuthorize("@check.checkPermissions({},{})") | ||
102 | public ResponseEntity<Boolean> publishInterface(@PathVariable("id") String id) | 97 | public ResponseEntity<Boolean> publishInterface(@PathVariable("id") String id) |
103 | throws ThingsboardException { | 98 | throws ThingsboardException { |
104 | return ResponseEntity.ok( | 99 | return ResponseEntity.ok( |
@@ -107,7 +102,6 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -107,7 +102,6 @@ public class TkDataViewInterfaceController extends BaseController { | ||
107 | 102 | ||
108 | @GetMapping("/cancel_publish/{id}") | 103 | @GetMapping("/cancel_publish/{id}") |
109 | @ApiOperation("取消发布") | 104 | @ApiOperation("取消发布") |
110 | - @PreAuthorize("@check.checkPermissions({},{})") | ||
111 | public ResponseEntity<Boolean> cancelPublishInterface(@PathVariable("id") String id) | 105 | public ResponseEntity<Boolean> cancelPublishInterface(@PathVariable("id") String id) |
112 | throws ThingsboardException { | 106 | throws ThingsboardException { |
113 | return ResponseEntity.ok( | 107 | return ResponseEntity.ok( |
@@ -116,7 +110,6 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -116,7 +110,6 @@ public class TkDataViewInterfaceController extends BaseController { | ||
116 | } | 110 | } |
117 | 111 | ||
118 | @ApiOperation("根据接口ID,获得接口详情") | 112 | @ApiOperation("根据接口ID,获得接口详情") |
119 | - @PreAuthorize("@check.checkPermissions({},{})") | ||
120 | @RequestMapping( | 113 | @RequestMapping( |
121 | value = "/get_interface_details", | 114 | value = "/get_interface_details", |
122 | params = {"ids"}, | 115 | params = {"ids"}, |
@@ -130,7 +123,6 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -130,7 +123,6 @@ public class TkDataViewInterfaceController extends BaseController { | ||
130 | 123 | ||
131 | @GetMapping("/filter_by_interface_type/{type}") | 124 | @GetMapping("/filter_by_interface_type/{type}") |
132 | @ApiOperation("根据接口类型过滤数据") | 125 | @ApiOperation("根据接口类型过滤数据") |
133 | - @PreAuthorize("@check.checkPermissions({},{})") | ||
134 | public List<TkDataViewInterfaceDTO> filterByInterfaceType(@PathVariable("type") String type) | 126 | public List<TkDataViewInterfaceDTO> filterByInterfaceType(@PathVariable("type") String type) |
135 | throws ThingsboardException { | 127 | throws ThingsboardException { |
136 | return tkDataViewInterfaceService.filterByInterfaceType( | 128 | return tkDataViewInterfaceService.filterByInterfaceType( |
@@ -139,7 +131,6 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -139,7 +131,6 @@ public class TkDataViewInterfaceController extends BaseController { | ||
139 | 131 | ||
140 | @GetMapping("/find_all_interface/{state}") | 132 | @GetMapping("/find_all_interface/{state}") |
141 | @ApiOperation("查询所有接口") | 133 | @ApiOperation("查询所有接口") |
142 | - @PreAuthorize("@check.checkPermissions({},{})") | ||
143 | public List<TkDataViewInterfaceDTO> findAll(@PathVariable("state") String state) | 134 | public List<TkDataViewInterfaceDTO> findAll(@PathVariable("state") String state) |
144 | throws ThingsboardException { | 135 | throws ThingsboardException { |
145 | return tkDataViewInterfaceService.findAll(state, getCurrentUser().getCurrentTenantId()); | 136 | return tkDataViewInterfaceService.findAll(state, getCurrentUser().getCurrentTenantId()); |
@@ -147,7 +138,6 @@ public class TkDataViewInterfaceController extends BaseController { | @@ -147,7 +138,6 @@ public class TkDataViewInterfaceController extends BaseController { | ||
147 | 138 | ||
148 | @GetMapping("/find/can_use_interfaces") | 139 | @GetMapping("/find/can_use_interfaces") |
149 | @ApiOperation("查询当前用户可使用的接口") | 140 | @ApiOperation("查询当前用户可使用的接口") |
150 | - @PreAuthorize("@check.checkPermissions({},{})") | ||
151 | public List<TkDataViewInterfaceDTO> findCanUseInterfaces() throws ThingsboardException { | 141 | public List<TkDataViewInterfaceDTO> findCanUseInterfaces() throws ThingsboardException { |
152 | boolean isSysAdminOrPtAdmin = getCurrentUser().isPtAdmin() || getCurrentUser().isSystemAdmin(); | 142 | boolean isSysAdminOrPtAdmin = getCurrentUser().isPtAdmin() || getCurrentUser().isSystemAdmin(); |
153 | return tkDataViewInterfaceService.findCanUseInterfaces( | 143 | return tkDataViewInterfaceService.findCanUseInterfaces( |
1 | +package org.thingsboard.server.controller.yunteng; | ||
2 | + | ||
3 | +import io.swagger.annotations.Api; | ||
4 | +import lombok.RequiredArgsConstructor; | ||
5 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
6 | +import org.springframework.validation.annotation.Validated; | ||
7 | +import org.springframework.web.bind.annotation.*; | ||
8 | +import org.thingsboard.server.common.data.StringUtils; | ||
9 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
10 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | ||
11 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | ||
12 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | ||
13 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
14 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | ||
15 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
16 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
17 | +import org.thingsboard.server.common.data.yunteng.dto.TkDeviceAccessInformationDTO; | ||
18 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | ||
19 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | ||
20 | +import org.thingsboard.server.controller.BaseController; | ||
21 | +import org.thingsboard.server.dao.yunteng.service.TkDeviceAccessInformationService; | ||
22 | + | ||
23 | +import java.util.HashMap; | ||
24 | + | ||
25 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
26 | + | ||
27 | +@RestController | ||
28 | +@RequiredArgsConstructor | ||
29 | +@RequestMapping("api/yt/device_profile/access_information") | ||
30 | +@Api(tags = {"设备接入信息管理"}) | ||
31 | +public class TkDeviceAccessInformationController extends BaseController { | ||
32 | + | ||
33 | + private final TkDeviceAccessInformationService service; | ||
34 | + | ||
35 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | ||
36 | + public TkPageData<TkDeviceAccessInformationDTO> page( | ||
37 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
38 | + @RequestParam(PAGE) int page, | ||
39 | + @RequestParam(value = "intranetIp", required = false) String intranetIp, | ||
40 | + @RequestParam(value = "intranetPort", required = false) String intranetPort, | ||
41 | + @RequestParam(value = "outerNetIp", required = false) String outerNetIp, | ||
42 | + @RequestParam(value = "outerNetPort", required = false) String outerNetPort, | ||
43 | + @RequestParam(value = "deviceAgreement", required = false) String deviceAgreement, | ||
44 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy) { | ||
45 | + | ||
46 | + HashMap<String, Object> queryMap = new HashMap<>(); | ||
47 | + queryMap.put(PAGE_SIZE, pageSize); | ||
48 | + queryMap.put(PAGE, page); | ||
49 | + queryMap.put(ORDER_FILED, orderBy); | ||
50 | + queryMap.put("intranetIp", intranetIp); | ||
51 | + queryMap.put("intranetPort", intranetPort); | ||
52 | + queryMap.put("outerNetIp", outerNetIp); | ||
53 | + queryMap.put("outerNetPort", outerNetPort); | ||
54 | + queryMap.put("deviceAgreement", deviceAgreement); | ||
55 | + | ||
56 | + return service.page(queryMap); | ||
57 | + } | ||
58 | + | ||
59 | + @PostMapping | ||
60 | + @PreAuthorize( | ||
61 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:device_profile:access_information:post'})") | ||
62 | + public ResponseResult<TkDeviceAccessInformationDTO> saveAccessInfo( | ||
63 | + @Validated({AddGroup.class}) @RequestBody TkDeviceAccessInformationDTO dto) | ||
64 | + throws ThingsboardException { | ||
65 | + if (!StringUtils.isEmpty(dto.getId())) { | ||
66 | + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
67 | + } | ||
68 | + return saveOrUpdate(dto); | ||
69 | + } | ||
70 | + | ||
71 | + @PutMapping | ||
72 | + @PreAuthorize( | ||
73 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:device_profile:access_information:update'})") | ||
74 | + public ResponseResult<TkDeviceAccessInformationDTO> updateAccessInfo( | ||
75 | + @Validated({UpdateGroup.class}) @RequestBody TkDeviceAccessInformationDTO dto) | ||
76 | + throws ThingsboardException { | ||
77 | + if (StringUtils.isEmpty(dto.getId())) { | ||
78 | + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
79 | + } | ||
80 | + return saveOrUpdate(dto); | ||
81 | + } | ||
82 | + | ||
83 | + @DeleteMapping | ||
84 | + @PreAuthorize( | ||
85 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:device_profile:access_information:delete'})") | ||
86 | + public ResponseResult<String> deleteSysDict( | ||
87 | + @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) | ||
88 | + throws ThingsboardException { | ||
89 | + deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
90 | + return service.delete(deleteDTO) | ||
91 | + ? ResponseResult.success(FastIotConstants.StateValue.DELETE_SUCCESS) | ||
92 | + : ResponseResult.failed(FastIotConstants.StateValue.DELETE_FAILED); | ||
93 | + } | ||
94 | + | ||
95 | + private ResponseResult<TkDeviceAccessInformationDTO> saveOrUpdate( | ||
96 | + TkDeviceAccessInformationDTO dto) throws ThingsboardException { | ||
97 | + dto.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
98 | + TkDeviceAccessInformationDTO newDTO = service.saveOrUpdate(dto); | ||
99 | + return ResponseResult.success(newDTO); | ||
100 | + } | ||
101 | +} |
@@ -134,6 +134,9 @@ public final class ModelConstants { | @@ -134,6 +134,9 @@ public final class ModelConstants { | ||
134 | /** 产品品类表 */ | 134 | /** 产品品类表 */ |
135 | public static final String TK_DEVICE_PROFILE_CATEGORY = "tk_device_profile_category"; | 135 | public static final String TK_DEVICE_PROFILE_CATEGORY = "tk_device_profile_category"; |
136 | 136 | ||
137 | + /** 设备接入信息表 */ | ||
138 | + public static final String TK_DEVICE_ACCESS_INFORMATION = "tk_device_access_information"; | ||
139 | + | ||
137 | /** ZLMediaKit 流媒体表 */ | 140 | /** ZLMediaKit 流媒体表 */ |
138 | public static final String TK_MEDIA_SERVER_NAME = "tk_media_server"; | 141 | public static final String TK_MEDIA_SERVER_NAME = "tk_media_server"; |
139 | 142 |
@@ -131,6 +131,8 @@ public enum ErrorMessage { | @@ -131,6 +131,8 @@ public enum ErrorMessage { | ||
131 | SIP_COMMAND_SEND_FAILED(400106,"sip命令下发失败"), | 131 | SIP_COMMAND_SEND_FAILED(400106,"sip命令下发失败"), |
132 | NOT_BELONG_CURRENT_CUSTOMER(400107,"该数据不属于当前客户"), | 132 | NOT_BELONG_CURRENT_CUSTOMER(400107,"该数据不属于当前客户"), |
133 | IMPORT_ERROR(400108,"请使用模板excel重新导入"), | 133 | IMPORT_ERROR(400108,"请使用模板excel重新导入"), |
134 | + INTRANET_ERROR(400109,"内网ip+端口不能重复,请重新输入"), | ||
135 | + OUTER_NET_ERROR(400110,"外网ip+端口不能重复,请重新输入"), | ||
134 | HAVE_NO_PERMISSION(500002,"没有修改权限"), | 136 | HAVE_NO_PERMISSION(500002,"没有修改权限"), |
135 | NOT_ALLOED_ISOLATED_IN_MONOLITH(500003,"【monolith】模式下,不能选择【isolated】类型的租户配置"); | 137 | NOT_ALLOED_ISOLATED_IN_MONOLITH(500003,"【monolith】模式下,不能选择【isolated】类型的租户配置"); |
136 | 138 |
1 | +package org.thingsboard.server.common.data.yunteng.dto; | ||
2 | + | ||
3 | +import com.fasterxml.jackson.databind.JsonNode; | ||
4 | +import io.swagger.annotations.ApiModelProperty; | ||
5 | +import lombok.Data; | ||
6 | +import lombok.EqualsAndHashCode; | ||
7 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | ||
8 | +import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; | ||
9 | + | ||
10 | +import javax.validation.constraints.NotEmpty; | ||
11 | + | ||
12 | +@EqualsAndHashCode(callSuper = true) | ||
13 | +@Data | ||
14 | +public class TkDeviceAccessInformationDTO extends TenantDTO { | ||
15 | + | ||
16 | + @ApiModelProperty(value = "内网ip") | ||
17 | + @NotEmpty( | ||
18 | + message = "内网ip不能为空或空字符串", | ||
19 | + groups = {AddGroup.class}) | ||
20 | + private String intranetIp; | ||
21 | + | ||
22 | + @ApiModelProperty(value = "内网端口") | ||
23 | + @NotEmpty( | ||
24 | + message = "内网端口不能为空或空字符串", | ||
25 | + groups = {AddGroup.class}) | ||
26 | + private String intranetPort; | ||
27 | + | ||
28 | + @ApiModelProperty(value = "外网IP") | ||
29 | + @NotEmpty( | ||
30 | + message = "外网IP不能为空或空字符串", | ||
31 | + groups = {AddGroup.class}) | ||
32 | + private String outerNetIp; | ||
33 | + | ||
34 | + @ApiModelProperty(value = "外网端口") | ||
35 | + private String outerNetPort; | ||
36 | + | ||
37 | + @ApiModelProperty(value = "设备接入协议") | ||
38 | + private TransportTypeEnum deviceAgreement; | ||
39 | + | ||
40 | + @ApiModelProperty(value = "sip扩展信息: serverId 服务器id serverRegion 服务器域 password 密码") | ||
41 | + private JsonNode sipExtend; | ||
42 | + | ||
43 | +} |
dao/src/main/java/org/thingsboard/server/dao/yunteng/entities/TkDeviceAccessInformationEntity.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.entities; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.annotation.TableField; | ||
4 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
5 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | ||
6 | +import com.fasterxml.jackson.databind.JsonNode; | ||
7 | +import lombok.Data; | ||
8 | +import lombok.EqualsAndHashCode; | ||
9 | +import org.apache.ibatis.type.EnumTypeHandler; | ||
10 | +import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | ||
11 | +import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; | ||
12 | + | ||
13 | +@Data | ||
14 | +@EqualsAndHashCode(callSuper = true) | ||
15 | +@TableName(value = ModelConstants.Table.TK_DEVICE_ACCESS_INFORMATION, autoResultMap = true) | ||
16 | +public class TkDeviceAccessInformationEntity extends TenantBaseEntity { | ||
17 | + | ||
18 | + private static final long serialVersionUID = -5381101569947753244L; | ||
19 | + | ||
20 | + /** 内网ip */ | ||
21 | + private String intranetIp; | ||
22 | + | ||
23 | + /** 内网端口 */ | ||
24 | + private String intranetPort; | ||
25 | + | ||
26 | + /** 外网IP */ | ||
27 | + private String outerNetIp; | ||
28 | + | ||
29 | + /** 外网端口 */ | ||
30 | + private String outerNetPort; | ||
31 | + | ||
32 | + /** 设备接入协议 */ | ||
33 | + @TableField(typeHandler = EnumTypeHandler.class) | ||
34 | + private TransportTypeEnum deviceAgreement; | ||
35 | + | ||
36 | + /** sip扩展信息 | ||
37 | + * serverId 服务器id | ||
38 | + * serverRegion 服务器域 | ||
39 | + * password 密码 | ||
40 | + * */ | ||
41 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
42 | + private JsonNode sipExtend; | ||
43 | + | ||
44 | + | ||
45 | + | ||
46 | +} |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/TkDeviceAccessInformationServiceImpl.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.impl; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
5 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
6 | +import lombok.RequiredArgsConstructor; | ||
7 | +import lombok.extern.slf4j.Slf4j; | ||
8 | +import org.springframework.stereotype.Service; | ||
9 | +import org.springframework.transaction.annotation.Transactional; | ||
10 | +import org.thingsboard.server.common.data.StringUtils; | ||
11 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
12 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | ||
13 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
14 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
15 | +import org.thingsboard.server.common.data.yunteng.dto.TkDeviceAccessInformationDTO; | ||
16 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | ||
17 | +import org.thingsboard.server.dao.yunteng.entities.TkDeviceAccessInformationEntity; | ||
18 | +import org.thingsboard.server.dao.yunteng.mapper.TkDeviceAccessInformationMapper; | ||
19 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ||
20 | +import org.thingsboard.server.dao.yunteng.service.TkDeviceAccessInformationService; | ||
21 | + | ||
22 | +import java.util.Map; | ||
23 | + | ||
24 | +@Slf4j | ||
25 | +@Service | ||
26 | +@RequiredArgsConstructor | ||
27 | +public class TkDeviceAccessInformationServiceImpl extends AbstractBaseService<TkDeviceAccessInformationMapper, TkDeviceAccessInformationEntity> | ||
28 | + implements TkDeviceAccessInformationService { | ||
29 | + | ||
30 | + @Override | ||
31 | + public TkPageData<TkDeviceAccessInformationDTO> page(Map<String, Object> queryMap) { | ||
32 | + String intranetIp = queryMap.get("intranetIp") != null ? String.valueOf(queryMap.get("intranetIp")) : null; | ||
33 | + String intranetPort = queryMap.get("intranetPort") != null ? String.valueOf(queryMap.get("intranetPort")) : null; | ||
34 | + String outerNetIp = queryMap.get("outerNetIp") != null ? String.valueOf(queryMap.get("outerNetIp")) : null; | ||
35 | + String outerNetPort = queryMap.get("outerNetPort") != null ? String.valueOf(queryMap.get("outerNetPort")) : null; | ||
36 | + String deviceAgreement = queryMap.get("deviceAgreement") != null ? String.valueOf(queryMap.get("deviceAgreement")) : null; | ||
37 | + IPage<TkDeviceAccessInformationEntity> iPage = | ||
38 | + baseMapper.selectPage( | ||
39 | + getPage(queryMap, "create_time", false), | ||
40 | + new QueryWrapper<TkDeviceAccessInformationEntity>() | ||
41 | + .lambda() | ||
42 | + .like( | ||
43 | + intranetIp != null, | ||
44 | + TkDeviceAccessInformationEntity::getIntranetIp,intranetIp) | ||
45 | + .eq( | ||
46 | + intranetPort != null, | ||
47 | + TkDeviceAccessInformationEntity::getIntranetPort,intranetPort) | ||
48 | + .like( | ||
49 | + outerNetIp != null, | ||
50 | + TkDeviceAccessInformationEntity::getOuterNetIp,outerNetIp) | ||
51 | + .eq( | ||
52 | + outerNetPort != null, | ||
53 | + TkDeviceAccessInformationEntity::getOuterNetPort,outerNetPort) | ||
54 | + .eq( | ||
55 | + deviceAgreement != null, | ||
56 | + TkDeviceAccessInformationEntity::getDeviceAgreement,deviceAgreement) | ||
57 | + ); | ||
58 | + return getPageData(iPage, TkDeviceAccessInformationDTO.class); | ||
59 | + } | ||
60 | + | ||
61 | + @Override | ||
62 | + public TkDeviceAccessInformationDTO saveOrUpdate(TkDeviceAccessInformationDTO dto ) { | ||
63 | + //内网重复校验 | ||
64 | + TkDeviceAccessInformationEntity intranet = baseMapper.selectOne(new LambdaQueryWrapper<TkDeviceAccessInformationEntity>() | ||
65 | + .eq(TkDeviceAccessInformationEntity::getIntranetIp, dto.getIntranetIp()) | ||
66 | + .eq(TkDeviceAccessInformationEntity::getIntranetPort,dto.getIntranetPort())); | ||
67 | + if(intranet!=null&&(StringUtils.isEmpty(dto.getId()) || !intranet.getId().equals(dto.getId()))){ | ||
68 | + throw new TkDataValidationException(ErrorMessage.INTRANET_ERROR.getMessage()); | ||
69 | + } | ||
70 | + //外网重复校验 | ||
71 | + TkDeviceAccessInformationEntity outerNet = baseMapper.selectOne(new LambdaQueryWrapper<TkDeviceAccessInformationEntity>() | ||
72 | + .eq(TkDeviceAccessInformationEntity::getOuterNetIp, dto.getOuterNetIp()) | ||
73 | + .eq(TkDeviceAccessInformationEntity::getOuterNetPort,dto.getOuterNetPort())); | ||
74 | + if(outerNet!=null&&(StringUtils.isEmpty(dto.getId()) || !outerNet.getId().equals(dto.getId()))){ | ||
75 | + throw new TkDataValidationException(ErrorMessage.OUTER_NET_ERROR.getMessage()); | ||
76 | + } | ||
77 | + LambdaQueryWrapper<TkDeviceAccessInformationEntity> filter = new QueryWrapper<TkDeviceAccessInformationEntity>().lambda() | ||
78 | + .eq(TkDeviceAccessInformationEntity::getId, dto.getId()); | ||
79 | + TkDeviceAccessInformationEntity old = baseMapper.selectOne(filter); | ||
80 | + TkDeviceAccessInformationEntity newData = dto.getEntity(TkDeviceAccessInformationEntity.class); | ||
81 | + if (old == null) { | ||
82 | + baseMapper.insert(newData); | ||
83 | + }else { | ||
84 | + baseMapper.update(newData, filter); | ||
85 | + } | ||
86 | + return dto; | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + @Transactional | ||
91 | + public boolean delete(DeleteDTO dto) { | ||
92 | + int result = | ||
93 | + baseMapper.delete( | ||
94 | + new LambdaQueryWrapper<TkDeviceAccessInformationEntity>() | ||
95 | + .eq(TkDeviceAccessInformationEntity::getTenantId, dto.getTenantId()) | ||
96 | + .in(TkDeviceAccessInformationEntity::getId, dto.getIds())); | ||
97 | + if (result > FastIotConstants.MagicNumber.ZERO && result != dto.getIds().size()) { | ||
98 | + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
99 | + } | ||
100 | + return result > FastIotConstants.MagicNumber.ZERO; | ||
101 | + } | ||
102 | +} |
dao/src/main/java/org/thingsboard/server/dao/yunteng/mapper/TkDeviceAccessInformationMapper.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.mapper; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
4 | +import org.apache.ibatis.annotations.Mapper; | ||
5 | +import org.thingsboard.server.dao.yunteng.entities.TkDeviceAccessInformationEntity; | ||
6 | +import org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileCategoryEntity; | ||
7 | + | ||
8 | +@Mapper | ||
9 | +public interface TkDeviceAccessInformationMapper extends BaseMapper<TkDeviceAccessInformationEntity> { | ||
10 | + | ||
11 | +} |
dao/src/main/java/org/thingsboard/server/dao/yunteng/service/TkDeviceAccessInformationService.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.service; | ||
2 | + | ||
3 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
4 | +import org.thingsboard.server.common.data.yunteng.dto.TkDeviceAccessInformationDTO; | ||
5 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | ||
6 | + | ||
7 | +import java.util.Map; | ||
8 | + | ||
9 | +public interface TkDeviceAccessInformationService { | ||
10 | + | ||
11 | + TkPageData<TkDeviceAccessInformationDTO> page(Map<String, Object> queryMap); | ||
12 | + | ||
13 | + TkDeviceAccessInformationDTO saveOrUpdate(TkDeviceAccessInformationDTO sysDictDTO); | ||
14 | + | ||
15 | + boolean delete(DeleteDTO dto); | ||
16 | + | ||
17 | +} |