master
wangshuai 5 years ago
parent 9ef1fdbefd
commit ad250a8998

@ -399,7 +399,20 @@ func SaveDataError2(fails []MySwagger.FailResult,datas []MySwagger.Data ,SystemI
* @Return error
*/
func GetMetadataResults(conditions string) (bool, string, int, []map[string]interface{}, error) {
sql := "SELECT * FROM t_dataex_metadata WHERE 1 = 1" + conditions + " ORDER BY create_time DESC, change_time DESC"
sql := "SELECT * FROM t_dataex_metadata WHERE 1 = 1 AND " + conditions + " AND eneble_flag = 1 ORDER BY create_time DESC, change_time DESC"
//数据条数
count, _ := DbUtil.Engine.SQL(sql).Query().Count()
//分页数据
list, err := DbUtil.Engine.SQL(sql).Query().List()
if list != nil {
return true, "数据获取成功", count, list, err
} else {
return false, "数据获取失败,数据源不存在", count, nil, nil
}
}
func GetDicIdsFromMetadata(conditions string) (bool, string, int, []map[string]interface{}, error) {
sql := "SELECT dic_id FROM t_dataex_metadata WHERE 1 = 1 AND " + conditions + " AND dic_id != '' AND eneble_flag = 1 ORDER BY create_time DESC, change_time DESC"
//数据条数
count, _ := DbUtil.Engine.SQL(sql).Query().Count()
//分页数据
@ -427,4 +440,30 @@ func GetJyt2012CountByParentIdAndDicValue(parentId string, dicValue string) int6
LogUtil.Error(ErrorConst.SqlQueryError, "数据库操作错误:"+err.Error())
}
return total
}
func GetJyt2012ResultsByParentId(parentId string) (bool, string, int, []map[string]interface{}, error) {
sql := "SELECT * FROM t_dataex_jyt2012 WHERE parent_id ='" + parentId + "' ORDER BY create_time DESC, change_time DESC"
//数据条数
count, _ := DbUtil.Engine.SQL(sql).Query().Count()
if count > 0 {
//分页数据
list, err := DbUtil.Engine.SQL(sql).Query().List()
return true, "数据获取成功", count, list, err
} else {
return false, "数据获取失败,数据源不存在", count, nil, nil
}
}
func GetJyt2012ResultsByParentIds(parentIds string) (bool, string, int, []map[string]interface{}, error) {
sql := "SELECT * FROM t_dataex_jyt2012 WHERE parent_id IN " + parentIds + " ORDER BY create_time DESC, change_time DESC"
//数据条数
count, _ := DbUtil.Engine.SQL(sql).Query().Count()
if count > 0 {
//分页数据
list, err := DbUtil.Engine.SQL(sql).Query().List()
return true, "数据获取成功", count, list, err
} else {
return false, "数据获取失败,数据源不存在", count, nil, nil
}
}

@ -9,6 +9,12 @@ import (
"strings"
)
//
//type dictionary struct {
// dics map[string]map[string]interface{} // 机构名称
//}
var dics []map[string]interface{}
/**
* @title ValidESDataContent
* @Description ESDataContent
@ -29,11 +35,25 @@ func ValidESDataContent(datasourceCode string, datas []MySwagger.Data) (bool, st
var conditions string
var esData DataEX.ESData
var r bool
var dicIds []string
var dicIdsStr string
conditions = " AND datasource_id='" + datasourceCode + "'"
conditions = "datasource_id='" + datasourceCode + "'"
// 从元数据集合获取该数据源对应的含有字典ID的字典ID集合
//res, _, _, metadataDicIds, _ := DataexDAO.GetMetadataResults(conditions)
//if res == true {
//
//}
// 获取该数据源对应的元数据集合
result, _, _, metadatas, _ := DataexDAO.GetMetadataResults(conditions)
if result == true {
//dic := make(map[string]interface{})
for _, vv := range metadatas {
dicIds = append(dicIds, "'" + vv["dic_id"].(string) + "'")
}
dicIdsStr = strings.Join(dicIds, ", ")
_, _, _, dics, _ = DataexDAO.GetJyt2012ResultsByParentIds(dicIdsStr)
for no := 0; no < len(datas) && no < 1000; no++ {
r = true
var jsonData map[string]interface{}
@ -81,7 +101,7 @@ func ValidESDataContent(datasourceCode string, datas []MySwagger.Data) (bool, st
*/
func ValidESDataContentItem(dataContentItem map[string]interface{}, itemName string, itemValue interface{}) (bool, string, error) {
if dataContentItem != nil {
dicId := dataContentItem["dic_id"]
dicId := dataContentItem["dic_id"].(string)
itemLength := dataContentItem["item_length"].(int64)
checkName := dataContentItem["check_name"].(int64)
checkDic := dataContentItem["check_dic"].(int64)
@ -98,7 +118,7 @@ func ValidESDataContentItem(dataContentItem map[string]interface{}, itemName str
} else if checkName > 0 { // 校验名称
return true, "ok", nil
} else if checkDic > 0 { // 校验字典
if CheckDic(dicId.(string), itemValue) == false {
if CheckDic(itemValue, dicId, dics) == false {
return false, "字典检测不通过", nil
} else {
return true, "ok", nil
@ -130,13 +150,15 @@ func ValidESDataContentItem(dataContentItem map[string]interface{}, itemName str
* @Param itemValue interface{}
* @Return bool
*/
func CheckDic(dicId string, itemValue interface{}) bool {
total := DataexDAO.GetJyt2012CountByParentIdAndDicValue(dicId, itemValue.(string))
if total > 0 {
return true
} else {
return false
func CheckDic(itemValue interface{}, dicId string, dics []map[string]interface{}) bool {
flag := false
for _, v := range dics {
if v["dic_value"] == itemValue && v["parent_id"] == dicId {
flag = true
}
}
return flag
}
// 暂时作废 2020-09-16
@ -165,3 +187,13 @@ func ValidESDataContentBak(datasourceCode string, dataContent map[string]interfa
return r, fails
}
// 暂时作废 2020-09-18
func CheckDicBak(dicId string, itemValue interface{}) bool {
total := DataexDAO.GetJyt2012CountByParentIdAndDicValue(dicId, itemValue.(string))
if total > 0 {
return true
} else {
return false
}
}

@ -133,3 +133,19 @@ func RemoveDataaccess(id string, model *models.TDataexDataaccess) (bool, string,
}
return true, "删除成功!", nil
}
func GetDataaccessCountByDatasourceCodeAndConsumeSystemId(datasourceCode string, consumeSystemId string) int64 {
business := new(models.TDataexDataaccess)
total, err := db.Where("datasource_code =? and consume_systemid =?", datasourceCode, consumeSystemId).Count(business)
if err != nil {
LogUtil.Error(ErrorConst.SqlQueryError, "数据库操作发生严重错误:"+err.Error())
}
return total
}
func IsDataaccessExistsByDatasourceCodeAndConsumeSystemId(datasourceCode string, consumeSystemId string) bool {
if GetDataaccessCountByDatasourceCodeAndConsumeSystemId(datasourceCode, consumeSystemId) > 0 {
return true
}
return false
}

@ -4,9 +4,8 @@ import (
"dsSupport/MyModel/AccessSystem/AccessSystemDao"
"dsSupport/MyModel/DataAccess/DataaccessDAO"
"dsSupport/MyModel/DataSource/DatasourceDAO"
"dsSupport/MyModel/DataSource/DatasourceService"
"dsSupport/MyModel/MySwagger"
"dsSupport/MyModel/OrgTree/OrgtreeService"
"dsSupport/MyModel/OrgTree/OrgtreeDAO"
"dsSupport/Utils/CacheUtil"
"dsSupport/Utils/CommonUtil"
"dsSupport/models"
@ -104,15 +103,22 @@ func GetDataaccessResults(swag MySwagger.DataaccessSwag) (bool, string, int, []m
* @Return error
*/
func CreateDataaccess(model models.TDataexDataaccess) (bool, string, error) {
if !DatasourceService.IsDatasourceExistsById(model.DatasourceId) {
return false, "DatasourceId不存在", nil
// 校验数据源编码是否存在
if !DatasourceDAO.IsDatasourceExistsByCode(html.EscapeString(model.DatasourceCode)) {
return false, "数据源编码不存在", nil
}
// 校验数据使用系统是否存在
_, e := AccessSystemDao.GetApp(model.ConsumeSystemid)
if e != nil {
return false, "SystemId不存在", nil
return false, "数据使用系统不存在", nil
}
// 校验数据源订阅是否存在
if DataaccessDAO.IsDataaccessExistsByDatasourceCodeAndConsumeSystemId(html.EscapeString(model.DatasourceCode), html.EscapeString(model.ConsumeSystemid)) {
return false, "数据源订阅已存在", nil
}
if !OrgtreeService.IsOrgtreeExistsById(model.ConsumeOrgid) {
return false, "OrgId不存在", nil
// 校验机构是否存在
if !OrgtreeDAO.IsOrgtreeExistsById(model.ConsumeOrgid) {
return false, "机构不存在", nil
}
business := new(models.TDataexDataaccess)
@ -145,15 +151,17 @@ func CreateDataaccess(model models.TDataexDataaccess) (bool, string, error) {
* @Return error
*/
func UpdateDataaccess(id string, model models.TDataexDataaccess) (bool, string, error) {
if !DatasourceService.IsDatasourceExistsById(model.DatasourceId) {
return false, "DatasourceId不存在", nil
// 校验数据源编码是否存在
if !DatasourceDAO.IsDatasourceExistsByCode(html.EscapeString(model.DatasourceCode)) {
return false, "数据源编码不存在", nil
}
_, e := AccessSystemDao.GetApp(model.ConsumeSystemid)
if e != nil {
return false, "SystemId不存在", nil
}
if !OrgtreeService.IsOrgtreeExistsById(model.ConsumeOrgid) {
return false, "OrgId不存在", nil
// 校验机构是否存在
if !OrgtreeDAO.IsOrgtreeExistsById(model.ConsumeOrgid) {
return false, "机构不存在", nil
}
business := new(models.TDataexDataaccess)

@ -79,17 +79,17 @@ func RemoveDatasource(id string, model *models.TDataexDatasource) (bool, string,
return true, "删除成功!", nil
}
func GetDatasourceCountById(id string) int64 {
func GetDatasourceCountByCode(code string) int64 {
business := new(models.TDataexDatasource)
total, err := db.Where("id =?", id).Count(business)
total, err := db.Where("code =?", code).Count(business)
if err != nil {
LogUtil.Error(ErrorConst.SqlUpdateError, "接入系统authToken Update数据库操作发生严重错误:"+err.Error())
LogUtil.Error(ErrorConst.SqlQueryError, "数据库操作发生严重错误:"+err.Error())
}
return total
}
func IsDatasourceExistsById(id string) bool {
if GetDatasourceCountById(id) > 0 {
func IsDatasourceExistsByCode(code string) bool {
if GetDatasourceCountByCode(code) > 0 {
return true
}
return false

@ -100,6 +100,11 @@ func CreateDatasource(c *gin.Context) {
return
}
if raw.DatasourceCode == "" {
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "数据源编码必填"})
return
}
success, message, _ := DatasourceService.CreateDatasource(raw)
if success {
c.JSON(http.StatusOK, MySwagger.Result{

@ -4,7 +4,7 @@ import (
"dsSupport/MyModel/AccessSystem/AccessSystemDao"
"dsSupport/MyModel/DataSource/DatasourceDAO"
"dsSupport/MyModel/MySwagger"
"dsSupport/MyModel/OrgTree/OrgtreeService"
"dsSupport/MyModel/OrgTree/OrgtreeDAO"
"dsSupport/Utils/CacheUtil"
"dsSupport/Utils/CommonUtil"
"dsSupport/Utils/ES7Util"
@ -111,12 +111,18 @@ func GetDatasourceResults(swag MySwagger.DatasourceSwag) (bool, string, int, []m
* @Return error
*/
func CreateDatasource(model models.TDataexDatasource) (bool, string, error) {
// 校验数据提供系统是否存在
_, e := AccessSystemDao.GetApp(model.SystemId)
if e != nil {
return false, "SystemId不存在", nil
return false, "数据提供系统不存在", nil
}
if !OrgtreeService.IsOrgtreeExistsById(model.ProvideOrgid) {
return false, "OrgId不存在", 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()
@ -140,8 +146,16 @@ func CreateDatasource(model models.TDataexDatasource) (bool, string, error) {
}
func UpdateDatasource(id string, model models.TDataexDatasource) (bool, string, error) {
// 校验数据提供系统是否存在
_, e := AccessSystemDao.GetApp(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")
@ -227,14 +241,14 @@ func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, c
return result, message, count, 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
}
//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
//}

@ -71,24 +71,24 @@ func RemoveMetadata(id string, model *models.TDataexMetadata) (bool, string, err
return true, "删除成功!", nil
}
func GetMetadataCountByDatasourceId(datasourceId string) int64 {
func GetMetadataCountByDatasourceCode(datasourceCode string) int64 {
business := new(models.TDataexMetadata)
total, err := db.Where("datasource_id =?", datasourceId).Count(business)
total, err := db.Where("datasource_id =?", datasourceCode).Count(business)
if err != nil {
LogUtil.Error(ErrorConst.SqlQueryError, "数据库操作发生严重错误:"+err.Error())
}
return total
}
func IsMetadataExistsByDatasourceId(datasourceId string) bool {
if GetMetadataCountByDatasourceId(datasourceId) > 0 {
func IsMetadataExistsByDatasourceCode(datasourceCode string) bool {
if GetMetadataCountByDatasourceCode(datasourceCode) > 0 {
return true
}
return false
}
func DeleteMetadataByDatasourceId(datasourceId string) (bool, string, error) {
_, err := db.Exec("DELETE FROM t_dataex_metadata WHERE datasource_id = ?", datasourceId)
func DeleteMetadataByDatasourceCode(datasourceCode string) (bool, string, error) {
_, err := db.Exec("DELETE FROM t_dataex_metadata WHERE datasource_id = ?", datasourceCode)
if err != nil {
LogUtil.Error(ErrorConst.SqlQueryError, "数据库操作发生严重错误:"+err.Error())
return false, "数据库操作失败", err

@ -1,8 +1,8 @@
package MetadataService
import (
"dsSupport/MyModel/DataSource/DatasourceService"
"dsSupport/MyModel/JYT2012/Jyt2012Service"
"dsSupport/MyModel/DataSource/DatasourceDAO"
"dsSupport/MyModel/JYT2012/Jyt2012DAO"
"dsSupport/MyModel/MetaData/MetadataDAO"
"dsSupport/MyModel/MySwagger"
"dsSupport/Utils/CacheUtil"
@ -81,11 +81,12 @@ func GetMetadataResults(swag MySwagger.MetadataSwag) (bool, string, int, []map[s
}
func CreateMetadata(model models.TDataexMetadata) (bool, string, error) {
if !DatasourceService.IsDatasourceExistsById(model.DatasourceId) {
return false, "DatasourceId不存在", nil
// 校验数据源编码是否存在
if !DatasourceDAO.IsDatasourceExistsByCode(html.EscapeString(model.DatasourceId)) {
return false, "数据源编码不存在", nil
}
if !Jyt2012Service.IsJyt2012ExistsById(model.DicId) {
return false, "DicId不存在", nil
if !Jyt2012DAO.IsJyt2012ExistsById(model.DicId) {
return false, "该字典不存在", nil
}
business := new(models.TDataexMetadata)
business.Id = CommonUtil.GetUUID()
@ -110,11 +111,12 @@ func CreateMetadata(model models.TDataexMetadata) (bool, string, error) {
}
func UpdateMetadata(id string, model models.TDataexMetadata) (bool, string, error) {
if !DatasourceService.IsDatasourceExistsById(model.DatasourceId) {
return false, "DatasourceId不存在", nil
// 校验数据源编码是否存在
if !DatasourceDAO.IsDatasourceExistsByCode(html.EscapeString(model.DatasourceId)) {
return false, "数据源编码不存在", nil
}
if !Jyt2012Service.IsJyt2012ExistsById(model.DicId) {
return false, "DicId不存在", nil
if !Jyt2012DAO.IsJyt2012ExistsById(model.DicId) {
return false, "该字典不存在", nil
}
business := new(models.TDataexMetadata)
@ -162,10 +164,10 @@ func RemoveMetadata(id string) (bool, string, error) {
}
func CreateMetadataES(indexName string) (bool, string, error) {
res, _, datasourceId, _ := DatasourceService.GetDatasourceIdByCode(indexName)
res, _, datasourceId, _ := DatasourceDAO.GetDatasourceIdByCode(indexName)
if res == true {
if MetadataDAO.IsMetadataExistsByDatasourceId(datasourceId.(string)) == true {
MetadataDAO.DeleteMetadataByDatasourceId(datasourceId.(string))
if MetadataDAO.IsMetadataExistsByDatasourceCode(datasourceId.(string)) == true {
MetadataDAO.DeleteMetadataByDatasourceCode(datasourceId.(string))
}
fmt.Println("datasourceId: ", datasourceId)
result := ES7Util.IndexDataContentMapping(indexName)

@ -1,6 +1,7 @@
package OrgtreeService
import (
"dsSupport/MyModel/AccessSystem/AccessSystemDao"
//"dsSupport/MyModel/LinkSystem/LinksystemService"
"dsSupport/MyModel/MySwagger"
"dsSupport/MyModel/OrgTree/OrgtreeDAO"
@ -74,9 +75,11 @@ func GetOrgtreeResults(swag MySwagger.OrgtreeSwag) (bool, string, int, []map[str
}
func CreateOrgtree(model models.TDataexOrgtree) (bool, string, error) {
//if ! LinksystemService.IsLinksystemExistsById(model.LinksystemId) {
// return false, "SystemId不存在", nil
//}
// 校验源业务系统是否存在
_, e := AccessSystemDao.GetApp(model.LinksystemId)
if e != nil {
return false, "源业务系统不存在", nil
}
business := new(models.TDataexOrgtree)
business.Id = CommonUtil.GetUUID()
business.OrgName = html.EscapeString(model.OrgName)
@ -98,9 +101,11 @@ func CreateOrgtree(model models.TDataexOrgtree) (bool, string, error) {
}
func UpdateOrgtree(id string, model models.TDataexOrgtree) (bool, string, error) {
//if ! LinksystemService.IsLinksystemExistsById(model.LinksystemId) {
// return false, "SystemId不存在", nil
//}
// 校验源业务系统是否存在
_, e := AccessSystemDao.GetApp(model.LinksystemId)
if e != nil {
return false, "源业务系统不存在", nil
}
business := new(models.TDataexOrgtree)
business.Id = html.EscapeString(id)
business.OrgName = html.EscapeString(model.OrgName)
@ -139,8 +144,8 @@ func RemoveOrgtree(id string) (bool, string, error) {
return result, message, error
}
func IsOrgtreeExistsById(id string) bool {
result := OrgtreeDAO.IsOrgtreeExistsById(id)
return result
}
//func IsOrgtreeExistsById(id string) bool {
// result := OrgtreeDAO.IsOrgtreeExistsById(id)
//
// return result
//}

Loading…
Cancel
Save