Browse Source

完善pos表,分表查询

MaiXinRong 3 years ago
parent
commit
8b89f662b1
3 changed files with 8 additions and 7 deletions
  1. 1 1
      app/controller/stage_controller.js
  2. 5 4
      app/service/pos.js
  3. 2 2
      app/service/stage_pos.js

+ 1 - 1
app/controller/stage_controller.js

@@ -264,7 +264,7 @@ module.exports = app => {
         async _getStagePosData(ctx) {
             let curStageData,
                 preStageData;
-            const posData = await ctx.service.pos.getPosDataWithAddStageOrder({ tid: ctx.tender.id });
+            const posData = await ctx.service.pos.getPosDataWithAddStageOrder(ctx.tender.id, { tid: ctx.tender.id });
             // 根据当前人,或指定对象查询数据
             // console.time('cur');
             if (ctx.stage.readOnly) {

+ 5 - 4
app/service/pos.js

@@ -36,23 +36,24 @@ module.exports = app => {
         }
 
         async getPosDataWithAddStageOrder(condition) {
+            if (!condition.tid) throw '查询计量单元缺少必要信息';
             const sql = 'SELECT p.id, p.tid, p.lid, p.name, p.quantity, p.position, p.drawing_code,' +
                 '    p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.porder, p.add_stage, p.add_times, p.add_user, s.order As add_stage_order,' +
                 '    p.sgfh_expr, p.sjcl_expr, p.qtcl_expr, p.real_qty, p.gxby_status, p.dagl_status, p.dagl_url,' +
                 '    p.gxby_limit, p.dagl_limit, p.ex_memo1, p.ex_memo2, p.ex_memo3' +
-                '  FROM ' + this.tableName + ' p ' +
+                '  FROM ' + this.departTableName(condition.tid) + ' p ' +
                 '  LEFT JOIN ' + this.ctx.service.stage.tableName + ' s' +
                 '  ON p.add_stage = s.id'
                 + this.ctx.helper.whereSql(condition, 'p');
             return await this.db.query(sql);
         }
 
-        async getPosDataByIds(ids) {
+        async getPosDataByIds(tid, ids) {
             if (ids instanceof Array && ids.length > 0) {
                 const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code,' +
                     '    sgfh_qty, sjcl_qty, qtcl_qty, add_stage, add_times, add_user, sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
                     '    dagl_status, dagl_url, gxby_status, gxby_limit, dagl_limit, ex_memo1, ex_memo2, ex_memo3' +
-                    '  FROM ' + this.tableName +
+                    '  FROM ' + this.departTableName(tid) +
                     '  WHERE id in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ')';
                 return await this.db.query(sql, []);
             } else {
@@ -70,7 +71,7 @@ module.exports = app => {
 
         async getPosDataByUnits(tenderId, units) {
             const sql = 'SELECT p.id, p.lid, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty' +
-                '  FROM ' + this.tableName + ' p' +
+                '  FROM ' + this.departTableName(tenderId) + ' p' +
                 '  LEFT JOIN ' + this.ctx.service.ledger.tableName + ' b' +
                 '  ON p.lid = b.id ' +
                 '  WHERE p.tid = ? and b.unit IN (?)';

+ 2 - 2
app/service/stage_pos.js

@@ -255,7 +255,7 @@ module.exports = app => {
         async _updateStagePosData(data) {
             let bills, precision, updateBills = null;
             const datas = data instanceof Array ? data : [data];
-            const orgPos = await this.ctx.service.pos.getPosDataByIds(this._.map(datas, 'pid'));
+            const orgPos = await this.ctx.service.pos.getPosDataByIds(this.ctx.tender.id, this._.map(datas, 'pid'));
             const result = {ledger: [], pos: [], stageUpdate: true};
             const orgStagePos = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id,
                 {pid: this._.map(datas, 'pid')});
@@ -593,7 +593,7 @@ module.exports = app => {
                     if (refreshData.isDeletePos) {
                         result.pos.pos = refreshData.pos;
                     } else if (refreshData.pos.length > 0) {
-                        result.pos.pos = await this.ctx.service.pos.getPosDataWithAddStageOrder({id: refreshData.pos});
+                        result.pos.pos = await this.ctx.service.pos.getPosDataWithAddStageOrder({tid: this.ctx.tender.id, id: refreshData.pos});
                         if (refreshData.stageUpdate) {
                             result.pos.curStageData = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: refreshData.pos});
                         }