...
|
...
|
@@ -4,6 +4,7 @@ import ( |
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
...
|
...
|
@@ -613,17 +614,165 @@ func (srv *MessagePersonalService) TodayMessageTaskAnomaly(param *command.GetUse |
|
|
}
|
|
|
return resp, nil
|
|
|
}
|
|
|
userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
// 获取员工全部子集
|
|
|
childUser, err := userDao.AllChildUser(param.UserId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取下级员工"+err.Error())
|
|
|
}
|
|
|
taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
//获取异常任务数据
|
|
|
childUserId := []string{}
|
|
|
for _, val := range childUser {
|
|
|
if val.Level == 2 || val.Level == 1 {
|
|
|
childUserId = append(childUserId, strconv.Itoa(val.Id))
|
|
|
}
|
|
|
}
|
|
|
taskList, err := taskDao.TaskIsAnomalyForNotice(param.CompanyId, childUserId, param.UserId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里异常的消息"+err.Error())
|
|
|
}
|
|
|
myUserId := strconv.Itoa(param.UserId)
|
|
|
|
|
|
var num1, num2, num3 int //我负责的任务,我的下级任务,我相关的任务
|
|
|
var todayMessage []domain.MessagePersonal
|
|
|
var msg string
|
|
|
for _, val := range taskList {
|
|
|
payload := map[string]string{
|
|
|
"id": strconv.Itoa(val.TaskId),
|
|
|
"taskName": val.TaskName,
|
|
|
"taskAlias": val.TaskAlias,
|
|
|
"leaderName": val.LeaderName,
|
|
|
}
|
|
|
payloadStr, _ := json.Marshal(payload)
|
|
|
newMessage := domain.MessagePersonal{
|
|
|
Id: 0,
|
|
|
Types: domain.MessageTypesTaskRecord,
|
|
|
TargetUserId: param.UserId,
|
|
|
ReadFlag: domain.MessageIsRead,
|
|
|
Title: "",
|
|
|
Content: "",
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
Payload: string(payloadStr),
|
|
|
}
|
|
|
if val.LeaderId == myUserId {
|
|
|
//是我负责的项目
|
|
|
|
|
|
t := 0
|
|
|
if val.WarnFlag > 0 {
|
|
|
t += 1
|
|
|
msg = fmt.Sprintf("您负责的任务【%s】里程碑发生异常,请前往处理。", val.TaskAlias)
|
|
|
}
|
|
|
if val.Anomaly > 1 {
|
|
|
t += 1
|
|
|
msg = fmt.Sprintf("您负责的任务【%s】已超过%d天没反馈,有异常风险,请前往处理。", val.TaskAlias, val.Anomaly)
|
|
|
}
|
|
|
if t > 1 {
|
|
|
msg = fmt.Sprintf("您负责的任务【%s】里程碑异常、反馈异常,请前往处理。", val.TaskAlias)
|
|
|
}
|
|
|
newMessage.Title = msg
|
|
|
newMessage.Content = msg
|
|
|
if t > 0 {
|
|
|
num1 += 1
|
|
|
todayMessage = append(todayMessage, newMessage)
|
|
|
}
|
|
|
continue
|
|
|
}
|
|
|
var inChild bool
|
|
|
for _, val2 := range childUserId {
|
|
|
//我的下级负责的任务
|
|
|
if val2 != val.LeaderId {
|
|
|
continue
|
|
|
}
|
|
|
inChild = true
|
|
|
t := 0
|
|
|
t2 := []string{}
|
|
|
if val.WarnFlag > 0 {
|
|
|
t += 1
|
|
|
msg = fmt.Sprintf("您下级负责的任务【%s】里程碑发生异常,请前往处理。", val.TaskAlias)
|
|
|
t2 = append(t2, "里程碑异常")
|
|
|
}
|
|
|
if val.Anomaly > 1 {
|
|
|
t += 1
|
|
|
msg = fmt.Sprintf("您下级负责的任务【%s】已超过%d天没反馈,有异常风险,请前往处理。", val.TaskAlias, val.Anomaly)
|
|
|
t2 = append(t2, "反馈异常")
|
|
|
}
|
|
|
if val.AssistFlag > 0 {
|
|
|
t += 1
|
|
|
msg = fmt.Sprintf("您需辅导的任务【%s】发生异常,请前往处理", val.TaskAlias)
|
|
|
t2 = append(t2, "辅导异常")
|
|
|
}
|
|
|
if t > 1 {
|
|
|
msg = fmt.Sprintf("您下级负责的任务【%s】%s,请前往处理。", val.TaskAlias, strings.Join(t2, "、"))
|
|
|
}
|
|
|
newMessage.Title = msg
|
|
|
newMessage.Content = msg
|
|
|
if t > 0 {
|
|
|
num2 += 1
|
|
|
todayMessage = append(todayMessage, newMessage)
|
|
|
}
|
|
|
break
|
|
|
}
|
|
|
if inChild {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
// 与我相关的任务
|
|
|
t := 0
|
|
|
if val.WarnFlag > 0 {
|
|
|
t += 1
|
|
|
msg = fmt.Sprintf("与您相关的任务【%s】里程碑发生异常,请知晓。", val.TaskAlias)
|
|
|
}
|
|
|
if val.Anomaly > 1 {
|
|
|
t += 1
|
|
|
msg = fmt.Sprintf("与您相关的任务【%s】已超过%d天没反馈,有异常风险,请知晓。", val.TaskAlias, val.Anomaly)
|
|
|
}
|
|
|
if t > 1 {
|
|
|
msg = fmt.Sprintf("与您相关的任务【%s】里程碑异常、反馈异常,请知晓。", val.TaskAlias)
|
|
|
}
|
|
|
newMessage.Title = msg
|
|
|
newMessage.Content = msg
|
|
|
if t > 0 {
|
|
|
num3 += 1
|
|
|
todayMessage = append(todayMessage, newMessage)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if len(todayMessage) > 0 {
|
|
|
for i := range todayMessage {
|
|
|
err = messageRepo.Save(&todayMessage[i])
|
|
|
if err != nil {
|
|
|
resp := map[string]interface{}{
|
|
|
"needNotify": false,
|
|
|
"list": []adapter.MessageListAdapter{{Content: err.Error()}},
|
|
|
}
|
|
|
return resp, nil
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var msgList []adapter.MessageListAdapter
|
|
|
resp := map[string]interface{}{
|
|
|
"needNotify": true,
|
|
|
"list": msgList,
|
|
|
"needNotify": false,
|
|
|
}
|
|
|
if len(msgList) == 0 {
|
|
|
resp["needNotify"] = false
|
|
|
if (num1 + num2 + num3) == 1 {
|
|
|
resp["needNotify"] = true
|
|
|
resp["list"] = []adapter.MessageListAdapter{{Content: msg}}
|
|
|
} else if (num1 + num2 + num3) > 1 {
|
|
|
resp["needNotify"] = true
|
|
|
str := []string{}
|
|
|
if num1 > 0 {
|
|
|
str = append(str, fmt.Sprintf("您负责的任务%d个任务", num1))
|
|
|
}
|
|
|
if num2 > 0 {
|
|
|
str = append(str, fmt.Sprintf("下级负责的%d个任务", num2))
|
|
|
}
|
|
|
if num3 > 0 {
|
|
|
str = append(str, fmt.Sprintf("与您有关的%d个任务发生异常", num3))
|
|
|
}
|
|
|
resp["list"] = []adapter.MessageListAdapter{{Content: strings.Join(str, "、") + ",请前往处理。"}}
|
|
|
}
|
|
|
return resp, nil
|
|
|
} |
...
|
...
|
|