瀏覽代碼

接口整理提交

jiaojiao7 4 年之前
父節點
當前提交
9668caf2f4
共有 3 個文件被更改,包括 36 次插入21 次删除
  1. 18 5
      api/v1/projects.go
  2. 4 7
      service/projectDetail.go
  3. 14 9
      test/project/project_test.go

+ 18 - 5
api/v1/projects.go

@@ -78,11 +78,24 @@ func getProjectsListDetail(c *gin.Context) {
 
 //获取项目详情
 func getProjectDetail(c *gin.Context) {
-	id := c.PostForm("projectid")
-	global.Logger.Info("projectid " + id)
-	data := map[string]interface{}{}
+	productID := c.MustGet("productID").(int)
+	appID := c.MustGet("appID").(string)
+	requestIP := c.MustGet("requestIP").(string)
+	id := c.PostForm("project_id")
+	p := gin.H{
+		"id": id,
+	}
+	bs, _ := json.Marshal(p)
+	param := string(bs)
+	global.Logger.Info("api getProjectDetail:", zap.Any("productID:", productID), zap.Any("appID", appID), zap.Any("param:", param))
 	if id != "" {
-		data = service.ProjectDetailData(id)
+		utils.Check(appID, productID, c, func() ([]map[string]interface{}, int, error) {
+			return service.ProjectDetailData(id)
+		}, param, requestIP)
 	}
-	c.JSON(200, data)
+	/*data := map[string]interface{}{}
+	if id != "" {
+		data = service.ProjectDetailData(id)
+	}*/
+	c.JSON(200, nil)
 }

+ 4 - 7
service/projectDetail.go

@@ -3,22 +3,19 @@ package service
 import (
 	"fmt"
 	"sfbase/core"
-	"sfbase/global"
 	"sfis/db"
 )
 
-func ProjectDetailData(id string) map[string]interface{} {
-	global.Logger.Info("id " + id)
-	data := map[string]interface{}{}
+func ProjectDetailData(id string) (data []map[string]interface{}, httpStatus int, err error) {
+	httpStatus = 200
 	_query := `{"query":{"bool":{"must":[{"term":{"id":"%s"}}],"must_not":[],"should":[]}},"_source":[%s]}`
 	fields := `"s_winner","projectname","projectcode","buyer","buyertel","buyerperson","jgtime","zbtime","bidamount","budget","buyerclass","area","city","list"`
 	query := fmt.Sprintf(_query, id, fields)
-	global.Logger.Info("query " + query)
 	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]
+		data = *infos
 	}
-	return data
+	return data, httpStatus, nil
 }

+ 14 - 9
test/project/project_test.go

@@ -73,15 +73,20 @@ func getData() {
 }
 
 //获取项目详情测试用例
-// func Test_ProjectDetails(t *testing.T) {
-// 	data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
-// 		"projectid": "5f6b4e12499cb0822d39c68f",
-// 	})
-// 	res := map[string]interface{}{}
-// 	s, _ := json.Marshal(data)
-// 	json.Unmarshal(s, &res)
-// 	log.Println("数据:", res)
-// }
+func Test_ProjectDetails(t *testing.T) {
+	appID := "sfPQRYRQMAAwcGBwYBCgcA"
+	secretKey := "a8Iws4mE"
+	data := make(url.Values)
+	projectId := "5f6b4e12499cb0822d39c68f"
+	data["project_id"] = []string{projectId}
+	data["app_id"] = []string{appID}
+	now := time.Now().Unix()
+	bs, _ := utils.HttpPostForm("http://localhost:8080/sfis/api/v1/projectList", map[string]string{
+		"token":     utils.MD5(fmt.Sprintf("%s%d%s", appID, now, secretKey)),
+		"timestamp": fmt.Sprint(now),
+	}, data)
+	log.Print(string(bs))
+}
 
 func post(url string, form map[string]string) (data map[string]interface{}) {
 	str := ""