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

feat: report nref #698

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.rebuild.core.metadata.MetadataHelper;
import com.rebuild.core.privileges.UserService;
import com.rebuild.core.service.approval.ApprovalHelper;
import com.rebuild.core.support.general.ProtocolFilterParser;
import com.rebuild.core.support.general.RecordBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -88,10 +89,11 @@ protected List<Map<String, Object>> buildData() {
} else if (varName.startsWith(DETAIL_PREFIX)) {
refName = DETAIL_PREFIX;
} else {
// 在客户中导出订单(下列 AccountId 为订单中引用客户的引用字段)
// .AccountId.SalesOrder.SalesOrderName
String[] split = varName.substring(1).split("\\.");
if (split.length < 2) throw new ReportsException("Bad REF (Miss .detail prefix?) : " + varName);

String refName2 = split[0] + split[1];
refName = varName.substring(0, refName2.length() + 2 /* dots */);
}
Expand Down Expand Up @@ -169,8 +171,12 @@ protected List<Map<String, Object>> buildData() {
String sortField = templateExtractor33.getSortField(refName);
querySql += " order by " + StringUtils.defaultIfBlank(sortField, "createdOn asc");

String relatedExpr = split[1] + "." + split[0];
String where = new ProtocolFilterParser(null).parseRelated(relatedExpr, recordId);
querySql = querySql.replace("%s = ?", where);

querySql = String.format(querySql, StringUtils.join(e.getValue(), ","),
ref2Entity.getPrimaryField().getName(), ref2Entity.getName(), split[0]);
ref2Entity.getPrimaryField().getName(), ref2Entity.getName());
}

log.info("SQL of template : {}", querySql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex
int colIndex = cell.getColumnIndex();
sheet = cell.getSheet();
Row prevRow = sheet.getRow(rowIndex - 1);
if (prevRow == null) return;
Cell prevCell = prevRow.getCell(colIndex);
List<CellRangeAddress> craList = sheet.getMergedRegions();
CellStyle cs = cell.getCellStyle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.rebuild.core.Application;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.privileges.UserHelper;
import com.rebuild.core.support.integration.QiniuCloud;
import com.rebuild.utils.JSONUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.map.LRUMap;
Expand Down Expand Up @@ -61,6 +62,7 @@ public static void storeFileSize(String filePath, int fileSize) {
public static Record createAttachment(String filePath, ID user) {
Record attach = EntityHelper.forNew(EntityHelper.Attachment, user);
attach.setString("filePath", filePath);
attach.setString("fileName", QiniuCloud.parseFileName(filePath));

String ext = FilenameUtils.getExtension(filePath);
if (StringUtils.isNotBlank(ext)) {
Expand All @@ -69,7 +71,7 @@ public static Record createAttachment(String filePath, ID user) {
}

if (FILESIZES.containsKey(filePath)) {
attach.setInt("fileSize", FILESIZES.remove(filePath));
attach.setInt("fileSize", FILESIZES.get(filePath));
} else {
Object[] db = Application.createQueryNoFilter("select fileSize from Attachment where filePath = ?")
.setParameter(1, filePath)
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/rebuild/core/support/setup/DatabaseFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import cn.devezhao.persist4j.Field;
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
import cn.devezhao.persist4j.util.support.QueryHelper;
import com.rebuild.core.Application;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.metadata.MetadataHelper;
Expand All @@ -23,6 +24,7 @@
import com.rebuild.core.support.ConfigurationItem;
import com.rebuild.core.support.KVStorage;
import com.rebuild.core.support.RebuildConfiguration;
import com.rebuild.core.support.integration.QiniuCloud;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.BooleanUtils;

Expand All @@ -37,6 +39,7 @@ public class DatabaseFixer {

private static final String KEY_41 = "DataMigratorV41";
private static final String KEY_346 = "DatabaseFixerV346";
private static final String KEY_360 = "DatabaseFixerV360";

/**
* 辅助数据库升级
Expand Down Expand Up @@ -69,6 +72,19 @@ public static void fixIfNeed() {
}
});
}

if (dbVer <= 54 && !BooleanUtils.toBoolean(KVStorage.getCustomValue(KEY_360))) {
log.info("Database fixing `V360` ...");
ThreadPool.exec(() -> {
try {
fixV360();
KVStorage.setCustomValue(KEY_360, "true");
log.info("Database fixed `V360` all succeeded");
} catch (Exception ex) {
log.error("Database fixing `V360` failed : {}", ThrowableUtils.getRootCause(ex).getLocalizedMessage());
}
});
}
}

// #41:多引用字段改为三方表
Expand Down Expand Up @@ -130,4 +146,16 @@ private static void fixV346() {
}
}
}

// V360:补充附件文件名称
private static void fixV360() {
Object[][] atts = QueryHelper.readArray(
Application.createQueryNoFilter("select attachmentId,filePath from Attachment"));
for (Object[] o : atts) {
String fileName = QiniuCloud.parseFileName((String) o[1]);
Record record = EntityHelper.forUpdate((ID) o[0], UserService.SYSTEM_USER, false);
record.setString("fileName", fileName);
Application.getCommonsService().update(record, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public JSON listFile(HttpServletRequest request) {

List<String> sqlWhere = new ArrayList<>();
if (StringUtils.isNotBlank(q)) {
sqlWhere.add(String.format("filePath like '%%%s%%'", CommonsUtils.escapeSql(q)));
sqlWhere.add(String.format("fileName like '%%%s%%'", CommonsUtils.escapeSql(q)));
}

// 附件
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/metadata-conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@
<field name="filePath" type="string" max-length="191" nullable="false" description="文件路径"/>
<field name="fileType" type="string" max-length="20" description="文件类型"/>
<field name="fileSize" type="int" default-value="0" description="文件大小"/>
<field name="fileName" type="string" max-length="100" description="文件名称"/>
<field name="fileMd5" type="string" max-length="32" description="文件MD5"/>
<field name="inFolder" type="reference" ref-entity="AttachmentFolder" description="所在目录"/>
<field name="isDeleted" type="bool" default-value="F" description="是否删除"/>
<index field-list="belongEntity,belongField,filePath,isDeleted"/>
<index field-list="inFolder,createdOn,filePath"/>
<index field-list="belongEntity,belongField,fileName,isDeleted"/>
<index field-list="inFolder,createdOn,fileName"/>
<index field-list="relatedRecord"/>
<index field-list="fileMd5"/>
</entity>

<entity name="AttachmentFolder" type-code="024" description="附件目录" queryable="false">
Expand Down
11 changes: 7 additions & 4 deletions src/main/resources/scripts/db-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,19 @@ create table if not exists `attachment` (
`FILE_PATH` varchar(191) not null comment '文件路径',
`FILE_TYPE` varchar(20) comment '文件类型',
`FILE_SIZE` int(11) default '0' comment '文件大小',
`FILE_NAME` varchar(100) comment '文件名称',
`FILE_MD5` varchar(32) comment '文件MD5',
`IN_FOLDER` char(20) comment '所在目录',
`IS_DELETED` char(1) default 'F' comment '是否删除',
`MODIFIED_ON` timestamp not null default current_timestamp comment '修改时间',
`MODIFIED_BY` char(20) not null comment '修改人',
`CREATED_BY` char(20) not null comment '创建人',
`CREATED_ON` timestamp not null default current_timestamp comment '创建时间',
primary key (`ATTACHMENT_ID`),
index IX0_attachment (`BELONG_ENTITY`, `BELONG_FIELD`, `FILE_PATH`, `IS_DELETED`),
index IX1_attachment (`IN_FOLDER`, `CREATED_ON`, `FILE_PATH`),
index IX2_attachment (`RELATED_RECORD`)
index IX0_attachment (`BELONG_ENTITY`, `BELONG_FIELD`, `FILE_NAME`, `IS_DELETED`),
index IX1_attachment (`IN_FOLDER`, `CREATED_ON`, `FILE_NAME`),
index IX2_attachment (`RELATED_RECORD`),
index IX3_attachment (`FILE_MD5`)
)Engine=InnoDB;

-- ************ Entity [AttachmentFolder] DDL ************
Expand Down Expand Up @@ -886,4 +889,4 @@ insert into `project_plan_config` (`CONFIG_ID`, `PROJECT_ID`, `PLAN_NAME`, `SEQ`

-- DB Version (see `db-upgrade.sql`)
insert into `system_config` (`CONFIG_ID`, `ITEM`, `VALUE`)
values ('021-9000000000000001', 'DBVer', 54);
values ('021-9000000000000001', 'DBVer', 55);
5 changes: 5 additions & 0 deletions src/main/resources/scripts/db-upgrade.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
-- Database upgrade scripts for rebuild 1.x and 2.x
-- Each upgraded starts with `-- #VERSION`

-- #55 (v3.6)
alter table `attachment`
add column `FILE_NAME` varchar(100) comment '文件名称',
add column `FILE_MD5` varchar(32) comment '文件MD5';

-- #54 (v3.5)
alter table `feeds`
add column `AUTO_LOCATION` varchar(100) comment '发布位置';
Expand Down