Commit 6e48154fb894f26b8f019cf9f78a5d85b8b21b6d

Authored by puhui999
2 parents d155876f a9dc654b

Merge remote-tracking branch 'refs/remotes/yudao/feature/iot' into iot

yudao-module-iot/yudao-module-iot-biz/pom.xml
@@ -70,11 +70,11 @@ @@ -70,11 +70,11 @@
70 </dependency> 70 </dependency>
71 71
72 <!-- 脚本插件相关 --> 72 <!-- 脚本插件相关 -->
73 - <dependency> 73 + <!--<dependency>
74 <groupId>cn.iocoder.boot</groupId> 74 <groupId>cn.iocoder.boot</groupId>
75 <artifactId>yudao-module-iot-plugin-script</artifactId> 75 <artifactId>yudao-module-iot-plugin-script</artifactId>
76 <version>${revision}</version> 76 <version>${revision}</version>
77 - </dependency> 77 + </dependency>-->
78 78
79 <!-- 消息队列相关 --> 79 <!-- 消息队列相关 -->
80 <dependency> 80 <dependency>
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductScriptServiceImpl.java
@@ -9,8 +9,6 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.script.IotProduct @@ -9,8 +9,6 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.script.IotProduct
9 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; 9 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
10 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductScriptDO; 10 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductScriptDO;
11 import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductScriptMapper; 11 import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductScriptMapper;
12 -import cn.iocoder.yudao.module.iot.plugin.script.context.PluginScriptContext;  
13 -import cn.iocoder.yudao.module.iot.plugin.script.service.ScriptService;  
14 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 12 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
15 import jakarta.annotation.Resource; 13 import jakarta.annotation.Resource;
16 import lombok.extern.slf4j.Slf4j; 14 import lombok.extern.slf4j.Slf4j;
@@ -42,8 +40,8 @@ public class IotProductScriptServiceImpl implements IotProductScriptService { @@ -42,8 +40,8 @@ public class IotProductScriptServiceImpl implements IotProductScriptService {
42 @Resource 40 @Resource
43 private IotProductService productService; 41 private IotProductService productService;
44 42
45 - @Resource  
46 - private ScriptService scriptService; 43 +// @Resource
  44 +// private ScriptService scriptService;
47 45
48 @Override 46 @Override
49 public Long createProductScript(IotProductScriptSaveReqVO createReqVO) { 47 public Long createProductScript(IotProductScriptSaveReqVO createReqVO) {
@@ -120,89 +118,90 @@ public class IotProductScriptServiceImpl implements IotProductScriptService { @@ -120,89 +118,90 @@ public class IotProductScriptServiceImpl implements IotProductScriptService {
120 118
121 @Override 119 @Override
122 public IotProductScriptTestRespVO testProductScript(IotProductScriptTestReqVO testReqVO) { 120 public IotProductScriptTestRespVO testProductScript(IotProductScriptTestReqVO testReqVO) {
123 - long startTime = System.currentTimeMillis();  
124 -  
125 - try {  
126 - // 验证产品是否存在  
127 - validateProductExists(testReqVO.getProductId());  
128 -  
129 - // 根据ID获取已保存的脚本(如果有)  
130 - IotProductScriptDO existingScript = null;  
131 - if (testReqVO.getId() != null) {  
132 - existingScript = getProductScript(testReqVO.getId());  
133 - }  
134 -  
135 - // 创建测试上下文  
136 - PluginScriptContext context = new PluginScriptContext();  
137 - IotProductDO product = productService.getProduct(testReqVO.getProductId());  
138 -  
139 - // 设置设备上下文(使用产品信息,没有具体设备)  
140 - context.withDeviceContext(product.getProductKey(), null);  
141 -  
142 - // 设置输入参数  
143 - Map<String, Object> params = new HashMap<>();  
144 - params.put("input", testReqVO.getTestInput());  
145 - params.put("productKey", product.getProductKey());  
146 - params.put("scriptType", testReqVO.getScriptType());  
147 -  
148 - // 根据脚本类型设置特定参数  
149 - switch (testReqVO.getScriptType()) {  
150 - case 1: // PROPERTY_PARSER  
151 - params.put("method", "property");  
152 - break;  
153 - case 2: // EVENT_PARSER  
154 - params.put("method", "event");  
155 - params.put("identifier", "default");  
156 - break;  
157 - case 3: // COMMAND_ENCODER  
158 - params.put("method", "command");  
159 - break;  
160 - default:  
161 - // 默认不添加额外参数  
162 - }  
163 -  
164 - // 添加所有参数到上下文  
165 - for (Map.Entry<String, Object> entry : params.entrySet()) {  
166 - context.setParameter(entry.getKey(), entry.getValue());  
167 - }  
168 -  
169 - // 执行脚本  
170 - Object result = scriptService.executeScript(  
171 - testReqVO.getScriptLanguage(),  
172 - testReqVO.getScriptContent(),  
173 - context);  
174 -  
175 - // 更新测试结果(如果是已保存的脚本)  
176 - if (existingScript != null) {  
177 - IotProductScriptDO updateObj = new IotProductScriptDO();  
178 - updateObj.setId(existingScript.getId());  
179 - updateObj.setLastTestTime(LocalDateTime.now());  
180 - updateObj.setLastTestResult(1); // 1表示成功  
181 - productScriptMapper.updateById(updateObj);  
182 - }  
183 -  
184 - long executionTime = System.currentTimeMillis() - startTime;  
185 - return IotProductScriptTestRespVO.success(result, executionTime);  
186 -  
187 - } catch (Exception e) {  
188 - log.error("[testProductScript][测试脚本异常]", e);  
189 -  
190 - // 如果是已保存的脚本,更新测试失败状态  
191 - if (testReqVO.getId() != null) {  
192 - try {  
193 - IotProductScriptDO updateObj = new IotProductScriptDO();  
194 - updateObj.setId(testReqVO.getId());  
195 - updateObj.setLastTestTime(LocalDateTime.now());  
196 - updateObj.setLastTestResult(0); // 0表示失败  
197 - productScriptMapper.updateById(updateObj);  
198 - } catch (Exception ex) {  
199 - log.error("[testProductScript][更新脚本测试结果异常]", ex);  
200 - }  
201 - }  
202 -  
203 - long executionTime = System.currentTimeMillis() - startTime;  
204 - return IotProductScriptTestRespVO.error(e.getMessage(), executionTime);  
205 - } 121 +// long startTime = System.currentTimeMillis();
  122 +//
  123 +// try {
  124 +// // 验证产品是否存在
  125 +// validateProductExists(testReqVO.getProductId());
  126 +//
  127 +// // 根据ID获取已保存的脚本(如果有)
  128 +// IotProductScriptDO existingScript = null;
  129 +// if (testReqVO.getId() != null) {
  130 +// existingScript = getProductScript(testReqVO.getId());
  131 +// }
  132 +//
  133 +// // 创建测试上下文
  134 +// PluginScriptContext context = new PluginScriptContext();
  135 +// IotProductDO product = productService.getProduct(testReqVO.getProductId());
  136 +//
  137 +// // 设置设备上下文(使用产品信息,没有具体设备)
  138 +// context.withDeviceContext(product.getProductKey(), null);
  139 +//
  140 +// // 设置输入参数
  141 +// Map<String, Object> params = new HashMap<>();
  142 +// params.put("input", testReqVO.getTestInput());
  143 +// params.put("productKey", product.getProductKey());
  144 +// params.put("scriptType", testReqVO.getScriptType());
  145 +//
  146 +// // 根据脚本类型设置特定参数
  147 +// switch (testReqVO.getScriptType()) {
  148 +// case 1: // PROPERTY_PARSER
  149 +// params.put("method", "property");
  150 +// break;
  151 +// case 2: // EVENT_PARSER
  152 +// params.put("method", "event");
  153 +// params.put("identifier", "default");
  154 +// break;
  155 +// case 3: // COMMAND_ENCODER
  156 +// params.put("method", "command");
  157 +// break;
  158 +// default:
  159 +// // 默认不添加额外参数
  160 +// }
  161 +//
  162 +// // 添加所有参数到上下文
  163 +// for (Map.Entry<String, Object> entry : params.entrySet()) {
  164 +// context.setParameter(entry.getKey(), entry.getValue());
  165 +// }
  166 +//
  167 +// // 执行脚本
  168 +// Object result = scriptService.executeScript(
  169 +// testReqVO.getScriptLanguage(),
  170 +// testReqVO.getScriptContent(),
  171 +// context);
  172 +//
  173 +// // 更新测试结果(如果是已保存的脚本)
  174 +// if (existingScript != null) {
  175 +// IotProductScriptDO updateObj = new IotProductScriptDO();
  176 +// updateObj.setId(existingScript.getId());
  177 +// updateObj.setLastTestTime(LocalDateTime.now());
  178 +// updateObj.setLastTestResult(1); // 1表示成功
  179 +// productScriptMapper.updateById(updateObj);
  180 +// }
  181 +//
  182 +// long executionTime = System.currentTimeMillis() - startTime;
  183 +// return IotProductScriptTestRespVO.success(result, executionTime);
  184 +//
  185 +// } catch (Exception e) {
  186 +// log.error("[testProductScript][测试脚本异常]", e);
  187 +//
  188 +// // 如果是已保存的脚本,更新测试失败状态
  189 +// if (testReqVO.getId() != null) {
  190 +// try {
  191 +// IotProductScriptDO updateObj = new IotProductScriptDO();
  192 +// updateObj.setId(testReqVO.getId());
  193 +// updateObj.setLastTestTime(LocalDateTime.now());
  194 +// updateObj.setLastTestResult(0); // 0表示失败
  195 +// productScriptMapper.updateById(updateObj);
  196 +// } catch (Exception ex) {
  197 +// log.error("[testProductScript][更新脚本测试结果异常]", ex);
  198 +// }
  199 +// }
  200 +//
  201 +// long executionTime = System.currentTimeMillis() - startTime;
  202 +// return IotProductScriptTestRespVO.error(e.getMessage(), executionTime);
  203 +// }
  204 + return null;
206 } 205 }
207 206
208 @Override 207 @Override