提交 722775bf authored 作者: ww1xhqc's avatar ww1xhqc

model layer 代码规约检查

上级 b237fd37
......@@ -5,6 +5,9 @@ import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
/**
* @author HASEE
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Documented
......
......@@ -15,5 +15,4 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface WorkFlowCoreNoScan {
String desc ="工作流核心不扫描!";
}
......@@ -4,6 +4,7 @@ package com.tykj.workflowcore.model_layer.controller;
import com.tykj.workflowcore.base.result.ResultUtil;
import com.tykj.workflowcore.model_layer.model.QueryCondition;
import com.tykj.workflowcore.model_layer.model.SearchTableInfoVo;
import com.tykj.workflowcore.model_layer.model.TableInfo;
import com.tykj.workflowcore.model_layer.model.TableVO;
import com.tykj.workflowcore.model_layer.service.ModelService;
......@@ -11,6 +12,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -43,11 +45,10 @@ public class ModelController {
**/
@ApiOperation("得到所有数据表信息")
@RequestMapping("/getAllEntity")
public ResponseEntity getAllEntity() {
List<TableInfo> tableInfos = null;
public ResponseEntity getAllEntity(SearchTableInfoVo searchTableInfoVo) {
Page<TableInfo> tableInfos = null;
try {
tableInfos = modelService.ListAllEntities();
tableInfos = modelService.listAllEntities(searchTableInfoVo);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
......@@ -80,16 +81,14 @@ public class ModelController {
**/
@ApiOperation("新增数据模型")
@PostMapping("/addModel")
//入参使用VO直接接收即可
//jsonStr -> TableVo
public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception {
List<TableInfo> tableInfos = modelService.ListAllEntities();
List<TableInfo> tableInfos = modelService.listAllEntities();
for (TableInfo tableInfo : tableInfos) {
if (tableVO.getModelName().equals(tableInfo.getName())) {
return ResultUtil.failed("表已经存在!");
}
}
modelService.NewTable(tableVO);
modelService.newTable(tableVO);
return ResultUtil.success("","新建成功");
}
......
......@@ -24,7 +24,10 @@ public class ColumnInfo {
@Column(name = "id")
private long id;
//0是,1否
/**
* 0是,1否
*/
@Column(name = "primary_key")
private Integer primarykey;
@Column(name = "name")
......
......@@ -18,7 +18,7 @@ public class ColumnVO {
private String filedType;
private String fieldName;
private String filedDescription;
private int filedLength;
private Integer filedLength;
private Integer primarykey=1;
}
......@@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author HASEE
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
......
package com.tykj.workflowcore.model_layer.model;
import com.tykj.workflowcore.base.page.JpaCustomPage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ClassName SearchTableInfoVo
* @Description TODO
* @Author WWW
* @Date 2021/3/11 16:06
* @Version 1.0
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class SearchTableInfoVo extends JpaCustomPage {
private String tableName;
}
......@@ -42,7 +42,10 @@ public class TableInfo implements Serializable {
@Column(name = "description")
private String desc;
//0是扫描,1是自建
/**
*0是扫描,1是自建
*/
@Column(name = "type")
private Integer type;
......@@ -51,7 +54,7 @@ public class TableInfo implements Serializable {
@Lob
@Column(name = "xml")
private String XML;
private String xml;
@Column(name = "update_time")
private Date updateTime;
......
......@@ -3,10 +3,8 @@ package com.tykj.workflowcore.model_layer.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.tykj.workflowcore.model_layer.model.ColumnInfo;
import com.tykj.workflowcore.model_layer.model.QueryCondition;
import com.tykj.workflowcore.model_layer.model.TableInfo;
import com.tykj.workflowcore.model_layer.model.TableVO;
import com.tykj.workflowcore.model_layer.model.*;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -22,24 +20,67 @@ import java.util.Map;
* @Date 2021/2/26 13:36
* @Version 1.0
*/
@Transactional
@Service
public interface ModelService {
List<TableInfo> ListAllEntities() throws SQLException;
/**
* 分页查询
* @param searchTableInfoVo
* @return
* @throws SQLException
*/
Page<TableInfo> listAllEntities(SearchTableInfoVo searchTableInfoVo) throws SQLException;
/**
* 方法重载不分页查询
* @return
* @throws SQLException
*/
List<TableInfo> listAllEntities() throws SQLException;
List<ColumnInfo> showModelFields(String ModelName);
TableVO addModel(String tableVO) throws JsonProcessingException;
/**
* 根据表名查询所有字段信息
* @param modelName
* @return
*/
List<ColumnInfo> showModelFields(String modelName);
TableVO NewTable(TableVO tableVO);
/**
* 新建模型
* @param tableVO
* @return
*/
TableVO newTable(TableVO tableVO);
/**
* 根据表名插入数据
* @param map
* @return
*/
int putValueByEntityName(Map<String, Object> map);
/**
* 扫描
* @param classList
*/
void swaggerScan(List<Class<?>> classList);
/**
* 根据表名查询所有
* @param name
* @return
* @throws SQLException
*/
List findAllByName(String name) throws SQLException;
/**
* 复杂查询
* @param tableName
* @param queryConditions
* @return
*/
List complexQuery(String tableName, List<QueryCondition> queryConditions);
}
package com.tykj.workflowcore.model_layer.utils;
import cn.hutool.json.XML;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import com.tykj.workflowcore.model_layer.model.ColumnVO;
import com.tykj.workflowcore.model_layer.model.TableInfo;
......@@ -32,38 +33,38 @@ import java.util.List;
* @Version 1.0
*/
public class CreatTableUtil {
public static String CreatTable(TableVO tableVO){
public static String creatTable(TableVO tableVO){
List<ColumnVO> dataList = tableVO.getDataList();
String XML_MAPPING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
String xmlMapping = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE hibernate-mapping PUBLIC\n" +
" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" +
" \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n" +
"<hibernate-mapping>\n" +
" <class entity-name=\"" + tableVO.getModelName() + "\" table=\"" + tableVO.getModelName() + "\">\n";
XML_MAPPING += " <id name=\"id\" type=\"java.lang.Long\" length=\"64\" unsaved-value=\"null\">\n" +
xmlMapping += " <id name=\"id\" type=\"java.lang.Long\" length=\"64\" unsaved-value=\"null\">\n" +
" <generator class=\"identity\" />\n" +
" </id>";
for (ColumnVO columnVO : dataList) {
XML_MAPPING +=
xmlMapping +=
" <property type=\"" + columnVO.getFiledType() + "\" name=\"" + columnVO.getFieldName() +
"\" column=\"" + columnVO.getFieldName() + "\"/>\n";
}
XML_MAPPING += " </class>" +
xmlMapping += " </class>" +
"</hibernate-mapping>";
return XML_MAPPING;
return xmlMapping;
}
public Session getSession(EntityManagerFactory entityManagerFactory,String XML){
public Session getSession(EntityManagerFactory entityManagerFactory,String xml){
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
StandardServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
sessionFactory.getSessionFactoryOptions();
metadataSources.addInputStream(new ByteArrayInputStream(XML.getBytes()));
metadataSources.addInputStream(new ByteArrayInputStream(xml.getBytes()));
Metadata metadata = metadataSources.buildMetadata();
//更新数据库Schema,如果不存在就创建表,存在就更新字段,不会影响已有数据
SchemaUpdate schemaUpdate = new SchemaUpdate();
......@@ -79,13 +80,13 @@ public class CreatTableUtil {
}
//处理.
public static String getClassName(String aClass){
int i = aClass.lastIndexOf(".");
String substring = aClass.substring(i+1);
return substring;
}
// 处理带空格的class
public static String getTypeName(String aClass){
return aClass.replace("class ", "");
......
......@@ -5,6 +5,9 @@ import com.tykj.workflowcore.model_layer.model.QueryCondition;
import java.util.List;
import java.util.Objects;
/**
* @author HASEE
*/
public class HqlUtil {
public static String createQuery(String tableName, List<QueryCondition> conditions) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论