可以新建实体

This commit is contained in:
devezhao-corp 2018-08-04 04:01:54 +08:00
parent ce9b676b51
commit 881faf946b
27 changed files with 724 additions and 48 deletions

View file

@ -121,5 +121,11 @@
<artifactId>qiniu-java-sdk</artifactId>
<version>7.2.9</version>
</dependency>
<dependency>
<groupId>com.github.stuxuhai</groupId>
<artifactId>jpinyin</artifactId>
<version>1.1.8</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,50 @@
/*
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.metadata;
import org.dom4j.Document;
import cn.devezhao.persist4j.dialect.Dialect;
import cn.devezhao.persist4j.metadata.impl.ConfigurationMetadataFactory;
/**
*
* @author zhaofang123@gmail.com
* @since 08/04/2018
*/
public class DynamicMetadataFactory extends ConfigurationMetadataFactory {
private static final long serialVersionUID = -5709281079615412347L;
public DynamicMetadataFactory(String configLocation, Dialect dialect) {
super(configLocation, dialect);
}
@Override
protected Document readConfiguration() {
Document config = super.readConfiguration();
appendConfig4Db(config);
return config;
}
/**
* 从数据库读取配置
*
* @param config
*/
private void appendConfig4Db(Document config) {
}
}

View file

@ -88,13 +88,13 @@ public class EntityHelper {
// 实体代码
public static final int User = 001;
public static final int Department = 002;
public static final int Role = 003;
public static final int RolePrivileges = 004;
public static final int RoleMember = 005;
public static final int User = 1;
public static final int Department = 2;
public static final int Role = 3;
public static final int RolePrivileges = 4;
public static final int RoleMember = 5;
public static final int MetaEntity = 010;
public static final int MetaField = 011;
public static final int MetaEntity = 10;
public static final int MetaField = 11;
}

View file

@ -10,7 +10,7 @@ import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
import cn.devezhao.persist4j.record.JsonRecordCreator;
import cn.devezhao.rebuild.server.Application;
import cn.devezhao.rebuild.server.service.user.UserService;
import cn.devezhao.rebuild.server.service.bizuser.UserService;
/**
* @author Zhao Fangfang
@ -68,7 +68,10 @@ public class ExtRecordCreator extends JsonRecordCreator {
r.setID(createdBy, r.getEditor());
}
if (entity.containsField(owningUser)) {
r.setID(owningUser, Application.getBean(UserService.class).getDeptOfUser(r.getEditor()));
r.setID(owningUser, r.getEditor());
}
if (entity.containsField(owningDept)) {
r.setID(owningDept, Application.getBean(UserService.class).getDeptOfUser(r.getEditor()));
}
}
}

View file

@ -109,7 +109,7 @@ public class SqlExecutor {
} finally {
SqlHelper.close(keyRs);
SqlHelper.close(pstmt);
SqlHelper.release(connect, factory.getDataSource());
SqlHelper.close(connect, factory.getDataSource());
}
}

View file

@ -0,0 +1,44 @@
/*
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.service.bizuser;
import cn.devezhao.persist4j.PersistManagerFactory;
import cn.devezhao.persist4j.engine.ID;
import cn.devezhao.rebuild.server.metadata.EntityHelper;
import cn.devezhao.rebuild.server.service.BaseService;
/**
*
* @author zhaofang123@gmail.com
* @since 08/03/2018
*/
public class DepartmentService extends BaseService {
/**
* 根级部门
*/
public static final ID ROOT_DEPT = ID.valueOf("002-0000000000000001");
protected DepartmentService(PersistManagerFactory persistManagerFactory) {
super(persistManagerFactory);
}
@Override
public int getEntity() {
return EntityHelper.Department;
}
}

View file

@ -0,0 +1,44 @@
/*
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.service.bizuser;
import cn.devezhao.persist4j.PersistManagerFactory;
import cn.devezhao.persist4j.engine.ID;
import cn.devezhao.rebuild.server.metadata.EntityHelper;
import cn.devezhao.rebuild.server.service.BaseService;
/**
*
* @author zhaofang123@gmail.com
* @since 08/03/2018
*/
public class RoleService extends BaseService {
/**
* 管理员权限
*/
public static final ID ADMIN_ROLE = ID.valueOf("003-0000000000000001");
protected RoleService(PersistManagerFactory persistManagerFactory) {
super(persistManagerFactory);
}
@Override
public int getEntity() {
return EntityHelper.Role;
}
}

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.service.user;
package cn.devezhao.rebuild.server.service.bizuser;
import cn.devezhao.persist4j.PersistManagerFactory;
import cn.devezhao.persist4j.engine.ID;
@ -29,22 +29,10 @@ import cn.devezhao.rebuild.server.service.BaseService;
*/
public class UserService extends BaseService {
/**
* 系统用户
*/
public static final ID SYS_USER = ID.valueOf("001-0000000000000000");
/**
* 管理员
*/
// 系统用户
public static final ID SYSTEM_USER = ID.valueOf("001-0000000000000000");
// 管理员
public static final ID ADMIN_USER = ID.valueOf("001-0000000000000001");
/**
* 根级部门
*/
public static final ID ROOT_DEPT = ID.valueOf("002-0000000000000001");
/**
* 管理员权限
*/
public static final ID ADMIN_ROLE = ID.valueOf("003-0000000000000001");
protected UserService(PersistManagerFactory persistManagerFactory) {
super(persistManagerFactory);

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.metadata;
package cn.devezhao.rebuild.server.service.entitymanage;
import cn.devezhao.persist4j.dialect.FieldType;
import cn.devezhao.persist4j.dialect.Type;
@ -24,14 +24,10 @@ import cn.devezhao.persist4j.dialect.Type;
* @author zhaofang123@gmail.com
* @since 05/18/2018
*/
public class FieldTypes {
public class ComplexFieldTypes {
// 文本
public static final Type TEXT = FieldType.STRING;
// 超大文本
public static final Type NTEXT = FieldType.NTEXT;
// 数字/整数/浮点数
public static final Type NUMBER = FieldType.DOUBLE;

View file

@ -0,0 +1,185 @@
/*
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.service.entitymanage;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.github.stuxuhai.jpinyin.PinyinException;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import cn.devezhao.commons.ObjectUtils;
import cn.devezhao.persist4j.Entity;
import cn.devezhao.persist4j.Field;
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.dialect.Dialect;
import cn.devezhao.persist4j.dialect.FieldType;
import cn.devezhao.persist4j.dialect.Type;
import cn.devezhao.persist4j.engine.ID;
import cn.devezhao.persist4j.metadata.CascadeModel;
import cn.devezhao.persist4j.metadata.impl.FieldImpl;
import cn.devezhao.persist4j.util.support.Table;
import cn.devezhao.rebuild.server.Application;
import cn.devezhao.rebuild.server.metadata.EntityHelper;
import cn.devezhao.rebuild.server.metadata.ExtRecordCreator;
/**
*
* @author zhaofang123@gmail.com
* @since 08/03/2018
*/
public class Entity2Schema {
private static final Log LOG = LogFactory.getLog(Entity2Schema.class);
final private ID user;
/**
* @param user
*/
public Entity2Schema(ID user) {
this.user = user;
}
/**
* @param entityLabel
* @param description
* @return
*/
public String create(String entityLabel, String description) {
String entityName = toPinyinString(entityLabel);
while (true) {
Object exists = Application.createQuery(
"select entityId from MetaEntity where entityName = ?")
.setParameter(1, entityName)
.unique();
if (exists != null) {
entityName += (1000 + RandomUtils.nextInt(8999));
} else {
break;
}
}
String physicalName = "T_" + entityName;
Object maxTypeCode[] = Application.createQuery(
"select min(typeCode) from MetaEntity").unique();
int typeCode = maxTypeCode == null || ObjectUtils.toInt(maxTypeCode[0]) == 0
? 999 : (ObjectUtils.toInt(maxTypeCode[0]) - 1);
Record record = EntityHelper.forNew(EntityHelper.MetaEntity, user);
record.setString("entityLabel", entityLabel);
record.setString("entityName", entityName);
record.setString("physicalName", physicalName);
record.setInt("typeCode", typeCode);
if (StringUtils.isNotBlank(description)) {
record.setString("description", description);
}
record = Application.getCommonService().create(record);
ID metaEntityId = record.getPrimary();
Entity unsafeEntity = new UnsafeEntity(entityName, physicalName, description, typeCode, null);
String primaryFiled = entityName + "Id";
createField(unsafeEntity, metaEntityId, primaryFiled, primaryFiled,
"ID", FieldType.PRIMARY.getName(), false, false, false, null);
createField(unsafeEntity, metaEntityId, ExtRecordCreator.createdOn, ExtRecordCreator.createdOn,
"创建人", FieldType.TIMESTAMP.getName(), false, false, false, null);
createField(unsafeEntity, metaEntityId, ExtRecordCreator.createdBy, ExtRecordCreator.createdBy,
"创建时间", FieldType.REFERENCE.getName(), false, false, false, null);
createField(unsafeEntity, metaEntityId, ExtRecordCreator.modifiedBy, ExtRecordCreator.modifiedBy,
"修改人", FieldType.REFERENCE.getName(), false, false, true, null);
createField(unsafeEntity, metaEntityId, ExtRecordCreator.modifiedOn, ExtRecordCreator.modifiedOn,
"修改时间", FieldType.TIMESTAMP.getName(), false, false, true, null);
createField(unsafeEntity, metaEntityId, ExtRecordCreator.owningUser, ExtRecordCreator.owningUser,
"所属用户", FieldType.REFERENCE.getName(), false, false, true, null);
createField(unsafeEntity, metaEntityId, ExtRecordCreator.owningDept, ExtRecordCreator.owningDept,
"所属部门", FieldType.REFERENCE.getName(), false, false, true, null);
boolean schemaReady = schema2Database(unsafeEntity);
if (!schemaReady) {
Application.getCommonService().delete(metaEntityId);
return null;
}
return entityName;
}
/**
* @param unsafeEntity
* @param entityId
* @param fieldName
* @param physicalName
* @param fieldLabel
* @param type
* @param nullable
* @param creatable
* @param updatable
* @param description
* @return
*/
protected ID createField(Entity unsafeEntity, ID entityId, String fieldName, String physicalName, String fieldLabel, String type,
boolean nullable, boolean creatable, boolean updatable, String description) {
Record record = EntityHelper.forNew(EntityHelper.MetaField, user);
record.setID("entityId", entityId);
record.setString("fieldName", fieldName);
record.setString("physicalName", physicalName);
record.setString("fieldLabel", fieldLabel);
record.setString("type", type);
record.setBoolean("nullable", nullable);
record.setBoolean("creatable", creatable);
record.setBoolean("updatable", updatable);
if (StringUtils.isNotBlank(description)) {
record.setString("description", description);
}
record = Application.getCommonService().create(record);
Dialect dialect = Application.getPersistManagerFactory().getDialect();
Type fieldType = dialect.getFieldType(type);
Field unsafeField = new FieldImpl(fieldName, physicalName, description, unsafeEntity, fieldType, CascadeModel.Ignore, 0, nullable, updatable, 0, null, false);
((UnsafeEntity) unsafeEntity).addField(unsafeField);
return record.getPrimary();
}
/**
* @param entity
* @return
*/
private boolean schema2Database(Entity entity) {
Dialect dialect = Application.getPersistManagerFactory().getDialect();
Table table = new Table(entity, dialect);
String ddlSqls[] = table.generateDDL(false, false);
try {
Application.getSqlExecutor().executeBatch(ddlSqls);
} catch (Throwable ex) {
LOG.error("DDL Error : \n" + StringUtils.join(ddlSqls, "\n"), ex);
return false;
}
return true;
}
// 中文 -> 拼音
private String toPinyinString(String text) {
try {
return PinyinHelper.convertToPinyinString(text, "", PinyinFormat.WITHOUT_TONE);
} catch (PinyinException e) {
throw new RuntimeException(text, e);
}
}
}

View file

@ -0,0 +1,38 @@
/*
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.service.entitymanage;
import cn.devezhao.persist4j.PersistManagerFactory;
import cn.devezhao.rebuild.server.metadata.EntityHelper;
import cn.devezhao.rebuild.server.service.BaseService;
/**
*
* @author zhaofang123@gmail.com
* @since 08/03/2018
*/
public class MetaEntityService extends BaseService {
protected MetaEntityService(PersistManagerFactory persistManagerFactory) {
super(persistManagerFactory);
}
@Override
public int getEntity() {
return EntityHelper.MetaEntity;
}
}

View file

@ -0,0 +1,38 @@
/*
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.service.entitymanage;
import cn.devezhao.persist4j.PersistManagerFactory;
import cn.devezhao.rebuild.server.metadata.EntityHelper;
import cn.devezhao.rebuild.server.service.BaseService;
/**
*
* @author zhaofang123@gmail.com
* @since 08/03/2018
*/
public class MetaFieldService extends BaseService {
protected MetaFieldService(PersistManagerFactory persistManagerFactory) {
super(persistManagerFactory);
}
@Override
public int getEntity() {
return EntityHelper.MetaField;
}
}

View file

@ -0,0 +1,38 @@
/*
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.service.entitymanage;
import cn.devezhao.persist4j.Field;
import cn.devezhao.persist4j.metadata.impl.EntityImpl;
/**
*
* @author zhaofang123@gmail.com
* @since 08/04/2018
*/
public class UnsafeEntity extends EntityImpl {
private static final long serialVersionUID = 2107073554299141281L;
public UnsafeEntity(String name, String physicalName, String description, int typeCode, String nameField) {
super(name, physicalName, description, typeCode, nameField);
}
@Override
public void addField(Field field) {
super.addField(field);
}
}

View file

@ -0,0 +1,53 @@
/*
Copyright 2018 DEVEZHAO(zhaofang123@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.web.entitymanage;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.devezhao.persist4j.engine.ID;
import cn.devezhao.rebuild.server.service.entitymanage.Entity2Schema;
import cn.devezhao.rebuild.web.commons.BaseControll;
/**
*
* @author zhaofang123@gmail.com
* @since 08/03/2018
*/
@Controller
@RequestMapping("/admin/entity/")
public class MetaEntityControll extends BaseControll {
@RequestMapping("entity-new")
public void entityNew(HttpServletRequest request, HttpServletResponse response) throws IOException {
ID user = getRequestUser(request);
String label = getParameterNotNull(request, "label");
String desc = getParameter(request, "desc");
String entityName = new Entity2Schema(user).create(label, desc);
if (entityName != null) {
writeSuccess(response, entityName);
} else {
writeFailure(response);
}
}
}

View file

@ -49,7 +49,7 @@
<constructor-arg index="0" ref="dataSource" />
<constructor-arg index="1" ref="dialect" />
<constructor-arg index="2">
<bean class="cn.devezhao.persist4j.metadata.impl.ConfigurationMetadataFactory">
<bean class="cn.devezhao.rebuild.server.metadata.DynamicMetadataFactory">
<constructor-arg index="0" value="metadata-conf.xml" />
<constructor-arg index="1" ref="dialect" />
</bean>
@ -87,5 +87,15 @@
<bean class="cn.devezhao.rebuild.server.service.CommonService">
<constructor-arg index="0" ref="persistManagerFactory" />
</bean>
<bean class="cn.devezhao.rebuild.server.service.bizuser.UserService">
<constructor-arg index="0" ref="persistManagerFactory" />
</bean>
<bean class="cn.devezhao.rebuild.server.service.bizuser.DepartmentService">
<constructor-arg index="0" ref="persistManagerFactory" />
</bean>
<bean class="cn.devezhao.rebuild.server.service.bizuser.RoleService">
<constructor-arg index="0" ref="persistManagerFactory" />
</bean>
</beans>

View file

@ -0,0 +1,7 @@
# User
INSERT INTO `user` (`USER_ID`, `LOGIN_NAME`, `PASSWORD`, `FULL_NAME`, `DEPT_ID`, `IS_DISABLED`, `CREATED_ON`, `CREATED_BY`, `MODIFIED_ON`, `MODIFIED_BY`, `OWNING_USER`, `OWNING_DEPT`) VALUES ('001-0000000000000000', 'system', 'system', '系统用户', '002-0000000000000001', 'T', CURRENT_TIMESTAMP, '001-0000000000000000', CURRENT_TIMESTAMP, '001-0000000000000000', '001-0000000000000000', '002-0000000000000001');
INSERT INTO `user` (`USER_ID`, `LOGIN_NAME`, `PASSWORD`, `FULL_NAME`, `DEPT_ID`, `IS_DISABLED`, `CREATED_ON`, `CREATED_BY`, `MODIFIED_ON`, `MODIFIED_BY`, `OWNING_USER`, `OWNING_DEPT`) VALUES ('001-0000000000000001', 'admin', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', '管理员', '002-0000000000000001', 'F', CURRENT_TIMESTAMP, '001-0000000000000000', CURRENT_TIMESTAMP, '001-0000000000000000', '001-0000000000000000', '002-0000000000000001');
# Dept
INSERT INTO `department` (`DEPT_ID`, `NAME`, `CREATED_ON`, `CREATED_BY`, `MODIFIED_ON`, `MODIFIED_BY`, `OWNING_USER`, `OWNING_DEPT`) VALUES ('002-0000000000000001', '总部', CURRENT_TIMESTAMP, '001-0000000000000000', CURRENT_TIMESTAMP, '001-0000000000000000', '001-0000000000000000', '002-0000000000000001');
# Role
INSERT INTO `role` (`ROLE_ID`, `NAME`, `CREATED_ON`, `CREATED_BY`, `MODIFIED_ON`, `MODIFIED_BY`, `OWNING_USER`, `OWNING_DEPT`) VALUES ('003-0000000000000001', '管理员', CURRENT_TIMESTAMP, '001-0000000000000000', CURRENT_TIMESTAMP, '001-0000000000000000', '001-0000000000000000', '002-0000000000000001');

View file

@ -4,9 +4,8 @@
<metadata-config schema-name-optimize="true" default-parent="SystemCommon">
<entity name="SystemCommon" type-code="000">
<field name="autoId" type="long" auto-value="true" nullable="false" />
<field name="createdOn" type="timestamp" nullable="false" updatable="false" />
<field name="createdBy" type="reference" ref-entity="User" nullable="false" />
<field name="createdBy" type="reference" ref-entity="User" nullable="false" updatable="false" />
<field name="modifiedOn" type="timestamp" nullable="false" />
<field name="modifiedBy" type="reference" ref-entity="User" nullable="false" />
<field name="owningUser" type="reference" ref-entity="User" nullable="false" />
@ -17,11 +16,11 @@
<field name="userId" type="primary" />
<field name="loginName" type="string" max-length="100" nullable="false" />
<field name="email" type="string" max-length="100" />
<field name="password" type="string" max-length="100" />
<field name="password" type="string" max-length="100" nullable="false" />
<field name="fullName" type="string" max-length="100" />
<field name="avatarUrl" type="string" max-length="300" />
<field name="jobTitle" type="string" max-length="100" />
<field name="detpId" type="reference" ref-entity="Department" />
<field name="deptId" type="reference" ref-entity="Department" nullable="false" />
<field name="isDisabled" type="bool" default-value="T" />
<index type="unique" field-list="loginName"/>
<index type="unique" field-list="email"/>
@ -31,11 +30,13 @@
<field name="deptId" type="primary" />
<field name="name" type="string" max-length="100" nullable="false" />
<field name="parentDept" type="reference" ref-entity="Department" />
<field name="isDisabled" type="bool" default-value="F" />
</entity>
<entity name="Role" type-code="003">
<field name="roleId" type="primary" />
<field name="name" type="string" max-length="100" nullable="false" />
<field name="isDisabled" type="bool" default-value="F" />
</entity>
<entity name="RolePrivileges" type-code="004">
@ -55,10 +56,15 @@
<field name="entityName" type="string" max-length="100" nullable="false" />
<field name="physicalName" type="string" max-length="100" nullable="false" />
<field name="entityLabel" type="string" max-length="100" nullable="false"/>
<field name="description" type="string" max-length="100"/>
<index type="unique" field-list="typeCode"/>
<index type="unique" field-list="entityName"/>
<index type="unique" field-list="physicalName"/>
</entity>
<entity name="MetaField" type-code="011">
<field name="fieldId" type="primary" />
<field name="entityId" type="reference" ref-entity="MetaEntity" cascade="delete" nullable="false" />
<field name="fieldName" type="string" max-length="100" nullable="false" />
<field name="physicalName" type="string" max-length="100" nullable="false" />
<field name="fieldLabel" type="string" max-length="100" nullable="false"/>
@ -66,9 +72,12 @@
<field name="nullable" type="bool" default-value="T"/>
<field name="creatable" type="bool" default-value="T"/>
<field name="updatable" type="bool" default-value="T"/>
<field name="precision" type="small-int" default-value="4"/>
<field name="precision" type="small-int" default-value="2"/>
<field name="maxLength" type="small-int" default-value="200"/>
<field name="defaultValue" type="string"/>
<field name="defaultValue" type="string" max-length="200"/>
<field name="description" type="string" max-length="100"/>
<index type="unique" field-list="entityId,fieldName"/>
<index type="unique" field-list="entityId,physicalName"/>
</entity>
</metadata-config>

View file

@ -0,0 +1,53 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/_include/Head.jsp"%>
<title>用户管理</title>
<style type="text/css">
.footer{padding-bottom:0 !important;}
</style>
</head>
<body class="dialog">
<div class="main-content">
<form>
<div class="form-group row">
<label class="col-12 col-sm-3 col-form-label text-sm-right">实体名称</label>
<div class="col-12 col-sm-8 col-lg-4">
<input class="form-control form-control-sm" type="text" id="entityLabel" maxlength="20">
</div>
</div>
<div class="form-group row">
<label class="col-12 col-sm-3 col-form-label text-sm-right">描述</label>
<div class="col-12 col-sm-8 col-lg-4">
<textarea class="form-control form-control-sm row2" id="description" maxlength="100"></textarea>
</div>
</div>
<div class="form-group row footer">
<label class="col-12 col-sm-3"></label>
<div class="col-12 col-sm-8 col-lg-4">
<button class="btn btn-primary btn-space" type="button" data-loading-text="请稍后">确定</button>
</div>
</div>
</form>
</div>
<%@ include file="/_include/Foot.jsp"%>
<script type="text/javascript">
$(document).ready(function(){
let btn = $('.btn-primary').click(function(){
let entityLabel = $('#entityLabel').val(),
desc = $('#description').val();
btn.button('loading');
$.post('entity-new', { label:entityLabel, desc:desc }, function(res){
if (res.error_code == 0) parent.location.href = 'manage.htm?entity=' + res.data;
else{
alert(res);
btn.button('reset');
}
});
});
});
</script>
</body>
</html>

View file

@ -0,0 +1,44 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/_include/Head.jsp"%>
<title>用户管理</title>
<style type="text/css">
.footer{padding-bottom:0 !important;}
</style>
</head>
<body class="dialog">
<div class="main-content">
<form>
<div class="form-group row">
<label class="col-12 col-sm-3 col-form-label text-sm-right">字段名称</label>
<div class="col-12 col-sm-8 col-lg-6">
<input class="form-control form-control-sm" type="text">
</div>
</div>
<div class="form-group row">
<label class="col-12 col-sm-3 col-form-label text-sm-right">类型</label>
<div class="col-12 col-sm-8 col-lg-6">
<select class="form-control form-control-sm">
<option value="text">文本</option>
<option value="number">数字</option>
</select>
</div>
</div>
<div class="form-group row footer">
<label class="col-12 col-sm-3 col-form-label text-sm-right"></label>
<div class="col-12 col-sm-8 col-lg-6">
<button class="btn btn-primary btn-space" type="button">确定</button>
</div>
</div>
</form>
</div>
<%@ include file="/_include/Foot.jsp"%>
<script type="text/javascript">
//$(window).resize(function(){ setTimeoutDelay(function(){ parent.rbModal.loaded() }, 50, 'rbModal-resize') });
$(document).ready(function(){
});
</script>
</body>
</html>

View file

@ -47,7 +47,7 @@
</a>
</div>
<div class="col-sm-2">
<a class="card entity" href="creator.htm">
<a class="card entity J_entity-new">
<div class="card-body">
<div class="float-left"><i class="icon zmdi zmdi-plus"></i></div>
<div class="float-left">
@ -63,7 +63,15 @@
</div>
</div>
<%@ include file="/_include/Foot.jsp"%>
<script type="text/babel">
const rbModal = ReactDOM.render(<RbModal title="新建实体" />, $('<div id="react-comps"></div>').appendTo(document.body)[0]);
</script>
<script type="text/javascript">
$(document).ready(function(){
$('.J_entity-new').click(function(){
rbModal.show('entity-new.htm');
})
})
</script>
</body>
</html>

View file

@ -54,7 +54,7 @@
</div>
<div class="col-sm-6">
<div class="dataTables_oper">
<button class="btn btn-space btn-primary" data-toggle="modal" data-target="#form-bp"><i class="icon zmdi zmdi-plus"></i> 新建</button>
<button class="btn btn-space btn-primary" onclick="rbModal.show('field-edit.htm')"><i class="icon zmdi zmdi-plus"></i> 新建</button>
<button class="btn btn-space btn-secondary" disabled="disabled"><i class="icon zmdi zmdi-delete"></i> 删除</button>
</div>
</div>
@ -104,6 +104,10 @@
</div>
</div>
<%@ include file="/_include/Foot.jsp"%>
<script src="${baseUrl}/assets/js/rb-list.js" type="text/javascript"></script>
<script type="text/babel">
const rbModal = ReactDOM.render(<RbModal title="新建字段" />, $('<div id="react-comps"></div>').appendTo(document.body)[0]);
</script>
<script type="text/javascript">
</script>
</body>

View file

@ -42,7 +42,37 @@
<div class="page-head">
<div class="page-head-title">基本信息</div>
</div>
<div class="main-content container-fluid">
<div class="main-content container-fluid" style="padding-top:3px">
<div class="card">
<div class="card-body">
<form>
<div class="form-group row">
<label class="col-12 col-sm-2 col-form-label text-sm-right">实体名称</label>
<div class="col-12 col-sm-8 col-lg-4">
<input class="form-control form-control-sm" type="text">
</div>
</div>
<div class="form-group row">
<label class="col-12 col-sm-2 col-form-label text-sm-right">系统标识</label>
<div class="col-12 col-sm-8 col-lg-4">
<input class="form-control form-control-sm" type="text" readonly="readonly">
</div>
</div>
<div class="form-group row">
<label class="col-12 col-sm-2 col-form-label text-sm-right">描述</label>
<div class="col-12 col-sm-8 col-lg-4">
<textarea class="form-control form-control-sm row2"></textarea>
</div>
</div>
<div class="form-group row footer">
<label class="col-12 col-sm-2 col-form-label text-sm-right"></label>
<div class="col-12 col-sm-8 col-lg-4">
<button class="btn btn-primary btn-space" type="button">确定</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>

View file

@ -44,4 +44,17 @@
body.dialog {
background-color: #fff;
}
textarea.row2 {
height: 52px !important;
resize: none;
}
textarea.row3 {
height: 72px !important;
resize: none;
}
a {
cursor: pointer;
}

View file

@ -13525,7 +13525,8 @@ canvas {
.page-head {
padding: 20px 25px 10px;
position: relative
position: relative;
padding-top: 25px;
}
@media print {
@ -21565,7 +21566,7 @@ select.form-control-xs:not([size]):not([multiple]) {
}
.form-control-sm,.input-group-sm>.form-control,.input-group-sm>.input-group-append>.btn,.input-group-sm>.input-group-append>.input-group-text,.input-group-sm>.input-group-prepend>.btn,.input-group-sm>.input-group-prepend>.input-group-text {
height: 37px;
height: 37px !important;
font-size: 1rem;
padding: 4px 12px
}

View file

@ -1,5 +1,6 @@
package cn.devezhao.rebuild.server;
import org.dom4j.Element;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@ -38,10 +39,11 @@ public class SchemaGen {
static void gen(int e) {
Entity entity = PMF.getMetadataFactory().getEntity(e);
Element root = ((ConfigurationMetadataFactory) PMF.getMetadataFactory()).getConfigDocument().getRootElement();
Table table = new Table(
entity,
PMF.getDialect(),
((ConfigurationMetadataFactory) PMF.getMetadataFactory()).getConfigDocument().getRootElement());
root.selectNodes("index"));
String[] ddl = table.generateDDL(true, false);

View file

@ -18,6 +18,8 @@ package cn.devezhao.rebuild.server;
import org.junit.Test;
import cn.devezhao.rebuild.server.metadata.EntityHelper;
/**
*
* @author zhaofang123@gmail.com
@ -28,6 +30,7 @@ public class StartupTest {
@Test
public void startup() {
Application.context();
EntityHelper.getEntity(1);
}
}

View file

@ -14,13 +14,22 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package cn.devezhao.rebuild.server.metadata;
package cn.devezhao.rebuild.server.service.entitymanage;
import org.junit.Test;
import cn.devezhao.rebuild.server.service.bizuser.UserService;
import cn.devezhao.rebuild.server.service.entitymanage.Entity2Schema;
/**
*
* @author zhaofang123@gmail.com
* @since 05/18/2018
* @since 08/03/2018
*/
public class MetadataConfigurer {
public class Entity2SchemaTest {
@Test
public void testCreate() throws Exception {
new Entity2Schema(UserService.ADMIN_USER).create("测试一把", null);
}
}