소스 검색

优化变更sql

ellisran 1 년 전
부모
커밋
e3edc41e71
3개의 변경된 파일6개의 추가작업 그리고 6개의 파일을 삭제
  1. 2 2
      app/service/change_apply_audit.js
  2. 2 2
      app/service/change_plan_audit.js
  3. 2 2
      app/service/change_project_audit.js

+ 2 - 2
app/service/change_apply_audit.js

@@ -389,9 +389,9 @@ module.exports = app => {
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`caid`,' +
                 '    m.`status` As `mstatus`, m.`code` As `mcode`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
-                '  FROM ?? AS ma, ?? AS m, ?? As t ' +
+                '  FROM ?? AS ma LEFT JOIN ?? AS m ON  ma.`caid` = m.`id` LEFT JSON ?? As t ON ma.`tid` = t.`id`' +
                 '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
-                '    and ma.`caid` = m.`id` and ma.`tid` = t.`id` ORDER BY ma.`begin_time` DESC';
+                '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.changeApply.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
             const result = await this.db.query(sql, sqlParam);
             // 过滤result中存在重复sid的值, 保留最新的一条

+ 2 - 2
app/service/change_plan_audit.js

@@ -392,9 +392,9 @@ module.exports = app => {
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`cpid`,' +
                 '    m.`status` As `mstatus`, m.`code` As `mcode`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
-                '  FROM ?? AS ma, ?? AS m, ?? As t ' +
+                '  FROM ?? AS ma LEFT JOIN ?? AS m ON  ma.`cpid` = m.`id` LEFT JSON ?? As t ON ma.`tid` = t.`id`' +
                 '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
-                '    and ma.`cpid` = m.`id` and ma.`tid` = t.`id` ORDER BY ma.`begin_time` DESC';
+                '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.changePlan.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
             const result = await this.db.query(sql, sqlParam);
             // 过滤result中存在重复sid的值, 保留最新的一条

+ 2 - 2
app/service/change_project_audit.js

@@ -397,9 +397,9 @@ module.exports = app => {
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`cpid`,' +
                 '    m.`status` As `mstatus`, m.`code` As `mcode`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
-                '  FROM ?? AS ma, ?? AS m, ?? As t ' +
+                '  FROM ?? AS ma LEFT JOIN ?? AS m ON  ma.`cpid` = m.`id` LEFT JSON ?? As t ON ma.`tid` = t.`id`' +
                 '  WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
-                '    and ma.`cpid` = m.`id` and ma.`tid` = t.`id` ORDER BY ma.`begin_time` DESC';
+                '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.changeProject.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.back, auditConst.status.back];
             const result = await this.db.query(sql, sqlParam);
             // 过滤result中存在重复cpid的值, 保留最新的一条