作者 tangxvhui

调整弹窗消息

... ... @@ -2,4 +2,5 @@ package command
type GetUserMessageCommand struct {
UserId int `json:"-"`
CompanyId int `json:"-"`
}
... ...
... ... @@ -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
}
... ...
... ... @@ -750,38 +750,21 @@ func (d *TaskDao) CountTaskIgnore(param ListTaskCondition) (int, error) {
}
type TaskData6 struct {
TaskId int `pg:"task_id"`
TaskName string `pg:"task_name"`
TaskAlias string `pg:"task_alias"`
LeaderName string `pg:"leader_name"`
LeaderId string `pg:"leader_id"`
WarnFlag int `pg:"warn_flag"`
AssistFlag int `pg:"assist_flag"`
Anomaly int `pg:"anomaly"`
TaskId int `pg:"task_id"` //任务id
TaskName string `pg:"task_name"` //任务名称
TaskAlias string `pg:"task_alias"` //任务名称
LeaderName string `pg:"leader_name"` //负责人名称
LeaderId string `pg:"leader_id"` //负责人id
WarnFlag int `pg:"warn_flag"` //里程碑异常
AssistFlag int `pg:"assist_flag"` //辅导异常
Anomaly int `pg:"anomaly"` //反馈异常
RelatedUser []int `pg:"related_user"` //相关人员
}
func (d *TaskDao) TaskIsAnomalyByLeader(leaderId []string) ([]TaskData6, error) {
sqlStr := `select
task.id as task_id,
task."name" as task_name ,
task.alias as task_alias,
task.leader ->>'id' as leader_id,
task.leader ->>'name' as leader_name,
task.assist_flag ,
task.warn_flag ,
task.anomaly
from task where 1=1
and task.deleted_at isnull
and (task.assist_flag+task.warn_flag +task.anomaly)>0
and task.leader ->>'id' in(?) `
result := []TaskData6{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, pg.In(leaderId))
return result, err
}
func (d *TaskDao) TaskIsAnomalyByRelatedUser(relatedUserId int) ([]TaskData6, error) {
sqlStr := `select
// 查询每日任务异常消息弹窗需要的数据
func (d *TaskDao) TaskIsAnomalyForNotice(companyId int, leaderId []string, relatedUserId int) ([]TaskData6, error) {
sqlStr := `
select
task.id as task_id,
task."name" as task_name ,
task.alias as task_alias,
... ... @@ -789,15 +772,44 @@ func (d *TaskDao) TaskIsAnomalyByRelatedUser(relatedUserId int) ([]TaskData6, er
task.leader ->>'name' as leader_name,
task.assist_flag ,
task.warn_flag ,
task.anomaly
task.anomaly ,
task.related_user
from task where 1=1
and task.deleted_at isnull
and task.company_id=?
and (task.assist_flag+task.warn_flag +task.anomaly)>0
and task.related_user @>? `
and (task.leader ->>'id' in(?) or task.related_user @>?)
`
relatedUser := fmt.Sprintf("[%d]", relatedUserId)
condition := []interface{}{companyId, pg.In(leaderId), relatedUser}
result := []TaskData6{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, relatedUser)
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// 按照 任务的相关人员(related_user),排除 既是相关人员,又是任务负责人的情况, 获取出现异常的任务
// func (d *TaskDao) TaskIsAnomalyByRelatedUser(relatedUserId int) ([]TaskData6, error) {
// sqlStr := `select
// task.id as task_id,
// task."name" as task_name ,
// task.alias as task_alias,
// task.leader ->>'id' as leader_id,
// task.leader ->>'name' as leader_name,
// task.assist_flag ,
// task.warn_flag ,
// task.anomaly
// from task where 1=1
// and task.deleted_at isnull
// and (task.assist_flag+task.warn_flag +task.anomaly)>0
// and task.related_user @>?
// and task.leader ->>'id' <> ?
// `
// relatedUser := fmt.Sprintf("[%d]", relatedUserId)
// condition := []interface{}{relatedUser, strconv.Itoa(relatedUserId)}
// result := []TaskData6{}
// tx := d.transactionContext.PgTx
// _, err := tx.Query(&result, sqlStr, condition...)
// return result, err
// }
... ...
... ... @@ -36,7 +36,8 @@ func (c *MessagePersonalController) TodayMessageTaskRecordAnomaly() {
userReq := middlewares.GetUser(c.Ctx)
param := command.GetUserMessageCommand{}
param.UserId = int(userReq.UserId)
data, err := srv.TodayMessageTaskRecordAnomalyV2(&param)
param.CompanyId = int(userReq.CompanyId)
data, err := srv.TodayMessageTaskAnomaly(&param)
c.Response(data, err)
}
... ...