123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package ice_message
- import (
- "bytes"
- "encoding/json"
- "errors"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/utils"
- "fmt"
- "io"
- "net/http"
- )
- // pushIceMessageLib 推送ICE消息
- func pushIceMessageLib(req *models.ReportIceMsgPushLibReq) (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")
- }
- // 参数校验
- req.PlatformId = utils.IceMsgPushPlatformId
- req.Type = 0 // 此处必须传入:2,如果为非待办则传0, 本次传输的是订阅号消息,故传0
- if req.Title == "" {
- return errors.New("title cannot be empty")
- }
- if req.Code == "" { //用户工号
- return errors.New("code cannot be empty")
- }
-
- if req.URL == "" {
- return errors.New("url cannot be empty")
- }
- if req.TaskId == "" {
- return errors.New("taskId cannot be empty")
- }
- if req.SystemId == "" {
- return errors.New("systemId cannot be empty")
- }
- // 准备请求数据
- jsonData, err := json.Marshal(req)
- if err != nil {
- return err
- }
- // 发送HTTP请求
- client := &http.Client{}
- request, err := http.NewRequest("POST", "https://coalaiinsight.ceic.com:8180/push", bytes.NewBuffer(jsonData))
- if err != nil {
- return err
- }
- request.Header.Set("Content-Type", "application/json")
- // 执行请求
- response, err := client.Do(request)
- if err != nil {
- return err
- }
- defer response.Body.Close()
- // 读取响应
- body, err := io.ReadAll(response.Body)
- if err != nil {
- return err
- }
- utils.FileLog.Info("pushIceMessageLib, req:", string(jsonData), "body:", string(body))
- // 解析响应
- var result models.IceMsgPushLibResp
- if err = json.Unmarshal(body, &result); err != nil {
- return err
- }
- // 检查响应状态
- if result.Code != 0 {
- return errors.New(result.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)
- }
- req := &models.ReportIceMsgPushLibReq{
- Title: title,
- Summary: summary,
- Content: content,
- Code: code,
- URL: url,
- TaskId: taskId,
- SystemId: taskId,
- }
-
- err = pushIceMessageLib(req)
- if err != nil {
- err = errors.New(fmt.Sprintf("推送失败,Err:%s", err.Error()))
- return err
- }
- return nil
- }
|