#!/bin/bash
# 修复 account.service.ts 中的字段名
# 只修改 Entity 字段名，保留参数名为 camelCase

# 1. 修复 where 条件中的字段名
sed -i 's/where: { userId }/where: { user_id: userId }/g' account.service.ts
sed -i 's/where: { merchantId }/where: { merchant_id: merchantId }/g' account.service.ts
sed -i 's/where: { accountName:/where: { account_name:/g' account.service.ts

# 2. 修复 create 对象中的字段名（保留参数名）
sed -i 's/userId,$/user_id: userId,/g' account.service.ts
sed -i 's/merchantId,$/merchant_id: merchantId,/g' account.service.ts
sed -i 's/accountName,$/account_name: accountName,/g' account.service.ts

# 3. 修复 account 对象的属性访问
sed -i 's/account\.frozenBalance/account.frozen_balance/g' account.service.ts
sed -i 's/account\.totalIncome/account.total_income/g' account.service.ts
sed -i 's/account\.totalExpense/account.total_expense/g' account.service.ts
sed -i 's/account\.debtAmount/account.debt_amount/g' account.service.ts

# 4. 删除不存在的字段
sed -i '/totalCashback/d' account.service.ts
sed -i '/totalWithdraw/d' account.service.ts
sed -i '/totalSettlement/d' account.service.ts
sed -i '/pendingSettlement/d' account.service.ts
sed -i '/totalOrderIncome/d' account.service.ts
sed -i '/totalRefund/d' account.service.ts
sed -i '/totalServiceFee/d' account.service.ts

# 5. 修复 transaction create 对象中的字段名
sed -i 's/\btransactionNo,$/transaction_no: transactionNo,/g' account.service.ts
sed -i 's/\buserId,$/user_id: userId,/g' account.service.ts
sed -i 's/\bmerchantId,$/merchant_id: merchantId,/g' account.service.ts
sed -i 's/\baccountId:/account_id:/g' account.service.ts
sed -i 's/\bbalanceBefore,$/balance_before: balanceBefore,/g' account.service.ts
sed -i 's/\bbalanceAfter,$/balance_after: balanceAfter,/g' account.service.ts
sed -i 's/\btransactionType:/transaction_type:/g' account.service.ts
sed -i 's/\bbusinessType,$/business_type: businessType,/g' account.service.ts
sed -i 's/\bbusinessId,$/business_id: businessId,/g' account.service.ts
sed -i 's/\bbusinessNo,$/business_no: businessNo,/g' account.service.ts
sed -i 's/\brelatedAccountType:/related_account_type:/g' account.service.ts

echo "Done"
