作者 tangxvhui

调整弹窗消息

1 package command 1 package command
2 2
3 type GetUserMessageCommand struct { 3 type GetUserMessageCommand struct {
4 - UserId int `json:"-"` 4 + UserId int `json:"-"`
  5 + CompanyId int `json:"-"`
5 } 6 }
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "encoding/json" 4 "encoding/json"
5 "fmt" 5 "fmt"
6 "strconv" 6 "strconv"
  7 + "strings"
7 "time" 8 "time"
8 9
9 "github.com/linmadan/egglib-go/core/application" 10 "github.com/linmadan/egglib-go/core/application"
@@ -613,17 +614,165 @@ func (srv *MessagePersonalService) TodayMessageTaskAnomaly(param *command.GetUse @@ -613,17 +614,165 @@ func (srv *MessagePersonalService) TodayMessageTaskAnomaly(param *command.GetUse
613 } 614 }
614 return resp, nil 615 return resp, nil
615 } 616 }
  617 + userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
  618 + // 获取员工全部子集
  619 + childUser, err := userDao.AllChildUser(param.UserId)
  620 + if err != nil {
  621 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取下级员工"+err.Error())
  622 + }
  623 + taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
  624 + //获取异常任务数据
  625 + childUserId := []string{}
  626 + for _, val := range childUser {
  627 + if val.Level == 2 || val.Level == 1 {
  628 + childUserId = append(childUserId, strconv.Itoa(val.Id))
  629 + }
  630 + }
  631 + taskList, err := taskDao.TaskIsAnomalyForNotice(param.CompanyId, childUserId, param.UserId)
  632 + if err != nil {
  633 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里异常的消息"+err.Error())
  634 + }
  635 + myUserId := strconv.Itoa(param.UserId)
  636 +
  637 + var num1, num2, num3 int //我负责的任务,我的下级任务,我相关的任务
  638 + var todayMessage []domain.MessagePersonal
  639 + var msg string
  640 + for _, val := range taskList {
  641 + payload := map[string]string{
  642 + "id": strconv.Itoa(val.TaskId),
  643 + "taskName": val.TaskName,
  644 + "taskAlias": val.TaskAlias,
  645 + "leaderName": val.LeaderName,
  646 + }
  647 + payloadStr, _ := json.Marshal(payload)
  648 + newMessage := domain.MessagePersonal{
  649 + Id: 0,
  650 + Types: domain.MessageTypesTaskRecord,
  651 + TargetUserId: param.UserId,
  652 + ReadFlag: domain.MessageIsRead,
  653 + Title: "",
  654 + Content: "",
  655 + CreatedAt: time.Time{},
  656 + UpdatedAt: time.Time{},
  657 + Payload: string(payloadStr),
  658 + }
  659 + if val.LeaderId == myUserId {
  660 + //是我负责的项目
  661 +
  662 + t := 0
  663 + if val.WarnFlag > 0 {
  664 + t += 1
  665 + msg = fmt.Sprintf("您负责的任务【%s】里程碑发生异常,请前往处理。", val.TaskAlias)
  666 + }
  667 + if val.Anomaly > 1 {
  668 + t += 1
  669 + msg = fmt.Sprintf("您负责的任务【%s】已超过%d天没反馈,有异常风险,请前往处理。", val.TaskAlias, val.Anomaly)
  670 + }
  671 + if t > 1 {
  672 + msg = fmt.Sprintf("您负责的任务【%s】里程碑异常、反馈异常,请前往处理。", val.TaskAlias)
  673 + }
  674 + newMessage.Title = msg
  675 + newMessage.Content = msg
  676 + if t > 0 {
  677 + num1 += 1
  678 + todayMessage = append(todayMessage, newMessage)
  679 + }
  680 + continue
  681 + }
  682 + var inChild bool
  683 + for _, val2 := range childUserId {
  684 + //我的下级负责的任务
  685 + if val2 != val.LeaderId {
  686 + continue
  687 + }
  688 + inChild = true
  689 + t := 0
  690 + t2 := []string{}
  691 + if val.WarnFlag > 0 {
  692 + t += 1
  693 + msg = fmt.Sprintf("您下级负责的任务【%s】里程碑发生异常,请前往处理。", val.TaskAlias)
  694 + t2 = append(t2, "里程碑异常")
  695 + }
  696 + if val.Anomaly > 1 {
  697 + t += 1
  698 + msg = fmt.Sprintf("您下级负责的任务【%s】已超过%d天没反馈,有异常风险,请前往处理。", val.TaskAlias, val.Anomaly)
  699 + t2 = append(t2, "反馈异常")
  700 + }
  701 + if val.AssistFlag > 0 {
  702 + t += 1
  703 + msg = fmt.Sprintf("您需辅导的任务【%s】发生异常,请前往处理", val.TaskAlias)
  704 + t2 = append(t2, "辅导异常")
  705 + }
  706 + if t > 1 {
  707 + msg = fmt.Sprintf("您下级负责的任务【%s】%s,请前往处理。", val.TaskAlias, strings.Join(t2, "、"))
  708 + }
  709 + newMessage.Title = msg
  710 + newMessage.Content = msg
  711 + if t > 0 {
  712 + num2 += 1
  713 + todayMessage = append(todayMessage, newMessage)
  714 + }
  715 + break
  716 + }
  717 + if inChild {
  718 + continue
  719 + }
  720 +
  721 + // 与我相关的任务
  722 + t := 0
  723 + if val.WarnFlag > 0 {
  724 + t += 1
  725 + msg = fmt.Sprintf("与您相关的任务【%s】里程碑发生异常,请知晓。", val.TaskAlias)
  726 + }
  727 + if val.Anomaly > 1 {
  728 + t += 1
  729 + msg = fmt.Sprintf("与您相关的任务【%s】已超过%d天没反馈,有异常风险,请知晓。", val.TaskAlias, val.Anomaly)
  730 + }
  731 + if t > 1 {
  732 + msg = fmt.Sprintf("与您相关的任务【%s】里程碑异常、反馈异常,请知晓。", val.TaskAlias)
  733 + }
  734 + newMessage.Title = msg
  735 + newMessage.Content = msg
  736 + if t > 0 {
  737 + num3 += 1
  738 + todayMessage = append(todayMessage, newMessage)
  739 + }
  740 + }
  741 +
  742 + if len(todayMessage) > 0 {
  743 + for i := range todayMessage {
  744 + err = messageRepo.Save(&todayMessage[i])
  745 + if err != nil {
  746 + resp := map[string]interface{}{
  747 + "needNotify": false,
  748 + "list": []adapter.MessageListAdapter{{Content: err.Error()}},
  749 + }
  750 + return resp, nil
  751 + }
  752 + }
  753 + }
616 if err := transactionContext.CommitTransaction(); err != nil { 754 if err := transactionContext.CommitTransaction(); err != nil {
617 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 755 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
618 } 756 }
619 -  
620 - var msgList []adapter.MessageListAdapter  
621 resp := map[string]interface{}{ 757 resp := map[string]interface{}{
622 - "needNotify": true,  
623 - "list": msgList, 758 + "needNotify": false,
624 } 759 }
625 - if len(msgList) == 0 {  
626 - resp["needNotify"] = false 760 + if (num1 + num2 + num3) == 1 {
  761 + resp["needNotify"] = true
  762 + resp["list"] = []adapter.MessageListAdapter{{Content: msg}}
  763 + } else if (num1 + num2 + num3) > 1 {
  764 + resp["needNotify"] = true
  765 + str := []string{}
  766 + if num1 > 0 {
  767 + str = append(str, fmt.Sprintf("您负责的任务%d个任务", num1))
  768 + }
  769 + if num2 > 0 {
  770 + str = append(str, fmt.Sprintf("下级负责的%d个任务", num2))
  771 + }
  772 + if num3 > 0 {
  773 + str = append(str, fmt.Sprintf("与您有关的%d个任务发生异常", num3))
  774 + }
  775 + resp["list"] = []adapter.MessageListAdapter{{Content: strings.Join(str, "、") + ",请前往处理。"}}
627 } 776 }
628 return resp, nil 777 return resp, nil
629 } 778 }
@@ -750,38 +750,21 @@ func (d *TaskDao) CountTaskIgnore(param ListTaskCondition) (int, error) { @@ -750,38 +750,21 @@ func (d *TaskDao) CountTaskIgnore(param ListTaskCondition) (int, error) {
750 } 750 }
751 751
752 type TaskData6 struct { 752 type TaskData6 struct {
753 - TaskId int `pg:"task_id"`  
754 - TaskName string `pg:"task_name"`  
755 - TaskAlias string `pg:"task_alias"`  
756 - LeaderName string `pg:"leader_name"`  
757 - LeaderId string `pg:"leader_id"`  
758 - WarnFlag int `pg:"warn_flag"`  
759 - AssistFlag int `pg:"assist_flag"`  
760 - Anomaly int `pg:"anomaly"` 753 + TaskId int `pg:"task_id"` //任务id
  754 + TaskName string `pg:"task_name"` //任务名称
  755 + TaskAlias string `pg:"task_alias"` //任务名称
  756 + LeaderName string `pg:"leader_name"` //负责人名称
  757 + LeaderId string `pg:"leader_id"` //负责人id
  758 + WarnFlag int `pg:"warn_flag"` //里程碑异常
  759 + AssistFlag int `pg:"assist_flag"` //辅导异常
  760 + Anomaly int `pg:"anomaly"` //反馈异常
  761 + RelatedUser []int `pg:"related_user"` //相关人员
761 } 762 }
762 763
763 -func (d *TaskDao) TaskIsAnomalyByLeader(leaderId []string) ([]TaskData6, error) {  
764 - sqlStr := `select  
765 - task.id as task_id,  
766 - task."name" as task_name ,  
767 - task.alias as task_alias,  
768 - task.leader ->>'id' as leader_id,  
769 - task.leader ->>'name' as leader_name,  
770 - task.assist_flag ,  
771 - task.warn_flag ,  
772 - task.anomaly  
773 -from task where 1=1  
774 -and task.deleted_at isnull  
775 -and (task.assist_flag+task.warn_flag +task.anomaly)>0  
776 -and task.leader ->>'id' in(?) `  
777 - result := []TaskData6{}  
778 - tx := d.transactionContext.PgTx  
779 - _, err := tx.Query(&result, sqlStr, pg.In(leaderId))  
780 - return result, err  
781 -}  
782 -  
783 -func (d *TaskDao) TaskIsAnomalyByRelatedUser(relatedUserId int) ([]TaskData6, error) {  
784 - sqlStr := `select 764 +// 查询每日任务异常消息弹窗需要的数据
  765 +func (d *TaskDao) TaskIsAnomalyForNotice(companyId int, leaderId []string, relatedUserId int) ([]TaskData6, error) {
  766 + sqlStr := `
  767 +select
785 task.id as task_id, 768 task.id as task_id,
786 task."name" as task_name , 769 task."name" as task_name ,
787 task.alias as task_alias, 770 task.alias as task_alias,
@@ -789,15 +772,44 @@ func (d *TaskDao) TaskIsAnomalyByRelatedUser(relatedUserId int) ([]TaskData6, er @@ -789,15 +772,44 @@ func (d *TaskDao) TaskIsAnomalyByRelatedUser(relatedUserId int) ([]TaskData6, er
789 task.leader ->>'name' as leader_name, 772 task.leader ->>'name' as leader_name,
790 task.assist_flag , 773 task.assist_flag ,
791 task.warn_flag , 774 task.warn_flag ,
792 - task.anomaly 775 + task.anomaly ,
  776 + task.related_user
793 from task where 1=1 777 from task where 1=1
794 and task.deleted_at isnull 778 and task.deleted_at isnull
  779 +and task.company_id=?
795 and (task.assist_flag+task.warn_flag +task.anomaly)>0 780 and (task.assist_flag+task.warn_flag +task.anomaly)>0
796 -and task.related_user @>? ` 781 +and (task.leader ->>'id' in(?) or task.related_user @>?)
  782 +`
797 783
798 relatedUser := fmt.Sprintf("[%d]", relatedUserId) 784 relatedUser := fmt.Sprintf("[%d]", relatedUserId)
  785 + condition := []interface{}{companyId, pg.In(leaderId), relatedUser}
799 result := []TaskData6{} 786 result := []TaskData6{}
800 tx := d.transactionContext.PgTx 787 tx := d.transactionContext.PgTx
801 - _, err := tx.Query(&result, sqlStr, relatedUser) 788 + _, err := tx.Query(&result, sqlStr, condition...)
802 return result, err 789 return result, err
803 } 790 }
  791 +
  792 +// 按照 任务的相关人员(related_user),排除 既是相关人员,又是任务负责人的情况, 获取出现异常的任务
  793 +// func (d *TaskDao) TaskIsAnomalyByRelatedUser(relatedUserId int) ([]TaskData6, error) {
  794 +// sqlStr := `select
  795 +// task.id as task_id,
  796 +// task."name" as task_name ,
  797 +// task.alias as task_alias,
  798 +// task.leader ->>'id' as leader_id,
  799 +// task.leader ->>'name' as leader_name,
  800 +// task.assist_flag ,
  801 +// task.warn_flag ,
  802 +// task.anomaly
  803 +// from task where 1=1
  804 +// and task.deleted_at isnull
  805 +// and (task.assist_flag+task.warn_flag +task.anomaly)>0
  806 +// and task.related_user @>?
  807 +// and task.leader ->>'id' <> ?
  808 +// `
  809 +// relatedUser := fmt.Sprintf("[%d]", relatedUserId)
  810 +// condition := []interface{}{relatedUser, strconv.Itoa(relatedUserId)}
  811 +// result := []TaskData6{}
  812 +// tx := d.transactionContext.PgTx
  813 +// _, err := tx.Query(&result, sqlStr, condition...)
  814 +// return result, err
  815 +// }
@@ -36,7 +36,8 @@ func (c *MessagePersonalController) TodayMessageTaskRecordAnomaly() { @@ -36,7 +36,8 @@ func (c *MessagePersonalController) TodayMessageTaskRecordAnomaly() {
36 userReq := middlewares.GetUser(c.Ctx) 36 userReq := middlewares.GetUser(c.Ctx)
37 param := command.GetUserMessageCommand{} 37 param := command.GetUserMessageCommand{}
38 param.UserId = int(userReq.UserId) 38 param.UserId = int(userReq.UserId)
39 - data, err := srv.TodayMessageTaskRecordAnomalyV2(&param) 39 + param.CompanyId = int(userReq.CompanyId)
  40 + data, err := srv.TodayMessageTaskAnomaly(&param)
40 c.Response(data, err) 41 c.Response(data, err)
41 } 42 }
42 43