test(添加SQL的工具类)
commit
ae7ec53cf4
2
LICENSE
2
LICENSE
|
@ -14,7 +14,7 @@ copies or substantial portions of the Software.
|
|||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
FITNESS FOR com.muyu.engine.text.A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
|
|
|
@ -9,6 +9,8 @@ import lombok.Builder;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DatabaseTableInformation 数据库信息表
|
||||
*
|
||||
|
@ -44,4 +46,8 @@ public class DatabaseTableInformation {
|
|||
* ID
|
||||
*/
|
||||
private Integer structureId;
|
||||
|
||||
/** 数据库表对象集合 */
|
||||
@TableField(exist = false)
|
||||
private List<DatabaseTable> databaseTables;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package com.muyu.data.source.domain.model;
|
||||
|
||||
import com.muyu.data.source.domain.DatabaseTable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接收JDBC需要的值
|
||||
*
|
||||
* @ClassName DataTableValue
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/5/13 21:31
|
||||
*/
|
||||
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DataTableValue {
|
||||
/**
|
||||
* 主机地址
|
||||
*/
|
||||
private String hostAddress;
|
||||
/**主机端口
|
||||
*
|
||||
*/
|
||||
private String hostPort;
|
||||
/**
|
||||
* 数据连接类型ID
|
||||
*/
|
||||
private Long dataAccessTypeId;
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private String databaseName;
|
||||
/**
|
||||
* 数据连接参数
|
||||
*/
|
||||
private String dataConnectionParameter;
|
||||
/**
|
||||
* 数据库用户名
|
||||
*/
|
||||
private String databaseUserName;
|
||||
/**
|
||||
* 数据库用户密码
|
||||
*/
|
||||
private String databaseUserPassword;
|
||||
|
||||
/**数据库表名*/
|
||||
private String tableName;
|
||||
|
||||
/** 表字段信息 */
|
||||
private List<DatabaseTable> databaseTables;
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muyu.data.source.domain.*;
|
||||
import com.muyu.data.source.domain.model.DataTableValue;
|
||||
import com.muyu.data.source.domain.model.DatabaseTableModel;
|
||||
import com.muyu.data.source.domain.red.DataSourceTableRed;
|
||||
import com.muyu.data.source.domain.req.DatabaseConnect;
|
||||
|
@ -168,4 +169,10 @@ public class DataSourceController extends BaseController {
|
|||
public Result<List<DataSourceTableRed>> information(){
|
||||
return dataSourceService.information();
|
||||
}
|
||||
|
||||
//获取数据
|
||||
@PostMapping("/tableParticulars")
|
||||
public Result<String> tableParticulars(@RequestBody DataTableValue dataTableValue){
|
||||
return dataSourceService.tableParticulars(dataTableValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,9 @@ import com.muyu.data.source.domain.DatabaseTable;
|
|||
import com.muyu.data.source.domain.SysDictDataTable;
|
||||
import com.muyu.data.source.service.DatabaseTableService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据库表对象 Controller层
|
||||
|
@ -33,4 +32,9 @@ public class DatabaseTableController {
|
|||
public Result<String> modification(@RequestBody DatabaseTable databaseTable){
|
||||
return databaseTableService.modification(databaseTable);
|
||||
}
|
||||
|
||||
@PostMapping("/tableNameList")
|
||||
public Result<List<DatabaseTable>> tableNameList(@RequestParam("tableName") String tableName){
|
||||
return databaseTableService.tableNameList(tableName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.data.source.domain.*;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.data.source.domain.model.DataTableValue;
|
||||
import com.muyu.data.source.domain.model.DatabaseTableModel;
|
||||
import com.muyu.data.source.domain.red.DataSourceTableRed;
|
||||
import com.muyu.data.source.domain.req.DataSourceSaveReq;
|
||||
|
@ -48,4 +49,6 @@ public interface DataSourceService extends IService<DataSource> {
|
|||
|
||||
Result<List<DataSourceTableRed>> information();
|
||||
|
||||
Result<String> tableParticulars(DataTableValue dataTableValue);
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import com.muyu.common.core.domain.Result;
|
|||
import com.muyu.data.source.domain.DatabaseTable;
|
||||
import com.muyu.data.source.domain.SysDictDataTable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DatabaseTable Service层接口
|
||||
*
|
||||
|
@ -15,4 +17,5 @@ import com.muyu.data.source.domain.SysDictDataTable;
|
|||
public interface DatabaseTableService extends IService<DatabaseTable> {
|
||||
Result<String> modification(DatabaseTable databaseTable);
|
||||
|
||||
Result<List<DatabaseTable>> tableNameList(String tableName);
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ import java.util.List;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import com.muyu.data.source.domain.*;
|
||||
import com.muyu.data.source.domain.model.DataTableValue;
|
||||
import com.muyu.data.source.domain.model.DatabaseTableModel;
|
||||
import com.muyu.data.source.domain.red.DataSourceTableRed;
|
||||
import com.muyu.data.source.domain.req.DataSourceSaveReq;
|
||||
import com.muyu.data.source.domain.req.DatabaseConnect;
|
||||
import com.muyu.data.source.mapper.DatabaseTableInformationMapper;
|
||||
import com.muyu.data.source.mapper.DatabaseTableMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -287,19 +289,44 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
|
||||
@Autowired
|
||||
private DatabaseTableInformationMapper databaseTableInformationMapper;
|
||||
@Autowired
|
||||
private DatabaseTableMapper databaseTableMapper;
|
||||
|
||||
@Override
|
||||
public Result<List<DataSourceTableRed>> information() {
|
||||
List<DataSourceTableRed> arrayList = new ArrayList<>();
|
||||
List<DataSource> dataSources = dataSourceMapper.selectList(null);
|
||||
ArrayList<DatabaseTableInformation> informationArrayList = new ArrayList<>();
|
||||
for (DataSource dataSource : dataSources) {
|
||||
|
||||
List<DatabaseTableInformation> table = dataSourceMapper.table(dataSource.getDatabaseName());
|
||||
|
||||
for (DatabaseTableInformation information : table) {
|
||||
List<DatabaseTable> databaseTables = databaseTableMapper.selectList(
|
||||
new LambdaQueryWrapper<DatabaseTable>() {{
|
||||
eq(DatabaseTable::getTableName, information.getName());
|
||||
eq(DatabaseTable::getDatabaseName, information.getDatabaseName());
|
||||
}}
|
||||
);
|
||||
|
||||
informationArrayList.add(
|
||||
DatabaseTableInformation.builder()
|
||||
.id(information.getId())
|
||||
.name(information.getName())
|
||||
.as(information.getAs())
|
||||
.dataTotal(information.getDataTotal())
|
||||
.databaseName(information.getDatabaseName())
|
||||
.type(information.getType())
|
||||
.structureId(information.getStructureId())
|
||||
.databaseTables(databaseTables)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
arrayList.add(
|
||||
DataSourceTableRed.builder()
|
||||
.dataSource(dataSource)
|
||||
.databaseTableInformationList(table)
|
||||
.databaseTableInformationList(informationArrayList)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
@ -307,4 +334,30 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
arrayList
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Result<String> tableParticulars(DataTableValue dataTableValue) {
|
||||
String url = "jdbc:mysql://" + dataTableValue.getHostAddress() + ":" + dataTableValue.getHostPort() + "/" + dataTableValue.getDatabaseName();
|
||||
String UserName = dataTableValue.getDatabaseUserName();
|
||||
String password = dataTableValue.getDatabaseUserPassword();
|
||||
|
||||
try {
|
||||
Connection con = DriverManager.getConnection(url, UserName, password);
|
||||
|
||||
PreparedStatement preparedStatement = con.prepareStatement("SELECT * FROM " + dataTableValue.getTableName());
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while(resultSet.next()) {
|
||||
String userId = resultSet.getString("user_id");
|
||||
String name = resultSet.getString("name");
|
||||
int age = resultSet.getInt("pwd");
|
||||
log.info("user_id:{},name:{},pwd:{}", userId, name, age);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.data.source.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.data.source.domain.DatabaseTable;
|
||||
|
@ -8,6 +9,8 @@ import com.muyu.data.source.service.DatabaseTableService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DatabaseTable Impl层业务实现类
|
||||
*
|
||||
|
@ -46,4 +49,16 @@ public class DatabaseTableServiceImpl extends ServiceImpl<DatabaseTableMapper, D
|
|||
)>0?"修改成功":"修改失败"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Result<List<DatabaseTable>> tableNameList(String tableName) {
|
||||
return Result.success(
|
||||
databaseTableMapper.selectList(
|
||||
new LambdaQueryWrapper<DatabaseTable>(){{
|
||||
eq(DatabaseTable::getTableName,tableName);
|
||||
}}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.data.unlt;
|
||||
package com.muyu.unlt;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
|
@ -57,7 +57,7 @@ public class ${ClassName} extends ${Entity}
|
|||
#end
|
||||
#foreach ($column in $columns)
|
||||
#if(!$table.isSuperColumn($column.javaField))
|
||||
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
|
||||
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[com.muyu.engine.text.A-Z]"))
|
||||
#set($AttrName=$column.javaField)
|
||||
#else
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
|
@ -90,7 +90,7 @@ public class ${ClassName} extends ${Entity}
|
|||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
#foreach ($column in $columns)
|
||||
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
|
||||
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[com.muyu.engine.text.A-Z]"))
|
||||
#set($AttrName=$column.javaField)
|
||||
#else
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
|
|
|
@ -48,7 +48,7 @@ public class ${subClassName} extends BaseEntity
|
|||
#end
|
||||
#foreach ($column in $subTable.columns)
|
||||
#if(!$table.isSuperColumn($column.javaField))
|
||||
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
|
||||
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[com.muyu.engine.text.A-Z]"))
|
||||
#set($AttrName=$column.javaField)
|
||||
#else
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
|
@ -69,7 +69,7 @@ public class ${subClassName} extends BaseEntity
|
|||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
#foreach ($column in $subTable.columns)
|
||||
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
|
||||
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[com.muyu.engine.text.A-Z]"))
|
||||
#set($AttrName=$column.javaField)
|
||||
#else
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.engine.text;
|
||||
|
||||
import com.muyu.model.DataModel;
|
||||
|
||||
/**
|
||||
* a
|
||||
*
|
||||
* @ClassName com.muyu.engine.text.A
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/5/13 16:32
|
||||
*/
|
||||
|
||||
|
||||
public class A implements Base{
|
||||
|
||||
@Override
|
||||
public void execution() {
|
||||
DataModel dataModel = ThreadConstant.get();
|
||||
System.out.println(dataModel.getValue());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.engine.text;
|
||||
|
||||
import com.muyu.model.DataModel;
|
||||
|
||||
/**
|
||||
* b
|
||||
*
|
||||
* @ClassName B
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/5/13 16:34
|
||||
*/
|
||||
|
||||
|
||||
public class B implements Base{
|
||||
@Override
|
||||
public void execution() {
|
||||
DataModel dataModel = ThreadConstant.get();
|
||||
dataModel.setValue("李四");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.muyu.engine.text;
|
||||
|
||||
/**
|
||||
* base
|
||||
*
|
||||
* @author AnNan.Wang
|
||||
* @ClassName: Base
|
||||
* @createTime: 2024/5/13 16:55
|
||||
*/
|
||||
public interface Base {
|
||||
public void execution();
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.engine.text;
|
||||
|
||||
import com.muyu.model.DataModel;
|
||||
|
||||
/**
|
||||
* c
|
||||
*
|
||||
* @ClassName C
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/5/13 16:41
|
||||
*/
|
||||
|
||||
|
||||
public class C implements Base{
|
||||
@Override
|
||||
public void execution() {
|
||||
DataModel dataModel = ThreadConstant.get();
|
||||
if ("张三".equals(dataModel.getValue())) {
|
||||
System.out.println("是张三");
|
||||
}else {
|
||||
System.out.printf("不是张三,而是%s",dataModel.getValue());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.muyu.engine.text;
|
||||
|
||||
import com.muyu.model.DataModel;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*
|
||||
* @ClassName Main
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/5/13 16:23
|
||||
*/
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
public static final ConcurrentHashMap<String,Base> ruleEngineMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
static {
|
||||
init();
|
||||
}
|
||||
|
||||
public static void init(){
|
||||
ruleEngineMap.put("a",new A());
|
||||
ruleEngineMap.put("b",new B());
|
||||
ruleEngineMap.put("c",new C());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
DataModel dataModel = new DataModel();
|
||||
dataModel.setValue("王五");
|
||||
dataModel.setKey("name");
|
||||
dataModel.setProcessClass(String.class);
|
||||
dataModel.setSourceType("varchar");
|
||||
dataModel.setProcessType("String");
|
||||
|
||||
ThreadConstant.set(dataModel);
|
||||
Base a = ruleEngineMap.get("a");
|
||||
Base b = ruleEngineMap.get("b");
|
||||
Base c = ruleEngineMap.get("c");
|
||||
a.execution();
|
||||
b.execution();
|
||||
c.execution();
|
||||
ThreadConstant.remove();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.engine.text;
|
||||
|
||||
|
||||
import com.muyu.model.DataModel;
|
||||
|
||||
/**
|
||||
* @ClassName ThreadConstant
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/5/13 16:26
|
||||
*/
|
||||
|
||||
|
||||
public class ThreadConstant {
|
||||
private static ThreadLocal<DataModel> threadLocal = new ThreadLocal<>();
|
||||
|
||||
public static DataModel get(){
|
||||
return threadLocal.get();
|
||||
}
|
||||
|
||||
public static void set(DataModel dataModel){
|
||||
threadLocal.set(dataModel);
|
||||
}
|
||||
public static void remove(){
|
||||
threadLocal.remove();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue