...
|
...
|
@@ -106,228 +106,6 @@ func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *comm |
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
// 获取关于任务里程碑异常的消息
|
|
|
// 每日一次
|
|
|
func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
nowDay := time.Now().Format("2006-01-02")
|
|
|
cnt, _, err := messageRepo.Find(map[string]interface{}{
|
|
|
"types": domain.MessageTypesTaskStage,
|
|
|
"targetUserId": param.UserId,
|
|
|
"createdAtDay": nowDay,
|
|
|
"limit": 1,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
|
|
|
}
|
|
|
if cnt > 0 {
|
|
|
resp := map[string]interface{}{
|
|
|
"needNotify": false,
|
|
|
"list": []adapter.MessageListAdapter{},
|
|
|
}
|
|
|
return resp, nil
|
|
|
}
|
|
|
userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
|
|
|
taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
// 我作为任务负责人的提醒
|
|
|
leaderIds := []string{strconv.Itoa(param.UserId)}
|
|
|
taskStageList, err := taskDao.TaskStageAnomalyByLeader(leaderIds)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
|
|
|
}
|
|
|
// 我作为任务相关方
|
|
|
taskStageList0, err := taskDao.TaskStageAnomalyByRelatedUser(param.UserId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
|
|
|
}
|
|
|
childUser, err := userDao.AllChildUser(param.UserId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取下级员工"+err.Error())
|
|
|
}
|
|
|
//我的直属下级人员
|
|
|
childUserId := []string{}
|
|
|
for _, val := range childUser {
|
|
|
if val.Level == 2 {
|
|
|
childUserId = append(childUserId, strconv.Itoa(val.Id))
|
|
|
}
|
|
|
}
|
|
|
// 作为上级,我的下级员工的异常里程碑
|
|
|
var taskList2 []dao.TaskData3
|
|
|
if len(childUserId) > 0 {
|
|
|
taskList2, err = taskDao.TaskStageAnomalyByLeader(childUserId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
|
|
|
}
|
|
|
}
|
|
|
//我的下下级人员
|
|
|
childUserId2 := []string{}
|
|
|
for _, val := range childUser {
|
|
|
if val.Level >= 3 {
|
|
|
childUserId2 = append(childUserId2, strconv.Itoa(val.Id))
|
|
|
}
|
|
|
}
|
|
|
// 作为上级, 我的下下级员工的异常里程碑
|
|
|
var taskList3 []dao.TaskData3
|
|
|
if len(childUserId2) > 0 {
|
|
|
taskList3, err = taskDao.TaskStageAnomalyByLeader(childUserId2)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
msgList := []adapter.MessageListAdapter{}
|
|
|
for _, val := range taskStageList {
|
|
|
s := fmt.Sprintf("【您负责的项目【%s】里程碑未按时完成,请重点关注,积极寻找上级辅导。】", val.TaskAlias)
|
|
|
msgList = append(msgList, adapter.MessageListAdapter{
|
|
|
Content: s,
|
|
|
})
|
|
|
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.MessageTypesTaskStage,
|
|
|
TargetUserId: param.UserId,
|
|
|
ReadFlag: domain.MessageIsRead,
|
|
|
Title: s,
|
|
|
Content: s,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
Payload: string(payloadStr),
|
|
|
}
|
|
|
err = messageRepo.Save(&newMessage)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
for _, val := range taskList2 {
|
|
|
s := fmt.Sprintf("【您下级%s负责的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskAlias)
|
|
|
msgList = append(msgList, adapter.MessageListAdapter{
|
|
|
Content: s,
|
|
|
})
|
|
|
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.MessageTypesTaskStage,
|
|
|
TargetUserId: param.UserId,
|
|
|
ReadFlag: domain.MessageIsRead,
|
|
|
Title: s,
|
|
|
Content: s,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
Payload: string(payloadStr),
|
|
|
}
|
|
|
err = messageRepo.Save(&newMessage)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
for _, val := range taskList3 {
|
|
|
s := fmt.Sprintf("【您下级%s关注的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskAlias)
|
|
|
msgList = append(msgList, adapter.MessageListAdapter{
|
|
|
Content: s,
|
|
|
})
|
|
|
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.MessageTypesTaskStage,
|
|
|
TargetUserId: param.UserId,
|
|
|
ReadFlag: domain.MessageIsRead,
|
|
|
Title: s,
|
|
|
Content: s,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
Payload: string(payloadStr),
|
|
|
}
|
|
|
err = messageRepo.Save(&newMessage)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
uidStr := strconv.Itoa(param.UserId)
|
|
|
//我作为任务相关人
|
|
|
loop:
|
|
|
for _, val := range taskStageList0 {
|
|
|
// 排除 我就是负责人,
|
|
|
if val.LeaderId == uidStr {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
//排除 我是任务负责人的直属上级
|
|
|
for _, val2 := range childUserId {
|
|
|
if val.LeaderId == val2 {
|
|
|
continue loop
|
|
|
}
|
|
|
}
|
|
|
|
|
|
s := fmt.Sprintf("【您关注的【%s】里程碑未按时完成,请知晓。】", val.TaskAlias)
|
|
|
msgList = append(msgList, adapter.MessageListAdapter{
|
|
|
Content: s,
|
|
|
})
|
|
|
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.MessageTypesTaskStage,
|
|
|
TargetUserId: param.UserId,
|
|
|
ReadFlag: domain.MessageIsRead,
|
|
|
Title: s,
|
|
|
Content: s,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
Payload: string(payloadStr),
|
|
|
}
|
|
|
err = messageRepo.Save(&newMessage)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
resp := map[string]interface{}{
|
|
|
"needNotify": true,
|
|
|
"list": msgList,
|
|
|
}
|
|
|
if len(msgList) == 0 {
|
|
|
resp["needNotify"] = false
|
|
|
}
|
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
// 获取关于任务反馈碑异常的消息
|
|
|
// 每日一次
|
|
|
func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
|
...
|
...
|
|