From 576743ed18bf51fe2618a15e976edd1178f9df36 Mon Sep 17 00:00:00 2001 From: alwaysfrin <39822157+alwaysfrin@users.noreply.github.com> Date: Fri, 8 Mar 2019 17:56:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=EF=BC=8C=E5=8A=A8=E6=80=81=E5=AF=B9=E8=B1=A1=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i3plus/pojo/base/dynamic/DynamicEntity.java | 204 ++++++++++++++++++++- 1 file changed, 195 insertions(+), 9 deletions(-) diff --git a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/dynamic/DynamicEntity.java b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/dynamic/DynamicEntity.java index 2fcee00..c8006b8 100644 --- a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/dynamic/DynamicEntity.java +++ b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/dynamic/DynamicEntity.java @@ -1,7 +1,21 @@ package cn.estsh.i3plus.pojo.base.dynamic; import cn.estsh.i3plus.pojo.base.bean.BaseBean; +import lombok.Getter; +import lombok.Setter; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * @Description : 基础动态对象,包含方法、参数等 @@ -10,24 +24,46 @@ import org.apache.commons.lang3.builder.ReflectionToStringBuilder; * @CreateDate : 2019-01-24 15:56 * @Modify: **/ -public class DynamicEntity extends BaseBean { +public class DynamicEntity extends BaseBean implements Serializable { + + public static final Logger LOGGER = LoggerFactory.getLogger(DynamicEntity.class); + public String tableName; + /*private String uri; private String method; - private String uri; private Object[] args; private Object result; private String operator; - private String appName; + private String appName;*/ + + public List propertyList; + + public DynamicEntity(){ + try { + this.setPropertyList(new ArrayList<>()); + initDynamic(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public DynamicEntity(String tableName){ + this.tableName = tableName; + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } /** * 获取当前对象 * - * @param method - * @param uri - * @param args - * @param result * @return - */ + *//* public DynamicEntity get(String method, String uri, Object[] args, Object result, String operator, String appName) { setMethod(method); setUri(uri); @@ -84,10 +120,160 @@ public class DynamicEntity extends BaseBean { public void setAppName(String appName) { this.appName = appName; + }*/ + + /** + * 初始化属性,以便动态加载 + * @throws InvocationTargetException + * @throws IllegalAccessException + * @throws NoSuchMethodException + */ + public void initDynamic() { + Field[] fields = this.getClass().getDeclaredFields(); + + Method setMethod = null; + String setMethodName,propName; + Object fieldVal = null; + + for(Field f : fields) { + propName = f.getName().replace("$cglib_prop_", ""); + if(!"LOGGER".equals(propName) && !"propertyList".equals(propName)) { + this.getPropertyList().add(propName); //添加到属性list中 + + setMethodName = "set" + propName.substring(0,1).toUpperCase() + propName.substring(1); + + f.setAccessible(true); + try { + fieldVal = f.get(this); + } catch (IllegalAccessException e) { + fieldVal = null; + } + + if(fieldVal == null) { + if (f.getType() == Integer.class) { + fieldVal = 0; + } else if (f.getType() == Long.class) { + fieldVal = 0L; + } else if (f.getType() == Float.class) { + fieldVal = 0.0f; + } else if (f.getType() == Double.class) { + fieldVal = 0.0d; + } else { + fieldVal = ""; + } + } + + try { + setMethod = this.getClass().getDeclaredMethod(setMethodName, new Class[]{f.getType()}); + setMethod.invoke(this, fieldVal); + } catch (NoSuchMethodException e) { + LOGGER.error("没有方法:{}", setMethodName, e); + } catch (IllegalAccessException e) { + LOGGER.error("入参出错:{}:{}:{}", f, f.getType(), fieldVal, e); + } catch (InvocationTargetException e) { + LOGGER.error("方法返回出错:{}", setMethodName, e); + } + } + } } @Override public String toString() { - return ReflectionToStringBuilder.toString(this); + String result = "{"; + + Object fieldVal = null; + Field[] fields = this.getClass().getDeclaredFields(); + String fieldName; + for(Field f : fields) { + fieldName = f.getName().replace("$cglib_prop_", ""); + if(!"LOGGER".equals(fieldName) && !"propertyList".equals(fieldName)) { + f.setAccessible(true); + fieldVal = new Object(); + try { + fieldVal = f.get(this); + } catch (IllegalAccessException e) { + fieldVal = null; + } + + if (fieldVal == null) { + if (f.getType() == Integer.class || f.getType() == Long.class) { + fieldVal = 0; + } else if (f.getType() == Float.class || f.getType() == Double.class) { + fieldVal = 0.0; + } else { + fieldVal = ""; + } + } + + result += "\"" + fieldName + "\":\"" + fieldVal + "\","; + } + } + if(fields.length > 0) { + result = result.substring(0,result.length()-1); + } + + result += "}"; + + return result; + } + + /** + * 根据属性名,设置属性值 + * @param propName + * @param val + * @throws InvocationTargetException + * @throws IllegalAccessException + * @throws NoSuchMethodException + */ + public void setDynProperty(String propName,Object val){ + //初始化set方法 + String setMethodName = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1); + //获取方法 + Method setMethod = null; + try { + setMethod = this.getClass().getDeclaredMethod(setMethodName, new Class[]{val.getClass()}); + setMethod.invoke(this, val); + } catch (NoSuchMethodException e) { + LOGGER.error("没有方法:{}",setMethodName,e); + } catch (IllegalAccessException e) { + LOGGER.error("入参出错:{}:{}",val,val.getClass(),e); + } catch (InvocationTargetException e) { + LOGGER.error("方法返回出错:{}",setMethodName,e); + } + } + + /** + * 获取属性值 + * @param propName + * @return + * @throws NoSuchMethodException + * @throws InvocationTargetException + * @throws IllegalAccessException + */ + public Object getDynProperty(String propName){ + //初始化set方法 + String setMethodName = "get" + propName.substring(0,1).toUpperCase() + propName.substring(1); + + try { + //获取方法 + Method getMethod = this.getClass().getDeclaredMethod(setMethodName); + //实现方法 + return getMethod.invoke(this); + } catch (NoSuchMethodException e) { + LOGGER.error("没有方法:{}:{}",setMethodName,propName,e); + } catch (IllegalAccessException e) { + LOGGER.error("没有方法:{}:{}",setMethodName,propName,e); + } catch (InvocationTargetException e) { + LOGGER.error("方法返回出错:{}",setMethodName,e); + } + return null; + } + + public List getPropertyList() { + return propertyList; + } + + public void setPropertyList(List propertyList) { + this.propertyList = propertyList; } } From dcdaece309e6533e8de0441c8403d6126f55511d Mon Sep 17 00:00:00 2001 From: alwaysfrin <39822157+alwaysfrin@users.noreply.github.com> Date: Fri, 8 Mar 2019 17:57:14 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estsh/i3plus/pojo/form/bean/BfDataObject.java | 45 ++++++++++++++++++ .../pojo/form/bean/BfDataObjectProperty.java | 53 ++++++++++++++++++++++ .../i3plus/pojo/form/bean/BfDataObjectRefer.java | 43 ++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObject.java create mode 100644 modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObjectProperty.java create mode 100644 modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObjectRefer.java diff --git a/modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObject.java b/modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObject.java new file mode 100644 index 0000000..c7a668f --- /dev/null +++ b/modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObject.java @@ -0,0 +1,45 @@ +package cn.estsh.i3plus.pojo.form.bean; + +import cn.estsh.i3plus.pojo.base.bean.BaseBean; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +/** + * @Description : 数据对象 + * @Reference : + * @Author : alwaysfrin + * @CreateDate : 2019-02-27 10:53 + * @Modify: + **/ +@Data +@Entity +@DynamicInsert +@DynamicUpdate +@EqualsAndHashCode(callSuper = true) +@Table(name="bf_data_object") +@Api(value="数据对象表",description = "用来存储动态对象的相关属性") +public class BfDataObject extends BaseBean { + + @Column(name="NAME") + @ApiParam(value ="中文名称") + private String objectName; + + @Column(name="TABLE_NAME") + @ApiParam(value ="表名") + private String tableName; + + @Column(name="is_view") + @ApiParam(value ="是否视图",access = "判断是否是视图,如果不是视图,则是表名") + //EnunmUtil.TRUE_OR_FALSE + private int isView; +} diff --git a/modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObjectProperty.java b/modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObjectProperty.java new file mode 100644 index 0000000..e67c549 --- /dev/null +++ b/modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObjectProperty.java @@ -0,0 +1,53 @@ +package cn.estsh.i3plus.pojo.form.bean; + +import cn.estsh.i3plus.pojo.base.bean.BaseBean; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +/** + * @Description : 数据对象 + * @Reference : + * @Author : alwaysfrin + * @CreateDate : 2019-02-27 10:53 + * @Modify: + **/ +@Data +@Entity +@DynamicInsert +@DynamicUpdate +@EqualsAndHashCode(callSuper = true) +@Table(name="bf_data_object_property") +@Api(value="数据对象属性表",description = "数据对象的属性明细表") +public class BfDataObjectProperty extends BaseBean { + + @Column(name="DATA_OBJECT_ID") + @ApiParam(value ="数据对象ID" , example = "-1") + @JsonSerialize(using = ToStringSerializer.class) + //外键关联数据对象主键 + private Long dataObjectId; + + @Column(name="PROP_NAME") + @ApiParam(value ="属性中文名称") + private String propName; + + @Column(name="PROP_OBJECT_NAME") + @ApiParam(value ="对象中的属性名") + //在动态对象中的属性名 + private String propObjectName; + + @Column(name="PROP_COLUMN_NAME") + @ApiParam(value ="属性字段名") + //属性在数据库中的字段名 + private String propColumnName; + +} diff --git a/modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObjectRefer.java b/modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObjectRefer.java new file mode 100644 index 0000000..4caa374 --- /dev/null +++ b/modules/i3plus-pojo-form/src/main/java/cn/estsh/i3plus/pojo/form/bean/BfDataObjectRefer.java @@ -0,0 +1,43 @@ +package cn.estsh.i3plus.pojo.form.bean; + +import cn.estsh.i3plus.pojo.base.bean.BaseBean; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +/** + * @Description : 数据对象 + * @Reference : + * @Author : alwaysfrin + * @CreateDate : 2019-02-27 10:53 + * @Modify: + **/ +@Data +@Entity +@DynamicInsert +@DynamicUpdate +@EqualsAndHashCode(callSuper = true) +@Table(name="bf_data_object") +@Api(value="数据对象表",description = "用来存储动态对象的相关属性") +public class BfDataObjectRefer extends BaseBean { + + @Column(name="NAME") + @ApiParam(value ="中文名称") + private String objectName; + + @Column(name="TABLE_NAME") + @ApiParam(value ="表名") + private String tableName; + + @Column(name="is_view") + @ApiParam(value ="是否视图",access = "判断是否是视图,如果不是视图,则是表名") + //EnunmUtil.TRUE_OR_FALSE + private int isView; +} From e4600e1c01ef5205fed2da0e4557e0bd504878c0 Mon Sep 17 00:00:00 2001 From: Silliter Date: Tue, 12 Mar 2019 16:59:19 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E7=A7=BB=E5=8A=A8=E4=BF=A1=E6=81=AF=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../estsh/i3plus/pojo/base/enumutil/WmsEnumUtil.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/enumutil/WmsEnumUtil.java b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/enumutil/WmsEnumUtil.java index c22bdc9..958a11f 100644 --- a/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/enumutil/WmsEnumUtil.java +++ b/modules/i3plus-pojo-base/src/main/java/cn/estsh/i3plus/pojo/base/enumutil/WmsEnumUtil.java @@ -1846,6 +1846,16 @@ public class WmsEnumUtil { return code; } + public static String valueOf(int val) { + String tmp = null; + for (int i = 0; i < values().length; i++) { + if (values()[i].value == val) { + tmp = values()[i].description; + } + } + return tmp; + } + public String getDescription() { return description; } @@ -1882,5 +1892,15 @@ public class WmsEnumUtil { public String getDescription() { return description; } + + public static String valueOf(int val) { + String tmp = null; + for (int i = 0; i < values().length; i++) { + if (values()[i].value == val) { + tmp = values()[i].description; + } + } + return tmp; + } } }