更新代码
This commit is contained in:
@@ -55,8 +55,6 @@ type OaDocActor struct {
|
||||
// NewOaDocActor 构造访问者上下文。
|
||||
// uid 为 backend 端 JWT 的 UserID,即 yz_system_tenant_user.uid。
|
||||
func NewOaDocActor(tid int, uid uint64) OaDocActor {
|
||||
models.EnsureOaDocumentTables()
|
||||
models.EnsureTenantUserOrgColumn()
|
||||
// 补建租户自己的系统内置分类(项目文档),按 tid 隔离
|
||||
models.EnsureOaDocDefaultCategories(tid)
|
||||
|
||||
@@ -363,7 +361,6 @@ func oaDocApplyUncategorized(qs orm.QuerySeter, a OaDocActor, scope string) orm.
|
||||
// scope="shared" 返回共享空间树(租户级),scope="personal" 返回当前用户的私密空间树。
|
||||
// 系统内置分类(项目文档)置顶;数量统计受可见性约束:无权限的私密文档不计入。
|
||||
func OaDocCategoryTree(a OaDocActor, scope string) ([]*OaDocCategoryItem, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
scope = oaDocScopeOf(scope)
|
||||
var list []models.OaDocCategory
|
||||
@@ -416,7 +413,6 @@ func OaDocCategoryTree(a OaDocActor, scope string) ([]*OaDocCategoryItem, error)
|
||||
// visibility<0 时按范围自动取对应可见性(共享→公开,私密→私密);可见性约束同样生效:无权限的私密文档不计入。
|
||||
// scope="all" 时跨两个空间统计(不限定 visibility)。
|
||||
func OaDocCountByCategory(a OaDocActor, scope string, visibility int) (map[uint64]int64, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
scope = oaDocScopeOf(scope)
|
||||
sql := "SELECT category_id, COUNT(*) AS cnt FROM yz_backend_oa_doc WHERE tid = ? AND is_deleted = 0"
|
||||
@@ -461,7 +457,6 @@ func oaDocIsReservedName(name string) bool {
|
||||
// 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) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
scope = oaDocScopeOf(scope)
|
||||
name = strings.TrimSpace(name)
|
||||
@@ -499,7 +494,6 @@ func OaDocCategoryCreate(a OaDocActor, scope string, parentID uint64, name, rema
|
||||
|
||||
// OaDocCategoryUpdate 修改分类名称/备注/排序,parentID < 0 表示不调整父级。
|
||||
func OaDocCategoryUpdate(a OaDocActor, id uint64, name, remark string, sort int, parentID int64) (*models.OaDocCategory, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
var item models.OaDocCategory
|
||||
if err := oaDocCategoryBaseAny(a.Tid).Filter("id", id).One(&item); err != nil {
|
||||
@@ -608,7 +602,6 @@ func oaDocCategoryIDsWithChildren(a OaDocActor, scope string, rootID uint64) ([]
|
||||
// OaDocCategoryDelete 删除分类:系统内置分类、存在子分类或文档时拒绝删除。
|
||||
// 共享空间分类任何租户成员均可删除(内置分类除外);私密空间分类仅本人可删除。
|
||||
func OaDocCategoryDelete(a OaDocActor, id uint64) error {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
var item models.OaDocCategory
|
||||
if err := oaDocCategoryBaseAny(a.Tid).Filter("id", id).One(&item); err != nil {
|
||||
@@ -709,7 +702,6 @@ type OaDocListParams struct {
|
||||
|
||||
// OaDocList 分页查询文档(自动应用可见性与范围过滤)。
|
||||
func OaDocList(a OaDocActor, p OaDocListParams) ([]models.OaDoc, int64, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
scope := oaDocScopeOf(p.Scope)
|
||||
qs := oaDocApplyVisible(oaDocBase(a.Tid), a)
|
||||
@@ -790,7 +782,6 @@ func OaDocList(a OaDocActor, p OaDocListParams) ([]models.OaDoc, int64, error) {
|
||||
|
||||
// OaDocGet 读取文档详情(不累加查看次数)。私密文档对无权限者返回未找到。
|
||||
func OaDocGet(a OaDocActor, id uint64) (*models.OaDoc, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
var item models.OaDoc
|
||||
qs := oaDocApplyVisible(oaDocBase(a.Tid).Filter("id", id), a)
|
||||
@@ -854,7 +845,6 @@ type OaDocSaveParams struct {
|
||||
// OaDocCreate 新增文档。
|
||||
// 若未传标题则回退为原始文件名(去扩展名);doc_type 由扩展名推断。
|
||||
func OaDocCreate(a OaDocActor, operatorName string, p OaDocSaveParams) (*models.OaDoc, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
tid := a.Tid
|
||||
|
||||
title := strings.TrimSpace(p.Title)
|
||||
@@ -925,7 +915,6 @@ func visibilityOf(v int8) int8 {
|
||||
|
||||
// OaDocUpdate 编辑文档(仅更新传入的字段)。
|
||||
func OaDocUpdate(a OaDocActor, id uint64, p OaDocSaveParams) (*models.OaDoc, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
var item models.OaDoc
|
||||
if err := oaDocApplyVisible(oaDocBase(a.Tid).Filter("id", id), a).One(&item); err != nil {
|
||||
@@ -1034,7 +1023,6 @@ func OaDocUpdate(a OaDocActor, id uint64, p OaDocSaveParams) (*models.OaDoc, err
|
||||
// OaDocDelete 批量软删除文档,并清理与被删文档相关的关联关系。
|
||||
// 仅对"可见且可管理"的文档生效;若给定 ID 全部无权操作则返回 ErrDocNoPermission。
|
||||
func OaDocDelete(a OaDocActor, ids []uint64) (int64, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
ids = normalizeIDs(ids)
|
||||
if len(ids) == 0 {
|
||||
@@ -1078,7 +1066,6 @@ func OaDocDelete(a OaDocActor, ids []uint64) (int64, error) {
|
||||
|
||||
// OaDocMove 批量移动文档到目标分类(0 表示未分类)。仅对可管理文档生效。
|
||||
func OaDocMove(a OaDocActor, ids []uint64, categoryID uint64) (int64, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
ids = normalizeIDs(ids)
|
||||
if len(ids) == 0 {
|
||||
@@ -1121,7 +1108,6 @@ func OaDocMove(a OaDocActor, ids []uint64, categoryID uint64) (int64, error) {
|
||||
|
||||
// OaDocToggleStar 收藏 / 取消收藏切换,返回切换后的状态。
|
||||
func OaDocToggleStar(a OaDocActor, id uint64) (int8, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
var item models.OaDoc
|
||||
if err := oaDocApplyVisible(oaDocBase(a.Tid).Filter("id", id), a).One(&item); err != nil {
|
||||
@@ -1165,7 +1151,6 @@ type OaDocTypeCount struct {
|
||||
// OaDocStats 文档库概览:总数、状态分布、类型分布、最近更新与热门文档。
|
||||
// scope 限定统计口径("shared" 共享文档空间 / "personal" 私密文档空间 / "all" 跨空间);可见性约束同样生效。
|
||||
func OaDocStats(a OaDocActor, scope string) (*OaDocStatsResult, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
scope = oaDocScopeOf(scope)
|
||||
vis := int8(-1)
|
||||
@@ -1290,7 +1275,6 @@ type OaDocLinkItem struct {
|
||||
|
||||
// OaDocLinkCreate 建立两个文档之间的关联。
|
||||
func OaDocLinkCreate(a OaDocActor, creatorID, sourceID, targetID uint64, relation, remark string) (*models.OaDocLink, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
tid := a.Tid
|
||||
|
||||
if sourceID == 0 || targetID == 0 {
|
||||
@@ -1345,7 +1329,6 @@ func OaDocLinkCreate(a OaDocActor, creatorID, sourceID, targetID uint64, relatio
|
||||
|
||||
// OaDocLinkDelete 删除关联关系(同时清理反向关系,保证图谱双向一致)。
|
||||
func OaDocLinkDelete(a OaDocActor, id uint64) error {
|
||||
models.EnsureOaDocumentTables()
|
||||
tid := a.Tid
|
||||
|
||||
var item models.OaDocLink
|
||||
@@ -1380,7 +1363,6 @@ func OaDocLinkDelete(a OaDocActor, id uint64) error {
|
||||
// OaDocLinkList 查询与某文档相关的全部关联(含反向),all 为 true 时返回租户全部关联。
|
||||
// 仅返回两端文档对当前访问者均可见的关联,避免私密文档被越权探查。
|
||||
func OaDocLinkList(a OaDocActor, docID uint64, all bool) ([]OaDocLinkItem, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
sql := `
|
||||
SELECT l.id, l.tid, l.source_id, l.target_id, l.relation, l.remark, l.create_time,
|
||||
@@ -1576,7 +1558,6 @@ type OaDocMemberItem struct {
|
||||
|
||||
// OaDocMembers 查询租户内用户(用于私密文档共享选人)。
|
||||
func OaDocMembers(tid int, keyword string, limit int) ([]OaDocMemberItem, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
if limit < 1 || limit > 200 {
|
||||
limit = 100
|
||||
}
|
||||
@@ -1705,7 +1686,6 @@ type OaDocGraphResult struct {
|
||||
// - kind=doc :文档之间的关联关系(yz_backend_oa_doc_link)
|
||||
// - kind=belong :文档到所属分类的归属关系,使孤立文档也能在图谱中定位
|
||||
func OaDocGraph(a OaDocActor, p OaDocGraphParams) (*OaDocGraphResult, error) {
|
||||
models.EnsureOaDocumentTables()
|
||||
|
||||
limit := p.Limit
|
||||
if limit < 1 || limit > 1000 {
|
||||
|
||||
Reference in New Issue
Block a user