|
@@ -1,6 +1,7 @@
|
|
package data_manage
|
|
package data_manage
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ sql2 "database/sql"
|
|
"eta/eta_hub/global"
|
|
"eta/eta_hub/global"
|
|
"eta/eta_hub/utils"
|
|
"eta/eta_hub/utils"
|
|
"fmt"
|
|
"fmt"
|
|
@@ -68,7 +69,7 @@ func (m *EdbInfo) GetItemsByCondition(cond string, pars []interface{}, fieldArr
|
|
order = ` ORDER BY ` + orderRule
|
|
order = ` ORDER BY ` + orderRule
|
|
}
|
|
}
|
|
sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s %s`, fields, cond, order)
|
|
sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s %s`, fields, cond, order)
|
|
- err = global.DbMap[utils.DbNameIndex].Raw(sql, pars).Find(&items).Error
|
|
|
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -84,28 +85,34 @@ func (m *EdbInfo) GetItemsPageByCondition(cond string, pars []interface{}, field
|
|
}
|
|
}
|
|
sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s %s`, fields, cond, order)
|
|
sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s %s`, fields, cond, order)
|
|
sql += fmt.Sprintf(` LIMIT %d,%d`, startSize, pageSize)
|
|
sql += fmt.Sprintf(` LIMIT %d,%d`, startSize, pageSize)
|
|
- err = global.DbMap[utils.DbNameIndex].Raw(sql, pars).Find(&items).Error
|
|
|
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
func (m *EdbInfo) GetItemsTotal(cond string, pars []interface{}) (total int, err error) {
|
|
func (m *EdbInfo) GetItemsTotal(cond string, pars []interface{}) (total int, err error) {
|
|
|
|
+ var totalNull sql2.NullInt64
|
|
//o := orm.NewOrmUsingDB("data")
|
|
//o := orm.NewOrmUsingDB("data")
|
|
sql := fmt.Sprintf(`SELECT COUNT(*) FROM edb_info WHERE 1=1 %s`, cond)
|
|
sql := fmt.Sprintf(`SELECT COUNT(*) FROM edb_info WHERE 1=1 %s`, cond)
|
|
- err = global.DbMap[utils.DbNameIndex].Raw(sql, pars).Scan(&total).Error
|
|
|
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Scan(&totalNull).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ total = int(totalNull.Int64)
|
|
|
|
+
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
func (m *EdbInfo) GetItemByUniCode(code string) (item *EdbInfo, err error) {
|
|
func (m *EdbInfo) GetItemByUniCode(code string) (item *EdbInfo, err error) {
|
|
//o := orm.NewOrmUsingDB("data")
|
|
//o := orm.NewOrmUsingDB("data")
|
|
sql := fmt.Sprintf(`SELECT * FROM edb_info WHERE unique_code = ? LIMIT 1`)
|
|
sql := fmt.Sprintf(`SELECT * FROM edb_info WHERE unique_code = ? LIMIT 1`)
|
|
- err = global.DbMap[utils.DbNameIndex].Raw(sql, code).Scan(&item).Error
|
|
|
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, code).First(&item).Error
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
func (m *EdbInfo) GetItemByEdbCode(code string) (item *EdbInfo, err error) {
|
|
func (m *EdbInfo) GetItemByEdbCode(code string) (item *EdbInfo, err error) {
|
|
//o := orm.NewOrmUsingDB("data")
|
|
//o := orm.NewOrmUsingDB("data")
|
|
sql := fmt.Sprintf(`SELECT * FROM edb_info WHERE edb_code = ? LIMIT 1`)
|
|
sql := fmt.Sprintf(`SELECT * FROM edb_info WHERE edb_code = ? LIMIT 1`)
|
|
- err = global.DbMap[utils.DbNameIndex].Raw(sql, code).Scan(&item).Error
|
|
|
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, code).First(&item).Error
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -138,6 +145,7 @@ type EdbInfoItem struct {
|
|
SysUserRealName string `description:"创建人姓名"`
|
|
SysUserRealName string `description:"创建人姓名"`
|
|
ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
|
|
ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
|
|
//EdbData []*EdbDataItem `description:"指标数据"`
|
|
//EdbData []*EdbDataItem `description:"指标数据"`
|
|
|
|
+ ClassifyList []*EdbClassifyIdItems `description:"分类列表"`
|
|
}
|
|
}
|
|
|
|
|
|
type EdbInfoItemResp struct {
|
|
type EdbInfoItemResp struct {
|
|
@@ -215,7 +223,7 @@ type TraceEdbInfoResp struct {
|
|
func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
|
|
func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
|
|
//o := orm.NewOrmUsingDB("data")
|
|
//o := orm.NewOrmUsingDB("data")
|
|
sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
|
|
sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
|
|
- err = global.DbMap[utils.DbNameIndex].Raw(sql, edbInfoId).Scan(&item).Error
|
|
|
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, edbInfoId).First(&item).Error
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -239,6 +247,41 @@ func GetEdbInfoByEdbCodeList(source int, edbCodeList []string) (items []*EdbInfo
|
|
}
|
|
}
|
|
//o := orm.NewOrmUsingDB("data")
|
|
//o := orm.NewOrmUsingDB("data")
|
|
sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code in (` + utils.GetOrmInReplace(num) + `) `
|
|
sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code in (` + utils.GetOrmInReplace(num) + `) `
|
|
- err = global.DbMap[utils.DbNameIndex].Raw(sql, source, edbCodeList).Scan(&items).Error
|
|
|
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, source, edbCodeList).Find(&items).Error
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type BaseEdbInfoItemResp struct {
|
|
|
|
+ List []*BaseEdbInfoItem `description:"指标列表"`
|
|
|
|
+ Paging *paging.PagingItem `description:"分页"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// BaseEdbInfoItem 指标信息
|
|
|
|
+type BaseEdbInfoItem struct {
|
|
|
|
+ UniqueCode string `description:"指标唯一编码"`
|
|
|
|
+ EdbCode string `description:"指标编码"`
|
|
|
|
+ EdbName string `description:"指标名称"`
|
|
|
|
+ SourceName string `description:"来源名称"`
|
|
|
|
+ Frequency string `description:"频率"`
|
|
|
|
+ Unit string `description:"单位"`
|
|
|
|
+ StartDate string `description:"起始日期"`
|
|
|
|
+ EndDate string `description:"终止日期"`
|
|
|
|
+ ClassifyList []*EdbClassifyIdItems `description:"分类列表"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func FormatEdbInfo2BaseItem(origin *EdbInfo) (item *BaseEdbInfoItem) {
|
|
|
|
+ if origin == nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ item = new(BaseEdbInfoItem)
|
|
|
|
+ item.SourceName = origin.SourceName
|
|
|
|
+ item.EdbCode = origin.EdbCode
|
|
|
|
+ item.EdbName = origin.EdbName
|
|
|
|
+ item.Frequency = origin.Frequency
|
|
|
|
+ item.Unit = origin.Unit
|
|
|
|
+ item.StartDate = origin.StartDate
|
|
|
|
+ item.EndDate = origin.EndDate
|
|
|
|
+ item.UniqueCode = origin.UniqueCode
|
|
|
|
+ //item.EdbData = edbData
|
|
return
|
|
return
|
|
}
|
|
}
|