Explorar el Código

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

laiguoran hace 3 años
padre
commit
39f005a78d

+ 0 - 1
app/extend/helper.js

@@ -282,7 +282,6 @@ module.exports = {
                 data,
                 dataType,
             }) : await this.ctx.curl(url);
-            // console.log(response);
             if (response.status !== 200) {
                 if (count > 0) {
                     count = count - 1;

+ 8 - 5
app/lib/sum_load.js

@@ -8,6 +8,7 @@
  * @version
  */
 const Ledger = require('../lib/ledger');
+const auditConst = require('../const/audit');
 
 class loadGclBaseTree {
     /**
@@ -394,12 +395,12 @@ class gatherStageGclTree extends loadGclBaseTree {
             }
             if (bn.contract_qty !== bn.org_contract_qty || bn.contract_tp !== bn.org_contract_tp || bn.qc_qty !== bn.org_qc_qty) {
                 let data = { lid: bn.id, contract_qty: bn.contract_qty, contract_tp: bn.contract_tp };
-                if (bn.is_import) {
-                    data.qc_qty = bn.qc_qty;
-                    data.qc_tp = bn.qc_tp;
-                } else {
+                if (!bn.is_import && bn.org_qc_qty) {
                     data.qc_qty = bn.org_qc_qty;
                     data.qc_tp = bn.org_qc_tp;
+                } else {
+                    data.qc_qty = bn.qc_qty;
+                    data.qc_tp = bn.qc_tp;
                 }
                 result.update.push(data);
             }
@@ -538,7 +539,9 @@ class sumLoad {
             const stage = await this.ctx.service.stage.getDataByCondition({tid: tender.tid, order: tender.stage});
             if (!stage) throw '选择的期不存在';
             const curStageData = await this.ctx.service.stageBills.getLastestStageData2(tender.tid, stage.id);
-            const curStageChange = await this.ctx.service.stageChangeFinal.getSumLoadFinalData(stage.id);
+            const curStageChange = stage.status === auditConst.stage.status.checked
+                ? await this.ctx.service.stageChangeFinal.getSumLoadFinalData(stage.id)
+                : await this.ctx.service.stageChange.getSumLoadFinalData(stage.id);
             this._loadCurStageAndChange(billsData, curStageData, curStageChange);
             const billsTree = new Ledger.billsTree(this.ctx, {
                 id: 'ledger_id',

+ 18 - 14
app/middleware/auto_finish_logger.js

@@ -7,32 +7,36 @@
  * @date 2017/10/30
  * @version
  */
+const os = require('os');
 
 module.exports = options => {
     return async function autoFinishLogger(ctx, next) {
         await next();
 
-        const bLogger = ctx.getLogger('finish');
+        if (ctx.url.indexOf('/public/') === 0) return;
+
         const responseTime = new Date();
-        const runTime = responseTime.getTime() - responseTime.getTime();
+        const runTime = responseTime.getTime() - ctx.logInfo.time.getTime();
+        let logData;
         if (ctx.session && ctx.session.sessionUser) {
-            const logData = {
-                requestTime: ctx.logTime,
-                responseTime, runTime,
-                method: ctx.method,
-                user: ctx.session.sessionUser,
-                project: ctx.session.sessionProject,
+            const cpus = os.cpus();
+            const endCpus = cpus.map(x => {
+                return `${((1-x.times.idle/(x.times.idle+x.times.user+x.times.nice+x.times.sys+x.times.irq))*100).toFixed(2)}%`
+            });
+            logData = {
+                requestTime: ctx.logInfo.time, responseTime, runTime,
+                beginCpus: ctx.logInfo.cpus, endCpus,
+                user: ctx.session.sessionUser.accountId, userName: ctx.session.sessionUser.name, loginType: ctx.session.sessionUser.loginType,
+                pCode: ctx.session.sessionProject.code,
                 data: ctx.request.body,
             };
-            bLogger.info(JSON.stringify(logData));
         } else {
-            const logData = {
-                requestTime: ctx.logTime,
-                responseTime, runTime,
-                method: ctx.method,
+            logData = {
+                requestTime: ctx.logTime, responseTime, runTime,
                 data: ctx.body,
             };
-            bLogger.info(JSON.stringify(logData));
         }
+        const bLogger = runTime > 500 ? ctx.getLogger('warning') : ctx.getLogger('finish');
+        bLogger.info(JSON.stringify(logData));
     };
 };

+ 6 - 1
app/middleware/auto_logger.js

@@ -7,6 +7,7 @@
  * @date 2017/10/30
  * @version
  */
+const os = require('os');
 
 module.exports = options => {
     return function* autoLogger(next) {
@@ -36,7 +37,11 @@ module.exports = options => {
             };
             bLogger.info(JSON.stringify(logData));
         }
-        this.logTime = new Date();
+        this.logInfo = { time: new Date() };
+        const cpus = os.cpus();
+        this.logInfo.cpus = cpus.map(x => {
+            return `${((1-x.times.idle/(x.times.idle+x.times.user+x.times.nice+x.times.sys+x.times.irq))*100).toFixed(2)}%`
+        });
 
         // 自动记录log的action
         // const autoLogAction = ['save', 'delete'];

+ 2 - 1
app/public/js/shares/cs_tools.js

@@ -959,7 +959,8 @@ const showSelectTab = function(select, spread, afterShow) {
                     { title: '清单编号', field: 'b_code', width: 80, formatter: '@' },
                     { title: '清单名称', field: 'name', width: 120, formatter: '@' },
                     { title: '单位', field: 'unit', width: 50, formatter: '@' },
-                    { title: '数量', field: 'qty', width: 60 },
+                    { title: setting.type === 'stage' ? '合同数量' : '数量', field: 'qty', width: 60 },
+                    { title: '变更数量', field: 'qc_qty', width: 60, visible: setting.type === 'stage' },
                     {
                         title: '类型', field: 'type', width: 100, getValue: function (x) {
                             switch (x.type) {

+ 1 - 0
app/public/js/stage.js

@@ -830,6 +830,7 @@ $(document).ready(() => {
         relaSpread: slSpread,
         storeKey: 'stage-slm-' + stage.id,
         id: 'stage-slm',
+        type: 'stage',
         afterLocated:  function () {
             stagePosSpreadObj.loadCurPosData();
         },

+ 9 - 0
app/service/stage_change.js

@@ -374,6 +374,15 @@ module.exports = app => {
             return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cid', 'cbid'], 'stimes', 'sorder');
         }
 
+        async getSumLoadFinalData(sid) {
+            const sql = 'Select cf.tid, cf.sid, cf.lid, cf.cid, cf.cbid, cf.qty, c.code As c_code' +
+                '  FROM ' + this.tableName + ' cf' +
+                '  Left Join ' + this.ctx.service.change.tableName + ' c ON cf.cid = c.cid' +
+                '  Where cf.sid = ?';
+            const result = await this.db.query(sql, [sid]);
+            return this.ctx.helper.filterLastestData(result, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
+        }
+
         async _getTender(stage) {
             if (this.ctx.tender) return this.ctx.tender;
             const tender = { id: stage.tid };

+ 2 - 3
app/service/stage_change_final.js

@@ -84,11 +84,10 @@ module.exports = app => {
         }
 
         async getSumLoadFinalData(sid) {
-            const sql = 'Select cf.tid, cf.sid, cf.lid, cf.cid, cf.cbid, sum(cf.qty) as qty, c.code As c_code' +
+            const sql = 'Select cf.tid, cf.sid, cf.lid, cf.cid, cf.cbid, cf.qty, c.code As c_code' +
                 '  FROM ' + this.tableName + ' cf' +
                 '  Left Join ' + this.ctx.service.change.tableName + ' c ON cf.cid = c.cid' +
-                '  Where cf.sid = ?' +
-                '  Group By cf.lid, cf.cbid';
+                '  Where cf.sid = ?';
             return await this.db.query(sql, [sid]);
         }
     }

+ 3 - 0
config/config.default.js

@@ -167,6 +167,9 @@ module.exports = appInfo => {
         },
         finish: {
             file: path.join(appInfo.root, 'logs', appInfo.name, config.version, 'finish.log'),
+        },
+        warning: {
+            file: path.join(appInfo.root, 'logs', appInfo.name, config.version, 'warning.log'),
         }
     };
 

+ 0 - 2
db_script/depart-database-table.js

@@ -284,7 +284,6 @@ const generateAllCreateSql = function () {
 // generateAllCreateSql();
 
 // const tenders = querySql('Select * From zh_tender');
-// console.log(tenders.length);
 //
 const log = [];
 const depart = async function (info) {
@@ -293,7 +292,6 @@ const depart = async function (info) {
         const sql = 'Insert Into ' + info.table + '_' + i +
             '  Select * From ' + info.table +
             '  Where ' + info.relaId + ' % ' + info.count + ' = ' + i;
-        console.log(sql);
         log.push(sql);
         await querySql(sql);
     }

+ 0 - 1
test/app/lib/rpt_data_analysis.test.js

@@ -202,7 +202,6 @@ describe('test/app/service/report_memory.test.js', () => {
             mem_stage_im_zl: ['lid', 'code'],
         });
         reportDataAnalysis.analysisObj.loadCooperationData.fun(ctx, data, [], {table: 'mem_stage_im_zl', co_sign: [0, 1, 2, 3]}, null);
-        console.log(data.mem_stage_im_zl);
     });
     it('test join', function* () {
         const ctx = app.mockContext(mockData);