package DatasourceService import ( "dsDataex/GenXorm/models" "dsDataex/MyModel/DataSource/DatasourceDAO" "dsDataex/MyModel/JYT2012/Jyt2012Service" "dsDataex/MyModel/LinkSystem/LinksystemService" "dsDataex/MyModel/MySwagger" "dsDataex/MyModel/OrgTree/OrgtreeService" "dsDataex/Utils/CacheUtil" "dsDataex/Utils/CommonUtil" "dsDataex/Utils/ES7Util" "encoding/json" "html" "strconv" "strings" "time" ) type ESDataContent struct { Address string `json:"address"` AreaCode string `json:"area_code"` OrgName string `json:"org_name"` } func GetDatasourceResults (swag MySwagger.DatasourceSwag) (bool, string, int32, []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) + "'") } 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 } 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 } func CreateDatasource (model models.TDataexDatasource) (bool, string, error) { if ! LinksystemService.IsLinksystemExistsById(model.SystemId) { return false, "SystemId不存在", nil } if ! Jyt2012Service.IsJyt2012ExistsById(model.DicId) { return false, "DicId不存在", nil } if ! OrgtreeService.IsOrgtreeExistsById(model.ProvideOrgid) { return false, "OrgId不存在", 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) { 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 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 esDatas []map[string]interface{} var esData map[string]interface{} //esDatas := make(map[string]map[string]interface{}) //esData := make(map[string]interface{}) for _, value := range esdata { //esDatas = append(esDatas, value.DataContent) j, _ := json.Marshal(value) json.Unmarshal(j, &esData) //fmt.Println(esData) esData = make(map[string]interface{}) esDatas = append(esDatas, esData) } return result, message, esDatas } func IsDatasourceExistsById(id string) bool { result :=DatasourceDAO.IsDatasourceExistsById(id) return result } func GetDatasourceIdByCode(code string) (bool, string, interface{}, error) { result, message, data, err := DatasourceDAO.GetDatasourceIdByCode(code) return result, message, data, err }