更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -16,16 +16,9 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// BackendOrganizationController 组织架构(组织、员工、职位)接口。
|
||||
//
|
||||
// 组织架构是租户端的通用基础数据:进销存(ERP)与办公自动化(OA)两个模块各自有独立界面,
|
||||
// 但读写的是同一份数据。所有查询与写入都强制带上 JWT 中的租户ID(tid),实现租户间隔离,
|
||||
// 前端传入的 tid / tenant_id 一律忽略,避免越权读取其它租户的数据。
|
||||
type BackendOrganizationController struct {
|
||||
beego.Controller
|
||||
|
||||
// jobRanks 职级映射缓存:beego 每请求新建一个控制器实例,
|
||||
// 因此这里的缓存只在单次请求内有效,正好避免职位列表逐条查职级表(N+1)。
|
||||
jobRanks map[uint64]models.BackendJobRank
|
||||
jobRanksTid uint64
|
||||
}
|
||||
@@ -129,11 +122,6 @@ type positionDTO struct {
|
||||
CreateTime string `json:"create_time"`
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 认证与响应
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// claims 解析 Authorization 头中的 JWT,要求是租户端(backend)用户且带有效租户ID。
|
||||
func (c *BackendOrganizationController) claims() (*jwtutil.Claims, bool) {
|
||||
claims, err := identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndBackend)
|
||||
if err != nil || claims.TenantId <= 0 {
|
||||
@@ -142,7 +130,6 @@ func (c *BackendOrganizationController) claims() (*jwtutil.Claims, bool) {
|
||||
return claims, true
|
||||
}
|
||||
|
||||
// tenantID 取当前登录租户ID,未通过认证时直接输出 401 并返回 false。
|
||||
func (c *BackendOrganizationController) tenantID() (uint64, bool) {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -169,10 +156,6 @@ func (c *BackendOrganizationController) jsonError(code int, msg string) {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 查询基座:所有 QuerySeter 都强制附加 tid 过滤
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
func (c *BackendOrganizationController) orgQuery(tid uint64) orm.QuerySeter {
|
||||
return models.Orm.QueryTable(new(models.BackendOrganization)).
|
||||
Filter("tid", tid).
|
||||
@@ -191,12 +174,6 @@ func (c *BackendOrganizationController) positionQuery(tid uint64) orm.QuerySeter
|
||||
Filter("delete_time__isnull", true)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 组织机构
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// GetOrganization 获取组织机构列表(扁平)。
|
||||
// GET /backend/{erp|oa}/getOrganization
|
||||
func (c *BackendOrganizationController) GetOrganization() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -217,8 +194,6 @@ func (c *BackendOrganizationController) GetOrganization() {
|
||||
c.jsonOK(c.organizationDTOList(tid, rows))
|
||||
}
|
||||
|
||||
// GetOrganizationDetail 获取组织机构详情。
|
||||
// GET /backend/{erp|oa}/getOrganizationDetail/:id
|
||||
func (c *BackendOrganizationController) GetOrganizationDetail() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -239,8 +214,6 @@ func (c *BackendOrganizationController) GetOrganizationDetail() {
|
||||
c.jsonOK(c.organizationDTO(tid, row))
|
||||
}
|
||||
|
||||
// CreateOrganization 创建组织机构。
|
||||
// POST /backend/{erp|oa}/createOrganization
|
||||
func (c *BackendOrganizationController) CreateOrganization() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -339,8 +312,6 @@ func (c *BackendOrganizationController) CreateOrganization() {
|
||||
c.jsonOK(map[string]interface{}{"id": id, "org_code": orgCode})
|
||||
}
|
||||
|
||||
// EditOrganization 更新组织机构。
|
||||
// POST /backend/{erp|oa}/editOrganization/:id
|
||||
func (c *BackendOrganizationController) EditOrganization() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -423,8 +394,6 @@ func (c *BackendOrganizationController) EditOrganization() {
|
||||
c.jsonOK(nil)
|
||||
}
|
||||
|
||||
// DeleteOrganization 删除组织机构(软删除)。
|
||||
// DELETE /backend/{erp|oa}/deleteOrganization/:id
|
||||
func (c *BackendOrganizationController) DeleteOrganization() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -470,8 +439,6 @@ func (c *BackendOrganizationController) DeleteOrganization() {
|
||||
c.jsonOK(nil)
|
||||
}
|
||||
|
||||
// GetCompanys 获取企业单位列表。
|
||||
// GET /backend/{erp|oa}/getCompanys
|
||||
func (c *BackendOrganizationController) GetCompanys() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -489,8 +456,6 @@ func (c *BackendOrganizationController) GetCompanys() {
|
||||
c.jsonOK(c.organizationDTOList(tid, rows))
|
||||
}
|
||||
|
||||
// GetDepartments 获取部门列表。
|
||||
// GET /backend/{erp|oa}/getDepartments?parent_id=1
|
||||
func (c *BackendOrganizationController) GetDepartments() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -514,8 +479,6 @@ func (c *BackendOrganizationController) GetDepartments() {
|
||||
c.jsonOK(c.organizationDTOList(tid, rows))
|
||||
}
|
||||
|
||||
// GetOrganizationTree 获取组织架构树。
|
||||
// GET /backend/{erp|oa}/getOrganizationTree
|
||||
func (c *BackendOrganizationController) GetOrganizationTree() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -532,8 +495,6 @@ func (c *BackendOrganizationController) GetOrganizationTree() {
|
||||
c.jsonOK(buildOrganizationTree(c.organizationDTOList(tid, rows)))
|
||||
}
|
||||
|
||||
// SearchOrganizations 按名称/编码搜索组织机构。
|
||||
// GET /backend/{erp|oa}/searchOrganizations?keyword=xx
|
||||
func (c *BackendOrganizationController) SearchOrganizations() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -562,8 +523,6 @@ func (c *BackendOrganizationController) SearchOrganizations() {
|
||||
c.jsonOK(c.organizationDTOList(tid, rows))
|
||||
}
|
||||
|
||||
// GetOrganizationHierarchy 获取指定组织的上级链与直接下级。
|
||||
// GET /backend/{erp|oa}/getOrganizationHierarchy/:org_id
|
||||
func (c *BackendOrganizationController) GetOrganizationHierarchy() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -588,7 +547,6 @@ func (c *BackendOrganizationController) GetOrganizationHierarchy() {
|
||||
return
|
||||
}
|
||||
|
||||
// 自底向上收集上级链,最多回溯 64 层,防止脏数据造成死循环
|
||||
ancestors := make([]organizationDTO, 0)
|
||||
parentID := org.ParentID
|
||||
for i := 0; i < 64 && parentID > 0; i++ {
|
||||
@@ -607,8 +565,6 @@ func (c *BackendOrganizationController) GetOrganizationHierarchy() {
|
||||
})
|
||||
}
|
||||
|
||||
// GetOrganizationStats 组织架构统计。
|
||||
// GET /backend/{erp|oa}/getOrganizationStats
|
||||
func (c *BackendOrganizationController) GetOrganizationStats() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -655,8 +611,6 @@ func (c *BackendOrganizationController) GetOrganizationStats() {
|
||||
})
|
||||
}
|
||||
|
||||
// MoveOrganization 移动组织节点到新的上级(拖拽调整层级)。
|
||||
// POST /backend/{erp|oa}/moveOrganization
|
||||
func (c *BackendOrganizationController) MoveOrganization() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -693,8 +647,6 @@ func (c *BackendOrganizationController) MoveOrganization() {
|
||||
c.jsonOK(nil)
|
||||
}
|
||||
|
||||
// BatchOrganizeOrganizations 批量启用/禁用/删除组织。
|
||||
// POST /backend/{erp|oa}/batchOrganizeOrganizations
|
||||
func (c *BackendOrganizationController) BatchOrganizeOrganizations() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -717,7 +669,6 @@ func (c *BackendOrganizationController) BatchOrganizeOrganizations() {
|
||||
case "disable":
|
||||
update = orm.Params{"status": int8(0)}
|
||||
case "delete":
|
||||
// 有下级或有员工的组织不允许批量删除,避免产生孤儿数据
|
||||
for _, id := range ids {
|
||||
childCount, _ := c.orgQuery(tid).Filter("parent_id", id).Exclude("status", 0).Count()
|
||||
if childCount > 0 {
|
||||
@@ -745,8 +696,6 @@ func (c *BackendOrganizationController) BatchOrganizeOrganizations() {
|
||||
c.jsonOK(map[string]interface{}{"affected": num})
|
||||
}
|
||||
|
||||
// CheckOrgCodeUnique 检查组织编码唯一性。
|
||||
// GET /backend/{erp|oa}/checkOrgCodeUnique?org_code=xx&exclude_id=1
|
||||
func (c *BackendOrganizationController) CheckOrgCodeUnique() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -776,12 +725,6 @@ func (c *BackendOrganizationController) CheckOrgCodeUnique() {
|
||||
c.jsonOK(map[string]interface{}{"unique": count == 0, "message": uniqueMessage(count == 0, "编码")})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 员工
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// GetEmployee 获取员工列表,支持按组织、关键词、状态过滤。
|
||||
// GET /backend/{erp|oa}/getEmployee?org_id=1&keyword=xx&status=1
|
||||
func (c *BackendOrganizationController) GetEmployee() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -795,7 +738,6 @@ func (c *BackendOrganizationController) GetEmployee() {
|
||||
orgID, _ = c.GetUint64("department_id")
|
||||
}
|
||||
if orgID > 0 {
|
||||
// 含下级组织:把整棵子树的组织ID都算进去
|
||||
orgIDs := c.collectOrgIDs(tid, orgID)
|
||||
values := make([]string, 0, len(orgIDs))
|
||||
for _, id := range orgIDs {
|
||||
@@ -823,7 +765,6 @@ 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))
|
||||
@@ -849,8 +790,6 @@ func (c *BackendOrganizationController) GetEmployee() {
|
||||
c.jsonOK(c.employeeDTOList(tid, rows))
|
||||
}
|
||||
|
||||
// GetOrganizationEmployees 获取指定组织(含下级)的员工列表。
|
||||
// GET /backend/{erp|oa}/getOrganizationEmployees/:org_id
|
||||
func (c *BackendOrganizationController) GetOrganizationEmployees() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -878,8 +817,6 @@ func (c *BackendOrganizationController) GetOrganizationEmployees() {
|
||||
c.jsonOK(c.employeeDTOList(tid, rows))
|
||||
}
|
||||
|
||||
// GetEmployeeDetail 获取员工详情。
|
||||
// GET /backend/{erp|oa}/getEmployeeDetail/:id
|
||||
func (c *BackendOrganizationController) GetEmployeeDetail() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -900,8 +837,6 @@ func (c *BackendOrganizationController) GetEmployeeDetail() {
|
||||
c.jsonOK(c.employeeDTO(tid, row))
|
||||
}
|
||||
|
||||
// CreateEmployee 创建员工。
|
||||
// POST /backend/{erp|oa}/createEmployee
|
||||
func (c *BackendOrganizationController) CreateEmployee() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -935,7 +870,6 @@ func (c *BackendOrganizationController) CreateEmployee() {
|
||||
c.jsonError(400, "账号已存在")
|
||||
return
|
||||
}
|
||||
// 校验是否先有用户:必须在「用户管理」中已存在该账号(先有用户,后自动生成员工)
|
||||
var tenantUser models.SystemTenantUser
|
||||
tuErr := models.Orm.QueryTable(new(models.SystemTenantUser)).
|
||||
Filter("tid", tid).
|
||||
@@ -998,14 +932,11 @@ func (c *BackendOrganizationController) CreateEmployee() {
|
||||
return
|
||||
}
|
||||
|
||||
// 同步到通讯录(员工为基础数据,已建档时档案字段优先)
|
||||
SyncContactOnEmployeeCreate(tid, uint64(id), &row)
|
||||
|
||||
c.jsonOK(map[string]interface{}{"id": id, "account": account})
|
||||
}
|
||||
|
||||
// EditEmployee 更新员工。
|
||||
// POST /backend/{erp|oa}/editEmployee/:id
|
||||
func (c *BackendOrganizationController) EditEmployee() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -1106,10 +1037,8 @@ func (c *BackendOrganizationController) EditEmployee() {
|
||||
return
|
||||
}
|
||||
|
||||
// 同步到通讯录(字段优先级:人事档案 > 员工)
|
||||
SyncContactOnEmployeeRefresh(tid, uint64(id))
|
||||
|
||||
// 反向同步到租户用户表(保持人员与用户一致)
|
||||
var updatedEmp models.BackendEmployee
|
||||
if err := c.employeeQuery(tid).Filter("id", id).One(&updatedEmp); err == nil {
|
||||
_ = services.SyncUserFromEmployee(tid, &updatedEmp)
|
||||
@@ -1118,14 +1047,6 @@ func (c *BackendOrganizationController) EditEmployee() {
|
||||
c.jsonOK(nil)
|
||||
}
|
||||
|
||||
// DeleteEmployee 员工离职/禁用:员工不做删除,只改账号状态。
|
||||
//
|
||||
// 说明:员工属于企业数据,人事档案(yz_backend_employee_file)与通讯录
|
||||
// (yz_backend_erp_contact)都以 employee_id 关联员工。一旦把员工软删除(写 delete_time),
|
||||
// 档案页与通讯录就查不到对应的人,等于连带删掉了企业数据。
|
||||
// 因此这里只把账号状态置为"离职"(2),不写 delete_time,也不触碰档案与通讯录记录。
|
||||
// 启用/禁用请走 editEmployee 改 account_status(1 启用 / 0 禁用 / 2 离职)。
|
||||
// DELETE /backend/{erp|oa}/deleteEmployee/:id
|
||||
func (c *BackendOrganizationController) DeleteEmployee() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -1142,14 +1063,12 @@ func (c *BackendOrganizationController) DeleteEmployee() {
|
||||
return
|
||||
}
|
||||
|
||||
// 员工不允许删除,仅置为离职状态;档案与通讯录原样保留
|
||||
if _, err := c.employeeQuery(tid).Filter("id", id).
|
||||
Update(orm.Params{"account_status": int8(2)}); err != nil {
|
||||
c.jsonError(500, "离职操作失败: "+err.Error())
|
||||
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)).
|
||||
@@ -1162,8 +1081,6 @@ func (c *BackendOrganizationController) DeleteEmployee() {
|
||||
c.jsonOK(nil)
|
||||
}
|
||||
|
||||
// MoveEmployeeToOrg 员工调岗:批量或单个移动到指定组织。
|
||||
// POST /backend/{erp|oa}/moveEmployeeToOrg
|
||||
func (c *BackendOrganizationController) MoveEmployeeToOrg() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -1193,7 +1110,6 @@ func (c *BackendOrganizationController) MoveEmployeeToOrg() {
|
||||
}
|
||||
|
||||
update := orm.Params{"department": strconv.FormatUint(orgID, 10)}
|
||||
// 部门变更时同步隶属单位:取该组织所在的顶层公司
|
||||
if companyID := c.rootCompanyID(tid, org); companyID > 0 {
|
||||
update["affiliate_unit"] = strconv.FormatUint(companyID, 10)
|
||||
}
|
||||
@@ -1214,8 +1130,6 @@ func (c *BackendOrganizationController) MoveEmployeeToOrg() {
|
||||
c.jsonOK(map[string]interface{}{"affected": num})
|
||||
}
|
||||
|
||||
// CheckEmployeeAccountUnique 检查员工账号唯一性。
|
||||
// GET /backend/{erp|oa}/checkEmployeeAccountUnique?account=xx&exclude_id=1
|
||||
func (c *BackendOrganizationController) CheckEmployeeAccountUnique() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -1245,12 +1159,6 @@ func (c *BackendOrganizationController) CheckEmployeeAccountUnique() {
|
||||
c.jsonOK(map[string]interface{}{"unique": count == 0, "message": uniqueMessage(count == 0, "账号")})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 职位
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// GetPosition 获取职位列表。
|
||||
// GET /backend/{erp|oa}/getPosition?department_id=1&keyword=xx
|
||||
func (c *BackendOrganizationController) GetPosition() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -1288,8 +1196,6 @@ func (c *BackendOrganizationController) GetPosition() {
|
||||
c.jsonOK(list)
|
||||
}
|
||||
|
||||
// GetPositionDetail 获取职位详情。
|
||||
// GET /backend/{erp|oa}/getPositionDetail/:id
|
||||
func (c *BackendOrganizationController) GetPositionDetail() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -1310,8 +1216,6 @@ func (c *BackendOrganizationController) GetPositionDetail() {
|
||||
c.jsonOK(c.positionDTO(tid, row))
|
||||
}
|
||||
|
||||
// CreatePosition 创建职位。
|
||||
// POST /backend/{erp|oa}/createPosition
|
||||
func (c *BackendOrganizationController) CreatePosition() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -1359,7 +1263,6 @@ func (c *BackendOrganizationController) CreatePosition() {
|
||||
sortVal, _ := c.getUintValue(body, "sort")
|
||||
remark, _ := c.getStringValue(body, "remark")
|
||||
|
||||
// 职级:必须是本租户的职级,且适用部门要对得上(0=全公司通用始终可用)。
|
||||
rankID, _ := c.getUint64Value(body, "rank_id")
|
||||
if rankID > 0 {
|
||||
rank, ok := c.jobRankMap(tid)[rankID]
|
||||
@@ -1397,8 +1300,6 @@ func (c *BackendOrganizationController) CreatePosition() {
|
||||
c.jsonOK(map[string]interface{}{"id": id, "position_code": positionCode})
|
||||
}
|
||||
|
||||
// EditPosition 更新职位。
|
||||
// POST /backend/{erp|oa}/editPosition/:id
|
||||
func (c *BackendOrganizationController) EditPosition() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -1456,7 +1357,6 @@ func (c *BackendOrganizationController) EditPosition() {
|
||||
update["position_type"] = int8(v)
|
||||
}
|
||||
if v, has := c.getUint64Value(body, "rank_id"); has {
|
||||
// 职级必须是本租户的职级;适用部门与职位所属部门不一致时拒绝。
|
||||
if v > 0 {
|
||||
rank, ok := c.jobRankMap(tid)[v]
|
||||
if !ok {
|
||||
@@ -1502,8 +1402,6 @@ func (c *BackendOrganizationController) EditPosition() {
|
||||
c.jsonOK(nil)
|
||||
}
|
||||
|
||||
// DeletePosition 删除职位(软删除)。
|
||||
// DELETE /backend/{erp|oa}/deletePosition/:id
|
||||
func (c *BackendOrganizationController) DeletePosition() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
@@ -1529,8 +1427,6 @@ func (c *BackendOrganizationController) DeletePosition() {
|
||||
c.jsonOK(nil)
|
||||
}
|
||||
|
||||
// CheckPositionCodeUnique 检查职位编码唯一性。
|
||||
// GET /backend/{erp|oa}/checkPositionCodeUnique?position_code=xx&exclude_id=1
|
||||
func (c *BackendOrganizationController) CheckPositionCodeUnique() {
|
||||
tid, ok := c.tenantID()
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user