|
@@ -0,0 +1,140 @@
|
|
|
+package gn
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
+ "eta_gn/eta_bridge/global"
|
|
|
+ "eta_gn/eta_bridge/services/alarm_msg"
|
|
|
+ "fmt"
|
|
|
+ "io"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+// OABaseDataResp
|
|
|
+// @Description: 基础返回
|
|
|
+type OABaseDataResp struct {
|
|
|
+ Code int `json:"code"`
|
|
|
+ Msg string `json:"msg"`
|
|
|
+}
|
|
|
+
|
|
|
+// OASendDbResp
|
|
|
+// @Description: 指标列表请求返回结构体
|
|
|
+type OASendDbResp struct {
|
|
|
+ OABaseDataResp
|
|
|
+ Data struct {
|
|
|
+ Result bool `json:"result"`
|
|
|
+ TaskId string `json:"taskId"`
|
|
|
+ } `json:"data"`
|
|
|
+}
|
|
|
+
|
|
|
+// OASendDbReq
|
|
|
+// @Description: oa审批请求参数
|
|
|
+type OASendDbReq struct {
|
|
|
+ AppPersonId string `json:"appPersonId"`
|
|
|
+ AppPersonName string `json:"appPersonName"`
|
|
|
+ AppTaskUrl string `json:"appTaskUrl"`
|
|
|
+ TaskName string `json:"taskName"`
|
|
|
+ StatusName string `json:"statusName"`
|
|
|
+ Status int `json:"status"`
|
|
|
+}
|
|
|
+
|
|
|
+// OASendDb
|
|
|
+// @Description: 获取指标列表
|
|
|
+// @param param
|
|
|
+// @return resp
|
|
|
+// @return err
|
|
|
+func OASendDb(param OASendDbReq) (resp OASendDbResp, err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg("更新SMM的token失败;ERR:"+err.Error(), 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ urlStr := global.CONFIG.Gn.OAHost + "/api/oa/sendDB"
|
|
|
+
|
|
|
+ // 请求
|
|
|
+ result, err := HttpPostOA(urlStr, param)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析响应结果
|
|
|
+ err = json.Unmarshal(result, &resp)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// HttpPostOA
|
|
|
+// @Description: post请求
|
|
|
+// @param urlPath
|
|
|
+// @param token
|
|
|
+// @param postDataParams
|
|
|
+// @return []byte
|
|
|
+// @return error
|
|
|
+func HttpPostOA(urlPath string, postDataParams interface{}) ([]byte, error) {
|
|
|
+ if global.CONFIG.Gn.OAHost == `` {
|
|
|
+ return nil, errors.New("OA平台地址为空")
|
|
|
+ }
|
|
|
+ // 请求地址
|
|
|
+ postUrl := global.CONFIG.Gn.DataHost + urlPath
|
|
|
+
|
|
|
+ var err error
|
|
|
+
|
|
|
+ postDataByte, e := json.Marshal(postDataParams)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("data json marshal err: %s", e.Error())
|
|
|
+ return []byte{}, err
|
|
|
+ }
|
|
|
+ postData := string(postDataByte)
|
|
|
+
|
|
|
+ body := io.NopCloser(strings.NewReader(postData))
|
|
|
+ client := &http.Client{}
|
|
|
+ req, err := http.NewRequest("POST", postUrl, body)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ req.Header.Set("content-Type", "application/json; charset=utf-8")
|
|
|
+ req.Header.Set("Accept-Encoding", "application/json; charset=utf-8")
|
|
|
+ req.Header.Set("Accept", "application/json; charset=utf-8")
|
|
|
+
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ _ = resp.Body.Close()
|
|
|
+ }()
|
|
|
+ result, err := io.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 日志记录
|
|
|
+ global.FILE_LOG.Debug("OA审批:地址:" + postUrl + ";\n请求参数:" + postData + ";\n返回参数:" + string(result))
|
|
|
+
|
|
|
+ // 解析返回参数,判断是否是json
|
|
|
+ if !json.Valid(result) {
|
|
|
+ err = errors.New("返回参数不是json格式")
|
|
|
+ return []byte{}, err
|
|
|
+ }
|
|
|
+
|
|
|
+ var baseResp OASendDbResp
|
|
|
+ // 解析响应结果
|
|
|
+ err = json.Unmarshal(result, &baseResp)
|
|
|
+ if err != nil {
|
|
|
+ return []byte{}, err
|
|
|
+ }
|
|
|
+
|
|
|
+ if baseResp.Code != 200 {
|
|
|
+ err = errors.New(fmt.Sprintf("响应代码:%d,错误信息:%s", baseResp.Code, baseResp.Msg))
|
|
|
+ global.LOG.Info(fmt.Sprint("post data err:", baseResp.Msg, ";url:", postUrl, ";response:", postData))
|
|
|
+
|
|
|
+ return []byte{}, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return result, err
|
|
|
+}
|