-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc_get.go
112 lines (105 loc) · 3.24 KB
/
doc_get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package ERPDocument
import (
"errors"
CoreCache "github.com/fotomxq/weeekj_core/v5/core/cache"
CoreFilter "github.com/fotomxq/weeekj_core/v5/core/filter"
CoreSQL "github.com/fotomxq/weeekj_core/v5/core/sql"
CoreSQLPages "github.com/fotomxq/weeekj_core/v5/core/sql/pages"
ERPCore "github.com/fotomxq/weeekj_core/v5/erp/core"
Router2SystemConfig "github.com/fotomxq/weeekj_core/v5/router2/system_config"
"strings"
)
// ArgsGetDocList 获取配置列表参数
type ArgsGetDocList struct {
//分页
Pages CoreSQLPages.ArgsDataList `json:"pages"`
//组织ID
// -1 跳过
OrgID int64 `db:"org_id" json:"orgID" check:"id" empty:"true"`
//配置ID
ConfigID int64 `db:"config_id" json:"configID" check:"id" empty:"true"`
//是否删除
IsRemove bool `db:"is_remove" json:"isRemove" check:"bool"`
//搜索
Search string `json:"search" check:"search" empty:"true"`
}
// GetDocList 获取配置列表参
func GetDocList(args *ArgsGetDocList) (dataList []FieldsDoc, dataCount int64, err error) {
where := ""
maps := map[string]interface{}{}
where = CoreSQL.GetDeleteSQL(args.IsRemove, where)
if args.OrgID > -1 {
where = where + " AND org_id = :org_id"
maps["org_id"] = args.OrgID
}
if args.ConfigID > -1 {
//检查是否发布
if !checkConfigPublish(args.ConfigID, args.OrgID) {
err = errors.New("config no publish")
return
}
//组装条件
where = where + " AND config_id = :config_id"
maps["config_id"] = args.ConfigID
}
if args.Search != "" {
args.Search = strings.ReplaceAll(args.Search, " ", "")
where = where + " AND (REPLACE(name, ' ', '') ILIKE '%' || :search || '%' OR REPLACE(des, ' ', '') ILIKE '%' || :search || '%' OR REPLACE(search_des, ' ', '') ILIKE '%' || :search || '%')"
maps["search"] = args.Search
}
tableName := "erp_document_doc"
var rawList []FieldsDoc
dataCount, err = CoreSQL.GetListPageAndCount(
Router2SystemConfig.MainDB.DB,
&rawList,
tableName,
"id",
"SELECT id "+"FROM "+tableName+" WHERE "+where,
where,
maps,
&args.Pages,
[]string{"id", "create_at", "update_at", "delete_at"},
)
if err != nil {
return
}
for _, v := range rawList {
vData := getDocByID(v.ID)
if vData.ID < 1 {
continue
}
dataList = append(dataList, vData)
}
return
}
// GetDoc 获取指定的配置
func GetDoc(id int64, orgID int64) (data FieldsDoc) {
data = getDocByID(id)
if data.ID < 1 || !CoreFilter.EqID2(orgID, data.OrgID) || CoreSQL.CheckTimeHaveData(data.DeleteAt) {
data = FieldsDoc{}
return
}
return
}
// GetDocAllVal 获取文档组件列
func GetDocAllVal(docID int64) (dataList []ERPCore.FieldsComponentVal) {
return docComponentValObj.GetAllVal(docID)
}
// GetDocName 获取配置名称
//func GetDocName(id int64) (name string) {
// data := getDocByID(id)
// return data.Name
//}
// getDocByID 获取配置
func getDocByID(id int64) (data FieldsDoc) {
cacheMark := getDocCacheMark(id)
if err := Router2SystemConfig.MainCache.GetStruct(cacheMark, &data); err == nil && data.ID > 0 {
return
}
err := Router2SystemConfig.MainDB.Get(&data, "SELECT id, create_at, update_at, delete_at, config_id, org_id, name, des, cover_file_id, params FROM erp_document_doc WHERE id = $1", id)
if err != nil {
return
}
Router2SystemConfig.MainCache.SetStruct(cacheMark, data, CoreCache.CacheTime3Day)
return
}