74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package smithy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelTask struct {
|
|
modules.MCompModel
|
|
module *Smithy
|
|
}
|
|
|
|
func (this *modelTask) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableSmithyTask)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Smithy)
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelTask) getTaskRecord(uid string) (*pb.DBTujianTask, error) {
|
|
tt := &pb.DBTujianTask{}
|
|
if err := this.Get(uid, tt); err != nil {
|
|
return tt, err
|
|
}
|
|
return tt, nil
|
|
}
|
|
|
|
func (this *modelTask) updateTaskRecord(uid string, taskId int32) error {
|
|
// if !this.CheckTaskStatus(uid, taskId) {
|
|
// return comm.NewCustomError(pb.ErrorCode_SmithyTaskNoFinished)
|
|
// }
|
|
// dt, err := this.getTaskRecord(uid)
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
|
|
// if dt.Uid == "" {
|
|
// this.Add(uid, &pb.DBTujianTask{Uid: uid, TaskId: taskId, Received: 2})
|
|
// } else {
|
|
// // 已存在 重复领取
|
|
// if dt.Received == 2 {
|
|
// return comm.NewCustomError(pb.ErrorCode_SmithyTaskReceived)
|
|
// } else {
|
|
// update := map[string]interface{}{
|
|
// "received": 2,
|
|
// }
|
|
// if err := this.Change(uid, update); err != nil {
|
|
// return err
|
|
// }
|
|
// }
|
|
// }
|
|
return nil
|
|
}
|
|
|
|
// 检查任务状态
|
|
func (this *modelTask) CheckTaskStatus(uid string, taskId int32) bool {
|
|
conf := this.module.configure.GetSmithyTask(taskId)
|
|
if conf == nil {
|
|
return false
|
|
}
|
|
if ec := this.module.ModuleRtask.CheckCondi(uid, conf.TypeId); ec != pb.ErrorCode_Success {
|
|
return false
|
|
}
|
|
return true
|
|
}
|