|
@@ -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
|
} |