|
|
package DatasourceService
|
|
|
|
|
|
import (
|
|
|
"dsSupport/MyModel/AccessSystem/AccessSystemDao"
|
|
|
"dsSupport/MyModel/DataSource/DatasourceDAO"
|
|
|
"dsSupport/MyModel/MySwagger"
|
|
|
"dsSupport/MyModel/OrgTree/OrgtreeDAO"
|
|
|
"dsSupport/Utils/CacheUtil"
|
|
|
"dsSupport/Utils/CommonUtil"
|
|
|
"dsSupport/Utils/ES7Util"
|
|
|
"dsSupport/Utils/ES7Util/DataEX"
|
|
|
"dsSupport/models"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"html"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// ESDataContent DataContent,定义了DataContent结构信息
|
|
|
type ESDataContent struct {
|
|
|
Address string `json:"address"` // 地址
|
|
|
AreaCode string `json:"area_code"` // 区域码
|
|
|
OrgName string `json:"org_name"` // 机构名称
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @title GetDatasourceResults
|
|
|
* @Description 获取数据源集合
|
|
|
* @Author wangshuai
|
|
|
* @Date 2020-09-17
|
|
|
* @Param swag MySwagger.DatasourceSwag 查询条件
|
|
|
* @Return bool 执行结果
|
|
|
* @Return string 提示信息
|
|
|
* @Return int 数据源数量
|
|
|
* @Return []map[string]interface{} 数据源集合
|
|
|
* @Return error 错误信息
|
|
|
*/
|
|
|
func GetDatasourceResults(swag MySwagger.DatasourceSwag) (bool, string, int, []map[string]interface{}, error) {
|
|
|
var condition string
|
|
|
var conditions []string
|
|
|
//var page int
|
|
|
var query MySwagger.DatasourceQuery
|
|
|
|
|
|
if swag.SystemId != "" {
|
|
|
conditions = append(conditions, "system_id="+"'"+html.EscapeString(swag.SystemId)+"'")
|
|
|
}
|
|
|
if swag.DatasourceName != "" {
|
|
|
conditions = append(conditions, "datasource_name="+"'"+html.EscapeString(swag.DatasourceName)+"'")
|
|
|
}
|
|
|
if swag.DatasourceCode != "" {
|
|
|
conditions = append(conditions, "datasource_code="+"'"+html.EscapeString(swag.DatasourceCode)+"'")
|
|
|
}
|
|
|
if swag.DatasourceDetail != "" {
|
|
|
conditions = append(conditions, "datasource_detail="+"'"+html.EscapeString(swag.DatasourceDetail)+"'")
|
|
|
}
|
|
|
if swag.SetFlag != 0 {
|
|
|
conditions = append(conditions, "set_flag="+"'"+strconv.Itoa(swag.SetFlag)+"'")
|
|
|
}
|
|
|
if swag.CollectFlag != 0 {
|
|
|
conditions = append(conditions, "collect_flag="+"'"+strconv.Itoa(swag.CollectFlag)+"'")
|
|
|
}
|
|
|
if swag.ProvideType != 0 {
|
|
|
conditions = append(conditions, "provider_type="+"'"+strconv.Itoa(swag.ProvideType)+"'")
|
|
|
}
|
|
|
if swag.ProvideOrgid != "" {
|
|
|
conditions = append(conditions, "provider_orgid="+"'"+html.EscapeString(swag.ProvideOrgid)+"'")
|
|
|
}
|
|
|
if swag.DatastoreType != 0 {
|
|
|
conditions = append(conditions, "datastore_type="+"'"+strconv.Itoa(swag.DatastoreType)+"'")
|
|
|
}
|
|
|
if swag.DicId != "" {
|
|
|
conditions = append(conditions, "dic_id="+"'"+html.EscapeString(swag.DicId)+"'")
|
|
|
}
|
|
|
if swag.DeleteFlag != 0 {
|
|
|
conditions = append(conditions, "delete_flag="+"'"+strconv.Itoa(swag.DeleteFlag)+"'")
|
|
|
} else {
|
|
|
conditions = append(conditions, "delete_flag='-1'")
|
|
|
}
|
|
|
if swag.EnableFlag != 0 {
|
|
|
conditions = append(conditions, "enable_flag="+"'"+strconv.Itoa(swag.EnableFlag)+"'")
|
|
|
}
|
|
|
if swag.Page != 0 {
|
|
|
//page = swag.Page
|
|
|
//query.Page = (page - 1) * 100
|
|
|
query.Page = swag.Page
|
|
|
} else {
|
|
|
query.Page = 1
|
|
|
}
|
|
|
|
|
|
if len(conditions) > 0 {
|
|
|
condition = " AND " + strings.Join(conditions, " AND ")
|
|
|
} else {
|
|
|
condition = ""
|
|
|
}
|
|
|
query.Conditions = condition
|
|
|
|
|
|
result, message, count, data, failResult := DatasourceDAO.GetDatasourceResults(query)
|
|
|
|
|
|
return result, message, count, data, failResult
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @title CreateDatasource
|
|
|
* @Description 创建数据源
|
|
|
* @Author wangshuai
|
|
|
* @Date 2020-09-17
|
|
|
* @Param model models.TDataexDatasource 数据源信息
|
|
|
* @Return bool 执行结果
|
|
|
* @Return string 提示信息
|
|
|
* @Return error 错误信息
|
|
|
*/
|
|
|
func CreateDatasource(model models.TDataexDatasource) (bool, string, error) {
|
|
|
// 校验数据提供系统是否存在
|
|
|
_, e := AccessSystemDao.GetAppByCode(model.SystemId)
|
|
|
if e != nil {
|
|
|
return false, "数据提供系统不存在", nil
|
|
|
}
|
|
|
// 校验机构是否存在
|
|
|
if !OrgtreeDAO.IsOrgtreeExistsById(model.ProvideOrgid) {
|
|
|
return false, "机构不存在", nil
|
|
|
}
|
|
|
// 校验数据源编码是否存在
|
|
|
if DatasourceDAO.IsDatasourceExistsByCode(html.EscapeString(model.DatasourceCode)) {
|
|
|
return false, "数据源编码已存在", nil
|
|
|
}
|
|
|
business := new(models.TDataexDatasource)
|
|
|
business.Id = CommonUtil.GetUUID()
|
|
|
business.SystemId = model.SystemId
|
|
|
business.DatasourceName = html.EscapeString(model.DatasourceName)
|
|
|
business.DatasourceCode = html.EscapeString(model.DatasourceCode)
|
|
|
business.DatasourceDetail = html.EscapeString(model.DatasourceDetail)
|
|
|
business.SetFlag = model.SetFlag
|
|
|
business.CollectFlag = model.CollectFlag
|
|
|
business.ProvideType = model.ProvideType
|
|
|
business.ProvideOrgid = html.EscapeString(model.ProvideOrgid)
|
|
|
business.DatastoreType = model.DatastoreType
|
|
|
business.DicId = html.EscapeString(model.DicId)
|
|
|
business.CreateTime = time.Now()
|
|
|
business.DeleteFlag = -1
|
|
|
business.EnableFlag = 1
|
|
|
|
|
|
result, message, error := DatasourceDAO.CreateDatasource(business)
|
|
|
|
|
|
return result, message, error
|
|
|
}
|
|
|
|
|
|
func UpdateDatasource(id string, model models.TDataexDatasource) (bool, string, error) {
|
|
|
// 校验数据提供系统是否存在
|
|
|
_, e := AccessSystemDao.GetAppByCode(model.SystemId)
|
|
|
if e != nil {
|
|
|
return false, "数据提供系统不存在", nil
|
|
|
}
|
|
|
// 校验机构是否存在
|
|
|
if !OrgtreeDAO.IsOrgtreeExistsById(model.ProvideOrgid) {
|
|
|
return false, "机构不存在", nil
|
|
|
}
|
|
|
business := new(models.TDataexDatasource)
|
|
|
//清除Redis缓存
|
|
|
var ids = []string{id}
|
|
|
var selector = CacheUtil.GetBean("t_dataex_datasource")
|
|
|
CacheUtil.DeleteCacheByIds(ids, selector)
|
|
|
|
|
|
business.Id = html.EscapeString(id)
|
|
|
business.DatasourceName = html.EscapeString(model.DatasourceName)
|
|
|
business.DatasourceCode = html.EscapeString(model.DatasourceCode)
|
|
|
business.DatasourceDetail = html.EscapeString(model.DatasourceDetail)
|
|
|
business.SetFlag = model.SetFlag
|
|
|
business.CollectFlag = model.CollectFlag
|
|
|
business.ProvideType = model.ProvideType
|
|
|
business.ProvideOrgid = html.EscapeString(model.ProvideOrgid)
|
|
|
business.DatastoreType = model.DatastoreType
|
|
|
business.DicId = html.EscapeString(model.DicId)
|
|
|
business.ChangeTime = time.Now()
|
|
|
business.EnableFlag = model.EnableFlag
|
|
|
|
|
|
result, message, error := DatasourceDAO.UpdateDatasource(id, business)
|
|
|
|
|
|
return result, message, error
|
|
|
}
|
|
|
|
|
|
func RemoveDatasource(id string) (bool, string, error) {
|
|
|
business := new(models.TDataexDatasource)
|
|
|
|
|
|
//清除Redis缓存
|
|
|
var ids = []string{id}
|
|
|
var selector = CacheUtil.GetBean("t_dataex_datasource")
|
|
|
CacheUtil.DeleteCacheByIds(ids, selector)
|
|
|
|
|
|
business.Id = html.EscapeString(id)
|
|
|
business.ChangeTime = time.Now()
|
|
|
business.DeleteTime = time.Now()
|
|
|
business.DeleteFlag = 1
|
|
|
business.EnableFlag = -1
|
|
|
|
|
|
result, message, error := DatasourceDAO.RemoveDatasource(id, business)
|
|
|
|
|
|
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, int, []DataEX.ESData2) {
|
|
|
t1 := time.Now()
|
|
|
count, _ := ES7Util.GetDocCount(datasourceCode, begin, conditions)
|
|
|
t2 := time.Now()
|
|
|
fmt.Println("t2与t1相差:", t2.Sub(t1))
|
|
|
result, message, esdata := ES7Util.SearchDocPage(datasourceCode, orgIDs, page, begin, conditions, sort)
|
|
|
|
|
|
t3 := time.Now()
|
|
|
fmt.Println("t3与t2相差:", t3.Sub(t2))
|
|
|
|
|
|
var ESData2 []DataEX.ESData2
|
|
|
var esData2 DataEX.ESData2
|
|
|
|
|
|
for _, value := range esdata {
|
|
|
var query = "AND datasource_code='" + datasourceCode + "'"
|
|
|
res, _, data, _ := DatasourceDAO.GetDatasourceRow(query)
|
|
|
var datasourceName interface{}
|
|
|
if res == true {
|
|
|
datasourceName = data["datasource_name"]
|
|
|
esData2.DatasourceName = datasourceName.(string)
|
|
|
}
|
|
|
|
|
|
esData2.SystemId = value.SystemId
|
|
|
esData2.DatasourceId = value.DatasourceId
|
|
|
//
|
|
|
esData2.ProvinceId = value.ProvinceId
|
|
|
esData2.ProvinceName = value.ProvinceName
|
|
|
esData2.CityId = value.CityId
|
|
|
esData2.CityName = value.CityName
|
|
|
esData2.AreaId = value.AreaId
|
|
|
esData2.AreaName = value.AreaName
|
|
|
esData2.BureauId = value.BureauId
|
|
|
esData2.RegionId = value.RegionId
|
|
|
esData2.MainId = value.MainId
|
|
|
esData2.OrgId = value.OrgId
|
|
|
esData2.OrgName = value.OrgName
|
|
|
esData2.OrgType = value.OrgType
|
|
|
esData2.SchoolType = value.SchoolType
|
|
|
esData2.SchoolTypeName = value.SchoolTypeName
|
|
|
esData2.DeptId = value.DeptId
|
|
|
esData2.StageId = value.StageId
|
|
|
esData2.GradeId = value.GradeId
|
|
|
esData2.ClassId = value.ClassId
|
|
|
esData2.DataId = value.DataId
|
|
|
esData2.FileUri = value.FileUri
|
|
|
esData2.BeginTime = value.BeginTime
|
|
|
esData2.EndTime = value.EndTime
|
|
|
esData2.DelFlag = value.DelFlag
|
|
|
esData2.EnableFlag = value.EnableFlag
|
|
|
esData2.DataContent = value.DataContent
|
|
|
ESData2 = append(ESData2, esData2)
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
var esDatas []map[string]interface{}
|
|
|
var datas []map[string]interface{}
|
|
|
|
|
|
for _, value := range esdata {
|
|
|
esData := make(map[string]interface{})
|
|
|
j, _ := json.Marshal(value)
|
|
|
json.Unmarshal(j, &esData)
|
|
|
esDatas = append(esDatas, esData)
|
|
|
}
|
|
|
*/
|
|
|
t4 := time.Now()
|
|
|
fmt.Println("t4与t3相差:", t4.Sub(t3))
|
|
|
|
|
|
/*
|
|
|
var query = ""
|
|
|
res, _, _, datasources, _ := DatasourceDAO.GetAllDatasourceResults(query)
|
|
|
fmt.Println(datasources)
|
|
|
if res == true {
|
|
|
listJson, _ :=json.Marshal(esDatas)
|
|
|
joinListJson, _ := json.Marshal(datasources)
|
|
|
mergedesDatas := CommonUtil.ListMerge(string(listJson), string(joinListJson), "datasource_id", "datasource_code", "datasource_name", "datasource_name")
|
|
|
|
|
|
json.Unmarshal([]byte(mergedesDatas), &datas)
|
|
|
}
|
|
|
*/
|
|
|
//t4 := time.Now()
|
|
|
//fmt.Println("t4与t3相差:", t4.Sub(t3))
|
|
|
fmt.Println("ESData2:", ESData2)
|
|
|
//var datas []map[string]interface{}
|
|
|
return result, message, count, ESData2
|
|
|
}
|
|
|
|
|
|
//func IsDatasourceExistsByCode(code string) bool {
|
|
|
// result := DatasourceDAO.IsDatasourceExistsByCode(code)
|
|
|
//
|
|
|
// return result
|
|
|
//}
|
|
|
//
|
|
|
//func GetDatasourceIdByCode(code string) (bool, string, interface{}, error) {
|
|
|
// result, message, data, err := DatasourceDAO.GetDatasourceIdByCode(code)
|
|
|
//
|
|
|
// return result, message, data, err
|
|
|
//}
|