|
@@ -33,6 +33,7 @@ const math = require('mathjs');
|
|
math.config({
|
|
math.config({
|
|
number: 'BigNumber',
|
|
number: 'BigNumber',
|
|
});
|
|
});
|
|
|
|
+const validField = ['name', 'is_pause', 'is_gather', 'start_tp', 'start_expr', 'range_tp', 'range_expr', 'tp', 'expr', 'postil', 'dl_type', 'dl_value'];
|
|
|
|
|
|
class PayCalculator {
|
|
class PayCalculator {
|
|
constructor (ctx, phasePay) {
|
|
constructor (ctx, phasePay) {
|
|
@@ -315,7 +316,7 @@ class PhasePayDetail extends TreeService {
|
|
*/
|
|
*/
|
|
constructor(ctx, setting) {
|
|
constructor(ctx, setting) {
|
|
super(ctx, {
|
|
super(ctx, {
|
|
- mid: 'phase_id',
|
|
|
|
|
|
+ mid: 'master_id',
|
|
kid: 'tree_id',
|
|
kid: 'tree_id',
|
|
pid: 'tree_pid',
|
|
pid: 'tree_pid',
|
|
order: 'tree_order',
|
|
order: 'tree_order',
|
|
@@ -328,6 +329,12 @@ class PhasePayDetail extends TreeService {
|
|
this.tableName = 'phase_pay_detail';
|
|
this.tableName = 'phase_pay_detail';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ getMasterKey(phasePay) {
|
|
|
|
+ return phasePay.curTimes
|
|
|
|
+ ? `${phasePay.id}-${phasePay.curTimes}-${phasePay.curOrder}`
|
|
|
|
+ : `${phasePay.id}-${phasePay.audit_times}-${phasePay.audit_max_sort}`;
|
|
|
|
+ }
|
|
|
|
+
|
|
async initPhaseDataEmpty(conn, phasePay) {
|
|
async initPhaseDataEmpty(conn, phasePay) {
|
|
const user_id = this.ctx.session.sessionUser.accountId;
|
|
const user_id = this.ctx.session.sessionUser.accountId;
|
|
const insertData = [];
|
|
const insertData = [];
|
|
@@ -342,24 +349,23 @@ class PhasePayDetail extends TreeService {
|
|
|
|
|
|
async initPhaseDataByPre(conn, phasePay, prePhase) {
|
|
async initPhaseDataByPre(conn, phasePay, prePhase) {
|
|
const preData = await this.getAllDataByCondition({
|
|
const preData = await this.getAllDataByCondition({
|
|
- where: { phase_id: prePhase.id, audit_times: prePhase.audit_times, audit_order: audit_max_order },
|
|
|
|
|
|
+ where: { phase_id: prePhase.id, audit_times: prePhase.audit_times, audit_sort: audit_max_sort },
|
|
});
|
|
});
|
|
for (const pd of preData) {
|
|
for (const pd of preData) {
|
|
delete pd.id;
|
|
delete pd.id;
|
|
pd.audit_times = 1;
|
|
pd.audit_times = 1;
|
|
- pd.audit_order = 0;
|
|
|
|
|
|
+ pd.audit_sort = 0;
|
|
}
|
|
}
|
|
await conn.insert(this.tableName, preData);
|
|
await conn.insert(this.tableName, preData);
|
|
}
|
|
}
|
|
|
|
|
|
- async initPhaseDataByAudit(conn, phasePay, newTimes, newOrder) {
|
|
|
|
- const preData = await this.getAllDataByCondition({
|
|
|
|
- where: { phase_id: prePhase.id, audit_times: phasePay.curTimes, audit_order: phasePay.curOrder },
|
|
|
|
- });
|
|
|
|
|
|
+ async initPhaseDataByAudit(conn, phasePay, newTimes, newSort) {
|
|
|
|
+ const preData = await this.getDetailData(phasePay);
|
|
for (const pd of preData) {
|
|
for (const pd of preData) {
|
|
delete pd.id;
|
|
delete pd.id;
|
|
|
|
+ pd.master_id = `${phasePay.id}-${newTimes}-${newSort}`;
|
|
pd.audit_times = newTimes;
|
|
pd.audit_times = newTimes;
|
|
- pd.audit_order = newOrder;
|
|
|
|
|
|
+ pd.audit_sort = newSort;
|
|
}
|
|
}
|
|
await conn.insert(this.tableName, preData);
|
|
await conn.insert(this.tableName, preData);
|
|
}
|
|
}
|
|
@@ -375,11 +381,7 @@ class PhasePayDetail extends TreeService {
|
|
}
|
|
}
|
|
|
|
|
|
async getDetailData(phasePay) {
|
|
async getDetailData(phasePay) {
|
|
- if (phasePay.curTimes) {
|
|
|
|
- return await this.getAllDataByCondition({ where: { phase_id: phasePay.id, audit_times: phasePay.curTimes, audit_sort: phasePay.curOrder } });
|
|
|
|
- } else {
|
|
|
|
- return await this.getAllDataByCondition({ where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_sort: phasePay.audit_max_order } });
|
|
|
|
- }
|
|
|
|
|
|
+ return await this.getAllDataByCondition({ where: { master_id: this.getMasterKey(phasePay)} });
|
|
}
|
|
}
|
|
calculate(phasePay, details) {
|
|
calculate(phasePay, details) {
|
|
const payTree = new Ledger.baseTree(this.ctx, {
|
|
const payTree = new Ledger.baseTree(this.ctx, {
|
|
@@ -417,6 +419,9 @@ class PhasePayDetail extends TreeService {
|
|
data.phase_id = phasePay.id;
|
|
data.phase_id = phasePay.id;
|
|
data.create_user_id = this.ctx.session.sessionUser.accountId;
|
|
data.create_user_id = this.ctx.session.sessionUser.accountId;
|
|
data.update_user_id = this.ctx.session.sessionUser.accountId;
|
|
data.update_user_id = this.ctx.session.sessionUser.accountId;
|
|
|
|
+ data.audit_times = phasePay.audit_times;
|
|
|
|
+ data.audit_sort = phasePay.audit_max_sort;
|
|
|
|
+ data.master_id = this.getMasterKey(phasePay);
|
|
if (parent) {
|
|
if (parent) {
|
|
data.is_minus = parent.is_minus;
|
|
data.is_minus = parent.is_minus;
|
|
}
|
|
}
|
|
@@ -426,10 +431,11 @@ class PhasePayDetail extends TreeService {
|
|
if (select.payType === payType.bqsf || select.payType === payType.bqyf) throw '不可新增子项';
|
|
if (select.payType === payType.bqsf || select.payType === payType.bqyf) throw '不可新增子项';
|
|
if (select.tree_level >= 2) throw '不可新增子项';
|
|
if (select.tree_level >= 2) throw '不可新增子项';
|
|
|
|
|
|
- const children = await this.getChildrenByParentId(phasePay.id, select[this.setting.kid]);
|
|
|
|
- const maxId = await this._getMaxLid(phasePay.id);
|
|
|
|
|
|
+ const masterId = this.getMasterKey(phasePay);
|
|
|
|
+ const children = await this.getChildrenByParentId(masterId, select[this.setting.kid]);
|
|
|
|
+ const maxId = await this._getMaxLid(masterId);
|
|
const insertData = [];
|
|
const insertData = [];
|
|
- for (let i = 0; i < count; i++) {
|
|
|
|
|
|
+ for (let i = 1; i <= count ; i++) {
|
|
const data = {
|
|
const data = {
|
|
tree_id: maxId + i, tree_pid: select.tree_id, tree_order: children.length + 1 + i,
|
|
tree_id: maxId + i, tree_pid: select.tree_id, tree_order: children.length + 1 + i,
|
|
tree_level: select.tree_level + 1, tree_is_leaf: 1
|
|
tree_level: select.tree_level + 1, tree_is_leaf: 1
|
|
@@ -450,21 +456,22 @@ class PhasePayDetail extends TreeService {
|
|
conn.rollback();
|
|
conn.rollback();
|
|
throw err;
|
|
throw err;
|
|
}
|
|
}
|
|
- this._cacheMaxLid(phasePay.id, maxId + 1);
|
|
|
|
|
|
+ this._cacheMaxLid(masterId, maxId + 1);
|
|
|
|
|
|
// 查询应返回的结果
|
|
// 查询应返回的结果
|
|
const resultData = {};
|
|
const resultData = {};
|
|
- resultData.create = await this.getNextsData(phasePay.id, data[0].tree_id, children.length);
|
|
|
|
- if (children.length === 0) resultData.update = await this.getDataByKid(phasePay.id, select.tree_id);
|
|
|
|
|
|
+ resultData.create = await this.getNextsData(masterId, select.tree_id, children.length);
|
|
|
|
+ if (children.length === 0) resultData.update = await this.getDataByKid(masterId, select.tree_id);
|
|
return resultData;
|
|
return resultData;
|
|
}
|
|
}
|
|
|
|
|
|
async addNext(phasePay, select, count = 1) {
|
|
async addNext(phasePay, select, count = 1) {
|
|
|
|
+ const masterId = this.getMasterKey(phasePay);
|
|
this.transaction = await this.db.beginTransaction();
|
|
this.transaction = await this.db.beginTransaction();
|
|
try {
|
|
try {
|
|
- if (select) await this._updateChildrenOrder(phasePay.id, select[this.setting.pid], select[this.setting.order] + 1, count);
|
|
|
|
|
|
+ if (select) await this._updateChildrenOrder(masterId, select[this.setting.pid], select[this.setting.order] + 1, count);
|
|
const newDatas = [];
|
|
const newDatas = [];
|
|
- const maxId = await this._getMaxLid(phasePay.id);
|
|
|
|
|
|
+ const maxId = await this._getMaxLid(masterId);
|
|
for (let i = 1; i < count + 1; i++) {
|
|
for (let i = 1; i < count + 1; i++) {
|
|
const newData = {};
|
|
const newData = {};
|
|
newData[this.setting.kid] = maxId + i;
|
|
newData[this.setting.kid] = maxId + i;
|
|
@@ -479,7 +486,7 @@ class PhasePayDetail extends TreeService {
|
|
newDatas.push(newData);
|
|
newDatas.push(newData);
|
|
}
|
|
}
|
|
const insertResult = await this.transaction.insert(this.tableName, newDatas);
|
|
const insertResult = await this.transaction.insert(this.tableName, newDatas);
|
|
- this._cacheMaxLid(phasePay.id, maxId + count);
|
|
|
|
|
|
+ this._cacheMaxLid(masterId, maxId + count);
|
|
|
|
|
|
if (insertResult.affectedRows !== count) throw '新增节点数据错误';
|
|
if (insertResult.affectedRows !== count) throw '新增节点数据错误';
|
|
await this.transaction.commit();
|
|
await this.transaction.commit();
|
|
@@ -491,11 +498,11 @@ class PhasePayDetail extends TreeService {
|
|
}
|
|
}
|
|
|
|
|
|
if (select) {
|
|
if (select) {
|
|
- const createData = await this.getChildBetween(phasePay.id, select[this.setting.pid], select[this.setting.order], select[this.setting.order] + count + 1);
|
|
|
|
- const updateData = await this.getNextsData(phasePay.id, select[this.setting.pid], select[this.setting.order] + count);
|
|
|
|
|
|
+ const createData = await this.getChildBetween(masterId, select[this.setting.pid], select[this.setting.order], select[this.setting.order] + count + 1);
|
|
|
|
+ const updateData = await this.getNextsData(masterId, select[this.setting.pid], select[this.setting.order] + count);
|
|
return {create: createData, update: updateData};
|
|
return {create: createData, update: updateData};
|
|
} else {
|
|
} else {
|
|
- const createData = await this.getChildBetween(phasePay.id, -1, 0, count + 1);
|
|
|
|
|
|
+ const createData = await this.getChildBetween(masterId, -1, 0, count + 1);
|
|
return {create: createData};
|
|
return {create: createData};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -503,7 +510,7 @@ class PhasePayDetail extends TreeService {
|
|
async addDetailNode(phasePay, targetId, count = 1) {
|
|
async addDetailNode(phasePay, targetId, count = 1) {
|
|
if (!phasePay) return null;
|
|
if (!phasePay) return null;
|
|
|
|
|
|
- const select = targetId ? await this.getDataByKid(phasePay.id, targetId) : null;
|
|
|
|
|
|
+ const select = targetId ? await this.getDataByKid(this.getMasterKey(phasePay), targetId) : null;
|
|
if (targetId && !select) throw '新增节点数据错误';
|
|
if (targetId && !select) throw '新增节点数据错误';
|
|
|
|
|
|
if (select[this.setting.level] === 1) {
|
|
if (select[this.setting.level] === 1) {
|
|
@@ -512,6 +519,48 @@ class PhasePayDetail extends TreeService {
|
|
return await this.addNext(phasePay, select, count);
|
|
return await this.addNext(phasePay, select, count);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async upMoveDetailNode(phasePay, targetId, count = 1) {
|
|
|
|
+ const masterId = this.getMasterKey(phasePay);
|
|
|
|
+ await this.upMoveNode(masterId, targetId, count);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async downMoveDetailNode(phasePay, targetId, count = 1) {
|
|
|
|
+ const masterId = this.getMasterKey(phasePay);
|
|
|
|
+ await this.downMoveNode(masterId, targetId, count);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async deleteDetailNode(phasePay, targetId, count = 1) {
|
|
|
|
+ const masterId = this.getMasterKey(phasePay);
|
|
|
|
+ await this.delete(masterId, targetId, count);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _filterValidField(id, data) {
|
|
|
|
+ const ud = { id };
|
|
|
|
+ for (const prop in data) {
|
|
|
|
+ if (validField.indexOf(prop) >= 0) ud[prop] = data[prop]
|
|
|
|
+ }
|
|
|
|
+ return ud;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async updateDetail(phasePay, data) {
|
|
|
|
+ const masterId = this.getMasterKey(phasePay);
|
|
|
|
+ if (Array.isArray(data)) {
|
|
|
|
+ const orgData = this.getDataByCondition({ where: { id: data.map(d => { return d.id; }) } });
|
|
|
|
+ const updateDatas = [];
|
|
|
|
+ for (const d of data) {
|
|
|
|
+ const node = orgData.find(x => { return x.id === d.id; });
|
|
|
|
+ if (!node || masterId !== node[this.setting.mid]) throw '提交数据错误';
|
|
|
|
+ updateDatas.push(this._filterValidField(node.id, d));
|
|
|
|
+ }
|
|
|
|
+ await this.db.updateRows(this.tableName, updateDatas);
|
|
|
|
+ } else {
|
|
|
|
+ const node = await this.getDataById(data.id);
|
|
|
|
+ if (!node || masterId !== node[this.setting.mid]) throw '提交数据错误';
|
|
|
|
+ const updateData = this._filterValidField(node.id, data);
|
|
|
|
+ await this.db.update(this.tableName, updateData);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = PhasePayDetail;
|
|
module.exports = PhasePayDetail;
|