作者 tangxvhui

日常保存

... ... @@ -2,6 +2,9 @@ package service
import (
"testing"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
func TestCheckYesterdayTaskRecord(t *testing.T) {
... ... @@ -21,3 +24,41 @@ func TestCheckYesterdayTaskRecord(t *testing.T) {
}
}
}
func TestCreatTaskAnamaly(t *testing.T) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
t.Error(err)
return
}
if err := transactionContext.StartTransaction(); err != nil {
t.Error(err)
return
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, taskRacordList, err := taskRecordRepo.Find(map[string]interface{}{
"ids": []int{1669736612939960320},
})
if err != nil {
t.Error(err)
return
}
if err := transactionContext.CommitTransaction(); err != nil {
t.Error(err)
return
}
for _, val := range taskRacordList {
err = checkTaskRecordV2(val)
if err != nil {
log.Logger.Info("检查每日任务反馈" + err.Error())
}
}
}
... ...
... ... @@ -95,7 +95,7 @@ func isNotWarnFlag(transactionContext application.TransactionContext, taskData *
})
_, oldAnomaly, err := taskAnomalyRepo.Find(map[string]interface{}{
"isLast": 1,
"category": 2,
"category": 1,
"limit": 1,
"taskId": taskData.Id,
"taskStageCheck": fmt.Sprintf(`{"id":"%d"}`, taskRecord.TaskStageCheck.Id),
... ... @@ -108,7 +108,10 @@ func isNotWarnFlag(transactionContext application.TransactionContext, taskData *
}
oldAnomaly[0].IsLast = 2
err = taskAnomalyRepo.Save(oldAnomaly[0])
return fmt.Errorf("取消里程碑异常:%s", err)
if err != nil {
return fmt.Errorf("取消里程碑异常:%s", err)
}
return nil
}
// 处理里程碑异常的情况
... ... @@ -123,7 +126,7 @@ func isWarnFlag(transactionContext application.TransactionContext, taskData *dom
_, oldAnomaly, err := taskAnomalyRepo.Find(map[string]interface{}{
"isLast": 1,
"category": 2,
"category": 1,
"limit": 1,
"taskId": taskData.Id,
"taskStageCheck": fmt.Sprintf(`{"id":"%d"}`, taskRecord.TaskStageCheck.Id),
... ... @@ -133,7 +136,7 @@ func isWarnFlag(transactionContext application.TransactionContext, taskData *dom
}
anomalyDataTmp := domain.TaskAnomaly{
Id: taskData.Id,
Id: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CompanyId: taskData.CompanyId,
... ... @@ -162,6 +165,7 @@ func isWarnFlag(transactionContext application.TransactionContext, taskData *dom
return fmt.Errorf("更新里程碑异常记录:%s", err)
}
}
_ = anomalyDataTmp.AnomalyDesc()
// 异常就通知自己和上级
//获取任务Leader的数据
_, useList, err := userRepo.Find(map[string]interface{}{"id": taskData.Leader.Id, "limit": 1})
... ... @@ -211,7 +215,10 @@ func isNotAssistFlag(transactionContext application.TransactionContext, taskData
}
oldAnomaly[0].IsLast = 2
err = taskAnomalyRepo.Save(oldAnomaly[0])
return fmt.Errorf("取消辅导异常:%s", err)
if err != nil {
return fmt.Errorf("取消辅导异常:%s", err)
}
return nil
}
// 处理辅导异常的情况
... ... @@ -235,7 +242,7 @@ func isAssistFlag(transactionContext application.TransactionContext, taskData *d
}
// 辅导异常通知该条任务负责人的上级;辅导异常超过N天,通知任务负责人的上上级
anomalyDataTmp := domain.TaskAnomaly{
Id: taskData.Id,
Id: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CompanyId: taskData.CompanyId,
... ... @@ -263,6 +270,7 @@ func isAssistFlag(transactionContext application.TransactionContext, taskData *d
return fmt.Errorf("更新里程碑异常记录:%s", err)
}
}
_ = anomalyDataTmp.AnomalyDesc()
//获取任务Leader的数据
_, useList, err := userRepo.Find(map[string]interface{}{"id": taskData.Leader.Id, "limit": 1})
if err != nil {
... ... @@ -311,7 +319,7 @@ func isNotAssessFlag(transactionContext application.TransactionContext, taskData
_, oldAnomaly, err := taskAnomalyRepo.Find(map[string]interface{}{
"isLast": 1,
"category": 3,
"category": 2,
"limit": 1,
"taskId": taskData.Id,
})
... ... @@ -323,8 +331,10 @@ func isNotAssessFlag(transactionContext application.TransactionContext, taskData
}
oldAnomaly[0].IsLast = 2
err = taskAnomalyRepo.Save(oldAnomaly[0])
return fmt.Errorf("取消辅导异常:%s", err)
if err != nil {
return fmt.Errorf("取消辅导异常:%s", err)
}
return nil
}
// 处理反馈异常的情况
... ... @@ -346,12 +356,12 @@ func isAssessFlag(transactionContext application.TransactionContext, taskData *d
}
//
anomalyDataTmp := domain.TaskAnomaly{
Id: taskData.Id,
Id: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CompanyId: taskData.CompanyId,
TaskId: taskData.Id,
Category: 3,
Category: 2,
CurrentStage: taskData.CurrentStage,
LastStage: taskData.LastStage,
TaskStageCheck: taskRecord.TaskStageCheck,
... ... @@ -373,6 +383,7 @@ func isAssessFlag(transactionContext application.TransactionContext, taskData *d
return fmt.Errorf("更新里程碑异常记录:%s", err)
}
}
_ = anomalyDataTmp.AnomalyDesc()
// 2天未反馈通知被评估人自己;3天通知上级
// 获取任务Leader的数据
_, useList, err := userRepo.Find(map[string]interface{}{"id": taskData.Leader.Id, "limit": 1})
... ...
... ... @@ -1141,6 +1141,7 @@ func (srv TaskService) ListTask3(param *command.SearchTaskCommand) (map[string]i
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计任务反馈异常总数"+err.Error())
}
//TODO 获取异常的任务反馈记录
taskResult := []*adapter.TaskItem{}
taskStageRepo := factory.CreateTaskStageRepository(map[string]interface{}{
... ...
... ... @@ -27,6 +27,7 @@ type TaskAnomaly struct {
RecordBegin int64 `json:"recordBegin"` // 异常记录的开始时间
NoticeWho []map[string]string `json:"noticeWho"` // 异常记录消息通知的人
Marks map[string]string `json:"marks"` // 已经操作的标记
Remark string `json:"remark"`
}
// 已点击“去更新”
... ... @@ -57,7 +58,7 @@ func (t *TaskAnomaly) SetNoticeWho(u *User) {
// 异常状况描述
func (t *TaskAnomaly) AnomalyDesc() (str string) {
nowTime := time.Now()
nowTime := t.CreatedAt
switch t.Category {
case 1:
//里程碑异常
... ... @@ -101,6 +102,7 @@ func (t *TaskAnomaly) AnomalyDesc() (str string) {
}
}
t.Remark = str
return str
}
... ...
... ... @@ -50,7 +50,7 @@ type TaskRecordRepository interface {
// 是否是辅导异常
func (r *TaskRecord) IsAssistAnomaly() bool {
r.AssistContent = strings.TrimSpace(r.AssistContent)
if r.AssistLevel == AssistLevel1 || r.AssistContent == "无" {
if r.AssistLevel == AssistLevel1 || r.AssistContent == "无" || len(r.AssistContent) == 0 {
return true
}
return false
... ...
... ... @@ -9,7 +9,7 @@ import (
// 任务的异常记录
type TaskAnomaly struct {
tableName struct{} `comment:"任务的异常记录" pg:"task_anomaly"`
Id int `pg:"id"` //
Id int `pg:"id,pk"` //
CreatedAt time.Time `pg:"created_at"` //
UpdatedAt time.Time `pg:"updated_at"` //
CompanyId int `pg:"company_id"` //
... ... @@ -25,4 +25,5 @@ type TaskAnomaly struct {
RecordBegin int64 `pg:"record_begin"` // 异常记录的开始时间
NoticeWho []map[string]string `pg:"notice_who"` // 异常记录消息通知的人
Marks map[string]string `pg:"marks"` // 已经操作的标记
Remark string `pg:"remark,use_zero"`
}
... ...
... ... @@ -62,6 +62,7 @@ func (repo *TaskAnomalyRepository) Save(param *domain.TaskAnomaly) error {
RecordBegin: param.RecordBegin,
NoticeWho: param.NoticeWho,
Marks: param.Marks,
Remark: param.Remark,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
... ...