feat(dataAccessServiceImpl,AccessServiceImpl)增加了同步和测试,完善了数据结构,重写字典

dev-1
王熙朝 2024-04-24 21:29:05 +08:00
parent 8e2250f874
commit 596a557ca1
10 changed files with 165 additions and 28 deletions

View File

@ -3,9 +3,7 @@ package com.muyu.system.controller;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController; import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.system.domain.SysUser; import com.muyu.common.system.domain.SysUser;
import com.muyu.system.domain.ListStructure; import com.muyu.system.domain.*;
import com.muyu.system.domain.TableList;
import com.muyu.system.domain.TableName;
import com.muyu.system.domain.vo.DeptVO; import com.muyu.system.domain.vo.DeptVO;
import com.muyu.system.domain.vo.SysUserVo; import com.muyu.system.domain.vo.SysUserVo;
import com.muyu.system.domain.vo.TableVo; import com.muyu.system.domain.vo.TableVo;
@ -35,7 +33,7 @@ public class AccreditController extends BaseController {
* *
* @return * @return
*/ */
@PostMapping("tableNameList") @PostMapping("/tableNameList")
public Result<List<TableList>> tableNameList(){ public Result<List<TableList>> tableNameList(){
List<TableList> list = service.tableNameList(); List<TableList> list = service.tableNameList();
return Result.success(list); return Result.success(list);
@ -45,7 +43,7 @@ public class AccreditController extends BaseController {
* *
* @return * @return
*/ */
@GetMapping("tableNameList2") @GetMapping("/tableNameList2")
public Result<List<String>> tableNameList2() throws SQLException { public Result<List<String>> tableNameList2() throws SQLException {
List<String> list = service.tableNameList2(); List<String> list = service.tableNameList2();
return Result.success(list); return Result.success(list);
@ -56,17 +54,32 @@ public class AccreditController extends BaseController {
* @return * @return
* @throws SQLException * @throws SQLException
*/ */
@GetMapping("listSqlJdbc") @GetMapping("/listSqlJdbc")
public Result listSqlJdbc(@RequestParam String tableName) throws SQLException { public Result listSqlJdbc(@RequestParam String tableName) throws SQLException {
return service.listSqlJdbc(tableName); return service.listSqlJdbc(tableName);
} }
/**
*
* @param dataAccess
* @return
*/
@PostMapping("/selJDBCStream")
public Result selJDBCStream(@RequestBody DataAccess dataAccess){
Integer id = service.selJDBCStream(dataAccess);
if (id>0){
return success("连接成功");
}else{
return error("连接失败");
}
}
/** /**
* *
* @param tableName * @param tableName
* @return * @return
*/ */
@PostMapping("selectTableXml/{tableName}") @PostMapping("/selectTableXml/{tableName}")
public Result<List<TableVo>> selectTableXml(@PathVariable String tableName){ public Result<List<TableVo>> selectTableXml(@PathVariable String tableName){
List<TableVo> list = service.selectTableXml(tableName); List<TableVo> list = service.selectTableXml(tableName);
return Result.success(list); return Result.success(list);
@ -124,4 +137,29 @@ public class AccreditController extends BaseController {
return success(list); return success(list);
} }
/**
*
* @return
*/
@PostMapping("/selectDictionaryMajor")
public Result<List<DictionaryMajor>> selectDictionaryMajor(){
List<DictionaryMajor> list = service.selectDictionaryMajor();
return Result.success(list);
}
/**
* /
* @param listStructure
* @return
*/
@PostMapping("/updateListStructure")
public Result updateListStructure(@RequestBody ListStructure listStructure){
Integer id = service.updateListStructure(listStructure);
if (id>0){
return success("修改完成");
}else{
return error("修改有异常请检查");
}
}
} }

View File

@ -101,4 +101,19 @@ public class DataAccessController extends BaseController
{ {
return toAjax(dataAccessService.deleteDataAccessByIds(ids)); return toAjax(dataAccessService.deleteDataAccessByIds(ids));
} }
/**
*
* @param dataAccess
* @return
*/
@PostMapping("/synchronization")
public Result synchronization(@RequestBody DataAccess dataAccess) throws SQLException {
Integer id = dataAccessService.synchronization(dataAccess);
if (id>0){
return success("成功同步");
}else{
return error("同步失败");
}
}
} }

View File

@ -3,7 +3,7 @@ package com.muyu.system.domain;
import lombok.Data; import lombok.Data;
@Data @Data
public class dictionaryMajor { public class DictionaryMajor {
/** /**
* *
*/ */
@ -11,5 +11,5 @@ public class dictionaryMajor {
/** /**
* *
*/ */
private Integer dictionaryExpression; private String dictionaryExpression;
} }

View File

@ -45,4 +45,12 @@ public class ListStructure {
* *
*/ */
private String columnComments; private String columnComments;
/**
*
*/
private String yesOrNo;
/**
*
*/
private String dictionary;
} }

View File

@ -1,9 +1,6 @@
package com.muyu.system.mapper; package com.muyu.system.mapper;
import com.muyu.system.domain.Library; import com.muyu.system.domain.*;
import com.muyu.system.domain.ListStructure;
import com.muyu.system.domain.TableList;
import com.muyu.system.domain.TableName;
import com.muyu.system.domain.vo.TableVo; import com.muyu.system.domain.vo.TableVo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -37,4 +34,9 @@ public interface AccreditMapper {
int selectOneTableList(@Param("s") String s); int selectOneTableList(@Param("s") String s);
int selectOneSqlJdbc(@Param("s") String s); int selectOneSqlJdbc(@Param("s") String s);
List<DictionaryMajor> selectDictionaryMajor();
Integer updateListStructure(ListStructure listStructure);
} }

View File

@ -1,10 +1,7 @@
package com.muyu.system.service; package com.muyu.system.service;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import com.muyu.system.domain.Library; import com.muyu.system.domain.*;
import com.muyu.system.domain.ListStructure;
import com.muyu.system.domain.TableList;
import com.muyu.system.domain.TableName;
import com.muyu.system.domain.vo.TableVo; import com.muyu.system.domain.vo.TableVo;
import java.sql.SQLException; import java.sql.SQLException;
@ -24,4 +21,10 @@ public interface AccreditService {
TableList selNameTableList(String name); TableList selNameTableList(String name);
List<ListStructure> selNameListStructure(String tableName); List<ListStructure> selNameListStructure(String tableName);
List<DictionaryMajor> selectDictionaryMajor();
Integer updateListStructure(ListStructure listStructure);
Integer selJDBCStream(DataAccess dataAccess);
} }

View File

@ -59,4 +59,6 @@ public interface IDataAccessService
* @return * @return
*/ */
public int deleteDataAccessById(Long id); public int deleteDataAccessById(Long id);
Integer synchronization(DataAccess dataAccess) throws SQLException;
} }

View File

@ -1,10 +1,8 @@
package com.muyu.system.service.impl; package com.muyu.system.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import com.muyu.system.domain.Library; import com.muyu.system.domain.*;
import com.muyu.system.domain.ListStructure;
import com.muyu.system.domain.TableList;
import com.muyu.system.domain.TableName;
import com.muyu.system.domain.vo.TableVo; import com.muyu.system.domain.vo.TableVo;
import com.muyu.system.mapper.AccreditMapper; import com.muyu.system.mapper.AccreditMapper;
import com.muyu.system.service.AccreditService; import com.muyu.system.service.AccreditService;
@ -133,6 +131,46 @@ public class AccreditServiceImpl implements AccreditService {
return mapper.selNameListStructure(tableName); return mapper.selNameListStructure(tableName);
} }
@Override
public List<DictionaryMajor> selectDictionaryMajor() {
return mapper.selectDictionaryMajor();
}
@Override
public Integer updateListStructure(ListStructure listStructure) {
//判断是否加入字典
if (!listStructure.getYesOrNo().equals("Y")){
listStructure.setDictionary(null);
}
//修改状态
Integer i = mapper.updateListStructure(listStructure);
return i;
}
@Override
public Integer selJDBCStream(DataAccess dataAccess) {
Integer id = 0;
try {
//加载数据库驱动
Class<?> aClass = Class.forName("com.mysql.cj.jdbc.Driver");
Driver driver = (Driver) aClass.newInstance();
System.out.println(driver);
//获取数据库连接
Connection connection = DriverManager.getConnection("jdbc:mysql://129.211.23.219:3306/"+ dataAccess.getDatabaseName() +"?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8","root","Qq4152637");
System.out.println(connection);
id = 1;
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
return id;
}
//获取字段注解 //获取字段注解
private Map<String,String> getColumnComments(DatabaseMetaData metaData,String typeName){ private Map<String,String> getColumnComments(DatabaseMetaData metaData,String typeName){
Map<String,String> columnComents = new HashMap<>(); Map<String,String> columnComents = new HashMap<>();

View File

@ -62,13 +62,6 @@ public class DataAccessServiceImpl implements IDataAccessService
@Override @Override
public int insertDataAccess(DataAccess dataAccess) throws SQLException { public int insertDataAccess(DataAccess dataAccess) throws SQLException {
int i = dataAccessMapper.insertDataAccess(dataAccess); int i = dataAccessMapper.insertDataAccess(dataAccess);
List<SysDept> list = sysDeptMapper.listDeptList();
DataAccess dataAccess1 = dataAccessMapper.oneDataAccess();
for (SysDept sysDept : list) {
//添加中间件
dataAccessMapper.insertMiddle(sysDept.getDeptId(),dataAccess1.getId());
}
accreditService.tableNameList2();
return i; return i;
} }
@ -107,4 +100,23 @@ public class DataAccessServiceImpl implements IDataAccessService
{ {
return dataAccessMapper.deleteDataAccessById(id); return dataAccessMapper.deleteDataAccessById(id);
} }
@Override
public Integer synchronization(DataAccess dataAccess) throws SQLException {
Integer id = 0;
/**
*
*/
List<SysDept> list = sysDeptMapper.listDeptList();
for (SysDept sysDept : list) {
//添加中间件
dataAccessMapper.insertMiddle(sysDept.getDeptId(),dataAccess.getId());
}
/**
*
*/
accreditService.tableNameList2();
id = 1;
return id;
}
} }

View File

@ -15,6 +15,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into tableList (name) insert into tableList (name)
values (#{s}); values (#{s});
</insert> </insert>
<update id="updateListStructure">
update list_structure
set yes_or_no = #{yesOrNo},
dictionary = #{dictionary}
where catalog_name = #{catalogName} and
table_name = #{tableName} and
column_lass_name = #{columnLassName} and
column_type_name = #{columnTypeName} and
column_name = #{columnName} and
precisions = #{precisions} and
scale = #{scale} and
is_null = #{isNull} and
schema_name = #{schemaName} and
column_comments = #{columnComments}
</update>
<select id="selectTableXml" resultType="com.muyu.system.domain.vo.TableVo"> <select id="selectTableXml" resultType="com.muyu.system.domain.vo.TableVo">
SELECT * SELECT *
FROM information_schema.columns FROM information_schema.columns
@ -59,5 +74,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(table_name) select count(table_name)
from list_structure where table_name = #{s}; from list_structure where table_name = #{s};
</select> </select>
<select id="selectDictionaryMajor" resultType="com.muyu.system.domain.DictionaryMajor">
select *
from dictionary_major
</select>
</mapper> </mapper>