作者 tangxvhui

调整检查task_record 的逻辑

... ... @@ -255,3 +255,11 @@ func CreateTaskLevelRepository(options map[string]interface{}) domain.TaskLevelR
}
return repository.NewTaskLevelRepository(transactionContext)
}
func CreateTaskAnomalyRepository(options map[string]interface{}) domain.TaskAnomalyRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewTaskAnomalyRepository(transactionContext)
}
... ...
... ... @@ -11,8 +11,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
//TODO 检查任务里程碑反馈, 记录异常情况
// 检查昨日提交的任务里程碑反馈
func CheckYesterdayTaskRecord() {
nowTime := time.Now()
... ...
... ... @@ -2,11 +2,15 @@ package service
import (
"fmt"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// TODO 检查任务里程碑反馈, 记录异常情况
func checkTaskRecordV2(param *domain.TaskRecord) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -21,7 +25,6 @@ func checkTaskRecordV2(param *domain.TaskRecord) error {
taskRepo := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, taskDataList, err := taskRepo.Find(map[string]interface{}{"id": param.TaskId})
if err != nil {
return fmt.Errorf("获取任务数据失败:%s", err)
... ... @@ -30,17 +33,85 @@ func checkTaskRecordV2(param *domain.TaskRecord) error {
return nil
}
taskData := taskDataList[0]
//userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
// 反馈异常,里程碑异常, 辅导异常
// 检查反馈异常
if param.IsRemarkAnomaly() {
taskData.Anomaly += 1
// err = isAssessFlag(transactionContext, taskData)
// if err != nil {
// return err
// }
} else {
taskData.Anomaly = 0
}
// 检查里程碑异常
if param.IsTaskStageAnomaly() {
taskData.WarnFlag = domain.TaskWarn
err := isWarnFlag(transactionContext, taskData)
if err != nil {
return err
}
} else {
taskData.WarnFlag = domain.TaskWarnNull
}
// 检查辅导异常
if param.IsAssistAnomaly() {
taskData.AssistFlag += 1
err = isAssistFlag(transactionContext, taskData)
if err != nil {
return err
}
} else {
taskData.AssistFlag = 0
}
// 保存任务数据
err = taskRepo.Save(taskData)
if err != nil {
return fmt.Errorf("保存任务数据:%s", err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
// 处理里程碑异常的情况
func isWarnFlag(transactionContext application.TransactionContext, taskData *domain.Task) error {
taskAnomalyRepo := factory.CreateTaskAnomalyRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取任务Leader的数据
_, useList, err := userRepo.Find(map[string]interface{}{"id": taskData.Leader.Id, "limit": 1})
if err != nil {
return fmt.Errorf("获取任务Leader:%s", err)
}
if len(useList) == 0 {
return nil
}
_, oldAnomaly, err := taskAnomalyRepo.Find(map[string]interface{}{"isLast": 1, "category": 2, "limit": 1})
if err != nil {
return fmt.Errorf("查询反馈异常的数据:%s", err)
}
// 异常就通知自己和上级
anomalyDataTmp := domain.TaskAnomaly{
Id: taskData.Id,
CreatedAt: taskData.CreatedAt,
UpdatedAt: taskData.UpdatedAt,
CompanyId: taskData.CompanyId,
TaskId: taskData.Id,
Category: 0,
Category: 1,
CurrentStage: taskData.CurrentStage,
LastStage: taskData.LastStage,
AssessFlag: 0,
WarnFlag: 0,
WarnFlag: int(taskData.WarnFlag),
AssistFlag: 0,
IsLast: 1,
TaskLevel: taskData.LevelName,
... ... @@ -48,45 +119,102 @@ func checkTaskRecordV2(param *domain.TaskRecord) error {
TaskAlias: taskData.Alias,
TaskSortBy: taskData.SortBy,
TaskEndTime: taskData.EndTime,
RecordBegin: 0,
NoticeWho: []int64{},
RecordBegin: time.Now().Unix(),
NoticeWho: []int64{taskData.Leader.Id, useList[0].ParentId},
Marks: map[string]string{
"a": "", "b": "", "c": "", "d": "",
},
}
var anomalyList []domain.TaskAnomaly
// 检查反馈异常
if param.IsRemarkAnomaly() {
taskData.Anomaly += 1
anomalyDataTmp.Category = 2
anomalyList = append(anomalyList, anomalyDataTmp)
} else {
taskData.Anomaly = 0
}
// 检查里程碑异常
if param.IsTaskStageAnomaly() {
taskData.WarnFlag = domain.TaskWarn
anomalyDataTmp.Category = 1
anomalyList = append(anomalyList, anomalyDataTmp)
} else {
taskData.WarnFlag = domain.TaskWarnNull
if len(oldAnomaly) > 0 {
anomalyDataTmp.RecordBegin = oldAnomaly[0].RecordBegin
anomalyDataTmp.WarnFlag = oldAnomaly[0].WarnFlag + 1
oldAnomaly[0].IsLast = 2
err = taskAnomalyRepo.Save(oldAnomaly[0])
if err != nil {
return fmt.Errorf("更新里程碑异常记录:%s", err)
}
}
// 检查辅导异常
if param.IsAssistAnomaly() {
taskData.AssistFlag += 1
anomalyDataTmp.Category = 3
anomalyList = append(anomalyList, anomalyDataTmp)
} else {
taskData.AssistFlag = 0
err = taskAnomalyRepo.Save(&anomalyDataTmp)
if err != nil {
return fmt.Errorf("保存里程碑异常记录:%s", err)
}
return nil
}
err = taskRepo.Save(taskData)
// 处理辅导异常的情况
func isAssistFlag(transactionContext application.TransactionContext, taskData *domain.Task) error {
taskAnomalyRepo := factory.CreateTaskAnomalyRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取任务Leader的数据
_, useList, err := userRepo.Find(map[string]interface{}{"id": taskData.Leader.Id, "limit": 1})
if err != nil {
return fmt.Errorf("保存任务数据:%s", err)
return fmt.Errorf("获取任务Leader:%s", err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return err
if len(useList) == 0 {
return nil
}
_, oldAnomaly, err := taskAnomalyRepo.Find(map[string]interface{}{"isLast": 1, "category": 3, "limit": 1})
if err != nil {
return fmt.Errorf("查询反馈异常的数据:%s", err)
}
// 辅导异常通知该条任务负责人的上级;辅导异常超过3天,通知任务负责人的上上级
anomalyDataTmp := domain.TaskAnomaly{
Id: taskData.Id,
CreatedAt: taskData.CreatedAt,
UpdatedAt: taskData.UpdatedAt,
CompanyId: taskData.CompanyId,
TaskId: taskData.Id,
Category: 3,
CurrentStage: taskData.CurrentStage,
LastStage: taskData.LastStage,
AssessFlag: 0,
WarnFlag: 0,
AssistFlag: taskData.AssistFlag,
IsLast: 1,
TaskLevel: taskData.LevelName,
TaskName: taskData.Name,
TaskAlias: taskData.Alias,
TaskSortBy: taskData.SortBy,
TaskEndTime: taskData.EndTime,
RecordBegin: time.Now().Unix(),
NoticeWho: []int64{useList[0].ParentId},
Marks: map[string]string{
"a": "", "b": "", "c": "", "d": "",
},
}
if taskData.AssistFlag >= taskData.AssistFlagMax {
//通知任务负责人的上上级
_, useList2, err := userRepo.Find(map[string]interface{}{"id": useList[0].ParentId, "limit": 1})
if err != nil {
return fmt.Errorf("获取任务Leader:%s", err)
}
if len(useList2) > 0 {
anomalyDataTmp.NoticeWho = append(anomalyDataTmp.NoticeWho, useList2[0].Id)
}
}
if len(oldAnomaly) > 0 {
anomalyDataTmp.RecordBegin = oldAnomaly[0].RecordBegin
oldAnomaly[0].IsLast = 2
err = taskAnomalyRepo.Save(oldAnomaly[0])
if err != nil {
return fmt.Errorf("更新里程碑异常记录:%s", err)
}
}
err = taskAnomalyRepo.Save(&anomalyDataTmp)
if err != nil {
return fmt.Errorf("保存里程碑异常记录:%s", err)
}
return nil
}
// 处理反馈异常的情况
func isAssessFlag(transactionContext application.TransactionContext, taskData *domain.Task) error {
return nil
}
... ...
... ... @@ -21,7 +21,7 @@ type TaskAnomaly struct {
TaskAlias string `json:"taskAlias"` // 任务别名
TaskSortBy TaskSortBy `json:"taskSortBy"` // 优先级排序;值越小优先级越高
TaskEndTime int64 `json:"taskEndTime"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间
RecordBegin int `json:"recordBegin"` // 异常记录的开始时间
RecordBegin int64 `json:"recordBegin"` // 异常记录的开始时间
NoticeWho []int64 `json:"noticeWho"` // 异常记录消息通知的人
Marks map[string]string `json:"marks"` // 已经操作的标记
}
... ...
... ... @@ -26,7 +26,7 @@ type TaskAnomaly struct {
TaskAlias string `pg:"task_alias"` // 任务别名
TaskSortBy int `pg:"task_sort_by"` // 优先级排序;值越小优先级越高
TaskEndTime int64 `pg:"task_end_time,use_zero"` // 任务截止的时间戳,单位:秒;等于0时表示未设置时间
RecordBegin int `pg:"record_begin"` // 异常记录的开始时间
RecordBegin int64 `pg:"record_begin"` // 异常记录的开始时间
NoticeWho []int64 `pg:"notice_who"` // 异常记录消息通知的人
Marks map[string]string `pg:"marks"` // 已经操作的标记
}
... ...
... ... @@ -14,75 +14,67 @@ import (
//任务
type TaskRepository struct {
type TaskAnomalyRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.TaskRepository = (*TaskRepository)(nil)
var _ domain.TaskAnomalyRepository = (*TaskAnomalyRepository)(nil)
func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) *TaskRepository {
return &TaskRepository{transactionContext: transactionContext}
func NewTaskAnomalyRepository(transactionContext *pgTransaction.TransactionContext) *TaskAnomalyRepository {
return &TaskAnomalyRepository{transactionContext: transactionContext}
}
func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
return &domain.Task{
Id: d.Id,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
CompanyId: d.CompanyId,
Name: d.Name,
Alias: d.Alias,
Leader: d.Leader,
Status: domain.TaskState(d.Status),
Level: d.Level,
LevelName: d.LevelName,
SortBy: domain.TaskSortBy(d.SortBy),
EndTime: d.EndTime,
UseEndTime: d.UseEndTime,
RelatedUser: d.RelatedUser,
RunAt: d.RunAt,
StopAt: d.StopAt,
Anomaly: d.Anomaly,
WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
AssistFlag: d.AssistFlag,
AssistFlagMax: d.AssistFlagMax,
CurrentStage: d.CurrentStage,
LastStage: d.LastStage,
CreatedBy: d.CreatedBy,
func (repo *TaskAnomalyRepository) TransformToDomain(d *models.TaskAnomaly) *domain.TaskAnomaly {
return &domain.TaskAnomaly{
Id: d.Id,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
CompanyId: d.CompanyId,
TaskId: d.TaskId,
Category: d.Category,
CurrentStage: d.CurrentStage,
LastStage: d.LastStage,
AssessFlag: d.AssessFlag,
WarnFlag: d.WarnFlag,
AssistFlag: d.AssistFlag,
IsLast: d.IsLast,
TaskLevel: d.TaskLevel,
TaskName: d.TaskName,
TaskAlias: d.TaskAlias,
TaskSortBy: domain.TaskSortBy(d.TaskSortBy),
TaskEndTime: d.TaskEndTime,
RecordBegin: d.RecordBegin,
NoticeWho: d.NoticeWho,
Marks: d.Marks,
}
}
func (repo *TaskRepository) Save(param *domain.Task) error {
func (repo *TaskAnomalyRepository) Save(param *domain.TaskAnomaly) error {
param.UpdatedAt = time.Now()
if param.Id == 0 {
param.CreatedAt = time.Now()
}
m := models.Task{
Id: param.Id,
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: param.DeletedAt,
Name: param.Name,
Alias: param.Alias,
CompanyId: param.CompanyId,
Leader: param.Leader,
Status: int(param.Status),
Level: param.Level,
LevelName: param.LevelName,
RelatedUser: param.RelatedUser,
LastStage: param.LastStage,
RunAt: param.RunAt,
StopAt: param.StopAt,
Anomaly: param.Anomaly,
WarnFlag: int(param.WarnFlag),
CurrentStage: param.CurrentStage,
SortBy: int(param.SortBy),
EndTime: param.EndTime,
UseEndTime: param.UseEndTime,
AssistFlag: param.AssistFlag,
AssistFlagMax: param.AssistFlagMax,
CreatedBy: param.CreatedBy,
m := models.TaskAnomaly{
Id: param.Id,
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
CompanyId: param.CompanyId,
TaskId: param.TaskId,
Category: param.Category,
CurrentStage: param.CurrentStage,
LastStage: param.LastStage,
AssessFlag: param.AssessFlag,
WarnFlag: param.WarnFlag,
AssistFlag: param.AssistFlag,
IsLast: param.IsLast,
TaskLevel: param.TaskLevel,
TaskName: param.TaskName,
TaskAlias: param.TaskAlias,
TaskSortBy: int(param.TaskSortBy),
TaskEndTime: param.TaskEndTime,
RecordBegin: param.RecordBegin,
NoticeWho: param.NoticeWho,
Marks: param.Marks,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
... ... @@ -100,28 +92,16 @@ func (repo *TaskRepository) Save(param *domain.Task) error {
return nil
}
func (repo *TaskRepository) Remove(id int) error {
func (repo *TaskAnomalyRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskAnomaly, error) {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
_, err := tx.Model(&models.Task{}).
Where("id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
func (repo *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) {
tx := repo.transactionContext.PgTx
m := new(models.Task)
m := new(models.TaskAnomaly)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有找到task数据")
return nil, fmt.Errorf("没有找到TaskAnomaly数据")
} else {
return nil, err
}
... ... @@ -130,33 +110,10 @@ func (repo *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domai
return u, nil
}
func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Task, error) {
func (repo *TaskAnomalyRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskAnomaly, error) {
tx := repo.transactionContext.PgTx
var m []*models.Task
query := tx.Model(&m).
Where("deleted_at isnull").
Limit(20)
if val, ok := queryOptions["name"]; ok {
query.Where("task.name like ?", val)
}
if val, ok := queryOptions["companyId"]; ok {
query.Where("task.company_id = ?", val)
}
if val, ok := queryOptions["id"]; ok {
query.Where("task.id=?", val)
}
if val, ok := queryOptions["leaderId"]; ok {
query.Where("task.leader->>'id'=?", val)
}
if val, ok := queryOptions["aliasOrLeader"]; ok {
query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val)
}
if val, ok := queryOptions["status"]; ok {
query.Where("task.status=?", val)
}
if val, ok := queryOptions["createdBy"]; ok {
query.Where("created_by = ?", val)
}
var m []*models.TaskAnomaly
query := tx.Model(&m)
if val, ok := queryOptions["limit"]; ok {
if limit, err := strconv.Atoi(fmt.Sprintf("%v", val)); err == nil {
query.Limit(limit)
... ... @@ -167,12 +124,21 @@ func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*d
query.Offset(offset)
}
}
if val, ok := queryOptions["category"]; ok {
query.Where(" category =? ", val)
}
if val, ok := queryOptions["currentStage"]; ok {
query.Where("current_stage @> ?", val)
}
if val, ok := queryOptions["isLast"]; ok {
query.Where("is_last=?", val)
}
query.Order("id desc")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var datas []*domain.Task
var datas []*domain.TaskAnomaly
for _, v := range m {
d := repo.TransformToDomain(v)
datas = append(datas, d)
... ...
... ... @@ -14,67 +14,75 @@ import (
//任务
type TaskAnomalyRepository struct {
type TaskRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.TaskAnomalyRepository = (*TaskAnomalyRepository)(nil)
var _ domain.TaskRepository = (*TaskRepository)(nil)
func NewTaskAnomalyRepository(transactionContext *pgTransaction.TransactionContext) *TaskAnomalyRepository {
return &TaskAnomalyRepository{transactionContext: transactionContext}
func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) *TaskRepository {
return &TaskRepository{transactionContext: transactionContext}
}
func (repo *TaskAnomalyRepository) TransformToDomain(d *models.TaskAnomaly) *domain.TaskAnomaly {
return &domain.TaskAnomaly{
Id: d.Id,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
CompanyId: d.CompanyId,
TaskId: d.TaskId,
Category: d.Category,
CurrentStage: d.CurrentStage,
LastStage: d.LastStage,
AssessFlag: d.AssessFlag,
WarnFlag: d.WarnFlag,
AssistFlag: d.AssistFlag,
IsLast: d.IsLast,
TaskLevel: d.TaskLevel,
TaskName: d.TaskName,
TaskAlias: d.TaskAlias,
TaskSortBy: domain.TaskSortBy(d.TaskSortBy),
TaskEndTime: d.TaskEndTime,
RecordBegin: d.RecordBegin,
NoticeWho: d.NoticeWho,
Marks: d.Marks,
func (repo *TaskRepository) TransformToDomain(d *models.Task) *domain.Task {
return &domain.Task{
Id: d.Id,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
CompanyId: d.CompanyId,
Name: d.Name,
Alias: d.Alias,
Leader: d.Leader,
Status: domain.TaskState(d.Status),
Level: d.Level,
LevelName: d.LevelName,
SortBy: domain.TaskSortBy(d.SortBy),
EndTime: d.EndTime,
UseEndTime: d.UseEndTime,
RelatedUser: d.RelatedUser,
RunAt: d.RunAt,
StopAt: d.StopAt,
Anomaly: d.Anomaly,
WarnFlag: domain.TaskWarnFlag(d.WarnFlag),
AssistFlag: d.AssistFlag,
AssistFlagMax: d.AssistFlagMax,
CurrentStage: d.CurrentStage,
LastStage: d.LastStage,
CreatedBy: d.CreatedBy,
}
}
func (repo *TaskAnomalyRepository) Save(param *domain.TaskAnomaly) error {
func (repo *TaskRepository) Save(param *domain.Task) error {
param.UpdatedAt = time.Now()
if param.Id == 0 {
param.CreatedAt = time.Now()
}
m := models.TaskAnomaly{
Id: param.Id,
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
CompanyId: param.CompanyId,
TaskId: param.TaskId,
Category: param.Category,
CurrentStage: param.CurrentStage,
LastStage: param.LastStage,
AssessFlag: param.AssessFlag,
WarnFlag: param.WarnFlag,
AssistFlag: param.AssistFlag,
IsLast: param.IsLast,
TaskLevel: param.TaskLevel,
TaskName: param.TaskName,
TaskAlias: param.TaskAlias,
TaskSortBy: int(param.TaskSortBy),
TaskEndTime: param.TaskEndTime,
RecordBegin: param.RecordBegin,
NoticeWho: param.NoticeWho,
Marks: param.Marks,
m := models.Task{
Id: param.Id,
CreatedAt: param.CreatedAt,
UpdatedAt: param.UpdatedAt,
DeletedAt: param.DeletedAt,
Name: param.Name,
Alias: param.Alias,
CompanyId: param.CompanyId,
Leader: param.Leader,
Status: int(param.Status),
Level: param.Level,
LevelName: param.LevelName,
RelatedUser: param.RelatedUser,
LastStage: param.LastStage,
RunAt: param.RunAt,
StopAt: param.StopAt,
Anomaly: param.Anomaly,
WarnFlag: int(param.WarnFlag),
CurrentStage: param.CurrentStage,
SortBy: int(param.SortBy),
EndTime: param.EndTime,
UseEndTime: param.UseEndTime,
AssistFlag: param.AssistFlag,
AssistFlagMax: param.AssistFlagMax,
CreatedBy: param.CreatedBy,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
... ... @@ -92,16 +100,28 @@ func (repo *TaskAnomalyRepository) Save(param *domain.TaskAnomaly) error {
return nil
}
func (repo *TaskAnomalyRepository) FindOne(queryOptions map[string]interface{}) (*domain.TaskAnomaly, error) {
func (repo *TaskRepository) Remove(id int) error {
tx := repo.transactionContext.PgTx
m := new(models.TaskAnomaly)
nowTime := time.Now()
_, err := tx.Model(&models.Task{}).
Where("id=?", id).
Set("deleted_at=?", nowTime).
Update()
return err
}
func (repo *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) {
tx := repo.transactionContext.PgTx
m := new(models.Task)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有找到TaskAnomaly数据")
return nil, fmt.Errorf("没有找到task数据")
} else {
return nil, err
}
... ... @@ -110,10 +130,33 @@ func (repo *TaskAnomalyRepository) FindOne(queryOptions map[string]interface{})
return u, nil
}
func (repo *TaskAnomalyRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskAnomaly, error) {
func (repo *TaskRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Task, error) {
tx := repo.transactionContext.PgTx
var m []*models.TaskAnomaly
query := tx.Model(&m)
var m []*models.Task
query := tx.Model(&m).
Where("deleted_at isnull").
Limit(20)
if val, ok := queryOptions["name"]; ok {
query.Where("task.name like ?", val)
}
if val, ok := queryOptions["companyId"]; ok {
query.Where("task.company_id = ?", val)
}
if val, ok := queryOptions["id"]; ok {
query.Where("task.id=?", val)
}
if val, ok := queryOptions["leaderId"]; ok {
query.Where("task.leader->>'id'=?", val)
}
if val, ok := queryOptions["aliasOrLeader"]; ok {
query.Where(`task.alias like ? or task.leader->>'name' like ?`, val, val)
}
if val, ok := queryOptions["status"]; ok {
query.Where("task.status=?", val)
}
if val, ok := queryOptions["createdBy"]; ok {
query.Where("created_by = ?", val)
}
if val, ok := queryOptions["limit"]; ok {
if limit, err := strconv.Atoi(fmt.Sprintf("%v", val)); err == nil {
query.Limit(limit)
... ... @@ -129,7 +172,7 @@ func (repo *TaskAnomalyRepository) Find(queryOptions map[string]interface{}) (in
if err != nil {
return 0, nil, err
}
var datas []*domain.TaskAnomaly
var datas []*domain.Task
for _, v := range m {
d := repo.TransformToDomain(v)
datas = append(datas, d)
... ...