Browse Source

保存接口

renjiaojiao 3 months ago
parent
commit
10dafad206
5 changed files with 90 additions and 8 deletions
  1. 3 1
      config.yaml
  2. 2 0
      config/db.go
  3. 38 4
      controller/kbController.go
  4. 2 3
      main.go
  5. 45 0
      service/kbService.go

+ 3 - 1
config.yaml

@@ -13,4 +13,6 @@ filePath: ./upload/
 wechatWorkUrl: https://qyapi.weixin.qq.com/cgi-bin/webhook/send
 wechatWorkUrl: https://qyapi.weixin.qq.com/cgi-bin/webhook/send
 wechatWorkKey: f195c32d-aed7-4070-8aa2-190eeebab00c
 wechatWorkKey: f195c32d-aed7-4070-8aa2-190eeebab00c
 wechatRemind:
 wechatRemind:
-  - 15038701380
+  - 15038701380
+workflowsUrl: https://dify.jydev.jianyu360.com/v1/workflows/run
+workflowsUser: abc-123

+ 2 - 0
config/db.go

@@ -22,6 +22,8 @@ type Config struct {
 	KbMySql       DatabaseConfig `yaml:"kbMySql"`
 	KbMySql       DatabaseConfig `yaml:"kbMySql"`
 	WechatWorkKey string         `yaml:"wechatWorkKey"`
 	WechatWorkKey string         `yaml:"wechatWorkKey"`
 	WechatRemind  []string       `yaml:"wechatRemind"`
 	WechatRemind  []string       `yaml:"wechatRemind"`
+	WorkflowsUrl  string         `yaml:"workflowsUrl"`
+	WorkflowsUser string         `yaml:"workflowsUser"`
 }
 }
 
 
 type DatabaseConfig struct {
 type DatabaseConfig struct {

+ 38 - 4
controller/kbController.go

@@ -92,7 +92,8 @@ func WorkTaskSave(r *gin.Context) {
 	err := json.Unmarshal([]byte(string(str)), &param)
 	err := json.Unmarshal([]byte(string(str)), &param)
 	if err != nil {
 	if err != nil {
 		r.JSON(http.StatusOK, gin.H{
 		r.JSON(http.StatusOK, gin.H{
-			"error": err.Error(),
+			"status": 0,
+			"error":  err.Error(),
 		})
 		})
 		return
 		return
 	}
 	}
@@ -101,7 +102,8 @@ func WorkTaskSave(r *gin.Context) {
 	kbUserId, err := service.CheckCreateUserAccount(name)
 	kbUserId, err := service.CheckCreateUserAccount(name)
 	if err != nil {
 	if err != nil {
 		r.JSON(http.StatusOK, gin.H{
 		r.JSON(http.StatusOK, gin.H{
-			"error": err.Error(),
+			"status": 0,
+			"error":  err.Error(),
 		})
 		})
 		return
 		return
 	}
 	}
@@ -120,7 +122,8 @@ func WorkTaskSave(r *gin.Context) {
 	err = task.WordTaskSave()
 	err = task.WordTaskSave()
 	if err != nil {
 	if err != nil {
 		r.JSON(http.StatusOK, gin.H{
 		r.JSON(http.StatusOK, gin.H{
-			"error": err.Error(),
+			"status": 0,
+			"error":  err.Error(),
 		})
 		})
 		return
 		return
 	}
 	}
@@ -128,11 +131,42 @@ func WorkTaskSave(r *gin.Context) {
 	err = service.SendWechatWorkMessage()
 	err = service.SendWechatWorkMessage()
 	if err != nil {
 	if err != nil {
 		r.JSON(http.StatusOK, gin.H{
 		r.JSON(http.StatusOK, gin.H{
-			"error": err.Error(),
+			"status": 0,
+			"error":  err.Error(),
 		})
 		})
 		return
 		return
 	}
 	}
 	r.JSON(http.StatusOK, gin.H{
 	r.JSON(http.StatusOK, gin.H{
+		"status":  1,
+		"error":   "",
 		"success": 1,
 		"success": 1,
 	})
 	})
 }
 }
+
+func GetTitle(r *gin.Context) {
+	str, _ := ioutil.ReadAll(r.Request.Body)
+	var param map[string]interface{}
+	err := json.Unmarshal([]byte(string(str)), &param)
+	if err != nil {
+		r.JSON(http.StatusOK, gin.H{
+			"status": 0,
+			"error":  err.Error(),
+		})
+		return
+	}
+	content := cm.ObjToString(param["content"])
+	toTitle, err := service.GetTitleByContent(content)
+	if err != nil {
+		r.JSON(http.StatusOK, gin.H{
+			"status": 0,
+			"error":  err.Error(),
+		})
+		return
+	}
+	r.JSON(http.StatusOK, gin.H{
+		"status": 1,
+		"error":  "",
+		"title":  toTitle,
+	})
+	return
+}

+ 2 - 3
main.go

@@ -32,9 +32,8 @@ func main() {
 	router.GET("/biBackService/resume/scanCode", controller.ScanCodeHandler)
 	router.GET("/biBackService/resume/scanCode", controller.ScanCodeHandler)
 	router.GET("/biBackService/resume/events", controller.EventsHandler)
 	router.GET("/biBackService/resume/events", controller.EventsHandler)
 	router.POST("/biBackService/kb/uploadFile", controller.UploadFile)
 	router.POST("/biBackService/kb/uploadFile", controller.UploadFile)
-	router.POST("/biBackService/kb/TaskSave", controller.WorkTaskSave)
-	// 后台管理页面的路由
-	//router.GET("/admin/search", adminSearchPageHandler)
+	router.POST("/biBackService/kb/taskSave", controller.WorkTaskSave)
+	router.POST("/biBackService/kb/getTitle", controller.GetTitle)
 
 
 	log.Println("服务器启动在", SysConfig.Port)
 	log.Println("服务器启动在", SysConfig.Port)
 	router.Run(SysConfig.Port)
 	router.Run(SysConfig.Port)

+ 45 - 0
service/kbService.go

@@ -2,6 +2,7 @@ package service
 
 
 import (
 import (
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/go-xweb/log"
 	. "biBackService/config"
 	. "biBackService/config"
 	"biBackService/public"
 	"biBackService/public"
 	"bytes"
 	"bytes"
@@ -12,6 +13,7 @@ import (
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
 	"os"
 	"os"
+	"strings"
 	"time"
 	"time"
 )
 )
 
 
@@ -138,3 +140,46 @@ func SendWechatWorkMessage() error {
 	}
 	}
 	return nil
 	return nil
 }
 }
+
+func GetTitleByContent(content string) (toTitle string, err error) {
+	reqUrl := SysConfig.WorkflowsUrl
+	method := "POST"
+	param := map[string]interface{}{
+		"inputs": map[string]interface{}{
+			"content": content,
+		},
+		"response_mode": "blocking",
+		"user":          SysConfig.WorkflowsUser,
+	}
+	jsonData, err := json.Marshal(param)
+	if err != nil {
+		return
+	}
+	payload := strings.NewReader(string(jsonData))
+
+	client := &http.Client{}
+	req, err := http.NewRequest(method, reqUrl, payload)
+	if err != nil {
+		return
+	}
+	req.Header.Add("Content-Type", "application/json")
+	req.Header.Add("Authorization", "Bearer app-w7OhSixqrVvZLa3wIEXNeoOh")
+	res, err := client.Do(req)
+	if err != nil {
+		return
+	}
+	defer res.Body.Close()
+
+	var result map[string]interface{}
+	if err = json.NewDecoder(res.Body).Decode(&result); err != nil {
+		return
+	}
+	log.Println("result", result)
+	if data, ok := result["data"].(map[string]interface{}); ok {
+		if outputs, oks := data["outputs"].(map[string]interface{}); oks {
+			toTitle = strings.Replace(common.ObjToString(outputs["title"]), "标题:", "", -1)
+		}
+	}
+	//toTitle = string(body)
+	return
+}