From 5de178d96443397c1f12b48f781a7cfda81cf610 Mon Sep 17 00:00:00 2001 From: zhuotianyuan Date: Fri, 9 Jan 2026 18:57:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=AE=A2=E5=8D=95=E6=9C=8D=E5=8A=A1):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=A2=E5=8D=95=E5=86=85=E5=AE=B9=E6=8B=AC?= =?UTF-8?q?=E5=8F=B7=E5=A4=84=E7=90=86=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加订单同步过程的调试日志 修复订单内容中括号内容的处理逻辑 修正控制器方法名拼写错误 --- src/controller/statistics.controller.ts | 2 +- src/service/order.service.ts | 85 ++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/src/controller/statistics.controller.ts b/src/controller/statistics.controller.ts index 424c380..c873c78 100644 --- a/src/controller/statistics.controller.ts +++ b/src/controller/statistics.controller.ts @@ -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) { diff --git a/src/service/order.service.ts b/src/service/order.service.ts index e153323..24293eb 100644 --- a/src/service/order.service.ts +++ b/src/service/order.service.ts @@ -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; + } + + + }