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