Sfoglia il codice sorgente

Merge branch 'master' of http://192.168.1.41:3000/maixinrong/Calculation

MaiXinRong 4 anni fa
parent
commit
7a2aea75e6

+ 10 - 0
app/const/audit.js

@@ -335,6 +335,15 @@ const material = (function() {
     return { status, statusString, statusClass, statusButton, statusButtonClass, auditProgress, auditProgressClass };
 })();
 
+// 推送类型
+const pushType = {
+    material: 1,
+    stage: 2,
+    change: 3,
+    revize: 4,
+    ledger: 5,
+};
+
 module.exports = {
     ledger,
     stage,
@@ -351,4 +360,5 @@ module.exports = {
         auditStatusClass,
     },
     filter,
+    pushType,
 };

+ 1 - 0
app/const/change.js

@@ -91,6 +91,7 @@ module.exports = {
         ke: { unit: '棵' },
         kuai: { unit: '块' },
         tai: { unit: '台' },
+        pian: { unit: '片' },
         xitong: { unit: '系统' },
         meiyishizhuang: { unit: '每一试桩' },
         qiaochangmi: { unit: '桥长米' },

+ 15 - 0
app/controller/dashboard_controller.js

@@ -210,6 +210,21 @@ module.exports = app => {
                 ctx.redirect(ctx.request.header.referer);
             }
         }
+
+        /**
+         * 将推送记录设置为已读
+         * @param {Object} ctx 上下文
+         */
+        async pushSet(ctx) {
+            try {
+                const { id } = JSON.parse(ctx.request.body.data);
+                const data = await ctx.service.noticePush.set(id);
+                ctx.body = { err: 0, msg: '' };
+            } catch (err) {
+                this.log(err);
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
     }
 
     return DashboardController;

+ 1 - 5
app/controller/material_controller.js

@@ -634,11 +634,7 @@ module.exports = app => {
                     const fileInfo = path.parse(stream.filename);
                     // const filepath = path.join('public/upload', this.ctx.tender.id.toString(), 'tc', 'fujian_' + create_time + fileInfo.ext);
                     const filepath = `public/upload/${this.ctx.tender.id.toString()}/tc/fujian_${create_time + idx.toString() + fileInfo.ext}`;
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', filepath));
-
-                    if (stream) {
-                        await sendToWormhole(stream);
-                    }
+                    await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
                     files.push({ filepath, name: stream.filename });
                     ++idx;
                 }

+ 3 - 2
app/public/js/change_set.js

@@ -650,6 +650,7 @@ function tableDataRemake(changeListData) {
                     const leafInfo = listinfo.leafXmjs.find(function (item) {
                         return (item.bwmx === undefined || item.bwmx === clinfo[2]) && (item.quantity !== null ? item.quantity === parseFloat(clinfo[5]) : 0 === parseFloat(clinfo[5]));
                     });
+                    console.log(leafInfo);
                     if (leafInfo) {
                         pushbwmx = leafInfo.code + '_' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : '') + ';' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
                     } else {
@@ -673,10 +674,10 @@ function tableDataRemake(changeListData) {
                 let pushbwmx = '0;0';
                 if (listinfo.leafXmjs !== undefined) {
                     const leafInfo = listinfo.leafXmjs.find(function (item) {
-                        return (item.bwmx === undefined || item.bwmx === clinfo[2]) && (item.quantity !== null ? item.quantity === parseFloat(clinfo[5]) : 0 === parseFloat(clinfo[5]));
+                        return (item.bwmx === undefined || item.bwmx === clinfo[2] || item.jldy === clinfo[2]) && (item.quantity !== null ? item.quantity === parseFloat(clinfo[5]) : 0 === parseFloat(clinfo[5]));
                     });
                     if (leafInfo) {
-                        pushbwmx = leafInfo.code + '_' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : '') + ';' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
+                        pushbwmx = leafInfo.code + '_' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (leafInfo.jldy ? leafInfo.jldy : '')) + ';' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
                     } else {
                         toastr.warning('台账清单列表已不存在'+ clinfo[0] +',已更新变更清单列表');
                         changeList.splice(index, 1);

+ 7 - 0
app/public/js/dashboard.js

@@ -53,4 +53,11 @@ $(document).ready(() => {
         $('#view-msg .modal-title').text('系统通知');
         $('#user_permission').html('');
     })
+
+    $('#notice').on('click', 'li a', function() {
+        const id = $(this).data('id')
+        postData(window.location.pathname + '/push', {id}, function() {
+            return
+        })
+    })
 });

+ 2 - 0
app/router.js

@@ -43,6 +43,8 @@ module.exports = app => {
     app.post('/dashboard/msg/set/:id', sessionAuth, datetimeFill, 'dashboardController.msgSet');
     app.get('/dashboard/msg/del/:id', sessionAuth, 'dashboardController.msgDelete');
 
+    // 推送相关
+    app.post('/dashboard/push', sessionAuth, 'dashboardController.pushSet');
     /**
      * 项目设置
      */

+ 59 - 28
app/service/material_audit.js

@@ -9,10 +9,7 @@
  */
 
 const auditConst = require('../const/audit').material;
-const materialConst = require('../const/material');
-// const smsTypeConst = require('../const/sms_type');
-const SMS = require('../lib/sms');
-
+const pushType = require('../const/audit').pushType;
 module.exports = app => {
     class MaterialAudit extends app.BaseService {
         /**
@@ -178,7 +175,6 @@ module.exports = app => {
 
         /**
          * 开始审批
-         *
          * @param {Number} materialId - 材料调差期id
          * @param {Number} times - 第几次审批
          * @return {Promise<boolean>}
@@ -195,9 +191,6 @@ module.exports = app => {
                 await transaction.update(this.ctx.service.material.tableName, {
                     id: materialId, status: auditConst.status.checking,
                 });
-                // 添加记录至推送表
-                await transaction.insert('zh_notice', { type: 'material', uid: audit.aid, status: auditConst.status.checking, is_read: 0, content: '待审核' });
-                console.log('1111');
                 // 本期一些必要数据(如应耗数量和上期调差金额)插入到material_bills_history表里
                 const materialBillsData = await this.ctx.service.materialBills.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
                 if (materialBillsData.length === 0) {
@@ -251,7 +244,7 @@ module.exports = app => {
             return true;
         }
 
-        async _checked(materialId, checkData, times) {
+        async _checked(pid, materialId, checkData, times) {
             const time = new Date();
             // 整理当前流程审核人状态更新
             const audit = await this.getDataByCondition({ mid: materialId, times, status: auditConst.status.checking });
@@ -269,6 +262,8 @@ module.exports = app => {
                     // await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, nextAudit.order, transaction);
                     // 流程至下一审批人
                     await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
+                    // 添加记录到推送表
+
                     // 同步 期信息
                     await transaction.update(this.ctx.service.material.tableName, {
                         id: materialId, status: auditConst.status.checking,
@@ -298,6 +293,9 @@ module.exports = app => {
                     await transaction.update(this.ctx.service.material.tableName, {
                         id: materialId, status: checkData.checkType,
                     });
+                    const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId)
+                    // 审核结束,将原报添加到推送表
+                    await transaction.insert('zh_notice', { pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checked, is_read: 0, content: noticeContent });
 
                     // 添加短信通知-审批通过提醒功能
                     // const mobile_array = [];
@@ -334,7 +332,7 @@ module.exports = app => {
             }
         }
 
-        async _checkNo(materialId, checkData, times) {
+        async _checkNo(pid, materialId, checkData, times) {
             const time = new Date();
             // 整理当前流程审核人状态更新
             const audit = await this.getDataByCondition({ mid: materialId, times, status: auditConst.status.checking });
@@ -351,11 +349,13 @@ module.exports = app => {
                 a.status = auditConst.status.uncheck;
                 order++;
             }
-
+            const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId)
             const transaction = await this.db.beginTransaction();
             try {
                 await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
-                // 同步 期信息
+                // 添加到消息推送表
+                await transaction.insert('zh_notice', { pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNo, is_read: 0, content: noticeContent });
+                // 同步期信息
                 await transaction.update(this.ctx.service.material.tableName, {
                     id: materialId, status: checkData.checkType,
                     times: times + 1,
@@ -441,6 +441,7 @@ module.exports = app => {
                     tid: audit.tid, mid: audit.mid, aid: audit.aid,
                     times: audit.times, order: audit.order + 2, status: auditConst.status.uncheck,
                 });
+
                 await transaction.insert(this.tableName, newAuditors);
                 await transaction.commit();
             } catch (error) {
@@ -460,12 +461,13 @@ module.exports = app => {
             if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.checkNoPre) {
                 throw '提交数据错误';
             }
+            const pid = this.ctx.session.sessionProject.id;
             switch (checkData.checkType) {
                 case auditConst.status.checked:
-                    await this._checked(materialId, checkData, times);
+                    await this._checked(pid, materialId, checkData, times);
                     break;
                 case auditConst.status.checkNo:
-                    await this._checkNo(materialId, checkData, times);
+                    await this._checkNo(pid, materialId, checkData, times);
                     break;
                 case auditConst.status.checkNoPre:
                     await this._checkNoPre(materialId, checkData, times);
@@ -476,6 +478,26 @@ module.exports = app => {
         }
 
         /**
+         * 用于添加推送所需的content内容
+         * @param {Number} pid 项目id
+         * @param {Number} tid 台账id
+         * @param {Number} mid 期id
+         */
+        async getNoticeContent(pid, tid, mid) {
+            const noticeSql = 'SELECT * FROM (SELECT ' +
+                '  t.`id` As `tid`, ma.`mid`, t.`name`, m.`order`, pa.`name` As `su_name`, pa.role As `su_role`' +
+                '  FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
+                '  LEFT JOIN ?? As m On t.`id` = m.`tid` AND m.`id` = ?' +
+                '  LEFT JOIN ?? As ma ON m.`id` = ma.`mid`' +
+                '  LEFT JOIN ?? As pa ON t.`user_id` = pa.`id`' +
+                '  WHERE  t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
+            const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.material.tableName, mid, this.tableName, this.ctx.service.projectAccount.tableName, pid];
+            const content = await this.db.query(noticeSql, noticeSqlParam);
+            return content.length ? JSON.stringify(content[0]) : '';
+
+        }
+
+        /**
          * 审批
          * @param {Number} materialId - 材料调差期id
          * @param {Number} times - 第几次审批
@@ -561,20 +583,29 @@ module.exports = app => {
          * @return {Promise<*>}
          */
         async getNoticeMaterial(pid, uid, time) {
-            const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
-                '    m.`order` As `m_order`, m.`status` As `m_status`, ' +
-                '    ma.`aid`, ma.`times`, ma.`order`, ma.`end_time`, ma.`tid`, ma.`mid`, ma.`status`, ' +
-                '    pa.`name` As `su_name`, pa.role As `su_role`, pa.company As `su_company`' +
-                '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `aid` = ? GROUP BY `tid`)) As t' +
-                '  LEFT JOIN ?? As m On t.`id` = m.`tid`' +
-                '  LEFT JOIN ?? As ma ON m.`id` = ma.`mid`' +
-                '  LEFT JOIN ?? As pa ON ma.`aid` = pa.`id`' +
-                '  WHERE ma.`end_time` > ? and t.`project_id` = ?' +
-                '  ORDER By ma.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`tid`' +
-                '  ORDER BY new_t.`end_time`';
-            const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.material.tableName, this.tableName,
-                this.ctx.service.projectAccount.tableName, time, pid];
-            return await this.db.query(sql, sqlParam);
+            // const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
+            //     '    m.`order` As `m_order`, m.`status` As `m_status`, ' +
+            //     '    ma.`aid`, ma.`times`, ma.`order`, ma.`end_time`, ma.`tid`, ma.`mid`, ma.`status`, ' +
+            //     '    pa.`name` As `su_name`, pa.role As `su_role`, pa.company As `su_company`' +
+            //     '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `aid` = ? GROUP BY `tid`)) As t' +
+            //     '  LEFT JOIN ?? As m On t.`id` = m.`tid`' +
+            //     '  LEFT JOIN ?? As ma ON m.`id` = ma.`mid`' +
+            //     '  LEFT JOIN ?? As pa ON ma.`aid` = pa.`id`' +
+            //     '  WHERE ma.`end_time` > ? and t.`project_id` = ?' +
+            //     '  ORDER By ma.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`tid`' +
+            //     '  ORDER BY new_t.`end_time`';
+            // const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.material.tableName, this.tableName,
+            //     this.ctx.service.projectAccount.tableName, time, pid];
+            // return await this.db.query(sql, sqlParam);
+            let notice =  await this.db.select('zh_notice', {
+                where: { pid, type: pushType.material, uid, is_read: 0 },
+            });
+            notice = notice.map(v => {
+                const extra = JSON.parse(v.content)
+                delete v.content
+                return { ...v, ...extra }
+            })
+            return notice;
         }
 
         /**

+ 35 - 0
app/service/notice_push.js

@@ -0,0 +1,35 @@
+'use strict';
+
+/**
+ * 推送表模型
+ *
+ * @author LanJianRong
+ * @date 2017/11/16
+ * @version
+ */
+
+module.exports = app => {
+
+    class NoticePush extends app.BaseService {
+
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'notice';
+        }
+
+        /**
+         * 将未读记录设置成已读
+         * @param {Number} id 推送记录id
+         */
+        async set(id) {
+            await this.update({ is_read: 1 }, { id });
+        }
+    }
+    return NoticePush;
+};

+ 9 - 5
app/service/tender.js

@@ -266,6 +266,11 @@ module.exports = app => {
         async deleteTenderNoBackup(id) {
             const transaction = await this.db.beginTransaction();
             try {
+                // 先删除附件文件
+                const attList = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { tid: id } });
+                const newAttList = await this.ctx.service.materialFile.getAllMaterialFiles(id);
+                attList.concat(newAttList);
+                await this.ctx.helper.delFiles(attList);
                 await transaction.delete(this.tableName, { id });
                 await transaction.delete(this.ctx.service.tenderInfo.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.ledger.tableName, { tender_id: id });
@@ -296,13 +301,12 @@ module.exports = app => {
                 await transaction.delete(this.ctx.service.materialBillsHistory.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.materialList.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.materialListNotjoin.tableName, { tid: id });
+
+
+                await transaction.delete(this.ctx.service.materialFile.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.signatureUsed.tableName, { tender_id: id });
                 await transaction.delete(this.ctx.service.signatureRole.tableName, { tender_id: id });
-                // 先删除附件文件
-                const attList = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { tid: id } });
-                const newAttList = await this.ctx.service.materialFile.getAllMaterialFiles(id);
-                attList.concat(newAttList);
-                await this.ctx.helper.delFiles(attList);
+
                 await transaction.delete(this.ctx.service.changeAtt.tableName, { tid: id });
                 await transaction.delete(this.ctx.service.materialFile.tableName, { tid: id });
                 await transaction.commit();

+ 11 - 11
app/view/dashboard/index.ejs

@@ -158,14 +158,14 @@
                         <div class="card-header">需要你关注</div>
                         <div class="card-body">
                             <% if (noticeLedger.length !== 0 || noticeRevise.length !== 0 || noticeStage.length !== 0 || noticeChange.length !== 0 || noticeMaterial.length !== 0) { %>
-                                <ul class="list-unstyled m-0">
+                                <ul id="notice" class="list-unstyled m-0">
                                     <% for (const nl of noticeLedger) { %>
                                         <li class="media pb-3 mb-3 border-bottom-1">
                                             <div class="media-body">
                                                 <div class="row">
                                                     <div class="col-auto"><span class="badge badge-info">台帐审批</span></div>
                                                     <div class="col-6">
-                                                        <a href="/tender/<%- nl.id %>"><%- nl.name %></a> 台帐<%- acLedger.statusString[nl.status]%>
+                                                        <a data-id="<%- nl.id %>"href="/tender/<%- nl.id %>"><%- nl.name %></a> 台帐<%- acLedger.statusString[nl.status]%>
                                                     </div>
                                                 </div>
                                                 <p class="mt-1 mb-0"><%- nl.lu_name %><small class="ml-1 text-muted"><%- (nl.lu_role ? '- ' + nl.lu_role : '') %></small>
@@ -180,8 +180,8 @@
                                                 <div class="row">
                                                     <div class="col-auto"><span class="badge badge-info">台账修订</span></div>
                                                     <div class="col-6">
-                                                        <a href="/tender/<%- nr.t_id %>"><%- nr.t_name %></a>
-                                                        <a href="/tender/<%- nr.t_id %>/revise/info">台账修订(第<%- nr.corder %>次)</a>
+                                                        <a data-id="<%- nr.id %>" href="/tender/<%- nr.t_id %>"><%- nr.t_name %></a>
+                                                        <a data-id="<%- nr.id %>" href="/tender/<%- nr.t_id %>/revise/info">台账修订(第<%- nr.corder %>次)</a>
                                                         <%- acRevise.statusString[nr.status]%>
                                                     </div>
                                                 </div>
@@ -197,8 +197,8 @@
                                                 <div class="row">
                                                     <div class="col-auto"><span class="badge badge-success">计量审批</span></div>
                                                     <div class="col-6">
-                                                        <a href="/tender/<%- ns.tid %>"><%- ns.name %></a>
-                                                        <a href="/tender/<%- ns.tid %>/measure/stage/<%- ns.s_order %>">第<%- ns.s_order %>期 </a>
+                                                        <a data-id="<%- ns.id %>" href="/tender/<%- ns.tid %>"><%- ns.name %></a>
+                                                        <a data-id="<%- ns.id %>" href="/tender/<%- ns.tid %>/measure/stage/<%- ns.s_order %>">第<%- ns.s_order %>期 </a>
                                                         <%- acStage.statusString[ns.status]%>
                                                     </div>
                                                 </div>
@@ -214,8 +214,8 @@
                                                 <div class="row">
                                                     <div class="col-auto"><span class="badge badge-danger">变更审批</span></div>
                                                     <div class="col-6">
-                                                        <a href="/tender/<%- nc.id %>"><%- nc.name %></a>
-                                                        <a href="/tender/<%- nc.id %>/change/<%- nc.cid %>/info"><%- nc.c_code %> </a>
+                                                        <a data-id="<%- nc.id %>" href="/tender/<%- nc.id %>"><%- nc.name %></a>
+                                                        <a data-id="<%- nc.id %>" href="/tender/<%- nc.id %>/change/<%- nc.cid %>/info"><%- nc.c_code %> </a>
                                                         <%- acChange.statusString[nc.cu_status]%>
                                                     </div>
                                                 </div>
@@ -231,13 +231,13 @@
                                                 <div class="row">
                                                     <div class="col-auto"><span class="badge badge-secondary">材料调差</span></div>
                                                     <div class="col-6">
-                                                        <a href="/tender/<%- nm.tid %>"><%- nm.name %></a>
-                                                        <a href="/tender/<%- nm.tid %>/measure/material/<%- nm.m_order %>">第<%- nm.m_order %>期 </a>
+                                                        <a data-id="<%- nm.id %>" href="/tender/<%- nm.tid %>"><%- nm.name %></a>
+                                                        <a data-id="<%- nm.id %>" href="/tender/<%- nm.tid %>/measure/material/<%- nm.order %>">第<%- nm.order %>期 </a>
                                                         <%- acMaterial.statusString[nm.status]%>
                                                     </div>
                                                 </div>
                                                 <p class="mt-1 mb-0"><%- nm.su_name %><small class="ml-1 text-muted"><%- (nm.su_role ? '- ' + nm.su_role : '') %></small>
-                                                    <span class="pull-right text-muted"><%- nm.end_time.toLocaleString() %></span>
+                                                    <span class="pull-right text-muted"><%- ctx.helper.formatFullDate(nm.create_time) %></span>
                                                 </p>
                                             </div>
                                         </li>

+ 14 - 0
sql/update20200728.sql

@@ -115,3 +115,17 @@ CREATE TABLE `zh_material_file` (
   `s_order` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '期数order',
   PRIMARY KEY (`id`)
 )COMMENT = '调差附件表';
+
+CREATE TABLE `zh_notice` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `type` int(11) NOT NULL COMMENT '推送的类型',
+  `uid` int(11) NOT NULL COMMENT '接收者id',
+  `status` int(11) NOT NULL COMMENT '状态',
+  `is_read` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已读,0:未读,1:已读',
+  `create_time` datetime DEFAULT CURRENT_TIMESTAMP,
+  `pid` int(11) NOT NULL COMMENT '项目id',
+  `content` text COLLATE utf8_unicode_ci NOT NULL COMMENT '推送必要的查询字段,如 ''{tid, mid}''',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='关注推送表';
+SELECT * FROM calculation.zh_notice;
+