Commit 1782376d by Sxy

feat: 加密

parent d1dcc3e4
......@@ -15,7 +15,7 @@ class BizOptCtl extends CtlBase {
let result = [];
for (let val of rs.results.rows) {
val.company_name = val.business_info.company;
val.customer_number = val.business_info.contactsPhone;
val.customer_number = system.decryptStr(val.business_info.contactsPhone);
val.customer_name = val.business_info.contactsName;
val.updated_at = moment(val.updated_at).format('YYYY-MM-DD HH:mm:ss');
val.created_at = moment(val.created_at).format('YYYY-MM-DD HH:mm:ss');
......
......@@ -15,7 +15,7 @@ class DeliverCtl extends CtlBase {
let result = [];
for (let val of rs.results.rows) {
val.company_name = val.delivery_info.companyName;
val.customer_number = val.delivery_info.contactsPhone;
val.customer_number = system.decryptStr(val.delivery_info.contactsPhone);
val.customer_name = val.delivery_info.contactsName;
val.service_address = val.delivery_info.serviceName;
val.updated_at = moment(val.updated_at).format('YYYY-MM-DD HH:mm:ss');
......
......@@ -20,7 +20,14 @@ module.exports = (db, DataTypes) => {
},
business_info: { // 商机详情
allowNull: false,
type: DataTypes.JSON
type: DataTypes.JSON,
get() {
let value = this.getDataValue('business_info');
return (value && {
...value,
contactsPhone: system.decryptStr(value.contactsPhone)
}) || value
}
},
source_number: { // 来源单号 (下单时产生的编号)
allowNull: true,
......
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
const { encryptStr, decryptStr } = system;
/**
* 材料缓存表
*/
......@@ -8,7 +9,14 @@ module.exports = (db, DataTypes) => {
return db.define("cacheinfo", {
cache_info: {
allowNull: false,
type: DataTypes.JSON
type: DataTypes.JSON,
set(value) {
this.setDataValue('cache_info', buildValue(value, encryptStr));
},
get() {
let value = this.getDataValue("cache_info");
return buildValue(value, decryptStr);
}
},
}, {
paranoid: false,//假的删除
......@@ -55,3 +63,43 @@ module.exports = (db, DataTypes) => {
});
}
/**
* 加密解密组装
* @param {*} value
* @param {*} cryptStr
*/
function buildValue(value, cryptStr) {
if (value) {
let newValue = JSON.parse(JSON.stringify(value));
if (newValue.proposerInfo) {
if (newValue.proposerInfo.contactInfo) {
newValue.proposerInfo.contactInfo.phone = cryptStr(newValue.proposerInfo.contactInfo.phone);
}
if (newValue.proposerInfo.recipientInfo) {
newValue.proposerInfo.recipientInfo.phone = cryptStr(newValue.proposerInfo.recipientInfo.phone);
}
if (newValue.proposerInfo.principalInfo) {
newValue.proposerInfo.principalInfo = newValue.proposerInfo.principalInfo.map(val => {
return {
...val,
certificateId: cryptStr(val.certificateId),
phone: cryptStr(val.phone)
}
})
}
}
if (newValue.shareholderData) {
newValue.shareholderData = newValue.shareholderData.map(val => {
return {
...val,
idNumber: cryptStr(val.idNumber)
}
})
}
return newValue;
} else {
return value;
}
}
......@@ -40,7 +40,14 @@ module.exports = (db, DataTypes) => {
},
delivery_info: { //服务概况
allowNull: false,
type: DataTypes.JSON
type: DataTypes.JSON,
get() {
let value = this.getDataValue('delivery_info');
return (value && {
...value,
contactsPhone: system.decryptStr(value.contactsPhone)
}) || value
}
},
delivery_status: {// 服务单流转状态
allowNull: false,
......
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
const { encryptStr, decryptStr } = system;
/**
* 材料表
*/
......@@ -8,11 +10,25 @@ module.exports = (db, DataTypes) => {
return db.define("material", {
proposerInfo: {
allowNull: false,
type: DataTypes.JSON
type: DataTypes.JSON,
set(value) {
this.setDataValue('proposerInfo', buildProposerInfo(value, encryptStr));
},
get() {
let value = this.getDataValue("proposerInfo");
return buildProposerInfo(value, decryptStr);
}
},
shareholderData: {
allowNull: false,
type: DataTypes.JSON
type: DataTypes.JSON,
set(value) {
this.setDataValue('shareholderData', buildShareholderData(value, encryptStr));
},
get() {
let value = this.getDataValue("shareholderData");
return buildShareholderData(value, decryptStr);
}
},
implementationPlanInfo: {
allowNull: false,
......@@ -79,3 +95,44 @@ module.exports = (db, DataTypes) => {
});
}
function buildProposerInfo(value, cryptStr) {
if (value) {
let newValue = JSON.parse(JSON.stringify(value));
if (newValue.contactInfo) {
newValue.contactInfo.phone = cryptStr(newValue.contactInfo.phone);
}
if (newValue.recipientInfo) {
newValue.recipientInfo.phone = cryptStr(newValue.recipientInfo.phone);
}
if (newValue.principalInfo) {
newValue.principalInfo = newValue.principalInfo.map(val => {
return {
...val,
certificateId: cryptStr(val.certificateId),
phone: cryptStr(val.phone)
}
})
}
return newValue;
} else {
return value;
}
}
function buildShareholderData(value, cryptStr) {
if (value) {
let newValue = JSON.parse(JSON.stringify(value));
newValue = value.map(val => {
return {
...val,
idNumber: cryptStr(val.idNumber)
}
})
return newValue
} else {
return value;
}
}
......@@ -323,13 +323,17 @@ class System {
if (!opStr) {
return opStr;
}
let keyHex = cryptoJS.enc.Utf8.parse(settings.encrypt_key);
let ivHex = cryptoJS.enc.Utf8.parse(settings.encrypt_secret.substring(0, 8));
var bytes = cryptoJS.TripleDES.decrypt(opStr, keyHex, {
iv: ivHex
});
var plaintext = bytes.toString(cryptoJS.enc.Utf8);
return plaintext;
try {
let keyHex = cryptoJS.enc.Utf8.parse(settings.encrypt_key);
let ivHex = cryptoJS.enc.Utf8.parse(settings.encrypt_secret.substring(0, 8));
var bytes = cryptoJS.TripleDES.decrypt(opStr, keyHex, {
iv: ivHex
});
var plaintext = bytes.toString(cryptoJS.enc.Utf8);
return plaintext || opStr;
} catch (err) {
return opStr;
}
}
}
Date.prototype.Format = function (fmt) { //author: meizz
......
......@@ -2,6 +2,7 @@ const axios = require("axios");
const settings = require("../../config/settings");
const system = require("../system");
const annualreportDao = system.getObject("db.delivery.annualreportDao");
const { encryptStr, decryptStr } = system;
const BUSINESSTYPE = {
ICP: "/qcfw/icp/",
......@@ -108,6 +109,7 @@ const pushChangeOrder = async (status, orderNum, data = {}) => {
* @param {*} materials
*/
const submitMaterials = async (deliverData, materials) => {
materials = buildValue(materials, encryptStr);
let status;
if (deliverData.delivery_status === system.SERVERSESTATUS.COLLECTING || deliverData.delivery_status === system.SERVERSESTATUS.SUBMITING) {
status = TXSTATUS.SUBMITING;
......@@ -214,6 +216,41 @@ const postRequest = async (url, data) => {
}
function buildValue(value, cryptStr) {
if (value) {
let newValue = JSON.parse(JSON.stringify(value));
if (newValue.proposerInfo) {
if (newValue.proposerInfo.contactInfo) {
newValue.proposerInfo.contactInfo.phone = cryptStr(newValue.proposerInfo.contactInfo.phone);
}
if (newValue.proposerInfo.recipientInfo) {
newValue.proposerInfo.recipientInfo.phone = cryptStr(newValue.proposerInfo.recipientInfo.phone);
}
if (newValue.proposerInfo.principalInfo) {
newValue.proposerInfo.principalInfo = newValue.proposerInfo.principalInfo.map(val => {
return {
...val,
certificateId: cryptStr(val.certificateId),
phone: cryptStr(val.phone)
}
})
}
}
if (newValue.shareholderData) {
newValue.shareholderData = newValue.shareholderData.map(val => {
return {
...val,
idNumber: cryptStr(val.idNumber)
}
})
}
return newValue;
} else {
return value;
}
}
module.exports = {
......
......@@ -15,6 +15,8 @@ var ENVINPUT = {
};
var settings = {
env: ENVINPUT.APP_ENV,
encrypt_key: ENVINPUT.ENCRYPT_KEY,
encrypt_secret: ENVINPUT.ENCRYPT_SECRET,
salt: "%iatpD1gcxz7iF#B",
defaultpwd: "gsb2020",
basepath: path.normalize(path.join(__dirname, '../..')),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment