mirror of
https://github.com/getrebuild/rebuild.git
synced 2024-09-21 07:55:56 +08:00
bizz entity QuickCode
This commit is contained in:
parent
57d1f1c4c4
commit
4261c79a6b
|
@ -27,10 +27,10 @@ import cn.devezhao.persist4j.dialect.Type;
|
||||||
*/
|
*/
|
||||||
public enum DisplayType {
|
public enum DisplayType {
|
||||||
|
|
||||||
NUMBER("数字", FieldType.LONG, 0, "##,###"),
|
NUMBER("数字", FieldType.LONG, -1, "##,###"),
|
||||||
DECIMAL("货币", FieldType.DECIMAL, 0, "##,##0.00"),
|
DECIMAL("货币", FieldType.DECIMAL, -1, "##,##0.00"),
|
||||||
DATE("日期", FieldType.DATE, 0, "yyyy-MM-dd"),
|
DATE("日期", FieldType.DATE, -1, "yyyy-MM-dd"),
|
||||||
DATETIME("日期时间", FieldType.TIMESTAMP, 0, "yyyy-MM-dd HH:mm:ss"),
|
DATETIME("日期时间", FieldType.TIMESTAMP, -1, "yyyy-MM-dd HH:mm:ss"),
|
||||||
TEXT("文本", FieldType.STRING, 300, null),
|
TEXT("文本", FieldType.STRING, 300, null),
|
||||||
NTEXT("大文本", FieldType.TEXT, 6000, null),
|
NTEXT("大文本", FieldType.TEXT, 6000, null),
|
||||||
EMAIL("邮箱", FieldType.STRING, 100, null),
|
EMAIL("邮箱", FieldType.STRING, 100, null),
|
||||||
|
@ -39,14 +39,14 @@ public enum DisplayType {
|
||||||
SERIES("自动编号", FieldType.STRING, 40, "{YYYYMMDD}-{0000}"),
|
SERIES("自动编号", FieldType.STRING, 40, "{YYYYMMDD}-{0000}"),
|
||||||
IMAGE("图片", FieldType.STRING, 700, null),
|
IMAGE("图片", FieldType.STRING, 700, null),
|
||||||
FILE("附件", FieldType.STRING, 700, null),
|
FILE("附件", FieldType.STRING, 700, null),
|
||||||
PICKLIST("列表", FieldType.REFERENCE),
|
PICKLIST("列表", FieldType.REFERENCE, -1, null),
|
||||||
REFERENCE("引用", FieldType.REFERENCE),
|
REFERENCE("引用", FieldType.REFERENCE, -1, null),
|
||||||
|
|
||||||
// 待启用/内部用
|
// 待启用/内部用
|
||||||
ID("主键", FieldType.PRIMARY),
|
ID("主键", FieldType.PRIMARY, -1, null),
|
||||||
ANYREFERENCE("任意引用", FieldType.ANY_REFERENCE),
|
ANYREFERENCE("任意引用", FieldType.ANY_REFERENCE, -1, null),
|
||||||
BOOL("布尔", FieldType.BOOL),
|
BOOL("布尔", FieldType.BOOL, -1, null),
|
||||||
LOCATION("位置", FieldType.STRING, 50, null),
|
LOCATION("位置", FieldType.STRING, 70, null),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -196,6 +196,7 @@ public class Field2Schema {
|
||||||
if (StringUtils.isNotBlank(comments)) {
|
if (StringUtils.isNotBlank(comments)) {
|
||||||
record.setString("comments", comments);
|
record.setString("comments", comments);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayType == DisplayType.PICKLIST) {
|
if (displayType == DisplayType.PICKLIST) {
|
||||||
refEntity = "PickList";
|
refEntity = "PickList";
|
||||||
}
|
}
|
||||||
|
@ -207,6 +208,12 @@ public class Field2Schema {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int maxLength = displayType.getMaxLength();
|
||||||
|
if (EntityHelper.QuickCode.equals(fieldName)) {
|
||||||
|
maxLength = 70;
|
||||||
|
}
|
||||||
|
record.setInt("maxLength", maxLength);
|
||||||
|
|
||||||
if (displayType == DisplayType.REFERENCE && StringUtils.isBlank(refEntity)) {
|
if (displayType == DisplayType.REFERENCE && StringUtils.isBlank(refEntity)) {
|
||||||
throw new ModificationMetadataException("引用字段必须指定引用实体");
|
throw new ModificationMetadataException("引用字段必须指定引用实体");
|
||||||
}
|
}
|
||||||
|
@ -218,7 +225,7 @@ public class Field2Schema {
|
||||||
String defaultValue = EntityHelper.IsDeleted.equals(fieldName) ? "F" : null;
|
String defaultValue = EntityHelper.IsDeleted.equals(fieldName) ? "F" : null;
|
||||||
|
|
||||||
Field unsafeField = new FieldImpl(
|
Field unsafeField = new FieldImpl(
|
||||||
fieldName, physicalName, fieldLabel, entity, displayType.getFieldType(), CascadeModel.Ignore, displayType.getMaxLength(),
|
fieldName, physicalName, fieldLabel, entity, displayType.getFieldType(), CascadeModel.Ignore, maxLength,
|
||||||
dbNullable, creatable, updatable, true, 6, defaultValue, autoValue);
|
dbNullable, creatable, updatable, true, 6, defaultValue, autoValue);
|
||||||
if (entity instanceof UnsafeEntity) {
|
if (entity instanceof UnsafeEntity) {
|
||||||
((UnsafeEntity) entity).addField(unsafeField);
|
((UnsafeEntity) entity).addField(unsafeField);
|
||||||
|
|
|
@ -21,6 +21,7 @@ package com.rebuild.server.service.base;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
|
|
||||||
import com.github.stuxuhai.jpinyin.PinyinHelper;
|
import com.github.stuxuhai.jpinyin.PinyinHelper;
|
||||||
import com.rebuild.server.Application;
|
import com.rebuild.server.Application;
|
||||||
|
@ -71,6 +72,9 @@ public class QuickCodeReindexTask extends BulkTask {
|
||||||
|
|
||||||
this.setTotal(records.size() + this.getTotal() + 1);
|
this.setTotal(records.size() + this.getTotal() + 1);
|
||||||
for (Record o : records) {
|
for (Record o : records) {
|
||||||
|
if (this.isInterrupted()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
this.setCompleteOne();
|
this.setCompleteOne();
|
||||||
|
|
||||||
String quickCodeNew = generateQuickCode(o);
|
String quickCodeNew = generateQuickCode(o);
|
||||||
|
@ -82,13 +86,17 @@ public class QuickCodeReindexTask extends BulkTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
Record record = EntityHelper.forUpdate(o.getPrimary(), UserService.SYSTEM_USER);
|
Record record = EntityHelper.forUpdate(o.getPrimary(), UserService.SYSTEM_USER);
|
||||||
record.setString("quickCode", quickCodeNew);
|
if (StringUtils.isBlank(quickCodeNew)) {
|
||||||
|
record.setNull(EntityHelper.QuickCode);
|
||||||
|
} else {
|
||||||
|
record.setString(EntityHelper.QuickCode, quickCodeNew);
|
||||||
|
}
|
||||||
record.removeValue(EntityHelper.ModifiedBy);
|
record.removeValue(EntityHelper.ModifiedBy);
|
||||||
record.removeValue(EntityHelper.ModifiedOn);
|
record.removeValue(EntityHelper.ModifiedOn);
|
||||||
Application.getCommonService().update(record);
|
Application.getCommonService().update(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (records.size() < 1000) {
|
if (records.size() < 1000 || this.isInterrupted()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,6 +139,11 @@ public class QuickCodeReindexTask extends BulkTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 你好世界 - NHSJ
|
||||||
|
* HelloWorld - HW
|
||||||
|
* hello world - HW
|
||||||
|
* 43284327432 - ""
|
||||||
|
*
|
||||||
* @param nameVal
|
* @param nameVal
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -139,12 +152,31 @@ public class QuickCodeReindexTask extends BulkTask {
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 提取 0-9+a-z+A-Z+中文+空格
|
||||||
|
nameVal = nameVal.replaceAll("[^a-zA-Z0-9\\s\u4e00-\u9fa5]", "");
|
||||||
|
|
||||||
String quickCode = StringUtils.EMPTY;
|
String quickCode = StringUtils.EMPTY;
|
||||||
try {
|
if (nameVal.matches("[a-zA-Z0-9\\s]+")) {
|
||||||
quickCode = PinyinHelper.getShortPinyin(nameVal).toUpperCase();
|
String aplit[] = nameVal.split("(?=[A-Z\\s])");
|
||||||
} catch (Exception e) {
|
StringBuffer sb = new StringBuffer();
|
||||||
LOG.error("QuickCode shorting error : " + nameVal, e);
|
for (String a : aplit) {
|
||||||
|
if (a.trim().length() > 0) {
|
||||||
|
sb.append(a.trim().substring(0, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
quickCode = sb.toString();
|
||||||
|
} else {
|
||||||
|
nameVal = nameVal.replaceAll(" ", "");
|
||||||
|
try {
|
||||||
|
quickCode = PinyinHelper.getShortPinyin(nameVal);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("QuickCode shorting error : " + nameVal, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return quickCode;
|
|
||||||
|
if (NumberUtils.isDigits(quickCode)) {
|
||||||
|
quickCode = StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
return quickCode.toUpperCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ public class ReferenceSearch extends BaseControll {
|
||||||
writeSuccess(response, ArrayUtils.EMPTY_STRING_ARRAY);
|
writeSuccess(response, ArrayUtils.EMPTY_STRING_ARRAY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
q = StringEscapeUtils.escapeSql(q);
|
||||||
|
|
||||||
Entity metaEntity = MetadataHelper.getEntity(entity);
|
Entity metaEntity = MetadataHelper.getEntity(entity);
|
||||||
Field nameField = MetadataHelper.getNameField(metaEntity);
|
Field nameField = MetadataHelper.getNameField(metaEntity);
|
||||||
|
@ -74,14 +75,16 @@ public class ReferenceSearch extends BaseControll {
|
||||||
}
|
}
|
||||||
if (StringUtils.isBlank(qFields)) {
|
if (StringUtils.isBlank(qFields)) {
|
||||||
qFields = nameField.getName();
|
qFields = nameField.getName();
|
||||||
|
if (metaEntity.containsField(EntityHelper.QuickCode)) {
|
||||||
|
qFields += "," + EntityHelper.QuickCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
q = StringEscapeUtils.escapeSql(q);
|
|
||||||
List<String> or = new ArrayList<>();
|
List<String> or = new ArrayList<>();
|
||||||
for (String field : qFields.split(",")) {
|
for (String field : qFields.split(",")) {
|
||||||
if (!metaEntity.containsField(field)) {
|
if (!metaEntity.containsField(field)) {
|
||||||
LOG.warn("No field for search : " + field);
|
LOG.warn("No field for search : " + field);
|
||||||
} else if (StringUtils.isNotBlank(q)) {
|
} else {
|
||||||
or.add(field + " like '%" + q + "%'");
|
or.add(field + " like '%" + q + "%'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<field name="deptId" type="reference" ref-entity="Department" cascade="remove-links" updatable="false" description="部门" />
|
<field name="deptId" type="reference" ref-entity="Department" cascade="remove-links" updatable="false" description="部门" />
|
||||||
<field name="roleId" type="reference" ref-entity="Role" cascade="remove-links" updatable="false" description="角色" />
|
<field name="roleId" type="reference" ref-entity="Role" cascade="remove-links" updatable="false" description="角色" />
|
||||||
<field name="isDisabled" type="bool" default-value="F" description="是否停用" />
|
<field name="isDisabled" type="bool" default-value="F" description="是否停用" />
|
||||||
<field name="quickCode" type="string" max-length="100"/>
|
<field name="quickCode" type="string" max-length="70"/>
|
||||||
<index type="unique" field-list="loginName" />
|
<index type="unique" field-list="loginName" />
|
||||||
<index type="unique" field-list="email" />
|
<index type="unique" field-list="email" />
|
||||||
</entity>
|
</entity>
|
||||||
|
@ -31,12 +31,14 @@
|
||||||
<field name="name" type="string" max-length="100" nullable="false" description="部门名称" />
|
<field name="name" type="string" max-length="100" nullable="false" description="部门名称" />
|
||||||
<field name="parentDept" type="reference" ref-entity="Department" cascade="remove-links" description="父级部门" />
|
<field name="parentDept" type="reference" ref-entity="Department" cascade="remove-links" description="父级部门" />
|
||||||
<field name="isDisabled" type="bool" default-value="F" description="是否停用" />
|
<field name="isDisabled" type="bool" default-value="F" description="是否停用" />
|
||||||
|
<field name="quickCode" type="string" max-length="70"/>
|
||||||
</entity>
|
</entity>
|
||||||
|
|
||||||
<entity name="Role" type-code="003" description="角色" name-field="name">
|
<entity name="Role" type-code="003" description="角色" name-field="name">
|
||||||
<field name="roleId" type="primary" />
|
<field name="roleId" type="primary" />
|
||||||
<field name="name" type="string" max-length="100" nullable="false" description="角色名称" />
|
<field name="name" type="string" max-length="100" nullable="false" description="角色名称" />
|
||||||
<field name="isDisabled" type="bool" default-value="F" description="是否停用" />
|
<field name="isDisabled" type="bool" default-value="F" description="是否停用" />
|
||||||
|
<field name="quickCode" type="string" max-length="70"/>
|
||||||
</entity>
|
</entity>
|
||||||
|
|
||||||
<entity name="RolePrivileges" type-code="004" parent="false">
|
<entity name="RolePrivileges" type-code="004" parent="false">
|
||||||
|
@ -80,12 +82,12 @@
|
||||||
<field name="creatable" type="bool" default-value="T" />
|
<field name="creatable" type="bool" default-value="T" />
|
||||||
<field name="updatable" type="bool" default-value="T" />
|
<field name="updatable" type="bool" default-value="T" />
|
||||||
<field name="precision" type="small-int" default-value="6" />
|
<field name="precision" type="small-int" default-value="6" />
|
||||||
<field name="defaultValue" type="string" max-length="200" />
|
<field name="defaultValue" type="string" max-length="300" />
|
||||||
<field name="maxLength" type="small-int" default-value="600" />
|
<field name="maxLength" type="small-int" default-value="300" />
|
||||||
<field name="refEntity" type="string" max-length="100" />
|
<field name="refEntity" type="string" max-length="100" />
|
||||||
<field name="cascade" type="string" max-length="20" default-value="ignore" />
|
<field name="cascade" type="string" max-length="20" default-value="ignore" />
|
||||||
<field name="comments" type="string" max-length="200" />
|
<field name="comments" type="string" max-length="300" />
|
||||||
<field name="extConfig" type="string" max-length="600" description="更多扩展配置,JSON格式KV" />
|
<field name="extConfig" type="string" max-length="700" description="更多扩展配置,JSON格式KV" />
|
||||||
<index type="unique" field-list="belongEntity,fieldName" />
|
<index type="unique" field-list="belongEntity,fieldName" />
|
||||||
<index type="unique" field-list="belongEntity,physicalName" />
|
<index type="unique" field-list="belongEntity,physicalName" />
|
||||||
</entity>
|
</entity>
|
||||||
|
|
|
@ -60,7 +60,7 @@ class DlgAssign extends RbModalHandler {
|
||||||
data: function(params) {
|
data: function(params) {
|
||||||
let query = {
|
let query = {
|
||||||
entity: 'User',
|
entity: 'User',
|
||||||
qfields: 'loginName,fullName,email',
|
qfields: 'loginName,fullName,email,quickCode',
|
||||||
q: params.term
|
q: params.term
|
||||||
}
|
}
|
||||||
return query
|
return query
|
||||||
|
|
|
@ -18,9 +18,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package com.rebuild.server.helper.task;
|
package com.rebuild.server.helper.task;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.rebuild.server.TestSupport;
|
import com.rebuild.server.TestSupport;
|
||||||
|
import com.rebuild.server.metadata.MetadataHelper;
|
||||||
|
import com.rebuild.server.service.base.QuickCodeReindexTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -29,8 +32,25 @@ import com.rebuild.server.TestSupport;
|
||||||
*/
|
*/
|
||||||
public class QuickCodeReindexTaskTest extends TestSupport {
|
public class QuickCodeReindexTaskTest extends TestSupport {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateQuickCode() throws Exception {
|
||||||
|
Assert.assertFalse("NHHSJ".equalsIgnoreCase(QuickCodeReindexTask.generateQuickCode("你 好 hello 世 界")));
|
||||||
|
Assert.assertTrue("HW".equalsIgnoreCase(QuickCodeReindexTask.generateQuickCode("hello world ........")));
|
||||||
|
Assert.assertTrue("HW".equalsIgnoreCase(QuickCodeReindexTask.generateQuickCode("HelloWorld!")));
|
||||||
|
Assert.assertTrue("NHSJ".equalsIgnoreCase(QuickCodeReindexTask.generateQuickCode("你好世界")));
|
||||||
|
Assert.assertTrue("NHSJ".equalsIgnoreCase(QuickCodeReindexTask.generateQuickCode("你 好 世 界")));
|
||||||
|
Assert.assertTrue("".equalsIgnoreCase(QuickCodeReindexTask.generateQuickCode("54325432543")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReindex() throws Exception {
|
public void testReindex() throws Exception {
|
||||||
|
new QuickCodeReindexTask(MetadataHelper.getEntity("User")).run();
|
||||||
|
new QuickCodeReindexTask(MetadataHelper.getEntity("Role")).run();
|
||||||
|
new QuickCodeReindexTask(MetadataHelper.getEntity("Department")).run();
|
||||||
|
|
||||||
|
String entity = "h45hy54hy";
|
||||||
|
if (MetadataHelper.containsEntity(entity)) {
|
||||||
|
new QuickCodeReindexTask(MetadataHelper.getEntity(entity)).run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue