Эх сурвалжийг харах

wip:年终报告pdf增加职位id

wangkaiyue 2 жил өмнө
parent
commit
dd7fb60469

+ 45 - 27
core/proxy/broker/outServer/SussBi.go

@@ -1,18 +1,18 @@
 package outServer
 
 import (
+	"bp.jydev.jianyu360.cn/BaseService/gateway/core/router"
 	"bytes"
 	"fmt"
+	"github.com/gogf/gf/v2/net/ghttp"
+	"github.com/gogf/gf/v2/util/gconv"
+	"golang.org/x/net/publicsuffix"
 	"io"
 	"io/ioutil"
 	"net/http"
 	"net/http/cookiejar"
 	"net/url"
-
-	"bp.jydev.jianyu360.cn/BaseService/gateway/core/router"
-	"github.com/gogf/gf/v2/net/ghttp"
-	"github.com/gogf/gf/v2/util/gconv"
-	"golang.org/x/net/publicsuffix"
+	"strings"
 )
 
 type sussBi struct {
@@ -70,30 +70,48 @@ func (s *sussBi) CheckLoginOut(r *ghttp.Request) bool {
 
 func (s *sussBi) Filter(r *ghttp.Request) error {
 	ctx := router.GetGContext(r.GetCtx())
-	if ctx.Sess.NewUid != 0 && r.Request.Method == http.MethodPost {
-		bodyBytes, err := io.ReadAll(r.Request.Body)
-		if err != nil {
-			return err
-		}
-		if len(bodyBytes) > 0 {
-			replaceMap := map[string]interface{}{
-				"jyUserPositionId": ctx.Sess.UserPositionId,
-				"jyUserAccountId":  ctx.Sess.UserAccountId,
-				"jyEntPositionId":  ctx.Sess.EntPositionId,
-				"jyEntAccountId":   ctx.Sess.EntAccountId,
-				"jyUserName":       ctx.Sess.UserName,
-				"jyEntName":        ctx.Sess.EntName,
-				"jyEntId":          ctx.Sess.EntId,
+	if ctx.Sess.NewUid != 0 {
+		if r.Request.Method == http.MethodPost {
+			bodyBytes, err := io.ReadAll(r.Request.Body)
+			if err != nil {
+				return err
+			}
+			if len(bodyBytes) > 0 {
+				replaceMap := map[string]interface{}{
+					"jyUserPositionId": ctx.Sess.UserPositionId,
+					"jyUserAccountId":  ctx.Sess.UserAccountId,
+					"jyEntPositionId":  ctx.Sess.EntPositionId,
+					"jyEntAccountId":   ctx.Sess.EntAccountId,
+					"jyUserName":       ctx.Sess.UserName,
+					"jyEntName":        ctx.Sess.EntName,
+					"jyEntId":          ctx.Sess.EntId,
+				}
+				finalBytes := bytes.ReplaceAll(bodyBytes, []byte(`"jyUserId"`), []byte(fmt.Sprintf(`"%d"`, ctx.Sess.NewUid)))
+				for k, v := range replaceMap {
+					finalBytes = bytes.ReplaceAll(finalBytes, []byte(`"`+k+`"`), []byte(`"`+fmt.Sprint(v)+`"`))
+				}
+				r.ContentLength = gconv.Int64(len(finalBytes))
+				r.Request.Header.Set("Content-Length", fmt.Sprintf("%d", len(finalBytes)))
+				//fmt.Printf("before len:%d value:%s\nafter: len:%d value:%s\n", len(bodyBytes), string(bodyBytes), len(finalBytes), string(finalBytes))
+				//fmt.Printf("header %+v\n", r.Request.Header)
+				r.Request.Body = ioutil.NopCloser(bytes.NewReader(finalBytes))
 			}
-			finalBytes := bytes.ReplaceAll(bodyBytes, []byte(`"jyUserId"`), []byte(fmt.Sprintf(`"%d"`, ctx.Sess.NewUid)))
-			for k, v := range replaceMap {
-				finalBytes = bytes.ReplaceAll(finalBytes, []byte(`"`+k+`"`), []byte(`"`+fmt.Sprint(v)+`"`))
+		} else if r.Request.Method == http.MethodGet {
+			// 年终报告pdf增加职位id
+			if strings.HasPrefix(r.RequestURI, "/api/meta/services/convertFileToPDF") {
+				newValues, err := url.ParseQuery(r.URL.RawQuery)
+				fmt.Printf("%v err:%v\n", newValues, err)
+				if err == nil && len(newValues) > 0 {
+					fmt.Println("b")
+					if _, ok := newValues["QUERY_PARAM_M_POSITION_ID"]; ok {
+						newValues["QUERY_PARAM_M_POSITION_ID"] = []string{fmt.Sprintf("%d", ctx.Sess.UserPositionId)}
+					}
+					if _, ok := newValues["position_id"]; ok {
+						newValues["position_id"] = []string{fmt.Sprintf("%d", ctx.Sess.UserPositionId)}
+					}
+					r.URL.RawQuery = newValues.Encode()
+				}
 			}
-			r.ContentLength = gconv.Int64(len(finalBytes))
-			r.Request.Header.Set("Content-Length", fmt.Sprintf("%d", len(finalBytes)))
-			//fmt.Printf("before len:%d value:%s\nafter: len:%d value:%s\n", len(bodyBytes), string(bodyBytes), len(finalBytes), string(finalBytes))
-			//fmt.Printf("header %+v\n", r.Request.Header)
-			r.Request.Body = ioutil.NopCloser(bytes.NewReader(finalBytes))
 		}
 	}
 	return nil