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

Merge branch 'master' of http://192.168.3.207:10080/group3/SwordFish_Interface_Service

xuzhiheng 4 жил өмнө
parent
commit
da434b76d4

+ 3 - 2
api/v1/projects.go

@@ -35,8 +35,9 @@ func getProjectsList(c *gin.Context) {
 
 //获取项目详情
 func getProjectDetail(c *gin.Context) {
-	id := c.Query("id")
-	data := &map[string]interface{}{}
+	id := c.PostForm("id")
+	global.Logger.Info("id "+ id)
+	data := map[string]interface{}{}
 	if id != "" {
 		data = service.ProjectDetailData(id)
 	}

+ 13 - 2
service/projectDetail.go

@@ -1,11 +1,22 @@
 package service
 
 import (
+	"fmt"
+	"sfbase/core"
 	"sfbase/global"
+	"sfis/db"
 )
 
-func ProjectDetailData(id string) *map[string]interface{} {
+func ProjectDetailData(id string) map[string]interface{} {
 	global.Logger.Info("id " + id)
-	data := &map[string]interface{}{}
+	data := map[string]interface{}{}
+	_query := `{"query":{"bool":{"must":[{"term":{"id":"%s"}}],"must_not":[],"should":[]}}}`
+	query := fmt.Sprintf(_query, id)
+	INDEX := core.GetStringConf("es.project.index")
+	TYPE := core.GetStringConf("es.project.itype")
+	infos := db.Es.Get(INDEX, TYPE, query)
+	if infos != nil && len(*infos) > 0 {
+		data = (*infos)[0]
+	}
 	return data
 }

+ 11 - 0
test/project/project_test.go

@@ -26,6 +26,17 @@ func getData() {
 	log.Println(data)
 }
 
+//获取项目详情测试用例
+func Test_ProjectDetails(t *testing.T) {
+	data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
+		"id": "5f6b4e12499cb0822d39c68f",
+	})
+	res := map[string]interface{}{}
+	s, _ := json.Marshal(data)
+	json.Unmarshal(s, &res)
+	log.Println("数据:", res)
+}
+
 func post(url string, form map[string]string) (data map[string]interface{}) {
 	str := ""
 	for k, v := range form {