增加存储返回 类型转换
This commit is contained in:
parent
911d711ea1
commit
b66bdcaadb
@ -0,0 +1,29 @@
|
||||
package cn.iocoder.yudao.module.llm.framework.backend.config;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.iocoder.yudao.module.llm.handler.JSONObjectTypeHandler;
|
||||
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
|
||||
import org.apache.ibatis.type.TypeHandlerRegistry;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@MapperScan("cn.iocoder.yudao.module.llm.dal.mysql.dataprocesstask")
|
||||
public class MyBatisConfig {
|
||||
|
||||
@Bean
|
||||
public JSONObjectTypeHandler jsonObjectTypeHandler() {
|
||||
return new JSONObjectTypeHandler();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConfigurationCustomizer configurationCustomizer() {
|
||||
return configuration -> {
|
||||
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
|
||||
if (!typeHandlerRegistry.hasTypeHandler(JSONObject.class)) {
|
||||
typeHandlerRegistry.register(JSONObject.class, jsonObjectTypeHandler());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.llm.handler;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class JSONObjectTypeHandler extends BaseTypeHandler<JSONObject> {
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, JSONObject parameter, JdbcType jdbcType) throws SQLException {
|
||||
ps.setString(i, parameter.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String jsonStr = rs.getString(columnName);
|
||||
return jsonStr == null ? null : new JSONObject(jsonStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String jsonStr = rs.getString(columnIndex);
|
||||
return jsonStr == null ? null : new JSONObject(jsonStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String jsonStr = cs.getString(columnIndex);
|
||||
return jsonStr == null ? null : new JSONObject(jsonStr);
|
||||
}
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.llm.service.async;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.dataprocesstask.DataProcessTaskDO;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.dataset.DatasetDO;
|
||||
import cn.iocoder.yudao.module.llm.dal.mysql.dataprocesstask.DataProcessTaskMapper;
|
||||
import cn.iocoder.yudao.module.llm.dal.mysql.dataset.DatasetMapper;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -9,12 +12,29 @@ import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class AsyncDataProcessService {
|
||||
@Resource
|
||||
private DatasetMapper datasetMapper;
|
||||
@Resource
|
||||
private DataProcessTaskMapper dataProcessTaskMapper;
|
||||
|
||||
/* @Resource
|
||||
private */
|
||||
@Async
|
||||
public void backups(DataProcessTaskDO dataProcessTask) {
|
||||
try {
|
||||
Thread.sleep(100000);
|
||||
}catch(InterruptedException e){
|
||||
// 判断备份数据集是否存在
|
||||
if (dataProcessTask.getDatasetPostId() == null){
|
||||
DatasetDO datasetDO = datasetMapper.selectById(dataProcessTask.getDatasetId());
|
||||
DatasetDO newData = BeanUtils.toBean(datasetDO, DatasetDO.class);
|
||||
newData.setId(null);
|
||||
datasetMapper.insert(newData);
|
||||
dataProcessTask.setDatasetPostId(newData.getId());
|
||||
dataProcessTaskMapper.updateById(dataProcessTask);
|
||||
}
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
dataProcessTaskMapper.updateStatus(dataProcessTask.getId(), 5);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user