Browse Source

台账、台账修订,历史数据存储与读取

MaiXinRong 3 years ago
parent
commit
9840402608

+ 1 - 0
app.js

@@ -115,4 +115,5 @@ module.exports = app => {
 
     app.signPdfOss = app.oss.get('signPdf');
     app.fujianOss = app.oss.get('fujian');
+    app.hisOss = app.oss.get('his');
 };

+ 6 - 11
app/controller/revise_controller.js

@@ -497,11 +497,8 @@ module.exports = app => {
 
         async history(ctx) {
             try {
-                const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id, false);
-                if (!revise) throw '台账修订数据有误';
+                const revise = ctx.revise;
 
-                // const reviseBills = await ctx.service.ledger.getData(ctx.tender.id);
-                // const revisePos = await ctx.service.pos.getPosData({tid: ctx.tender.id});
                 const [ledgerSpread, posSpread] = this._getSpreadSetting(revise);
                 const sjsRela = await this.ctx.service.project.getSjsRela(ctx.session.sessionProject.id);
                 this.ctx.helper.refreshSpreadShow(sjsRela.ledgerCol, [ledgerSpread, posSpread]);
@@ -522,7 +519,6 @@ module.exports = app => {
                 const renderData = {
                     measureType, audit, revise,
                     ledgerSpread, posSpread,
-                    // reviseBills, revisePos,
                     readOnly: true,
                     historyRevise,
                     auditHistory,
@@ -557,15 +553,14 @@ module.exports = app => {
          */
         async loadHistoryData(ctx) {
             try {
-                const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id, false);
-                if (!revise) throw '台账修订数据有误';
-
-                const reviseBills = await ctx.service.ledger.getData(ctx.tender.id);
-                const revisePos = await ctx.service.pos.getPosData({ tid: ctx.tender.id });
+                const billsFile = await this.ctx.app.hisOss.get(ctx.app.config.hisOssPath + ctx.revise.bills_file);
+                const reviseBills = JSON.parse(billsFile.content);
+                const posFile = await this.ctx.app.hisOss.get(ctx.app.config.hisOssPath + ctx.revise.pos_file);
+                const revisePos = JSON.parse(posFile.content);
                 ctx.body = { err: 0, msg: '', data: { bills: reviseBills, pos: revisePos } };
             } catch (error) {
                 ctx.helper.log(error);
-                this.ajaxErrorBody(error, '获取台账修订数据错误,请刷新页面');
+                this.ajaxErrorBody(error, '获取台账修订数据错误');
             }
         }
 

+ 3 - 1
app/middleware/revise_check.js

@@ -21,7 +21,9 @@ module.exports = options => {
     return function* reviseCheck(next) {
         try {
             // 获取revise
-            const revise = yield this.service.ledgerRevise.getLastestRevise(this.tender.id);
+            const revise = this.params.rid
+                ? yield this.service.ledgerRevise.getDataById(this.params.rid)
+                : yield this.service.ledgerRevise.getLastestRevise(this.tender.id);
             if (!revise) throw '台账修订数据有误';
             revise.reviseUsers = [revise.uid];
             if (revise.status !== auditConst.status.uncheck) {

+ 1 - 1
app/public/js/revise_history.js

@@ -300,7 +300,7 @@ $(document).ready(() => {
     })('a[name=showLevel]', billsSheet);
 
     $('#reviseHistory').change(function () {
-        postData(window.location.pathname + '/info', { rid: this.value }, function (result) {
+        postData('info', { rid: this.value }, function (result) {
             $('#user-name').val(result.user_name);
             $('#content')[0].textContent = result.content;
             $('#end-time').val(result.end_time_str);

+ 2 - 2
app/router.js

@@ -231,8 +231,8 @@ module.exports = app => {
 
 
     // 查看修订数据
-    app.get('/tender/:id/revise/history', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.history');
-    app.post('/tender/:id/revise/history/load', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.loadHistoryData');
+    app.get('/tender/:id/revise/history/:rid', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.history');
+    app.post('/tender/:id/revise/history/:rid/load', sessionAuth, tenderCheck, uncheckTenderCheck, reviseCheck, 'reviseController.loadHistoryData');
     app.post('/tender/:id/revise/history/info', sessionAuth, tenderCheck, uncheckTenderCheck, 'reviseController.historyInfo');
 
     // 修订审批

+ 25 - 0
app/service/ledger_audit.js

@@ -242,6 +242,26 @@ module.exports = app => {
         }
 
         /**
+         * 备份
+         * @param {Object} revise - 修订
+         * @returns {Promise<void>}
+         * @private
+         */
+        async backupLedgerHistoryFile() {
+            const timestamp = (new Date()).getTime();
+
+            const billsHis = `${this.ctx.session.sessionProject.id}/${this.ctx.tender.id}/bills${timestamp}.json`;
+            const bills = await this.ctx.service.ledger.getData(this.ctx.tender.id);
+            await this.ctx.app.hisOss.put(this.ctx.app.config.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
+
+            const posHis = `${this.ctx.session.sessionProject.id}/${this.ctx.tender.id}/pos${timestamp}.json`;
+            const pos = await this.ctx.service.pos.getData(this.ctx.tender.id);
+            await this.ctx.app.hisOss.put(this.ctx.app.config.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
+
+            return [billsHis, posHis];
+        }
+
+        /**
          * 开始审批
          *
          * @param {Number} tenderId - 标段id
@@ -259,6 +279,9 @@ module.exports = app => {
             }
             const sum = await this.ctx.service.ledger.addUp({ tender_id: tenderId /* , is_leaf: true*/ });
 
+            // 拷贝备份台账数据
+            const [billsHis, posHis] = await this.backupLedgerHistoryFile();
+
             const transaction = await this.db.beginTransaction();
             try {
                 await transaction.update(this.tableName, {
@@ -271,6 +294,8 @@ module.exports = app => {
                     ledger_status: auditConst.status.checking,
                     total_price: sum.total_price,
                     deal_tp: sum.deal_tp,
+                    bills_file: billsHis,
+                    pos_file: posHis,
                 });
 
                 // 添加短信通知-需要审批提醒功能

+ 5 - 5
app/service/ledger_revise.js

@@ -30,7 +30,7 @@ module.exports = app => {
          * @returns {Promise<*>} - ledger_change下所有数据,并关联 project_account(读取提交人名称、单位、公司)
          */
         async getReviseList (tid) {
-            const sql = 'SELECT lc.id, lc.tid, lc.corder, lc.in_time, lc.uid, lc.begin_time, lc.end_time, lc.times, lc.status, lc.valid, lc.content,' +
+            const sql = 'SELECT lc.id, lc.tid, lc.corder, lc.in_time, lc.uid, lc.begin_time, lc.end_time, lc.times, lc.status, lc.valid, lc.content, lc.bills_file,' +
                 '    pa.name As user_name, pa.role As user_role, pa.company As user_company' +
                 '  FROM ' + this.tableName + ' As lc' +
                 '  INNER JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa ON lc.uid = pa.id' +
@@ -158,13 +158,13 @@ module.exports = app => {
         async backupReviseHistoryFile(revise) {
             const timestamp = (new Date()).getTime();
 
-            const billsHis = '/revise/bills' + timestamp + '.json';
+            const billsHis = `${this.ctx.session.sessionProject.id}/${this.ctx.tender.id}/bills${timestamp}.json`;
             const bills = await this.ctx.service.reviseBills.getData(revise.tid);
-            await this.ctx.helper.saveBufferFile(JSON.stringify(bills), this.ctx.app.config.filePath + billsHis);
+            await this.ctx.app.hisOss.put(this.ctx.app.config.hisOssPath + billsHis, Buffer.from(JSON.stringify(bills), 'utf8'));
 
-            const posHis = '/revise/pos' + timestamp + '.json';
+            const posHis = `${this.ctx.session.sessionProject.id}/${this.ctx.tender.id}/pos${timestamp}.json`;
             const pos = await this.ctx.service.revisePos.getData(revise.tid);
-            await this.ctx.helper.saveBufferFile(JSON.stringify(pos), this.ctx.app.config.filePath + posHis);
+            await this.ctx.app.hisOss.put(this.ctx.app.config.hisOssPath + posHis, Buffer.from(JSON.stringify(pos), 'utf8'));
 
             return [billsHis, posHis];
         }

+ 2 - 2
app/view/revise/index.ejs

@@ -75,8 +75,8 @@
                             <a href="<%- preUrl + '/revise/info' %>">查看修订内容</a>
                             <% } %>
                             <% } %>
-                            <% if (lr.lastest) { %>
-                            <a href="<%- preUrl + '/revise/history' %>">查看修订内容</a>
+                            <% if (lr.bills_file) { %>
+                                <a href="<%- preUrl + '/revise/history/' + lr.id %>">查看修订内容</a>
                             <% } %>
                         </td>
                     </tr>

+ 4 - 0
config/config.default.js

@@ -202,6 +202,7 @@ module.exports = appInfo => {
 
     config.proxy = true;
 
+    config.hisOssPath = 'prod/';
     config.oss = {
         clients: {
             signPdf: {
@@ -210,6 +211,9 @@ module.exports = appInfo => {
             fujian: {
                 bucket: 'jiliang-saas',
             },
+            his: {
+                bucket: 'jiliang-his',
+            }
         },
         default: {
             accessKeyId: 'LTAIALMjBHOs9PLA',

+ 1 - 0
config/config.local.js

@@ -91,6 +91,7 @@ module.exports = appInfo => {
         appsecret: '457d64c55f48f57cd22eca47e53d15cb',
     };
 
+    config.hisOssPath = 'qa/';
     config.oss = {
         clients: {
             signPdf: {

+ 1 - 0
config/config.qa.js

@@ -53,6 +53,7 @@ module.exports = appInfo => {
         rolling: true, // 每次都更新session有效期
     };
 
+    config.hisOssPath = 'qa/';
     config.oss = {
         clients: {
             signPdf: {

+ 1 - 0
config/config.uat.js

@@ -59,6 +59,7 @@ module.exports = appInfo => {
         appsecret: 'ca7c0dbd9e94dc3b1c3b0e73865743f4',
     };
 
+    config.hisOssPath = 'uat/';
     config.oss = {
         clients: {
             signPdf: {

+ 7 - 0
sql/update.sql

@@ -216,3 +216,10 @@ MODIFY COLUMN `add_stage`  int(11) NOT NULL COMMENT '新增期id' AFTER `quantit
 ADD COLUMN `add_stage_order`  tinyint(4) NOT NULL DEFAULT 0 COMMENT '新增期序号' AFTER `add_stage`;
 
 Update zh_change_pos p Left Join zh_stage s ON p.add_stage = s.id Set p.add_stage_order = s.order where p.add_stage_order > 0;
+
+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);