Files
bl/modules/blazing/service/task.go
2025-08-28 02:27:14 +00:00

65 lines
1.1 KiB
Go

package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
"encoding/json"
)
type TaskService struct {
*UserService
}
func NewTaskService(id uint32) *TaskService {
return &TaskService{
&UserService{
userid: id,
Service: &cool.Service{
Model: model.NewTask(),
},
},
}
}
func (s *TaskService) Exec(t func(map[uint32]model.TaskInfo) bool) (ret bool) {
var tt model.Task
s.GetModel().Scan(&tt)
var ttt map[uint32]model.TaskInfo
json.Unmarshal([]byte(tt.Data), &ttt)
ret = t(ttt)
t1, _ := json.Marshal(&ttt)
tt.Data = string(t1)
s.GetModel().Save(&tt) //退出时保存
return
}
/**
* 完成任务
*/
func (s *TaskService) CompleteTask(task uint32) bool {
return s.Exec(func(ttt map[uint32]model.TaskInfo) bool {
if conditions, ok := ttt[task]; ok {
conditions.Status = 3
ttt[task] = conditions
}
return false
})
}
/**
* 校验任务是否已经完成
*/
func (s *TaskService) CheckTaskCompleted(task uint32) bool {
return s.Exec(func(ttt map[uint32]model.TaskInfo) bool {
if conditions, ok := ttt[task]; ok {
return conditions.Status == 3
}
return false
})
}