Files
kami_backend/internal/logic/camel_oil/account_history.go
danial 15e2426e85 feat(camel_oil): 新增骆驼加油账号管理模块
- 实现账号增删改查接口和逻辑
- 支持账号状态更新及状态历史记录功能
- 提供账号列表、历史和统计信息查询API
- 实现账号轮询机制,支持按使用时间轮询获取账号
- 增加账号登录流程及批量登录功能,集成接码平台和平台API
- 管理账号订单容量,支持容量检查与账号登录触发
- 提供账号池状态统计接口
- 账号历史记录查询支持多种变更类型文本展示
- 密码等敏感信息采用脱敏展示
- 完善日志记录和错误处理机制,保证业务稳定运行
2025-11-21 00:49:50 +08:00

86 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package camel_oil
import (
"context"
v1 "kami/api/camel_oil/v1"
"kami/internal/consts"
"kami/internal/dao"
"kami/internal/model/entity"
"kami/utility/config"
"github.com/gogf/gf/v2/os/glog"
)
// ====================================================================================
// 账号历史记录查询
// ====================================================================================
// GetAccountHistory 获取账号历史记录
func (s *sCamelOil) GetAccountHistory(ctx context.Context, req *v1.AccountHistoryReq) (res *v1.AccountHistoryRes, err error) {
// 1. 构建查询
m := dao.V1CamelOilAccountHistory.Ctx(ctx).DB(config.GetDatabaseV1())
m = m.Where(dao.V1CamelOilAccountHistory.Columns().AccountId, req.AccountId)
// 2. 查询总数
total, err := m.Count()
if err != nil {
glog.Error(ctx, "查询账号历史记录总数失败", err)
return nil, err
}
// 3. 查询列表
var histories []*entity.V1CamelOilAccountHistory
err = m.Page(req.Current, req.PageSize).
OrderDesc(dao.V1CamelOilAccountHistory.Columns().Id).
Scan(&histories)
if err != nil {
glog.Error(ctx, "查询账号历史记录列表失败", err)
return nil, err
}
// 4. 组装响应数据
items := make([]v1.AccountHistoryItem, 0, len(histories))
for _, history := range histories {
items = append(items, v1.AccountHistoryItem{
HistoryUuid: history.HistoryUuid,
AccountId: history.AccountId,
ChangeType: consts.CamelOilAccountChangeType(history.ChangeType),
ChangeText: getAccountChangeTypeText(history.ChangeType),
StatusBefore: consts.CamelOilAccountStatus(history.StatusBefore),
StatusAfter: consts.CamelOilAccountStatus(history.StatusAfter),
FailureCount: history.FailureCount,
Remark: history.Remark,
CreatedAt: history.CreatedAt,
})
}
res = &v1.AccountHistoryRes{}
res.List = items
res.Total = total
return res, nil
}
// getAccountChangeTypeText 获取账号变更类型文本
func getAccountChangeTypeText(changeType string) string {
changeTypeMap := map[string]string{
"create": "创建账号",
"login": "登录成功",
"offline": "检测到掉线",
"login_fail": "登录失败",
"pause": "暂停使用订单数达到10",
"resume": "恢复使用(次日重置)",
"invalidate": "账号失效单日下单不足10个",
"order_bind": "绑定订单",
"order_complete": "订单完成",
"update": "更新账号信息",
"delete": "删除账号",
}
if text, ok := changeTypeMap[changeType]; ok {
return text
}
return changeType
}