浏览代码

Merge branch 'feature/gn3.2_send_msg' into debug

xyxie 1 周之前
父节点
当前提交
25dc9fe4ff

+ 10 - 1
controllers/ppt_v2.go

@@ -571,11 +571,20 @@ func (this *PptV2Controller) DetailPpt() {
 		br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
 		return
 	}
+
+	// 查询是否展示发送消息按钮
+	canSendMsg := false
+	if pptInfo.ClassifyId != 0 {
+		classifyInfo, err := models.GetClassifyById(pptInfo.ClassifyId)
+		if err == nil && utils.InArrayByStr(utils.REPORT_ICE_MSG_CLASSIFY_NAMES, classifyInfo.ClassifyName) {
+			canSendMsg = true
+		}
+	}
 	resp := new(models.PPTDetailResp)
 	resp.PptV2Detail = pptInfo2
 	resp.Editor = editor
 	resp.HasAuth = hasAuth
-
+	resp.CanSendMsg = canSendMsg
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 111 - 6
controllers/report_ice_message.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"eta_gn/eta_api/models"
 	"eta_gn/eta_api/models/system"
+	"eta_gn/eta_api/services"
 	"eta_gn/eta_api/services/ice_message"
 	"eta_gn/eta_api/utils"
 	"fmt"
@@ -277,6 +278,8 @@ func (c *ReportIceMessageController) IceMsgPush() {
 	var title, summary, content string
 	var reportInfo *models.Report
 	var pptInfo *models.PptV2
+	var classifyName string
+	var url string
 	// 根据类型判断
 	if classifyType == 1 {// 推送研报
 		if req.ReportId <= 0 {
@@ -308,8 +311,7 @@ func (c *ReportIceMessageController) IceMsgPush() {
 			sendClassifyId = reportInfo.ClassifyIdFirst
 		}
 		title = reportInfo.Title
-		summary = reportInfo.Abstract
-		content = reportInfo.Title
+		url = reportInfo.DetailPdfUrl
 	} else if classifyType == 2 {// 推送PPT
 		if req.PptId <= 0 {
 			br.Msg = "PPTID不能为空"
@@ -327,10 +329,22 @@ func (c *ReportIceMessageController) IceMsgPush() {
 		}
 		sendClassifyId = pptInfo.ClassifyId
 		title = pptInfo.Title
-		summary = pptInfo.Abstract
-		content = pptInfo.Title
+		url = pptInfo.PptxUrl
 	}
-	//
+	// 获取分类名称
+	classify, err := models.GetClassifyById(sendClassifyId)
+	if err != nil {
+		if !utils.IsErrNoRow(err) {
+			br.Msg = "查询失败"
+			br.ErrMsg = "查询失败,Err:" + err.Error()
+			return
+		}else{
+			br.Msg = "分类不存在"
+			return
+		}
+	}
+	classifyName = classify.ClassifyName
+
 	// 判断该分类是否设置了消息推送配置
 	configObj := new(models.ReportMessageConfig)
 	config, err := configObj.GetItemByClassifyId(sendClassifyId)
@@ -375,7 +389,7 @@ func (c *ReportIceMessageController) IceMsgPush() {
 			// 生成taskId
 	        taskId := utils.MD5(fmt.Sprintf("%s_%s_%s_%s", req.ReportId, req.PptId, item.AdminId, time.Now().Format("20060102150405")))
 	
-			err = ice_message.PushIceMessage(title, summary, content, item.EmployeeId, taskId, req.ReportId, req.PptId)
+			err = ice_message.PushIceMessage(title, summary, content, item.EmployeeId, taskId, req.ReportId, req.PptId, url, classifyName)
 			if err != nil {
 				sendStatus = 2
 			}else{
@@ -437,4 +451,95 @@ func (c *ReportIceMessageController) IceMsgPush() {
 		br.ErrMsg = "推送失败,Err:" + err.Error()
 		br.Ret = 408
 	}
+}
+
+// ListClassify
+// @Title 获取分类列表
+// @Description 获取分类列表
+// @Param   KeyWord   query   string  true       "检索关键词"
+// @Param   ClassifyType   query   int  false       "分类类型:0-全部(默认);1-研报;2-PPT"
+// @Param   Enabled   query   int  false       "启用状态:-1-全部(默认);0-禁用;1-启用"
+// @Success 200 {object} models.Classify
+// @router /ice_msg/classify [get]
+func (c *ReportIceMessageController) ListClassify() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	classifyNames := make([]string, 0)
+	classifyNames = append(classifyNames, utils.REPORT_ICE_MSG_CLASSIFY_NAMES...)
+	
+
+	// 获取所有分类
+	originList, err := models.GetClassifyListByClassifyNameList(classifyNames)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	//查找所有的父级分类
+	parentIds := make([]int, 0)
+	for _, v := range originList {
+		// 解析levelpath
+		levelPath := strings.Split(v.LevelPath, ",")
+		for _, i := range levelPath {
+			if i != "" {
+				parentId, _ := strconv.Atoi(i)
+				parentIds = append(parentIds, parentId)
+			}
+		}
+	}
+	originList, err = models.GetClassifyListByParentIdList(parentIds)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	list := originList
+	classifyIds := make([]int, 0)
+	for _, v := range list {
+		classifyIds = append(classifyIds, v.Id)
+	}
+	// 指定分类类型(上级中的分类类型可能与最下层的不一致,但是要把上级也一起取出来, 这需求...=_=!)'
+	reportMsgConfigMap := make(map[int][]int)
+	// 根据分类ID获取配置项
+	reportMsgObj := new(models.ReportMessageConfig)
+	configList, err := reportMsgObj.GetListByClassifyIdList(classifyIds)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	
+	for _, v := range configList {
+		if v.NotifyUsers != "" {
+			notifyUsers := strings.Split(v.NotifyUsers, ",")
+			for _, user := range notifyUsers {
+				userInt, _ := strconv.Atoi(user)
+				reportMsgConfigMap[v.ClassifyId] = append(reportMsgConfigMap[v.ClassifyId], userInt)
+			}
+		}
+	}
+	for _, v := range list {
+		if iceMessageUsers, ok := reportMsgConfigMap[v.Id]; ok {
+			v.IceMsgUsers = iceMessageUsers
+		}
+	}
+
+
+	// 先将分类列表排序
+	services.SortClassifyListBySortAndCreateTime(list)
+	// 接着转换结构
+	list = services.GetClassifyListTreeRecursive(list, 0)
+	// 过滤掉没有子目录的分类
+	list = services.RecursiveFilterNoChildTreeClassify(list)
+
+	resp := new(models.ClassifyListResp)
+	resp.List = list
+	br.Data = resp
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
 }

+ 5 - 0
controllers/report_v2.go

@@ -336,6 +336,11 @@ func (this *ReportController) ListReport() {
 		} else {
 			item.Editor = markStatus.Editor
 		}
+
+		// 判断分类名称
+		if item.ClassifyIdThird != 0 && utils.InArrayByStr(utils.REPORT_ICE_MSG_CLASSIFY_NAMES, item.ClassifyNameThird) {
+			item.CanSendMsg = true
+		}
 	}
 
 	page := paging.GetPaging(currentIndex, pageSize, total)

+ 7 - 0
models/classify.go

@@ -199,6 +199,7 @@ type ClassifyList struct {
 	LevelPath             string          `gorm:"column:level_path" json:"level_path"` //`description:"分类的层级路径,英文逗号分隔"`
 	VisiableUsers         []int           `gorm:"-"`
 	IceMsgUsers           []int           `gorm:"-"`
+	NeedIceMsg            bool            `gorm:"-"`
 }
 
 type ClassifyItem struct {
@@ -412,6 +413,12 @@ func GetClassifyListByKeyword(keyWord string, enabled, classifyType int) (items
 	return
 }
 
+func GetClassifyListByClassifyNameList(classifyNameList []string) (items []*ClassifyList, err error) {
+	sql := `SELECT * FROM classify WHERE classify_name IN (` + utils.GetOrmInReplace(len(classifyNameList)) + `) ORDER BY sort ASC, create_time ASC`
+	err = global.DmSQL["rddp"].Raw(sql, classifyNameList).Find(&items).Error
+	return
+}
+
 // GetClassifyListByParentIdList
 // @Description: 获取分类列表
 // @author: Roc

+ 1 - 0
models/ppt_v2.go

@@ -330,6 +330,7 @@ type PPTDetailResp struct {
 	*PptV2Detail
 	Editor  PPTEditingCache `description:"编辑人信息"`
 	HasAuth bool            `description:"是否有权限"`
+	CanSendMsg bool          `description:"是否可以发送消息"`
 }
 
 // PPTEditingCache PPT编辑缓存信息

+ 2 - 1
models/report.go

@@ -158,6 +158,7 @@ type ReportList struct {
 	ClassifyNameThird   string            `gorm:"column:classify_name_third" description:"三级分类名称"`
 	InheritReportId     int               `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
 	ReportSource        int               `gorm:"column:report_source" description:"报告来源:1-系统内;2-智力共享"`
+	CanSendMsg       bool               `gorm:"-"`
 }
 
 type ReportListResp struct {
@@ -555,7 +556,7 @@ func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
 }
 
 func GetBaseReportInfoByReportId(reportId int) (item *Report, err error) {
-	sql := `SELECT id, title, report_code, abstract, author, frequency, classify_id_first, classify_id_second, classify_id_third, classify_name_first, classify_name_second, classify_name_third, state FROM report WHERE id = ?`
+	sql := `SELECT id, title, report_code, abstract, author, frequency, classify_id_first, classify_id_second, classify_id_third, classify_name_first, classify_name_second, classify_name_third, state, detail_pdf_url FROM report WHERE id = ?`
 	err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
 	return
 }

+ 9 - 0
routers/commentsRouter.go

@@ -8260,6 +8260,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers:ReportIceMessageController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers:ReportIceMessageController"],
+        beego.ControllerComments{
+            Method: "ListClassify",
+            Router: `/ice_msg/classify`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta_gn/eta_api/controllers:ReportIceMessageController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers:ReportIceMessageController"],
         beego.ControllerComments{
             Method: "IceMsgConfig",

+ 1 - 23
services/classify.go

@@ -302,8 +302,6 @@ func AddReportClassify(classifyName string, parentId int, classifyType, isRemind
 			// 	errMsg = "添加分类可见权限失败"
 			// 	return
 			// }
-			// 继承父级分类的推送消息配置
-			inheritReportClassifyMsgConfig(parentId, classify.Id)
 		}
 	}
 
@@ -869,24 +867,4 @@ func GetClassifyChildIdsTreeRecursive(list []*models.Classify, parentId int) []i
 		}
 	}
 	return res
-}
-
-// 继承父级分类的推送消息配置
-func inheritReportClassifyMsgConfig(parentClassifyId, currClassifyId int) (err error) {
-	// 获取父级分类的推送消息配置
-	configObj := new(models.ReportMessageConfig)
-	parentClassifyMsgConfig, err := configObj.GetItemByClassifyId(parentClassifyId)
-	if err == nil && parentClassifyMsgConfig != nil && parentClassifyMsgConfig.ConfigId > 0 {
-		// 变更为当前分类的推送消息配置
-		parentClassifyMsgConfig.ClassifyId = currClassifyId
-		parentClassifyMsgConfig.ModifyTime = time.Now().Local()
-		err = parentClassifyMsgConfig.Update([]string{"ClassifyId", "ModifyTime"})
-		if err != nil {
-			return
-		}
-	}else {
-		err = nil
-	}
-
-	return
-}
+}

+ 39 - 12
services/ice_message/ice_message_lib.go

@@ -13,18 +13,21 @@ import (
 
 // pushIceMessageLib 推送ICE消息
 func pushIceMessageLib(req *models.ReportIceMsgPushLibReq) (err error) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Error("pushIceMessageLib, err:", err.Error())
+		}
+	}()
 	if req == nil {
 		return errors.New("request cannot be nil")
 	}
 	if utils.IceMsgPushUrl == "" {
 		return errors.New("iceMsgPushUrl cannot be empty")
 	}
-	if utils.IceMsgPushPlatformId == "" {
-		return errors.New("iceMsgPushPlatformId cannot be empty")
-	}
-
+    if req.PlatformId == "" {
+        return errors.New("platformId cannot be empty")
+    }
 	// 参数校验
-	req.PlatformId = utils.IceMsgPushPlatformId
 	req.Type = 0  // 此处必须传入:2,如果为非待办则传0, 本次传输的是订阅号消息,故传0
 	if req.Title == "" {
 		return errors.New("title cannot be empty")
@@ -51,7 +54,7 @@ func pushIceMessageLib(req *models.ReportIceMsgPushLibReq) (err error) {
 
 	// 发送HTTP请求
 	client := &http.Client{}
-	request, err := http.NewRequest("POST", "https://coalaiinsight.ceic.com:8180/push", bytes.NewBuffer(jsonData))
+	request, err := http.NewRequest("POST", utils.IceMsgPushUrl, bytes.NewBuffer(jsonData))
 	if err != nil {
 		return err
 	}
@@ -81,18 +84,21 @@ func pushIceMessageLib(req *models.ReportIceMsgPushLibReq) (err error) {
 	if result.Code != 0 {
 		return errors.New(result.Msg)
 	}
+	if result.Info.Ret != "0" {
+		return errors.New(result.Info.Msg)
+	}
 
 	return nil
 }
 
-func PushIceMessage(title, summary, content, code, taskId string, reportId, pptId int) (err error) {
-	var url string
-	if reportId > 0 {
-		url = fmt.Sprintf("%s/report/report_detail?reportId=%s", utils.IceMsgPushUrl, reportId)
-	} else if pptId > 0 {
-		url = fmt.Sprintf("%s/report/ppt_detail?pptId=%s", utils.IceMsgPushUrl, pptId)
+func PushIceMessage(title, summary, content, code, taskId string, reportId, pptId int, url string, classifyName string) (err error) {
+	if url == "" {
+		err = errors.New("url cannot be empty")
+		return 
 	}
+	platformId := GetIcePlatformIdByClassifyName(classifyName)
 	req := &models.ReportIceMsgPushLibReq{
+		PlatformId: platformId,
 		Title: title,
 		Summary: summary,
 		Content: content,
@@ -109,4 +115,25 @@ func PushIceMessage(title, summary, content, code, taskId string, reportId, pptI
 	}
 	return nil
 }
+//生产platform_id:
+//煤炭市场日报:e3Rz
+//煤炭市场快讯:e3Ry
+//煤炭市场周报(简报):e3R9
+//煤炭市场周报:e3R8
+//煤炭市场月报:e3t1
+func GetIcePlatformIdByClassifyName(classifyName string) (string) {
+	switch classifyName {
+	case "煤炭市场日报":
+		return "e3Rz"
+	case "煤炭市场快讯":
+		return "e3Ry"
+	case "煤炭市场周报(简报)":
+		return "e3R9"
+	case "煤炭市场周报":
+		return "e3R8"
+	case "煤炭市场月报":
+		return "e3t1"
+	}
+	return ""
+}
 

+ 0 - 2
utils/config.go

@@ -275,7 +275,6 @@ var (
 // ice订阅号推送地址
 var (
 	IceMsgPushUrl string
-	IceMsgPushPlatformId string
 )
 
 func init() {
@@ -621,5 +620,4 @@ func init() {
 
 	// ice订阅号推送地址
 	IceMsgPushUrl = config["ice_msg_push_url"]
-	IceMsgPushPlatformId = config["ice_msg_push_platform_id"]
 }

+ 8 - 0
utils/constants.go

@@ -503,3 +503,11 @@ const (
 )
 
 const ReportPptEditingWait = 30 // 报告/PPT编辑退出后其他人的等待时长(单位:s)
+
+var REPORT_ICE_MSG_CLASSIFY_NAMES = []string{
+	"煤炭市场日报",
+	"煤炭市场快讯",
+	"煤炭市场周报(简报)",
+	"煤炭市场周报",
+	"煤炭市场月报",
+}