...
|
...
|
@@ -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)
|
...
|
...
|
|