MCPcopy Index your code
hub / github.com/TruthHun/DocHub / RecoverFromRecycle

Method RecoverFromRecycle

models/RecycleModel.go:32–105  ·  view source on GitHub ↗

将文档从回收站中恢复过来,文档的状态必须是-1才可以 @param ids 文档id @return err 返回错误,nil表示恢复成功,否则恢复失败

(ids ...interface{})

Source from the content-addressed store, hash-verified

30//@param ids 文档id
31//@return err 返回错误,nil表示恢复成功,否则恢复失败
32func (this *DocumentRecycle) RecoverFromRecycle(ids ...interface{}) (err error) {
33 var (
34 docInfo []DocumentInfo
35 dsId []interface{} //document_store id
36 o = orm.NewOrm()
37 md5Arr []interface{}
38 )
39
40 if len(ids) == 0 {
41 return
42 }
43 o.Begin()
44 defer func() {
45 if err != nil {
46 o.Rollback()
47 } else {
48 o.Commit()
49 }
50 }()
51
52 qs := o.QueryTable(GetTableDocumentInfo()).Filter("Id__in", ids...).Filter("Status", DocStatusDeleted)
53 qs.All(&docInfo)
54 _, err = qs.Update(orm.Params{"Status": DocStatusNormal})
55 if err != nil {
56 return
57 }
58
59 //总文档数量增加
60 sqlSys := fmt.Sprintf("update %v set `CntDoc`=`CntDoc`+? where Id = 1", GetTableSys())
61 _, err = o.Raw(sqlSys, len(docInfo)).Exec()
62 if err != nil {
63 return
64 }
65 reward := NewSys().GetByField("Reward").Reward
66 client := NewElasticSearchClient()
67 sqlUser := fmt.Sprintf("update %v set `Document`=`Document`+?,`Coin`=`Coin`+? where Id=?", GetTableUserInfo())
68 sqlCate := fmt.Sprintf("update %v set `Cnt`=`Cnt`+? where `Id` in(?,?,?)", GetTableCategory())
69 now := int(time.Now().Unix())
70 doc := NewDocument()
71 for _, v := range docInfo {
72 dsId = append(dsId, v.DsId)
73
74 _, err = o.Raw(sqlUser, 1, reward, v.Uid).Exec()
75 if err != nil {
76 return
77 }
78
79 // 积分变更
80 log := &CoinLog{Uid: v.Uid, Coin: reward, TimeCreate: now}
81 log.Log = fmt.Sprintf("系统恢复《%v》文档,获得 %v 个金币奖励", doc.GetDocument(v.Id, "Title").Title, reward)
82 _, err = o.Insert(log)
83 if err != nil {
84 return
85 }
86
87 _, err = o.Raw(sqlCate, 1, v.ChanelId, v.Cid, v.Pid).Exec()
88 if err != nil {
89 return

Callers 1

ActionMethod · 0.95

Calls 15

GetDocumentMethod · 0.95
BuildIndexByIdMethod · 0.95
GetTableDocumentInfoFunction · 0.85
GetTableSysFunction · 0.85
NewSysFunction · 0.85
NewElasticSearchClientFunction · 0.85
GetTableUserInfoFunction · 0.85
GetTableCategoryFunction · 0.85
NewDocumentFunction · 0.85
GetTableDocumentRecycleFunction · 0.85
GetTableDocumentIllegalFunction · 0.85
AllMethod · 0.80

Tested by

no test coverage detected