feat(feat):
deploy-hxtesting / build-and-deploy (push) Successful in 1m14s

1.将职称角色中的“从OA同步企微账号”及设置角色、“员工与部门在「组织架构」中统一维护,此处仅配置职称角色”迁移到组织架构页面中,
2.平台新增成员自动添加到“组织架构”页面自动匹配对应部门;
3.在“组织架构”页面可直接设置角色
4.“组织架构”页面职称按名称、工号、部门查找员工
5.新增成员默认放在最上面按时间倒序排列
6.所有登录平台的用户直接默认打开AI对话页面
7.页面3、4中的”AIDO“改为”和信智汇学院“
This commit is contained in:
runny committed 2026-11-24 14:38:20 +08:00
1 parent 196478114c
commit 8f225ecea9
26 files changed
+644 -406

No files matched your search

+57 -7
View File
@@ -65,15 +65,25 @@ func (r *orgCenterRepository) DeleteDept(ctx context.Context, tenantID uint64, i
// ---------------------------------------------------------------------------
// employeeFilter 组装员工列表的公共过滤(租户/部门/关键词)。
// users/org_depts 联查在此一并挂上:keyword 需要按姓名/部门名过滤,且 Count
// 与列表共用同一过滤,联查必须两边一致(users/org_depts 对档案均为 1:1,
// 不影响 Count 语义)。
func (r *orgCenterRepository) employeeFilter(ctx context.Context, tenantID uint64, q *types.OrgListQuery) *gorm.DB {
tx := r.db.WithContext(ctx).Model(&types.OrgEmployee{}).Where("org_employees.tenant_id = ?", tenantID)
tx := r.db.WithContext(ctx).Model(&types.OrgEmployee{}).
Where("org_employees.tenant_id = ?", tenantID).
Joins("LEFT JOIN users u ON u.id = org_employees.user_id").
Joins("LEFT JOIN org_depts dp ON dp.id = org_employees.dept_id AND dp.tenant_id = org_employees.tenant_id AND dp.deleted_at IS NULL")
if q != nil {
if q.DeptID != "" {
tx = tx.Where("org_employees.dept_id = ?", q.DeptID)
}
if q.Keyword != "" {
tx = tx.Where("org_employees.employee_no ILIKE ? OR org_employees.post ILIKE ? OR org_employees.user_id ILIKE ?",
"%"+q.Keyword+"%", "%"+q.Keyword+"%", "%"+q.Keyword+"%")
// 按姓名/工号/部门名/岗位模糊查找;姓名取真实姓名(display_name)
// 回退平台账号(username),与列表展示口径一致。
tx = tx.Where(
"org_employees.employee_no ILIKE ? OR COALESCE(NULLIF(u.display_name, ''), u.username, '') ILIKE ? "+
"OR COALESCE(dp.name, '') ILIKE ? OR org_employees.post ILIKE ? OR org_employees.user_id ILIKE ?",
"%"+q.Keyword+"%", "%"+q.Keyword+"%", "%"+q.Keyword+"%", "%"+q.Keyword+"%", "%"+q.Keyword+"%")
}
}
return tx
@@ -102,9 +112,7 @@ func (r *orgCenterRepository) ListEmployees(ctx context.Context, tenantID uint64
tx := filter().
// user_name 取真实姓名(display_name)优先:员工编号型 IdP(Casdoor)的
// username 存工号,真实姓名在 display_name(见 000143 迁移)。
Select(`org_employees.*, COALESCE(NULLIF(u.display_name, ''), u.username, '') AS user_name, COALESCE(dp.name, '') AS dept_name`).
Joins("LEFT JOIN users u ON u.id = org_employees.user_id").
Joins("LEFT JOIN org_depts dp ON dp.id = org_employees.dept_id AND dp.tenant_id = org_employees.tenant_id AND dp.deleted_at IS NULL")
Select(`org_employees.*, COALESCE(NULLIF(u.display_name, ''), u.username, '') AS user_name, COALESCE(dp.name, '') AS dept_name`)
if moduleKey != "" {
// 绑定行缺失时回退 '[]'(学员为全员隐式角色,无需绑定行)。
tx = tx.Select(`org_employees.*, COALESCE(NULLIF(u.display_name, ''), u.username, '') AS user_name, COALESCE(dp.name, '') AS dept_name,
@@ -112,8 +120,9 @@ func (r *orgCenterRepository) ListEmployees(ctx context.Context, tenantID uint64
Joins("LEFT JOIN org_module_members mm ON mm.tenant_id = org_employees.tenant_id AND mm.employee_id = org_employees.id AND mm.module_key = ? AND mm.deleted_at IS NULL", moduleKey)
}
var employees []*types.OrgEmployee
// 新增成员置顶(时间倒序):最新建档/导入的员工排在列表最前。
err := tx.
Order("org_employees.created_at ASC").
Order("org_employees.created_at DESC").
Offset((page - 1) * pageSize).Limit(pageSize).
Find(&employees).Error
return employees, total, err
@@ -141,6 +150,27 @@ func (r *orgCenterRepository) GetEmployeeByUserID(ctx context.Context, tenantID
return &m, nil
}
// InsertEmployeesIfAbsent 自动入册专用:成员加入空间时补建员工档案。
// 与 UpsertEmployees(导入语义,整行覆盖)不同,本方法只补空不覆盖——
// 已有档案的工号/部门仅在为空时用新值回填(如 Casdoor 后同步到部门),
// 人工维护过(或 OA 同步)的字段一律保留。
func (r *orgCenterRepository) InsertEmployeesIfAbsent(ctx context.Context, employees []*types.OrgEmployee) error {
if len(employees) == 0 {
return nil
}
return r.db.WithContext(ctx).
Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "tenant_id"}, {Name: "user_id"}},
DoUpdates: clause.Assignments(map[string]interface{}{
// 档案已有工号/部门时不覆盖(空串/空 id 视为未维护,由新值补齐)。
"employee_no": gorm.Expr("COALESCE(NULLIF(org_employees.employee_no, ''), EXCLUDED.employee_no)"),
"dept_id": gorm.Expr("COALESCE(NULLIF(org_employees.dept_id, ''), EXCLUDED.dept_id)"),
"updated_at": gorm.Expr("CURRENT_TIMESTAMP"),
}),
}).
Create(&employees).Error
}
// UpsertEmployees bulk-imports employee profiles keyed by (tenant, user_id).
func (r *orgCenterRepository) UpsertEmployees(ctx context.Context, employees []*types.OrgEmployee) error {
if len(employees) == 0 {
@@ -244,6 +274,26 @@ func (r *orgCenterRepository) GetUsernamesByUserIDs(ctx context.Context, tenantI
return m, nil
}
// GetRosterUserInfos resolves the roster-relevant user fields (平台账号 + Casdoor
// 同步部门) for the given user IDs within the tenant — source for auto-creating
// employee profiles when members join (EnsureEmployeesForUsers 的取数口径与
// GetUsernamesByUserIDs 一致:本空间 active 成员)。
func (r *orgCenterRepository) GetRosterUserInfos(ctx context.Context, tenantID uint64, userIDs []string) ([]*types.TrainingUserInfo, error) {
if len(userIDs) == 0 {
return nil, nil
}
var users []*types.TrainingUserInfo
err := r.db.WithContext(ctx).
Table("users u").
Select("u.id, u.username, u.dept_code, u.dept_name").
Joins("JOIN tenant_members tm ON tm.user_id = u.id AND tm.tenant_id = ? "+
"AND tm.status = 'active' AND tm.deleted_at IS NULL", tenantID).
Where("u.id IN ?", userIDs).
Where("u.is_active = TRUE AND u.deleted_at IS NULL").
Scan(&users).Error
return users, err
}
// ---------------------------------------------------------------------------
// 模块角色绑定
// ---------------------------------------------------------------------------