|
@@ -42,7 +42,7 @@ module.exports = app => {
|
|
|
async getAuditor(materialId, auditorId, times = 1) {
|
|
|
const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
|
|
|
' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
|
|
|
- ' WHERE la.`mid` = ? and la.`aid` = ? and la.`times` = ?';
|
|
|
+ ' WHERE la.`mid` = ? and la.`aid` = ? and la.`times` = ? ORDER BY la.`order` DESC';
|
|
|
const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, materialId, auditorId, times];
|
|
|
return await this.db.queryOne(sql, sqlParam);
|
|
|
}
|
|
@@ -930,10 +930,16 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getAuditGroupByList(materialId, times) {
|
|
|
- const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tid`, la.`mid`, la.`aid`, la.`order`, la.`status`, la.audit_type, la.audit_order ' +
|
|
|
- ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
|
|
|
- ' WHERE la.`mid` = ? and la.`times` = ? GROUP BY la.`aid` ORDER BY la.`order`';
|
|
|
- const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, materialId, times];
|
|
|
+ // const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tid`, la.`mid`, la.`aid`, la.`order`, la.`status`, la.audit_type, la.audit_order ' +
|
|
|
+ // ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
|
|
|
+ // ' WHERE la.`mid` = ? and la.`times` = ? GROUP BY la.`aid` ORDER BY la.`order`';
|
|
|
+ // const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, materialId, times];
|
|
|
+ const sql =
|
|
|
+ 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`mid`, la.`order`, la.`status`, la.audit_type, la.audit_order ' +
|
|
|
+ ' FROM (SELECT `aid`, max(`order`) `order` FROM ?? WHERE `mid` = ? and `times` = ? and `is_old` = ? GROUP BY aid) sa' +
|
|
|
+ ' LEFT JOIN ?? la ON sa.`aid` = la.`aid` AND sa.`order` = la.`order`' +
|
|
|
+ ' Left JOIN ?? AS pa On la.`aid` = pa.`id` WHERE la.`mid` = ? and la.`times` = ? and la.`is_old` = ? order BY la.`order`';
|
|
|
+ const sqlParam = [this.tableName, materialId, times, 0, this.tableName, this.ctx.service.projectAccount.tableName, materialId, times, 0];
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
|
|
@@ -1209,6 +1215,14 @@ module.exports = app => {
|
|
|
const flowAuditors = auditors.filter(x => { return x.order === now_audit.order; });
|
|
|
await transaction.delete(this.tableName, { mid: materialId, times, aid: now_audit.aid, order: now_audit.order });
|
|
|
if (flowAuditors.length === 1) await this._syncOrderByDelete(transaction, materialId, now_audit.order, times);
|
|
|
+ // 旧的更新为is_old为1
|
|
|
+ await transaction.update(this.tableName, { is_old: 1 }, {
|
|
|
+ where: {
|
|
|
+ mid: materialId,
|
|
|
+ times,
|
|
|
+ aid: data.old_aid,
|
|
|
+ }
|
|
|
+ });
|
|
|
} else if (data.operate === 'change') {
|
|
|
const nowAudit = await this.getDataByCondition({ mid: materialId, times, aid: now_audit.aid, order: now_audit.order });
|
|
|
if (now_audit.status !== auditConst.status.uncheck || !nowAudit) {
|
|
@@ -1216,6 +1230,14 @@ module.exports = app => {
|
|
|
}
|
|
|
nowAudit.aid = data.new_aid;
|
|
|
await transaction.update(this.tableName, nowAudit);
|
|
|
+ // 旧的更新为is_old为1
|
|
|
+ await transaction.update(this.tableName, { is_old: 1 }, {
|
|
|
+ where: {
|
|
|
+ mid: materialId,
|
|
|
+ times,
|
|
|
+ aid: data.old_aid,
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
if (this.ctx.tender.info.shenpi.material === shenpiConst.sp_status.gdspl) {
|
|
|
const newAuditors = await transaction.select(this.tableName, { where: { mid: materialId, times } });
|