更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
+17
-185
@@ -13,10 +13,6 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// OA 文档管理业务逻辑层(文档库 + 文档图谱)。
|
||||
// 只处理业务与数据访问,不感知 HTTP;错误以 error 向上抛出,由控制器转译。
|
||||
|
||||
// 业务错误
|
||||
var (
|
||||
ErrDocCategoryNotFound = errors.New("分类不存在")
|
||||
ErrDocCategoryHasChild = errors.New("存在子分类,请先删除子分类")
|
||||
@@ -37,37 +33,24 @@ var (
|
||||
ErrDocNoPermission = errors.New("无权操作该私密文档")
|
||||
)
|
||||
|
||||
// ---------------- 访问者上下文与可见性 ----------------
|
||||
|
||||
// OaDocActor 文档访问者上下文。
|
||||
//
|
||||
// 两级隔离:
|
||||
// 1. 租户隔离:所有查询强制带 tid,tid 只取自 JWT,前端无法指定;
|
||||
// 2. 用户隔离:visibility=1 的私密文档,仅创建者、被共享者(用户/部门)可见;
|
||||
// group_id=0 的用户沿用系统既有约定(未分配角色视为全权限),可查看全部私密文档。
|
||||
type OaDocActor struct {
|
||||
Tid int // 租户ID
|
||||
UID uint64 // 登录用户ID(yz_system_tenant_user.uid)
|
||||
OrgIDs []uint64 // 所属部门及全部子部门ID
|
||||
IsAdmin bool // 是否全权限(group_id=0)
|
||||
Tid int
|
||||
UID uint64
|
||||
OrgIDs []uint64
|
||||
IsAdmin bool
|
||||
}
|
||||
|
||||
// NewOaDocActor 构造访问者上下文。
|
||||
// uid 为 backend 端 JWT 的 UserID,即 yz_system_tenant_user.uid。
|
||||
func NewOaDocActor(tid int, uid uint64) OaDocActor {
|
||||
// 补建租户自己的系统内置分类(项目文档),按 tid 隔离
|
||||
models.EnsureOaDocDefaultCategories(tid)
|
||||
|
||||
actor := OaDocActor{Tid: tid, UID: uid, OrgIDs: []uint64{}}
|
||||
|
||||
var user models.SystemTenantUser
|
||||
// uid 来自令牌(identity_id),查老表前先换算成老 uid
|
||||
if err := models.Orm.QueryTable(new(models.SystemTenantUser)).
|
||||
Filter("tid", tid).
|
||||
Filter("uid", ResolveTenantUID(uint64(tid), uid)).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&user); err != nil {
|
||||
// 查不到归属信息时退化为"普通用户",仅能看公开文档
|
||||
return actor
|
||||
}
|
||||
actor.IsAdmin = user.GroupID == 0
|
||||
@@ -77,7 +60,6 @@ func NewOaDocActor(tid int, uid uint64) OaDocActor {
|
||||
return actor
|
||||
}
|
||||
|
||||
// oaDocOrgSubTree 返回指定组织及其全部子组织 ID(含自身)。
|
||||
func oaDocOrgSubTree(tid int, rootID uint64) []uint64 {
|
||||
var orgs []models.BackendOrganization
|
||||
if _, err := models.Orm.QueryTable(new(models.BackendOrganization)).
|
||||
@@ -107,14 +89,13 @@ func oaDocOrgSubTree(tid int, rootID uint64) []uint64 {
|
||||
return result
|
||||
}
|
||||
|
||||
// oaDocSharedDocIDs 查询共享给该访问者(本人或所属部门)的文档 ID。
|
||||
func oaDocSharedDocIDs(a OaDocActor) []uint64 {
|
||||
if a.UID == 0 && len(a.OrgIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
orgIDs := a.OrgIDs
|
||||
if len(orgIDs) == 0 {
|
||||
orgIDs = []uint64{0} // 避免 SQL 出现 IN ()
|
||||
orgIDs = []uint64{0}
|
||||
}
|
||||
|
||||
userCond := orm.NewCondition().
|
||||
@@ -143,15 +124,13 @@ func oaDocSharedDocIDs(a OaDocActor) []uint64 {
|
||||
return ids
|
||||
}
|
||||
|
||||
// oaDocVisibleCond 生成可见性条件;管理员返回 nil 表示不限制。
|
||||
// 可见 = 公开 OR 本人创建 OR 已共享给本人/所属部门
|
||||
func oaDocVisibleCond(a OaDocActor) *orm.Condition {
|
||||
if a.IsAdmin {
|
||||
return nil
|
||||
}
|
||||
shared := oaDocSharedDocIDs(a)
|
||||
if len(shared) == 0 {
|
||||
shared = []uint64{0} // 避免 SQL 出现 IN ()
|
||||
shared = []uint64{0}
|
||||
}
|
||||
return orm.NewCondition().
|
||||
Or("visibility", models.DocVisibilityPublic).
|
||||
@@ -159,7 +138,6 @@ func oaDocVisibleCond(a OaDocActor) *orm.Condition {
|
||||
Or("id__in", shared)
|
||||
}
|
||||
|
||||
// oaDocApplyVisible 给既有查询集叠加可见性条件(保留此前设置的过滤条件)。
|
||||
func oaDocApplyVisible(qs orm.QuerySeter, a OaDocActor) orm.QuerySeter {
|
||||
cond := oaDocVisibleCond(a)
|
||||
if cond == nil {
|
||||
@@ -168,21 +146,13 @@ func oaDocApplyVisible(qs orm.QuerySeter, a OaDocActor) orm.QuerySeter {
|
||||
return qs.SetCond(qs.GetCond().AndCond(cond))
|
||||
}
|
||||
|
||||
// ---------------- 可见性(共享 / 私密) ----------------
|
||||
//
|
||||
// 文档库按「共享文档 / 私密文档」两个空间组织,每个空间各自一棵分类树;
|
||||
// 文档可见性由 visibility 决定,并与所在空间一一对应:0=租户公开(共享空间),1=私密(私密空间,仅创建者及被共享者可见)。
|
||||
// "我的文档"由 creator_id 决定,不与空间字段强耦合。
|
||||
|
||||
// oaDocVisibilityRestrictSQL 生成 Raw SQL 场景复用的「用户级可见性」条件片段
|
||||
// (非管理员才附加:公开 OR 本人创建 OR 已共享给我)。prefix 为表别名前缀。
|
||||
func oaDocVisibilityRestrictSQL(a OaDocActor, prefix string) (string, []interface{}) {
|
||||
if a.IsAdmin {
|
||||
return "", nil
|
||||
}
|
||||
shared := oaDocSharedDocIDs(a)
|
||||
if len(shared) == 0 {
|
||||
shared = []uint64{0} // 避免 SQL 出现 IN ()
|
||||
shared = []uint64{0}
|
||||
}
|
||||
placeholders := make([]string, len(shared))
|
||||
for i := range shared {
|
||||
@@ -197,8 +167,6 @@ func oaDocVisibilityRestrictSQL(a OaDocActor, prefix string) (string, []interfac
|
||||
prefix, prefix, prefix, strings.Join(placeholders, ",")), args
|
||||
}
|
||||
|
||||
// oaDocApplyVisibility 给查询集叠加绝对可见性过滤(按文档自身的 visibility 字段)。
|
||||
// v<0 不过滤;0=公开;1=私密。
|
||||
func oaDocApplyVisibility(qs orm.QuerySeter, v int) orm.QuerySeter {
|
||||
switch v {
|
||||
case 0:
|
||||
@@ -210,7 +178,6 @@ func oaDocApplyVisibility(qs orm.QuerySeter, v int) orm.QuerySeter {
|
||||
}
|
||||
}
|
||||
|
||||
// oaDocVisibleIDSet 从给定文档 ID 中筛出当前访问者可见的部分。
|
||||
func oaDocVisibleIDSet(a OaDocActor, ids []uint64) map[uint64]bool {
|
||||
out := make(map[uint64]bool, len(ids))
|
||||
if len(ids) == 0 {
|
||||
@@ -229,8 +196,6 @@ func oaDocVisibleIDSet(a OaDocActor, ids []uint64) map[uint64]bool {
|
||||
return out
|
||||
}
|
||||
|
||||
// oaDocCanManage 私密文档的管理权限:仅创建者与全权限用户可改删。
|
||||
// 公开文档沿用租户内共享编辑的既有行为。
|
||||
func oaDocCanManage(a OaDocActor, doc *models.OaDoc) bool {
|
||||
if a.IsAdmin || doc.Visibility != models.DocVisibilityPrivate {
|
||||
return true
|
||||
@@ -238,7 +203,6 @@ func oaDocCanManage(a OaDocActor, doc *models.OaDoc) bool {
|
||||
return doc.CreatorID == a.UID
|
||||
}
|
||||
|
||||
// 文档关系中文名
|
||||
var docRelationLabel = map[string]string{
|
||||
models.DocRelationReference: "引用",
|
||||
models.DocRelationRelated: "相关",
|
||||
@@ -246,7 +210,6 @@ var docRelationLabel = map[string]string{
|
||||
models.DocRelationBelong: "从属",
|
||||
}
|
||||
|
||||
// DocRelationLabel 返回关系的中文名,未知关系原样返回。
|
||||
func DocRelationLabel(relation string) string {
|
||||
if v, ok := docRelationLabel[relation]; ok {
|
||||
return v
|
||||
@@ -254,18 +217,12 @@ func DocRelationLabel(relation string) string {
|
||||
return relation
|
||||
}
|
||||
|
||||
// ---------------- 分类 ----------------
|
||||
|
||||
// OaDocCategoryItem 分类树节点(附带文档数量)
|
||||
type OaDocCategoryItem struct {
|
||||
models.OaDocCategory
|
||||
DocCount int64 `json:"doc_count"`
|
||||
Children []*OaDocCategoryItem `json:"children"`
|
||||
}
|
||||
|
||||
// ---------------- 范围(共享 / 私密) ----------------
|
||||
|
||||
// oaDocScopeOf 归一化范围参数:空或未知一律视为共享文档空间。
|
||||
func oaDocScopeOf(scope string) string {
|
||||
if scope == models.DocScopePersonal {
|
||||
return models.DocScopePersonal
|
||||
@@ -276,7 +233,6 @@ func oaDocScopeOf(scope string) string {
|
||||
return models.DocScopeShared
|
||||
}
|
||||
|
||||
// oaDocScopeVisibility 返回某范围对应的文档可见性:私密→私密(1),其余→租户公开(0)。
|
||||
func oaDocScopeVisibility(scope string) int8 {
|
||||
if scope == models.DocScopePersonal {
|
||||
return models.DocVisibilityPrivate
|
||||
@@ -284,7 +240,6 @@ func oaDocScopeVisibility(scope string) int8 {
|
||||
return models.DocVisibilityPublic
|
||||
}
|
||||
|
||||
// oaDocScopeOfVisibility 由文档可见性反推范围:私密(1)→私密文档空间,其余→共享文档空间。
|
||||
func oaDocScopeOfVisibility(v int8) string {
|
||||
if v == models.DocVisibilityPrivate {
|
||||
return models.DocScopePersonal
|
||||
@@ -292,7 +247,6 @@ func oaDocScopeOfVisibility(v int8) string {
|
||||
return models.DocScopeShared
|
||||
}
|
||||
|
||||
// oaDocCategoryUserID 返回某范围下分类的归属用户:共享→0(租户级),私密→当前用户(绑定到用户级别)。
|
||||
func oaDocCategoryUserID(a OaDocActor, scope string) uint64 {
|
||||
if scope == models.DocScopePersonal {
|
||||
return a.UID
|
||||
@@ -300,21 +254,15 @@ func oaDocCategoryUserID(a OaDocActor, scope string) uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// oaDocCategoryBaseAny 租户内未删除分类的基础查询集(不限范围,用于按 ID 检索 / 权限校验)
|
||||
func oaDocCategoryBaseAny(tid int) orm.QuerySeter {
|
||||
return models.Orm.QueryTable(new(models.OaDocCategory)).
|
||||
Filter("tid", tid).
|
||||
Filter("is_deleted", 0)
|
||||
}
|
||||
|
||||
// oaDocCategoryBase 返回指定范围内的未删除分类基础查询集。
|
||||
// 共享空间:scope=shared 且 user_id=0(租户级,所有人共用);
|
||||
// 私密空间:scope=personal 且 user_id=当前用户(绑定到用户级别,互不干扰);
|
||||
// all:跨两个空间(仅图谱等全局视图使用)。
|
||||
func oaDocCategoryBase(a OaDocActor, scope string) orm.QuerySeter {
|
||||
s := oaDocScopeOf(scope)
|
||||
if s == models.DocScopeAll {
|
||||
// 跨空间:不加 scope / user_id 过滤
|
||||
return oaDocCategoryBaseAny(a.Tid)
|
||||
}
|
||||
qs := oaDocCategoryBaseAny(a.Tid).Filter("scope", s)
|
||||
@@ -326,7 +274,6 @@ func oaDocCategoryBase(a OaDocActor, scope string) orm.QuerySeter {
|
||||
return qs
|
||||
}
|
||||
|
||||
// oaDocCategoryIDs 返回指定范围内全部未删除分类的 ID。
|
||||
func oaDocCategoryIDs(a OaDocActor, scope string) ([]uint64, error) {
|
||||
var list []models.OaDocCategory
|
||||
qs := oaDocCategoryBaseAny(a.Tid)
|
||||
@@ -349,18 +296,14 @@ func oaDocCategoryIDs(a OaDocActor, scope string) ([]uint64, error) {
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// oaDocApplyUncategorized 筛选"未分类"文档:category_id=0 或不属于当前范围任何分类。
|
||||
func oaDocApplyUncategorized(qs orm.QuerySeter, a OaDocActor, scope string) orm.QuerySeter {
|
||||
ids, err := oaDocCategoryIDs(a, scope)
|
||||
if err != nil || len(ids) == 0 {
|
||||
return qs // 范围内没有任何分类,全部视为未分类
|
||||
return qs
|
||||
}
|
||||
return qs.Exclude("category_id__in", ids)
|
||||
}
|
||||
|
||||
// OaDocCategoryTree 返回指定范围内的文档分类树,每个节点附带该分类下的文档数量。
|
||||
// scope="shared" 返回共享空间树(租户级),scope="personal" 返回当前用户的私密空间树。
|
||||
// 系统内置分类(项目文档)置顶;数量统计受可见性约束:无权限的私密文档不计入。
|
||||
func OaDocCategoryTree(a OaDocActor, scope string) ([]*OaDocCategoryItem, error) {
|
||||
|
||||
scope = oaDocScopeOf(scope)
|
||||
@@ -384,7 +327,6 @@ func OaDocCategoryTree(a OaDocActor, scope string) ([]*OaDocCategoryItem, error)
|
||||
}
|
||||
nodes[item.ID] = item
|
||||
}
|
||||
// 父节点必须也在本范围内(私密空间的父节点不会是共享空间的分类),否则归入根
|
||||
for i := range list {
|
||||
item := nodes[list[i].ID]
|
||||
if parent, ok := nodes[list[i].ParentID]; ok && list[i].ParentID != 0 {
|
||||
@@ -393,8 +335,6 @@ func OaDocCategoryTree(a OaDocActor, scope string) ([]*OaDocCategoryItem, error)
|
||||
roots = append(roots, item)
|
||||
}
|
||||
}
|
||||
// 汇总子孙分类的文档数到父级:父级展示的是"包含所有子分类"的文档总数,
|
||||
// 避免出现父级有子分类却显示 0 的情况。
|
||||
var rollup func(item *OaDocCategoryItem) int64
|
||||
rollup = func(item *OaDocCategoryItem) int64 {
|
||||
total := item.DocCount
|
||||
@@ -410,9 +350,6 @@ func OaDocCategoryTree(a OaDocActor, scope string) ([]*OaDocCategoryItem, error)
|
||||
return roots, nil
|
||||
}
|
||||
|
||||
// OaDocCountByCategory 统计指定范围内各分类下未删除文档的数量。
|
||||
// visibility<0 时按范围自动取对应可见性(共享→公开,私密→私密);可见性约束同样生效:无权限的私密文档不计入。
|
||||
// scope="all" 时跨两个空间统计(不限定 visibility)。
|
||||
func OaDocCountByCategory(a OaDocActor, scope string, visibility int) (map[uint64]int64, error) {
|
||||
|
||||
scope = oaDocScopeOf(scope)
|
||||
@@ -446,17 +383,11 @@ func OaDocCountByCategory(a OaDocActor, scope string, visibility int) (map[uint6
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// oaDocIsReservedName 判断分类名是否为系统保留名。
|
||||
// 「未分类」是虚拟分类(文档 category_id=0),不允许新建同名真实分类;
|
||||
// 「项目文档」为系统内置分类名(共享空间),禁止重复创建。
|
||||
func oaDocIsReservedName(name string) bool {
|
||||
name = strings.TrimSpace(name)
|
||||
return name == "未分类" || name == models.DocCategoryNameProject
|
||||
}
|
||||
|
||||
// OaDocCategoryCreate 在指定空间下新建分类。
|
||||
// scope="shared" 创建到共享空间(user_id=0,租户级);scope="personal" 创建到当前用户的私密空间(user_id=uid)。
|
||||
// 父级分类必须与目标空间一致,否则视为不存在。
|
||||
func OaDocCategoryCreate(a OaDocActor, scope string, parentID uint64, name, remark string, sort int) (*models.OaDocCategory, error) {
|
||||
|
||||
scope = oaDocScopeOf(scope)
|
||||
@@ -493,7 +424,6 @@ func OaDocCategoryCreate(a OaDocActor, scope string, parentID uint64, name, rema
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// OaDocCategoryUpdate 修改分类名称/备注/排序,parentID < 0 表示不调整父级。
|
||||
func OaDocCategoryUpdate(a OaDocActor, id uint64, name, remark string, sort int, parentID int64) (*models.OaDocCategory, error) {
|
||||
|
||||
var item models.OaDocCategory
|
||||
@@ -561,8 +491,6 @@ func OaDocCategoryUpdate(a OaDocActor, id uint64, name, remark string, sort int,
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// OaDocCategoryDescendants 收集某分类的全部子孙 ID(不含自身)。
|
||||
// 遍历租户内全部未删除分类(跨空间),用于移动时的环路检测。
|
||||
func OaDocCategoryDescendants(a OaDocActor, rootID uint64) ([]uint64, error) {
|
||||
var list []models.OaDocCategory
|
||||
if _, err := oaDocCategoryBaseAny(a.Tid).All(&list); err != nil && err != orm.ErrNoRows {
|
||||
@@ -588,7 +516,6 @@ func OaDocCategoryDescendants(a OaDocActor, rootID uint64) ([]uint64, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// oaDocCategoryIDsWithChildren 返回指定分类及其所有子孙 ID;rootID=0 时返回 nil 表示不限制。
|
||||
func oaDocCategoryIDsWithChildren(a OaDocActor, scope string, rootID uint64) ([]uint64, error) {
|
||||
if rootID == 0 {
|
||||
return nil, nil
|
||||
@@ -600,15 +527,12 @@ func oaDocCategoryIDsWithChildren(a OaDocActor, scope string, rootID uint64) ([]
|
||||
return append([]uint64{rootID}, children...), nil
|
||||
}
|
||||
|
||||
// OaDocCategoryDelete 删除分类:系统内置分类、存在子分类或文档时拒绝删除。
|
||||
// 共享空间分类任何租户成员均可删除(内置分类除外);私密空间分类仅本人可删除。
|
||||
func OaDocCategoryDelete(a OaDocActor, id uint64) error {
|
||||
|
||||
var item models.OaDocCategory
|
||||
if err := oaDocCategoryBaseAny(a.Tid).Filter("id", id).One(&item); err != nil {
|
||||
return ErrDocCategoryNotFound
|
||||
}
|
||||
// 内置分类(如「项目文档」)为默认分类,任何租户都不可删除
|
||||
if item.IsSystem == models.DocCategorySystem {
|
||||
return ErrDocCategorySystem
|
||||
}
|
||||
@@ -641,7 +565,6 @@ func OaDocCategoryDelete(a OaDocActor, id uint64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// oaDocCategoryExists 判断指定范围内是否存在该分类(私密空间按 user_id 隔离)。
|
||||
func oaDocCategoryExists(a OaDocActor, scope string, id uint64) (bool, error) {
|
||||
n, err := oaDocCategoryBase(a, scope).Filter("id", id).Count()
|
||||
if err != nil {
|
||||
@@ -650,8 +573,6 @@ func oaDocCategoryExists(a OaDocActor, scope string, id uint64) (bool, error) {
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
// oaDocCheckCategoryOwner 校验分类是否可被该访问者操作。
|
||||
// 共享分类(user_id=0)租户内任何成员均可操作;私密分类(user_id>0)仅归属用户本人可操作。
|
||||
func oaDocCheckCategoryOwner(a OaDocActor, item *models.OaDocCategory) error {
|
||||
if item.UserID == 0 {
|
||||
return nil
|
||||
@@ -662,8 +583,6 @@ func oaDocCheckCategoryOwner(a OaDocActor, item *models.OaDocCategory) error {
|
||||
return ErrDocCategoryNotFound
|
||||
}
|
||||
|
||||
// oaDocCategoryUsable 读取指定范围内的分类并校验当前访问者是否可以使用它(用于文档归类)。
|
||||
// 不存在或不属于当前范围/用户时返回 ok=false。
|
||||
func oaDocCategoryUsable(a OaDocActor, scope string, id uint64) (models.OaDocCategory, bool, error) {
|
||||
var item models.OaDocCategory
|
||||
if err := oaDocCategoryBase(a, scope).Filter("id", id).One(&item); err != nil {
|
||||
@@ -672,27 +591,20 @@ func oaDocCategoryUsable(a OaDocActor, scope string, id uint64) (models.OaDocCat
|
||||
return item, true, nil
|
||||
}
|
||||
|
||||
// ---------------- 文档 ----------------
|
||||
|
||||
// oaDocBase 租户内未删除文档的基础查询集
|
||||
func oaDocBase(tid int) orm.QuerySeter {
|
||||
return models.Orm.QueryTable(new(models.OaDoc)).
|
||||
Filter("tid", tid).
|
||||
Filter("is_deleted", 0)
|
||||
}
|
||||
|
||||
// OaDocListParams 文档列表查询条件。
|
||||
// Scope 限定空间:"shared"=共享文档(租户公开),"personal"=私密文档(绑定用户级别),"all"=跨两个空间。
|
||||
// Status/DocType/Star 使用 -1 表示"全部";CategoryID > 0 时包含其全部子孙分类(须与 Scope 同空间)。
|
||||
// Mine 为 true 时只看本人创建的文档。Actor 用于租户内用户级可见性过滤。
|
||||
type OaDocListParams struct {
|
||||
Actor OaDocActor
|
||||
Scope string
|
||||
Keyword string
|
||||
CategoryID uint64
|
||||
Uncategorized bool // true 时只看未分类(category_id = 0)的文档
|
||||
Visibility int // -1 不限(由 Scope 推导);0 公开;1 私密
|
||||
Mine bool // true 时只看本人创建的文档
|
||||
Uncategorized bool
|
||||
Visibility int
|
||||
Mine bool
|
||||
Status int
|
||||
DocType int
|
||||
Tag string
|
||||
@@ -701,7 +613,6 @@ type OaDocListParams struct {
|
||||
PageSize int
|
||||
}
|
||||
|
||||
// OaDocList 分页查询文档(自动应用可见性与范围过滤)。
|
||||
func OaDocList(a OaDocActor, p OaDocListParams) ([]models.OaDoc, int64, error) {
|
||||
|
||||
scope := oaDocScopeOf(p.Scope)
|
||||
@@ -731,7 +642,6 @@ func OaDocList(a OaDocActor, p OaDocListParams) ([]models.OaDoc, int64, error) {
|
||||
if len(ids) > 0 {
|
||||
qs = qs.Filter("category_id__in", ids)
|
||||
} else {
|
||||
// 所选分类不在当前空间,直接返回空结果
|
||||
qs = qs.Filter("category_id__in", []uint64{})
|
||||
}
|
||||
}
|
||||
@@ -771,7 +681,6 @@ func OaDocList(a OaDocActor, p OaDocListParams) ([]models.OaDoc, int64, error) {
|
||||
if list == nil {
|
||||
list = []models.OaDoc{}
|
||||
}
|
||||
// 列表不返回体积较大的编辑源,仅标记是否在线制作
|
||||
for i := range list {
|
||||
if strings.TrimSpace(list[i].Content) != "" {
|
||||
list[i].IsOnline = 1
|
||||
@@ -781,7 +690,6 @@ func OaDocList(a OaDocActor, p OaDocListParams) ([]models.OaDoc, int64, error) {
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
// OaDocGet 读取文档详情(不累加查看次数)。私密文档对无权限者返回未找到。
|
||||
func OaDocGet(a OaDocActor, id uint64) (*models.OaDoc, error) {
|
||||
|
||||
var item models.OaDoc
|
||||
@@ -792,7 +700,6 @@ func OaDocGet(a OaDocActor, id uint64) (*models.OaDoc, error) {
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// OaDocView 读取文档详情并累加查看次数。
|
||||
func OaDocView(a OaDocActor, id uint64) (*models.OaDoc, error) {
|
||||
item, err := OaDocGet(a, id)
|
||||
if err != nil {
|
||||
@@ -804,7 +711,6 @@ func OaDocView(a OaDocActor, id uint64) (*models.OaDoc, error) {
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// OaDocDownload 记录一次下载并回传文档(供前端拿到下载地址)。
|
||||
func OaDocDownload(a OaDocActor, id uint64) (*models.OaDoc, error) {
|
||||
item, err := OaDocGet(a, id)
|
||||
if err != nil {
|
||||
@@ -816,13 +722,9 @@ func OaDocDownload(a OaDocActor, id uint64) (*models.OaDoc, error) {
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// OaDocSaveParams 文档新增/编辑入参。
|
||||
// SetCategory 为 true 时才以 CategoryID 覆盖原值(允许显式改为 0 即"未分类")。
|
||||
type OaDocSaveParams struct {
|
||||
SetCategory bool
|
||||
CategoryID uint64
|
||||
// SetVisibility 为 true 时才以 Visibility 覆盖原值,
|
||||
// 避免"未传该字段"被当成"改为租户公开"(int8 零值无法区分未传与显式 0)
|
||||
SetVisibility bool
|
||||
Title string
|
||||
FileID uint64
|
||||
@@ -832,7 +734,6 @@ type OaDocSaveParams struct {
|
||||
Size uint64
|
||||
Tags string
|
||||
Summary string
|
||||
// Content 在线制作文档的编辑源(富文本 HTML),SetContent 为 true 时才覆盖
|
||||
SetContent bool
|
||||
Content string
|
||||
Status int8
|
||||
@@ -840,11 +741,9 @@ type OaDocSaveParams struct {
|
||||
OwnerID uint64
|
||||
OwnerName string
|
||||
IsStar int8
|
||||
Visibility int8 // 0-租户公开 1-私密
|
||||
Visibility int8
|
||||
}
|
||||
|
||||
// OaDocCreate 新增文档。
|
||||
// 若未传标题则回退为原始文件名(去扩展名);doc_type 由扩展名推断。
|
||||
func OaDocCreate(a OaDocActor, operatorName string, p OaDocSaveParams) (*models.OaDoc, error) {
|
||||
tid := a.Tid
|
||||
|
||||
@@ -855,7 +754,6 @@ func OaDocCreate(a OaDocActor, operatorName string, p OaDocSaveParams) (*models.
|
||||
if title == "" {
|
||||
return nil, ErrDocTitleEmpty
|
||||
}
|
||||
// 分类须与文档可见性同空间:共享(visibility=0)→共享空间;私密(visibility=1)→私密空间(绑定用户级别)。
|
||||
if p.CategoryID > 0 {
|
||||
scope := oaDocScopeOfVisibility(p.Visibility)
|
||||
if _, ok, err := oaDocCategoryUsable(a, scope, p.CategoryID); err != nil {
|
||||
@@ -906,7 +804,6 @@ func OaDocCreate(a OaDocActor, operatorName string, p OaDocSaveParams) (*models.
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// visibilityOf 归一化可见性取值:仅 1 视为私密,其余一律公开。
|
||||
func visibilityOf(v int8) int8 {
|
||||
if v == 1 {
|
||||
return 1
|
||||
@@ -914,7 +811,6 @@ func visibilityOf(v int8) int8 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// OaDocUpdate 编辑文档(仅更新传入的字段)。
|
||||
func OaDocUpdate(a OaDocActor, id uint64, p OaDocSaveParams) (*models.OaDoc, error) {
|
||||
|
||||
var item models.OaDoc
|
||||
@@ -927,7 +823,6 @@ func OaDocUpdate(a OaDocActor, id uint64, p OaDocSaveParams) (*models.OaDoc, err
|
||||
|
||||
fields := []string{"UpdateTime"}
|
||||
if p.SetCategory && p.CategoryID != item.CategoryID {
|
||||
// 分类须与文档可见性同空间:以"更新后"的可见性推导范围
|
||||
if p.CategoryID > 0 {
|
||||
v := item.Visibility
|
||||
if p.SetVisibility {
|
||||
@@ -1004,7 +899,6 @@ func OaDocUpdate(a OaDocActor, id uint64, p OaDocSaveParams) (*models.OaDoc, err
|
||||
item.OwnerName = owner
|
||||
fields = append(fields, "OwnerName")
|
||||
}
|
||||
// 在线文档编辑源:仅在显式传入时覆盖
|
||||
if p.SetContent && p.Content != item.Content {
|
||||
item.Content = p.Content
|
||||
fields = append(fields, "Content")
|
||||
@@ -1021,8 +915,6 @@ func OaDocUpdate(a OaDocActor, id uint64, p OaDocSaveParams) (*models.OaDoc, err
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// OaDocDelete 批量软删除文档,并清理与被删文档相关的关联关系。
|
||||
// 仅对"可见且可管理"的文档生效;若给定 ID 全部无权操作则返回 ErrDocNoPermission。
|
||||
func OaDocDelete(a OaDocActor, ids []uint64) (int64, error) {
|
||||
|
||||
ids = normalizeIDs(ids)
|
||||
@@ -1065,14 +957,12 @@ func OaDocDelete(a OaDocActor, ids []uint64) (int64, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// OaDocMove 批量移动文档到目标分类(0 表示未分类)。仅对可管理文档生效。
|
||||
func OaDocMove(a OaDocActor, ids []uint64, categoryID uint64) (int64, error) {
|
||||
|
||||
ids = normalizeIDs(ids)
|
||||
if len(ids) == 0 {
|
||||
return 0, ErrDocIDEmpty
|
||||
}
|
||||
// 移动仅改变文档归属分类;分类须与每篇文档的可见性同空间(共享/私密)
|
||||
if categoryID > 0 {
|
||||
var sample models.OaDoc
|
||||
if _, err := oaDocApplyVisible(oaDocBase(a.Tid).Filter("id__in", ids), a).OrderBy("id").Limit(1).All(&sample); err == nil {
|
||||
@@ -1107,7 +997,6 @@ func OaDocMove(a OaDocActor, ids []uint64, categoryID uint64) (int64, error) {
|
||||
return oaDocBase(a.Tid).Filter("id__in", allowed).Update(params)
|
||||
}
|
||||
|
||||
// OaDocToggleStar 收藏 / 取消收藏切换,返回切换后的状态。
|
||||
func OaDocToggleStar(a OaDocActor, id uint64) (int8, error) {
|
||||
|
||||
var item models.OaDoc
|
||||
@@ -1125,7 +1014,6 @@ func OaDocToggleStar(a OaDocActor, id uint64) (int8, error) {
|
||||
return item.IsStar, nil
|
||||
}
|
||||
|
||||
// OaDocStatsResult 文档库概览统计
|
||||
type OaDocStatsResult struct {
|
||||
Total int64 `json:"total"`
|
||||
Published int64 `json:"published"`
|
||||
@@ -1134,23 +1022,19 @@ type OaDocStatsResult struct {
|
||||
Starred int64 `json:"starred"`
|
||||
Uncategorized int64 `json:"uncategorized"`
|
||||
LinkCount int64 `json:"link_count"`
|
||||
// 可见性维度概览(不受当前 visibility 筛选影响,始终反映全库口径):
|
||||
PublicCount int64 `json:"public_count"` // 团队公开文档数
|
||||
PrivateCount int64 `json:"private_count"` // 私密文档数
|
||||
MineCount int64 `json:"mine_count"` // 我创建的文档数
|
||||
PublicCount int64 `json:"public_count"`
|
||||
PrivateCount int64 `json:"private_count"`
|
||||
MineCount int64 `json:"mine_count"`
|
||||
TypeCounts []OaDocTypeCount `json:"type_counts"`
|
||||
RecentDocs []models.OaDoc `json:"recent_docs"`
|
||||
HotDocs []models.OaDoc `json:"hot_docs"`
|
||||
}
|
||||
|
||||
// OaDocTypeCount 按文档类型统计
|
||||
type OaDocTypeCount struct {
|
||||
DocType int8 `json:"doc_type"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
// OaDocStats 文档库概览:总数、状态分布、类型分布、最近更新与热门文档。
|
||||
// scope 限定统计口径("shared" 共享文档空间 / "personal" 私密文档空间 / "all" 跨空间);可见性约束同样生效。
|
||||
func OaDocStats(a OaDocActor, scope string) (*OaDocStatsResult, error) {
|
||||
|
||||
scope = oaDocScopeOf(scope)
|
||||
@@ -1159,7 +1043,6 @@ func OaDocStats(a OaDocActor, scope string) (*OaDocStatsResult, error) {
|
||||
vis = oaDocScopeVisibility(scope)
|
||||
}
|
||||
|
||||
// 当前范围内的全部可见文档(私密仅创建者/被共享者可见)
|
||||
allVisible := oaDocApplyVisible(oaDocBase(a.Tid), a)
|
||||
if vis >= 0 {
|
||||
allVisible = allVisible.Filter("visibility", vis)
|
||||
@@ -1174,7 +1057,6 @@ func OaDocStats(a OaDocActor, scope string) (*OaDocStatsResult, error) {
|
||||
starred, _ := base.Filter("is_star", 1).Count()
|
||||
uncategorized, _ := oaDocApplyUncategorized(base, a, scope).Count()
|
||||
|
||||
// 关联数只统计"当前空间口径下文档发起"的连线
|
||||
linkCount := int64(0)
|
||||
linkExtra, linkExtraArgs := oaDocVisibilityRestrictSQL(a, "d.")
|
||||
linkArgs := []interface{}{a.Tid}
|
||||
@@ -1257,9 +1139,6 @@ func OaDocStats(a OaDocActor, scope string) (*OaDocStatsResult, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ---------------- 文档关联 ----------------
|
||||
|
||||
// OaDocLinkItem 关联关系 + 两端文档标题,便于前端直接展示
|
||||
type OaDocLinkItem struct {
|
||||
ID uint64 `json:"id"`
|
||||
Tid int `json:"tid"`
|
||||
@@ -1274,7 +1153,6 @@ type OaDocLinkItem struct {
|
||||
TargetTitle string `json:"target_title"`
|
||||
}
|
||||
|
||||
// OaDocLinkCreate 建立两个文档之间的关联。
|
||||
func OaDocLinkCreate(a OaDocActor, creatorID, sourceID, targetID uint64, relation, remark string) (*models.OaDocLink, error) {
|
||||
tid := a.Tid
|
||||
|
||||
@@ -1290,7 +1168,6 @@ func OaDocLinkCreate(a OaDocActor, creatorID, sourceID, targetID uint64, relatio
|
||||
}
|
||||
|
||||
for _, id := range []uint64{sourceID, targetID} {
|
||||
// 关联两端文档必须对当前访问者可见,避免私密文档被越权串接
|
||||
if _, err := OaDocGet(a, id); err != nil {
|
||||
return nil, ErrDocLinkTargetNotFound
|
||||
}
|
||||
@@ -1317,18 +1194,15 @@ func OaDocLinkCreate(a OaDocActor, creatorID, sourceID, targetID uint64, relatio
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 反向补一条同类关系,使图谱连线无向展示
|
||||
reverse := *item
|
||||
reverse.ID = 0
|
||||
reverse.SourceID, reverse.TargetID = targetID, sourceID
|
||||
if _, err := models.Orm.Insert(&reverse); err != nil {
|
||||
// 唯一索引冲突说明反向关系已存在,忽略即可
|
||||
_ = err
|
||||
}
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// OaDocLinkDelete 删除关联关系(同时清理反向关系,保证图谱双向一致)。
|
||||
func OaDocLinkDelete(a OaDocActor, id uint64) error {
|
||||
tid := a.Tid
|
||||
|
||||
@@ -1337,7 +1211,6 @@ func OaDocLinkDelete(a OaDocActor, id uint64) error {
|
||||
Filter("tid", tid).Filter("id", id).One(&item); err != nil {
|
||||
return ErrDocLinkNotFound
|
||||
}
|
||||
// 关联两端文档必须对当前访问者可见,避免私密文档被越权解除关联
|
||||
if _, err := OaDocGet(a, item.SourceID); err != nil {
|
||||
return ErrDocNoPermission
|
||||
}
|
||||
@@ -1345,7 +1218,6 @@ func OaDocLinkDelete(a OaDocActor, id uint64) error {
|
||||
return ErrDocNoPermission
|
||||
}
|
||||
|
||||
// SetCond 会整体替换查询条件,tid 必须写进 cond
|
||||
forward := orm.NewCondition().
|
||||
And("source_id", item.SourceID).
|
||||
And("target_id", item.TargetID).
|
||||
@@ -1361,8 +1233,6 @@ func OaDocLinkDelete(a OaDocActor, id uint64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// OaDocLinkList 查询与某文档相关的全部关联(含反向),all 为 true 时返回租户全部关联。
|
||||
// 仅返回两端文档对当前访问者均可见的关联,避免私密文档被越权探查。
|
||||
func OaDocLinkList(a OaDocActor, docID uint64, all bool) ([]OaDocLinkItem, error) {
|
||||
|
||||
sql := `
|
||||
@@ -1386,7 +1256,6 @@ LEFT JOIN yz_backend_oa_doc t ON t.id = l.target_id AND t.is_deleted = 0
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 收集所有涉及的文档 ID,批量判定可见性后过滤
|
||||
endpointIDs := make([]uint64, 0, len(rows)*2)
|
||||
seen := make(map[uint64]bool, len(rows)*2)
|
||||
for _, r := range rows {
|
||||
@@ -1415,15 +1284,11 @@ LEFT JOIN yz_backend_oa_doc t ON t.id = l.target_id AND t.is_deleted = 0
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ---------------- 文档共享(私密文档可见性授权) ----------------
|
||||
|
||||
// OaDocShareItem 共享目标项(创建/更新入参)。
|
||||
type OaDocShareItem struct {
|
||||
ShareType int8 `json:"share_type"` // 0-用户 1-部门
|
||||
ShareType int8 `json:"share_type"`
|
||||
TargetID uint64 `json:"target_id"`
|
||||
}
|
||||
|
||||
// OaDocShareView 共享项视图(含目标名称)。
|
||||
type OaDocShareView struct {
|
||||
ID uint64 `json:"id"`
|
||||
DocID uint64 `json:"doc_id"`
|
||||
@@ -1432,7 +1297,6 @@ type OaDocShareView struct {
|
||||
TargetName string `json:"target_name"`
|
||||
}
|
||||
|
||||
// OaDocShareList 读取文档的共享清单(仅可见文档)。
|
||||
func OaDocShareList(a OaDocActor, docID uint64) ([]OaDocShareView, error) {
|
||||
if _, err := OaDocGet(a, docID); err != nil {
|
||||
return nil, err
|
||||
@@ -1458,7 +1322,6 @@ func OaDocShareList(a OaDocActor, docID uint64) ([]OaDocShareView, error) {
|
||||
return views, nil
|
||||
}
|
||||
|
||||
// oaDocShareTargetName 解析共享目标名称(用户姓名 / 部门名称)。
|
||||
func oaDocShareTargetName(tid int, shareType int8, targetID uint64) string {
|
||||
if targetID == 0 {
|
||||
return ""
|
||||
@@ -1481,7 +1344,6 @@ func oaDocShareTargetName(tid int, shareType int8, targetID uint64) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// OaDocShareSet 全量替换文档的共享授权:仅创建者或全权限用户可设置。
|
||||
func OaDocShareSet(a OaDocActor, docID uint64, items []OaDocShareItem) ([]OaDocShareView, error) {
|
||||
doc, err := OaDocGet(a, docID)
|
||||
if err != nil {
|
||||
@@ -1509,7 +1371,6 @@ func OaDocShareSet(a OaDocActor, docID uint64, items []OaDocShareItem) ([]OaDocS
|
||||
clean = append(clean, OaDocShareItem{ShareType: st, TargetID: it.TargetID})
|
||||
}
|
||||
|
||||
// 全量替换:先清空再写入
|
||||
if _, err := models.Orm.QueryTable(new(models.OaDocShare)).
|
||||
Filter("tid", a.Tid).Filter("doc_id", docID).Delete(); err != nil {
|
||||
return nil, err
|
||||
@@ -1529,7 +1390,6 @@ func OaDocShareSet(a OaDocActor, docID uint64, items []OaDocShareItem) ([]OaDocS
|
||||
return OaDocShareList(a, docID)
|
||||
}
|
||||
|
||||
// OaDocShareRemove 删除单条共享授权(需对文档可管理)。
|
||||
func OaDocShareRemove(a OaDocActor, id uint64) error {
|
||||
var item models.OaDocShare
|
||||
if err := models.Orm.QueryTable(new(models.OaDocShare)).
|
||||
@@ -1548,7 +1408,6 @@ func OaDocShareRemove(a OaDocActor, id uint64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// OaDocMemberItem 租户用户(供文档共享选人)。
|
||||
type OaDocMemberItem struct {
|
||||
UID uint64 `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
@@ -1557,7 +1416,6 @@ type OaDocMemberItem struct {
|
||||
OrgName string `json:"org_name"`
|
||||
}
|
||||
|
||||
// OaDocMembers 查询租户内用户(用于私密文档共享选人)。
|
||||
func OaDocMembers(tid int, keyword string, limit int) ([]OaDocMemberItem, error) {
|
||||
if limit < 1 || limit > 200 {
|
||||
limit = 100
|
||||
@@ -1616,9 +1474,6 @@ func OaDocMembers(tid int, keyword string, limit int) ([]OaDocMemberItem, error)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ---------------- 文档图谱 ----------------
|
||||
|
||||
// OaDocGraphParams 图谱查询条件
|
||||
type OaDocGraphParams struct {
|
||||
Keyword string
|
||||
CategoryID uint64
|
||||
@@ -1628,7 +1483,6 @@ type OaDocGraphParams struct {
|
||||
Limit int
|
||||
}
|
||||
|
||||
// OaDocGraphNode 图谱节点;Category=0 文档,Category=1 分类
|
||||
type OaDocGraphNode struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -1645,7 +1499,6 @@ type OaDocGraphNode struct {
|
||||
Value int `json:"value"`
|
||||
}
|
||||
|
||||
// OaDocGraphLink 图谱连线;Kind=doc 为文档关联,Kind=belong 为文档归属分类
|
||||
type OaDocGraphLink struct {
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
@@ -1655,14 +1508,12 @@ type OaDocGraphLink struct {
|
||||
Kind string `json:"kind"`
|
||||
}
|
||||
|
||||
// OaDocRelationCount 关系类型分布
|
||||
type OaDocRelationCount struct {
|
||||
Relation string `json:"relation"`
|
||||
Label string `json:"label"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
// OaDocGraphStats 图谱概览统计
|
||||
type OaDocGraphStats struct {
|
||||
DocCount int64 `json:"doc_count"`
|
||||
LinkCount int64 `json:"link_count"`
|
||||
@@ -1673,7 +1524,6 @@ type OaDocGraphStats struct {
|
||||
TopNodes []OaDocGraphNode `json:"top_nodes"`
|
||||
}
|
||||
|
||||
// OaDocGraphResult 图谱数据
|
||||
type OaDocGraphResult struct {
|
||||
Nodes []OaDocGraphNode `json:"nodes"`
|
||||
Links []OaDocGraphLink `json:"links"`
|
||||
@@ -1681,11 +1531,6 @@ type OaDocGraphResult struct {
|
||||
Stats OaDocGraphStats `json:"stats"`
|
||||
}
|
||||
|
||||
// OaDocGraph 构建文档知识图谱。
|
||||
//
|
||||
// 节点包含文档与(可选)分类中心;连线包含:
|
||||
// - kind=doc :文档之间的关联关系(yz_backend_oa_doc_link)
|
||||
// - kind=belong :文档到所属分类的归属关系,使孤立文档也能在图谱中定位
|
||||
func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
|
||||
limit := p.Limit
|
||||
@@ -1733,9 +1578,7 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
})
|
||||
}
|
||||
|
||||
// 文档之间的关联连线
|
||||
if len(docIDs) > 0 {
|
||||
// SetCond 会整体替换查询条件,tid 必须写进 cond
|
||||
cond := orm.NewCondition().
|
||||
And("tid", a.Tid).
|
||||
And("source_id__in", docIDs).
|
||||
@@ -1749,7 +1592,6 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
return nil, err
|
||||
}
|
||||
for _, l := range linkList {
|
||||
// 双向各存一条,按 id 去重避免出现两条重复连线
|
||||
if l.SourceID > l.TargetID {
|
||||
continue
|
||||
}
|
||||
@@ -1766,11 +1608,8 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// 归属分类连线 + 分类中心节点
|
||||
categoryCount := int64(0)
|
||||
if p.IncludeCategory {
|
||||
// 图谱包含两类分类节点:共享分类(user_id=0,Category=1)与当前用户自己的私密分类(Category=2)。
|
||||
// 只取用户可见范围(共享 + 本人私密),避免把其他用户的私密分类暴露出来。
|
||||
catCond := orm.NewCondition().
|
||||
And("tid", a.Tid).
|
||||
And("is_deleted", 0).
|
||||
@@ -1786,7 +1625,6 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
catByID[c.ID] = c
|
||||
}
|
||||
|
||||
// 文档 → 分类 归属连线(仅当分类在当前可见范围内,避免出现指向不存在节点的悬空连线)
|
||||
for _, d := range docs {
|
||||
if d.CategoryID == 0 {
|
||||
continue
|
||||
@@ -1805,7 +1643,6 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
degree[fmt.Sprintf("c%d", d.CategoryID)]++
|
||||
}
|
||||
|
||||
// 分类 → 父分类 层级连线(补全分类树的上下级结构,避免顶级/上级分类缺失)
|
||||
for _, c := range cats {
|
||||
if c.ParentID == 0 {
|
||||
continue
|
||||
@@ -1824,11 +1661,10 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
degree[fmt.Sprintf("c%d", c.ParentID)]++
|
||||
}
|
||||
|
||||
// 当前可见范围内的全部分类都作为中心节点,保证分类树完整
|
||||
for _, c := range cats {
|
||||
catKind := 1
|
||||
if c.UserID != 0 {
|
||||
catKind = 2 // 私密分类
|
||||
catKind = 2
|
||||
}
|
||||
nodes = append(nodes, OaDocGraphNode{
|
||||
ID: fmt.Sprintf("c%d", c.ID),
|
||||
@@ -1839,7 +1675,6 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// 仅看有关系的文档:剔除孤立节点
|
||||
if p.OnlyLinked {
|
||||
kept := make([]OaDocGraphNode, 0, len(nodes))
|
||||
for _, n := range nodes {
|
||||
@@ -1855,7 +1690,6 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
nodes[i].Value = degree[nodes[i].ID] + 1
|
||||
}
|
||||
|
||||
// 统计
|
||||
stats := OaDocGraphStats{
|
||||
DocCount: int64(len(docs)),
|
||||
CategoryCount: categoryCount,
|
||||
@@ -1878,7 +1712,6 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
stats.AvgDegree = float64(docLinkCount*2) / float64(len(docs))
|
||||
}
|
||||
|
||||
// 关系分布直接由已可见的关联连线统计(每条去重连线计 1,与图谱展示一致)
|
||||
relCountMap := make(map[string]int64, 4)
|
||||
for _, l := range links {
|
||||
if l.Kind != "doc" {
|
||||
@@ -1924,7 +1757,6 @@ func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// normalizeIDs 过滤无效 ID 并去重
|
||||
func normalizeIDs(ids []uint64) []uint64 {
|
||||
seen := make(map[uint64]bool, len(ids))
|
||||
result := make([]uint64, 0, len(ids))
|
||||
|
||||
Reference in new issue
Block a user