Browse Source

1. 汇总对比,数据存储,优先
2. 报表数据,汇总对比数据,查询调整

MaiXinRong 2 months ago
parent
commit
15a4d29ac4

+ 14 - 0
app/controller/spss_controller.js

@@ -11,6 +11,9 @@
 const measureType = require('../const/tender').measureType;
 const status = require('../const/audit').stage.status;
 const moment = require('moment');
+const stashCtrl = {
+    first: false,
+};
 
 module.exports = app => {
 
@@ -34,6 +37,7 @@ module.exports = app => {
                 const renderData = {
                     categoryData,
                     stashList,
+                    stashCtrl,
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.spss.gatherInfo)
                 };
                 await this.layout('spss/gather_info.ejs', renderData, 'spss/gather_info_modal.ejs');
@@ -49,6 +53,7 @@ module.exports = app => {
                 const renderData = {
                     categoryData,
                     stashList,
+                    stashCtrl,
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.spss.gatherLedger)
                 };
                 await this.layout('spss/gather_ledger.ejs', renderData, 'spss/spss_modal.ejs');
@@ -64,6 +69,7 @@ module.exports = app => {
                 const renderData = {
                     categoryData,
                     stashList,
+                    stashCtrl,
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.spss.gatherStage)
                 };
                 await this.layout('spss/gather_stage.ejs', renderData, 'spss/spss_modal.ejs');
@@ -79,6 +85,7 @@ module.exports = app => {
                 const renderData = {
                     categoryData,
                     stashList,
+                    stashCtrl,
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.spss.gatherStageExtra)
                 };
                 await this.layout('spss/gather_stage_extra.ejs', renderData, 'spss/spss_modal.ejs');
@@ -94,6 +101,7 @@ module.exports = app => {
                 const renderData = {
                     categoryData,
                     stashList,
+                    stashCtrl,
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.spss.gatherStagePay)
                 };
                 await this.layout('spss/gather_stage_pay.ejs', renderData, 'spss/spss_modal.ejs');
@@ -109,6 +117,7 @@ module.exports = app => {
                 const renderData = {
                     categoryData,
                     stashList,
+                    stashCtrl,
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.spss.compareLedger)
                 };
                 await this.layout('spss/compare_ledger.ejs', renderData, 'spss/spss_modal.ejs');
@@ -124,6 +133,7 @@ module.exports = app => {
                 const renderData = {
                     categoryData,
                     stashList,
+                    stashCtrl,
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.spss.compareStage),
                 };
                 await this.layout('spss/compare_stage.ejs', renderData, 'spss/spss_modal.ejs');
@@ -736,6 +746,10 @@ module.exports = app => {
                         await this.ctx.service.spssStash.addSpssStash(data.type, data.select, data.result);
                         responseData.data = await this.ctx.service.spssStash.getSpssStashList(this.ctx.subProject.id, data.type);
                         break;
+                    case 'first':
+                        await this.ctx.service.spssStash.firstSpssStash(this.ctx.subProject.id, data.type, data.id);
+                        responseData.data = await this.ctx.service.spssStash.getSpssStashList(this.ctx.subProject.id, data.type);
+                        break;
                     default: throw '未知操作';
                 }
                 ctx.body = responseData;

+ 14 - 2
app/public/js/shares/spss_stash.js

@@ -4,11 +4,12 @@ const SpssStash = function(setting){
     const refreshStashListHtml = function(list) {
         const html = [];
         for (const [i, l] of list.entries()) {
-            html.push('<tr class="text-center">');
+            html.push(`<tr class="text-center ${l.spss_first ? 'bg-warning-50' : ''}">`);
             html.push(`<td>${i+1}</td>`);
             html.push(`<td>${moment(l.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
             html.push(`<td>${l.user_name}</td>`);
-            html.push(`<td><button name="load-spss-stash" class="btn btn-sm btn-primary" sid="${l.id}">载入</button></td>`);
+            const firstBtn = stashCtrl.first ? `<button name="first-spss-stash" class="btn btn-sm btn-primary ml-1" sid="${l.id}">优先</button>` : '';
+            html.push(`<td><button name="load-spss-stash" class="btn btn-sm btn-primary" sid="${l.id}">载入</button>${firstBtn}</td>`);
             html.push('</tr>');
         }
         $('#spss-stash-list').html(html.join(''));
@@ -45,5 +46,16 @@ const SpssStash = function(setting){
             setting.loadStashData(result);
         });
     });
+    $('body').on('click', '[name=first-spss-stash]', function() {
+        const id = this.getAttribute('sid');
+        if (!id) {
+            toastr.warning('数据错误,请刷新页面后重试');
+            return;
+        }
+
+        postData(setting.url, { type: setting.type, action: 'first', id: id }, function(result) {
+            refreshStashListHtml(result);
+        });
+    });
     return { showStash }
 };

+ 0 - 2
app/public/js/spss_gather_ledger.js

@@ -212,8 +212,6 @@ $(document).ready(() => {
                 treeCalc.calculateAll(billsTree);
                 SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree, true);
                 posSpreadObj.loadCurPosData();
-
-                $('#stash-hint').html(`当前显示:${moment(data.create_time).format('YYYY-MM-DD HH:mm:ss')} (${data.user_name})`);
             });
         },
     });

+ 16 - 2
app/service/spss_stash.js

@@ -33,7 +33,7 @@ module.exports = app => {
         async getSpssStashList(spid, spssType) {
             const result = await this.getAllDataByCondition({
                 where: this.getCondition(spid, spssType),
-                columns: [ 'id', 'user_id', 'user_name', 'create_time' ],
+                columns: [ 'id', 'user_id', 'user_name', 'create_time', 'spss_first'],
                 orders: [['create_time', 'desc']],
             });
             if (result.length > maxStashCount) {
@@ -54,7 +54,7 @@ module.exports = app => {
         async getLatestSpssStash(spid, type) {
             const data = await this.getAllDataByCondition({
                 where: this.getCondition(spid, type),
-                orders: [['create_time', 'desc']],
+                orders: [['spss_first', 'desc'], ['create_time', 'desc']],
                 limit: 1,
                 offset: 0,
             });
@@ -75,6 +75,20 @@ module.exports = app => {
             await this.db.insert(this.tableName, data);
         }
 
+        async firstSpssStash(spid, type, id) {
+            const data = await this.getSpssStashList(spid, type);
+            if (!data.find(x => { return x.id === id})) throw '您选择的缓存数据不存在,请刷新页面后再试';
+            const updateData = [];
+            for (const d of data) {
+                if (d.id === id) {
+                    updateData.push({ id: d.id, spss_first: 1 });
+                } else if (d.spss_first) {
+                    updateData.push({ id: d.id, spss_first: 0 });
+                }
+            }
+            if (updateData.length > 0) await this.db.updateRows(this.tableName, updateData);
+            return updateData;
+        }
     }
 
     return SpssStash;

+ 4 - 1
app/view/spss/spss_stash_modal.ejs

@@ -21,4 +21,7 @@
             </div>
         </div>
     </div>
-</div>
+</div>
+<script>
+    const stashCtrl = JSON.parse('<%- JSON.stringify(stashCtrl) %>');
+</script>

+ 1 - 0
sql/update.sql

@@ -141,6 +141,7 @@ CREATE TABLE `zh_spss_stash`  (
   `spss_type` varchar(20) NOT NULL COMMENT '汇总对比类型',
   `spss_select` varchar(1000) NOT NULL COMMENT '汇总对比选择',
   `spss_result` json NULL COMMENT '汇总对比结果',
+  `spss_first` tinyint(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '报表查询优先',
   PRIMARY KEY (`id`)
 );