浏览代码

完善接口字段

xuzhiheng 4 年之前
父节点
当前提交
6324648d62
共有 3 个文件被更改,包括 34 次插入14 次删除
  1. 14 2
      api/v1/projects.go
  2. 10 3
      service/projects.go
  3. 10 9
      test/project/project_test.go

+ 14 - 2
api/v1/projects.go

@@ -16,6 +16,7 @@ func ProjectApiRegister(router *gin.Engine) {
 	{
 		routerGroup.POST("/projectList", getProjectsList)
 		routerGroup.POST("/projectDetail", getProjectDetail)
+		routerGroup.POST("/projectListDetail", getProjectsListDetail)
 	}
 }
 
@@ -28,7 +29,18 @@ func getProjectsList(c *gin.Context) {
 	data := &map[string]interface{}{}
 	if projectName != "" || winner != "" {
 		global.Logger.Info("666")
-		data = service.ProjectListData(projectName, winner, time)
+		data = service.ProjectListData(projectName, winner, time, false)
+	}
+	c.JSON(200, data)
+}
+
+//获取项目列表及详情接口
+func getProjectsListDetail(c *gin.Context) {
+	winner := c.PostForm("winner")
+	global.Logger.Info("winner " + winner)
+	data := &map[string]interface{}{}
+	if winner != "" {
+		data = service.ProjectListData("", winner, "", true)
 	}
 	c.JSON(200, data)
 }
@@ -36,7 +48,7 @@ func getProjectsList(c *gin.Context) {
 //获取项目详情
 func getProjectDetail(c *gin.Context) {
 	id := c.PostForm("id")
-	global.Logger.Info("id "+ id)
+	global.Logger.Info("id " + id)
 	data := map[string]interface{}{}
 	if id != "" {
 		data = service.ProjectDetailData(id)

+ 10 - 3
service/projects.go

@@ -12,7 +12,8 @@ import (
 
 var (
 	pjt_count    = 100
-	pjt_field    = `"_id","area","city","bidamount","firsttime","projectname","s_winner","buyer","buyerclass"`
+	pjt_field    = `"_id","jgtime","zbtime","projectname","buyer","buyerclass"`
+	pjt_fields   = `"_id","area","city","bidamount","budget","zbtime","jgtime","projectname","projectcode","s_winner","buyer","buyerclass","buyerperson","buyertel","sourceinfourl"`
 	pjt_sort     = `{"firsttime":-1}`
 	query        = `{"query": {"bool": {"must":[%s],"should":[%s],"minimum_should_match": 1}}}`
 	query_string = `{"constant_score": {"boost": 2,"query": {"match_phrase": {"projectname.pname": {"analyzer": "my_ngram","query": "%s","slop": 6}}}}},{"multi_match": {"query": "%s","fields": ["projectname.pname"],"analyzer": "ik","minimum_should_match": "100%%"}}`
@@ -22,7 +23,7 @@ var (
 	highlightStr = `%s: {"fragment_size": %d,"number_of_fragments": 1}`
 )
 
-func ProjectListData(projectName, winner, time string) (data *map[string]interface{}) {
+func ProjectListData(projectName, winner, time string, isDetail bool) (data *map[string]interface{}) {
 	global.Logger.Info("projectName " + projectName)
 	global.Logger.Info("winner " + winner)
 	global.Logger.Info("time " + time)
@@ -67,7 +68,13 @@ func ProjectListData(projectName, winner, time string) (data *map[string]interfa
 	Es := db.GetEs()
 	global.Logger.Info("INDEX " + INDEX)
 	global.Logger.Info("TYPE " + TYPE)
-	repl := GetAllByNgram(Es, INDEX, TYPE, qstr, "", pjt_sort, pjt_field, 0, pjt_count, 0, false)
+	fields := ""
+	if isDetail {
+		fields = pjt_fields
+	} else {
+		fields = pjt_field
+	}
+	repl := GetAllByNgram(Es, INDEX, TYPE, qstr, "", pjt_sort, fields, 0, pjt_count, 0, false)
 	if repl != nil && len(*repl) > 0 {
 		(*data)["data"] = repl
 	}

+ 10 - 9
test/project/project_test.go

@@ -11,6 +11,7 @@ import (
 
 var (
 	apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectList"
+	// apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectListDetail"
 )
 
 func Test_Project(t *testing.T) {
@@ -27,15 +28,15 @@ func getData() {
 }
 
 //获取项目详情测试用例
-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 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 := ""