|
@@ -250,7 +250,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async _updateArchiveCommon(ctx, prjId, stgId, rptId, parentUuidName, childUuids, splitField) {
|
|
|
+ async _updateArchiveCommon(ctx, prjId, stgId, rptId, parentUuidName, childUuids) {
|
|
|
const updateDate = new Date();
|
|
|
const montStr = (updateDate.getMonth() + 1) < 10 ? ('0' + (updateDate.getMonth() + 1)) : (updateDate.getMonth() + 1);
|
|
|
const dateStr = (updateDate.getDate()) < 10 ? ('0' + updateDate.getDate()) : (updateDate.getDate());
|
|
@@ -294,20 +294,26 @@ module.exports = app => {
|
|
|
// 以及删除子oss文件
|
|
|
if (item.items[updateRmIdx].childUuids && item.items[updateRmIdx].childUuids.length > 0) {
|
|
|
for (const childUuid of item.items[updateRmIdx].childUuids) {
|
|
|
- await ctx.app.signPdfOss.delete(`archive/${childUuid}.PDF`);
|
|
|
+ let uuid = '';
|
|
|
+ if (typeof childUuid === 'string') {
|
|
|
+ uuid = childUuid;
|
|
|
+ } else {
|
|
|
+ uuid = childUuid.uuid;
|
|
|
+ }
|
|
|
+ await ctx.app.signPdfOss.delete(`archive/${uuid}.PDF`);
|
|
|
}
|
|
|
}
|
|
|
item.items.splice(updateRmIdx, 1);
|
|
|
}
|
|
|
|
|
|
- const newItem = { uuid: parentUuidName, updateDate_time: dtStr, childUuids, splitField };
|
|
|
+ const newItem = { uuid: parentUuidName, updateDate_time: dtStr, childUuids };
|
|
|
item.items.push(newItem);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!hasArchive) {
|
|
|
// 表示有新的模板需要添加
|
|
|
- contentArr.push({ rpt_id: rptId, items: [{ uuid: parentUuidName, updateDate_time: dtStr, childUuids, splitField }] });
|
|
|
+ contentArr.push({ rpt_id: rptId, items: [{ uuid: parentUuidName, updateDate_time: dtStr, childUuids }] });
|
|
|
}
|
|
|
const updatedRst = await ctx.service.rptArchive.updateArchive(orgArchiveList[0].id, prjId, stgId, contentArr);
|
|
|
// console.log(updatedRst);
|
|
@@ -315,7 +321,7 @@ module.exports = app => {
|
|
|
} else {
|
|
|
// 需要增加
|
|
|
const archiveArr = [];
|
|
|
- archiveArr.push({ rpt_id: rptId, items: [{ uuid: parentUuidName, updateDate_time: dtStr, childUuids, splitField }] });
|
|
|
+ archiveArr.push({ rpt_id: rptId, items: [{ uuid: parentUuidName, updateDate_time: dtStr, childUuids }] });
|
|
|
const addedRst = await ctx.service.rptArchive.createArchive(prjId, stgId, archiveArr);
|
|
|
rst = { err: 0, msg: parentUuidName, data: { uuid: parentUuidName, fileName, updateDate, updatedRst: archiveArr } };
|
|
|
}
|
|
@@ -330,11 +336,12 @@ module.exports = app => {
|
|
|
const stgId = ctx.params.stgId;
|
|
|
const rptId = ctx.params.rptId;
|
|
|
// const childAmt = parseInt(ctx.params.childAmt); // 子分页数量
|
|
|
- const childInfo = ctx.params.childAmt.split(';'); // 这个参数带比较多的信息,包含分割指标的:1. 名称 2. ID 3. 内容
|
|
|
+ const childInfo = ctx.params.splitInfo.split(';'); // 这个参数带比较多的信息,包含分割指标的:1. 名称 2. ID 3. 内容
|
|
|
const splitArcPages = JSON.parse(childInfo[0]);
|
|
|
// console.log(splitArcPages);
|
|
|
const childAmt = splitArcPages.length;
|
|
|
const splitFieldObj = JSON.parse(childInfo[1]);
|
|
|
+ const ttlPages = parseInt(childInfo[2]); // 总页数
|
|
|
// console.log(splitFieldObj);
|
|
|
const parentUuid = uuidV1();
|
|
|
const childUuids = [];
|
|
@@ -350,8 +357,15 @@ module.exports = app => {
|
|
|
//*/
|
|
|
let fileName = parentUuid + '.PDF';
|
|
|
if (index > 0) {
|
|
|
- childUuids.push(uuidV1());
|
|
|
- fileName = childUuids[childUuids.length - 1] + '.PDF';
|
|
|
+ const cUuid = uuidV1();
|
|
|
+ const startPage = splitArcPages[index - 1];
|
|
|
+ // const endPage = splitArcPages[index - 1];
|
|
|
+ let endPage = ttlPages;
|
|
|
+ if (index < splitArcPages.length) {
|
|
|
+ endPage = splitArcPages[index] - 1;
|
|
|
+ }
|
|
|
+ childUuids.push({ uuid: cUuid, totalPages: (endPage - startPage + 1), startPage, endPage, splitKeyValue: splitFieldObj.splitPageValues[index - 1] });
|
|
|
+ fileName = cUuid + '.PDF';
|
|
|
}
|
|
|
const oss_result = await ctx.app.signPdfOss.put('archive/' + fileName, stream);
|
|
|
if (!(oss_result && oss_result.url && oss_result.res.status === 200)) {
|
|
@@ -366,7 +380,7 @@ module.exports = app => {
|
|
|
}
|
|
|
// stream = await parts();
|
|
|
}
|
|
|
- const body = await this._updateArchiveCommon(ctx, prjId, stgId, rptId, parentUuid, childUuids, splitFieldObj);
|
|
|
+ const body = await this._updateArchiveCommon(ctx, prjId, stgId, rptId, parentUuid, childUuids);
|
|
|
ctx.body = body;
|
|
|
} catch (error) {
|
|
|
ctx.helper.log(error);
|
|
@@ -390,7 +404,7 @@ module.exports = app => {
|
|
|
if (!(oss_result && oss_result.url && oss_result.res.status === 200)) {
|
|
|
throw '上传文件失败';
|
|
|
}
|
|
|
- const body = await this._updateArchiveCommon(ctx, prjId, stgId, rptId, newUuidName, [], {});
|
|
|
+ const body = await this._updateArchiveCommon(ctx, prjId, stgId, rptId, newUuidName, []);
|
|
|
ctx.body = body;
|
|
|
} catch (err) {
|
|
|
this.log(err);
|
|
@@ -428,7 +442,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const body = await this._updateArchiveCommon(ctx, prjId, stgId, rptId, orgUuidName, [], {});
|
|
|
+ const body = await this._updateArchiveCommon(ctx, prjId, stgId, rptId, orgUuidName, []);
|
|
|
ctx.body = body;
|
|
|
} catch (err) {
|
|
|
this.log(err);
|
|
@@ -495,8 +509,13 @@ module.exports = app => {
|
|
|
if (item.items[subIdx].childUuids && item.items[subIdx].childUuids.length > 0) {
|
|
|
// 如果有子分页,也得删除!
|
|
|
for (const childUuid of item.items[subIdx].childUuids) {
|
|
|
- let childUuidName = childUuid;
|
|
|
- if (!childUuid.includes('.PDF')) childUuidName = childUuidName + '.PDF';
|
|
|
+ let childUuidName = '';
|
|
|
+ if (typeof childUuid === 'string') {
|
|
|
+ childUuidName = childUuid;
|
|
|
+ } else {
|
|
|
+ childUuidName = childUuid.uuid;
|
|
|
+ }
|
|
|
+ if (!childUuidName.includes('.PDF')) childUuidName = childUuidName + '.PDF';
|
|
|
await ctx.app.signPdfOss.delete(`archive/${childUuidName}`);
|
|
|
}
|
|
|
}
|