task_anomaly.go
6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package domain
import (
"fmt"
"strconv"
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils/xtime"
)
const (
AnomalyCategoryType1 int = 1 //里程碑异常
AnomalyCategoryType2 int = 2 //反馈异常
AnomalyCategoryType3 int = 3 //辅导异常
)
// 任务的异常记录
type TaskAnomaly struct {
Id int
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
CompanyId int `json:"companyId,string"`
TaskId int `json:"taskId,string"` // 任务id
TaskRecordId int `json:"taskRecordId,string"` // 任务反馈的进度
Category int `json:"category"` // 异常记录的分类 1里程碑异常;2反馈异常;3 辅导异常
CurrentStage TaskStage `json:"currentStage"` // 计划进度的里程碑
LastStage TaskStage `json:"lastStage"` // 实际进度完成的里程碑
TaskStageCheck TaskStage `json:"taskStageCheck"` // 当天任务反馈操作里程碑记录
AssessFlag int `json:"assessFlag"` // 异常反馈的次数
WarnFlag int `json:"warnFlag"` // 里程碑异常次数
AssistFlag int `json:"assistFlag"` // 辅导异常次数
IsLast int `json:"isLast"` // 是否是最新的一条记录 1 是最新的记录 2 不是最新的记录
RecordBegin int64 `json:"recordBegin"` // 异常记录的开始时间
NoticeWho []map[string]string `json:"noticeWho"` // 异常记录消息通知的人
Marks map[string]string `json:"marks"` // 已经操作的标记
Remark string `json:"remark"`
}
// 存储
type TaskAnomalyRepository interface {
Save(param *TaskAnomaly) error
FindOne(queryOptions map[string]interface{}) (*TaskAnomaly, error)
Find(queryOptions map[string]interface{}) (int, []*TaskAnomaly, error)
}
// 已点击“去更新”
func (t *TaskAnomaly) MarkA() {
t.Marks["a"] = "已更新"
}
// 已点击 "去反馈"
func (t *TaskAnomaly) MarkB() {
t.Marks["b"] = "已反馈"
}
// 已点击 "找上级"
func (t *TaskAnomaly) MarkC() {
t.Marks["c"] = "已求助"
}
// 已点击 "去辅导"
func (t *TaskAnomaly) MarkD() {
t.Marks["d"] = "已辅导"
}
func (t *TaskAnomaly) SetNoticeWho(u *User) {
uid := strconv.Itoa(int(u.Id))
for _, v := range t.NoticeWho {
if v["id"] == uid {
return
}
}
t.NoticeWho = append(t.NoticeWho, map[string]string{
"id": uid, "name": u.Name,
})
}
// 异常状况描述
func (t *TaskAnomaly) AnomalyDesc() (str string) {
nowTime := t.CreatedAt
if nowTime.IsZero() {
nowTime = time.Now()
}
switch t.Category {
case 1:
//里程碑异常
{
//逾期未完成
planCompletedAt := time.Unix(t.CurrentStage.PlanCompletedAt, 0)
subDay := xtime.SubDayAbs(nowTime, planCompletedAt)
str = fmt.Sprintf("里程碑%s已逾期%d天", t.TaskStageCheck.Name, subDay)
}
case 2:
//反馈异常
{
recordBegin := time.Unix(t.RecordBegin, 0)
subDay := xtime.SubDayAbs(nowTime, recordBegin)
str = fmt.Sprintf(
"本任务自%s未正常反馈项目进度,已异常%d天",
recordBegin.Local().Format("2006-01-02"),
subDay,
)
}
case 3:
// 辅导异常
{
recordBegin := time.Unix(t.RecordBegin, 0)
subDay := xtime.SubDayAbs(nowTime, recordBegin)
str = fmt.Sprintf(
"本任务计划于%s完成辅导,已逾期%d天",
recordBegin.Local().Format("2006-01-02"),
subDay,
)
}
}
t.Remark = str
return str
}
// 检查是否是反馈异常
func (t *TaskAnomaly) IsAssessFlag(taskData *Task, taskRecordData *TaskRecord) bool {
if taskData.Anomaly <= 0 {
return false
}
*t = TaskAnomaly{
Id: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CompanyId: taskData.CompanyId,
TaskId: taskData.Id,
TaskRecordId: taskRecordData.Id,
Category: AnomalyCategoryType2,
CurrentStage: taskData.CurrentStage,
LastStage: taskData.LastStage,
TaskStageCheck: taskRecordData.TaskStageCheck,
AssessFlag: taskData.Anomaly,
WarnFlag: 0,
AssistFlag: 0,
IsLast: 1,
RecordBegin: xtime.DayZeroTime(taskRecordData.CreatedAt).Unix(),
NoticeWho: []map[string]string{},
Marks: map[string]string{
"a": "去更新", "b": "去反馈", "c": "找上级", "d": "去辅导",
},
Remark: "",
}
return true
}
// 检查是否是里程碑异常
func (t *TaskAnomaly) IsWarnFlag(taskData *Task, taskRecordData *TaskRecord) bool {
if taskData.CurrentStage.Id == 0 {
// 没有新的里程碑
return false
}
if taskData.CurrentStage.PlanCompletedAt > time.Now().Unix() {
//新的里程碑未过期, 不计入异常情况
return false
}
*t = TaskAnomaly{
Id: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CompanyId: taskData.CompanyId,
TaskId: taskData.Id,
TaskRecordId: taskRecordData.Id,
Category: AnomalyCategoryType1,
CurrentStage: taskData.CurrentStage,
LastStage: taskData.LastStage,
TaskStageCheck: taskRecordData.TaskStageCheck,
AssessFlag: 0,
WarnFlag: 1,
AssistFlag: 0,
IsLast: 1,
RecordBegin: taskData.CurrentStage.PlanCompletedAt,
NoticeWho: []map[string]string{},
Marks: map[string]string{
"a": "去更新", "b": "去反馈", "c": "找上级", "d": "去辅导",
},
Remark: "",
}
return true
}
// 检查是否是辅导异常,
func (t *TaskAnomaly) IsAssistFlag(taskData *Task, taskRecordData *TaskRecord) bool {
if taskData.AssistFlag <= taskData.AssistFlagMax {
return false
}
*t = TaskAnomaly{
Id: 0,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CompanyId: taskData.CompanyId,
TaskId: taskData.Id,
TaskRecordId: taskRecordData.Id,
Category: AnomalyCategoryType3,
CurrentStage: taskData.CurrentStage,
LastStage: taskData.LastStage,
TaskStageCheck: taskRecordData.TaskStageCheck,
AssessFlag: taskData.Anomaly,
WarnFlag: 0,
AssistFlag: 1,
IsLast: 1,
RecordBegin: xtime.DayZeroTime(taskRecordData.CreatedAt).Unix(),
NoticeWho: []map[string]string{},
Marks: map[string]string{
"a": "去更新", "b": "去反馈", "c": "找上级", "d": "去辅导",
},
Remark: "",
}
nowTime := xtime.DayZeroTime(time.Now()).Unix()
if taskData.CurrentStage.Id > 0 && taskData.CurrentStage.PlanCompletedAt < nowTime {
t.WarnFlag = 1
}
return true
}