Skip to content

Commit da61f82

Browse files
authored
Be 4.0 4 (#875)
* CHINESEDATE * name tagged * feat: 表单回填公式 * Update trigger-design.js * fix * fix: EasyFilterEval * fix:字段权限
1 parent 9821064 commit da61f82

28 files changed

+324
-108
lines changed

@rbv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit b8035a2ae730f694837babfd0a33702da29f4b0b
1+
Subproject commit cb2cdcc0405f4dbbb4a21548707921769c27d23c

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ REBUILD 对于开发环境的要求非常简单,由于使用 Java 开发,因
8080

8181
- JDK 1.8+(兼容 OpenJDK)
8282
- MySQL 5.6+
83-
- Redis 3.2+(非必须,默认使用内置的 Ehcache 缓存
84-
- Tomcat 8.0+(非必须,默认使用 SpringBooot 内置 Tomcat
85-
- Apache Maven 3.6+
83+
- Apache Maven 3.6+(非必须,IDE 自带
84+
- Redis 3.2+(非必须,默认使用内置 Ehcache 缓存
85+
- Tomcat 8.0+(非必须,默认使用内置 Tomcat)
8686
- IDEA 或 Eclipse (for JEE)
8787

8888
更多详情请参见 [开发人员文档](https://getrebuild.com/docs/dev/)

src/main/java/com/rebuild/core/configuration/general/AutoFillinManager.java

+37-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.rebuild.core.Application;
2222
import com.rebuild.core.configuration.ConfigBean;
2323
import com.rebuild.core.configuration.ConfigManager;
24+
import com.rebuild.core.metadata.EntityRecordCreator;
2425
import com.rebuild.core.metadata.MetadataHelper;
2526
import com.rebuild.core.metadata.easymeta.DisplayType;
2627
import com.rebuild.core.metadata.easymeta.EasyField;
@@ -38,6 +39,7 @@
3839
import java.util.ArrayList;
3940
import java.util.Collections;
4041
import java.util.Date;
42+
import java.util.HashMap;
4143
import java.util.HashSet;
4244
import java.util.Iterator;
4345
import java.util.List;
@@ -58,14 +60,24 @@ public class AutoFillinManager implements ConfigManager {
5860

5961
private AutoFillinManager() {}
6062

63+
/**
64+
* @param field
65+
* @param sourceId
66+
* @return
67+
*/
68+
public JSONArray getFillinValue(Field field, ID sourceId) {
69+
return getFillinValue(field, sourceId, null);
70+
}
71+
6172
/**
6273
* 获取回填值
6374
*
6475
* @param field
6576
* @param sourceId
77+
* @param formData
6678
* @return
6779
*/
68-
public JSONArray getFillinValue(Field field, ID sourceId) {
80+
public JSONArray getFillinValue(Field field, ID sourceId, JSONObject formData) {
6981
final EasyField easyField = EasyMetaFactory.valueOf(field);
7082

7183
// 内置字段无配置
@@ -154,7 +166,27 @@ public JSONArray getFillinValue(Field field, ID sourceId) {
154166
} else {
155167
targetFieldMeta = targetEntity.getField(targetField);
156168
}
157-
169+
170+
// v40 使用公式回填
171+
String sourceFieldFormula40 = e.getString("sourceFieldFormula");
172+
if (StringUtils.isNotBlank(sourceFieldFormula40)) {
173+
Map<String, Object> varsInFormula = new HashMap<>();
174+
if (formData != null) {
175+
formData.remove(EntityRecordCreator.META_FIELD);
176+
JSONObject formDataMain = (JSONObject) formData.remove("$$$main");
177+
if (formDataMain != null) {
178+
formDataMain.remove(EntityRecordCreator.META_FIELD);
179+
String dtfName = MetadataHelper.getDetailToMainField(field.getOwnEntity()).getName() + ".";
180+
formDataMain.forEach((k, v) -> varsInFormula.put(dtfName + k, v));
181+
}
182+
varsInFormula.putAll(formData);
183+
}
184+
185+
Object value = CalcFormulaSupport.evalCalcFormula(targetFieldMeta, varsInFormula, sourceFieldFormula40);
186+
if (value == null) sourceRecord.setNull(sourceField);
187+
else sourceRecord.setObjectValue(sourceField, value);
188+
}
189+
158190
Object value = null;
159191
if (sourceRecord.hasValue(sourceField, false)) {
160192
value = sourceRecord.getObjectValue(sourceField);
@@ -404,6 +436,9 @@ private List<ConfigBean> getConfig(Field field) {
404436
.set("whenUpdate", extra.getBooleanValue("whenUpdate"))
405437
.set("fillinForce", extra.getBooleanValue("fillinForce"))
406438
.set("fillinBackend", extra.getBooleanValue("fillinBackend"));
439+
if (extra.getString("sourceFieldFormula") != null) {
440+
entry.set("sourceFieldFormula", extra.getString("sourceFieldFormula"));
441+
}
407442
entries.add(entry);
408443
}
409444

src/main/java/com/rebuild/core/configuration/general/FormsBuilder.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.rebuild.core.service.approval.RobotApprovalManager;
3939
import com.rebuild.core.service.general.GeneralEntityService;
4040
import com.rebuild.core.service.query.QueryHelper;
41+
import com.rebuild.core.support.License;
4142
import com.rebuild.core.support.general.DataListWrapper;
4243
import com.rebuild.core.support.general.FieldValueHelper;
4344
import com.rebuild.core.support.i18n.Language;
@@ -361,8 +362,6 @@ protected void buildModelElements(JSONArray elements, Entity entity, Record reco
361362
|| EntityHelper.isUnsavedId(recordData.getPrimary());
362363

363364
final FieldPrivileges fp = Application.getPrivilegesManager().getFieldPrivileges();
364-
// 是否来自明细共同编辑
365-
final boolean isProTableLayout = FormsBuilderContextHolder.getMainIdOfDetail(false) != null;
366365

367366
// Check and clean
368367
for (Iterator<Object> iter = elements.iterator(); iter.hasNext(); ) {
@@ -500,6 +499,10 @@ protected void buildModelElements(JSONArray elements, Entity entity, Record reco
500499
Application.getPrivilegesManager().allowCreate(user, refEntity.getEntityCode()));
501500
el.put("referenceEntity", EasyMetaFactory.toJSON(refEntity));
502501
}
502+
503+
if (dt == DisplayType.REFERENCE && License.isRbvAttached()) {
504+
el.put("fillinWithFormData", true);
505+
}
503506
}
504507

505508
// 新建记录
@@ -615,7 +618,12 @@ protected void buildModelElements(JSONArray elements, Entity entity, Record reco
615618
if (isNew) {
616619
if (!fp.isCreatable(fieldMeta, user)) el.put("readonly", true);
617620
} else {
618-
if (!fp.isReadble(fieldMeta, user)) iter.remove();
621+
// v40 保留占位
622+
if (!fp.isReadable(fieldMeta, user)) {
623+
el.put("unreadable", true);
624+
el.put("readonly", true);
625+
el.remove("value");
626+
}
619627
else if (!fp.isUpdatable(fieldMeta, user)) el.put("readonly", true);
620628
}
621629
}

src/main/java/com/rebuild/core/privileges/FieldPrivileges.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public boolean isCreatable(Field field, ID user) {
3636
* @param user
3737
* @return
3838
*/
39-
public boolean isReadble(Field field, ID user) {
39+
public boolean isReadable(Field field, ID user) {
4040
return true;
4141
}
4242

src/main/java/com/rebuild/core/service/trigger/aviator/AviatorUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class AviatorUtils {
7474
addCustomFunction(new ChineseYuanFunction());
7575
addCustomFunction(new TextFunction());
7676
addCustomFunction(new IsNullFunction());
77+
addCustomFunction(new ChineseDateFunction());
7778
}
7879

7980
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*!
2+
Copyright (c) REBUILD <https://getrebuild.com/> and/or its owners. All rights reserved.
3+
4+
rebuild is dual-licensed under commercial and open source licenses (GPLv3).
5+
See LICENSE and COMMERCIAL in the project root for license information.
6+
*/
7+
8+
package com.rebuild.core.service.trigger.aviator;
9+
10+
import cn.devezhao.commons.CalendarUtils;
11+
import cn.devezhao.commons.ObjectUtils;
12+
import cn.hutool.core.date.ChineseDate;
13+
import com.googlecode.aviator.runtime.function.AbstractFunction;
14+
import com.googlecode.aviator.runtime.type.AviatorBoolean;
15+
import com.googlecode.aviator.runtime.type.AviatorNil;
16+
import com.googlecode.aviator.runtime.type.AviatorObject;
17+
import com.googlecode.aviator.runtime.type.AviatorString;
18+
19+
import java.util.Date;
20+
import java.util.Map;
21+
22+
/**
23+
* Usage: CHINESEDATE($date, [$traditional])
24+
* Return: Date
25+
*
26+
* @author devezhao
27+
* @since 2025/3/10
28+
*/
29+
public class ChineseDateFunction extends AbstractFunction {
30+
private static final long serialVersionUID = 8286269123896553078L;
31+
32+
public AviatorObject call(Map<String, Object> env, AviatorObject arg1) {
33+
return call(env, arg1, AviatorBoolean.FALSE);
34+
}
35+
36+
@Override
37+
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
38+
Object o = arg1.getValue(env);
39+
final Date $date = o instanceof Date ? (Date) o : CalendarUtils.parse(o.toString());
40+
if ($date == null) return AviatorNil.NIL;
41+
42+
// 是否农历
43+
boolean $traditional = ObjectUtils.toBool(arg2.getValue(env));
44+
45+
String dstr;
46+
if ($traditional) {
47+
ChineseDate cd = new ChineseDate($date);
48+
dstr = String.format("%s%s %s年(%d)",
49+
cd.getChineseMonth(true), cd.getChineseDay(), cd.getCyclical(), cd.getChineseYear());
50+
} else {
51+
dstr = CalendarUtils.getCNDateFormat().format($date);
52+
}
53+
return new AviatorString(dstr);
54+
}
55+
56+
@Override
57+
public String getName() {
58+
return "CHINESEDATE";
59+
}
60+
}

src/main/java/com/rebuild/core/support/general/CalcFormulaSupport.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import cn.devezhao.persist4j.Record;
1515
import com.rebuild.core.Application;
1616
import com.rebuild.core.configuration.general.AutoFillinManager;
17+
import com.rebuild.core.metadata.MetadataHelper;
1718
import com.rebuild.core.metadata.MetadataSorter;
1819
import com.rebuild.core.metadata.easymeta.DisplayType;
1920
import com.rebuild.core.metadata.easymeta.EasyDateTime;
@@ -97,17 +98,28 @@ public static int calcFormulaBackend(Record record) {
9798
return calc;
9899
}
99100

101+
/**
102+
* @param targetField
103+
* @param varsInFormula
104+
* @return
105+
*/
106+
public static Object evalCalcFormula(Field targetField, Map<String, Object> varsInFormula) {
107+
return evalCalcFormula(targetField, varsInFormula, null);
108+
}
109+
100110
/**
101111
* 计算
102112
*
103113
* @param targetField
104114
* @param varsInFormula
115+
* @param specFormula
105116
* @return
106117
*/
107-
public static Object evalCalcFormula(Field targetField, Map<String, Object> varsInFormula) {
118+
public static Object evalCalcFormula(Field targetField, Map<String, Object> varsInFormula, String specFormula) {
108119
final Entity entity = targetField.getOwnEntity();
109120
final EasyField easyField = EasyMetaFactory.valueOf(targetField);
110-
String formula = easyField.getExtraAttr(EasyFieldConfigProps.NUMBER_CALCFORMULA);
121+
String formula = specFormula;
122+
if (formula == null) formula = easyField.getExtraAttr(EasyFieldConfigProps.NUMBER_CALCFORMULA);
111123
formula = formula.replace("{{NOW}}", EasyDateTime.VAR_NOW);
112124

113125
boolean calcReady = true;
@@ -118,7 +130,9 @@ public static Object evalCalcFormula(Field targetField, Map<String, Object> vars
118130
continue;
119131
}
120132

121-
if (!entity.containsField(fieldName)) {
133+
// v40 支持点连接字段
134+
Field field = MetadataHelper.getLastJoinField(entity, fieldName);
135+
if (field == null) {
122136
calcReady = false;
123137
break;
124138
}
@@ -130,7 +144,7 @@ public static Object evalCalcFormula(Field targetField, Map<String, Object> vars
130144
}
131145

132146
String val2str = fieldValue.toString();
133-
DisplayType dt = EasyMetaFactory.valueOf(entity.getField(fieldName)).getDisplayType();
147+
DisplayType dt = EasyMetaFactory.getDisplayType(field);
134148
if (dt == DisplayType.DATE || dt == DisplayType.DATETIME) {
135149
fieldValue = CalendarUtils.parse(val2str, CalendarUtils.UTC_DATETIME_FORMAT.substring(0, val2str.length()));
136150
} else if (dt == DisplayType.NUMBER || dt == DisplayType.DECIMAL) {

src/main/java/com/rebuild/core/support/general/DataListWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ protected boolean checkHasJoinFieldPrivileges(SelectItem field, Object[] origina
296296
*/
297297
protected boolean checkHasFieldPrivileges(SelectItem field) {
298298
ID u = user == null ? UserContextHolder.getUser() : user;
299-
return Application.getPrivilegesManager().getFieldPrivileges().isReadble(field.getField(), u);
299+
return Application.getPrivilegesManager().getFieldPrivileges().isReadable(field.getField(), u);
300300
}
301301

302302
/**

src/main/java/com/rebuild/web/admin/ProtectedAdmin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public enum PaEntry {
9797
PRO("/project", "项目"),
9898
FJS("/frontjs-code", "FrontJS"),
9999
USR("/bizuser/users;bizuser/departments", "部门用户"),
100-
ROL("/bizuser/role-privileges", "角色权限"),
100+
ROL("/bizuser/role-privileges;/bizuser/role", "角色权限"),
101101
TEM("/bizuser/teams", "团队"),
102102
LLG("/audit/login-logs", "登录日志"),
103103
REV("/audit/revision-history", "变更历史"),

src/main/java/com/rebuild/web/general/ModelExtrasController.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@
6060
public class ModelExtrasController extends BaseController {
6161

6262
// 获取表单回填数据
63-
@GetMapping("fillin-value")
63+
@RequestMapping("fillin-value")
6464
public JSON getFillinValue(@EntityParam Entity entity, @IdParam(name = "source") ID sourceRecord,
6565
HttpServletRequest request) {
6666
String field = getParameterNotNull(request, "field");
6767
Field useField = entity.getField(field);
68+
JSONObject formData40 = (JSONObject) ServletUtils.getRequestJson(request);
6869

69-
return AutoFillinManager.instance.getFillinValue(useField, sourceRecord);
70+
return AutoFillinManager.instance.getFillinValue(useField, sourceRecord, formData40);
7071
}
7172

7273
// 记录转换

src/main/java/com/rebuild/web/general/RelatedListController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public JSON relatedList(@IdParam(name = "mainid") ID mainid, HttpServletRequest
8282
List<Object> res = new ArrayList<>();
8383
for (Object[] o : array) {
8484
Object nameValue = o[1];
85-
if (!fp.isReadble(relatedEntity.getNameField(), user)) {
85+
if (!fp.isReadable(relatedEntity.getNameField(), user)) {
8686
nameValue = FieldValueHelper.NO_READ_PRIVILEGES;
8787
nameValue = Language.L("[无权限]");
8888
} else {

src/main/resources/web/admin/metadata/auto-fillin.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
.dataTables_wrapper .rb-datatable-header {
1010
position: static;
1111
}
12-
span.badge {
12+
.rb-datatable-header span.badge {
1313
font-size: 1rem;
1414
padding: 4px 10px;
1515
font-weight: normal;

src/main/resources/web/assets/css/config-comps.css

+13
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,16 @@ See LICENSE and COMMERCIAL in the project root for license information.
3030
background-color: transparent;
3131
line-height: 15px;
3232
}
33+
34+
.data-list td.name span.badge {
35+
margin: 0;
36+
}
37+
38+
.data-list td.name span.badge:first-child {
39+
margin-left: 5px;
40+
}
41+
42+
.data-list td.name span.badge:hover {
43+
opacity: 0.8;
44+
cursor: pointer;
45+
}

src/main/resources/web/assets/css/rb-page.css

+6-1
Original file line numberDiff line numberDiff line change
@@ -4949,7 +4949,8 @@ pre.unstyle {
49494949
}
49504950

49514951
.protable .table th,
4952-
.protable .table thead td {
4952+
.protable .table thead td,
4953+
.protable .table tfoot td {
49534954
background-color: #eceff1;
49544955
font-weight: normal;
49554956
border-bottom-width: 1px;
@@ -5946,6 +5947,10 @@ div.formula-code {
59465947
line-height: 1;
59475948
}
59485949

5950+
.badge.badge-dark {
5951+
border: 0 none;
5952+
}
5953+
59495954
.modal-dialog-centered-unset .modal-dialog-centered {
59505955
display: block;
59515956
}

src/main/resources/web/assets/css/view-page.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ body {
449449
width: 28px;
450450
height: 28px;
451451
overflow: hidden;
452-
line-height: 1.1;
452+
line-height: 1.2;
453453
padding: 0;
454454
min-width: 0;
455455
min-height: 0;

0 commit comments

Comments
 (0)