Commit 71c6d65195c0151031a1f79179de828a1c77c1ef

Authored by xp.Huang
2 parents 59149c28 ec6ad557

Merge branch '2024-2-19' into 'master_dev'

feat:新增设备接入信息

See merge request yunteng/thingskit!341
... ... @@ -5,7 +5,6 @@ import io.swagger.annotations.ApiOperation;
5 5 import io.swagger.annotations.ApiParam;
6 6 import lombok.RequiredArgsConstructor;
7 7 import org.springframework.http.ResponseEntity;
8   -import org.springframework.security.access.prepost.PreAuthorize;
9 8 import org.springframework.validation.annotation.Validated;
10 9 import org.springframework.web.bind.annotation.*;
11 10 import org.thingsboard.server.common.data.exception.ThingsboardException;
... ... @@ -65,7 +64,6 @@ public class TkDataViewInterfaceController extends BaseController {
65 64
66 65 @PostMapping
67 66 @ApiOperation("新增")
68   - @PreAuthorize("@check.checkPermissions({},{})")
69 67 public ResponseEntity<TkDataViewInterfaceDTO> save(
70 68 @Validated({AddGroup.class}) @RequestBody TkDataViewInterfaceDTO tkDataViewInterfaceDTO)
71 69 throws ThingsboardException {
... ... @@ -77,7 +75,6 @@ public class TkDataViewInterfaceController extends BaseController {
77 75
78 76 @PutMapping
79 77 @ApiOperation("修改")
80   - @PreAuthorize("@check.checkPermissions({},{})")
81 78 public ResponseEntity<TkDataViewInterfaceDTO> update(
82 79 @Validated({UpdateGroup.class}) @RequestBody TkDataViewInterfaceDTO TkDataViewInterfaceDTO)
83 80 throws ThingsboardException {
... ... @@ -88,7 +85,6 @@ public class TkDataViewInterfaceController extends BaseController {
88 85
89 86 @DeleteMapping
90 87 @ApiOperation("删除")
91   - @PreAuthorize("@check.checkPermissions({},{})")
92 88 public ResponseEntity<Boolean> delete(
93 89 @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)
94 90 throws ThingsboardException {
... ... @@ -98,7 +94,6 @@ public class TkDataViewInterfaceController extends BaseController {
98 94
99 95 @GetMapping("/publish/{id}")
100 96 @ApiOperation("发布")
101   - @PreAuthorize("@check.checkPermissions({},{})")
102 97 public ResponseEntity<Boolean> publishInterface(@PathVariable("id") String id)
103 98 throws ThingsboardException {
104 99 return ResponseEntity.ok(
... ... @@ -107,7 +102,6 @@ public class TkDataViewInterfaceController extends BaseController {
107 102
108 103 @GetMapping("/cancel_publish/{id}")
109 104 @ApiOperation("取消发布")
110   - @PreAuthorize("@check.checkPermissions({},{})")
111 105 public ResponseEntity<Boolean> cancelPublishInterface(@PathVariable("id") String id)
112 106 throws ThingsboardException {
113 107 return ResponseEntity.ok(
... ... @@ -116,7 +110,6 @@ public class TkDataViewInterfaceController extends BaseController {
116 110 }
117 111
118 112 @ApiOperation("根据接口ID,获得接口详情")
119   - @PreAuthorize("@check.checkPermissions({},{})")
120 113 @RequestMapping(
121 114 value = "/get_interface_details",
122 115 params = {"ids"},
... ... @@ -130,7 +123,6 @@ public class TkDataViewInterfaceController extends BaseController {
130 123
131 124 @GetMapping("/filter_by_interface_type/{type}")
132 125 @ApiOperation("根据接口类型过滤数据")
133   - @PreAuthorize("@check.checkPermissions({},{})")
134 126 public List<TkDataViewInterfaceDTO> filterByInterfaceType(@PathVariable("type") String type)
135 127 throws ThingsboardException {
136 128 return tkDataViewInterfaceService.filterByInterfaceType(
... ... @@ -139,7 +131,6 @@ public class TkDataViewInterfaceController extends BaseController {
139 131
140 132 @GetMapping("/find_all_interface/{state}")
141 133 @ApiOperation("查询所有接口")
142   - @PreAuthorize("@check.checkPermissions({},{})")
143 134 public List<TkDataViewInterfaceDTO> findAll(@PathVariable("state") String state)
144 135 throws ThingsboardException {
145 136 return tkDataViewInterfaceService.findAll(state, getCurrentUser().getCurrentTenantId());
... ... @@ -147,7 +138,6 @@ public class TkDataViewInterfaceController extends BaseController {
147 138
148 139 @GetMapping("/find/can_use_interfaces")
149 140 @ApiOperation("查询当前用户可使用的接口")
150   - @PreAuthorize("@check.checkPermissions({},{})")
151 141 public List<TkDataViewInterfaceDTO> findCanUseInterfaces() throws ThingsboardException {
152 142 boolean isSysAdminOrPtAdmin = getCurrentUser().isPtAdmin() || getCurrentUser().isSystemAdmin();
153 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 134 /** 产品品类表 */
135 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 140 /** ZLMediaKit 流媒体表 */
138 141 public static final String TK_MEDIA_SERVER_NAME = "tk_media_server";
139 142
... ...
... ... @@ -131,6 +131,8 @@ public enum ErrorMessage {
131 131 SIP_COMMAND_SEND_FAILED(400106,"sip命令下发失败"),
132 132 NOT_BELONG_CURRENT_CUSTOMER(400107,"该数据不属于当前客户"),
133 133 IMPORT_ERROR(400108,"请使用模板excel重新导入"),
  134 + INTRANET_ERROR(400109,"内网ip+端口不能重复,请重新输入"),
  135 + OUTER_NET_ERROR(400110,"外网ip+端口不能重复,请重新输入"),
134 136 HAVE_NO_PERMISSION(500002,"没有修改权限"),
135 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 +}
... ...
  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 +}
... ...
  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 +}
... ...
  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 +}
... ...
  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 +}
... ...