正在显示
17 个修改的文件
包含
50 行增加
和
51 行删除
| @@ -11,6 +11,7 @@ import org.slf4j.Logger; | @@ -11,6 +11,7 @@ import org.slf4j.Logger; | ||
| 11 | import org.slf4j.LoggerFactory; | 11 | import org.slf4j.LoggerFactory; |
| 12 | 12 | ||
| 13 | import javax.annotation.PreDestroy; | 13 | import javax.annotation.PreDestroy; |
| 14 | +import java.nio.charset.StandardCharsets; | ||
| 14 | import java.util.Set; | 15 | import java.util.Set; |
| 15 | 16 | ||
| 16 | public class MqttService { | 17 | public class MqttService { |
| @@ -86,7 +87,7 @@ public class MqttService { | @@ -86,7 +87,7 @@ public class MqttService { | ||
| 86 | } | 87 | } |
| 87 | public void publish(String topic, String messageStr) throws MqttException { | 88 | public void publish(String topic, String messageStr) throws MqttException { |
| 88 | MqttMessage message = new MqttMessage(); | 89 | MqttMessage message = new MqttMessage(); |
| 89 | - message.setPayload(messageStr.getBytes()); | 90 | + message.setPayload(messageStr.getBytes(StandardCharsets.UTF_8)); |
| 90 | mqttclient.publish(topic,message); | 91 | mqttclient.publish(topic,message); |
| 91 | } | 92 | } |
| 92 | 93 |
| 1 | -package com.zhonglai.luhui.api.controller.iot; | 1 | +package com.zhonglai.luhui.admin.controller.iot; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.google.gson.JsonObject; | 4 | import com.google.gson.JsonObject; |
| 5 | import com.ruoyi.common.core.domain.AjaxResult; | 5 | import com.ruoyi.common.core.domain.AjaxResult; |
| 6 | import com.ruoyi.common.utils.GsonConstructor; | 6 | import com.ruoyi.common.utils.GsonConstructor; |
| 7 | import com.zhonglai.luhui.action.BaseController; | 7 | import com.zhonglai.luhui.action.BaseController; |
| 8 | -import com.zhonglai.luhui.api.controller.iot.dto.AddCamera; | ||
| 9 | -import com.zhonglai.luhui.api.controller.iot.dto.HostCommand; | ||
| 10 | -import com.zhonglai.luhui.api.controller.iot.dto.HostCommandFunction; | ||
| 11 | -import com.zhonglai.luhui.api.controller.iot.dto.camera.StartStream; | ||
| 12 | -import com.zhonglai.luhui.api.controller.iot.dto.camera.StartStreamBySerial; | ||
| 13 | -import com.zhonglai.luhui.api.controller.iot.dto.camera.StopStream; | ||
| 14 | -import com.zhonglai.luhui.api.service.RocketMqSendService; | ||
| 15 | import com.zhonglai.luhui.device.dto.CommandType; | 8 | import com.zhonglai.luhui.device.dto.CommandType; |
| 16 | import com.zhonglai.luhui.device.dto.DeviceCommand; | 9 | import com.zhonglai.luhui.device.dto.DeviceCommand; |
| 10 | +import com.zhonglai.luhui.device.dto.camera.*; | ||
| 11 | +import com.zhonglai.luhui.device.service.impl.RocketMqSendService; | ||
| 17 | import io.swagger.annotations.Api; | 12 | import io.swagger.annotations.Api; |
| 18 | import io.swagger.annotations.ApiImplicitParam; | 13 | import io.swagger.annotations.ApiImplicitParam; |
| 19 | import io.swagger.annotations.ApiImplicitParams; | 14 | import io.swagger.annotations.ApiImplicitParams; |
| @@ -49,7 +44,7 @@ public class ControlGkjController extends BaseController { | @@ -49,7 +44,7 @@ public class ControlGkjController extends BaseController { | ||
| 49 | @ApiOperation(value = "cd") | 44 | @ApiOperation(value = "cd") |
| 50 | @ApiImplicitParams({ | 45 | @ApiImplicitParams({ |
| 51 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), | 46 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), |
| 52 | - @ApiImplicitParam(name = "path", value = "路径", required = true, dataType = "String", paramType = "path"), | 47 | + @ApiImplicitParam(name = "path", value = "路径", required = true, dataType = "String", paramType = "query"), |
| 53 | }) | 48 | }) |
| 54 | @GetMapping("/cd/{deviceId}") | 49 | @GetMapping("/cd/{deviceId}") |
| 55 | public AjaxResult cd(@PathVariable String deviceId,String path) { | 50 | public AjaxResult cd(@PathVariable String deviceId,String path) { |
| @@ -68,7 +63,7 @@ public class ControlGkjController extends BaseController { | @@ -68,7 +63,7 @@ public class ControlGkjController extends BaseController { | ||
| 68 | @ApiOperation(value = "mkdir") | 63 | @ApiOperation(value = "mkdir") |
| 69 | @ApiImplicitParams({ | 64 | @ApiImplicitParams({ |
| 70 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), | 65 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), |
| 71 | - @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "path"), | 66 | + @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "query"), |
| 72 | }) | 67 | }) |
| 73 | @GetMapping("/mkdir/{deviceId}") | 68 | @GetMapping("/mkdir/{deviceId}") |
| 74 | public AjaxResult mkdir(@PathVariable String deviceId,String name) { | 69 | public AjaxResult mkdir(@PathVariable String deviceId,String name) { |
| @@ -87,7 +82,7 @@ public class ControlGkjController extends BaseController { | @@ -87,7 +82,7 @@ public class ControlGkjController extends BaseController { | ||
| 87 | @ApiOperation(value = "rm") | 82 | @ApiOperation(value = "rm") |
| 88 | @ApiImplicitParams({ | 83 | @ApiImplicitParams({ |
| 89 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), | 84 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), |
| 90 | - @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "path"), | 85 | + @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "query"), |
| 91 | }) | 86 | }) |
| 92 | @GetMapping("/rm/{deviceId}") | 87 | @GetMapping("/rm/{deviceId}") |
| 93 | public AjaxResult rm(@PathVariable String deviceId,String name) { | 88 | public AjaxResult rm(@PathVariable String deviceId,String name) { |
| @@ -106,8 +101,8 @@ public class ControlGkjController extends BaseController { | @@ -106,8 +101,8 @@ public class ControlGkjController extends BaseController { | ||
| 106 | @ApiOperation(value = "copy") | 101 | @ApiOperation(value = "copy") |
| 107 | @ApiImplicitParams({ | 102 | @ApiImplicitParams({ |
| 108 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), | 103 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), |
| 109 | - @ApiImplicitParam(name = "source", value = "源", required = true, dataType = "String", paramType = "path"), | ||
| 110 | - @ApiImplicitParam(name = "target", value = "目标", required = true, dataType = "String", paramType = "path"), | 104 | + @ApiImplicitParam(name = "source", value = "源", required = true, dataType = "String", paramType = "query"), |
| 105 | + @ApiImplicitParam(name = "target", value = "目标", required = true, dataType = "String", paramType = "query"), | ||
| 111 | }) | 106 | }) |
| 112 | @GetMapping("/copy/{deviceId}") | 107 | @GetMapping("/copy/{deviceId}") |
| 113 | public AjaxResult copy(@PathVariable String deviceId,String source,String target) { | 108 | public AjaxResult copy(@PathVariable String deviceId,String source,String target) { |
| @@ -127,7 +122,7 @@ public class ControlGkjController extends BaseController { | @@ -127,7 +122,7 @@ public class ControlGkjController extends BaseController { | ||
| 127 | @ApiOperation(value = "mk") | 122 | @ApiOperation(value = "mk") |
| 128 | @ApiImplicitParams({ | 123 | @ApiImplicitParams({ |
| 129 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), | 124 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), |
| 130 | - @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "path"), | 125 | + @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "query"), |
| 131 | }) | 126 | }) |
| 132 | @GetMapping("/mk/{deviceId}") | 127 | @GetMapping("/mk/{deviceId}") |
| 133 | public AjaxResult mk(@PathVariable String deviceId,String name) { | 128 | public AjaxResult mk(@PathVariable String deviceId,String name) { |
| @@ -146,8 +141,8 @@ public class ControlGkjController extends BaseController { | @@ -146,8 +141,8 @@ public class ControlGkjController extends BaseController { | ||
| 146 | @ApiOperation(value = "download") | 141 | @ApiOperation(value = "download") |
| 147 | @ApiImplicitParams({ | 142 | @ApiImplicitParams({ |
| 148 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), | 143 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), |
| 149 | - @ApiImplicitParam(name = "url", value = "url", required = true, dataType = "String", paramType = "path"), | ||
| 150 | - @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "path"), | 144 | + @ApiImplicitParam(name = "url", value = "url", required = true, dataType = "String", paramType = "query"), |
| 145 | + @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "query"), | ||
| 151 | }) | 146 | }) |
| 152 | @GetMapping("/download/{deviceId}") | 147 | @GetMapping("/download/{deviceId}") |
| 153 | public AjaxResult download(@PathVariable String deviceId,String url,String name) { | 148 | public AjaxResult download(@PathVariable String deviceId,String url,String name) { |
| @@ -167,8 +162,8 @@ public class ControlGkjController extends BaseController { | @@ -167,8 +162,8 @@ public class ControlGkjController extends BaseController { | ||
| 167 | @ApiOperation(value = "upload") | 162 | @ApiOperation(value = "upload") |
| 168 | @ApiImplicitParams({ | 163 | @ApiImplicitParams({ |
| 169 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), | 164 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataType = "String", paramType = "path"), |
| 170 | - @ApiImplicitParam(name = "url", value = "url", required = true, dataType = "String", paramType = "path"), | ||
| 171 | - @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "path"), | 165 | + @ApiImplicitParam(name = "url", value = "url", required = true, dataType = "String", paramType = "query"), |
| 166 | + @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "query"), | ||
| 172 | }) | 167 | }) |
| 173 | @GetMapping("/upload/{deviceId}") | 168 | @GetMapping("/upload/{deviceId}") |
| 174 | public AjaxResult upload(@PathVariable String deviceId,String url,String name) { | 169 | public AjaxResult upload(@PathVariable String deviceId,String url,String name) { |
| @@ -18,7 +18,7 @@ get_system_performance() { | @@ -18,7 +18,7 @@ get_system_performance() { | ||
| 18 | CPU_USAGE=\$(top -bn1 | grep "Cpu(s)" | awk '{print \$2 + \$4}') | 18 | CPU_USAGE=\$(top -bn1 | grep "Cpu(s)" | awk '{print \$2 + \$4}') |
| 19 | 19 | ||
| 20 | # 获取内存使用率 | 20 | # 获取内存使用率 |
| 21 | - MEMORY_USAGE=\$(free | grep Mem | awk '{print \$3/\$2 * 100.0}') | 21 | + MEMORY_USAGE=\$(ps -eo rss= | awk -v total=\$(grep MemTotal /proc/meminfo | awk '{print \$2}') '{sum+=\$1} END {print sum/total*100}'}') |
| 22 | 22 | ||
| 23 | # 获取磁盘使用率 | 23 | # 获取磁盘使用率 |
| 24 | DISK_USAGE=\$(df -h | grep '^/dev/' | grep -v 'boot' | awk '{print \$5}' | tr -d '%' | paste -sd+ | bc) | 24 | DISK_USAGE=\$(df -h | grep '^/dev/' | grep -v 'boot' | awk '{print \$5}' | tr -d '%' | paste -sd+ | bc) |
| @@ -21,10 +21,10 @@ get_system_performance() { | @@ -21,10 +21,10 @@ get_system_performance() { | ||
| 21 | MEMORY_USAGE=\$(free | grep Mem | awk '{print \$3/\$2 * 100.0}') | 21 | MEMORY_USAGE=\$(free | grep Mem | awk '{print \$3/\$2 * 100.0}') |
| 22 | 22 | ||
| 23 | # 获取磁盘使用率 | 23 | # 获取磁盘使用率 |
| 24 | - DISK_USAGE=\$(df -h | grep '^/dev/' | grep -v 'boot' | awk '{print \$5}' | tr -d '%' | paste -sd+ | bc) | 24 | + DISK_USAGE=\$(df -h | grep '^/dev/' | grep -v 'boot' | awk '{print \$5}' | tr -d '%' | sort -nr | head -1) |
| 25 | 25 | ||
| 26 | # 获取系统连接数 | 26 | # 获取系统连接数 |
| 27 | - CONNECTION_COUNT=\$(netstat -an | grep ESTABLISHED | wc -l) | 27 | + CONNECTION_COUNT=\$(ss -tan state established | wc -l) |
| 28 | 28 | ||
| 29 | # 获取前10进程的内存详情,使用 "fg9527" 分隔符 | 29 | # 获取前10进程的内存详情,使用 "fg9527" 分隔符 |
| 30 | MEMORY_INFO=\$(ps aux --sort=-rss | head -n 11 | awk 'NR==1 {print "USERfg9527PIDfg9527MEMORY(M)fg9527COMMAND"; next} {cmd=""; for(i=11;i<=NF;i++) cmd=cmd\$i" "; printf "%sfg9527%sfg9527%.2fMfg9527%s\n", \$1, \$2, \$6/1024, cmd}' | tr '\n' ';') | 30 | MEMORY_INFO=\$(ps aux --sort=-rss | head -n 11 | awk 'NR==1 {print "USERfg9527PIDfg9527MEMORY(M)fg9527COMMAND"; next} {cmd=""; for(i=11;i<=NF;i++) cmd=cmd\$i" "; printf "%sfg9527%sfg9527%.2fMfg9527%s\n", \$1, \$2, \$6/1024, cmd}' | tr '\n' ';') |
| @@ -2,24 +2,18 @@ package com.zhonglai.luhui.api.controller.iot; | @@ -2,24 +2,18 @@ package com.zhonglai.luhui.api.controller.iot; | ||
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | import com.ruoyi.common.annotation.Log; | 4 | import com.ruoyi.common.annotation.Log; |
| 5 | -import com.ruoyi.common.constant.HttpStatus; | ||
| 6 | import com.ruoyi.common.core.domain.AjaxResult; | 5 | import com.ruoyi.common.core.domain.AjaxResult; |
| 7 | -import com.ruoyi.common.core.domain.Message; | ||
| 8 | import com.ruoyi.common.enums.BusinessType; | 6 | import com.ruoyi.common.enums.BusinessType; |
| 9 | import com.ruoyi.common.utils.GsonConstructor; | 7 | import com.ruoyi.common.utils.GsonConstructor; |
| 10 | import com.zhonglai.luhui.action.BaseController; | 8 | import com.zhonglai.luhui.action.BaseController; |
| 11 | -import com.zhonglai.luhui.api.service.RocketMqSendService; | ||
| 12 | -import com.zhonglai.luhui.device.domain.IotDevice; | 9 | +import com.zhonglai.luhui.device.service.impl.RocketMqSendService; |
| 13 | import com.zhonglai.luhui.device.dto.CommandType; | 10 | import com.zhonglai.luhui.device.dto.CommandType; |
| 14 | import com.zhonglai.luhui.device.dto.DeviceCommand; | 11 | import com.zhonglai.luhui.device.dto.DeviceCommand; |
| 15 | -import com.zhonglai.luhui.device.service.IIotDeviceService; | ||
| 16 | -import com.zhonglai.luhui.rocketmq.service.RocketMqService; | ||
| 17 | import io.swagger.annotations.Api; | 12 | import io.swagger.annotations.Api; |
| 18 | import io.swagger.annotations.ApiImplicitParam; | 13 | import io.swagger.annotations.ApiImplicitParam; |
| 19 | import io.swagger.annotations.ApiImplicitParams; | 14 | import io.swagger.annotations.ApiImplicitParams; |
| 20 | import io.swagger.annotations.ApiOperation; | 15 | import io.swagger.annotations.ApiOperation; |
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
| 23 | import org.springframework.util.StreamUtils; | 17 | import org.springframework.util.StreamUtils; |
| 24 | import org.springframework.web.bind.annotation.PathVariable; | 18 | import org.springframework.web.bind.annotation.PathVariable; |
| 25 | import org.springframework.web.bind.annotation.PostMapping; | 19 | import org.springframework.web.bind.annotation.PostMapping; |
| @@ -7,7 +7,7 @@ import com.ruoyi.common.enums.BusinessType; | @@ -7,7 +7,7 @@ import com.ruoyi.common.enums.BusinessType; | ||
| 7 | import com.ruoyi.common.utils.DateUtils; | 7 | import com.ruoyi.common.utils.DateUtils; |
| 8 | import com.ruoyi.system.domain.user.UserTerminalGroupRelation; | 8 | import com.ruoyi.system.domain.user.UserTerminalGroupRelation; |
| 9 | import com.zhonglai.luhui.action.BaseController; | 9 | import com.zhonglai.luhui.action.BaseController; |
| 10 | -import com.zhonglai.luhui.api.controller.iot.dto.GroupTerminalRequest; | 10 | +import com.zhonglai.luhui.device.dto.camera.GroupTerminalRequest; |
| 11 | import com.zhonglai.luhui.api.controller.test.TestDto; | 11 | import com.zhonglai.luhui.api.controller.test.TestDto; |
| 12 | import com.zhonglai.luhui.dao.service.PublicService; | 12 | import com.zhonglai.luhui.dao.service.PublicService; |
| 13 | import com.zhonglai.luhui.device.domain.IotTerminal; | 13 | import com.zhonglai.luhui.device.domain.IotTerminal; |
| @@ -6,12 +6,13 @@ import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | @@ -6,12 +6,13 @@ import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | ||
| 6 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; | 6 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; |
| 7 | import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; | 7 | import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult; |
| 8 | 8 | ||
| 9 | +import java.nio.charset.StandardCharsets; | ||
| 9 | import java.util.HashMap; | 10 | import java.util.HashMap; |
| 10 | 11 | ||
| 11 | public class HostReq { | 12 | public class HostReq { |
| 12 | public AnalysisResult analysisPayload(byte[] payload) | 13 | public AnalysisResult analysisPayload(byte[] payload) |
| 13 | { | 14 | { |
| 14 | - return analysisPayload(new String(payload)); | 15 | + return analysisPayload(new String(payload, StandardCharsets.UTF_8)); |
| 15 | } | 16 | } |
| 16 | 17 | ||
| 17 | public AnalysisResult analysisPayload(String payload) { | 18 | public AnalysisResult analysisPayload(String payload) { |
| @@ -25,6 +26,10 @@ public class HostReq { | @@ -25,6 +26,10 @@ public class HostReq { | ||
| 25 | } | 26 | } |
| 26 | message.setCode(MessageCode.DEFAULT_SUCCESS_CODE); | 27 | message.setCode(MessageCode.DEFAULT_SUCCESS_CODE); |
| 27 | message.setMessage("操作成功"); | 28 | message.setMessage("操作成功"); |
| 29 | + }else | ||
| 30 | + { | ||
| 31 | + message.setCode(MessageCode.DEFAULT_FAIL_CODE); | ||
| 32 | + message.setMessage(jsonObject.has("message")?jsonObject.get("message").getAsString():"操作失败"); | ||
| 28 | } | 33 | } |
| 29 | return new AnalysisResult(false, true, null, message); | 34 | return new AnalysisResult(false, true, null, message); |
| 30 | } | 35 | } |
| @@ -47,6 +47,7 @@ import org.springframework.beans.factory.annotation.Value; | @@ -47,6 +47,7 @@ import org.springframework.beans.factory.annotation.Value; | ||
| 47 | import org.springframework.stereotype.Service; | 47 | import org.springframework.stereotype.Service; |
| 48 | 48 | ||
| 49 | import javax.annotation.PostConstruct; | 49 | import javax.annotation.PostConstruct; |
| 50 | +import java.nio.charset.StandardCharsets; | ||
| 50 | import java.util.Arrays; | 51 | import java.util.Arrays; |
| 51 | import java.util.List; | 52 | import java.util.List; |
| 52 | import java.util.Map; | 53 | import java.util.Map; |
| @@ -89,7 +90,7 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | @@ -89,7 +90,7 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | ||
| 89 | public Message onMessage(MessageExt messageExt) { | 90 | public Message onMessage(MessageExt messageExt) { |
| 90 | log.info("监听到消息{}",messageExt); | 91 | log.info("监听到消息{}",messageExt); |
| 91 | 92 | ||
| 92 | - String str = new String(messageExt.getBody()); | 93 | + String str = new String(messageExt.getBody(), StandardCharsets.UTF_8); |
| 93 | log.info("消息body{}",str); | 94 | log.info("消息body{}",str); |
| 94 | 95 | ||
| 95 | DeviceCommand deviceCommand = GsonConstructor.get().fromJson(str, DeviceCommand.class); | 96 | DeviceCommand deviceCommand = GsonConstructor.get().fromJson(str, DeviceCommand.class); |
| 1 | package com.zhonglai.luhui.device.protocol.factory.service; | 1 | package com.zhonglai.luhui.device.protocol.factory.service; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONArray; | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.google.gson.*; | 5 | import com.google.gson.*; |
| 5 | import com.ruoyi.common.utils.GsonConstructor; | 6 | import com.ruoyi.common.utils.GsonConstructor; |
| @@ -260,10 +261,20 @@ public class IotThingsModelService { | @@ -260,10 +261,20 @@ public class IotThingsModelService { | ||
| 260 | } | 261 | } |
| 261 | 262 | ||
| 262 | // 不要再无脑 toString(),直接走 safeNewhingsModel | 263 | // 不要再无脑 toString(),直接走 safeNewhingsModel |
| 263 | - JsonElement fieldElement = GsonConstructor.get().fromJson( | ||
| 264 | - String.valueOf(jsData.get(key)), | ||
| 265 | - JsonElement.class | ||
| 266 | - ); | 264 | + Object fieldObj = jsData.get(key); |
| 265 | + JsonElement fieldElement; | ||
| 266 | + | ||
| 267 | + if (fieldObj instanceof JSONObject || fieldObj instanceof JSONArray) { | ||
| 268 | + // 已经是 JSON 对象/数组,直接转字符串再解析 | ||
| 269 | + fieldElement = GsonConstructor.get().fromJson(fieldObj.toString(), JsonElement.class); | ||
| 270 | + } else { | ||
| 271 | + // 普通值,直接包装成 JsonPrimitive | ||
| 272 | + fieldElement = new JsonPrimitive(String.valueOf(fieldObj)); | ||
| 273 | + } | ||
| 274 | +// JsonElement fieldElement = GsonConstructor.get().fromJson( | ||
| 275 | +// String.valueOf(jsData.get(key)), | ||
| 276 | +// JsonElement.class | ||
| 277 | +// ); | ||
| 267 | 278 | ||
| 268 | ThingsModelItemBase thingsModelBase = | 279 | ThingsModelItemBase thingsModelBase = |
| 269 | ThingsModelItemBase.newhingsModelReverse( | 280 | ThingsModelItemBase.newhingsModelReverse( |
-
请 注册 或 登录 后发表评论