Forráskód Böngészése

优化部分查询语句

MaiXinRong 3 éve
szülő
commit
6fd3a84fd8

+ 12 - 18
app/service/advance_audit.js

@@ -22,8 +22,8 @@ module.exports = app => {
         async getAuditGroupByList(vid, times = 1) {
             const sql =
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`vid`, la.`order` ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`vid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` GROUP BY la.`audit_id` ORDER BY la.`order`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
+                '  WHERE la.`vid` = ? and la.`times` = ? GROUP BY la.`audit_id` ORDER BY la.`order`';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, vid, times];
             return await this.db.query(sql, sqlParam);
         }
@@ -38,12 +38,8 @@ module.exports = app => {
             const result = await this.getAuditGroupByList(vid, times);
             const sql =
                 'SELECT pa.`id` As audit_id, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As vid, 0 As `order`' +
-                '  FROM ' +
-                this.ctx.service.advance.tableName +
-                ' As s' +
-                '  LEFT JOIN ' +
-                this.ctx.service.projectAccount.tableName +
-                ' As pa' +
+                '  FROM ' + this.ctx.service.advance.tableName + ' As s' +
+                '  LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
                 '  ON s.uid = pa.id' +
                 '  WHERE s.id = ?';
             const sqlParam = [times, vid, vid];
@@ -164,9 +160,8 @@ module.exports = app => {
         async getCurAuditor(vid, times = 1) {
             const sql =
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`create_time`, la.`end_time` ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`vid` = ? and la.`status` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
+                '  WHERE la.`vid` = ? and la.`status` = ? and la.`times` = ?';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, vid, auditConst.status.checking, times];
             return await this.db.queryOne(sql, sqlParam);
         }
@@ -203,9 +198,8 @@ module.exports = app => {
         async getAuditor(vid, audit_id, times = 1) {
             const sql =
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`create_time`, la.`end_time` ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`vid` = ? and la.`audit_id` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
+                '  WHERE la.`vid` = ? and la.`audit_id` = ? and la.`times` = ?';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, vid, audit_id, times];
             return await this.db.queryOne(sql, sqlParam);
         }
@@ -537,16 +531,16 @@ module.exports = app => {
                 case auditConst.status.checkNoPre:
                     sql =
                         'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`vid`, la.`order` ' +
-                        'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`vid` = ? and la.`status` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`order` desc';
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
+                        '  WHERE la.`vid` = ? and la.`status` = ? order by la.`times` desc, la.`order` desc';
                     sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, vid, status];
                     auditor = await this.db.queryOne(sql, sqlParam);
                     break;
                 case auditConst.status.checkNo:
                     sql =
                         'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`vid`, la.`order` ' +
-                        'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`vid` = ? and la.`status` = ? and la.`times` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`order` desc';
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
+                        '  WHERE la.`vid` = ? and la.`status` = ? and la.`times` = ? order by la.`times` desc, la.`order` desc';
                     sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, vid, auditConst.status.checkNo, parseInt(times) - 1];
                     auditor = await this.db.queryOne(sql, sqlParam);
                     break;

+ 14 - 14
app/service/material_audit.js

@@ -37,9 +37,8 @@ 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, ?? AS pa ' +
-                'WHERE la.`mid` = ? and la.`aid` = ? and la.`times` = ?' +
-                '    and la.`aid` = pa.`id`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                '  WHERE la.`mid` = ? and la.`aid` = ? and la.`times` = ?';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, materialId, auditorId, times];
             return await this.db.queryOne(sql, sqlParam);
         }
@@ -69,8 +68,8 @@ module.exports = app => {
         async getFinalAuditGroup(materialId, times = 1) {
             const sql =
                 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, pa.`sign_path`, la.`times`, la.`mid`, Max(la.`order`) as max_order ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`mid` = ? and la.`times` = ? and la.`aid` = pa.`id` GROUP BY la.`aid` ORDER BY la.`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 result = await this.db.query(sql, sqlParam);
             for (const r of result) {
@@ -92,9 +91,8 @@ module.exports = app => {
          */
         async getCurAuditor(materialId, 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, ?? AS pa ' +
-                'WHERE la.`mid` = ? and la.`status` = ? and la.`times` = ?' +
-                '    and la.`aid` = pa.`id`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
+                '  WHERE la.`mid` = ? and la.`status` = ? and la.`times` = ?';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, materialId, auditConst.status.checking, times];
             return await this.db.queryOne(sql, sqlParam);
         }
@@ -782,8 +780,8 @@ module.exports = app => {
          */
         async getAuditGroupByList(materialId, times) {
             const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`mid`, la.`aid`, la.`order` ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`mid` = ? and la.`times` = ? and la.`aid` = pa.`id` GROUP BY la.`aid` ORDER BY la.`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];
             return await this.db.query(sql, sqlParam);
         }
@@ -855,15 +853,17 @@ module.exports = app => {
                 case auditConst.status.checked :
                 case auditConst.status.checkNoPre :
                     sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`mid`, la.`aid`, la.`order` ' +
-                        'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`mid` = ? and la.`status` = ? and la.`aid` = pa.`id` order by la.`times` desc, la.`order` desc';
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
+                        '  WHERE la.`mid` = ? and la.`status` = ? ' +
+                        '  ORDER BY la.`times` desc, la.`order` desc';
                     sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, materialId, status];
                     auditor = await this.db.queryOne(sql, sqlParam);
                     break;
                 case auditConst.status.checkNo :
                     sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`mid`, la.`aid`, la.`order` ' +
-                        'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`mid` = ? and la.`status` = ? and la.`times` = ? and la.`aid` = pa.`id` order by la.`times` desc, la.`order` desc';
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                        '  WHERE la.`mid` = ? and la.`status` = ? and la.`times` = ?' +
+                        '  ORDER BY la.`times` desc, la.`order` desc';
                     sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, materialId, auditConst.status.checkNo, parseInt(times) - 1];
                     auditor = await this.db.queryOne(sql, sqlParam);
                     break;

+ 14 - 23
app/service/revise_audit.js

@@ -39,9 +39,8 @@ module.exports = app => {
         async getAuditor(reviseId, auditorId, times = 1) {
             const sql =
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`rid` = ? and la.`audit_id` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
+                '  WHERE la.`rid` = ? and la.`audit_id` = ? and la.`times` = ?';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditorId, times];
             return await this.db.queryOne(sql, sqlParam);
         }
@@ -57,11 +56,8 @@ module.exports = app => {
             const sql =
                 'SELECT la.`audit_id`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`,' +
                 '    pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`' +
-                '  FROM ' +
-                this.tableName +
-                ' AS la ' +
-                '  INNER JOIN ' +
-                this.ctx.service.projectAccount.tableName +
+                '  FROM ' + this.tableName + ' AS la ' +
+                '  INNER JOIN ' + this.ctx.service.projectAccount.tableName +
                 ' AS pa ON la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id`' +
                 '  ORDER BY la.`audit_order`';
             const sqlParam = [reviseId, times];
@@ -101,9 +97,8 @@ module.exports = app => {
         async getCurAuditor(reviseId, times = 1) {
             const sql =
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
+                '  WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ?';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditConst.status.checking, times];
             return await this.db.queryOne(sql, sqlParam);
         }
@@ -686,16 +681,16 @@ module.exports = app => {
                 case auditConst.status.checkNoPre:
                     sql =
                         'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
-                        'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`rid` = ? and la.`status` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc';
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
+                        '  WHERE la.`rid` = ? and la.`status` = ? order by la.`times` desc, la.`audit_order` desc';
                     sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, status];
                     auditor = await this.db.queryOne(sql, sqlParam);
                     break;
                 case auditConst.status.checkNo:
                     sql =
                         'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
-                        'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc';
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
+                        '  WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ? order by la.`times` desc, la.`audit_order` desc';
                     sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, auditConst.status.checkNo, parseInt(times) - 1];
                     auditor = await this.db.queryOne(sql, sqlParam);
                     break;
@@ -715,8 +710,8 @@ module.exports = app => {
         async getAuditGroupByList(rid, times) {
             const sql =
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` GROUP BY la.`audit_id` ORDER BY la.`audit_order`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
+                '  WHERE la.`rid` = ? and la.`times` = ? GROUP BY la.`audit_id` ORDER BY la.`audit_order`';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, times];
             return await this.db.query(sql, sqlParam);
             // const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid`';
@@ -750,12 +745,8 @@ module.exports = app => {
 
         async getAllAuditors(tenderId) {
             const sql =
-                'SELECT ra.audit_id, ra.tender_id FROM ' +
-                this.tableName +
-                ' ra' +
-                '  LEFT JOIN ' +
-                this.ctx.service.tender.tableName +
-                ' t On ra.tender_id = t.id' +
+                'SELECT ra.audit_id, ra.tender_id FROM ' + this.tableName + ' ra' +
+                '  LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ra.tender_id = t.id' +
                 '  WHERE t.id = ?' +
                 '  GROUP BY ra.audit_id';
             const sqlParam = [tenderId];

+ 27 - 51
app/service/stage_audit.js

@@ -42,9 +42,8 @@ module.exports = app => {
         async getAuditor(stageId, 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, ?? AS pa ' +
-                'WHERE la.`sid` = ? and la.`aid` = ? and la.`times` = ?' +
-                '    and la.`aid` = pa.`id`';
+                'FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                'WHERE la.`sid` = ? and la.`aid` = ? and la.`times` = ?';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditorId, times];
             return await this.db.queryOne(sql, sqlParam);
         }
@@ -117,11 +116,8 @@ module.exports = app => {
          * @return {Promise<*>}
          */
         async getStatusName(stageId) {
-            const sql =
-                'SELECT pa.`name` ' +
-                'FROM ?? AS sa, ?? AS pa ' +
-                'WHERE sa.`sid` = ?' +
-                '    and sa.`aid` = pa.`id` and sa.`status` != ? ORDER BY sa.`times` DESC, sa.`order` DESC';
+            const sql = 'SELECT pa.`name` FROM ?? AS sa Left Join ?? AS pa On sa.`aid` = pa.`id`' +
+                '  WHERE sa.`sid` = ? and sa.`status` != ? ORDER BY sa.`times` DESC, sa.`order` DESC';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.uncheck];
             return await this.db.queryOne(sql, sqlParam);
         }
@@ -136,9 +132,8 @@ module.exports = app => {
         async getCurAuditor(stageId, 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, ?? AS pa ' +
-                'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ?' +
-                '    and la.`aid` = pa.`id`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                '  WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ?';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.checking, times];
             return await this.db.queryOne(sql, sqlParam);
         }
@@ -996,9 +991,11 @@ module.exports = app => {
                 'SELECT sa.`aid`, sa.`times`, sa.`order`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
                 '    s.`order` As `sorder`, s.`status` As `sstatus`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
-                '  FROM ?? AS sa, ?? AS s, ?? As t ' +
+                '  FROM ?? AS sa ' +
+                '    Left Join ?? AS s On sa.`sid` = s.`id` ' +
+                '    Left Join ?? As t ON sa.`tid` = t.`id`' +
                 '  WHERE ((sa.`aid` = ? and sa.`status` = ?) OR (s.`user_id` = ? and sa.`status` = ? and s.`status` = ? and sa.`times` = (s.`times`-1)))' +
-                '    and sa.`sid` = s.`id` and sa.`tid` = t.`id` ORDER BY sa.`begin_time` DESC';
+                '  ORDER BY sa.`begin_time` DESC';
             const sqlParam = [
                 this.tableName,
                 this.ctx.service.stage.tableName,
@@ -1020,20 +1017,6 @@ module.exports = app => {
          * @return {Promise<*>}
          */
         async getNoticeStage(pid, uid, time) {
-            // const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
-            //             '    s.`order` As `s_order`, s.`status` As `s_status`, ' +
-            //             '    sa.`aid`, sa.`times`, sa.`order`, sa.`end_time`, sa.`tid`, sa.`sid`, sa.`status`, ' +
-            //             '    pa.`name` As `su_name`, pa.role As `su_role`, pa.company As `su_company`' +
-            //             '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `aid` = ? GROUP BY `tid`)) As t' +
-            //             '  LEFT JOIN ?? As s On t.`id` = s.`tid`' +
-            //             '  LEFT JOIN ?? As sa ON s.`id` = sa.`sid`' +
-            //             '  LEFT JOIN ?? As pa ON sa.`aid` = pa.`id`' +
-            //             '  WHERE sa.`end_time` > ? and t.`project_id` = ?' +
-            //             '  ORDER By sa.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`tid`' +
-            //             '  ORDER By new_t.`end_time`';
-            // const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.stage.tableName, this.tableName,
-            //     this.ctx.service.projectAccount.tableName, time, pid];
-            // return await this.db.query(sql, sqlParam);
             let notice = await this.db.select('zh_notice', {
                 where: { pid, type: pushType.stage, uid },
                 orders: [['create_time', 'desc']],
@@ -1077,13 +1060,10 @@ module.exports = app => {
         async getAuditGroupByList(stageId, times) {
             const sql =
                 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`aid`, la.`order` ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` GROUP BY la.`aid` ORDER BY la.`order`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
+                '  WHERE la.`sid` = ? and la.`times` = ? GROUP BY la.`aid` ORDER BY la.`order`';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, times];
             return await this.db.query(sql, sqlParam);
-            // const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid`';
-            // const sqlParam = [this.tableName, stageId, times];
-            // return await this.db.query(sql, sqlParam);
         }
 
         /**
@@ -1096,12 +1076,8 @@ module.exports = app => {
             const result = await this.getAuditGroupByList(stageId, times);
             const sql =
                 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As sid, 0 As `order`' +
-                '  FROM ' +
-                this.ctx.service.stage.tableName +
-                ' As s' +
-                '  LEFT JOIN ' +
-                this.ctx.service.projectAccount.tableName +
-                ' As pa' +
+                '  FROM ' + this.ctx.service.stage.tableName + ' As s' +
+                '  LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
                 '  ON s.user_id = pa.id' +
                 '  WHERE s.id = ?';
             const sqlParam = [times, stageId, stageId];
@@ -1152,18 +1128,16 @@ module.exports = app => {
                 case auditConst.status.checking:
                 case auditConst.status.checked:
                 case auditConst.status.checkNoPre:
-                    sql =
-                        'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
-                        'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`sid` = ? and la.`status` = ? and la.`aid` = pa.`id` order by la.`times` desc, la.`order` desc';
+                    sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
+                          '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
+                          '  WHERE la.`sid` = ? and la.`status` = ? order by la.`times` desc, la.`order` desc';
                     sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, status];
                     auditor = await this.db.queryOne(sql, sqlParam);
                     break;
                 case auditConst.status.checkNo:
-                    sql =
-                        'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
-                        'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ? and la.`aid` = pa.`id` order by la.`times` desc, la.`order` desc';
+                    sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
+                          '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
+                          '  WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ? order by la.`times` desc, la.`order` desc';
                     sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.checkNo, parseInt(times) - 1];
                     auditor = await this.db.queryOne(sql, sqlParam);
                     break;
@@ -1201,9 +1175,11 @@ module.exports = app => {
                 '    s.*,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id`,' +
                 '    ti.`deal_info` ' +
-                '  FROM ?? AS sa, ?? AS s, ?? As t, ?? AS ti ' +
-                '  WHERE sa.`aid` = ? and sa.`status` = ?' +
-                '    and sa.`sid` = s.`id` and sa.`tid` = t.`id` and ti.`tid` = t.`id`';
+                '  FROM ?? AS sa' +
+                '    Left Join ?? AS s On sa.`sid` = s.`id`' +
+                '    Left Join ?? As t On sa.`tid` = t.`id`' +
+                '    Left Join ?? AS ti ON ti.`tid` = t.`id`' +
+                '  WHERE sa.`aid` = ? and sa.`status` = ?';
             const sqlParam = [
                 this.tableName,
                 this.ctx.service.stage.tableName,
@@ -1379,8 +1355,8 @@ module.exports = app => {
         async getFinalAuditGroup(stageId, times) {
             const sql =
                 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, pa.`sign_path`, la.`times`, la.`sid`, Max(la.`order`) as max_order ' +
-                'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` GROUP BY la.`aid` ORDER BY la.`order`';
+                '  FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
+                '  WHERE la.`sid` = ? and la.`times` = ? GROUP BY la.`aid` ORDER BY la.`order`';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, times];
             const result = await this.db.query(sql, sqlParam);
             for (const r of result) {

+ 2 - 2
app/service/stage_pay.js

@@ -291,8 +291,8 @@ module.exports = app => {
                         '    `pre_tp`, `end_tp`, `pre_used`, `pre_finish`, `start_stage_order`) ' +
                         '  SELECT SP.`tid`, SP.`sid`, SP.`pid`, ?, ?, SP.name, SP.`tp`, SP.`expr`, SP.`pause`,' +
                         '     SP.`pre_tp`, SP.`end_tp`, SP.`pre_used`, SP.`pre_finish`, SP.`start_stage_order` ' +
-                        '  FROM ?? As SP, ?? As P ' +
-                        '  WHERE SP.`sid` = ? AND SP.`stimes` = ? AND SP.`sorder` = ? And SP.`pid` = P.`id` And P.`valid`';
+                        '  FROM ?? As SP' +
+                        '  WHERE SP.`sid` = ? AND SP.`stimes` = ? AND SP.`sorder` = ?';
             const sqlParam = [this.tableName, times, order, this.tableName, this.ctx.service.pay.tableName,
                 stage.id, stage.curTimes, stage.curOrder];
             return await transaction.query(sql, sqlParam);