Jelajahi Sumber

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

TonyKang 3 tahun lalu
induk
melakukan
5c96fe67b2

+ 22 - 0
app/const/sync_api.js

@@ -0,0 +1,22 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author EllisRan
+ * @date 2021/9/15
+ * @version
+ */
+
+const api_url = {
+    notice: 'api/notice',
+};
+
+const notice_type = ['zj'];
+
+
+module.exports = {
+    api_url,
+    notice_type,
+
+};

+ 32 - 1
app/extend/helper.js

@@ -21,6 +21,8 @@ const WX = require('../lib/wechat');
 const timesLen = 100;
 const UAParser = require('ua-parser-js');
 const math = require('mathjs');
+const syncApiConst = require('../const/sync_api');
+const crypto = require('crypto');
 
 module.exports = {
     _,
@@ -1384,5 +1386,34 @@ module.exports = {
                 }
             }
         }
-    }
+    },
+
+    /**
+     * 发送请求获取详细地址
+     * @param {String} type - 通知类型
+     * @param {String} datas - 请求发送数据
+     * @return {Object} the result of request
+     * @private
+     */
+    async syncNoticeSend(type, datas) {
+        const key = this.ctx.session.sessionProject.code;
+        const time = new Date().getTime();
+        const projectData = await this.ctx.service.project.getDataById(this.ctx.session.sessionProject.id);
+        const sign = crypto.createHash('md5').update(key + projectData.secret + time.toString()).digest('hex').toString();
+        const res = await this.ctx.curl(this.ctx.app.config.syncUrl + syncApiConst.api_url.notice, {
+            method: 'POST',
+            contentType: 'json',
+            data: {
+                projectCode: key,
+                key,
+                time,
+                sign,
+                customType: type,
+                base_data: datas,
+            },
+            dateType: 'json',
+            timeout: [30000, 60000],
+            timing: true,
+        });
+    },
 };

+ 2 - 0
app/middleware/session_auth.js

@@ -34,6 +34,8 @@ module.exports = options => {
             this.session.sessionUser.permission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
             const projectData = yield this.service.project.getDataById(this.session.sessionProject.id);
             this.session.sessionProject.page_show = yield this.service.projectAccount.getPageShow(projectData.page_show);
+            this.session.sessionProject.custom = projectData.custom;
+            this.session.sessionProject.customType = projectData.customType;
 
             // 同步消息
             yield this.service.notify.syncNotifyData();

+ 1 - 0
app/service/project_account.js

@@ -135,6 +135,7 @@ module.exports = app => {
                         userAccount: projectData.user_account,
                         custom: projectData.custom,
                         page_show: await this.getPageShow(projectData.page_show),
+                        customType: projectData.customType,
                     };
 
                     // 查找对应数据

+ 27 - 0
app/service/stage.js

@@ -15,6 +15,7 @@ const fs = require('fs');
 const path = require('path');
 const _ = require('lodash');
 const projectLogConst = require('../const/project_log');
+const syncApiConst = require('../const/sync_api');
 
 module.exports = app => {
     class Stage extends app.BaseService {
@@ -381,6 +382,19 @@ module.exports = app => {
                 }
 
                 await transaction.commit();
+                // 通知发送 - 第三方更新
+                if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
+                    const base_data = {
+                        tid: tenderId,
+                        sid: result.insertId,
+                        op: 'insert',
+                    };
+                    this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                    // 存在上一期时
+                    base_data.op = preStage ? 'update' : 'insert';
+                    base_data.sid = -1;
+                    this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                }
                 return newStage;
             } catch (err) {
                 await transaction.rollback();
@@ -499,6 +513,19 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 const stageInfo = await this.getDataById(id);
+                // 通知发送 - 第三方更新
+                if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
+                    const base_data = {
+                        tid: this.ctx.tender.id,
+                        sid: id,
+                        op: 'delete',
+                    };
+                    await this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                    // 是否还存在其他期
+                    base_data.op = stageInfo.order === 1 ? 'delete' : 'update';
+                    base_data.sid = -1;
+                    await this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                }
                 await transaction.delete(this.tableName, { id });
                 await transaction.delete(this.ctx.service.pos.tableName, { add_stage: id });
                 await transaction.delete(this.ctx.service.stageAudit.tableName, { sid: id });

+ 49 - 0
app/service/stage_audit.js

@@ -16,6 +16,7 @@ const wxConst = require('../const/wechat_template');
 const shenpiConst = require('../const/shenpi');
 const payConst = require('../const/deal_pay');
 const pushType = require('../const/audit').pushType;
+const syncApiConst = require('../const/sync_api');
 
 module.exports = app => {
     class StageAudit extends app.BaseService {
@@ -335,6 +336,18 @@ module.exports = app => {
 
                 // todo 更新标段tender状态 ?
                 await transaction.commit();
+                // 通知发送 - 第三方更新
+                if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
+                    const base_data = {
+                        tid: this.ctx.tender.id,
+                        sid: stageId,
+                        op: 'update',
+                    };
+                    this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                    base_data.op = 'update';
+                    base_data.sid = -1;
+                    this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                }
             } catch (err) {
                 await transaction.rollback();
                 throw err;
@@ -832,6 +845,18 @@ module.exports = app => {
                 default:
                     throw '无效审批操作';
             }
+            // 通知发送 - 第三方更新
+            if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
+                const base_data = {
+                    tid: this.ctx.tender.id,
+                    sid: stageId,
+                    op: 'update',
+                };
+                this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                base_data.op = 'update';
+                base_data.sid = -1;
+                this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+            }
         }
 
         /**
@@ -932,6 +957,18 @@ module.exports = app => {
                 await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
 
                 await transaction.commit();
+                // 通知发送 - 第三方更新
+                if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
+                    const base_data = {
+                        tid: this.ctx.tender.id,
+                        sid: stageId,
+                        op: 'update',
+                    };
+                    this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                    base_data.op = 'update';
+                    base_data.sid = -1;
+                    this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                }
             } catch (err) {
                 await transaction.rollback();
                 throw err;
@@ -1258,6 +1295,18 @@ module.exports = app => {
                     cache_time_r: time,
                 });
                 await transaction.commit();
+                // 通知发送 - 第三方更新
+                if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
+                    const base_data = {
+                        tid: this.ctx.tender.id,
+                        sid: this.ctx.stage.id,
+                        op: 'update',
+                    };
+                    this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                    base_data.op = 'update';
+                    base_data.sid = -1;
+                    this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
+                }
             } catch (err) {
                 await transaction.rollback();
                 throw err;

+ 2 - 0
app/view/measure/stage_modal.ejs

@@ -139,6 +139,8 @@
             toastr.error('请选择开始-截止日期');
             return false;
         }
+        console.log($('#edit-period').val());
+        return false;
     };
     <% } %>
     $('.datepicker-here').datepicker({

+ 2 - 0
config/config.default.js

@@ -212,5 +212,7 @@ module.exports = appInfo => {
         },
     };
 
+    config.syncUrl = 'https://sync.jl.smartcost.com.cn/';
+
     return config;
 };

+ 2 - 0
config/config.local.js

@@ -88,6 +88,8 @@ module.exports = appInfo => {
         appid: 'wx3d5394b238a3bc9a',
         appsecret: '457d64c55f48f57cd22eca47e53d15cb',
     };
+    // 自带接口系统地址
+    config.syncUrl = 'http://127.0.0.1:7169/';
 
     config.is_debug = true;
 

+ 2 - 0
config/config.qa.js

@@ -52,6 +52,8 @@ module.exports = appInfo => {
         //renew: true, // session临近过期更新过期时间
         rolling: true, // 每次都更新session有效期
     };
+    // 自带接口系统地址
+    config.syncUrl = 'http://jlqa.smartcost.com.cn:7169/';
 
     config.is_debug = true;
 

+ 2 - 0
config/config.uat.js

@@ -59,5 +59,7 @@ module.exports = appInfo => {
         appsecret: 'ca7c0dbd9e94dc3b1c3b0e73865743f4',
     };
 
+    config.syncUrl = 'http://sync.jluat.smartcost.com.cn/';
+
     return config;
 };

+ 28 - 1
sql/update.sql

@@ -86,4 +86,31 @@ CREATE TABLE `zh_stage_rela_pos_final` (
 ) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
 ALTER TABLE `zh_rpt_archive`
-CHANGE COLUMN `content` `content` JSON NULL DEFAULT NULL ;
+CHANGE COLUMN `content` `content` JSON NULL DEFAULT NULL ;
+
+CREATE TABLE `zh_s2b_z_proj` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `pid` int(11) NOT NULL COMMENT '项目id',
+  `xmName` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '项目发改全称',
+  `xmCode` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '项目发改赋码',
+  `opCode` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '来源编码',
+  `base_data` text COLLATE utf8_unicode_ci COMMENT '用来存定制接口所需参数',
+  PRIMARY KEY (`id`),
+  KEY `pid` (`pid`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+-- --------------------------------------------------------
+
+--
+-- 表的结构 `zh_s2b_z_tender`
+--
+
+CREATE TABLE `zh_s2b_z_tender` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `tid` int(11) NOT NULL COMMENT '标段id',
+  `base_data` text COLLATE utf8_unicode_ci COMMENT 'json,一些需要的数据',
+  PRIMARY KEY (`id`),
+  KEY `tid` (`tid`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='浙江项目标段表';
+
+ALTER TABLE `zh_project` ADD `customType` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '定制项目通知类型参数' AFTER `secret`;