提交 2d7f2c96 authored 作者: 黄夏豪's avatar 黄夏豪

为 workflow 的 entity 加上了@NoScan 注解

启动类里增加了 model扫描
上级 f9cd3177
package com.tykj.workflowcore;
import com.tykj.workflowcore.api.service.ApiService;
import com.tykj.workflowcore.model_layer.service.ModelService;
import liquibase.pro.packaged.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
/**
* @author HuangXiahao
......@@ -15,6 +24,9 @@ import java.io.File;
@Component
public class WorkflowCoreRunner implements CommandLineRunner {
@Autowired
ModelService modelService;
@Bean
ClassLoader initClassLoader(){
return getClass().getClassLoader();
......@@ -25,6 +37,7 @@ public class WorkflowCoreRunner implements CommandLineRunner {
System.out.println("核心成功启动");
//创建xml文件夹 如果不存在的话
createXmlMkdir();
modelService.swaggerScan(loadClassByLoader(this.getClass().getClassLoader()));
}
public void createXmlMkdir(){
......@@ -34,6 +47,47 @@ public class WorkflowCoreRunner implements CommandLineRunner {
}
}
//通过loader加载所有类
private List<Class<?>> loadClassByLoader(ClassLoader load) {
List<Class<?>> classes = new ArrayList<>();
try {
Enumeration<URL> urls = load.getResources("");
//放所有类型
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
//文件类型(其实是文件夹)
if (url.getProtocol().equals("file")) {
loadClassByPath(null, url.getPath(), classes, load);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return classes;
}
//通过文件路径加载所有类 root 主要用来替换path中前缀(除包路径以外的路径)
private void loadClassByPath(String root, String path, List<Class<?>> list, ClassLoader load) {
File f = new File(path);
if (root == null) root = f.getPath();
//判断是否是class文件
if (f.isFile() && f.getName().matches("^.*\\.class$")) {
try {
String classPath = f.getPath();
//截取出className 将路径分割符替换为.(windows是\ linux、mac是/)
String className = classPath.substring(root.length() + 1, classPath.length() - 6).replace('/', '.').replace('\\', '.');
list.add(load.loadClass(className));
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
File[] fs = f.listFiles();
if (fs == null) return;
for (File file : fs) {
loadClassByPath(root, file.getPath(), list, load);
}
}
}
}
package com.tykj.workflowcore.workflow_editer.util;
package com.tykj.workflowcore.base.result;
import org.springframework.http.ResponseEntity;
......
package com.tykj.workflowcore.workflow_editer.util;
package com.tykj.workflowcore.base.result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
......
......@@ -35,4 +35,6 @@ public interface ModelService {
TableVO NewTable(TableVO tableVO);
int putValueByEntityName(Map<String ,Object> map );
void swaggerScan(List<Class<?>> classList);
}
......@@ -240,86 +240,89 @@ public class ModelImpl implements ModelService {
newSession.close();
}
public void SwaggerScan(Class<?> aClass) {
if (!aClass.isAnnotationPresent(WorkFlowCoreNoScan.class)) {
if (aClass.isAnnotationPresent(Entity.class)) {
TableInfo tableInfo = new TableInfo();
@Override
public void swaggerScan(List<Class<?>> classList) {
for (Class<?> aClass : classList) {
if (!aClass.isAnnotationPresent(WorkFlowCoreNoScan.class)) {
if (aClass.isAnnotationPresent(Entity.class)) {
TableInfo tableInfo = new TableInfo();
// tableInfo.setId(id);
TableVO tableVO = new TableVO();
String className = getClassName(aClass.toString());
tableVO.setModelName(className.toLowerCase() + "_model_test");
if (aClass.isAnnotationPresent(ApiModel.class)) {
ApiModel annotation = aClass.getAnnotation(ApiModel.class);
StringBuilder APiModelDocument = new StringBuilder();
if (annotation.value() != null && !annotation.value().equals("")) {
APiModelDocument.append(annotation.value() + "|");
}
if (annotation.description() != null && !annotation.description().equals("")) {
APiModelDocument.append(annotation.description() + "|");
}
tableVO.setModelTitle(APiModelDocument.toString());
} else {
tableVO.setModelTitle("");
}
Field[] declaredFields = aClass.getDeclaredFields();
java.lang.reflect.Type genericType = null;
List<ColumnVO> list = new ArrayList<>();
for (Field declaredField : declaredFields) {
ColumnVO columnVO = new ColumnVO();
genericType = declaredField.getGenericType();
columnVO.setFiledType(genericType.toString());
columnVO.setFieldName(getClassName(declaredField.toString()));
TableVO tableVO = new TableVO();
String className = getClassName(aClass.toString());
tableVO.setModelName(className.toLowerCase() + "_model_test");
if (declaredField.isAnnotationPresent(ApiModelProperty.class)) {
ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
StringBuilder ApiModelPropertyDocument = new StringBuilder();
if (aClass.isAnnotationPresent(ApiModel.class)) {
ApiModel annotation = aClass.getAnnotation(ApiModel.class);
StringBuilder APiModelDocument = new StringBuilder();
if (annotation.value() != null && !annotation.value().equals("")) {
ApiModelPropertyDocument.append(annotation.value() + "|");
APiModelDocument.append(annotation.value() + "|");
}
if (annotation.example() != null && !annotation.example().equals("")) {
ApiModelPropertyDocument.append(annotation.example() + "|");
if (annotation.description() != null && !annotation.description().equals("")) {
APiModelDocument.append(annotation.description() + "|");
}
columnVO.setFiledDescription(ApiModelPropertyDocument.toString());
tableVO.setModelTitle(APiModelDocument.toString());
} else {
columnVO.setFiledDescription("无描述");
tableVO.setModelTitle("");
}
list.add(columnVO);
}
tableVO.setDataList(list);
String xml = CreatTable(tableVO);
tableInfo.setName(tableVO.getModelName());
tableInfo.setCnName(tableVO.getModelTitle());
tableInfo.setXML(xml);
tableInfo= tableInfoDao.save(tableInfo);
List<ColumnVO> dataList = tableVO.getDataList();
for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setName(columnVO.getFieldName());
columnInfo.setType(columnVO.getFiledType());
columnInfo.setLength(columnVO.getFiledLength());
columnInfo.setCnName(columnVO.getFiledDescription());
if (genericType.toString().equals("class java.lang.String")){
columnInfo.setLength(65535);
Field[] declaredFields = aClass.getDeclaredFields();
java.lang.reflect.Type genericType = null;
List<ColumnVO> list = new ArrayList<>();
for (Field declaredField : declaredFields) {
ColumnVO columnVO = new ColumnVO();
genericType = declaredField.getGenericType();
columnVO.setFiledType(genericType.toString());
columnVO.setFieldName(getClassName(declaredField.toString()));
if (declaredField.isAnnotationPresent(ApiModelProperty.class)) {
ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
StringBuilder ApiModelPropertyDocument = new StringBuilder();
if (annotation.value() != null && !annotation.value().equals("")) {
ApiModelPropertyDocument.append(annotation.value() + "|");
}
if (annotation.example() != null && !annotation.example().equals("")) {
ApiModelPropertyDocument.append(annotation.example() + "|");
}
columnVO.setFiledDescription(ApiModelPropertyDocument.toString());
} else {
columnVO.setFiledDescription("无描述");
}
list.add(columnVO);
}
else if (genericType.toString().equals("class java.lang.Integer")){
columnInfo.setLength(11);
tableVO.setDataList(list);
String xml = CreatTable(tableVO);
tableInfo.setName(tableVO.getModelName());
tableInfo.setCnName(tableVO.getModelTitle());
tableInfo.setXML(xml);
tableInfo= tableInfoDao.save(tableInfo);
List<ColumnVO> dataList = tableVO.getDataList();
for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setName(columnVO.getFieldName());
columnInfo.setType(columnVO.getFiledType());
columnInfo.setLength(columnVO.getFiledLength());
columnInfo.setCnName(columnVO.getFiledDescription());
if (genericType.toString().equals("class java.lang.String")){
columnInfo.setLength(65535);
}
else if (genericType.toString().equals("class java.lang.Integer")){
columnInfo.setLength(11);
}else {
columnInfo.setLength(0);
}else {
columnInfo.setLength(0);
}
columnInfo.setDbName(className);
columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo);
}
columnInfo.setDbName(className);
columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo);
}
}
}
}
......
package com.tykj.workflowcore.workflow_editer.entity;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -24,6 +25,7 @@ import java.util.Date;
@AllArgsConstructor
@NoArgsConstructor
@Entity
@WorkFlowCoreNoScan
@Api("流程表")
public class FlowsInfo {
@Id
......
package com.tykj.workflowcore.workflow_editer.entity;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import com.tykj.workflowcore.workflow_editer.vo.InFormPageVo;
import com.tykj.workflowcore.workflow_editer.vo.OutFormPageVo;
import io.swagger.annotations.Api;
......@@ -24,6 +25,7 @@ import java.util.Date;
@AllArgsConstructor
@NoArgsConstructor
@Entity
@WorkFlowCoreNoScan
@Api("表单页面")
public class FormPage {
......
package com.tykj.workflowcore.workflow_editer.entity;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -23,6 +24,7 @@ import javax.persistence.Id;
@AllArgsConstructor
@NoArgsConstructor
@Entity
@WorkFlowCoreNoScan
@Api("节点所在页面")
public class NodePage {
......
package com.tykj.workflowcore.workflow_editer.entity;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......
package com.tykj.workflowcore.workflow_editer.entity;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -24,6 +25,7 @@ import java.util.Date;
@AllArgsConstructor
@NoArgsConstructor
@Entity
@WorkFlowCoreNoScan
@Api("消息发送")
public class SiteMessage {
@Id
......
package com.tykj.workflowcore.workflow_editer.entity;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
......@@ -22,6 +23,7 @@ import javax.persistence.Id;
@AllArgsConstructor
@NoArgsConstructor
@Entity
@WorkFlowCoreNoScan
public class VariableStorage {
@Id
......
package com.tykj.workflowcore.workflow_editer.util;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author dengdiyi
* @description 接口返回统一标准类
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonPropertyOrder(value = {"message", "data"})
public class ResultObj<T> {
private T data;
private String message;
public ResultObj(T o) {
this.data = o;
this.message = "no message";
}
public ResultObj(String m) {
this.message = m;
}
}
package com.tykj.workflowcore.workflow_editer.util;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
/**
* @author HuangXiahao
* @version V1.0
* @class ResultMessage
* @packageName com.example.hello.demo.resultObject
**/
public class ResultUtil<T> {
/**
* 成功返回结果
*
* @param data 获取的数据
*/
public static <T> ResponseEntity<ResultObj<T>> success(T data,String message) {
return ResponseEntity.ok(new ResultObj<>(data,message));
}
/**
* 成功返回结果
*
* @param data 获取的数据
*/
public static <T> ResponseEntity success(T data, HttpHeaders headers) {
return new ResponseEntity(new ResultObj(data), headers, HttpStatus.OK);
}
/**
* 失败返回结果
*/
public static <T> ResponseEntity failed() {
return ResponseEntity.status(500).body(new ResultObj("服务器内部发生错误"));
}
/**
* 失败返回结果
*/
public static <T> ResponseEntity failed(T content) {
return new ResponseEntity(new ResultObj(content), HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
* 失败返回结果
*/
public static <T> ResponseEntity failed(HttpStatus httpStatus) {
return new ResponseEntity(httpStatus);
}
/**
* 失败返回结果
*/
public static <T> ResponseEntity failed(HttpStatus httpStatus, T content) {
return new ResponseEntity(new ResultObj(content), httpStatus);
}
/**
* 参数验证失败返回结果
*/
public static <T> ResponseEntity validateFailed(T content) {
return failed(HttpStatus.INTERNAL_SERVER_ERROR, content);
}
/**
* 未登录返回结果
*/
public static <T> ResponseEntity unauthorized() {
return failed(HttpStatus.UNAUTHORIZED);
}
/**
* 未授权返回结果
*/
public static <T> ResponseEntity forbidden() {
return failed(HttpStatus.FORBIDDEN);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论