订单详情
This commit is contained in:
@@ -22,6 +22,7 @@ ALIYUN_APS_DB_PASSWORD=
|
|||||||
ALIYUN_APS_DB_NAME=
|
ALIYUN_APS_DB_NAME=
|
||||||
ALIYUN_APS_DB_CHARSET=utf8mb4
|
ALIYUN_APS_DB_CHARSET=utf8mb4
|
||||||
ALIYUN_APS_DB_CONNECTION_LIMIT=5
|
ALIYUN_APS_DB_CONNECTION_LIMIT=5
|
||||||
|
ALIYUN_APS_DB_CONNECT_TIMEOUT=20000
|
||||||
ALIYUN_APS_SMTP_HOST=smtp.163.com
|
ALIYUN_APS_SMTP_HOST=smtp.163.com
|
||||||
ALIYUN_APS_SMTP_PORT=465
|
ALIYUN_APS_SMTP_PORT=465
|
||||||
ALIYUN_APS_SMTP_SECURE=true
|
ALIYUN_APS_SMTP_SECURE=true
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export const config = {
|
|||||||
database: process.env.ALIYUN_APS_DB_NAME || '',
|
database: process.env.ALIYUN_APS_DB_NAME || '',
|
||||||
charset: process.env.ALIYUN_APS_DB_CHARSET || 'utf8mb4',
|
charset: process.env.ALIYUN_APS_DB_CHARSET || 'utf8mb4',
|
||||||
connectionLimit: Math.max(1, Number.parseInt(process.env.ALIYUN_APS_DB_CONNECTION_LIMIT || '5', 10) || 5),
|
connectionLimit: Math.max(1, Number.parseInt(process.env.ALIYUN_APS_DB_CONNECTION_LIMIT || '5', 10) || 5),
|
||||||
|
connectTimeout: Math.max(1000, Number.parseInt(process.env.ALIYUN_APS_DB_CONNECT_TIMEOUT || '20000', 10) || 20000),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import mysql from 'mysql2/promise';
|
|||||||
import { config } from './config.js';
|
import { config } from './config.js';
|
||||||
|
|
||||||
let pool = null;
|
let pool = null;
|
||||||
|
let customerMapCache = null;
|
||||||
|
|
||||||
const MESSAGE_TABLE_DDL = `
|
const MESSAGE_TABLE_DDL = `
|
||||||
CREATE TABLE IF NOT EXISTS aliyun_aps_messages (
|
CREATE TABLE IF NOT EXISTS aliyun_aps_messages (
|
||||||
@@ -52,6 +53,7 @@ function getPool() {
|
|||||||
database: config.db.database,
|
database: config.db.database,
|
||||||
charset: config.db.charset,
|
charset: config.db.charset,
|
||||||
connectionLimit: config.db.connectionLimit,
|
connectionLimit: config.db.connectionLimit,
|
||||||
|
connectTimeout: config.db.connectTimeout,
|
||||||
waitForConnections: true,
|
waitForConnections: true,
|
||||||
});
|
});
|
||||||
return pool;
|
return pool;
|
||||||
@@ -130,6 +132,9 @@ function safeDateTime(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getCustomerMap() {
|
async function getCustomerMap() {
|
||||||
|
if (customerMapCache) {
|
||||||
|
return customerMapCache;
|
||||||
|
}
|
||||||
const [rows] = await getPool().query('SELECT account_id, login_name FROM aps_customer');
|
const [rows] = await getPool().query('SELECT account_id, login_name FROM aps_customer');
|
||||||
const map = new Map();
|
const map = new Map();
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
@@ -141,7 +146,8 @@ async function getCustomerMap() {
|
|||||||
map.set(loginName, accountId);
|
map.set(loginName, accountId);
|
||||||
map.set(loginName.replace(/\s+/g, ''), accountId);
|
map.set(loginName.replace(/\s+/g, ''), accountId);
|
||||||
}
|
}
|
||||||
return map;
|
customerMapCache = map;
|
||||||
|
return customerMapCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveCustomerAccountId(customerMap, customerAccount) {
|
function resolveCustomerAccountId(customerMap, customerAccount) {
|
||||||
@@ -186,6 +192,7 @@ export async function closeDbPool() {
|
|||||||
}
|
}
|
||||||
await pool.end();
|
await pool.end();
|
||||||
pool = null;
|
pool = null;
|
||||||
|
customerMapCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function ensureMessagesTable() {
|
export async function ensureMessagesTable() {
|
||||||
|
|||||||
Reference in New Issue
Block a user