修复快捷工具无法显示

This commit is contained in:
hero920103 committed 2026-10-30 17:29:28 +08:00
1 parent 9898962836
commit 2e2b837a20
23 files changed
+1941 -38

No files matched your search

+47
View File
@@ -20,6 +20,11 @@ import (
// 前端传入的 tid / tenant_id 一律忽略,避免越权读取其它租户的数据。
type BackendOrganizationController struct {
beego.Controller
// jobRanks 职级映射缓存:beego 每请求新建一个控制器实例,
// 因此这里的缓存只在单次请求内有效,正好避免职位列表逐条查职级表(N+1)。
jobRanks map[uint64]models.BackendJobRank
jobRanksTid uint64
}
const orgSettingsCodePrefix = "backend_org_settings"
@@ -112,6 +117,9 @@ type positionDTO struct {
PositionCode string `json:"position_code"`
PositionName string `json:"position_name"`
PositionType int8 `json:"position_type"`
RankID uint64 `json:"rank_id"`
RankName string `json:"rank_name"`
RankLevelNo int `json:"rank_level_no"`
Status int8 `json:"status"`
Sort uint `json:"sort"`
Remark string `json:"remark"`
@@ -1298,12 +1306,27 @@ 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]
if !ok {
c.jsonError(400, "职级不存在")
return
}
if rank.DepartmentID != 0 && departmentID > 0 && rank.DepartmentID != departmentID {
c.jsonError(400, "职级「"+rank.RankName+"」不属于所选部门")
return
}
}
row := models.BackendPosition{
Tid: tid,
DepartmentID: departmentID,
PositionCode: positionCode,
PositionName: positionName,
PositionType: int8(positionType),
RankID: rankID,
Status: 1,
Sort: sortVal,
Remark: strPtrIfNotEmpty(remark),
@@ -1379,6 +1402,30 @@ func (c *BackendOrganizationController) EditPosition() {
if v, has := c.getIntValue(body, "position_type"); has {
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 {
c.jsonError(400, "职级不存在")
return
}
departmentID := uint64(0)
if cur, has := c.getUint64Value(body, "department_id"); has {
departmentID = cur
} else {
var cur models.BackendPosition
if err := c.positionQuery(tid).Filter("id", id).One(&cur); err == nil {
departmentID = cur.DepartmentID
}
}
if rank.DepartmentID != 0 && departmentID > 0 && rank.DepartmentID != departmentID {
c.jsonError(400, "职级「"+rank.RankName+"」不属于所选部门")
return
}
}
update["rank_id"] = v
}
if v, has := c.getIntValue(body, "status"); has {
update["status"] = int8(v)
}