fix: align workbench queries with current schema

This commit is contained in:
richjohnrambo
2026-09-14 10:49:06 +08:00
parent 4c964ee3ba
commit 8b5c5e3df5
+7 -7
View File
@@ -75,7 +75,7 @@ func (s *Store) Departments(ctx context.Context, userID int64, parentID, cursor
var items []OrganizationDepartment var items []OrganizationDepartment
query := `SELECT d.department_id,d.name,d.parent_id, query := `SELECT d.department_id,d.name,d.parent_id,
(SELECT COUNT(*) FROM im_org_departments c WHERE c.parent_id=d.department_id) AS child_count, (SELECT COUNT(*) FROM im_org_departments c WHERE c.parent_id=d.department_id) AS child_count,
(SELECT COUNT(*) FROM im_org_members m WHERE m.department_id=d.department_id AND m.status='active') AS member_count, (SELECT COUNT(*) FROM im_org_members m WHERE m.department_id=d.department_id AND m.employment_state='active') AS member_count,
d.version d.version
FROM im_org_departments d WHERE d.parent_id=?` FROM im_org_departments d WHERE d.parent_id=?`
args := []any{parentID} args := []any{parentID}
@@ -94,8 +94,8 @@ func (s *Store) Departments(ctx context.Context, userID int64, parentID, cursor
func (s *Store) DepartmentMembers(ctx context.Context, userID int64, departmentID, cursor string, limit int) ([]OrganizationMember, string, error) { func (s *Store) DepartmentMembers(ctx context.Context, userID int64, departmentID, cursor string, limit int) ([]OrganizationMember, string, error) {
var items []OrganizationMember var items []OrganizationMember
query := `SELECT user_id,department_id,display_name,position,IFNULL(mobile,'') AS mobile,IFNULL(email,'') AS email, query := `SELECT user_id,department_id,display_name,position,IFNULL(mobile,'') AS mobile,IFNULL(email,'') AS email,
IFNULL(avatar_file_id,'') AS avatar_file_id,status,contactable,version IFNULL(avatar_file_id,'') AS avatar_file_id,employment_state AS status,contactable,version
FROM im_org_members WHERE department_id=? AND status='active'` FROM im_org_members WHERE department_id=? AND employment_state='active'`
args := []any{departmentID} args := []any{departmentID}
if cursor != "" { if cursor != "" {
query += ` AND user_id>?` query += ` AND user_id>?`
@@ -111,7 +111,7 @@ func (s *Store) DepartmentMembers(ctx context.Context, userID int64, departmentI
func (s *Store) Members(ctx context.Context, userID int64, departmentID, keyword, cursor string, limit int) ([]OrganizationMember, string, error) { func (s *Store) Members(ctx context.Context, userID int64, departmentID, keyword, cursor string, limit int) ([]OrganizationMember, string, error) {
var items []OrganizationMember var items []OrganizationMember
where := []string{"status='active'"} where := []string{"employment_state='active'"}
args := []any{} args := []any{}
if departmentID != "" { if departmentID != "" {
where = append(where, "department_id=?") where = append(where, "department_id=?")
@@ -127,7 +127,7 @@ func (s *Store) Members(ctx context.Context, userID int64, departmentID, keyword
args = append(args, cursor) args = append(args, cursor)
} }
query := `SELECT user_id,department_id,display_name,position,IFNULL(mobile,'') AS mobile,IFNULL(email,'') AS email, query := `SELECT user_id,department_id,display_name,position,IFNULL(mobile,'') AS mobile,IFNULL(email,'') AS email,
IFNULL(avatar_file_id,'') AS avatar_file_id,status,contactable,version IFNULL(avatar_file_id,'') AS avatar_file_id,employment_state AS status,contactable,version
FROM im_org_members WHERE ` + strings.Join(where, " AND ") + ` ORDER BY user_id ASC LIMIT ?` FROM im_org_members WHERE ` + strings.Join(where, " AND ") + ` ORDER BY user_id ASC LIMIT ?`
args = append(args, limit+1) args = append(args, limit+1)
if err := s.db.SelectContext(ctx, &items, query, args...); err != nil { if err := s.db.SelectContext(ctx, &items, query, args...); err != nil {
@@ -138,7 +138,7 @@ func (s *Store) Members(ctx context.Context, userID int64, departmentID, keyword
func (s *Store) AttendanceConfig(ctx context.Context, userID int64, date time.Time) (*AttendanceConfig, error) { func (s *Store) AttendanceConfig(ctx context.Context, userID int64, date time.Time) (*AttendanceConfig, error) {
var rule AttendanceRule var rule AttendanceRule
if err := s.db.GetContext(ctx, &rule, `SELECT rule_id,name,workday,location_required,wifi_required,allow_outside_checkin,appeal_allowed,appeal_deadline if err := s.db.GetContext(ctx, &rule, `SELECT rule_id,name,workday,location_required,wifi_required,allow_outside_checkin,appeal_allowed,NULL AS appeal_deadline
FROM im_attendance_rules WHERE state='active' ORDER BY id ASC LIMIT 1`); err != nil { FROM im_attendance_rules WHERE state='active' ORDER BY id ASC LIMIT 1`); err != nil {
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return &AttendanceConfig{Date: date, Timezone: "Asia/Shanghai", Rule: AttendanceRule{}, Shifts: []AttendanceShift{}}, nil return &AttendanceConfig{Date: date, Timezone: "Asia/Shanghai", Rule: AttendanceRule{}, Shifts: []AttendanceShift{}}, nil
@@ -709,7 +709,7 @@ func (s *Store) ReopenMonthly(ctx context.Context, userID int64, reportID string
func (s *Store) MailboxConfig(ctx context.Context) (*MailboxConfig, error) { func (s *Store) MailboxConfig(ctx context.Context) (*MailboxConfig, error) {
var cfg MailboxConfig var cfg MailboxConfig
if err := s.db.GetContext(ctx, &cfg, `SELECT enabled,allow_anonymous,required_fields,max_length,attachment_policy,notice_title,notice_content,version FROM im_mailbox_config WHERE id=1`); err != nil { if err := s.db.GetContext(ctx, &cfg, `SELECT enabled,allow_anonymous,required_fields,max_length,attachment_policy,notice_title,notice_content,CAST(COALESCE(UNIX_TIMESTAMP(notice_updated_at),1) AS UNSIGNED) AS version FROM im_mailbox_config WHERE id=1`); err != nil {
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return &MailboxConfig{Enabled: true, AllowAnonymous: true, RequiredFields: `["subject","content"]`, MaxLength: 5000, AttachmentPolicy: `{"max_files":5}`, NoticeTitle: "总经理信箱", NoticeContent: "请如实填写诉求。", Version: 1}, nil return &MailboxConfig{Enabled: true, AllowAnonymous: true, RequiredFields: `["subject","content"]`, MaxLength: 5000, AttachmentPolicy: `{"max_files":5}`, NoticeTitle: "总经理信箱", NoticeContent: "请如实填写诉求。", Version: 1}, nil
} }