master
wangshuai 5 years ago
parent 5dce50653a
commit 35224df1db

@ -40,7 +40,7 @@ func ReadDataaccess(c *gin.Context) {
Fail: false,
Message: message,
Total: count,
Data: data,
Datas: data,
})
return

@ -47,7 +47,7 @@ func ReadDataerror(c *gin.Context) {
Fail: false,
Message: message,
Total: count,
Data: data,
Datas: data,
})
return

@ -15,6 +15,7 @@ func Routers(r *gin.RouterGroup) {
rr.POST("/datasource/UpdateDatasource/:id", DatasourceOpenAPI.UpdateDatasource)
rr.POST("/datasource/DeleteDatasource/:id", DatasourceOpenAPI.DeleteDatasource)
rr.POST("/datasource/ReadESDoc", DatasourceOpenAPI.ReadESDoc)
rr.POST("/datasource/GetESDoc", DatasourceOpenAPI.GetESDoc)
return
}

@ -40,7 +40,7 @@ func ReadDatasource(c *gin.Context) {
Fail: false,
Message: message,
Total: count,
Data: data,
Datas: data,
})
return
@ -211,6 +211,52 @@ func ReadESDoc(c *gin.Context) {
success, message, esdata := DatasourceService.ReadESDoc(datasourceCode, orgIDs, page, begin, conditions, sort)
//fmt.Println("esdata=", esdata)
if success {
c.JSON(http.StatusOK, MySwagger.Result{
Success: true,
Fail: false,
Message: message,
Datas: esdata,
})
return
} else {
c.JSON(http.StatusOK, MySwagger.Result{
Success: false,
Fail: true,
Message: message,
})
return
}
return
}
// 获取es数据 godoc
// @Summary 获取es数据
// @Description 获取es数据
// @Tags datasource
// @ID getESDoc
// @Accept json
// @Produce json
// @Param input body MySwagger.DatasourceESSwag true "es数据"
// @Success 200 {object} MySwagger.Result
// @Failure 400 {object} MySwagger.Result
// @Router /v1/openapi/datasource/GetESDoc [post]
func GetESDoc(c *gin.Context) {
var raw MySwagger.DatasourceESSwag
if err := c.ShouldBindJSON(&raw); err != nil {
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "JSON格式错误"})
fmt.Println(err)
return
}
datasourceCode := raw.DatasourceCode
dataID := raw.DataId
success, message, esdata := DatasourceService.GetESDoc(datasourceCode, dataID)
if success {
c.JSON(http.StatusOK, MySwagger.Result{
Success: true,

@ -3,7 +3,6 @@ package DatasourceService
import (
"dsSupport/MyModel/AccessSystem/AccessSystemDao"
"dsSupport/MyModel/DataSource/DatasourceDAO"
"dsSupport/MyModel/JYT2012/Jyt2012Service"
"dsSupport/MyModel/MySwagger"
"dsSupport/MyModel/OrgTree/OrgtreeService"
"dsSupport/Utils/CacheUtil"
@ -92,9 +91,6 @@ func CreateDatasource(model models.TDataexDatasource) (bool, string, error) {
if e != nil {
return false, "SystemId不存在", nil
}
if !Jyt2012Service.IsJyt2012ExistsById(model.DicId) {
return false, "DicId不存在", nil
}
if !OrgtreeService.IsOrgtreeExistsById(model.ProvideOrgid) {
return false, "OrgId不存在", nil
}
@ -164,6 +160,24 @@ func RemoveDatasource(id string) (bool, string, error) {
return result, message, error
}
func GetESDoc(datasourceCode string, dataId string) (bool, string, map[string]interface{}) {
result, message, esdata := ES7Util.IndexDocGet(datasourceCode, dataId)
var query = "AND datasource_code='" + datasourceCode + "'"
res, _, data, _ := DatasourceDAO.GetDatasourceRow(query)
var datasourceName interface{}
if res == true {
datasourceName = data["datasource_name"]
}
m := make(map[string]interface{})
j, _ := json.Marshal(esdata)
json.Unmarshal(j, &m)
m["datasource_name"] = datasourceName
return result, message, m
}
func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, conditions map[string]interface{}, sort map[string]interface{}) (bool, string, []map[string]interface{}) {
result, message, esdata := ES7Util.SearchDocPage(datasourceCode, orgIDs, page, begin, conditions, sort)
var query = "AND datasource_code='" + datasourceCode + "'"

@ -26,7 +26,7 @@ func ReadESDocAmount(c *gin.Context) {
Fail: false,
Message: message,
Total: count,
Data: data,
Datas: data,
})
return

@ -49,7 +49,7 @@ func ReadJyt2012(c *gin.Context) {
Fail: false,
Message: message,
Total: count,
Data: data,
Datas: data,
})
return

@ -37,7 +37,7 @@ func ReadMetadata(c *gin.Context) {
Fail: false,
Message: message,
Total: count,
Data: data,
Datas: data,
})
return

@ -4,7 +4,8 @@ type DatasourceESSwag struct {
DatasourceCode string `json:"datasource_code" xorm:"not null comment('数据源编码') VARCHAR(8)" example:"org_tree"`
OrgIDs []string `json:"orgids" xorm:"not null comment('提供数据范围【1本机构2本机构以及下属机构-1不限制】') VARCHAR(36)" example:"[F38BD0DB-0142-4356-8F2B-623813FC2578,F38BD0DB-0142-4356-8F2B-623813FC2578]"`
BeginTime string `json:"begin_time" example:"2020-06-22 17:26:53"`
Conditions map[string]interface{} `json:"conditions" example:"[{res_id:12300,res_name:初一语文一单元作业,teacher_id:123001,time_spend:100s}]"`
Sort map[string]interface{} `json:"sort" example:"[{res_id:12300,res_name:初一语文一单元作业,teacher_id:123001,time_spend:100s}]"`
Conditions map[string]interface{} `json:"conditions" example:""`
Sort map[string]interface{} `json:"sort" example:""`
DataId string `json:"data_id" example:"CfBQnRJPyXMEI5nqLT0"`
Page int `json:"page" example:"1"`
}

@ -5,5 +5,6 @@ type Result struct {
Fail bool `json:"fail" example:"false"`
Message string `json:"message" example:"操作成功"`
Total int `json:"total" example:"120"`
Data []map[string]interface{} `json:"data" `
Data map[string]interface{} `json:"data" `
Datas []map[string]interface{} `json:"data" `
}

@ -35,7 +35,7 @@ func ReadOrgtree(c *gin.Context) {
Fail: false,
Message: message,
Total: count,
Data: data,
Datas: data,
})
return

@ -458,7 +458,6 @@ func IndexDocGet(indexName string,dataID string) (bool,string,DataEX.ESData) {
query.Filter(term).Filter(term2)
result,err:=ES7Client.Search().Index(indexName).Query(query).Do(CTX)
if err == nil{
var ttyp DataEX.ESData
for _, item := range result.Each(reflect.TypeOf(ttyp)) {
@ -466,6 +465,7 @@ func IndexDocGet(indexName string,dataID string) (bool,string,DataEX.ESData) {
data = item.(DataEX.ESData)
break
}
return true,"获取数据成功", data
}else{
return false,"获取数据失败", data
@ -698,3 +698,35 @@ func GetLatestDoc(indexName string) (bool,string,DataEX.ESData) {
return false,"获取数据失败", data
}
}
func GetDoc(indexName string, dataId string) (bool,string,DataEX.ESData) {
var data DataEX.ESData
var list []DataEX.ESData
term2 := elastic.NewTermQuery("enable_flag", 1)
//query.Filter(term2)
term3 := elastic.NewTermQuery("data_id", dataId)
query:=elastic.NewBoolQuery()
query.Filter(term2).Filter(term3)
count, err := ES7Client.Count(indexName).Query(query).Do(CTX)
fmt.Println("count= ", count)
result,err:=ES7Client.Search().Index(indexName).Query(query).From(0).Sort("begin_time", false).Size(1).Do(CTX)
fmt.Println(result)
if err == nil{
var ttyp DataEX.ESData
//fmt.Println("reflect.TypeOf(ttyp)=", reflect.TypeOf(ttyp))
for _, item := range result.Each(reflect.TypeOf(ttyp)) {
//fmt.Println("item=", item)
data := item.(DataEX.ESData)
//fmt.Println("data=", data)
list = append(list,data)
}
fmt.Println("list=", list)
return true,"获取数据成功", data
}else{
return false,"获取数据失败", data
}
}

@ -1334,6 +1334,47 @@ var doc = `{
}
}
},
"/v1/openapi/datasource/GetESDoc": {
"post": {
"description": "获取es数据",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"datasource"
],
"summary": "获取es数据",
"operationId": "getESDoc",
"parameters": [
{
"description": "es数据",
"name": "input",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MySwagger.DatasourceESSwag"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/MySwagger.Result"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/MySwagger.Result"
}
}
}
}
},
"/v1/openapi/datasource/ReadDatasource": {
"post": {
"description": "获取数据源列表",
@ -2207,6 +2248,10 @@ var doc = `{
"type": "object",
"additionalProperties": true
},
"data_id": {
"type": "string",
"example": "CfBQnRJPyXMEI5nqLT0"
},
"datasource_code": {
"type": "string",
"example": "org_tree"
@ -2215,7 +2260,11 @@ var doc = `{
"type": "array",
"items": {
"type": "string"
}
},
"example": [
"[F38BD0DB-0142-4356-8F2B-623813FC2578",
"F38BD0DB-0142-4356-8F2B-623813FC2578]"
]
},
"page": {
"type": "integer",
@ -2309,12 +2358,16 @@ var doc = `{
},
"dic_name": {
"type": "string",
"example": "10"
"example": "sex"
},
"dic_type": {
"type": "integer",
"example": 1
},
"dic_value": {
"type": "string",
"example": "10"
},
"enable_flag": {
"type": "integer",
"example": 1
@ -2490,28 +2543,13 @@ var doc = `{
"MySwagger.Result": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true
}
},
"fail": {
"type": "boolean",
"example": false
},
"message": {
"type": "string",
"example": "操作成功"
"example": "接入系统票据验证失败"
},
"success": {
"type": "boolean",
"example": true
},
"total": {
"type": "integer",
"example": 120
"example": false
}
}
}

@ -1318,6 +1318,47 @@
}
}
},
"/v1/openapi/datasource/GetESDoc": {
"post": {
"description": "获取es数据",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"datasource"
],
"summary": "获取es数据",
"operationId": "getESDoc",
"parameters": [
{
"description": "es数据",
"name": "input",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/MySwagger.DatasourceESSwag"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/MySwagger.Result"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/MySwagger.Result"
}
}
}
}
},
"/v1/openapi/datasource/ReadDatasource": {
"post": {
"description": "获取数据源列表",
@ -2191,6 +2232,10 @@
"type": "object",
"additionalProperties": true
},
"data_id": {
"type": "string",
"example": "CfBQnRJPyXMEI5nqLT0"
},
"datasource_code": {
"type": "string",
"example": "org_tree"
@ -2199,7 +2244,11 @@
"type": "array",
"items": {
"type": "string"
}
},
"example": [
"[F38BD0DB-0142-4356-8F2B-623813FC2578",
"F38BD0DB-0142-4356-8F2B-623813FC2578]"
]
},
"page": {
"type": "integer",
@ -2293,12 +2342,16 @@
},
"dic_name": {
"type": "string",
"example": "10"
"example": "sex"
},
"dic_type": {
"type": "integer",
"example": 1
},
"dic_value": {
"type": "string",
"example": "10"
},
"enable_flag": {
"type": "integer",
"example": 1
@ -2474,28 +2527,13 @@
"MySwagger.Result": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true
}
},
"fail": {
"type": "boolean",
"example": false
},
"message": {
"type": "string",
"example": "操作成功"
"example": "接入系统票据验证失败"
},
"success": {
"type": "boolean",
"example": true
},
"total": {
"type": "integer",
"example": 120
"example": false
}
}
}

@ -110,10 +110,16 @@ definitions:
conditions:
additionalProperties: true
type: object
data_id:
example: CfBQnRJPyXMEI5nqLT0
type: string
datasource_code:
example: org_tree
type: string
orgids:
example:
- '[F38BD0DB-0142-4356-8F2B-623813FC2578'
- F38BD0DB-0142-4356-8F2B-623813FC2578]
items:
type: string
type: array
@ -184,11 +190,14 @@ definitions:
example: 我是字典项说明
type: string
dic_name:
example: "10"
example: sex
type: string
dic_type:
example: 1
type: integer
dic_value:
example: "10"
type: string
enable_flag:
example: 1
type: integer
@ -317,23 +326,12 @@ definitions:
type: object
MySwagger.Result:
properties:
data:
items:
additionalProperties: true
type: object
type: array
fail:
example: false
type: boolean
message:
example: 操作成功
example: 接入系统票据验证失败
type: string
success:
example: true
example: false
type: boolean
total:
example: 120
type: integer
type: object
host: 127.0.0.1:8005
info:
@ -1181,6 +1179,33 @@ paths:
summary: 删除数据源
tags:
- datasource
/v1/openapi/datasource/GetESDoc:
post:
consumes:
- application/json
description: 获取es数据
operationId: getESDoc
parameters:
- description: es数据
in: body
name: input
required: true
schema:
$ref: '#/definitions/MySwagger.DatasourceESSwag'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/MySwagger.Result'
"400":
description: Bad Request
schema:
$ref: '#/definitions/MySwagger.Result'
summary: 获取es数据
tags:
- datasource
/v1/openapi/datasource/ReadDatasource:
post:
consumes:

Loading…
Cancel
Save