Browse Source

fix:oa待办

Roc 5 months ago
parent
commit
2a72f65d90
7 changed files with 210 additions and 2 deletions
  1. 1 0
      config/config.go
  2. 45 0
      controller/gn/oa.go
  3. BIN
      eta_bridge
  4. 13 0
      models/request/gn/oa.go
  5. 9 0
      routers/gn.go
  6. 2 2
      services/alarm_msg/alarm_msg.go
  7. 140 0
      services/gn/oa.go

+ 1 - 0
config/config.go

@@ -89,4 +89,5 @@ type Gn struct {
 	AuthUserApiUrl      string `mapstructure:"auth-user-api-url" json:"auth-user-api-url" yaml:"auth-user-api-url" description:"统一认证-获取UserInfo地址"`
 	DefaultRoleId       int    `mapstructure:"default-role-id" json:"default-role-id" yaml:"default-role-id" description:"默认的角色id"`
 	DefaultUserPass     string `mapstructure:"default-user-pass" json:"default-user-pass" yaml:"default-user-pass" description:"默认密码"`
+	OAHost              string `mapstructure:"oa-host" json:"oa-host" yaml:"oa-host" description:"oa服务地址"`
 }

+ 45 - 0
controller/gn/oa.go

@@ -0,0 +1,45 @@
+package gn
+
+import (
+	"eta_gn/eta_bridge/controller/resp"
+	"eta_gn/eta_bridge/global"
+	gnRequest "eta_gn/eta_bridge/models/request/gn"
+	"eta_gn/eta_bridge/services/gn"
+	"github.com/gin-gonic/gin"
+	"github.com/go-playground/validator/v10"
+)
+
+// OA
+// @Description: 发布OA待办
+// @author: Roc
+// @receiver gc
+// @datetime 2024-10-29 13:23:42
+// @param c *gin.Context
+func (gc *GuoNengController) OA(c *gin.Context) {
+	var req gnRequest.PostOAReq
+	if e := c.Bind(&req); e != nil {
+		err, ok := e.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+e.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
+		return
+	}
+
+	oaReq := gn.OASendDbReq{
+		AppPersonId:   req.AppPersonId,
+		AppPersonName: req.AppPersonName,
+		AppTaskUrl:    req.AppTaskUrl,
+		TaskName:      req.TaskName,
+		StatusName:    req.StatusName,
+		Status:        req.Status,
+	}
+	_, err := gn.OASendDb(oaReq)
+	if err != nil {
+		resp.FailData("请求失败", err.Error(), c)
+		return
+	}
+
+	resp.Ok("请求成功", c)
+}

BIN
eta_bridge


+ 13 - 0
models/request/gn/oa.go

@@ -0,0 +1,13 @@
+package gn
+
+// PostOAReq
+// @Description: 请求oa待办参数
+type PostOAReq struct {
+	AppPersonId   string `json:"appPersonId" form:"appPersonId" description:"⽤户⼯号"`
+	AppPersonName string `json:"appPersonName" form:"appPersonName" description:"⽤户名"`
+	AppTaskUrl    string `json:"appTaskUrl" form:"appTaskUrl" description:"待办地址,跳转地址"`
+	TaskName      string `json:"taskName" form:"taskName" description:"待办标题"`
+	StatusName    string `json:"statusName" form:"statusName" description:"待办节点名称"`
+	Status        int    `json:"status" form:"status" description:"待办状态:1-插⼊,2-更新,3-删除"`
+	AppTaskId     string `json:"appTaskId" form:"appTaskId" description:"待办任务ID:插⼊时不需要传参,由接⼝⽣成唯⼀ID并返回,需要业务系统保存此ID,⽤于后续的更新和删除操作"`
+}

+ 9 - 0
routers/gn.go

@@ -14,6 +14,9 @@ func InitGn(r *gin.RouterGroup) {
 
 	// 4A身份供应接口
 	init4A(r)
+
+	// OA接口
+	initOA(r)
 }
 
 func init4A(r *gin.RouterGroup) {
@@ -26,3 +29,9 @@ func init4A(r *gin.RouterGroup) {
 	group.POST("user/restoreAccount", control.RestoreAccount)
 	group.POST("user/ChangePassword", control.ChangePassword)
 }
+
+func initOA(r *gin.RouterGroup) {
+	control := new(gn.GuoNengController)
+	group := r.Group("gn/")
+	group.POST("oa", control.OA)
+}

+ 2 - 2
services/alarm_msg/alarm_msg.go

@@ -4,7 +4,6 @@ import (
 	"encoding/json"
 	"eta_gn/eta_bridge/global"
 	"eta_gn/eta_bridge/utils"
-	"github.com/rdlucklib/rdluck_tools/http"
 )
 
 var (
@@ -27,5 +26,6 @@ func SendAlarmMsg(msgBody string, level int) {
 		global.LOG.Critical("SendAlarmMsg json.Marshal Err:" + err.Error())
 		return
 	}
-	_, _ = http.Post(AlarmMsgUrl, string(param))
+	global.FILE_LOG.Info(string(param))
+	//_, _ = http.Post(AlarmMsgUrl, string(param))
 }

+ 140 - 0
services/gn/oa.go

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