Kaynağa Gözat

Merge branch 'dev' into uat

MaiXinRong 3 yıl önce
ebeveyn
işleme
eb846e5830

+ 2 - 2
app/controller/ledger_controller.js

@@ -473,11 +473,11 @@ module.exports = app => {
          */
         async loadExplodeData(ctx) {
             try {
-                const ledgerData = ctx.tender.ledgerReadOnly
+                const ledgerData = ctx.tender.ledgerReadOnly && ctx.tender.his
                     ? await ctx.helper.loadLedgerDataFromOss(ctx.tender.his.bills_file)
                     : await ctx.service.ledger.getData(ctx.tender.id);
                 const posData = this.ctx.tender.data.measure_type === measureType.tz.value
-                    ? (ctx.tender.ledgerReadOnly
+                    ? (ctx.tender.ledgerReadOnly && ctx.tender.his
                         ? await ctx.helper.loadLedgerDataFromOss(ctx.tender.his.pos_file)
                         : await ctx.service.pos.getPosData({tid: ctx.tender.id}))
                     : [];

+ 1 - 3
app/controller/stage_controller.js

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

+ 3 - 1
app/middleware/tender_check.js

@@ -46,7 +46,9 @@ module.exports = options => {
             if (tender.data.project_id !== this.session.sessionProject.id) {
                 throw '您无权查看该项目';
             }
-            tender.his = yield this.service.ledgerHistory.getLatestHistory(tender.id);
+            tender.his = tender.data.ledger_status === auditConst.status.checkNo
+                ? yield this.service.ledgerHistory.getDataById(tender.data.his_id)
+                : null;
             const accountId = this.session.sessionUser.accountId;
             const advanceAuditors = yield this.service.advanceAudit.getAllAuditors(tender.id);
             const advanceAuditorsId = this.helper._.map(advanceAuditors, 'audit_id');

+ 27 - 0
app/service/ledger_history.js

@@ -65,6 +65,33 @@ module.exports = app => {
 
         /**
          * 备份
+         * @param {Object} tender - 标段
+         * @return {Promise<void>} - 新增备份id
+         * @private
+         */
+        async backupStageLedgerHistory(stage) {
+            const now = new Date();
+            const timestamp = (now).getTime();
+
+            const billsHis = `${this.ctx.session.sessionProject.id}/${stage.tid}/ledger/bills${timestamp}-s.json`;
+            const bills = await this.ctx.service.ledger.getData(stage.tid);
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
+
+            const posHis = `${this.ctx.session.sessionProject.id}/${stage.tid}/ledger/pos${timestamp}-s.json`;
+            const pos = await this.ctx.service.pos.getPosData({ tid: stage.tid });
+            await this.ctx.hisOss.put(this.ctx.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
+
+            const result = await this.db.insert(this.tableName, {
+                pid: this.ctx.session.sessionProject.id, tid: stage.tid, sid: stage.id,
+                in_time: now,
+                bills_file: billsHis, pos_file: posHis,
+            });
+
+            return result.insertId;
+        }
+
+        /**
+         * 备份
          * @param {Object} revise - 修订
          * @return {Promise<void>} - 新增备份id
          * @private

+ 4 - 4
app/service/material_bills.js

@@ -261,9 +261,9 @@ module.exports = app => {
                     m_spread: newm_spread,
                     origin: null,
                     m_tp: newTp,
-                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), decimal.tp) : mb.pre_tp,
+                    pre_tp: mb.m_tp !== null ? this.ctx.helper.add(mb.pre_tp, mb.m_tp) : mb.pre_tp,
                     m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp),
-                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), decimal.tp) : mb.tax_pre_tp,
+                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp) : mb.tax_pre_tp,
                 };
                 await transaction.update(this.tableName, updateData);
                 const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, newm_spread), decimal.tp) : 0;
@@ -281,9 +281,9 @@ module.exports = app => {
                     m_spread: newm_spread,
                     origin: null,
                     m_tp: newTp,
-                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), decimal.tp) : mb.pre_tp,
+                    pre_tp: mb.m_tp !== null ? this.ctx.helper.add(mb.pre_tp, mb.m_tp) : mb.pre_tp,
                     m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp),
-                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), decimal.tp) : mb.tax_pre_tp,
+                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp) : mb.tax_pre_tp,
                 };
                 await transaction.update(this.tableName, updateData);
                 const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(quantity, newm_spread), decimal.tp) : 0;

+ 14 - 2
app/service/stage_audit.js

@@ -470,7 +470,19 @@ module.exports = app => {
                     await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
                 } else {
                     await this.ctx.service.tenderTag.saveTenderTag(this.ctx.tender.id, {stage_time: new Date()}, transaction);
-                    const ledgerHis = await this.ctx.service.ledgerHistory.getLatestHistory(this.ctx.tender.id);
+                    let his_id;
+                    if (this.ctx.tender.measureType === measureType.tz.value) {
+                        const ledgerHis = await this.ctx.service.ledgerHistory.getLatestHistory(this.ctx.tender.id);
+                        his_id = ledgerHis.id;
+                    } else {
+                        const sapCount = await this.ctx.service.pos.count({ add_stage: this.ctx.stage.id });
+                        if (sapCount > 0) {
+                            his_id = await this.ctx.service.ledgerHistory.backupStageLedgerHistory(this.ctx.stage);
+                        } else {
+                            const ledgerHis = await this.ctx.service.ledgerHistory.getLatestHistory(this.ctx.tender.id);
+                            his_id = ledgerHis.id;
+                        }
+                    }
                     // 本期结束
                     // 生成截止本期数据 final数据
                     await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
@@ -486,7 +498,7 @@ module.exports = app => {
                         sf_tp: sfPay.tp,
                         tp_history: JSON.stringify(this.ctx.stage.tp_history),
                         cache_time_r: this.ctx.stage.cache_time_l,
-                        his_id: ledgerHis.id,
+                        his_id,
                     });
 
                     // 添加短信通知-审批通过提醒功能

+ 1 - 1
app/view/setting/sub_menu.ejs

@@ -5,7 +5,7 @@
     <div class="scrollbar-auto">
         <div class="nav-box">
             <ul class="nav-list list-unstyled">
-                <% if (projectData.user_account === ctx.session.sessionUser.account) { %>
+                <% if (ctx.session.sessionUser.is_admin) { %>
                 <% for (const index in ctx.subMenu) { %>
                 <% if (!ctx.subMenu[index].display) continue; %>
                 <li <% if (ctx.url.indexOf(ctx.subMenu[index].url) !== -1) { %>class="active"<% } %>>

+ 18 - 5
db_script/ledger_his.js

@@ -8,7 +8,19 @@
  * @version
  */
 
+const fs = require('fs');
+const path = require('path');
+var util = require('util');
+var logPath = path.join(__dirname, 'update_revise.log');
+var logFile = fs.createWriteStream(logPath, { flags: 'a' });
+
+console.log = function() {
+    logFile.write(util.format.apply(null, arguments) + '\n');
+    process.stdout.write(util.format.apply(null, arguments) + '\n');
+};
+
 const audit = require('../app/const/audit');
+const measureType = require('../app/const/message_type');
 
 const mysql = require('mysql');
 const oss = require('ali-oss');
@@ -81,8 +93,8 @@ const saveReviseLedgerHis = async function (tender, revise) {
     const billsHis = revise.bills_file;
     const posHis = revise.pos_file;
 
-    const result = await querySql('Insert Into zh_ledger_history(pid, tid, in_time, bills_file, pos_file, rid, rorder) Values(?, ?, ?, ?, ?, ?, ?)',
-        [tender.project_id, tender.id, now, billsHis, posHis, revise.id, revise.corder]);
+    const result = await querySql('Insert Into zh_ledger_history(pid, tid, in_time, bills_file, pos_file, rid, rorder, valid) Values(?, ?, ?, ?, ?, ?, ?, ?)',
+        [tender.project_id, tender.id, now, billsHis, posHis, revise.id, revise.corder, revise.valid]);
 
     if (!result) throw 'err';
     return result.insertId;
@@ -99,13 +111,13 @@ const doCompleteTender = async function(t) {
             }
             if (r.bills_file) {
                 r.his_id = await saveReviseLedgerHis(t, r);
-                his_id = r.his_id;
+                if (r.valid) his_id = r.his_id;
                 await querySql('Update zh_ledger_revise Set his_id = ? Where id = ?', [his_id, r.id]);
             } else {
                 if (r.status !== 1) withoutHisRevise.push(r);
             }
         }
-        if (!his_id) his_id = await saveLedgerHis(t);
+        if (!his_id || t.measure_type === measureType.gcl.value) his_id = await saveLedgerHis(t);
         await querySql('Update zh_tender Set his_id = ? Where id = ?', [his_id, t.id]);
         const stages = await querySql('Select * From zh_stage where tid = ? and status = ?', [t.id, audit.stage.status.checked]);
         for (const s of stages) {
@@ -166,5 +178,6 @@ doComplete();
 //     }
 //     pool.end();
 // };
-doCompeletTest();
+
+// doCompeletTest();
 

+ 59 - 0
db_script/update_revise.js

@@ -0,0 +1,59 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const fs = require('fs');
+const path = require('path');
+var util = require('util');
+const oss = require('ali-oss');
+const config = process.argv.splice(2)[0];
+if (['local', 'uat', 'default'].indexOf(config) < 0) throw `参数错误: ${config}`;
+const options = require(`../config/config.${config}`)({ baseDir: __dirname + '/app', root: __dirname, name: 'calc' });
+
+const ossOption = {
+    bucket: options.oss.clients.his.bucket,
+    accessKeyId: options.oss.default.accessKeyId,
+    accessKeySecret: options.oss.default.accessKeySecret,
+    endpoint: options.oss.default.endpoint,
+    timeout: options.oss.default.timeout,
+};
+const ossClient = new oss(ossOption);
+
+var logPath = path.join(__dirname, 'update_revise.log');
+var logFile = fs.createWriteStream(logPath, { flags: 'a' });
+
+console.log = function() {
+    logFile.write(util.format.apply(null, arguments) + '\n');
+    process.stdout.write(util.format.apply(null, arguments) + '\n');
+};
+
+const filepath = ['/etc/calc/files/revise', 'mnt/files/calc/revise'];
+// const filepath = ['/etc/calc/files/xx'];
+
+let iCount = 0;
+const updatePath = async function (filepath) {
+    console.log(`UpdatePath: ${filepath}`);
+    const files = fs.readdirSync(filepath);
+    for (const f of files) {
+        const stat = fs.statSync(path.join(filepath, f));
+        const ossPath = options.hisOssPath + 'revise/' + f;
+        if (stat.isFile()) await ossClient.put(ossPath, path.join(filepath, f));
+        console.log(`UpdateOss: ${path.join(filepath, f)} --> ${ossPath}`);
+        iCount++;
+    }
+    console.log('');
+};
+const updateAll = async function () {
+    for (const p of filepath) {
+        await updatePath(p);
+    }
+    console.log(`UpdateOss: ${iCount} files`);
+};
+
+updateAll();

+ 4 - 5
sql/update.sql

@@ -221,9 +221,6 @@ ALTER TABLE `zh_tender`
 ADD COLUMN `bills_file`  varchar(255) NOT NULL DEFAULT '' COMMENT '台账-清单文件' AFTER `has_rela`,
 ADD COLUMN `pos_file`  varchar(255) NOT NULL DEFAULT '' COMMENT '台账-计量单元文件' AFTER `bills_file`;
 
-UPDATE `zh_ledger_revise` SET bills_file = replace(bills_file, '/revise', 'revise') WHERE not ISNULL(bills_file);
-UPDATE `zh_ledger_revise` SET pos_file = replace(pos_file, '/revise', 'revise') WHERE not ISNULL(pos_file);
-
 CREATE TABLE `zh_material_checklist`  (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `tid` int(11) NOT NULL COMMENT '标段id',
@@ -261,12 +258,11 @@ ALTER TABLE `zh_tender`
 ADD COLUMN `his_id`  bigint(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT '台账历史数据id' AFTER `s2b_dagl_limit`;
 
 ALTER TABLE `zh_stage`
-ADD COLUMN `his_id`  bigint(20) UNSIGNED NOT NULL COMMENT '历史台账id' AFTER `tp_history`;
+ADD COLUMN `his_id`  bigint(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT '历史台账id' AFTER `tp_history`;
 
 ALTER TABLE `zh_stage_pay`
 ADD COLUMN `postil`  varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '本期批注' AFTER `start_stage_order`;
 
-
 ALTER TABLE `zh_tender` ADD `c_code_rules` TEXT NULL DEFAULT NULL COMMENT '变更立项及申请的编号规则json' AFTER `c_rule_first`;
 
 CREATE TABLE `zh_change_project`  (
@@ -320,3 +316,6 @@ CREATE TABLE `zh_change_project_audit`  (
   `opinion` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '审批意见',
   PRIMARY KEY (`id`) USING BTREE
 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '变更立项审批表';
+
+UPDATE `zh_ledger_revise` SET bills_file = replace(bills_file, '/revise', 'revise') WHERE not ISNULL(bills_file);
+UPDATE `zh_ledger_revise` SET pos_file = replace(pos_file, '/revise', 'revise') WHERE not ISNULL(pos_file);