更新
This commit is contained in:
1 parent
b6b528490c
commit
4ab63e77ed
28 files changed
+1858
-695
No files matched your search
@@ -5,9 +5,12 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/identity"
|
||||
"server/pkg/jwtutil"
|
||||
"server/services"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
@@ -66,21 +69,21 @@ func defaultOrgSettings() orgSettings {
|
||||
}
|
||||
|
||||
type organizationDTO struct {
|
||||
ID uint64 `json:"id"`
|
||||
Tid uint64 `json:"tid"`
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
OrgName string `json:"org_name"`
|
||||
OrgCode string `json:"org_code"`
|
||||
ParentID uint64 `json:"parent_id"`
|
||||
ParentName string `json:"parent_name"`
|
||||
LeaderID uint64 `json:"leader_id"`
|
||||
LeaderName string `json:"leader_name"`
|
||||
IsCompany int `json:"is_company"`
|
||||
Sort uint `json:"sort"`
|
||||
Status int8 `json:"status"`
|
||||
Remark string `json:"remark"`
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
ID uint64 `json:"id"`
|
||||
Tid uint64 `json:"tid"`
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
OrgName string `json:"org_name"`
|
||||
OrgCode string `json:"org_code"`
|
||||
ParentID uint64 `json:"parent_id"`
|
||||
ParentName string `json:"parent_name"`
|
||||
LeaderID uint64 `json:"leader_id"`
|
||||
LeaderName string `json:"leader_name"`
|
||||
IsCompany int `json:"is_company"`
|
||||
Sort uint `json:"sort"`
|
||||
Status int8 `json:"status"`
|
||||
Remark string `json:"remark"`
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
}
|
||||
|
||||
type employeeDTO struct {
|
||||
@@ -785,7 +788,7 @@ func (c *BackendOrganizationController) GetEmployee() {
|
||||
return
|
||||
}
|
||||
|
||||
cond := orm.NewCondition().And("tid", tid).And("delete_time__isnull", true)
|
||||
cond := orm.NewCondition().AndCond(orm.NewCondition().Or("tid", tid).Or("tid__isnull", true)).And("delete_time__isnull", true)
|
||||
|
||||
orgID, _ := c.GetUint64("org_id")
|
||||
if orgID == 0 {
|
||||
@@ -820,6 +823,29 @@ func (c *BackendOrganizationController) GetEmployee() {
|
||||
return
|
||||
}
|
||||
|
||||
// uk_account 为全局唯一索引,历史员工可能 tid 为空;只在当前用户账号可确认归属时认领这类历史记录。
|
||||
var tenantUsers []models.SystemTenantUser
|
||||
_, _ = models.Orm.QueryTable(new(models.SystemTenantUser)).Filter("tid", tid).Filter("delete_time__isnull", true).All(&tenantUsers, "account")
|
||||
ownedAccounts := make(map[string]struct{}, len(tenantUsers))
|
||||
for _, user := range tenantUsers {
|
||||
if user.Account != nil && strings.TrimSpace(*user.Account) != "" {
|
||||
ownedAccounts[strings.TrimSpace(*user.Account)] = struct{}{}
|
||||
}
|
||||
}
|
||||
filtered := make([]models.BackendEmployee, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
if row.Tid != nil && *row.Tid > 0 && *row.Tid != int(tid) {
|
||||
continue
|
||||
}
|
||||
if row.Tid == nil || *row.Tid == 0 {
|
||||
if _, belongsToTenant := ownedAccounts[strings.TrimSpace(row.Account)]; !belongsToTenant {
|
||||
continue
|
||||
}
|
||||
}
|
||||
filtered = append(filtered, row)
|
||||
}
|
||||
rows = filtered
|
||||
|
||||
c.jsonOK(c.employeeDTOList(tid, rows))
|
||||
}
|
||||
|
||||
@@ -909,6 +935,17 @@ func (c *BackendOrganizationController) CreateEmployee() {
|
||||
c.jsonError(400, "账号已存在")
|
||||
return
|
||||
}
|
||||
// 校验是否先有用户:必须在「用户管理」中已存在该账号(先有用户,后自动生成员工)
|
||||
var tenantUser models.SystemTenantUser
|
||||
tuErr := models.Orm.QueryTable(new(models.SystemTenantUser)).
|
||||
Filter("tid", tid).
|
||||
Filter("account", account).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&tenantUser)
|
||||
if tuErr != nil {
|
||||
c.jsonError(400, "该账号在「用户管理」中不存在,请先前往「用户管理」添加用户")
|
||||
return
|
||||
}
|
||||
|
||||
gender, hasGender := c.getIntValue(body, "gender", "sex")
|
||||
status, hasStatus := c.getIntValue(body, "account_status", "status")
|
||||
@@ -1072,13 +1109,19 @@ func (c *BackendOrganizationController) EditEmployee() {
|
||||
// 同步到通讯录(字段优先级:人事档案 > 员工)
|
||||
SyncContactOnEmployeeRefresh(tid, uint64(id))
|
||||
|
||||
// 反向同步到租户用户表(保持人员与用户一致)
|
||||
var updatedEmp models.BackendEmployee
|
||||
if err := c.employeeQuery(tid).Filter("id", id).One(&updatedEmp); err == nil {
|
||||
_ = services.SyncUserFromEmployee(tid, &updatedEmp)
|
||||
}
|
||||
|
||||
c.jsonOK(nil)
|
||||
}
|
||||
|
||||
// DeleteEmployee 员工离职/禁用:员工不做删除,只改账号状态。
|
||||
//
|
||||
// 说明:员工属于企业数据,人事档案(yz_backend_employee_file)与通讯录
|
||||
//(yz_backend_erp_contact)都以 employee_id 关联员工。一旦把员工软删除(写 delete_time),
|
||||
// (yz_backend_erp_contact)都以 employee_id 关联员工。一旦把员工软删除(写 delete_time),
|
||||
// 档案页与通讯录就查不到对应的人,等于连带删掉了企业数据。
|
||||
// 因此这里只把账号状态置为"离职"(2),不写 delete_time,也不触碰档案与通讯录记录。
|
||||
// 启用/禁用请走 editEmployee 改 account_status(1 启用 / 0 禁用 / 2 离职)。
|
||||
@@ -1106,6 +1149,16 @@ func (c *BackendOrganizationController) DeleteEmployee() {
|
||||
return
|
||||
}
|
||||
|
||||
// 员工置为离职状态后,同步将对应用户的状态置为禁用(0),防止离职人员继续登录系统
|
||||
var emp models.BackendEmployee
|
||||
if err := c.employeeQuery(tid).Filter("id", id).One(&emp); err == nil && emp.Account != "" {
|
||||
_, _ = models.Orm.QueryTable(new(models.SystemTenantUser)).
|
||||
Filter("tid", tid).
|
||||
Filter("account", emp.Account).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(orm.Params{"status": int8(0), "update_time": time.Now()})
|
||||
}
|
||||
|
||||
c.jsonOK(nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user