Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be 3.7 9 #767

Merged
merged 16 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .deploy/fallstart-rebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

RBHOME=/path/to/v-rebuild-standalone
cd $RBHOME

PID=$(ps -ef | grep $RBHOME | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo "Rebuild-Standalone is not running. Starting ..."
./start-rebuild.sh
else
echo "Rebuild-Standalone is running"
fi
2 changes: 1 addition & 1 deletion .deploy/restart-rebuild.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

JARFILE=rebuild-boot.jar
JARFILE=/path/to/rebuild-boot.jar

echo "Use jar file [ $JARFILE ]"

Expand Down
2 changes: 1 addition & 1 deletion @rbv
Submodule @rbv updated from e27d02 to d4dcb3
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ protected BaseLayoutManager() {
public static final String TYPE_TAB = "TAB";
// 视图-新建相关
public static final String TYPE_ADD = "ADD";
// 列表-自定义操作
public static final String TYPE_EASYACTION = "EASYACTION";

@Override
protected String getConfigEntity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*!
Copyright (c) Ruifang Tech <http://ruifang-tech.com/> and/or its owners. All rights reserved.
*/

package com.rebuild.core.configuration.general;

import cn.devezhao.persist4j.engine.ID;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.core.configuration.ConfigBean;
import com.rebuild.core.privileges.UserHelper;
import com.rebuild.core.privileges.UserService;

/**
* 自定义操作按钮
*
* @author Zixin (RB)
* @since 6/5/2024
*/
public class EasyActionManager extends BaseLayoutManager {

public static final EasyActionManager instance = new EasyActionManager();

private EasyActionManager() {
}

/**
* @param entity
* @param user
* @return
*/
public JSON getEasyAction(String entity, ID user) {
ConfigBean cb = getLayout(UserService.SYSTEM_USER, entity, TYPE_EASYACTION, null);
if (cb == null) return null;

JSONArray items = (JSONArray) cb.getJSON("config");
if (items == null || items.isEmpty()) return null;

JSONArray items4User = new JSONArray();
for (Object item : items) {
JSONObject itemObj = (JSONObject) item;

JSONArray itemsL2 = itemObj.getJSONArray("items");
boolean hasChild = itemsL2 != null && !itemsL2.isEmpty();
if (hasChild) {
JSONArray items4UserL2 = new JSONArray();
for (Object itemL2 : itemsL2) {
JSONObject itemL2Obj = (JSONObject) itemL2;
String shareTo = itemL2Obj.getString("shareTo");
if (UserHelper.isAdmin(user) || isShareTo(shareTo, user)) {
items4UserL2.add(itemL2Obj);
}
}

// 是否可见由子元素确定
if (!items4UserL2.isEmpty()) {
itemObj.put("items", items4UserL2);
items4User.add(itemObj);
}

} else {
String shareTo = itemObj.getString("shareTo");
if (UserHelper.isAdmin(user) || isShareTo(shareTo, user)) {
items4User.add(itemObj);
}
}
}

return items4User;
}

/**
* @param entity
* @return
*/
public ConfigBean getEasyActionRaw(String entity) {
return getLayout(UserService.SYSTEM_USER, entity, TYPE_EASYACTION, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,28 +190,25 @@ else if (viewMode) {
}
}

ID recordId4Layout = recordId;
// v3.7 明细使用指定记录布局
if (entityMeta.getMainEntity() != null) {
// for New
if (recordId == null) {
ID mainid = FormsBuilderContextHolder.getMainIdOfDetail(false);
if (mainid != null && !EntityHelper.isUnsavedId(mainid)) {
List<ID> ids = QueryHelper.detailIdsNoFilter(mainid, entityMeta);
if (!ids.isEmpty()) recordId4Layout = ids.get(0);
}
}
// for Update
else {
ID s = FormsBuilderContextHolder.getLayoutSpecRecord(false);
if (s != null) recordId4Layout = s;
// v3.7 指定布局
ID recordOrLayoutId = recordId;

// 优先使用
ID forceLayout = FormsBuilderContextHolder.getSpecLayout(false);
if (forceLayout != null) recordOrLayoutId = forceLayout;
// 明细共同编辑
if (forceLayout == null && entityMeta.getMainEntity() != null && recordId == null) {
ID mainid = FormsBuilderContextHolder.getMainIdOfDetail(false);
if (mainid != null && !EntityHelper.isUnsavedId(mainid)) {
List<ID> ids = QueryHelper.detailIdsNoFilter(mainid, entityMeta);
if (!ids.isEmpty()) recordOrLayoutId = ids.get(0);
}
}

int applyType = recordId == null ? FormsManager.APPLY_ONNEW : FormsManager.APPLY_ONEDIT;
if (viewMode) applyType = FormsManager.APPLY_ONVIEW;

ConfigBean model = getFormLayout(entity, recordId4Layout, applyType);
ConfigBean model = getFormLayout(entity, recordOrLayoutId, applyType);
JSONArray elements = (JSONArray) model.getJSON("elements");
if (elements == null || elements.isEmpty()) {
return formatModelError(Language.L("表单布局尚未配置,请配置后使用"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public class FormsBuilderContextHolder {

private static final ThreadLocal<ID> MAINID_OF_DETAIL = new NamedThreadLocal<>("MainId from details");

private static final ThreadLocal<ID> LAYOUT_SPEC_RECORD = new NamedThreadLocal<>("Layout using specified record");
private static final ThreadLocal<ID> SPEC_LAYOUT = new NamedThreadLocal<>("Layout using specified");

/**
* 明细指定主记录
*
* @param mainid
*/
public static void setMainIdOfDetail(ID mainid) {
Expand All @@ -40,19 +42,21 @@ public static ID getMainIdOfDetail(boolean once) {
}

/**
* @param specRecordId
* 指定表单布局
*
* @param specLayout
*/
public static void setLayoutSpecRecord(ID specRecordId) {
LAYOUT_SPEC_RECORD.set(specRecordId);
public static void setSpecLayout(ID specLayout) {
SPEC_LAYOUT.set(specLayout);
}

/**
* @param once
* @return
*/
public static ID getLayoutSpecRecord(boolean once) {
ID specRecordId = LAYOUT_SPEC_RECORD.get();
if (specRecordId != null && once) LAYOUT_SPEC_RECORD.remove();
public static ID getSpecLayout(boolean once) {
ID specRecordId = SPEC_LAYOUT.get();
if (specRecordId != null && once) SPEC_LAYOUT.remove();
return specRecordId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.core.configuration.ConfigBean;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.service.query.ParseHelper;
import com.rebuild.core.service.query.QueryHelper;
import com.rebuild.utils.JSONUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* 表单布局管理
*
* @author Zixin (RB)
* @since 08/30/2018
*/
@Slf4j
public class FormsManager extends BaseLayoutManager {

public static final FormsManager instance = new FormsManager();
Expand All @@ -45,34 +49,53 @@ public ConfigBean getNewFormLayout(String entity) {

/**
* @param entity
* @param recordId
* @param recordOrLayoutId 指定布局
* @param applyType
* @return
*/
public ConfigBean getFormLayout(String entity, ID recordId, int applyType) {
public ConfigBean getFormLayout(String entity, ID recordOrLayoutId, int applyType) {
final Object[][] alls = getAllConfig(entity, TYPE_FORM);

// TODO `applyType` 暂未用

ConfigBean use = null;
for (Object[] o : alls) {
ConfigBean cb = findConfigBean(alls, (ID) o[0]);
ShareToAttr attr = new ShareToAttr(cb);
if (recordId == null) {
if (attr.isFallback()) {
use = cb;

// 1.指定布局
if (recordOrLayoutId != null && recordOrLayoutId.getEntityCode() == EntityHelper.LayoutConfig) {
for (Object[] o : alls) {
if (recordOrLayoutId.equals(o[0])) {
use = findConfigBean(alls, (ID) o[0]);;
break;
}
} else {
if (attr.isMatchUseFilter(recordId)) {
use = cb;
break;
}

if (use == null) {
log.warn("Spec layout not longer exists : {}", recordOrLayoutId);
recordOrLayoutId = null;
}
}

// 2.使用布局
if (use == null) {
for (Object[] o : alls) {
ConfigBean cb = findConfigBean(alls, (ID) o[0]);
ShareToAttr attr = new ShareToAttr(cb);
if (recordOrLayoutId == null) {
if (attr.isFallback()) {
use = cb;
break;
}
} else {
if (attr.isMatchUseFilter(recordOrLayoutId)) {
use = cb;
break;
}
}
}
}

// 默认布局
if (use == null && recordId != null) {
// 3.默认布局(fallback)
if (use == null && recordOrLayoutId != null) {
for (Object[] o : alls) {
ConfigBean cb = findConfigBean(alls, (ID) o[0]);
ShareToAttr attr = new ShareToAttr(cb);
Expand Down Expand Up @@ -132,6 +155,14 @@ public List<ConfigBean> getAllFormsAttr(String entity) {
ConfigBean cb = findConfigBean(alls, (ID) o[0]).remove("config");
flist.add(cb.remove("elements"));
}

// A-Z
flist.sort((o1, o2) -> {
String name1 = Objects.toString(o1.getString("name"), "0");
String name2 = Objects.toString(o2.getString("name"), "0");
return name1.compareTo(name2);
});

return flist;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ApprovalProcessor(ID recordId, ID approval) {
public boolean submit(JSONObject selectNextUsers) throws ApprovalException {
final ApprovalState currentState = ApprovalHelper.getApprovalState(this.recordId);
if (currentState == ApprovalState.PROCESSING || currentState == ApprovalState.APPROVED) {
throw new ApprovalException(Language.L("无效审批状态 (%s) ,请刷新后重试", currentState));
throw new ApprovalException(Language.L("无效审批状态 (%s),请刷新后重试", currentState));
}

FlowNodeGroup nextNodes = getNextNodes(FlowNode.NODE_ROOT);
Expand Down Expand Up @@ -729,7 +729,7 @@ protected static void share2CcIfNeed(ID recordId, Set<ID> shareTo) {
private ApprovalStatus checkApprovalState(ApprovalState mustbe) {
final ApprovalStatus status = ApprovalHelper.getApprovalStatus(this.recordId);
if (status.getCurrentState() != mustbe) {
throw new ApprovalException(Language.L("无效审批状态 (%s) ,请刷新后重试", status.getCurrentState()));
throw new ApprovalException(Language.L("无效审批状态 (%s),请刷新后重试", status.getCurrentState()));
}
return status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ else if (ParseHelper.SFU.equalsIgnoreCase(op)) {
// `in`
value = MessageFormat.format(
"( select {0} from {1} group by {0} having (count({0}) > {2}) )",
field, rootEntity.getName(), NumberUtils.toInt(value, 1));
field, rootEntity.getName(), String.valueOf(NumberUtils.toInt(value, 1)));
}

if (StringUtils.isBlank(value)) {
Expand Down Expand Up @@ -784,7 +784,7 @@ private String useValueOfVarRecord(String value, Field queryField) {

Object useValue = null;

// {@CURRENT} DATE
// {@CURRENT} for DATE
if (CURRENT_ANY.equals(fieldName) || CURRENT_DATE.equals(fieldName)) {
DisplayType dt = EasyMetaFactory.getDisplayType(queryField);
if (dt == DisplayType.DATE || dt == DisplayType.DATETIME || dt == DisplayType.TIME) {
Expand All @@ -797,18 +797,21 @@ private String useValueOfVarRecord(String value, Field queryField) {
Department dept = UserHelper.getDepartment(UserContextHolder.getUser());
if (dept != null) useValue = dept.getIdentity();
}

} else {
log.warn("Cannot use `CURRENT` in `{}` (None date fields)", queryField);
log.warn("Cannot use `{}` in `{}` (None date fields)", value, queryField);
return StringUtils.EMPTY;
}
}
// {@CURRENT.} USER
// {@CURRENT.} for USER
if (fieldName.startsWith(CURRENT_ANY + ".")) {
String userField = fieldName.substring(CURRENT_ANY.length() + 1);
Object[] o = Application.getQueryFactory().uniqueNoFilter(getUser(), userField);
if (o == null || o[0] == null) return StringUtils.EMPTY;
else useValue = o[0];
if (o == null || o[0] == null) {
log.warn("Cannot use `{}` in `{}` (No value found)", value, queryField);
return StringUtils.EMPTY;
} else {
useValue = o[0];
}
}

if (useValue == null) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/rebuild/web/admin/bizz/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.rebuild.core.privileges.bizz.Department;
import com.rebuild.core.privileges.bizz.User;
import com.rebuild.core.support.i18n.I18nUtils;
import com.rebuild.core.support.i18n.Language;
import com.rebuild.core.support.integration.SMSender;
import com.rebuild.utils.JSONUtils;
import com.rebuild.web.EntityController;
Expand Down Expand Up @@ -197,6 +198,15 @@ public RespBody userResetpwd(@IdParam ID userId, HttpServletRequest request) {
record.setString("password", newp);
Application.getBean(UserService.class).update(record);

if (getBoolParameter(request, "email")) {
String email = Application.getUserStore().getUser(userId).getEmail();
if (email != null && SMSender.availableMail()) {
String subject = Language.L("密码已被管理员重置");
String content = Language.L("你的密码已被管理员重置,请使用新密码登录。[][] 新密码:**%s**", newp);
SMSender.sendMailAsync(email, subject, content);
}
}

return RespBody.ok();
}

Expand Down
Loading
Loading