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

Enh list aside #854

Merged
merged 15 commits into from
Dec 31, 2024
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ git:
submodules: false

before_script:
- mysql -e "CREATE DATABASE rebuild30 COLLATE utf8mb4_general_ci;"
- mysql -e "CREATE USER 'rebuild'@'127.0.0.1' IDENTIFIED BY 'rebuild'; GRANT ALL PRIVILEGES ON rebuild30.* TO 'rebuild'@'127.0.0.1'; FLUSH PRIVILEGES;"
- mysql -D rebuild30 < src/main/resources/scripts/db-init.sql
- mysql -e "CREATE DATABASE rebuild40 COLLATE utf8mb4_general_ci;"
- mysql -e "CREATE USER 'rebuild'@'127.0.0.1' IDENTIFIED BY 'rebuild'; GRANT ALL PRIVILEGES ON rebuild40.* TO 'rebuild'@'127.0.0.1'; FLUSH PRIVILEGES;"
- mysql -D rebuild40 < src/main/resources/scripts/db-init.sql

# codecov
after_success:
Expand Down
2 changes: 1 addition & 1 deletion @rbv
Submodule @rbv updated from e28024 to 04323f
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM amazoncorretto:11-alpine
#docker pull amazoncorretto:11-alpine

RUN apk add ttf-dejavu

EXPOSE 18080

COPY ./target/rebuild.jar /app/rebuild/rebuild-boot.jar

#COPY ./.deploy/SourceHanSansK-Regular.ttf /app/rebuild/.rebuild/

WORKDIR /app/rebuild/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void postProcessEnvironment(ConfigurableEnvironment env, SpringApplicatio

// `application-bean.xml` 占位符必填
if (dbUrl == null) {
dbUrl = "jdbc:mysql://127.0.0.1:3306/rebuild30?characterEncoding=UTF8";
dbUrl = "jdbc:mysql://127.0.0.1:3306/rebuild40?characterEncoding=UTF8";
confPs.put("db.url", dbUrl);
}
if (env.getProperty("db.user") == null) confPs.put("db.user", "rebuild");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,33 @@
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.EasyEntity;
import com.rebuild.core.metadata.easymeta.EasyField;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.metadata.impl.EasyEntityConfigProps;
import com.rebuild.core.service.dashboard.ChartManager;
import com.rebuild.core.service.query.ParseHelper;
import com.rebuild.core.support.i18n.Language;
import com.rebuild.utils.JSONUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.rebuild.core.metadata.impl.EasyEntityConfigProps.ADVLIST_ASIDE_SHOWS;
import static com.rebuild.core.metadata.impl.EasyEntityConfigProps.ADVLIST_HIDE_CHARTS;
import static com.rebuild.core.metadata.impl.EasyEntityConfigProps.ADVLIST_HIDE_FILTERS;
import static com.rebuild.core.metadata.impl.EasyEntityConfigProps.ADVLIST_MODE3_SHOWCATEGORY;
import static com.rebuild.core.metadata.impl.EasyEntityConfigProps.ADVLIST_MODE3_SHOWCHARTS;
import static com.rebuild.core.metadata.impl.EasyEntityConfigProps.ADVLIST_MODE3_SHOWFILTERS;
import static com.rebuild.core.metadata.impl.EasyEntityConfigProps.ADVLIST_SHOWCATEGORY;

/**
* 数据列表
*
Expand Down Expand Up @@ -373,4 +385,59 @@ private JSON formatShowFields(Entity entity, JSONArray showFields) {
}
return emptyConfig;
}

/**
* 获取侧栏显示
*
* @param easyEntity
* @param listMode
* @return
*/
public JSONArray getAdvListAsideShows(EasyEntity easyEntity, int listMode) {
final JSONObject extraAttrs = easyEntity.getExtraAttrs();

Map<String, Object[]> itemsMap = new HashMap<>();
if (listMode == 3) {
if (extraAttrs.getBooleanValue(ADVLIST_MODE3_SHOWFILTERS)) {
itemsMap.put(ADVLIST_MODE3_SHOWFILTERS, new Object[]{Language.L("常用查询"), 1, "asideFilters"});
}
if (extraAttrs.getString(ADVLIST_MODE3_SHOWCATEGORY) != null) {
itemsMap.put(ADVLIST_MODE3_SHOWCATEGORY, new Object[]{Language.L("分组"), 2, "asideCategory"});
}
if (extraAttrs.getBooleanValue(ADVLIST_MODE3_SHOWCHARTS)) {
itemsMap.put(ADVLIST_MODE3_SHOWCHARTS, new Object[]{Language.L("图表"), 3, "asideCharts"});
}
} else {
if (!extraAttrs.getBooleanValue(ADVLIST_HIDE_FILTERS)) {
itemsMap.put(ADVLIST_HIDE_FILTERS, new Object[]{Language.L("常用查询"), 1, "asideFilters"});
}
if (extraAttrs.getString(ADVLIST_SHOWCATEGORY) != null) {
itemsMap.put(ADVLIST_SHOWCATEGORY, new Object[]{Language.L("分组"), 2, "asideCategory"});
}
if (!extraAttrs.getBooleanValue(ADVLIST_HIDE_CHARTS)) {
itemsMap.put(ADVLIST_HIDE_CHARTS, new Object[]{Language.L("图表"), 3, "asideCharts"});
}
}

String shows = easyEntity.getExtraAttr(ADVLIST_ASIDE_SHOWS);
JSONObject showsConf;
if (JSONUtils.wellFormat(shows)) showsConf = JSON.parseObject(shows);
else showsConf = new JSONObject();

for (String name : showsConf.keySet()) {
JSONObject o = showsConf.getJSONObject(name);
Object[] item = itemsMap.get(name);
if (o == null || item == null) continue;

String label = o.getString("label");
int order = o.getIntValue("order");
if (StringUtils.isNotBlank(label)) item[0] = label;
if (order > 0) item[1] = order;
itemsMap.put(name, item);
}

List<Object[]> items = new ArrayList<>(itemsMap.values());
items.sort(Comparator.comparingInt(o -> (int) o[1]));
return (JSONArray) JSON.toJSON(items);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ public class EasyEntityConfigProps {
* @see #ADVLIST_HIDE_FILTERS
*/
public static final String ADVLIST_MODE3_SHOWFILTERS = "mode3ShowFilters";
/**
* @see #ADVLIST_HIDE_CHARTS
*/
public static final String ADVLIST_MODE3_SHOWCHARTS = "mode3ShowCharts";
/**
* @see #ADVLIST_SHOWCATEGORY
*/
public static final String ADVLIST_MODE3_SHOWCATEGORY = "mode3ShowCategory";
/**
* 列表侧栏显示样式
*/
public static final String ADVLIST_ASIDE_SHOWS = "advListAsideShows";
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private Field createBuiltinField(Entity entity, String fieldName, String fieldLa
*/
private boolean schema2Database(Entity entity) {
Dialect dialect = Application.getPersistManagerFactory().getDialect();
Table table = new Table(entity, dialect);
Table table = new Table40(entity, dialect);
String[] ddls = table.generateDDL(false, false, false);

try {
Expand Down
37 changes: 29 additions & 8 deletions src/main/java/com/rebuild/core/metadata/impl/Field2Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ public boolean dropField(Field field, boolean force) {
} catch (Throwable ex) {
// ?
if (ThrowableUtils.getRootCause(ex).getLocalizedMessage().contains("exists")) {
log.warn("Column not exists? " + ex.getLocalizedMessage());
log.warn("Column not exists? {}", ex.getLocalizedMessage());
} else {
log.error("DDL ERROR : \n" + ddl, ex);
log.error("DDL ERROR : \n{}", ddl, ex);
return false;
}
}
Expand Down Expand Up @@ -208,7 +208,7 @@ public boolean schema2Database(Entity entity, Field[] fields) {
*/
public boolean schema2Database(Entity entity, Field[] fields, Collection<String> uniqueKeyFields) {
Dialect dialect = Application.getPersistManagerFactory().getDialect();
final Table table = new Table(entity, dialect);
final Table table = new Table40(entity, dialect);
final String alterSql = "alter table `" + entity.getPhysicalName() + "`";

// H2 只能一个个字段的加
Expand All @@ -220,7 +220,7 @@ public boolean schema2Database(Entity entity, Field[] fields, Collection<String>
try {
Application.getSqlExecutor().executeBatch(new String[]{ddl.toString()}, DDL_TIMEOUT);
} catch (Throwable ex) {
log.error("DDL ERROR : \n" + ddl, ex);
log.error("DDL ERROR : \n{}", ddl, ex);
return false;
}
}
Expand Down Expand Up @@ -249,9 +249,9 @@ public boolean schema2Database(Entity entity, Field[] fields, Collection<String>
// Duplicate column name: 'xxx'
if (fields.length == 1
&& ThrowableUtils.getRootCause(ex).getLocalizedMessage().contains("Duplicate column")) {
log.warn("Duplicate column exists? " + ex.getLocalizedMessage());
log.warn("Duplicate column exists? {}", ex.getLocalizedMessage());
} else {
log.error("DDL ERROR : \n" + ddl, ex);
log.error("DDL ERROR : \n{}", ddl, ex);
return false;
}
}
Expand Down Expand Up @@ -487,13 +487,13 @@ public boolean castType(Field field, DisplayType toType, boolean force) {
String alterTypeSql = null;
try {
Dialect dialect = Application.getPersistManagerFactory().getDialect();
final Table table = new Table(field.getOwnEntity(), dialect);
final Table table = new Table40(field.getOwnEntity(), dialect);
StringBuilder ddl = new StringBuilder();
table.generateFieldDDL(field, ddl);

alterTypeSql = String.format("alter table `%s` change column `%s` ",
field.getOwnEntity().getPhysicalName(), field.getPhysicalName());
alterTypeSql += ddl.toString().trim().replace(" ", " ");
alterTypeSql += ddl.toString().trim().replaceAll("\\s+", " ");

Application.getSqlExecutor().executeBatch(new String[]{alterTypeSql}, DDL_TIMEOUT);
log.info("Cast field type : {}", alterTypeSql);
Expand All @@ -519,4 +519,25 @@ public boolean castType(Field field, DisplayType toType, boolean force) {

return true;
}

/**
* @param field
* @return
*/
public boolean fixsDatetime40(Field field) {
if (field.getType() != FieldType.TIMESTAMP) return false;

Dialect dialect = Application.getPersistManagerFactory().getDialect();
final Table table = new Table40(field.getOwnEntity(), dialect);
StringBuilder ddl = new StringBuilder();
table.generateFieldDDL(field, ddl);

String alterTypeSql = String.format("alter table `%s` change column `%s` ",
field.getOwnEntity().getPhysicalName(), field.getPhysicalName());
alterTypeSql += ddl.toString().trim().replaceAll("\\s+", " ");

Application.getSqlExecutor().executeBatch(new String[]{alterTypeSql}, DDL_TIMEOUT);
log.info("Fixs datetime field : {}", alterTypeSql);
return true;
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/rebuild/core/metadata/impl/Table40.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*!
Copyright (c) REBUILD <https://getrebuild.com/> and/or its owners. All rights reserved.

rebuild is dual-licensed under commercial and open source licenses (GPLv3).
See LICENSE and COMMERCIAL in the project root for license information.
*/

package com.rebuild.core.metadata.impl;

import cn.devezhao.persist4j.Entity;
import cn.devezhao.persist4j.Field;
import cn.devezhao.persist4j.dialect.Dialect;
import cn.devezhao.persist4j.util.support.Table;

import java.util.List;

/**
* Fixs timestamp to datetime
*
* @author Zixin (RB)
* @since 12/28/2024
*/
public class Table40 extends Table {

public Table40(Entity entity, Dialect dialect) {
super(entity, dialect);
}

public Table40(Entity entity, Dialect dialect, List<?> indexList) {
super(entity, dialect, indexList);
}

@Override
public void generateFieldDDL(Field field, StringBuilder into, boolean allowZeroDate) {
StringBuilder tmp = new StringBuilder();
super.generateFieldDDL(field, tmp, allowZeroDate);
String tmpFix = tmp.toString().replace(" timestamp ", " datetime ");
into.append(tmpFix);
}
}
71 changes: 0 additions & 71 deletions src/main/java/com/rebuild/core/metadata/impl/TsetEntity.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class Installer implements InstallState {

private String EXISTS_SN;

private Installer() { }
private Installer() {}

/**
* @param installProps
Expand Down
Loading
Loading