Skip to content

Commit

Permalink
Fix v3.4.2 (#659)
Browse files Browse the repository at this point in the history
* fix: Gitee#I7ZYWV

* be: getNetworkDate

* fix: disabled DateNotSync

* 3.4.2

* feat: DDD/EVW/WVM
  • Loading branch information
getrebuild authored Sep 14, 2023
1 parent 5ef90d9 commit 37c01fe
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 31 deletions.
2 changes: 1 addition & 1 deletion @rbv
Submodule @rbv updated from 180069 to e83ed9
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ REBUILD 对于开发环境的要求非常简单,由于使用 Java 开发,因
- MySQL 5.6+
- Redis 3.2+(非必须,默认使用内置的 Ehcache 缓存)
- Tomcat 8.0+(非必须,默认使用 SpringBooot 内置 Tomcat)
- Apache Maven 3.3+
- Apache Maven 3.6+
- IDEA 或 Eclipse (for JEE)

更多详情请参见 [开发人员文档](https://getrebuild.com/docs/dev/)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.rebuild</groupId>
<artifactId>rebuild</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
<name>rebuild</name>
<description>Building your business-systems freely!</description>
<!-- UNCOMMENT USE TOMCAT -->
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/rebuild/core/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public class Application implements ApplicationListener<ApplicationStartedEvent>
/**
* Rebuild Version
*/
public static final String VER = "3.4.1";
public static final String VER = "3.4.2";
/**
* Rebuild Build [MAJOR]{1}[MINOR]{2}[PATCH]{2}[BUILD]{2}
*/
public static final int BUILD = 3040106;
public static final int BUILD = 3040207;

static {
// Driver for DB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.rebuild.core.metadata.MetadataHelper;
import com.rebuild.core.metadata.MetadataSorter;
import com.rebuild.core.metadata.easymeta.DisplayType;
import com.rebuild.core.metadata.easymeta.EasyDecimal;
import com.rebuild.core.metadata.easymeta.EasyField;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.metadata.impl.EasyEntityConfigProps;
Expand Down Expand Up @@ -219,7 +220,7 @@ else if (viewMode) {
}
}

buildModelElements(elements, entityMeta, recordData, user, !viewMode);
buildModelElements(elements, entityMeta, recordData, user, viewMode, !viewMode);

if (elements.isEmpty()) {
return formatModelError(Language.L("此表单布局尚未配置,请配置后使用"));
Expand Down Expand Up @@ -318,9 +319,10 @@ private ApprovalState getHadApproval(Entity entity, ID recordId) {
* @param entity
* @param recordData
* @param user
* @param viewModel
* @param useAdvControl
*/
protected void buildModelElements(JSONArray elements, Entity entity, Record recordData, ID user, boolean useAdvControl) {
protected void buildModelElements(JSONArray elements, Entity entity, Record recordData, ID user, boolean viewModel, boolean useAdvControl) {
final User formUser = Application.getUserStore().getUser(user);
final Date now = CalendarUtils.now();

Expand All @@ -345,6 +347,7 @@ protected void buildModelElements(JSONArray elements, Entity entity, Record reco
Object displayOnUpdate = el.remove("displayOnUpdate");
Object requiredOnCreate = el.remove("requiredOnCreate");
Object requiredOnUpdate = el.remove("requiredOnUpdate");
if (viewModel) useAdvControl = false;
if (useAdvControl) {
// fix v3.3.4 跟随主记录新建/更新
boolean isNew2 = isNew;
Expand Down Expand Up @@ -474,12 +477,12 @@ protected void buildModelElements(JSONArray elements, Entity entity, Record reco
} else {
Object defaultValue = easyField.exprDefaultValue();
if (defaultValue != null) {
defaultValue = easyField.wrapValue(defaultValue);
// `wrapValue` 会添加格式符号
if (easyField.getDisplayType() == DisplayType.DECIMAL) {
el.put("value", defaultValue.toString());
} else {
el.put("value", easyField.wrapValue(defaultValue));
defaultValue = EasyDecimal.clearFlaged(defaultValue);
}
el.put("value", defaultValue);
}
}
}
Expand Down Expand Up @@ -514,9 +517,14 @@ protected void buildModelElements(JSONArray elements, Entity entity, Record reco

// 编辑/视图/记录转换
if (recordData != null) {
// FIXME `wrapFieldValue` 会添加格式符号(小数)
Object value = wrapFieldValue(recordData, easyField, user);
if (value != null) el.put("value", value);
if (value != null) {
// `wrapValue` 会添加格式符号
if (!viewModel && easyField.getDisplayType() == DisplayType.DECIMAL) {
value = EasyDecimal.clearFlaged(value);
}
el.put("value", value);
}

// 父级级联
if ((dt == DisplayType.REFERENCE || dt == DisplayType.N2NREFERENCE) && recordData.getPrimary() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public JSONArray build(JSONArray fieldElements) {
}
}

FormsBuilder.instance.buildModelElements(fieldElements, entity, recordData, user, false);
FormsBuilder.instance.buildModelElements(fieldElements, entity, recordData, user, false, false);
return fieldElements;
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/rebuild/core/metadata/easymeta/EasyDecimal.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,15 @@ public static BigDecimal fixedDecimalScale(Object decimalValue, EasyField decima
return BigDecimal.valueOf(d);
}
}

/**
* 清除小数符号
*
* @param flagedValue
* @return
*/
public static String clearFlaged(Object flagedValue) {
if (flagedValue == null) return null;
return flagedValue.toString().replaceAll("[^\\d^.^-]", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected JSON buildNewForm(Entity entity, Record record, ID user) {
if (hasError != null) throw new DataSpecificationException(hasError);

JSONArray elements = ((JSONObject) model).getJSONArray("elements");
buildModelElements(elements, entity, record, user, true);
buildModelElements(elements, entity, record, user, false, true);
return model;
}
}
Expand Down
38 changes: 32 additions & 6 deletions src/main/java/com/rebuild/core/service/query/AdvFilterParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.math.BigDecimal;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -326,9 +327,36 @@ else if (ParseHelper.IN.equals(op) && ID.isId(value)) {

if (ParseHelper.TDA.equalsIgnoreCase(op)
|| ParseHelper.YTA.equalsIgnoreCase(op)
|| ParseHelper.TTA.equalsIgnoreCase(op)) {

if (ParseHelper.YTA.equalsIgnoreCase(op)) {
|| ParseHelper.TTA.equalsIgnoreCase(op)
|| ParseHelper.DDD.equalsIgnoreCase(op)
|| ParseHelper.EVW.equalsIgnoreCase(op) || ParseHelper.EVM.equalsIgnoreCase(op)) {

if (ParseHelper.DDD.equalsIgnoreCase(op)) {
int x = NumberUtils.toInt(value);
value = formatDate(addDay(x), 0);
} else if (ParseHelper.EVW.equalsIgnoreCase(op) || ParseHelper.EVM.equalsIgnoreCase(op)) {
Calendar c = CalendarUtils.getInstance();
int x = NumberUtils.toInt(value);
if (ParseHelper.EVW.equalsIgnoreCase(op)) {
boolean isSunday = c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
if (isSunday) c.add(Calendar.DAY_OF_WEEK, -1);
if (x < 1) x = 1;
if (x > 7) x = 7;
x += 1;
if (x <= 7) {
c.set(Calendar.DAY_OF_WEEK, x);
} else {
c.set(Calendar.DAY_OF_WEEK, 7);
c.add(Calendar.DAY_OF_WEEK, 1);
}
} else {
if (x < 1) x = 1;
if (x > 31) x = 31;
c.set(Calendar.DAY_OF_MONTH, x);
}
value = formatDate(c.getTime(), 0);
}
else if (ParseHelper.YTA.equalsIgnoreCase(op)) {
value = formatDate(addDay(-1), 0);
} else if (ParseHelper.TTA.equalsIgnoreCase(op)) {
value = formatDate(addDay(1), 0);
Expand Down Expand Up @@ -774,9 +802,7 @@ public static String validEquation(String equation) {
// 括弧成对出现
for (int i = 0; i < 20; i++) {
clearEquation = clearEquation.replace("()", "");
if (clearEquation.length() == 0) {
return equation;
}
if (clearEquation.isEmpty()) return equation;
}
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/rebuild/core/service/query/ParseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public class ParseHelper {
public static final String PUY = "PUY"; // 本年-
public static final String CUY = "CUY"; // 本年
public static final String NUY = "NUY"; // 本年+
public static final String DDD = "DDD"; // 指定天+-
public static final String EVW = "EVW"; // 每周几
public static final String EVM = "EVM"; // 每月几

// 日期时间

Expand Down Expand Up @@ -180,6 +183,8 @@ protected static String convetOperation(String token) {
PUW.equalsIgnoreCase(token) || PUM.equalsIgnoreCase(token) || PUQ.equalsIgnoreCase(token) || PUY.equalsIgnoreCase(token) ||
NUW.equalsIgnoreCase(token) || NUM.equalsIgnoreCase(token) || NUQ.equalsIgnoreCase(token) || NUY.equalsIgnoreCase(token)) {
return "between";
} else if (DDD.equalsIgnoreCase(token) || EVW.equalsIgnoreCase(token) || EVM.equalsIgnoreCase(token)) {
return "=";
}

throw new UnsupportedOperationException("Unsupported token of operation : " + token);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/rebuild/core/support/SysbaseHeartbeat.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.rebuild.core.support.i18n.Language;
import com.rebuild.utils.CommonsUtils;
import com.rebuild.utils.OshiUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;

import java.io.File;
Expand All @@ -29,6 +30,7 @@
* @author devezhao
* @since 2020/12/7
*/
@Slf4j
public class SysbaseHeartbeat {

private static final String CKEY_DANGERS = "_DANGERS";
Expand Down Expand Up @@ -75,10 +77,14 @@ public void heartbeat() {
}

// #3
Date networkDate = OshiUtils.getNetworkDate();
long networkDateLeft = (networkDate.getTime() - CalendarUtils.now().getTime()) / 1000;
final Date networkDate = OshiUtils.getNetworkDate();
final Date localDate = CalendarUtils.now();
final long networkDateLeft = (networkDate.getTime() - localDate.getTime()) / 1000;
if (Math.abs(networkDateLeft) > 15) {
log.warn("Server date offset : {} vs {}", networkDate, localDate);
dangers.put(DateNotSync, String.valueOf(networkDateLeft));
// FIXME v3.4.2 暂时禁用
dangers.remove(DateNotSync);
} else {
dangers.remove(DateNotSync);
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/rebuild/utils/OshiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.rebuild.utils;

import cn.devezhao.commons.CalendarUtils;
import cn.devezhao.commons.ObjectUtils;
import cn.devezhao.commons.runtime.MemoryInformationBean;
import com.esotericsoftware.minlog.Log;
Expand Down Expand Up @@ -115,9 +116,8 @@ public static String getLocalIp() {
*/
public static Date getNetworkDate() {
final String[] FROMURLS = new String[] {
"http://www.baidu.com/",
"http://bjtime.cn/",
"http://www.google.com/",
"https://www.baidu.com/",
"https://www.microsoft.com/",
};

for (String u : FROMURLS) {
Expand All @@ -126,11 +126,10 @@ public static Date getNetworkDate() {
long l = conn.getDate();
return new Date(l);
} catch (Exception ex) {
Log.debug("Failed with : {}", u);
log.warn("Cannot fetch date from : {}", u, ex);
}
}

log.warn("Cannot getdate from network");
return new Date();
return CalendarUtils.now();
}
}
5 changes: 4 additions & 1 deletion src/main/resources/i18n/lang.zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2724,5 +2724,8 @@
"你无权撤销审批":"你无权撤销审批",
"你无权撤回审批":"你无权撤回审批",
"无权访问该页面":"无权访问该页面",
"系统即将开始维护,暂时禁止登录":"系统即将开始维护,暂时禁止登录"
"系统即将开始维护,暂时禁止登录":"系统即将开始维护,暂时禁止登录",
"本月..":"本月..",
"指定..天":"指定..天",
"本周..":"本周.."
}
9 changes: 9 additions & 0 deletions src/main/resources/web/assets/js/rb-advfilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ const OP_TYPE = {
NUQ: $L('下季度'),
PUY: $L('去年'),
NUY: $L('明年'),
EVW: $L('本周..'),
EVM: $L('本月..'),
DDD: $L('指定..天'),
}
const OP_NOVALUE = ['NL', 'NT', 'SFU', 'SFB', 'SFD', 'YTA', 'TDA', 'TTA', 'PUW', 'CUW', 'NUW', 'PUM', 'CUM', 'NUM', 'PUQ', 'CUQ', 'NUQ', 'PUY', 'CUY', 'NUY']
const OP_DATE_NOPICKER = [
Expand Down Expand Up @@ -367,6 +370,9 @@ const OP_DATE_NOPICKER = [
'PUY',
'CUY',
'NUY',
'EVW',
'EVM',
'DDD',
]
const REFENTITY_CACHE = {}
const PICKLIST_CACHE = {}
Expand Down Expand Up @@ -453,6 +459,9 @@ class FilterItem extends React.Component {
'PUY',
'CUY',
'NUY',
'EVW',
'EVM',
'DDD',
]
} else if (fieldType === 'TIME') {
op = ['GT', 'LT', 'EQ', 'BW']
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/web/error/server-status.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ <h5 class="text-bold mt-5">[[${bundle.L('系统信息')}]]</h5>
</tr>
<tr>
<th>System Time</th>
<td>[[${T(cn.devezhao.commons.CalendarUtils).now().toLocaleString()}]]</td>
<td>[[${T(cn.devezhao.commons.CalendarUtils).now()}]]</td>
</tr>
<tr>
<th>Startup Time</th>
<td>[[${T(com.rebuild.core.ServerStatus).STARTUP_TIME.toLocaleString()}]]</td>
<td>[[${T(com.rebuild.core.ServerStatus).STARTUP_TIME}]]</td>
</tr>
<tr>
<th>Data Directory</th>
Expand Down

0 comments on commit 37c01fe

Please sign in to comment.