fix(订单服务): 修复订单内容括号处理并添加同步日志
添加订单同步过程的调试日志 修复订单内容中括号内容的处理逻辑 修正控制器方法名拼写错误
This commit is contained in:
parent
af10bbe704
commit
5de178d964
|
|
@ -79,7 +79,7 @@ export class StatisticsController {
|
|||
|
||||
@ApiOkResponse()
|
||||
@Get('/orderSource')
|
||||
async getOrderSorce(@Query() params) {
|
||||
async getOrderSource(@Query() params) {
|
||||
try {
|
||||
return successResponse(await this.statisticsService.getOrderSorce(params));
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ export class OrderService {
|
|||
updated: 0,
|
||||
errors: []
|
||||
};
|
||||
|
||||
console.log('开始进入循环同步订单', result.length, '个订单')
|
||||
// 遍历每个订单进行同步
|
||||
for (const order of result) {
|
||||
try {
|
||||
|
|
@ -162,6 +162,7 @@ export class OrderService {
|
|||
} else {
|
||||
syncResult.created++;
|
||||
}
|
||||
// console.log('updated', syncResult.updated, 'created:', syncResult.created)
|
||||
} catch (error) {
|
||||
// 记录错误但不中断整个同步过程
|
||||
syncResult.errors.push({
|
||||
|
|
@ -171,6 +172,8 @@ export class OrderService {
|
|||
syncResult.processed++;
|
||||
}
|
||||
}
|
||||
console.log('同步完成', syncResult.updated, 'created:', syncResult.created)
|
||||
|
||||
this.logger.debug('syncOrders result', syncResult)
|
||||
return syncResult;
|
||||
}
|
||||
|
|
@ -2545,7 +2548,7 @@ export class OrderService {
|
|||
'姓名地址': nameAddress,
|
||||
'邮箱': order.customer_email || '',
|
||||
'号码': phone,
|
||||
'订单内容': orderContent,
|
||||
'订单内容': this.removeLastParenthesesContent(orderContent),
|
||||
'盒数': boxCount,
|
||||
'换盒数': exchangeBoxCount,
|
||||
'换货内容': exchangeContent,
|
||||
|
|
@ -2646,6 +2649,84 @@ async exportToCsv(data: any[], options: { type?: 'string' | 'buffer'; fileName?:
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除每个分号前面一个左右括号和最后一个左右括号包含的内容(包括括号本身)
|
||||
* @param str 输入字符串
|
||||
* @returns 删除后的字符串
|
||||
*/
|
||||
removeLastParenthesesContent(str: string): string {
|
||||
if (!str || typeof str !== 'string') {
|
||||
return str;
|
||||
}
|
||||
|
||||
// 辅助函数:删除指定位置的括号对及其内容
|
||||
const removeParenthesesAt = (s: string, leftIndex: number): string => {
|
||||
if (leftIndex === -1) return s;
|
||||
|
||||
let rightIndex = -1;
|
||||
let parenCount = 0;
|
||||
|
||||
for (let i = leftIndex; i < s.length; i++) {
|
||||
const char = s[i];
|
||||
if (char === '(') {
|
||||
parenCount++;
|
||||
} else if (char === ')') {
|
||||
parenCount--;
|
||||
if (parenCount === 0) {
|
||||
rightIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rightIndex !== -1) {
|
||||
return s.substring(0, leftIndex) + s.substring(rightIndex + 1);
|
||||
}
|
||||
|
||||
return s;
|
||||
};
|
||||
|
||||
// 1. 处理每个分号前面的括号对
|
||||
let result = str;
|
||||
|
||||
// 找出所有分号的位置
|
||||
const semicolonIndices: number[] = [];
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
if (result[i] === ';') {
|
||||
semicolonIndices.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
// 从后向前处理每个分号,避免位置变化影响后续处理
|
||||
for (let i = semicolonIndices.length - 1; i >= 0; i--) {
|
||||
const semicolonIndex = semicolonIndices[i];
|
||||
|
||||
// 从分号位置向前查找最近的左括号
|
||||
let lastLeftParenIndex = -1;
|
||||
for (let j = semicolonIndex - 1; j >= 0; j--) {
|
||||
if (result[j] === '(') {
|
||||
lastLeftParenIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果找到左括号,删除该括号对及其内容
|
||||
if (lastLeftParenIndex !== -1) {
|
||||
result = removeParenthesesAt(result, lastLeftParenIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 处理整个字符串的最后一个括号对
|
||||
let lastLeftParenIndex = result.lastIndexOf('(');
|
||||
if (lastLeftParenIndex !== -1) {
|
||||
result = removeParenthesesAt(result, lastLeftParenIndex);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue