作者 tangxvhui

更新手机端 消息通知

... ... @@ -45,15 +45,15 @@ func messageTaskStageAnomaly() ([]*domain.MessagePersonal, error) {
if len(userList) == 0 {
continue
}
//通知相关人员
// 【您关注的【%s】里程碑未按时完成,请知晓。】
var leaderParentId int
//通知负责人
for _, val2 := range userList {
content := ""
if val2.Level == 1 {
content = fmt.Sprintf("【您负责的项目【%s】里程碑未按时完成,请重点关注,积极寻找上级辅导。】", val.TaskName)
} else if val2.Level == 2 {
leaderParentId = val2.Id
content = fmt.Sprintf("【您下级%s负责的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskName)
} else if val2.Level >= 3 {
content = fmt.Sprintf("【您下级%s关注的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskName)
... ... @@ -80,6 +80,35 @@ func messageTaskStageAnomaly() ([]*domain.MessagePersonal, error) {
}
allMessage = append(allMessage, &newMessage)
}
//通知相关人员
//【您关注的【%s】里程碑未按时完成,请知晓。】
for _, val2 := range val.RelatedUser {
if val2 == val.LeaderId {
continue
}
if val2 == leaderParentId {
continue
}
payload := map[string]string{
"taskId": strconv.Itoa(val.TaskId),
"taskAlias": val.TaskAlias,
"taskName": val.TaskName,
}
payloadStr, _ := json.Marshal(payload)
content := fmt.Sprintf("【您关注的【%s】里程碑未按时完成,请知晓。】", val.TaskAlias)
newMessage := domain.MessagePersonal{
Id: 0,
Types: domain.MessageTypesTaskStageApp,
TargetUserId: val2,
ReadFlag: domain.MessageIsRead,
Title: content,
Content: content,
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
Payload: string(payloadStr),
}
allMessage = append(allMessage, &newMessage)
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, err
... ... @@ -99,65 +128,69 @@ func messageTaskRecordAnomaly() ([]*domain.MessagePersonal, error) {
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
// userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
// taskData, err := taskDao.TaskRecordAnomalyAll()
// if err != nil {
// return nil, fmt.Errorf("获取任务信息%s", err)
// }
// if len(taskData) == 0 {
// return nil, nil
// }
// var allMessage []*domain.MessagePersonal
// for _, val := range taskData {
// //获取我全上级
// userList, err := userDao.AllParentUser(val.LeaderId)
// if err != nil {
// return nil, fmt.Errorf("获取上级人员信息%s", err)
// }
// if len(userList) == 0 {
// continue
// }
// //通知相关人员
// //通知负责人
// for _, val2 := range userList {
// content := ""
// if val2.Level == 1 {
// content = fmt.Sprintf("【您负责的项目【%s】已超过%s日未反馈进度,请前往该战略任务进行反馈。】", val.TaskName)
// } else if val2.Level == 2 {
// content = fmt.Sprintf("【您下级%s负责的项目【%s】已超过%s日未反馈进度,请前往辅导。】", val.LeaderName, val.TaskName)
// } else if val2.Level == 3 {
// content = fmt.Sprintf("【您下级%s关注的项目【%s】已超过%s日未反馈进度,请前往辅导。】", val.LeaderName, val.TaskName)
// }
// if content == "" {
// continue
// }
// payload := map[string]string{
// "task_id": strconv.Itoa(val.TaskId),
// "task_alias": val.TaskAlias,
// "task_name": val.TaskName,
// }
// payloadStr, _ := json.Marshal(payload)
// newMessage := domain.MessagePersonal{
// Id: 0,
// Types: domain.MessageTypesTaskStageApp,
// TargetUserId: val2.Id,
// ReadFlag: domain.MessageIsRead,
// Title: content,
// Content: content,
// CreatedAt: time.Time{},
// UpdatedAt: time.Time{},
// Payload: string(payloadStr),
// }
// allMessage = append(allMessage, &newMessage)
// }
// }
taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
taskData, err := taskDao.TaskRecordAnomalyAll()
if err != nil {
return nil, fmt.Errorf("获取任务信息%s", err)
}
if len(taskData) == 0 {
return nil, nil
}
var allMessage []*domain.MessagePersonal
for _, val := range taskData {
//获取我全上级
userList, err := userDao.AllParentUser(val.LeaderId)
if err != nil {
return nil, fmt.Errorf("获取上级人员信息%s", err)
}
if len(userList) == 0 {
continue
}
//通知负责人
for _, val2 := range userList {
payload := map[string]string{
"taskId": strconv.Itoa(val.TaskId),
"taskAlias": val.TaskAlias,
"taskName": val.TaskName,
}
payloadStr, _ := json.Marshal(payload)
newMessage := domain.MessagePersonal{
Id: 0,
Types: domain.MessageTypesTaskStageApp,
TargetUserId: val2.Id,
ReadFlag: domain.MessageIsRead,
Title: "",
Content: "",
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
Payload: string(payloadStr),
}
content := ""
if val2.Level == 1 {
content = fmt.Sprintf("【您负责的项目【%s】已超过%d日未反馈进度,请前往该战略任务进行反馈。】", val.TaskName, val.Anomaly)
newMessage.Content = content
newMessage.Title = content
allMessage = append(allMessage, &newMessage)
}
if val2.Level == 2 && val.Anomaly > 3 {
content = fmt.Sprintf("【您下级%s负责的项目【%s】已超过%d日未反馈进度,请前往辅导。】", val.LeaderName, val.TaskName, val.Anomaly)
newMessage.Content = content
newMessage.Title = content
allMessage = append(allMessage, &newMessage)
}
if val2.Level == 3 && val.Anomaly > 5 {
content = fmt.Sprintf("【您下级%s关注的项目【%s】已超过%d日未反馈进度,请前往辅导。】", val.LeaderName, val.TaskName, val.Anomaly)
newMessage.Content = content
newMessage.Title = content
allMessage = append(allMessage, &newMessage)
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, err
}
// return allMessage, nil
return nil, nil
return allMessage, nil
}
func saveAllMessagePersonal(msgList []*domain.MessagePersonal) error {
... ... @@ -194,6 +227,11 @@ func appMessageSend() error {
return fmt.Errorf("生成里程碑异常的消息通知失败%s", err)
}
appMessage = append(appMessage, messageList...)
messageList2, err := messageTaskRecordAnomaly()
if err != nil {
return fmt.Errorf("生成任务反馈异常的消息通知失败%s", err)
}
appMessage = append(appMessage, messageList2...)
openApi := serviceGateway.NewHttplibMmmOpenApiServiceGateway()
for _, val := range appMessage {
_, err := openApi.PushInfo(1, constant.APP_MESSAGE_KEY, []int64{int64(val.TargetUserId)}, val.Title, val.Content)
... ...
... ... @@ -9,8 +9,8 @@ import (
func TestGenerateToken(t *testing.T) {
ut := UserAuth{
CompanyId: 8,
UserId: 3422174102828544,
Phone: "17708397664",
UserId: 3422185340122624,
Phone: "13066667710",
PlatformId: 29,
AdminType: 1,
}
... ...