|
@@ -31,7 +31,11 @@ module.exports = app => {
|
|
|
_analysisTenderCache(tender, cache, uid) {
|
|
|
commonField.forEach(f => { tender[f] = cache[f]; });
|
|
|
tender.ledger_tp = cache.ledger_tp ? JSON.parse(cache.ledger_tp) : {};
|
|
|
- if (!cache.stage_count || (cache.stage_count === 1 && cache.stage_status === auditConst.stage.status.uncheck && cache.stage_flow_cur_uid !== uid)) {
|
|
|
+
|
|
|
+ uid = uid + '';
|
|
|
+ cache.stage_flow_cur_uid = cache.stage_flow_cur_uid ? cache.stage_flow_cur_uid.split(',') : [];
|
|
|
+ cache.stage_flow_pre_uid = cache.stage_flow_pre_uid ? cache.stage_flow_pre_uid.split(',') : [];
|
|
|
+ if (!cache.stage_count || (cache.stage_count === 1 && cache.stage_status === auditConst.stage.status.uncheck && cache.stage_flow_cur_uid.indexOf(uid) < 0)) {
|
|
|
tender.cur_flow = JSON.parse(cache.ledger_flow_cur_info || cache.ledger_flow_pre_info);
|
|
|
tender.cur_flow.title = '台账';
|
|
|
tender.pre_flow = cache.ledger_flow_pre_info ? JSON.parse(cache.ledger_flow_pre_info) : null;
|
|
@@ -41,7 +45,7 @@ module.exports = app => {
|
|
|
status: auditConst.ledger.tiStatusString[cache.ledger_status],
|
|
|
status_class: auditConst.ledger.tiStatusStringClass[cache.ledger_status],
|
|
|
};
|
|
|
- } else if (cache.stage_status !== auditConst.stage.status.uncheck || cache.stage_flow_cur_uid === uid) {
|
|
|
+ } else if (cache.stage_status !== auditConst.stage.status.uncheck || cache.stage_flow_cur_uid.indexOf(uid) >= 0) {
|
|
|
tender.stage_status = cache.stage_status;
|
|
|
tender.stage_count = tender.stage_count;
|
|
|
tender.stage_complete_count = tender.stage_complete_count;
|
|
@@ -59,7 +63,7 @@ module.exports = app => {
|
|
|
tender.stage_status = auditConst.stage.status.checked;
|
|
|
tender.stage_count = tender.stage_complete_count;
|
|
|
tender.stage_complete_count = tender.stage_complete_count;
|
|
|
- tender.cur_flow = (cache.stage_status !== auditConst.stage.status.uncheck || cache.stage_flow_cur_uid !== uid)
|
|
|
+ tender.cur_flow = (cache.stage_status !== auditConst.stage.status.uncheck || cache.stage_flow_cur_uid.indexOf(uid) < 0)
|
|
|
? JSON.parse(cache.stage_flow_pre_info) : JSON.parse(cache.stage_flow_cur_info || cache.stage_flow_pre_info);
|
|
|
tender.pre_flow = cache.stage_flow_pre_info ? JSON.parse(cache.stage_flow_pre_info) : null;
|
|
|
tender.stage_tp = cache.stage_flow_pre_tp ? JSON.parse(cache.stage_flow_pre_tp) : {};
|
|
@@ -114,12 +118,12 @@ module.exports = app => {
|
|
|
|
|
|
async updateLedgerCache(transaction, tid, status, checkType, next, tp) {
|
|
|
const orgCache = await this.getDataById(tid);
|
|
|
- const preInfo = JSON.parse(orgCache.ledger_flow_cur_info);
|
|
|
+ const preInfo = JSON.parse(orgCache.ledger_flow_cur_info || orgCache.ledger_flow_pre_info);
|
|
|
preInfo.time = new Date();
|
|
|
preInfo.status = checkType;
|
|
|
const data = {
|
|
|
id: tid, ledger_status: status,
|
|
|
- ledger_flow_pre_uid: orgCache.ledger_flow_cur_uid, ledger_flow_pre_info: JSON.stringify(preInfo),
|
|
|
+ ledger_flow_pre_uid: orgCache.ledger_flow_cur_uid || orgCache.ledger_flow_pre_uid, ledger_flow_pre_info: JSON.stringify(preInfo),
|
|
|
};
|
|
|
if (next) {
|
|
|
const info = await this.ctx.service.projectAccount.getAccountCacheData(next.audit_id);
|
|
@@ -165,15 +169,15 @@ module.exports = app => {
|
|
|
pre_positive_qc_tp: preStage.pre_positive_qc_tp, pre_negative_qc_tp: preStage.pre_positive_qc_tp,
|
|
|
pre_yf_tp: preStage.pre_yf_tp, pre_sf_tp: preStage.pre_sf_tp,
|
|
|
});
|
|
|
- const auditor = await this.ctx.service.stageAudit.getLastestAuditor(preStage.id, preStage.times, preStage.status);
|
|
|
- const user_info = JSON.stringify({
|
|
|
- order: preStage.order, status: preStage.status, time: auditor.end_time,
|
|
|
+ const auditors = await this.ctx.service.stageAudit.getLastestAuditors(preStage.id, preStage.times, preStage.status);
|
|
|
+ const user_info = auditors.length > 0 ? JSON.stringify(auditors.map(auditor => { return {
|
|
|
+ order: preStage.order, status: preStage.status, time: auditor.end_time, audit_order: auditor.audit_order,
|
|
|
name: auditor.name, company: auditor.company, role: auditor.role, mobile: auditor.mobile, telephone: auditor.telephone,
|
|
|
- });
|
|
|
+ }})) : '';
|
|
|
await transaction.update(this.tableName, {
|
|
|
id: delStage.tid, stage_count: preStage.order, stage_complete_count: preStage.order, stage_status: preStage.status,
|
|
|
stage_flow_cur_uid: 0, stage_flow_cur_info: '', stage_flow_cur_tp: '',
|
|
|
- stage_flow_pre_uid: auditor.aid, stage_flow_pre_info: user_info, stage_flow_pre_tp: tp,
|
|
|
+ stage_flow_pre_uid: auditors.map(x => { return x.aid; }).join(','), stage_flow_pre_info: user_info, stage_flow_pre_tp: tp,
|
|
|
});
|
|
|
} else {
|
|
|
await transaction.update(this.tableName, {
|
|
@@ -184,7 +188,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async updateStageCache4Start(transaction, stage, status, auditor, ledgerTp, stageTp) {
|
|
|
+ async updateStageCache4Start(transaction, stage, status, auditors, ledgerTp, stageTp) {
|
|
|
const orgCache = await this.getDataById(stage.tid);
|
|
|
const data = { id: stage.tid, stage_status: status };
|
|
|
if (ledgerTp) data.ledger_tp = JSON.stringify(ledgerTp);
|
|
@@ -196,42 +200,41 @@ module.exports = app => {
|
|
|
data.stage_flow_pre_info = JSON.stringify(info);
|
|
|
data.stage_flow_pre_tp = JSON.stringify(tp);
|
|
|
|
|
|
- data.stage_flow_cur_uid = auditor.aid;
|
|
|
- const cur_flow_info = await this.ctx.service.projectAccount.getAccountCacheData(auditor.aid);
|
|
|
- cur_flow_info.order = stage.order;
|
|
|
- cur_flow_info.status = auditConst.stage.status.checking;
|
|
|
+ const auditIds = auditors.map(x => { return x.aid; });
|
|
|
+ data.stage_flow_cur_uid = auditIds.join(',');
|
|
|
+ const cur_flow_info = await this.ctx.service.projectAccount.getAccountCacheDatas(auditIds,
|
|
|
+ {order: stage.order, audit_type: auditors[0].audit_type, audit_order: 1, status: auditConst.stage.status.checking});
|
|
|
data.stage_flow_cur_info = JSON.stringify(cur_flow_info);
|
|
|
data.stage_flow_cur_tp = JSON.stringify(tp);
|
|
|
await transaction.update(this.tableName, data);
|
|
|
}
|
|
|
|
|
|
- async updateStageCache4Flow(transaction, stage, status, auditor, preAuditor, ledgerTp, stageTp, pcTp) {
|
|
|
+ async updateStageCache4Flow(transaction, stage, status, auditors, preAuditors, ledgerTp, stageTp, pcTp) {
|
|
|
const orgCache = await this.getDataById(stage.tid);
|
|
|
const data = { id: stage.tid, stage_status: status };
|
|
|
if (ledgerTp) data.ledger_tp = JSON.stringify(ledgerTp);
|
|
|
const tp = orgCache.stage_flow_cur_tp ? JSON.parse(orgCache.stage_flow_cur_tp) : (orgCache.stage_flow_pre_tp ? JSON.parse(orgCache.stage_flow_pre_tp) : {});
|
|
|
if (stageTp) this._.assign(tp, stageTp);
|
|
|
if (pcTp) this._.assign(tp, pcTp);
|
|
|
- if (preAuditor) {
|
|
|
- data.stage_flow_pre_uid = preAuditor.aid;
|
|
|
- const info = await this.ctx.service.projectAccount.getAccountCacheData(preAuditor.aid);
|
|
|
- info.order = preAuditor.order;
|
|
|
- info.status = preAuditor.status;
|
|
|
- info.time = new Date();
|
|
|
- data.stage_flow_pre_info = JSON.stringify(info);
|
|
|
+ if (preAuditors && preAuditors.length > 0) {
|
|
|
+ const preAuditorIds = preAuditors.map(x => { return x.aid; });
|
|
|
+ data.stage_flow_pre_uid = preAuditorIds.join(',');
|
|
|
+ const info = await this.ctx.service.projectAccount.getAccountCacheDatas(preAuditorIds,
|
|
|
+ { order: stage.order, status: preAuditors[0].status, audit_type:preAuditors[0].audit_type, audit_order: preAuditors[0].audit_order, time: new Date() });
|
|
|
+ data.stage_flow_pre_info = info.length > 0 ? JSON.stringify(info) : '';
|
|
|
} else {
|
|
|
data.stage_flow_pre_uid = orgCache.stage_flow_cur_uid;
|
|
|
data.stage_flow_pre_info = orgCache.stage_flow_cur_info;
|
|
|
}
|
|
|
data.stage_flow_pre_tp = JSON.stringify(tp);
|
|
|
- if (auditor) {
|
|
|
- data.stage_flow_cur_uid = auditor.aid;
|
|
|
- const info = await this.ctx.service.projectAccount.getAccountCacheData(auditor.aid);
|
|
|
- info.order = auditor.order;
|
|
|
- info.status = status;
|
|
|
- data.stage_flow_cur_info = JSON.stringify(info);
|
|
|
+
|
|
|
+ if (auditors && auditors.length > 0) {
|
|
|
+ const auditorIds = auditors.map(x => { return x.aid; });
|
|
|
+ data.stage_flow_cur_uid = auditorIds.join(',');
|
|
|
+ const info = await this.ctx.service.projectAccount.getAccountCacheDatas(auditorIds, { order: stage.order, audit_type: auditors[0].audit_type, status, audit_order: auditors[0].audit_order });
|
|
|
+ data.stage_flow_cur_info = info.length > 0 ? JSON.stringify(info) : '';
|
|
|
}
|
|
|
- if (status === auditConst.stage.status.checked && !auditor) data.stage_complete_count = stage.order;
|
|
|
+ if (status === auditConst.stage.status.checked && (!auditors || auditors.length === 0)) data.stage_complete_count = stage.order;
|
|
|
data.stage_flow_cur_tp = JSON.stringify(tp);
|
|
|
await transaction.update(this.tableName, data);
|
|
|
}
|
|
@@ -362,12 +365,13 @@ module.exports = app => {
|
|
|
const preStage = lastStage.order > 1 ? await this.ctx.service.stage.getDataByCondition({ tid: lastStage.tid, order: lastStage.order - 1}) : null;
|
|
|
if (lastStage.status === auditConst.stage.status.uncheck) {
|
|
|
if (preStage) {
|
|
|
- const preAuditor = await this.ctx.service.stageAudit.getLastestAuditor(preStage.id, preStage.times, preStage.status);
|
|
|
- data.stage_flow_pre_uid = preAuditor.aid;
|
|
|
- data.stage_flow_pre_info = JSON.stringify({
|
|
|
- order: preAuditor.order, status: preAuditor.status, time: preAuditor.end_time,
|
|
|
+ const preAuditors = await this.ctx.service.stageAudit.getLastestAuditors(preStage.id, preStage.times, preStage.status);
|
|
|
+ const preAuditorIds = preAuditors.map(x => { return x.aid; });
|
|
|
+ data.stage_flow_pre_uid = preAuditorIds.join(',');
|
|
|
+ data.stage_flow_pre_info = preAuditors.length > 0 ? JSON.stringify(preAuditors.map(preAuditor => { return {
|
|
|
+ order: preAuditor.order, audit_type: preAuditor.audit_type, audit_order: preAuditor.order, status: preAuditor.status, time: preAuditor.end_time,
|
|
|
name: preAuditor.name, company: preAuditor.company, role: preAuditor.role, mobile: preAuditor.mobile, telephone: preAuditor.telephone,
|
|
|
- });
|
|
|
+ }})) : '';
|
|
|
data.stage_flow_pre_tp = JSON.stringify({
|
|
|
contract_tp: preStage.contract_tp || 0, qc_tp: preStage.qc_tp || 0, contract_pc_tp: preStage.contract_pc_tp, qc_pc_tp: preStage.qc_pc_tp, pc_tp: preStage.pc_tp,
|
|
|
positive_qc_tp: preStage.positive_qc_tp, positive_qc_pc_tp: preStage.positive_qc_pc_tp, negative_qc_tp: preStage.negative_qc_pc_tp, negative_qc_pc_tp: preStage.negative_qc_pc_tp,
|
|
@@ -380,34 +384,37 @@ module.exports = app => {
|
|
|
lastStage.curOrder = 0;
|
|
|
await this._calcTp(lastStage, tp);
|
|
|
data.stage_flow_cur_uid = lastStage.user_id;
|
|
|
- const curInfo = await this.ctx.service.projectAccount.getAccountCacheData(lastStage.user_id, { order: 0, status: lastStage.status });
|
|
|
+ const curInfo = await this.ctx.service.projectAccount.getAccountCacheData(lastStage.user_id, { order: lastStage.order, audit_order: 0, audit_type: auditConst.auditType.key.common, status: lastStage.status });
|
|
|
data.stage_flow_cur_info = JSON.stringify(curInfo);
|
|
|
data.stage_flow_cur_tp = JSON.stringify(tp);
|
|
|
} else if (lastStage.status === auditConst.stage.status.checked) {
|
|
|
- const preAuditor = await this.ctx.service.stageAudit.getLastestAuditor(lastStage.id, lastStage.times, lastStage.status);
|
|
|
- lastStage.curOrder = preAuditor.order;
|
|
|
+ const preAuditors = await this.ctx.service.stageAudit.getLastestAuditors(lastStage.id, lastStage.times, lastStage.status);
|
|
|
+ const preAuditorIds = preAuditors.map(x => { return x.aid; });
|
|
|
+ lastStage.curOrder = preAuditors[0].order;
|
|
|
await this._calcTp(lastStage, tp);
|
|
|
- data.stage_flow_pre_uid = preAuditor.aid;
|
|
|
- data.stage_flow_pre_info = JSON.stringify({
|
|
|
- order: preAuditor.order, status: preAuditor.status, time: preAuditor.end_time,
|
|
|
+ data.stage_flow_pre_uid = preAuditorIds.join(',');
|
|
|
+ data.stage_flow_pre_info = preAuditors.length > 0 ? JSON.stringify(preAuditors.map(preAuditor => { return {
|
|
|
+ order: lastStage.order, audit_type: preAuditor.audit_type, audit_order: preAuditor.order, status: preAuditor.status, time: preAuditor.end_time,
|
|
|
name: preAuditor.name, company: preAuditor.company, role: preAuditor.role, mobile: preAuditor.mobile, telephone: preAuditor.telephone,
|
|
|
- });
|
|
|
+ }})) : '';
|
|
|
data.stage_flow_cur_tp = JSON.stringify(tp);
|
|
|
data.stage_flow_pre_tp = JSON.stringify(tp);
|
|
|
} else if (lastStage.status === auditConst.stage.status.checkNo) {
|
|
|
lastStage.curOrder = 0;
|
|
|
await this._calcTp(lastStage, tp);
|
|
|
data.stage_flow_cur_uid = lastStage.user_id;
|
|
|
- const curInfo = await this.ctx.service.projectAccount.getAccountCacheData(lastStage.user_id, { order: 0, status: auditConst.stage.status.uncheck });
|
|
|
+ const curInfo = await this.ctx.service.projectAccount.getAccountCacheData(lastStage.user_id,
|
|
|
+ { order: lastStage.order, audit_order: 0, audit_type: auditConst.auditType.key.common, status: auditConst.stage.status.uncheck });
|
|
|
data.stage_flow_cur_info = JSON.stringify(curInfo);
|
|
|
data.stage_flow_cur_tp = JSON.stringify(tp);
|
|
|
- const preAuditor = await this.ctx.service.stageAudit.getLastestAuditor(lastStage.id, lastStage.times - 1, lastStage.status);
|
|
|
- data.stage_flow_pre_uid = preAuditor.aid;
|
|
|
- data.stage_flow_pre_info = JSON.stringify({
|
|
|
- order: preAuditor.order, status: preAuditor.status, time: preAuditor.end_time,
|
|
|
+ const preAuditors = await this.ctx.service.stageAudit.getLastestAuditors(lastStage.id, lastStage.times - 1, lastStage.status);
|
|
|
+ const preAuditorIds = preAuditors.map(x => { return x.aid; });
|
|
|
+ data.stage_flow_pre_uid = preAuditorIds.join(',');
|
|
|
+ data.stage_flow_pre_info = preAuditors.length > 0 ? JSON.stringify(preAuditors.map(preAuditor => { return {
|
|
|
+ order: lastStage.order, audit_type: preAuditor.audit_type, audit_order: preAuditor.order, status: preAuditor.status, time: preAuditor.end_time,
|
|
|
name: preAuditor.name, company: preAuditor.company, role: preAuditor.role, mobile: preAuditor.mobile, telephone: preAuditor.telephone,
|
|
|
- });
|
|
|
- const his = lastStage.tp_history.find(x => { return x.times === preAuditor.times && x.order === preAuditor.order; });
|
|
|
+ }})) : '';
|
|
|
+ const his = lastStage.tp_history.find(x => { return x.times === preAuditors[0].times && x.order === preAuditors[0].order; });
|
|
|
if (his) {
|
|
|
tp.contract_tp = his.contract_tp;
|
|
|
tp.qc_tp = his.qc_tp;
|
|
@@ -418,29 +425,32 @@ module.exports = app => {
|
|
|
}
|
|
|
data.stage_flow_pre_tp = JSON.stringify(tp);
|
|
|
} else {
|
|
|
- const curAuditor = await this.ctx.service.stageAudit.getLastestAuditor(lastStage.id, lastStage.times, lastStage.status);
|
|
|
- lastStage.curOrder = curAuditor.order;
|
|
|
+ const curAuditors = await this.ctx.service.stageAudit.getLastestAuditors(lastStage.id, lastStage.times, lastStage.status);
|
|
|
+ const curAuditorIds = curAuditors.map(x => { return x.aid; });
|
|
|
+ lastStage.curOrder = curAuditors[0].order;
|
|
|
await this._calcTp(lastStage, tp);
|
|
|
- data.stage_flow_cur_uid = curAuditor.aid;
|
|
|
- data.stage_flow_cur_info = JSON.stringify({
|
|
|
- order: curAuditor.order, status: curAuditor.status,
|
|
|
+ data.stage_flow_cur_uid = curAuditorIds.join(',');
|
|
|
+ data.stage_flow_cur_info = JSON.stringify(curAuditors.map(curAuditor => { return {
|
|
|
+ order: lastStage.order, audit_order: curAuditor.order, status: curAuditor.status,
|
|
|
name: curAuditor.name, company: curAuditor.company, role: curAuditor.role, mobile: curAuditor.mobile, telephone: curAuditor.telephone,
|
|
|
- });
|
|
|
+ }}));
|
|
|
data.stage_flow_cur_tp = JSON.stringify(tp);
|
|
|
- const preAuditor = curAuditor.order > 1 ? await this.ctx.service.stageAudit.getAuditorByOrder(lastStage.id, lastStage.times, curAuditor.order - 1) : null;
|
|
|
- if (preAuditor) {
|
|
|
- data.stage_flow_pre_uid = preAuditor.aid;
|
|
|
- data.stage_flow_pre_info = JSON.stringify({
|
|
|
- order: preAuditor.order, status: preAuditor.status, time: curAuditor.begin_time,
|
|
|
+ const preAuditors = lastStage.curOrder > 1 ? await this.ctx.service.stageAudit.getAuditorsByOrder(lastStage.id, lastStage.times, lastStage.curOrder - 1) : [];
|
|
|
+ if (preAuditors.length > 0) {
|
|
|
+ const preAuditorIds = preAuditors.map(x => { return x.aid; });
|
|
|
+ data.stage_flow_pre_uid = preAuditorIds.join(',');
|
|
|
+ data.stage_flow_pre_info = JSON.stringify(preAuditors.map(preAuditor => { return {
|
|
|
+ order: lastStage.order, audit_type: preAuditor.audit_type, audit_order: preAuditor.audit_order, status: preAuditor.status, time: preAuditor.end_time,
|
|
|
name: preAuditor.name, company: preAuditor.company, role: preAuditor.role, mobile: preAuditor.mobile, telephone: preAuditor.telephone,
|
|
|
- });
|
|
|
+ }}));
|
|
|
} else {
|
|
|
data.stage_flow_pre_uid = lastStage.user_id;
|
|
|
- const preInfo = await this.ctx.service.projectAccount.getAccountCacheData(lastStage.user_id, { order: 0, status: auditConst.stage.status.uncheck, time: curAuditor.begin_time });
|
|
|
+ const preInfo = await this.ctx.service.projectAccount.getAccountCacheData(lastStage.user_id,
|
|
|
+ { order: lastStage.order, audit_order: 0, audit_type: 1, status: auditConst.stage.status.uncheck, time: curAuditors[0].begin_time });
|
|
|
data.stage_flow_pre_info = JSON.stringify(preInfo);
|
|
|
}
|
|
|
- const his = preAuditor
|
|
|
- ? lastStage.tp_history.find(x => { return x.times === preAuditor.times && x.order === preAuditor.order; })
|
|
|
+ const his = preAuditors.length > 0
|
|
|
+ ? lastStage.tp_history.find(x => { return x.times === preAuditors[0].times && x.order === preAuditors[0].order; })
|
|
|
: lastStage.tp_history.find(x => { return x.times === lastStage.times && x.order === 0; });
|
|
|
if (his) {
|
|
|
tp.contract_tp = his.contract_tp;
|