mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-03-13 20:53:42 +08:00
Merge remote-tracking branch 'origin/main'
# Conflicts: # ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/DifyServiceImpl.java # ruoyi-modules/ruoyi-generator/src/main/java/org/ruoyi/generator/impl/GenTableServiceImpl.java
This commit is contained in:
@@ -25,8 +25,10 @@ import org.ruoyi.service.IChatSessionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import org.ruoyi.chat.support.ChatServiceHelper;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.ruoyi.chat.support.RetryNotifier;
|
||||
|
||||
/**
|
||||
* dify 聊天管理
|
||||
@@ -111,23 +113,25 @@ public class DifyServiceImpl implements IChatService {
|
||||
chatRequestResponse.setUserId(chatRequest.getUserId());
|
||||
chatRequestResponse.setSessionId(chatRequest.getSessionId());
|
||||
chatRequestResponse.setPrompt(respMessage.toString());
|
||||
// 先保存助手消息,再发布异步计费事件
|
||||
chatCostService.saveMessage(chatRequestResponse);
|
||||
chatCostService.publishBillingEvent(chatRequestResponse);
|
||||
chatCostService.deductToken(chatRequestResponse);
|
||||
RetryNotifier.clear(emitter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorEvent event) {
|
||||
System.err.println("错误: " + event.getMessage());
|
||||
ChatServiceHelper.onStreamError(emitter, event.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Throwable throwable) {
|
||||
System.err.println("异常: " + throwable.getMessage());
|
||||
ChatServiceHelper.onStreamError(emitter, throwable.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("dify请求失败:{}", e.getMessage());
|
||||
ChatServiceHelper.onStreamError(emitter, e.getMessage());
|
||||
}
|
||||
|
||||
return emitter;
|
||||
|
||||
@@ -43,6 +43,11 @@ public class SchemaVo implements Serializable {
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
/**
|
||||
* 字典
|
||||
*/
|
||||
private String dictType;
|
||||
|
||||
|
||||
/**
|
||||
* 表注释
|
||||
|
||||
@@ -21,18 +21,9 @@ import org.ruoyi.generator.util.VelocityInitializer;
|
||||
import org.ruoyi.generator.util.VelocityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 业务 服务层实现
|
||||
@@ -62,6 +53,41 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFrontendTemplateFiles(String workPath, String previewCode) {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
ProcessBuilder builder;
|
||||
if (os.contains("win")) {
|
||||
// Windows下用 cmd /c 执行 previewCode
|
||||
builder = new ProcessBuilder("cmd.exe", "/c", previewCode);
|
||||
} else {
|
||||
// macOS/Linux 用 bash -c 执行 previewCode
|
||||
builder = new ProcessBuilder("bash", "-c", previewCode);
|
||||
}
|
||||
|
||||
// 设置工作目录
|
||||
builder.directory(new File(workPath));
|
||||
builder.redirectErrorStream(true);
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
builder.start().getInputStream(),
|
||||
StandardCharsets.UTF_8
|
||||
)
|
||||
)) {
|
||||
String line;
|
||||
log.info("执行结果:");
|
||||
while ((line = reader.readLine()) != null) {
|
||||
log.info(line);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("生成前端代码出错", e);
|
||||
throw new RuntimeException("生成前端代码失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据表名称生成代码到classpath
|
||||
*/
|
||||
@@ -223,7 +249,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
column.put("javaField", javaField);
|
||||
column.put("capJavaField", toCamelCase(field.getCode(), true));
|
||||
|
||||
// 布尔值属性(兼容两种格式)
|
||||
// 布尔值dictType属性(兼容两种格式)
|
||||
boolean isPk = "1".equals(field.getIsPk());
|
||||
boolean isRequired = "1".equals(field.getIsRequired());
|
||||
boolean isInsert = "1".equals(field.getIsInsert());
|
||||
|
||||
@@ -207,6 +207,7 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("schemaGroupCode", schemaGroupVo.getCode());
|
||||
result.put("tableName", schema.getTableName());
|
||||
result.put("dictType",schema.getDictType());
|
||||
result.put("tableComment", schema.getComment());
|
||||
result.put("className", toCamelCase(schema.getTableName(), true));
|
||||
result.put("tableCamelName", StrUtil.toCamelCase(schema.getTableName()));
|
||||
@@ -222,6 +223,8 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
if (pkField != null) {
|
||||
Map<String, Object> pkColumn = new HashMap<>();
|
||||
pkColumn.put("columnName", pkField.getCode());
|
||||
pkColumn.put("dictType", pkField.getDictType());
|
||||
|
||||
pkColumn.put("columnComment", pkField.getName());
|
||||
pkColumn.put("javaField", StrUtil.toCamelCase(pkField.getCode()));
|
||||
pkColumn.put("javaType", getJavaType(pkField.getType()));
|
||||
@@ -233,6 +236,7 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
for (SchemaFieldVo field : fields) {
|
||||
Map<String, Object> column = new HashMap<>();
|
||||
column.put("columnName", field.getCode());
|
||||
column.put("dictType", field.getDictType());
|
||||
column.put("columnComment", field.getName());
|
||||
column.put("javaField", StrUtil.toCamelCase(field.getCode()));
|
||||
column.put("javaType", getJavaType(field.getType()));
|
||||
@@ -279,6 +283,7 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
field.setDefaultValue((String) columnInfo.get("columnDefault"));
|
||||
field.setComment((String) columnInfo.get("columnComment"));
|
||||
field.setName((String) columnInfo.get("columnComment"));
|
||||
field.setDictType(StrUtil.toCamelCase((String) columnInfo.get("dictType")));
|
||||
field.setCode(StrUtil.toCamelCase((String) columnInfo.get("columnName")));
|
||||
field.setType((String) columnInfo.get("dataType"));
|
||||
field.setLength(Integer.valueOf(String.valueOf(columnInfo.get("columnSize"))));
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ${ClassName} implements Serializable {
|
||||
@Version
|
||||
#end
|
||||
#if($column.isPk==1)
|
||||
@TableId(value = "$column.columnName")
|
||||
@TableId(value = "${column.columnName}", type = IdType.AUTO)
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user