task_record.go 3.8 KB
package domain

import (
	"strings"
	"time"
)

const (
	AssistLevel1 int = 1 // 未辅导
	AssistLevel2 int = 2 // 已辅导-辅导对里程碑无作用
	AssistLevel3 int = 3 // 已辅导-辅导对里程碑作用一般
	AssistLevel4 int = 4 // 已辅导-辅导对里程碑作用很好
)

const (
	AnomalyStateInit int = -1 // 反馈初始值
	AnomalyState0    int = 0  // 反馈异常
	AnomalyState1    int = 1  // 反馈正常
)

const (
	AssistStateInit int = -1 // 辅导初始值
	AssistState0    int = 0  // 辅导异常
	AssistState1    int = 1  // 辅导正常
)

// TaskRecord 任务反馈情况记录
type TaskRecord struct {
	Id             int          `json:"id,string" comment:"记录ID"`
	CompanyId      int          `json:"companyId,string" comment:"公司ID"`
	StaffAssessId  int          `json:"staffAssessId,string" comment:"每日评估的ID"`
	TaskId         int          `json:"taskId,string" comment:"任务ID"`
	TaskCategory   string       `json:"taskCategory" comment:"任务类别"`
	TaskName       string       `json:"taskName" comment:"任务名称"`
	TaskAlias      string       `json:"taskAlias" comment:"任务别名"`
	TaskLeader     TaskLeader   `json:"taskLeader" comment:"任务负责人"`
	RemarkContent  []RemarkText `json:"remarkContent" comment:"反馈填写"`
	AssistLevel    int          `json:"assistLevel" comment:"上级辅导情况"`
	AssistContent  string       `json:"assistContent" comment:"上级辅导内容"`
	AnomalyState   int          `json:"anomalyState" comment:"反馈异常状态(-1初始状态、0异常、1正常)"`
	AssistState    int          `json:"assistState" comment:"辅导异常状态(-1初始状态、0异常、1正常)"`
	TaskStages     []TaskStage  `json:"taskStages" comment:"里程碑列表"`
	TaskStageCheck TaskStage    `json:"taskStageCheck" comment:"提交的里程碑"`
	CreatedAt      time.Time    `json:"createdAt" comment:"创建时间"`
	UpdatedAt      time.Time    `json:"updatedAt" comment:"更新时间"`
	DeletedAt      *time.Time   `json:"deletedAt" comment:"删除时间"`
	TaskCreatedBy  int          `json:"taskCreatedBy" comment:"任务的创建方式"` // 任务的创建方式 0: 模板导入创建,1:主动创建
}

type TaskRecordRepository interface {
	Insert(t *TaskRecord) (*TaskRecord, error)
	Remove(t *TaskRecord) (*TaskRecord, error)
	FindOne(queryOptions map[string]interface{}) (*TaskRecord, error)
	Find(queryOptions map[string]interface{}) (int, []*TaskRecord, error)
}

// 是否是辅导异常
func (r *TaskRecord) IsAssistAnomaly() bool {
	// 判断是否辅导异常
	taskStageAnomaly := true
	if r.TaskStageCheck.RealCompletedAt > 0 {
		taskStageAnomaly = false
	}

	remarkAnomaly := true
	for _, val := range r.RemarkContent {
		txt := strings.TrimSpace(val.RemarkText)
		if len(txt) == 0 || txt == "无" {
			continue
		}
		remarkAnomaly = false
		break
	}

	assistAnomaly := false
	if taskStageAnomaly || remarkAnomaly {
		assistAnomaly = true
	}
	r.AssistContent = strings.TrimSpace(r.AssistContent)
	if r.AssistLevel == AssistLevel1 || r.AssistContent == "无" || len(r.AssistContent) == 0 {

	} else {
		assistAnomaly = false
	}
	return assistAnomaly
}

// 是否是里程碑异常
// func (r *TaskRecord) IsTaskStageAnomaly() bool {
// 	if r.TaskStageCheck.Id == 0 {
// 		return false
// 	}
// 	realCompletedAt := r.TaskStageCheck.RealCompletedAt
// 	if realCompletedAt == 0 {
// 		//假设现在完成
// 		realCompletedAt = time.Now().Unix()
// 	}
// 	if r.TaskStageCheck.PlanCompletedAt < realCompletedAt {
// 		//逾期完成,或者预期未完成
// 		return true
// 	}

// 	return false
// }

// 是否是反馈异常
func (r *TaskRecord) IsRemarkAnomaly() bool {
	isAnomaly := true
	for _, val := range r.RemarkContent {
		txt := strings.TrimSpace(val.RemarkText)
		if len(txt) == 0 || txt == "无" {
			continue
		}
		isAnomaly = false
		break
	}

	return isAnomaly
}