提交 265a73d1 authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 去掉hutool工具

上级 d632f671
...@@ -72,7 +72,7 @@ public interface ModelService { ...@@ -72,7 +72,7 @@ public interface ModelService {
* @return * @return
* @throws SQLException * @throws SQLException
*/ */
List findAllByName(String name) throws SQLException; List<Map<String, Object>> findAllByName(String name) throws SQLException;
/** /**
...@@ -81,7 +81,7 @@ public interface ModelService { ...@@ -81,7 +81,7 @@ public interface ModelService {
* @param queryConditions * @param queryConditions
* @return * @return
*/ */
List complexQuery(String tableName, List<QueryCondition> queryConditions); List<Map<String, Object>> complexQuery(String tableName, List<QueryCondition> queryConditions);
......
package com.tykj.workflowcore.model_layer.service.impl; package com.tykj.workflowcore.model_layer.service.impl;
import cn.hutool.db.Db;
import com.github.wenhao.jpa.PredicateBuilder; import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications; import com.github.wenhao.jpa.Specifications;
import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan; import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan;
...@@ -26,8 +24,8 @@ import org.hibernate.type.Type; ...@@ -26,8 +24,8 @@ import org.hibernate.type.Type;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
...@@ -70,6 +68,9 @@ public class ModelImpl implements ModelService { ...@@ -70,6 +68,9 @@ public class ModelImpl implements ModelService {
@Autowired @Autowired
private ColumnInfoDao columnInfoDao; private ColumnInfoDao columnInfoDao;
@Autowired
private JdbcTemplate jdbcTemplate;
/** /**
* @param * @param
* @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo> * @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo>
...@@ -361,31 +362,22 @@ public class ModelImpl implements ModelService { ...@@ -361,31 +362,22 @@ public class ModelImpl implements ModelService {
* @Date 10:51 2021/3/11 * @Date 10:51 2021/3/11
**/ **/
@Override @Override
public List findAllByName(String name) { public List<Map<String, Object>> findAllByName(String name) {
if (name != null && name != "") { if (name != null && name != "") {
try { String sql="select * from "+name;
return Db.use().findAll(name); return jdbcTemplate.queryForList(sql);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
} }
return null; return null;
} }
@Override @Override
public List complexQuery(String tableName, List<QueryCondition> queryConditions) { public List<Map<String, Object>> complexQuery(String tableName, List<QueryCondition> queryConditions) {
List<cn.hutool.db.Entity> list = null;
if (!"".equals(tableName)) { if (!"".equals(tableName)) {
String query = createQuery(tableName, queryConditions); String query = createQuery(tableName, queryConditions);
try { return jdbcTemplate.queryForList(query);
list = Db.use().query(query);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
} else {
return null;
} }
return list; return null;
} }
@Override @Override
public List<TableInfo> listAllEntities() { public List<TableInfo> listAllEntities() {
...@@ -450,11 +442,8 @@ public class ModelImpl implements ModelService { ...@@ -450,11 +442,8 @@ public class ModelImpl implements ModelService {
private void UpdateColumnName(String tableName, String oldColumnName, String newColumnName) { private void UpdateColumnName(String tableName, String oldColumnName, String newColumnName) {
// ALTER TABLE stu rename column name to name2; // ALTER TABLE stu rename column name to name2;
if (""!=tableName&&tableName!=null){ if (""!=tableName&&tableName!=null){
try {
Db.use().execute(" ALTER TABLE " + tableName + " rename column " + oldColumnName + " to " + newColumnName + ";"); jdbcTemplate.execute(" ALTER TABLE " + tableName + " rename column " + oldColumnName + " to " + newColumnName + ";");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
} }
else { else {
log.info("列名:{}或者新列名:{}不合法!",oldColumnName,newColumnName); log.info("列名:{}或者新列名:{}不合法!",oldColumnName,newColumnName);
...@@ -469,11 +458,7 @@ public class ModelImpl implements ModelService { ...@@ -469,11 +458,7 @@ public class ModelImpl implements ModelService {
*/ */
private void delOneColumn(String tableName, String columnName) { private void delOneColumn(String tableName, String columnName) {
// ALTER TABLE fab2 DROP test1; // ALTER TABLE fab2 DROP test1;
try { jdbcTemplate.execute("ALTER TABLE " + tableName + " DROP " + columnName + ";");
Db.use().execute("ALTER TABLE " + tableName + " DROP " + columnName + ";");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
} }
/** /**
...@@ -484,11 +469,7 @@ public class ModelImpl implements ModelService { ...@@ -484,11 +469,7 @@ public class ModelImpl implements ModelService {
*/ */
private void addOneColumn(String tableName, String columnName, String type) { private void addOneColumn(String tableName, String columnName, String type) {
// alter table fab2 add test1 varchar(10) not Null; // alter table fab2 add test1 varchar(10) not Null;
try { jdbcTemplate.execute(" alter table "+tableName+" add "+columnName+" "+type);
Db.use().execute(" alter table "+tableName+" add "+columnName+" "+type);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
} }
} }
...@@ -50,7 +50,6 @@ public class CreateTableUtil { ...@@ -50,7 +50,6 @@ public class CreateTableUtil {
public Session getSession(EntityManagerFactory entityManagerFactory,String xml){ public Session getSession(EntityManagerFactory entityManagerFactory,String xml){
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
StandardServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry(); StandardServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();
MetadataSources metadataSources = new MetadataSources(serviceRegistry); MetadataSources metadataSources = new MetadataSources(serviceRegistry);
...@@ -68,6 +67,7 @@ public class CreateTableUtil { ...@@ -68,6 +67,7 @@ public class CreateTableUtil {
Session newSession = newSessionFactory.openSession(); Session newSession = newSessionFactory.openSession();
return newSession; return newSession;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论