|
@@ -1,10 +1,12 @@
|
|
|
package services
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"errors"
|
|
|
"eta_gn/eta_task/models"
|
|
|
"eta_gn/eta_task/models/report"
|
|
|
"eta_gn/eta_task/services/alarm_msg"
|
|
|
+ "eta_gn/eta_task/services/eta_bridge"
|
|
|
"eta_gn/eta_task/utils"
|
|
|
"fmt"
|
|
|
"golang.org/x/net/context"
|
|
@@ -507,3 +509,325 @@ func getMinClassify(reportInfo *models.Report) (minClassifyId int, minClassifyNa
|
|
|
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// ReportWriteRemind 报告撰写提醒
|
|
|
+func ReportWriteRemind(cont context.Context) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tips := fmt.Sprintf("ReportWriteRemind-报告撰写提醒失败, ErrMsg: %v", err)
|
|
|
+ fmt.Println(tips)
|
|
|
+ utils.FileLog.Info(tips)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ timeNow := time.Now()
|
|
|
+ timeClock := timeNow.Format("15:04")
|
|
|
+
|
|
|
+ // 查询需要提醒的分类
|
|
|
+ classifies := make([]*models.Classify, 0)
|
|
|
+ {
|
|
|
+ ob := new(models.Classify)
|
|
|
+ cond := ` AND is_remind = ? AND remind_time = ?`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, 1, timeClock)
|
|
|
+ list, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取分类失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ classifies = list
|
|
|
+ }
|
|
|
+ if len(classifies) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var reportClassifyIds, pptClassifyIds []int
|
|
|
+ classifyMatch := make(map[string]bool)
|
|
|
+ for _, v := range classifies {
|
|
|
+ if v.ClassifyType == utils.ReportTypeDefault {
|
|
|
+ // levelPath作为下面报告的匹配
|
|
|
+ var levelIds []int
|
|
|
+ var firstId, secondId, thirdId int
|
|
|
+ levelArr := strings.Split(v.LevelPath, ",")
|
|
|
+ for _, l := range levelArr {
|
|
|
+ id, _ := strconv.Atoi(l)
|
|
|
+ levelIds = append(levelIds, id)
|
|
|
+ }
|
|
|
+ if len(levelIds) > 2 {
|
|
|
+ firstId = levelIds[0]
|
|
|
+ secondId = levelIds[1]
|
|
|
+ thirdId = levelIds[2]
|
|
|
+ }
|
|
|
+ if len(levelIds) > 1 {
|
|
|
+ firstId = levelIds[0]
|
|
|
+ secondId = levelIds[1]
|
|
|
+ }
|
|
|
+ if len(levelIds) > 0 {
|
|
|
+ firstId = levelIds[0]
|
|
|
+ }
|
|
|
+ classifyMatch[fmt.Sprintf("%d-%d-%d", firstId, secondId, thirdId)] = true
|
|
|
+ reportClassifyIds = append(reportClassifyIds, v.Id)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if v.ClassifyType == utils.ReportTypePPT {
|
|
|
+ pptClassifyIds = append(pptClassifyIds, v.Id)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询需要提醒的报告
|
|
|
+ remindReports := make([]*models.Report, 0)
|
|
|
+ if len(reportClassifyIds) > 0 {
|
|
|
+ ob := new(models.Report)
|
|
|
+ cond := ` AND report_source = ? AND state = ? AND topic_end_time >= ?`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, utils.ReportSourceOuter, models.ReportStateWaitSubmit, timeNow)
|
|
|
+ list, e := ob.GetItemsByCondition(cond, pars, []string{"id", "title", "admin_id", "classify_id_first", "classify_id_second", "classify_id_third"}, "")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取待提醒报告失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ k := fmt.Sprintf("%d-%d-%d", v.ClassifyIdFirst, v.ClassifyIdSecond, v.ClassifyIdThird)
|
|
|
+ if !classifyMatch[k] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ remindReports = append(remindReports, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询需要提醒的PPT
|
|
|
+ remindPpts := make([]*models.PptV2, 0)
|
|
|
+ if len(pptClassifyIds) > 0 {
|
|
|
+ ob := new(models.PptV2)
|
|
|
+ cond := ` AND report_source = ? AND state = ? AND topic_end_time >= ? AND classify_id IN (?)`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, utils.ReportSourceOuter, models.ReportStateWaitSubmit, timeNow, pptClassifyIds)
|
|
|
+ list, e := ob.GetItemsByCondition(cond, pars, models.PptReportQueryFields, "")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取待提醒报告失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ remindPpts = list
|
|
|
+ }
|
|
|
+ if len(remindReports) == 0 && len(remindPpts) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ reportMessages := make([]*models.ReportMessage, 0)
|
|
|
+ // 报告提醒
|
|
|
+ if len(remindReports) > 0 {
|
|
|
+ var remindReportIds []int
|
|
|
+ for _, v := range remindReports {
|
|
|
+ remindReportIds = append(remindReportIds, v.Id)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取协作人
|
|
|
+ grantOb := new(models.ReportGrant)
|
|
|
+ grantCond := ` AND report_id IN (?)`
|
|
|
+ grantPars := make([]interface{}, 0)
|
|
|
+ grantPars = append(grantPars, remindReportIds)
|
|
|
+ grants, e := grantOb.GetItemsByCondition(grantCond, grantPars, []string{}, "")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取报告协作人失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportGrants := make(map[int][]int)
|
|
|
+ for _, v := range grants {
|
|
|
+ reportGrants[v.ReportId] = append(reportGrants[v.ReportId], v.GrantId)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 推送消息
|
|
|
+ for _, v := range remindReports {
|
|
|
+ var userIds []int
|
|
|
+ userIds = append(userIds, v.AdminId)
|
|
|
+ for _, p := range reportGrants[v.Id] {
|
|
|
+ if !utils.InArrayByInt(userIds, p) {
|
|
|
+ userIds = append(userIds, p)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, u := range userIds {
|
|
|
+ m := new(models.ReportMessage)
|
|
|
+ m.SendUserId = 0
|
|
|
+ m.ReceiveUserId = u
|
|
|
+ m.Content = fmt.Sprintf("您有一篇【%s】待编辑,请点击查看", v.Title)
|
|
|
+ m.ReportType = utils.ReportTypeDefault
|
|
|
+ m.ReportId = v.Id
|
|
|
+ m.MessageType = models.ReportMessageTypeWriteNotice
|
|
|
+ m.CreateTime = time.Now()
|
|
|
+ m.ModifyTime = time.Now()
|
|
|
+ reportMessages = append(reportMessages, m)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // PPT提醒
|
|
|
+ if len(remindPpts) > 0 {
|
|
|
+ for _, v := range remindPpts {
|
|
|
+ // 收信人
|
|
|
+ var userIds []int
|
|
|
+ userIds = append(userIds, v.AdminId)
|
|
|
+ partnerArr := strings.Split(v.CollaborateUsers, ",")
|
|
|
+ for _, p := range partnerArr {
|
|
|
+ id, _ := strconv.Atoi(p)
|
|
|
+ if id <= 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if !utils.InArrayByInt(userIds, id) {
|
|
|
+ userIds = append(userIds, id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, u := range userIds {
|
|
|
+ m := new(models.ReportMessage)
|
|
|
+ m.SendUserId = 0
|
|
|
+ m.ReceiveUserId = u
|
|
|
+ m.Content = fmt.Sprintf("您有一篇【%s】待编辑,请点击查看", v.Title)
|
|
|
+ m.ReportType = utils.ReportTypePPT
|
|
|
+ m.ReportId = v.PptId
|
|
|
+ m.MessageType = models.ReportMessageTypeWriteNotice
|
|
|
+ m.CreateTime = time.Now()
|
|
|
+ m.ModifyTime = time.Now()
|
|
|
+ reportMessages = append(reportMessages, m)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(reportMessages) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ messageOb := new(models.ReportMessage)
|
|
|
+ if e := messageOb.CreateMulti(reportMessages); e != nil {
|
|
|
+ err = fmt.Errorf("新增报告提醒失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // OA消息
|
|
|
+ go func() {
|
|
|
+ _ = SendOaReportMessage(reportMessages)
|
|
|
+ }()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// SendOaReportMessage 推送OA报告消息
|
|
|
+func SendOaReportMessage(reportMessages []*models.ReportMessage) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tips := fmt.Sprintf("SendOaReportMessage-报告OA消息推送失败, ErrMsg: %v", err)
|
|
|
+ fmt.Println(tips)
|
|
|
+ utils.FileLog.Info(tips)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ // 未开启则不管
|
|
|
+ conf, e := models.GetBusinessConfByKey(models.BusinessOpenOaMsg)
|
|
|
+ if e != nil {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("获取OA消息开关失败, %v", e))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var sendOa bool
|
|
|
+ if conf != nil && conf.ConfVal == "true" {
|
|
|
+ sendOa = true
|
|
|
+ }
|
|
|
+ if !sendOa {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ hostConf, e := models.GetBusinessConfByKey(models.BusinessOaReportHost)
|
|
|
+ if e != nil {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("获取OA消息跳转Host失败, %v", e))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var hostUrl string
|
|
|
+ if hostConf != nil {
|
|
|
+ hostUrl = hostConf.ConfVal
|
|
|
+ }
|
|
|
+ if hostUrl == "" {
|
|
|
+ utils.FileLog.Info("OA消息跳转Host未配置")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportUrl := fmt.Sprintf("%s/reportNew", hostUrl)
|
|
|
+ pptUrl := fmt.Sprintf("%s/pptlist", hostUrl)
|
|
|
+
|
|
|
+ // 查询用户,匹配工号
|
|
|
+ adminIdOut := make(map[int]*models.Admin)
|
|
|
+ {
|
|
|
+ adminOb := new(models.Admin)
|
|
|
+ admins, e := adminOb.GetItemsByCondition(``, make([]interface{}, 0), []string{"admin_id", "real_name", "out_id"}, "")
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取员工列表失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range admins {
|
|
|
+ adminIdOut[v.AdminId] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 推送OA
|
|
|
+ oaMessages := make([]*models.OaReportMessage, 0)
|
|
|
+ for _, v := range reportMessages {
|
|
|
+ // 接收用户
|
|
|
+ receiver := adminIdOut[v.ReceiveUserId]
|
|
|
+ if receiver == nil || (receiver != nil && receiver.AdminId <= 0) {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("SendOaReportMessage-OA推送用户异常, UserId: %d", v.ReceiveUserId))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ oaMessage := new(models.OaReportMessage)
|
|
|
+ oaMessage.ReceiveUserId = receiver.AdminId
|
|
|
+ oaMessage.ReportType = v.ReportType
|
|
|
+ oaMessage.ReportId = v.ReportId
|
|
|
+ oaMessage.Source = models.OaReportMessageSourceRemind
|
|
|
+ oaMessage.SendStatus = models.OaReportMessageStatusFail
|
|
|
+ oaMessage.CreateTime = time.Now()
|
|
|
+ oaMessage.ModifyTime = time.Now()
|
|
|
+
|
|
|
+ // OA请求参数
|
|
|
+ var params eta_bridge.PostOAReq
|
|
|
+ params.AppPersonId = receiver.OutId
|
|
|
+ params.AppPersonName = receiver.RealName
|
|
|
+ if v.ReportType == utils.ReportTypeDefault {
|
|
|
+ params.AppTaskUrl = reportUrl
|
|
|
+ }
|
|
|
+ if v.ReportType == utils.ReportTypePPT {
|
|
|
+ params.AppTaskUrl = pptUrl
|
|
|
+ }
|
|
|
+ params.TaskName = v.Content
|
|
|
+ params.StatusName = v.Content
|
|
|
+ params.Status = 1
|
|
|
+ b, e := json.Marshal(params)
|
|
|
+ if e != nil {
|
|
|
+ oaMessage.MessageResult = fmt.Sprintf("OA推送JSON格式化失败, %v", e)
|
|
|
+ oaMessages = append(oaMessages, oaMessage)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ oaMessage.MessageParams = string(b)
|
|
|
+
|
|
|
+ // OA请求
|
|
|
+ resByte, e, _ := eta_bridge.HttpEtaBridgePost(utils.SyncOaTodoPath, params)
|
|
|
+ if e != nil {
|
|
|
+ oaMessage.MessageResult = fmt.Sprintf("OA推送POST请求失败, %v", e)
|
|
|
+ oaMessages = append(oaMessages, oaMessage)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ oaMessage.MessageResult = string(resByte)
|
|
|
+ var sendRes eta_bridge.PostOAResp
|
|
|
+ if e = json.Unmarshal(resByte, &sendRes); e != nil {
|
|
|
+ oaMessages = append(oaMessages, oaMessage)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if sendRes.Code != 200 {
|
|
|
+ oaMessages = append(oaMessages, oaMessage)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ oaMessage.TaskId = sendRes.Data
|
|
|
+ oaMessage.SendStatus = models.OaReportMessageStatusSuccess
|
|
|
+ oaMessages = append(oaMessages, oaMessage)
|
|
|
+ }
|
|
|
+ if len(oaMessages) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ oaMessageOb := new(models.OaReportMessage)
|
|
|
+ if e := oaMessageOb.CreateMulti(oaMessages); e != nil {
|
|
|
+ err = fmt.Errorf("新增OA待办记录失败, %v", e)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|