-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
302 lines (287 loc) · 9.63 KB
/
report.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
package OrgReport
import (
"errors"
"fmt"
BaseFileSys2 "github.com/fotomxq/weeekj_core/v5/base/filesys2"
CoreFilter "github.com/fotomxq/weeekj_core/v5/core/filter"
CoreSQL "github.com/fotomxq/weeekj_core/v5/core/sql"
CoreSQLConfig "github.com/fotomxq/weeekj_core/v5/core/sql/config"
CoreSQLPages "github.com/fotomxq/weeekj_core/v5/core/sql/pages"
Router2SystemConfig "github.com/fotomxq/weeekj_core/v5/router2/system_config"
"github.com/lib/pq"
"time"
)
// ArgsGetReportList 获取反馈列表参数
type ArgsGetReportList struct {
//分页
Pages CoreSQLPages.ArgsDataList `json:"pages"`
//组织
OrgID int64 `json:"orgID" check:"id" empty:"true"`
//是否需要已经回复参数
NeedIsReport bool `json:"needIsReport" check:"bool"`
IsReport bool `json:"isReport" check:"bool"`
//搜索
Search string `json:"search" check:"search" empty:"true"`
}
type DataGetReportList struct {
//ID
ID int64 `db:"id" json:"id"`
//创建时间
CreateAt string `db:"create_at" json:"createAt"`
//投诉来源
// 可以全部为0或空,则代表匿名
FromSystem string `db:"from_system" json:"fromSystem"`
FromID int64 `db:"from_id" json:"fromID"`
FromName string `db:"from_name" json:"fromName"`
//建议内容
Des string `db:"des" json:"des"`
//投诉目标
// 可以不含投诉目标,具体看投诉人意愿和业务逻辑需要
TargetSystem string `db:"target_system" json:"targetSystem"`
TargetID int64 `db:"target_id" json:"targetID"`
TargetName string `db:"target_name" json:"targetName"`
//投诉图片
DesFiles pq.Int64Array `db:"des_files" json:"desFiles"`
DesFileURLs []string `json:"desFileURLs"`
//反馈内容
ReportAt string `db:"report_at" json:"reportAt"`
ReportDes string `db:"report_des" json:"reportDes"`
//扩展参数
Params CoreSQLConfig.FieldsConfigsType `db:"params" json:"params"`
}
// GetReportList 获取反馈列表
func GetReportList(args *ArgsGetReportList) (dataList []DataGetReportList, dataCount int64, err error) {
where := ""
maps := map[string]interface{}{}
if args.OrgID > -1 {
where = where + "org_id = :org_id"
maps["org_id"] = args.OrgID
}
if args.NeedIsReport {
where = CoreSQL.GetDeleteSQLField(args.IsReport, where, "report_at")
}
if args.Search != "" {
if where != "" {
where = where + " AND "
}
where = where + "(des ILIKE '%' || :search || '%' OR report_des ILIKE '%' || :search || '%')"
maps["search"] = args.Search
}
if where == "" {
where = "true"
}
tableName := "org_report"
var rawList []FieldsReport
dataCount, err = CoreSQL.GetListPageAndCount(
Router2SystemConfig.MainDB.DB,
&rawList,
tableName,
"id",
"SELECT id FROM "+tableName+" WHERE "+where,
where,
maps,
&args.Pages,
[]string{"id", "create_at", "report_at"},
)
for _, v := range rawList {
vData := getReportByID(v.ID)
if vData.ID < 1 {
continue
}
dataList = append(dataList, DataGetReportList{
ID: vData.ID,
CreateAt: CoreFilter.GetTimeToDefaultTime(vData.CreateAt),
FromSystem: vData.FromSystem,
FromID: vData.FromID,
FromName: vData.FromName,
Des: CoreFilter.SubStrQuick(vData.Des, 10),
TargetSystem: vData.TargetSystem,
TargetID: vData.TargetID,
TargetName: vData.TargetName,
DesFiles: vData.DesFiles,
DesFileURLs: BaseFileSys2.GetPublicURLsByClaimIDs(vData.DesFiles),
ReportAt: CoreFilter.GetTimeToDefaultTime(vData.ReportAt),
ReportDes: CoreFilter.SubStrQuick(vData.ReportDes, 10),
Params: vData.Params,
})
}
return
}
// ArgsGetReport 获取反馈数
type ArgsGetReport struct {
//ID
ID int64 `db:"id" json:"id" check:"id"`
//组织
OrgID int64 `db:"org_id" json:"orgID" check:"id" empty:"true"`
}
type DataGetReport struct {
//ID
ID int64 `db:"id" json:"id"`
//创建时间
CreateAt string `db:"create_at" json:"createAt"`
//投诉来源
// 可以全部为0或空,则代表匿名
FromSystem string `db:"from_system" json:"fromSystem"`
FromID int64 `db:"from_id" json:"fromID"`
FromName string `db:"from_name" json:"fromName"`
//建议内容
Des string `db:"des" json:"des"`
//建议附图
DesFiles []string `db:"des_files" json:"desFiles"`
//投诉目标
// 可以不含投诉目标,具体看投诉人意愿和业务逻辑需要
TargetSystem string `db:"target_system" json:"targetSystem"`
TargetID int64 `db:"target_id" json:"targetID"`
TargetName string `db:"target_name" json:"targetName"`
//反馈内容
ReportAt string `db:"report_at" json:"reportAt"`
ReportDes string `db:"report_des" json:"reportDes"`
ReportFiles []string `db:"report_files" json:"reportFiles"`
//扩展参数
Params CoreSQLConfig.FieldsConfigsType `db:"params" json:"params"`
}
// GetReport 获取反馈数据包
func GetReport(args *ArgsGetReport) (data DataGetReport, err error) {
rawData := getReportByID(args.ID)
if rawData.ID < 1 || !CoreFilter.EqID2(args.OrgID, rawData.OrgID) {
err = errors.New("no data")
return
}
data = DataGetReport{
ID: rawData.ID,
CreateAt: CoreFilter.GetTimeToDefaultTime(rawData.CreateAt),
FromSystem: rawData.FromSystem,
FromID: rawData.FromID,
FromName: rawData.FromName,
Des: rawData.Des,
DesFiles: BaseFileSys2.GetPublicURLsByClaimIDs(rawData.DesFiles),
TargetSystem: rawData.TargetSystem,
TargetID: rawData.TargetID,
TargetName: rawData.TargetName,
ReportAt: CoreFilter.GetTimeToDefaultTime(rawData.ReportAt),
ReportDes: rawData.ReportDes,
ReportFiles: BaseFileSys2.GetPublicURLsByClaimIDs(rawData.ReportFiles),
Params: rawData.Params,
}
return
}
// ArgsAddReport 添加新的反馈参数
type ArgsAddReport struct {
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id" empty:"true"`
//投诉来源
// 可以全部为0或空,则代表匿名
FromSystem string `db:"from_system" json:"fromSystem" check:"mark"`
FromID int64 `db:"from_id" json:"fromID" check:"id" empty:"true"`
FromName string `db:"from_name" json:"fromName" check:"name"`
//投诉目标
// 可以不含投诉目标,具体看投诉人意愿和业务逻辑需要
TargetSystem string `db:"target_system" json:"targetSystem"`
TargetID int64 `db:"target_id" json:"targetID"`
TargetName string `db:"target_name" json:"targetName"`
//建议内容
Des string `db:"des" json:"des" check:"des" min:"1" max:"3000"`
//建议附图
DesFiles pq.Int64Array `db:"des_files" json:"desFiles" check:"ids" empty:"true"`
//扩展参数
Params CoreSQLConfig.FieldsConfigsType `db:"params" json:"params"`
}
// AddReport 添加新的反馈
func AddReport(args *ArgsAddReport) (err error) {
if len(args.DesFiles) > 10 {
err = errors.New("too many files")
return
}
_, err = CoreSQL.CreateOne(Router2SystemConfig.MainDB.DB, "INSERT INTO org_report (org_id, from_system, from_id, from_name, des, des_files, target_system, target_id, target_name, params) VALUES (:org_id,:from_system,:from_id,:from_name,:des,:des_files,:target_system,:target_id,:target_name,:params)", args)
if err != nil {
return
}
return
}
// ArgsReReport 处理反馈参数
type ArgsReReport struct {
//ID
ID int64 `db:"id" json:"id" check:"id"`
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id" empty:"true"`
//反馈内容
ReportAt string `db:"report_at" json:"reportAt"`
ReportDes string `db:"report_des" json:"reportDes"`
ReportFiles pq.Int64Array `db:"report_files" json:"reportFiles"`
//扩展参数
Params CoreSQLConfig.FieldsConfigsType `db:"params" json:"params"`
}
// ReReport 处理反馈
func ReReport(args *ArgsReReport) (errCode string, err error) {
//获取时间
var reportAt time.Time
reportAt, err = CoreFilter.GetTimeByDefault(args.ReportAt)
if err != nil {
errCode = "err_time"
return
}
//获取数据
rawData := getReportByID(args.ID)
if rawData.ID < 1 || !CoreFilter.EqID2(args.OrgID, rawData.OrgID) {
errCode = "err_no_data"
err = errors.New("no data")
return
}
//检查是否已经回复
if CoreSQL.CheckTimeHaveData(rawData.ReportAt) {
errCode = "err_have_report"
err = errors.New("have report")
return
}
//修改反馈
_, err = CoreSQL.UpdateOne(Router2SystemConfig.MainDB.DB, "UPDATE org_report SET report_at = :report_at, report_des = :report_des, report_files = :report_files, params = :params WHERE id = :id", map[string]interface{}{
"id": args.ID,
"report_at": reportAt,
"report_des": args.ReportDes,
"report_files": args.ReportFiles,
"params": args.Params,
})
if err != nil {
errCode = "err_insert"
return
}
//删除缓冲
deleteReportCache(args.ID)
//反馈
return
}
// 获取ID
func getReportByID(id int64) (data FieldsReport) {
cacheMark := getReportCacheMark(id)
if err := Router2SystemConfig.MainCache.GetStruct(cacheMark, &data); err == nil && data.ID > 0 {
return
}
_ = Router2SystemConfig.MainDB.Get(&data, "SELECT id, create_at, org_id, from_system, from_id, from_name, des, des_files, target_system, target_id, target_name, report_at, report_des, report_files, params FROM org_report WHERE id = $1", id)
if data.ID < 1 {
return
}
Router2SystemConfig.MainCache.SetStruct(cacheMark, data, 10800)
return
}
type ArgsDeleteReport struct {
//ID
ID int64 `db:"id" json:"id" check:"id"`
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id" empty:"true"`
}
// 删除反馈
func DeleteReport(args *ArgsDeleteReport) (err error) {
_, err = CoreSQL.DeleteAllSoft(Router2SystemConfig.MainDB.DB, "org_report", "id = :id AND org_id = :org_id", args)
if err != nil {
return
}
deleteReportCache(args.ID)
return
}
// 缓冲
func getReportCacheMark(id int64) string {
return fmt.Sprint("org:report:id:", id)
}
func deleteReportCache(id int64) {
Router2SystemConfig.MainCache.DeleteMark(getReportCacheMark(id))
}