diff --git a/.claude/settings.local.json b/.claude/settings.local.json deleted file mode 100644 index 9a8e9dae..00000000 --- a/.claude/settings.local.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "permissions": { - "allow": [ - "Bash(python3 -c \"import pdfplumber; pdf = pdfplumber.open\\('D:/SoftProject/Java/fastbee/docs/platform/DCP接口文档\\(轴力计\\).pdf'\\); [print\\(p.extract_text\\(\\)\\) for p in pdf.pages[:15]]; pdf.close\\(\\)\")", - "Bash(mvn compile *)" - ] - } -} diff --git a/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformApiController.java b/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformApiController.java index 005ac305..01b39d2e 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformApiController.java +++ b/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformApiController.java @@ -64,12 +64,4 @@ public class PlatformApiController extends BaseController { public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(platformApiService.deletePlatformApiByIds(ids)); } - - @PreAuthorize("@ss.hasPermi('iot:platformConnect:api:edit')") - @PostMapping("/test") - @ApiOperation("测试接口连通性(使用当前表单数据,不依赖已保存记录)") - public AjaxResult test(@RequestBody PlatformApi platformApi, - @RequestParam(required = false) Long tenantChannelId) { - return success(platformApiService.testApi(platformApi, tenantChannelId)); - } } diff --git a/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformBindingController.java b/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformBindingController.java index cb7f1e0b..7e3e89a2 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformBindingController.java +++ b/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformBindingController.java @@ -44,11 +44,7 @@ public class PlatformBindingController extends BaseController { @PostMapping @ApiOperation("新增设备绑定") public AjaxResult add(@RequestBody PlatformBinding binding) { - Boolean result = platformBindingService.insertPlatformBinding(binding); - if (result) { - return success(binding.getId()); - } - return error("新增失败"); + return toAjax(platformBindingService.insertPlatformBinding(binding)); } @PreAuthorize("@ss.hasPermi('iot:platformConnect:binding:edit')") @@ -66,11 +62,4 @@ public class PlatformBindingController extends BaseController { public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(platformBindingService.deletePlatformBindingByIds(ids)); } - - @PreAuthorize("@ss.hasPermi('iot:platformConnect:binding:edit')") - @PostMapping("/generateDefaultMappings") - @ApiOperation("根据设备类型生成默认字段映射") - public AjaxResult generateDefaultMappings(@RequestParam Long bindingId, @RequestParam String deviceType) { - return success(platformBindingService.generateDefaultMappings(bindingId, deviceType)); - } } diff --git a/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformTenantChannelController.java b/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformTenantChannelController.java index 2ee780dd..14951d11 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformTenantChannelController.java +++ b/fastbee-open-api/src/main/java/com/fastbee/controller/platform/PlatformTenantChannelController.java @@ -64,15 +64,4 @@ public class PlatformTenantChannelController extends BaseController { public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(platformTenantChannelService.deletePlatformTenantChannelByIds(ids)); } - - @PreAuthorize("@ss.hasPermi('iot:platformConnect:tenantChannel:edit')") - @PostMapping("/fetchRemoteInfo") - @ApiOperation("获取第三方平台远程信息(用户ID、项目列表)") - public AjaxResult fetchRemoteInfo(@RequestBody PlatformTenantChannel tenantChannel) { - try { - return success(platformTenantChannelService.fetchRemoteInfo(tenantChannel)); - } catch (Exception e) { - return error(e.getMessage()); - } - } } diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformApiService.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformApiService.java index 27e02243..79e8b1ca 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformApiService.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformApiService.java @@ -2,7 +2,6 @@ package com.fastbee.iot.platform.service; import com.baomidou.mybatisplus.extension.service.IService; import com.fastbee.iot.platform.domain.PlatformApi; -import com.fastbee.iot.platform.model.PlatformHttpResponse; import java.util.List; @@ -16,6 +15,4 @@ public interface IPlatformApiService extends IService { Boolean updatePlatformApi(PlatformApi entity); Boolean deletePlatformApiByIds(Long[] ids); - - PlatformHttpResponse testApi(PlatformApi api, Long tenantChannelId); } diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformBindingService.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformBindingService.java index 30b4f486..69acb824 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformBindingService.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformBindingService.java @@ -2,7 +2,6 @@ package com.fastbee.iot.platform.service; import com.baomidou.mybatisplus.extension.service.IService; import com.fastbee.iot.platform.domain.PlatformBinding; -import com.fastbee.iot.platform.domain.PlatformFieldMapping; import java.util.List; @@ -16,9 +15,4 @@ public interface IPlatformBindingService extends IService { Boolean updatePlatformBinding(PlatformBinding entity); Boolean deletePlatformBindingByIds(Long[] ids); - - /** - * 根据设备类型生成默认字段映射 - */ - List generateDefaultMappings(Long bindingId, String deviceType); } diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformTenantChannelService.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformTenantChannelService.java index bf1c12df..d32a3d68 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformTenantChannelService.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/IPlatformTenantChannelService.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.fastbee.iot.platform.domain.PlatformTenantChannel; import java.util.List; -import java.util.Map; public interface IPlatformTenantChannelService extends IService { List selectPlatformTenantChannelList(PlatformTenantChannel query); @@ -16,9 +15,4 @@ public interface IPlatformTenantChannelService extends IService fetchRemoteInfo(PlatformTenantChannel tenantChannel); } diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/PlatformHttpClient.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/PlatformHttpClient.java index ec0d19aa..d4fecb17 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/PlatformHttpClient.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/PlatformHttpClient.java @@ -101,7 +101,25 @@ public class PlatformHttpClient { // 7. 设置 Body String contentType = StringUtils.isNotEmpty(api.getContentType()) ? api.getContentType() : "application/json"; - applyBody(request, api.getBodyTemplate(), contentType, variables, result); + String body = buildBody(api.getBodyTemplate(), contentType, variables); + if (StringUtils.isNotEmpty(body)) { + if (contentType.contains("json")) { + request.addHeader("Content-Type", "application/json"); + request.addBody(body); + } else if (contentType.contains("form")) { + request.addHeader("Content-Type", "application/x-www-form-urlencoded"); + JSONObject formData = JSON.parseObject(body); + if (formData != null) { + for (Map.Entry entry : formData.entrySet()) { + request.addBody(entry.getKey(), entry.getValue()); + } + } + } else { + request.addHeader("Content-Type", contentType); + request.addBody(body); + } + result.setRequestBody(body); + } // 8. 执行请求 ForestResponse response = request.execute(ForestResponse.class); @@ -152,62 +170,7 @@ public class PlatformHttpClient { } /** - * 解析 bodyTemplate 并设置到请求中 - * bodyTemplate 可能是: - * 1. null/空 — 无 body - * 2. 带 mode 字段的 JSON:{"mode":"x-www-form-urlencoded","urlencoded":[...]} 或 {"mode":"form-data","formData":[...]} - * 3. 普通 JSON 字符串(raw-json 模式直接存的原始内容) - */ - private void applyBody(ForestRequest request, String bodyTemplate, String contentType, - Map variables, PlatformHttpResponse result) { - if (StringUtils.isEmpty(bodyTemplate)) { - return; - } - try { - JSONObject parsed = JSON.parseObject(bodyTemplate); - String mode = parsed != null ? parsed.getString("mode") : null; - if ("x-www-form-urlencoded".equals(mode) || "form-data".equals(mode)) { - // 取 urlencoded 或 formData 数组,转为 key-value 表单参数 - String arrayKey = "x-www-form-urlencoded".equals(mode) ? "urlencoded" : "formData"; - com.alibaba.fastjson2.JSONArray rows = parsed.getJSONArray(arrayKey); - if (rows != null && !rows.isEmpty()) { - request.addHeader("Content-Type", "application/x-www-form-urlencoded"); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < rows.size(); i++) { - JSONObject row = rows.getJSONObject(i); - if (row == null) continue; - Boolean enabled = row.getBoolean("enabled"); - if (Boolean.FALSE.equals(enabled)) continue; - String key = row.getString("key"); - String value = row.getString("value"); - if (StringUtils.isEmpty(key)) continue; - value = substituteVariables(value != null ? value : "", variables); - request.addBody(key, value); - if (sb.length() > 0) sb.append('&'); - sb.append(key).append('=').append(value); - } - result.setRequestBody(sb.toString()); - } - return; - } - } catch (Exception ignored) { - // 不是 JSON 或无 mode 字段,按 raw 处理 - } - // raw-json 或普通文本 - String body = substituteVariables(bodyTemplate, variables); - if (StringUtils.isNotEmpty(body)) { - if (contentType.contains("json")) { - request.addHeader("Content-Type", "application/json"); - } else { - request.addHeader("Content-Type", contentType); - } - request.addBody(body); - result.setRequestBody(body); - } - } - - /** - * 构建请求体(保留兼容旧调用,内部不再使用) + * 构建请求体 */ private String buildBody(String bodyTemplate, String contentType, Map variables) { if (StringUtils.isEmpty(bodyTemplate)) { diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/PlatformTokenService.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/PlatformTokenService.java index 9bd4be24..adb0b84f 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/PlatformTokenService.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/PlatformTokenService.java @@ -60,12 +60,6 @@ public class PlatformTokenService { if (authConfig.containsKey("expiresIn")) { expiresIn = authConfig.getIntValue("expiresIn"); } - } else if ("oauth2_password".equals(authType)) { - JSONObject result2 = acquireOAuth2PasswordToken(tenantChannel.getBaseUrl(), authConfig); - token = result2.getString("token"); - if (result2.containsKey("expiresIn")) { - expiresIn = result2.getIntValue("expiresIn"); - } } else if ("custom_token".equals(authType)) { JSONObject result = acquireCustomToken(tenantChannel.getBaseUrl(), authConfig); token = result.getString("token"); @@ -184,44 +178,6 @@ public class PlatformTokenService { throw new RuntimeException("自定义 token 获取失败: " + response.getContent()); } - /** - * OAuth2 password 模式获取 token(DCP 风格:form-urlencoded,grant_type=password) - * authConfig 需包含: tokenUrl, userName, password, clientId, scope - */ - private JSONObject acquireOAuth2PasswordToken(String baseUrl, JSONObject authConfig) { - String tokenUrl = resolveTokenUrl(baseUrl, authConfig.getString("tokenUrl")); - String clientId = authConfig.getString("clientId"); - String userName = authConfig.getString("userName"); - String password = authConfig.getString("password"); - String scope = authConfig.getString("scope"); - - ForestRequest request = Forest.request(); - request.setUrl(tokenUrl); - request.setType(ForestRequestType.POST); - request.addHeader("Content-Type", "application/x-www-form-urlencoded"); - request.addBody("grant_type", "password"); - if (StringUtils.isNotEmpty(clientId)) { - request.addBody("client_id", clientId); - } - if (StringUtils.isNotEmpty(scope)) { - request.addBody("scope", scope); - } - request.addBody("userName", userName); - request.addBody("password", password); - - ForestResponse response = request.execute(ForestResponse.class); - if (response.isSuccess()) { - JSONObject body = JSON.parseObject(response.getContent()); - JSONObject result = new JSONObject(); - result.put("token", body.getString("access_token")); - if (body.containsKey("expires_in")) { - result.put("expiresIn", body.getIntValue("expires_in")); - } - return result; - } - throw new RuntimeException("OAuth2 password token 获取失败: " + response.getContent()); - } - /** * 解析 authConfig JSON */ diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformApiServiceImpl.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformApiServiceImpl.java index 0befef33..eeb7c613 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformApiServiceImpl.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformApiServiceImpl.java @@ -6,33 +6,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fastbee.common.utils.DateUtils; import com.fastbee.common.utils.StringUtils; import com.fastbee.iot.platform.domain.PlatformApi; -import com.fastbee.iot.platform.domain.PlatformTemplate; -import com.fastbee.iot.platform.domain.PlatformTenantChannel; import com.fastbee.iot.platform.mapper.PlatformApiMapper; -import com.fastbee.iot.platform.model.PlatformHttpResponse; import com.fastbee.iot.platform.service.IPlatformApiService; -import com.fastbee.iot.platform.service.IPlatformTemplateService; -import com.fastbee.iot.platform.service.IPlatformTenantChannelService; -import com.fastbee.iot.platform.service.PlatformHttpClient; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import java.util.Arrays; -import java.util.Collections; import java.util.List; @Service public class PlatformApiServiceImpl extends ServiceImpl implements IPlatformApiService { - @Resource - private IPlatformTemplateService platformTemplateService; - - @Resource - private IPlatformTenantChannelService platformTenantChannelService; - - @Resource - private PlatformHttpClient platformHttpClient; - @Override public List selectPlatformApiList(PlatformApi query) { LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); @@ -67,35 +50,4 @@ public class PlatformApiServiceImpl extends ServiceImpl lqw = Wrappers.lambdaQuery(); - lqw.eq(PlatformTenantChannel::getTemplateId, api.getTemplateId()); - lqw.last("LIMIT 1"); - channel = platformTenantChannelService.getOne(lqw); - } - if (channel == null) { - channel = new PlatformTenantChannel(); - channel.setBaseUrl(template.getBaseUrlTemplate()); - } - return platformHttpClient.call(channel, template, api, Collections.emptyMap()); - } } diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformBindingServiceImpl.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformBindingServiceImpl.java index 460ca7b2..13d51543 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformBindingServiceImpl.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformBindingServiceImpl.java @@ -6,21 +6,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fastbee.common.utils.DateUtils; import com.fastbee.common.utils.StringUtils; import com.fastbee.iot.platform.domain.PlatformBinding; -import com.fastbee.iot.platform.domain.PlatformFieldMapping; import com.fastbee.iot.platform.mapper.PlatformBindingMapper; -import com.fastbee.iot.platform.mapper.PlatformFieldMappingMapper; import com.fastbee.iot.platform.service.IPlatformBindingService; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.*; +import java.util.Arrays; +import java.util.List; @Service public class PlatformBindingServiceImpl extends ServiceImpl implements IPlatformBindingService { - @Resource - private PlatformFieldMappingMapper fieldMappingMapper; - @Override public List selectPlatformBindingList(PlatformBinding query) { LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); @@ -61,67 +56,4 @@ public class PlatformBindingServiceImpl extends ServiceImpl generateDefaultMappings(Long bindingId, String deviceType) { - // 先检查是否已有映射 - LambdaQueryWrapper existQuery = Wrappers.lambdaQuery(); - existQuery.eq(PlatformFieldMapping::getBindingId, bindingId); - Long existCount = fieldMappingMapper.selectCount(existQuery); - if (existCount > 0) { - // 已有映射,直接返回现有列表 - return fieldMappingMapper.selectList(existQuery); - } - - // 根据设备类型生成默认映射 - List mappings = buildDefaultMappings(deviceType); - int sortOrder = 1; - for (PlatformFieldMapping mapping : mappings) { - mapping.setBindingId(bindingId); - mapping.setDirection("OUTBOUND"); - mapping.setSortOrder(sortOrder++); - mapping.setStatus(1); - fieldMappingMapper.insert(mapping); - } - return mappings; - } - - private List buildDefaultMappings(String deviceType) { - List list = new ArrayList<>(); - switch (deviceType) { - case "RAIN": - list.add(createMapping("THING_MODEL", "rainfall", "累计雨量", "value", "雨量值", "DIRECT")); - list.add(createMapping("THING_MODEL", "temperature", "温度", "temperature", "温度", "DIRECT")); - break; - case "TILT": - list.add(createMapping("THING_MODEL", "xAngle", "X轴角度", "xDeg", "X轴角度", "DIRECT")); - list.add(createMapping("THING_MODEL", "yAngle", "Y轴角度", "yDeg", "Y轴角度", "DIRECT")); - list.add(createMapping("THING_MODEL", "zAngle", "Z轴角度", "zDeg", "Z轴角度", "DIRECT")); - list.add(createMapping("THING_MODEL", "temperature", "温度", "temperature", "温度", "DIRECT")); - break; - case "STATIC_LEVEL": - list.add(createMapping("THING_MODEL", "height", "液位高度", "height", "液位高度", "DIRECT")); - list.add(createMapping("THING_MODEL", "temperature", "温度", "temperature", "温度", "DIRECT")); - break; - case "AXIAL_FORCE": - list.add(createMapping("THING_MODEL", "strain", "应变值", "e", "应变值", "DIRECT")); - break; - default: - break; - } - return list; - } - - private PlatformFieldMapping createMapping(String sourceType, String sourceKey, String sourceName, - String targetPath, String targetName, String transformType) { - PlatformFieldMapping mapping = new PlatformFieldMapping(); - mapping.setSourceType(sourceType); - mapping.setSourceKey(sourceKey); - mapping.setSourceName(sourceName); - mapping.setTargetPath(targetPath); - mapping.setTargetName(targetName); - mapping.setTransformType(transformType); - mapping.setRequired(1); - return mapping; - } } diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformTenantChannelServiceImpl.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformTenantChannelServiceImpl.java index 314dc16f..b6a07e87 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformTenantChannelServiceImpl.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/platform/service/impl/PlatformTenantChannelServiceImpl.java @@ -1,39 +1,21 @@ package com.fastbee.iot.platform.service.impl; -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONArray; -import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.dtflys.forest.Forest; -import com.dtflys.forest.http.ForestRequest; -import com.dtflys.forest.http.ForestRequestType; -import com.dtflys.forest.http.ForestResponse; import com.fastbee.common.utils.DateUtils; import com.fastbee.common.utils.StringUtils; -import com.fastbee.iot.platform.domain.PlatformTemplate; import com.fastbee.iot.platform.domain.PlatformTenantChannel; import com.fastbee.iot.platform.mapper.PlatformTenantChannelMapper; import com.fastbee.iot.platform.service.IPlatformTenantChannelService; -import com.fastbee.iot.platform.service.IPlatformTemplateService; -import com.fastbee.iot.platform.service.PlatformTokenService; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.*; +import java.util.Arrays; +import java.util.List; -@Slf4j @Service public class PlatformTenantChannelServiceImpl extends ServiceImpl implements IPlatformTenantChannelService { - @Resource - private PlatformTokenService platformTokenService; - - @Resource - private IPlatformTemplateService platformTemplateService; - @Override public List selectPlatformTenantChannelList(PlatformTenantChannel query) { LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); @@ -71,75 +53,4 @@ public class PlatformTenantChannelServiceImpl extends ServiceImpl fetchRemoteInfo(PlatformTenantChannel tenantChannel) { - Map result = new HashMap<>(); - - // 获取模板信息 - PlatformTemplate template = platformTemplateService.selectPlatformTemplateById(tenantChannel.getTemplateId()); - if (template == null) { - throw new RuntimeException("平台模板不存在"); - } - - // 获取 token - String token = platformTokenService.getToken(tenantChannel, template); - if (StringUtils.isEmpty(token)) { - throw new RuntimeException("获取平台 token 失败,请检查凭证配置"); - } - - String baseUrl = StringUtils.isNotEmpty(tenantChannel.getBaseUrl()) ? tenantChannel.getBaseUrl() : template.getBaseUrlTemplate(); - if (StringUtils.isEmpty(baseUrl)) { - throw new RuntimeException("baseUrl 未配置"); - } - baseUrl = baseUrl.endsWith("/") ? baseUrl.substring(0, baseUrl.length() - 1) : baseUrl; - - // 1. 获取用户信息 - String userUrl = baseUrl + "/api/app/user/user-id"; - ForestRequest userRequest = Forest.request(); - userRequest.setUrl(userUrl); - userRequest.setType(ForestRequestType.GET); - userRequest.addHeader("Authorization", "Bearer " + token); - ForestResponse userResponse = userRequest.execute(ForestResponse.class); - - if (!userResponse.isSuccess()) { - throw new RuntimeException("获取用户信息失败: " + userResponse.getContent()); - } - - JSONObject userInfo = JSON.parseObject(userResponse.getContent()); - String userId = userInfo.getString("id"); - String userName = userInfo.getString("userName"); - result.put("userId", userId); - result.put("userName", userName); - - // 2. 获取项目列表 - if (StringUtils.isNotEmpty(userId)) { - String projectUrl = baseUrl + "/api/app/project/by-user-id/" + userId; - ForestRequest projectRequest = Forest.request(); - projectRequest.setUrl(projectUrl); - projectRequest.setType(ForestRequestType.GET); - projectRequest.addHeader("Authorization", "Bearer " + token); - ForestResponse projectResponse = projectRequest.execute(ForestResponse.class); - - if (projectResponse.isSuccess()) { - JSONArray projects = JSON.parseArray(projectResponse.getContent()); - List> projectList = new ArrayList<>(); - if (projects != null) { - for (int i = 0; i < projects.size(); i++) { - JSONObject proj = projects.getJSONObject(i); - Map item = new HashMap<>(); - item.put("id", proj.getString("id")); - item.put("name", proj.getString("name")); - projectList.add(item); - } - } - result.put("projects", projectList); - } else { - log.warn("获取项目列表失败: {}", projectResponse.getContent()); - result.put("projects", Collections.emptyList()); - } - } - - return result; - } } diff --git a/sql/iot_platform_connect_menu_upgrade.sql b/sql/iot_platform_connect_menu_upgrade.sql deleted file mode 100644 index 727d99ab..00000000 --- a/sql/iot_platform_connect_menu_upgrade.sql +++ /dev/null @@ -1,20 +0,0 @@ --- ===================================================================== --- 平台对接菜单重组:8个平级菜单 → 3个主入口 + 1个"高级配置"子目录 --- 执行前提:已执行过 iot_platform_connect.sql(菜单已存在) --- ===================================================================== - --- 1. 新增"高级配置"目录(menu_id=3580, parent=3500) -INSERT IGNORE INTO `sys_menu` (menu_id, menu_name, parent_id, order_num, `path`, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) -VALUES (3580, '高级配置', 3500, 4, 'advanced', NULL, NULL, 1, 0, 'M', '0', '0', '', 'system', 'admin', NOW(), 'admin', NOW(), '平台对接高级配置目录'); - --- 2. 主入口菜单调整(直接挂在3500下,调整排序和名称) -UPDATE `sys_menu` SET `menu_name` = '连接管理', `order_num` = 1, `icon` = 'peoples' WHERE `menu_id` = 3540; -UPDATE `sys_menu` SET `order_num` = 2 WHERE `menu_id` = 3560; -UPDATE `sys_menu` SET `menu_name` = '推送记录', `order_num` = 3, `icon` = 'log' WHERE `menu_id` = 3510; - --- 3. 高级配置子菜单(parent_id 改为3580) -UPDATE `sys_menu` SET `parent_id` = 3580, `order_num` = 1 WHERE `menu_id` = 3501; -UPDATE `sys_menu` SET `parent_id` = 3580, `order_num` = 2 WHERE `menu_id` = 3520; -UPDATE `sys_menu` SET `parent_id` = 3580, `order_num` = 3 WHERE `menu_id` = 3530; -UPDATE `sys_menu` SET `parent_id` = 3580, `order_num` = 4 WHERE `menu_id` = 3550; -UPDATE `sys_menu` SET `parent_id` = 3580, `order_num` = 5 WHERE `menu_id` = 3570; diff --git a/yack-web/src/api/iot/platformConnect/api.js b/yack-web/src/api/iot/platformConnect/api.js index 7cb58b00..f28cdff5 100644 --- a/yack-web/src/api/iot/platformConnect/api.js +++ b/yack-web/src/api/iot/platformConnect/api.js @@ -19,12 +19,3 @@ export function updateApi(data) { export function delApi(id) { return request({ url: '/iot/platformConnect/api/' + id, method: 'delete' }) } - -export function testApi(data, tenantChannelId) { - return request({ - url: '/iot/platformConnect/api/test', - method: 'post', - params: tenantChannelId ? { tenantChannelId } : {}, - data: data - }) -} diff --git a/yack-web/src/api/iot/platformConnect/binding.js b/yack-web/src/api/iot/platformConnect/binding.js index ba296367..89cc1707 100644 --- a/yack-web/src/api/iot/platformConnect/binding.js +++ b/yack-web/src/api/iot/platformConnect/binding.js @@ -19,7 +19,3 @@ export function updateBinding(data) { export function delBinding(id) { return request({ url: '/iot/platformConnect/binding/' + id, method: 'delete' }) } - -export function generateDefaultMappings(bindingId, deviceType) { - return request({ url: '/iot/platformConnect/binding/generateDefaultMappings', method: 'post', params: { bindingId, deviceType } }) -} diff --git a/yack-web/src/api/iot/platformConnect/tenantChannel.js b/yack-web/src/api/iot/platformConnect/tenantChannel.js index d278f75f..9cbfc126 100644 --- a/yack-web/src/api/iot/platformConnect/tenantChannel.js +++ b/yack-web/src/api/iot/platformConnect/tenantChannel.js @@ -19,7 +19,3 @@ export function updateTenantChannel(data) { export function delTenantChannel(id) { return request({ url: '/iot/platformConnect/tenantChannel/' + id, method: 'delete' }) } - -export function fetchRemoteInfo(data) { - return request({ url: '/iot/platformConnect/tenantChannel/fetchRemoteInfo', method: 'post', data: data }) -} diff --git a/yack-web/src/assets/icons/svg/api.svg b/yack-web/src/assets/icons/svg/api.svg deleted file mode 100644 index f32ed877..00000000 --- a/yack-web/src/assets/icons/svg/api.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/yack-web/src/views/iot/platformConnect/api/index.vue b/yack-web/src/views/iot/platformConnect/api/index.vue index 8fa5b47c..6926933a 100644 --- a/yack-web/src/views/iot/platformConnect/api/index.vue +++ b/yack-web/src/views/iot/platformConnect/api/index.vue @@ -102,45 +102,21 @@ - - + + -
- - - {{ testResult.requestUrl }} - {{ testResult.statusCode }} - {{ testResult.durationMs }} ms - {{ testResult.errorMessage }} - -
-
请求体
-
{{ formatJson(testResult.requestBody) }}
-
-
-
响应体
-
{{ formatJson(testResult.body) }}
-
-
- diff --git a/yack-web/src/views/iot/platformConnect/components/HttpRequestDesigner.vue b/yack-web/src/views/iot/platformConnect/components/HttpRequestDesigner.vue index 24a53915..02fbc38d 100644 --- a/yack-web/src/views/iot/platformConnect/components/HttpRequestDesigner.vue +++ b/yack-web/src/views/iot/platformConnect/components/HttpRequestDesigner.vue @@ -1,21 +1,21 @@ @@ -98,40 +65,8 @@ export default { return { activeTab: 'params', methodOptions: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], - importJsonDialogVisible: false, - importJsonText: '', - importJsonError: '', }; }, - methods: { - flushEditors() { - ['paramsEditor', 'headersEditor', 'configEditor', 'formDataEditor', 'urlencodedEditor'].forEach(refName => { - const editor = this.$refs[refName]; - if (editor && typeof editor.flushBulk === 'function') { - editor.flushBulk(); - } - }); - }, - confirmImportJson() { - const text = this.importJsonText.trim(); - if (!text) { - this.importJsonError = '内容不能为空'; - return; - } - // 将模板变量临时替换为合法值再做 JSON 校验 - const sanitized = text.replace(/\$\{[^}]+\}/g, '"__var__"'); - try { - JSON.parse(sanitized); - } catch (e) { - this.importJsonError = 'JSON 格式不正确:' + e.message; - return; - } - this.designer.body.raw = text; - this.importJsonDialogVisible = false; - this.importJsonText = ''; - this.importJsonError = ''; - }, - }, computed: { designer: { get() { @@ -149,60 +84,9 @@ export default { diff --git a/yack-web/src/views/iot/platformConnect/tenantChannel/index.vue b/yack-web/src/views/iot/platformConnect/tenantChannel/index.vue index c8f6f42f..de11ab14 100644 --- a/yack-web/src/views/iot/platformConnect/tenantChannel/index.vue +++ b/yack-web/src/views/iot/platformConnect/tenantChannel/index.vue @@ -1,16 +1,8 @@ - - diff --git a/yack-web/src/views/iot/platformConnect/utils/requestTemplate.js b/yack-web/src/views/iot/platformConnect/utils/requestTemplate.js index b99767f9..dc91b9b0 100644 --- a/yack-web/src/views/iot/platformConnect/utils/requestTemplate.js +++ b/yack-web/src/views/iot/platformConnect/utils/requestTemplate.js @@ -1,50 +1,3 @@ -/** 键值行 -> Postman 风格批量文本(每行 key:value) */ -export function rowsToBulkText(rows) { - return (rows || []) - .map(item => { - if (!item || !item.key) { - return ''; - } - const prefix = item.enabled === false ? '#' : ''; - const value = item.value == null ? '' : String(item.value); - return `${prefix}${item.key}:${value}`; - }) - .filter(Boolean) - .join('\n'); -} - -/** 批量文本 -> 键值行;# 开头表示禁用 */ -export function bulkTextToRows(text) { - const rows = []; - (text || '').split(/\r?\n/).forEach(line => { - const trimmed = line.trim(); - if (!trimmed) { - return; - } - let enabled = true; - let content = trimmed; - if (content.startsWith('#')) { - enabled = false; - content = content.slice(1).trim(); - if (!content) { - return; - } - } - const colonIndex = content.indexOf(':'); - if (colonIndex < 0) { - rows.push({ enabled, key: content, value: '', description: '' }); - return; - } - rows.push({ - enabled, - key: content.slice(0, colonIndex).trim(), - value: content.slice(colonIndex + 1), - description: '', - }); - }); - return rows; -} - export function rowsToObject(rows) { const result = {} ;(rows || []).forEach(item => { @@ -123,7 +76,7 @@ export function serializeDesigner(value) { } else if (body.mode === 'x-www-form-urlencoded') { bodyTemplate = JSON.stringify({ mode: body.mode, urlencoded: body.urlencoded || [] }); } else { - bodyTemplate = null; + bodyTemplate = ''; } return { method: value.method,