diff --git a/models/employee.go b/models/employee.go index 1ae1670..91ae62d 100644 --- a/models/employee.go +++ b/models/employee.go @@ -18,7 +18,7 @@ type Employee struct { From string `json:"from" gorm:"size:50;not null;default:'';comment:来源"` TypeId int8 `json:"type_id" gorm:"not null;default:0;comment:关联类型"` LastLoginAt int64 `json:"last_login_at" gorm:"not null;default:0;comment:最后登录时间"` - LastLoginIP string `json:"last_login_ip" gorm:"size:20;not null;default:'';comment:最后登录ip"` + LastLoginIp string `json:"last_login_ip" gorm:"size:20;not null;default:'';comment:最后登录ip"` CreatedAt int64 `json:"created_at" gorm:"not null;default:0;comment:创建时间"` UpdatedAt int64 `json:"updated_at" gorm:"not null;default:0;comment:更新时间"` DeletedAt int64 `json:"deleted_at" gorm:"not null;default:0;comment:删除时间"` diff --git a/models/response/Employee.go b/models/response/Employee.go index b294987..9efb8c0 100644 --- a/models/response/Employee.go +++ b/models/response/Employee.go @@ -111,6 +111,12 @@ type UserListItem struct { Status int8 `json:"status"` SplitAccountConfigId int64 `json:"split_account_config_id"` SplitAccountConfig *SplitAccountConfigInfo `json:"split_account_config,omitempty"` // 分账配置详情 + AboutId int64 `json:"about_id"` // 租户ID + Phone string `json:"phone"` // 手机号 + From string `json:"from"` // 来源 + LastLoginIp string `json:"last_login_ip"` // 最后登录IP + Code string `json:"code"` // 机械码 + ExpireTime int64 `json:"expire_time"` // 到期时间 } // GetUserListResponse 用户列表响应 diff --git a/service/employee.go b/service/employee.go index 1885a9f..a45d604 100644 --- a/service/employee.go +++ b/service/employee.go @@ -889,7 +889,7 @@ func (s *EmployeeService) createEmployeeLevelLog(empId int64, operationType int8 }, nil } */ -func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*systemRes.GetUserListResponse, error) { +/*func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*systemRes.GetUserListResponse, error) { if req.Page < 1 { req.Page = 1 } @@ -971,6 +971,102 @@ func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*system items = append(items, item) } + return &systemRes.GetUserListResponse{ + List: items, + Total: total, + Page: req.Page, + PageSize: req.PageSize, + }, nil +}*/ + +func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*systemRes.GetUserListResponse, error) { + if req.Page < 1 { + req.Page = 1 + } + if req.PageSize < 1 || req.PageSize > 100 { + req.PageSize = 20 + } + + query := database.DB.Model(&models.Employee{}).Where("deleted_at = ?", 0) + + if req.Status != "" { + query = query.Where("status = ?", req.Status) + } + if req.Username != "" { + query = query.Where("username LIKE ?", "%"+req.Username+"%") + } + if req.Tel != "" { + query = query.Where("phone LIKE ?", "%"+req.Tel+"%") + } + + var total int64 + if err := query.Count(&total).Error; err != nil { + return nil, utils.NewError("查询总数失败") + } + + var employees []models.Employee + offset := (req.Page - 1) * req.PageSize + if err := query.Order("created_at DESC").Offset(offset).Limit(req.PageSize).Find(&employees).Error; err != nil { + return nil, utils.NewError("查询用户列表失败") + } + + // 收集所有需要查询的分账配置ID + splitConfigIDs := make([]int64, 0) + for _, emp := range employees { + if emp.SplitAccountConfigId > 0 { + splitConfigIDs = append(splitConfigIDs, emp.SplitAccountConfigId) + } + } + + // 批量查询分账配置 + splitConfigMap := make(map[int64]*systemRes.SplitAccountConfigInfo) + if len(splitConfigIDs) > 0 { + var splitConfigs []models.SplitAccountConfig + database.DB.Where("id IN ? AND deleted_at = ?", splitConfigIDs, 0).Find(&splitConfigs) + + for _, config := range splitConfigs { + splitConfigMap[config.ID] = &systemRes.SplitAccountConfigInfo{ + ID: config.ID, + RuleName: config.RuleName, + RuleValue: json.RawMessage(config.RuleValue), + Status: config.Status, + Description: config.Description, + CreatedBy: config.CreatedBy, + UpdatedBy: config.UpdatedBy, + CreatedAt: config.CreatedAt, + UpdatedAt: config.UpdatedAt, + } + } + } + + var items []systemRes.UserListItem + for _, emp := range employees { + item := systemRes.UserListItem{ + ID: emp.ID, + EmployeeIDStr: emp.EmployeeIDStr, + Username: emp.Username, + Name: emp.Name, + Role: emp.Role, + Status: emp.Status, + SplitAccountConfigId: emp.SplitAccountConfigId, + AboutId: emp.AboutId, + Phone: emp.Phone, + From: emp.From, + LastLoginIp: emp.LastLoginIp, + Code: emp.Code, + ExpireTime: emp.ExpireTime, + } + + // 如果有关联的分账配置,添加详情 + if emp.SplitAccountConfigId > 0 { + if config, exists := splitConfigMap[emp.SplitAccountConfigId]; exists { + item.SplitAccountConfig = config + } + } + + items = append(items, item) + } + return &systemRes.GetUserListResponse{ List: items, Total: total,