Browse Source

导入分项清单excel调整

MaiXinRong 4 years ago
parent
commit
5e1bbed9a4
3 changed files with 14 additions and 5 deletions
  1. 8 0
      app/lib/analysis_excel.js
  2. 5 4
      app/service/stage_bills_final.js
  3. 1 1
      app/service/stage_pos_final.js

+ 8 - 0
app/lib/analysis_excel.js

@@ -205,6 +205,11 @@ class ImportBaseTree {
         }
     }
 
+    _assignRelaField(temp, node) {
+        _.assignInWith(temp, node,
+            (objValue, srcValue, key) => { return ['name', 'unit'].indexOf(key) > -1 ? objValue : srcValue; });
+    }
+
     /**
      * 添加 项目节
      * @param {Object} node - 项目节
@@ -218,6 +223,7 @@ class ImportBaseTree {
             const temp = this.findTempData(node);
             if (temp) {
                 this.defineCacheData(temp);
+                this._assignRelaField(temp, node);
                 return temp;
             } else {
                 const parent = this.findXmjParent(node.code);
@@ -229,6 +235,7 @@ class ImportBaseTree {
                 return this.addNodeWithParent(node, null);
             } else {
                 this.defineCacheData(n);
+                this._assignRelaField(n, node);
                 return n;
             }
         }
@@ -432,6 +439,7 @@ class ImportStd18Tree extends ImportBaseTree {
         const temp = this.findTempData(node);
         if (temp) {
             this.defineCacheData(temp);
+            this._assignRelaField(temp, node);
             return temp;
         } else {
             const parent = this.findXmjParent(node.code);

+ 5 - 4
app/service/stage_bills_final.js

@@ -94,10 +94,12 @@ module.exports = app => {
                         c.contract_tp = this.ctx.helper.add(c.contract_tp, p.contract_tp);
                         c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
                         c.qc_tp = this.ctx.helper.add(c.qc_tp, p.qc_tp);
-                        c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
+                        c.used = p.used || !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
+                            || !this.ctx.helper.checkZero(c.contract_tp) || !this.ctx.helper.checkZero(c.qc_tp);
                         pre.splice(pre.indexOf(p), 1);
                     } else {
-                        c.used = !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty);
+                        c.used = !this.ctx.helper.checkZero(c.contract_qty) || !this.ctx.helper.checkZero(c.qc_qty)
+                            || !this.ctx.helper.checkZero(c.contract_tp) || !this.ctx.helper.checkZero(c.qc_tp);
                     }
                 }
 
@@ -105,13 +107,12 @@ module.exports = app => {
                     if (p.id !== undefined) delete p.id;
                     p.sid = stage.id;
                     p.sorder = stage.order;
-                    p.used = p.used || !this.ctx.helper.checkZero(p.contract_qty) || !this.ctx.helper.checkZero(p.qc_qty);
                 }
                 await transaction.insert(this.tableName, cur ? cur.concat(pre) : pre);
             } else {
                 const sql = 'Insert Into ??(tid, sid, lid, sorder, contract_qty, contract_tp, qc_qty, qc_tp, used)' +
                     '  SELECT b.tid, b.sid, b.lid, ? As `sorder`, b.contract_qty, b.contract_tp, b.qc_qty, b.qc_tp,' +
-                    '    IFNULL((b.contract_qty <> 0 or b.contract_tp <> 0 or b.qc_qty <> 0 or b.qc_tp <> 0), 0) As used' +
+                    '    IF(IFNULL(b.contract_qty, 0) <> 0 or IFNULL(b.contract_tp, 0) <> 0 or IFNULL(b.qc_qty, 0) <> 0 or IFNULL(b.qc_tp, 0) <> 0, 1, 0) As used' +
                     '  FROM ' + this.ctx.service.stageBills.tableName + ' AS b' +
                     '  INNER JOIN(' +
                     '    SELECT Max(`times` * ' + timesLen + ' + `order`) As `flow`, `lid` FROM ' + this.ctx.service.stageBills.tableName +

+ 1 - 1
app/service/stage_pos_final.js

@@ -101,7 +101,7 @@ module.exports = app => {
             } else {
                 const sql = 'Insert Into ??(tid, sid, lid, pid, sorder, contract_qty, qc_qty, used)' +
                             '  SELECT p.tid, p.sid, p.lid, p.pid, ? As `sorder`, p.contract_qty, p.qc_qty,' +
-                            '    IFNULL((p.contract_qty <> 0 or p.qc_qty <> 0), 0) As used' +
+                            '    IF(IFNULL(p.contract_qty, 0) <> 0 or IFNULL(p.qc_qty, 0) <> 0, 1, 0) As used' +
                             '  FROM ' + this.ctx.service.stagePos.tableName + ' AS p' +
                             '  INNER JOIN(' +
                             '    SELECT Max(`times` * ' + timesLen +' + `order`) As `flow`, `pid` FROM ' + this.ctx.service.stagePos.tableName +