bizz entity QuickCode

This commit is contained in:
FangfangZhao 2019-01-04 23:12:59 +08:00
parent 57d1f1c4c4
commit 4261c79a6b
7 changed files with 90 additions and 26 deletions

View file

@ -27,10 +27,10 @@ import cn.devezhao.persist4j.dialect.Type;
*/
public enum DisplayType {
NUMBER("数字", FieldType.LONG, 0, "##,###"),
DECIMAL("货币", FieldType.DECIMAL, 0, "##,##0.00"),
DATE("日期", FieldType.DATE, 0, "yyyy-MM-dd"),
DATETIME("日期时间", FieldType.TIMESTAMP, 0, "yyyy-MM-dd HH:mm:ss"),
NUMBER("数字", FieldType.LONG, -1, "##,###"),
DECIMAL("货币", FieldType.DECIMAL, -1, "##,##0.00"),
DATE("日期", FieldType.DATE, -1, "yyyy-MM-dd"),
DATETIME("日期时间", FieldType.TIMESTAMP, -1, "yyyy-MM-dd HH:mm:ss"),
TEXT("文本", FieldType.STRING, 300, null),
NTEXT("大文本", FieldType.TEXT, 6000, null),
EMAIL("邮箱", FieldType.STRING, 100, null),
@ -39,14 +39,14 @@ public enum DisplayType {
SERIES("自动编号", FieldType.STRING, 40, "{YYYYMMDD}-{0000}"),
IMAGE("图片", FieldType.STRING, 700, null),
FILE("附件", FieldType.STRING, 700, null),
PICKLIST("列表", FieldType.REFERENCE),
REFERENCE("引用", FieldType.REFERENCE),
PICKLIST("列表", FieldType.REFERENCE, -1, null),
REFERENCE("引用", FieldType.REFERENCE, -1, null),
// 待启用/内部用
ID("主键", FieldType.PRIMARY),
ANYREFERENCE("任意引用", FieldType.ANY_REFERENCE),
BOOL("布尔", FieldType.BOOL),
LOCATION("位置", FieldType.STRING, 50, null),
ID("主键", FieldType.PRIMARY, -1, null),
ANYREFERENCE("任意引用", FieldType.ANY_REFERENCE, -1, null),
BOOL("布尔", FieldType.BOOL, -1, null),
LOCATION("位置", FieldType.STRING, 70, null),
;

View file

@ -196,6 +196,7 @@ public class Field2Schema {
if (StringUtils.isNotBlank(comments)) {
record.setString("comments", comments);
}
if (displayType == DisplayType.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)) {
throw new ModificationMetadataException("引用字段必须指定引用实体");
}
@ -218,7 +225,7 @@ public class Field2Schema {
String defaultValue = EntityHelper.IsDeleted.equals(fieldName) ? "F" : null;
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);
if (entity instanceof UnsafeEntity) {
((UnsafeEntity) entity).addField(unsafeField);

View file

@ -21,6 +21,7 @@ package com.rebuild.server.service.base;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import com.rebuild.server.Application;
@ -71,6 +72,9 @@ public class QuickCodeReindexTask extends BulkTask {
this.setTotal(records.size() + this.getTotal() + 1);
for (Record o : records) {
if (this.isInterrupted()) {
break;
}
this.setCompleteOne();
String quickCodeNew = generateQuickCode(o);
@ -82,13 +86,17 @@ public class QuickCodeReindexTask extends BulkTask {
}
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.ModifiedOn);
Application.getCommonService().update(record);
}
if (records.size() < 1000) {
if (records.size() < 1000 || this.isInterrupted()) {
break;
}
}
@ -131,6 +139,11 @@ public class QuickCodeReindexTask extends BulkTask {
}
/**
* 你好世界 - NHSJ
* HelloWorld - HW
* hello world - HW
* 43284327432 - ""
*
* @param nameVal
* @return
*/
@ -139,12 +152,31 @@ public class QuickCodeReindexTask extends BulkTask {
return StringUtils.EMPTY;
}
// 提取 0-9+a-z+A-Z+中文+空格
nameVal = nameVal.replaceAll("[^a-zA-Z0-9\\s\u4e00-\u9fa5]", "");
String quickCode = StringUtils.EMPTY;
try {
quickCode = PinyinHelper.getShortPinyin(nameVal).toUpperCase();
} catch (Exception e) {
LOG.error("QuickCode shorting error : " + nameVal, e);
if (nameVal.matches("[a-zA-Z0-9\\s]+")) {
String aplit[] = nameVal.split("(?=[A-Z\\s])");
StringBuffer sb = new StringBuffer();
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();
}
}

View file

@ -65,6 +65,7 @@ public class ReferenceSearch extends BaseControll {
writeSuccess(response, ArrayUtils.EMPTY_STRING_ARRAY);
return;
}
q = StringEscapeUtils.escapeSql(q);
Entity metaEntity = MetadataHelper.getEntity(entity);
Field nameField = MetadataHelper.getNameField(metaEntity);
@ -74,14 +75,16 @@ public class ReferenceSearch extends BaseControll {
}
if (StringUtils.isBlank(qFields)) {
qFields = nameField.getName();
if (metaEntity.containsField(EntityHelper.QuickCode)) {
qFields += "," + EntityHelper.QuickCode;
}
}
q = StringEscapeUtils.escapeSql(q);
List<String> or = new ArrayList<>();
for (String field : qFields.split(",")) {
if (!metaEntity.containsField(field)) {
LOG.warn("No field for search : " + field);
} else if (StringUtils.isNotBlank(q)) {
} else {
or.add(field + " like '%" + q + "%'");
}
}

View file

@ -21,7 +21,7 @@
<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="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="email" />
</entity>
@ -31,12 +31,14 @@
<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="isDisabled" type="bool" default-value="F" description="是否停用" />
<field name="quickCode" type="string" max-length="70"/>
</entity>
<entity name="Role" type-code="003" description="角色" name-field="name">
<field name="roleId" type="primary" />
<field name="name" type="string" max-length="100" nullable="false" description="角色名称" />
<field name="isDisabled" type="bool" default-value="F" description="是否停用" />
<field name="quickCode" type="string" max-length="70"/>
</entity>
<entity name="RolePrivileges" type-code="004" parent="false">
@ -80,12 +82,12 @@
<field name="creatable" type="bool" default-value="T" />
<field name="updatable" type="bool" default-value="T" />
<field name="precision" type="small-int" default-value="6" />
<field name="defaultValue" type="string" max-length="200" />
<field name="maxLength" type="small-int" default-value="600" />
<field name="defaultValue" type="string" max-length="300" />
<field name="maxLength" type="small-int" default-value="300" />
<field name="refEntity" type="string" max-length="100" />
<field name="cascade" type="string" max-length="20" default-value="ignore" />
<field name="comments" type="string" max-length="200" />
<field name="extConfig" type="string" max-length="600" description="更多扩展配置JSON格式KV" />
<field name="comments" type="string" max-length="300" />
<field name="extConfig" type="string" max-length="700" description="更多扩展配置JSON格式KV" />
<index type="unique" field-list="belongEntity,fieldName" />
<index type="unique" field-list="belongEntity,physicalName" />
</entity>

View file

@ -60,7 +60,7 @@ class DlgAssign extends RbModalHandler {
data: function(params) {
let query = {
entity: 'User',
qfields: 'loginName,fullName,email',
qfields: 'loginName,fullName,email,quickCode',
q: params.term
}
return query

View file

@ -18,9 +18,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
package com.rebuild.server.helper.task;
import org.junit.Assert;
import org.junit.Test;
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 {
@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
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();
}
}
}