@@ -0,0 +1,116 @@
|
||||
package taskser
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/v/oncetaskmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func GetOnceTaskList(p commod.Page) ([]oncetaskmod.OnceTask, bool, error) {
|
||||
ot, err := oncetaskmod.GetOnceTaskAll(nil)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
skip := p.Skip()
|
||||
if uint64(len(ot)) <= skip {
|
||||
return nil, false, nil
|
||||
}
|
||||
ot = ot[skip:]
|
||||
if uint64(len(ot)) <= p.Limit() {
|
||||
return ot, false, nil
|
||||
}
|
||||
return ot[:p.Limit()], true, nil
|
||||
}
|
||||
|
||||
func AddOnceTask(aor oncetaskmod.AddOnceReq) error {
|
||||
var ot oncetaskmod.OnceTask
|
||||
i := 0
|
||||
if aor.Title != nil {
|
||||
ot.Title = *aor.Title
|
||||
i++
|
||||
}
|
||||
if aor.Desc != nil {
|
||||
ot.Desc = *aor.Desc
|
||||
i++
|
||||
}
|
||||
if aor.Img != nil {
|
||||
ot.Img = *aor.Img
|
||||
i++
|
||||
}
|
||||
if len(aor.Prizes) != 0 {
|
||||
ot.Prizes = aor.Prizes
|
||||
i++
|
||||
}
|
||||
if aor.Type != nil {
|
||||
ot.Type = *aor.Type
|
||||
i++
|
||||
}
|
||||
if aor.FinishCondition != nil {
|
||||
ot.FinishCondition = *aor.FinishCondition
|
||||
i++
|
||||
}
|
||||
if aor.Link != nil {
|
||||
ot.Link = *aor.Link
|
||||
i++
|
||||
}
|
||||
if aor.Status != nil {
|
||||
ot.Status = *aor.Status
|
||||
i++
|
||||
}
|
||||
if aor.SortNum != nil {
|
||||
ot.SortNum = *aor.SortNum
|
||||
i++
|
||||
}
|
||||
if i == 0 {
|
||||
return nil
|
||||
}
|
||||
now := time.Now()
|
||||
ot.CreatedAt = now
|
||||
ot.UpdatedAt = now
|
||||
if err := oncetaskmod.AddOnceTask(nil, ot); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func EditOnceTask(eor oncetaskmod.EditOnceReq) error {
|
||||
if eor.ID.IsZero() {
|
||||
return nil
|
||||
}
|
||||
b := make(bson.M)
|
||||
if eor.Title != nil {
|
||||
b["title"] = *eor.Title
|
||||
}
|
||||
if eor.Desc != nil {
|
||||
b["desc"] = *eor.Desc
|
||||
}
|
||||
if eor.Img != nil {
|
||||
b["img"] = *eor.Img
|
||||
}
|
||||
if len(eor.Prizes) != 0 {
|
||||
b["prizes"] = eor.Prizes
|
||||
}
|
||||
if eor.Type != nil {
|
||||
b["type"] = *eor.Type
|
||||
}
|
||||
if eor.FinishCondition != nil {
|
||||
b["finishCondition"] = *eor.FinishCondition
|
||||
}
|
||||
if eor.Link != nil {
|
||||
b["link"] = *eor.Link
|
||||
}
|
||||
if eor.Status != nil {
|
||||
b["status"] = *eor.Status
|
||||
}
|
||||
if eor.SortNum != nil {
|
||||
b["sortNum"] = *eor.SortNum
|
||||
}
|
||||
if len(b) == 0 {
|
||||
return nil
|
||||
}
|
||||
b["updatedAt"] = time.Now()
|
||||
return oncetaskmod.UpdateOnceTask(nil, eor.ID, b)
|
||||
}
|
||||
Reference in New Issue
Block a user