edb_info.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. package models
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "github.com/shopspring/decimal"
  8. "hongze/hongze_edb_lib/utils"
  9. "strconv"
  10. "time"
  11. )
  12. type EdbInfo struct {
  13. EdbInfoId int `orm:"column(edb_info_id);pk"`
  14. SourceName string `description:"来源名称"`
  15. Source int `description:"来源id"`
  16. EdbCode string `description:"指标编码"`
  17. EdbName string `description:"指标名称"`
  18. EdbNameSource string `description:"指标名称来源"`
  19. Frequency string `description:"频率"`
  20. Unit string `description:"单位"`
  21. StartDate string `description:"起始日期"`
  22. EndDate string `description:"终止日期"`
  23. ClassifyId int `description:"分类id"`
  24. SysUserId int
  25. SysUserRealName string
  26. UniqueCode string `description:"指标唯一编码"`
  27. CreateTime time.Time
  28. ModifyTime time.Time
  29. MinValue float64 `description:"指标最小值"`
  30. MaxValue float64 `description:"指标最大值"`
  31. CalculateFormula string `description:"计算公式"`
  32. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  33. Sort int `description:"排序字段"`
  34. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  35. MoveFrequency string `description:"移动频度"`
  36. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  37. ServerUrl string `description:"服务器地址"`
  38. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  39. EdbNameEn string `description:"英文指标名称"`
  40. UnitEn string `description:"英文单位"`
  41. LatestDate string `description:"数据最新日期"`
  42. LatestValue float64 `description:"数据最新值"`
  43. ChartImage string `description:"图表图片"`
  44. Calendar string `description:"公历/农历"`
  45. }
  46. // AddEdbInfo 添加指标
  47. func AddEdbInfo(item *EdbInfo) (lastId int64, err error) {
  48. o := orm.NewOrm()
  49. lastId, err = o.Insert(item)
  50. return
  51. }
  52. // EdbInfoList 指标数据列表
  53. type EdbInfoList struct {
  54. EdbInfoId int `orm:"column(edb_info_id);pk"`
  55. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  56. SourceName string `description:"来源名称"`
  57. Source int `description:"来源id"`
  58. EdbCode string `description:"指标编码"`
  59. EdbNameEn string `description:"英文指标名称"`
  60. EdbName string `description:"指标名称"`
  61. Frequency string `description:"频率"`
  62. FrequencyEn string `description:"英文频率"`
  63. Unit string `description:"单位"`
  64. UnitEn string `description:"英文单位"`
  65. StartDate string `description:"起始日期"`
  66. EndDate string `description:"终止日期"`
  67. LatestDate string `description:"数据最新日期"`
  68. LatestValue float64 `description:"数据最新值"`
  69. ClassifyId int `description:"分类id"`
  70. UniqueCode string `description:"指标唯一编码"`
  71. SysUserId int `description:"创建人id"`
  72. SysUserRealName string `description:"创建人姓名"`
  73. ModifyTime string `description:"最新修改时间"`
  74. CreateTime string `description:"创建时间"`
  75. EdbNameAlias string `json:"-" description:"指标名称,别名"`
  76. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  77. ChartImage string `description:"图表图片"`
  78. RuleType int `description:"预测规则,1:最新,2:固定值"`
  79. FixedValue float64 `description:"固定值"`
  80. DataList []*EdbData `description:"实际指标数据"`
  81. PredictDataList []*EdbData `description:"预测指标数据"`
  82. Button EdbClassifyItemsButton `description:"操作权限"`
  83. IsEnEdb bool `description:"是否展示英文标识"`
  84. }
  85. // EdbClassifyItemsButton 操作按钮
  86. type EdbClassifyItemsButton struct {
  87. AddButton bool `description:"是否可添加"`
  88. OpButton bool `description:"是否可编辑"`
  89. DeleteButton bool `description:"是否可删除"`
  90. MoveButton bool `description:"是否可移动"`
  91. ShowEdbRelation bool `description:"是否展示关联指标"`
  92. ShowChartRelation bool `description:"是否展示关联图表"`
  93. }
  94. // GetEdbInfoByName 根据指标名称获取所有的指标数据列表
  95. func GetEdbInfoByName(edbName string) (items []*EdbInfoList, err error) {
  96. o := orm.NewOrm()
  97. sql := ` SELECT * FROM edb_info WHERE edb_name=? `
  98. _, err = o.Raw(sql, edbName).QueryRows(&items)
  99. return
  100. }
  101. // ModifyEdbInfoNameSource 根据来源修改指标名称
  102. func ModifyEdbInfoNameSource(edbNameSource string, edbInfoId int) (err error) {
  103. o := orm.NewOrm()
  104. sql := ` UPDATE edb_info SET edb_name_source=? WHERE edb_info_id = ? `
  105. _, err = o.Raw(sql, edbNameSource, edbInfoId).Exec()
  106. return
  107. }
  108. // GetEdbInfoById 根据指标id获取指标信息
  109. func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  110. o := orm.NewOrm()
  111. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  112. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  113. return
  114. }
  115. // GetEdbInfoByUniqueCode 根据指标唯一编码获取指标信息
  116. func GetEdbInfoByUniqueCode(uniqueCode string) (item *EdbInfo, err error) {
  117. o := orm.NewOrm()
  118. sql := ` SELECT * FROM edb_info WHERE unique_code=? `
  119. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  120. return
  121. }
  122. // GetEdbInfoByIdList 根据指标id列表获取指标信息
  123. func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  124. num := len(edbInfoIdList)
  125. if num <= 0 {
  126. return
  127. }
  128. o := orm.NewOrm()
  129. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  130. _, err = o.Raw(sql, edbInfoIdList).QueryRows(&items)
  131. return
  132. }
  133. // Update 更新EdbInfo信息
  134. func (edbInfo *EdbInfo) Update(cols []string) (err error) {
  135. o := orm.NewOrm()
  136. _, err = o.Update(edbInfo, cols...)
  137. return
  138. }
  139. // EdbInfoSearchData
  140. type EdbInfoSearchData struct {
  141. EdbDataId int `description:"数据ID"`
  142. DataTime string `description:"数据日期"`
  143. Value float64 `description:"数据"`
  144. }
  145. // GetEdbDataListAll 获取指标数据列表 order:1升序,其余值为降序
  146. func GetEdbDataListAll(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchData, err error) {
  147. o := orm.NewOrm()
  148. sql := ``
  149. tableName := GetEdbDataTableName(source)
  150. sql = ` SELECT * FROM %s WHERE 1=1 `
  151. sql = fmt.Sprintf(sql, tableName)
  152. if condition != "" {
  153. sql += condition
  154. }
  155. if order == 1 {
  156. sql += ` ORDER BY data_time ASC `
  157. } else {
  158. sql += ` ORDER BY data_time DESC `
  159. }
  160. _, err = o.Raw(sql, pars).QueryRows(&item)
  161. return
  162. }
  163. // GetEdbDataListAllByTo 根据事务链接获取指标数据列表 order:1升序,其余值为降序
  164. func GetEdbDataListAllByTo(to orm.TxOrmer, condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchData, err error) {
  165. sql := ``
  166. tableName := GetEdbDataTableName(source)
  167. sql = ` SELECT * FROM %s WHERE 1=1 `
  168. sql = fmt.Sprintf(sql, tableName)
  169. if condition != "" {
  170. sql += condition
  171. }
  172. if order == 1 {
  173. sql += ` ORDER BY data_time ASC `
  174. } else {
  175. sql += ` ORDER BY data_time DESC `
  176. }
  177. _, err = to.Raw(sql, pars).QueryRows(&item)
  178. return
  179. }
  180. // EdbInfoMaxAndMinInfo 指标最新数据记录结构体
  181. type EdbInfoMaxAndMinInfo struct {
  182. MinDate string `description:"最小日期"`
  183. MaxDate string `description:"最大日期"`
  184. MinValue float64 `description:"最小值"`
  185. MaxValue float64 `description:"最大值"`
  186. LatestValue float64 `description:"最新值"`
  187. LatestDate string `description:"实际数据最新日期"`
  188. }
  189. // GetEdbInfoMaxAndMinInfo 获取指标的最新数据记录信息
  190. func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  191. o := orm.NewOrm()
  192. sql := ``
  193. tableName := GetEdbDataTableName(source)
  194. sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
  195. sql = fmt.Sprintf(sql, tableName)
  196. err = o.Raw(sql, edbCode).QueryRow(&item)
  197. var latest_value float64
  198. sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
  199. sql = fmt.Sprintf(sql, tableName)
  200. err = o.Raw(sql, edbCode).QueryRow(&latest_value)
  201. item.LatestValue = latest_value
  202. return
  203. }
  204. // ModifyEdbInfoMaxAndMinInfo 修改指标的最新数据信息
  205. func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  206. o := orm.NewOrm()
  207. sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,modify_time=NOW() WHERE edb_info_id=? `
  208. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, edbInfoId).Exec()
  209. return
  210. }
  211. // GetEdbDataCount 获取edb指标数据的数量; order:1升序,其余值为降序
  212. func GetEdbDataCount(condition string, pars []interface{}, source int) (count int, err error) {
  213. o := orm.NewOrm()
  214. sql := ``
  215. tableName := GetEdbDataTableName(source)
  216. sql = ` SELECT COUNT(1) AS count FROM %s WHERE 1=1 `
  217. sql = fmt.Sprintf(sql, tableName)
  218. if condition != "" {
  219. sql += condition
  220. }
  221. err = o.Raw(sql, pars).QueryRow(&count)
  222. return
  223. }
  224. // GetLastEdbData 获取最近的一条指标数据
  225. func GetLastEdbData(condition string, pars []interface{}, source int) (item *EdbInfoSearchData, err error) {
  226. o := orm.NewOrm()
  227. sql := ``
  228. tableName := GetEdbDataTableName(source)
  229. sql = ` SELECT * FROM %s WHERE 1=1 `
  230. sql = fmt.Sprintf(sql, tableName)
  231. if condition != "" {
  232. sql += condition
  233. }
  234. sql += ` ORDER BY data_time DESC `
  235. err = o.Raw(sql, pars).QueryRow(&item)
  236. return
  237. }
  238. // GetEdbInfoByEdbCode 根据指标code获取指标信息
  239. func GetEdbInfoByEdbCode(source int, edbCode string) (item *EdbInfo, err error) {
  240. o := orm.NewOrm()
  241. sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code=? `
  242. err = o.Raw(sql, source, edbCode).QueryRow(&item)
  243. return
  244. }
  245. // GetEdbInfoOnlyByEdbCode 仅根据指标code获取指标信息
  246. func GetEdbInfoOnlyByEdbCode(edbCode string) (item *EdbInfo, err error) {
  247. o := orm.NewOrm()
  248. sql := ` SELECT * FROM edb_info WHERE edb_code=? `
  249. err = o.Raw(sql, edbCode).QueryRow(&item)
  250. return
  251. }
  252. // GetEdbInfoCalculateListByCondition 获取指标关系列表
  253. func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (items []*EdbInfoCalculateMapping, err error) {
  254. o := orm.NewOrm()
  255. sql := ` SELECT * FROM edb_info_calculate_mapping WHERE 1=1 `
  256. if condition != "" {
  257. sql += condition
  258. }
  259. _, err = o.Raw(sql, pars).QueryRows(&items)
  260. return
  261. }
  262. // GetEdbInfoCalculateCountByCondition 获取关联指标数量
  263. func GetEdbInfoCalculateCountByCondition(condition string, pars []interface{}) (count int, err error) {
  264. o := orm.NewOrm()
  265. sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_mapping WHERE 1=1 `
  266. if condition != "" {
  267. sql += condition
  268. }
  269. err = o.Raw(sql, pars).QueryRow(&count)
  270. return
  271. }
  272. // 优化版本-处理数据精度问题
  273. type EdbInfoSearchDataV1 struct {
  274. EdbDataId int `description:"数据ID"`
  275. DataTime string `description:"数据日期"`
  276. Value string `description:"数据"`
  277. }
  278. // 优化版本-处理数据精度问题
  279. func GetEdbDataListAllV1(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchDataV1, err error) {
  280. o := orm.NewOrm()
  281. sql := ``
  282. tableName := GetEdbDataTableName(source)
  283. sql = ` SELECT * FROM %s WHERE 1=1 `
  284. sql = fmt.Sprintf(sql, tableName)
  285. if condition != "" {
  286. sql += condition
  287. }
  288. if order == 1 {
  289. sql += ` ORDER BY data_time ASC `
  290. } else {
  291. sql += ` ORDER BY data_time DESC `
  292. }
  293. _, err = o.Raw(sql, pars).QueryRows(&item)
  294. return
  295. }
  296. // GetEdbDataListAllV1ByTo 通过事务链接获取数据列表
  297. func GetEdbDataListAllV1ByTo(to orm.TxOrmer, condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchDataV1, err error) {
  298. sql := ``
  299. tableName := GetEdbDataTableName(source)
  300. sql = ` SELECT * FROM %s WHERE 1=1 `
  301. sql = fmt.Sprintf(sql, tableName)
  302. if condition != "" {
  303. sql += condition
  304. }
  305. if order == 1 {
  306. sql += ` ORDER BY data_time ASC `
  307. } else {
  308. sql += ` ORDER BY data_time DESC `
  309. }
  310. _, err = to.Raw(sql, pars).QueryRows(&item)
  311. return
  312. }
  313. // GetEdbInfoByCondition 获取指标列表
  314. func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (item []*EdbInfo, err error) {
  315. o := orm.NewOrm()
  316. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  317. if condition != "" {
  318. sql += condition
  319. }
  320. if order == 1 {
  321. sql += ` ORDER BY end_date ASC `
  322. } else {
  323. sql += ` ORDER BY edb_info_id ASC `
  324. }
  325. _, err = o.Raw(sql, pars).QueryRows(&item)
  326. return
  327. }
  328. // UnifiedModifyEdbInfoMaxAndMinInfo 统一修改指标的最大最小值
  329. func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg string) {
  330. // 修改最大最小值
  331. maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.EdbCode)
  332. if err != nil {
  333. if err.Error() == utils.ErrNoRow() {
  334. err = nil
  335. return
  336. }
  337. errMsg = "刷新指标失败!"
  338. err = errors.New("获取指标最大最小值失败,err:" + err.Error())
  339. return
  340. }
  341. if maxAndMinItem != nil {
  342. err = ModifyEdbInfoMaxAndMinInfo(edbInfo.EdbInfoId, maxAndMinItem)
  343. if err != nil {
  344. errMsg = "刷新指标失败!"
  345. err = errors.New("修改指标最大最小值失败,err:" + err.Error())
  346. return
  347. }
  348. }
  349. // 修改关联的预测指标
  350. go ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId(edbInfo.EdbInfoId, maxAndMinItem)
  351. return
  352. }
  353. // UnifiedModifyPredictEdbInfoMaxAndMinInfo 统一修改预测运算指标的最大最小值
  354. func UnifiedModifyPredictEdbInfoMaxAndMinInfo(edbInfo *EdbInfo, latestDateStr string, latestValue float64) (err error, errMsg string) {
  355. // 修改最大最小值
  356. maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.EdbCode)
  357. if err != nil {
  358. if err.Error() == utils.ErrNoRow() {
  359. err = nil
  360. return
  361. }
  362. errMsg = "刷新指标失败!"
  363. err = errors.New("获取指标最大最小值失败,err:" + err.Error())
  364. return
  365. }
  366. if maxAndMinItem != nil {
  367. maxAndMinItem.LatestDate = latestDateStr
  368. maxAndMinItem.LatestValue = latestValue
  369. err = ModifyPredictEdbInfoMaxAndMinInfo(edbInfo.EdbInfoId, maxAndMinItem)
  370. if err != nil {
  371. errMsg = "刷新指标失败!"
  372. err = errors.New("修改指标最大最小值失败,err:" + err.Error())
  373. return
  374. }
  375. }
  376. return
  377. }
  378. // GetChartPredictEdbInfoDataList 获取图表的预测指标的未来数据
  379. func GetChartPredictEdbInfoDataList(predictEdbConf PredictEdbConf, latestDateStr string, lastDataValue float64, endDateStr, frequency string, order int) (predictEdbInfoData []*EdbInfoSearchData, err error) {
  380. endDate, err := time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
  381. if err != nil {
  382. return
  383. }
  384. latestDate, err := time.ParseInLocation(utils.FormatDate, latestDateStr, time.Local)
  385. if err != nil {
  386. return
  387. }
  388. // 开始预测数据的时间
  389. startDate := latestDate
  390. dataValue := lastDataValue
  391. if predictEdbConf.RuleType == 2 {
  392. dataValue = predictEdbConf.FixedValue
  393. }
  394. //获取后面的预测数据
  395. dayList := getPredictEdbDayList(startDate, endDate, frequency)
  396. predictEdbInfoData = make([]*EdbInfoSearchData, 0)
  397. // order:1升序,其余值为降序
  398. if order == 1 {
  399. for k, v := range dayList {
  400. predictEdbInfoData = append(predictEdbInfoData, &EdbInfoSearchData{
  401. EdbDataId: predictEdbConf.PredictEdbInfoId + 10000000000 + k,
  402. DataTime: v.Format(utils.FormatDate),
  403. Value: dataValue,
  404. })
  405. }
  406. } else {
  407. lenDayList := len(dayList)
  408. if lenDayList > 0 {
  409. for i := lenDayList - 1; i >= 0; i-- {
  410. v := dayList[i]
  411. predictEdbInfoData = append(predictEdbInfoData, &EdbInfoSearchData{
  412. EdbDataId: predictEdbConf.PredictEdbInfoId + 10000000000 + i,
  413. DataTime: v.Format(utils.FormatDate),
  414. Value: dataValue,
  415. })
  416. }
  417. }
  418. }
  419. return
  420. }
  421. // GetChartPredictEdbInfoDataListByConfList 获取图表的预测指标的未来数据
  422. func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbConfAndData, filtrateStartDateStr, latestDateStr, endDateStr, frequency string, realPredictEdbInfoData []*EdbInfoSearchData) (predictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
  423. endDate, err := time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
  424. if err != nil {
  425. return
  426. }
  427. latestDate, err := time.ParseInLocation(utils.FormatDate, latestDateStr, time.Local)
  428. if err != nil {
  429. return
  430. }
  431. // 开始预测数据的时间
  432. startDate := latestDate
  433. // 如果有筛选时间的话
  434. if filtrateStartDateStr != `` {
  435. filtrateStartDate, tmpErr := time.ParseInLocation(utils.FormatDate, filtrateStartDateStr, time.Local)
  436. if tmpErr != nil {
  437. err = tmpErr
  438. return
  439. }
  440. //如果筛选时间晚于实际数据时间,那么就以筛选时间作为获取预测数据的时间
  441. if filtrateStartDate.After(latestDate) {
  442. startDate = filtrateStartDate.AddDate(0, 0, -1)
  443. }
  444. }
  445. //var dateArr []string
  446. // 对应日期的值
  447. existMap := make(map[string]float64)
  448. for _, v := range realPredictEdbInfoData {
  449. //dateArr = append(dateArr, v.DataTime)
  450. existMap[v.DataTime] = v.Value
  451. }
  452. predictEdbInfoData = make([]*EdbInfoSearchData, 0)
  453. //dataValue := lastDataValue
  454. //预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值
  455. for _, predictEdbConf := range predictEdbConfList {
  456. dataEndTime := endDate
  457. if predictEdbConf.EndDate.Before(dataEndTime) {
  458. dataEndTime = predictEdbConf.EndDate
  459. }
  460. var tmpMinValue, tmpMaxValue float64 // 当前预测结果中的最大/最小值
  461. dayList := getPredictEdbDayList(startDate, dataEndTime, frequency)
  462. if len(dayList) <= 0 { // 如果未来没有日期的话,那么就退出当前循环,进入下一个循环
  463. continue
  464. }
  465. switch predictEdbConf.RuleType {
  466. case 1: //1:最新
  467. var lastDataValue float64 //最新值
  468. tmpAllData := make([]*EdbInfoSearchData, 0)
  469. tmpAllData = append(tmpAllData, realPredictEdbInfoData...)
  470. tmpAllData = append(tmpAllData, predictEdbInfoData...)
  471. lenTmpAllData := len(tmpAllData)
  472. if lenTmpAllData > 0 {
  473. lastDataValue = tmpAllData[lenTmpAllData-1].Value
  474. }
  475. predictEdbInfoData = GetChartPredictEdbInfoDataListByRule1(predictEdbConf.PredictEdbInfoId, lastDataValue, dayList, predictEdbInfoData, existMap)
  476. tmpMaxValue = lastDataValue
  477. tmpMinValue = lastDataValue
  478. case 2: //2:固定值
  479. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  480. if tmpErr != nil {
  481. err = tmpErr
  482. return
  483. }
  484. dataValue, _ := tmpValDecimal.Float64()
  485. predictEdbInfoData = GetChartPredictEdbInfoDataListByRule1(predictEdbConf.PredictEdbInfoId, dataValue, dayList, predictEdbInfoData, existMap)
  486. tmpMaxValue = dataValue
  487. tmpMinValue = dataValue
  488. case 3: //3:同比
  489. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  490. if tmpErr != nil {
  491. err = tmpErr
  492. return
  493. }
  494. tbValue, _ := tmpValDecimal.Float64()
  495. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTb(predictEdbConf.PredictEdbInfoId, tbValue, dayList, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  496. case 4: //4:同差
  497. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  498. if tmpErr != nil {
  499. err = tmpErr
  500. return
  501. }
  502. tcValue, _ := tmpValDecimal.Float64()
  503. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTc(predictEdbConf.PredictEdbInfoId, tcValue, dayList, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  504. case 5: //5:环比
  505. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  506. if tmpErr != nil {
  507. err = tmpErr
  508. return
  509. }
  510. hbValue, _ := tmpValDecimal.Float64()
  511. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleHb(predictEdbConf.PredictEdbInfoId, hbValue, dayList, realPredictEdbInfoData, predictEdbInfoData, existMap)
  512. case 6: //6:环差
  513. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  514. if tmpErr != nil {
  515. err = tmpErr
  516. return
  517. }
  518. hcValue, _ := tmpValDecimal.Float64()
  519. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleHc(predictEdbConf.PredictEdbInfoId, hcValue, dayList, realPredictEdbInfoData, predictEdbInfoData, existMap)
  520. case 7: //7:N期移动均值
  521. nValue, tmpErr := strconv.Atoi(predictEdbConf.Value)
  522. if tmpErr != nil {
  523. err = tmpErr
  524. return
  525. }
  526. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleNMoveMeanValue(predictEdbConf.PredictEdbInfoId, nValue, dayList, realPredictEdbInfoData, predictEdbInfoData, existMap)
  527. case 8: //8:N期段线性外推值
  528. nValue, tmpErr := strconv.Atoi(predictEdbConf.Value)
  529. if tmpErr != nil {
  530. err = tmpErr
  531. return
  532. }
  533. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleNLinearRegression(predictEdbConf.PredictEdbInfoId, nValue, dayList, realPredictEdbInfoData, predictEdbInfoData, existMap)
  534. if err != nil {
  535. return
  536. }
  537. case 9: //9:动态环差”预测规则;
  538. hcDataMap := make(map[string]float64) //规则计算的环差值map
  539. if predictEdbConf.PredictEdbInfoId > 0 {
  540. tmpPredictEdbRuleDataList, tmpErr := GetPredictEdbRuleDataItemList(predictEdbConf.PredictEdbInfoId, predictEdbConf.ConfigId, startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
  541. if tmpErr != nil {
  542. err = tmpErr
  543. return
  544. }
  545. for _, v := range tmpPredictEdbRuleDataList {
  546. hcDataMap[v.DataTime] = v.Value
  547. }
  548. } else {
  549. if len(predictEdbConf.DataList) <= 0 {
  550. return
  551. }
  552. for _, v := range predictEdbConf.DataList {
  553. currentDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  554. if tmpErr != nil {
  555. continue
  556. }
  557. // 只处理时间段内的数据
  558. if currentDate.Before(startDate) || currentDate.After(endDate) {
  559. continue
  560. }
  561. hcDataMap[v.DataTime] = v.Value
  562. }
  563. }
  564. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTrendsHC(predictEdbConf.PredictEdbInfoId, dayList, realPredictEdbInfoData, predictEdbInfoData, hcDataMap, existMap)
  565. case 10: //10:根据 给定终值后插值 规则获取预测数据
  566. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  567. if tmpErr != nil {
  568. err = tmpErr
  569. return
  570. }
  571. finalValue, _ := tmpValDecimal.Float64()
  572. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleFinalValueHc(predictEdbConf.PredictEdbInfoId, finalValue, dayList, realPredictEdbInfoData, predictEdbInfoData, existMap)
  573. case 11: //11:根据 季节性 规则获取预测数据
  574. var seasonConf SeasonConf
  575. tmpErr := json.Unmarshal([]byte(predictEdbConf.Value), &seasonConf)
  576. if tmpErr != nil {
  577. err = errors.New("季节性配置信息异常:" + tmpErr.Error())
  578. return
  579. }
  580. calendar := "公历"
  581. if seasonConf.Calendar == "农历" {
  582. calendar = "农历"
  583. }
  584. yearList := make([]int, 0)
  585. //选择方式,1:连续N年;2:指定年份
  586. if seasonConf.YearType == 1 {
  587. if seasonConf.NValue < 1 {
  588. err = errors.New("连续N年不允许小于1")
  589. return
  590. }
  591. currYear := time.Now().Year()
  592. for i := 0; i < seasonConf.NValue; i++ {
  593. yearList = append(yearList, currYear-i-1)
  594. }
  595. } else {
  596. yearList = seasonConf.YearList
  597. }
  598. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleSeason(predictEdbConf.PredictEdbInfoId, yearList, calendar, dayList, realPredictEdbInfoData, predictEdbInfoData, existMap)
  599. if err != nil {
  600. return
  601. }
  602. case 12: //12:根据 移动平均同比 规则获取预测数据
  603. var moveAverageConf MoveAverageConf
  604. tmpErr := json.Unmarshal([]byte(predictEdbConf.Value), &moveAverageConf)
  605. if tmpErr != nil {
  606. err = errors.New("季节性配置信息异常:" + tmpErr.Error())
  607. return
  608. }
  609. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleMoveAverageTb(predictEdbConf.PredictEdbInfoId, moveAverageConf.NValue, moveAverageConf.Year, dayList, realPredictEdbInfoData, predictEdbInfoData, existMap)
  610. if err != nil {
  611. return
  612. }
  613. case 13: //13:根据 同比增速差值 规则获取预测数据
  614. tmpValDecimal, tmpErr := decimal.NewFromString(predictEdbConf.Value)
  615. if tmpErr != nil {
  616. err = tmpErr
  617. return
  618. }
  619. tbEndValue, _ := tmpValDecimal.Float64()
  620. predictEdbInfoData, tmpMinValue, tmpMaxValue = GetChartPredictEdbInfoDataListByRuleTbzscz(predictEdbConf.PredictEdbInfoId, tbEndValue, dayList, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  621. case 14: //14:根据 一元线性拟合 规则获取预测数据
  622. var ruleConf RuleLineNhConf
  623. err = json.Unmarshal([]byte(predictEdbConf.Value), &ruleConf)
  624. if err != nil {
  625. err = errors.New("一元线性拟合规则配置信息异常:" + err.Error())
  626. return
  627. }
  628. // 规则计算的拟合残差值map
  629. newNhccDataMap := make(map[string]float64)
  630. if predictEdbConf.PredictEdbInfoId > 0 { //已经生成的动态数据
  631. tmpPredictEdbRuleDataList, tmpErr := GetPredictEdbRuleDataItemList(predictEdbConf.PredictEdbInfoId, predictEdbConf.ConfigId, startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
  632. if tmpErr != nil {
  633. err = tmpErr
  634. return
  635. }
  636. for _, v := range tmpPredictEdbRuleDataList {
  637. newNhccDataMap[v.DataTime] = v.Value
  638. }
  639. } else { //未生成的动态数据,需要使用外部传入的数据进行计算
  640. newNhccDataMap, err, _ = getCalculateNhccData(append(realPredictEdbInfoData, predictEdbInfoData...), ruleConf)
  641. }
  642. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleLineNh(predictEdbConf.PredictEdbInfoId, dayList, realPredictEdbInfoData, predictEdbInfoData, newNhccDataMap, existMap)
  643. if err != nil {
  644. return
  645. }
  646. case 15: //15:N年均值:过去N年同期均值。过去N年可以连续或者不连续,指标数据均用线性插值补全为日度数据后计算;
  647. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleNAnnualAverage(predictEdbConf.PredictEdbInfoId, predictEdbConf.Value, dayList, realPredictEdbInfoData, predictEdbInfoData, existMap)
  648. if err != nil {
  649. return
  650. }
  651. case 16: //16:年度值倒推
  652. predictEdbInfoData, tmpMinValue, tmpMaxValue, err = GetChartPredictEdbInfoDataListByRuleAnnualValueInversion(predictEdbConf.PredictEdbInfoId, predictEdbConf.Value, dayList, frequency, realPredictEdbInfoData, predictEdbInfoData, existMap)
  653. if err != nil {
  654. return
  655. }
  656. }
  657. // 下一个规则的开始日期
  658. {
  659. lenPredictEdbInfoData := len(predictEdbInfoData)
  660. if lenPredictEdbInfoData > 0 {
  661. tmpDataEndTime, _ := time.ParseInLocation(utils.FormatDate, predictEdbInfoData[lenPredictEdbInfoData-1].DataTime, time.Local)
  662. if startDate.Before(tmpDataEndTime) {
  663. startDate = tmpDataEndTime
  664. }
  665. }
  666. }
  667. if tmpMinValue < minValue {
  668. minValue = tmpMinValue
  669. }
  670. if tmpMaxValue < maxValue {
  671. maxValue = tmpMaxValue
  672. }
  673. }
  674. return
  675. }
  676. // GetPredictEdbDayList 获取预测指标日期列表
  677. // GetPredictEdbDayList 获取预测指标日期列表
  678. func getPredictEdbDayList(startDate, endDate time.Time, frequency string) (dayList []time.Time) {
  679. //if !utils.InArrayByStr([]string{"日度", "周度", "月度"}, frequency)
  680. switch frequency {
  681. case "日度":
  682. for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 1) {
  683. //周六、日排除
  684. if currDate.Weekday() == time.Sunday || currDate.Weekday() == time.Saturday {
  685. continue
  686. }
  687. dayList = append(dayList, currDate)
  688. }
  689. case "周度":
  690. //nextDate := startDate.AddDate(0, 0, 7)
  691. for currDate := startDate.AddDate(0, 0, 7); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 7) {
  692. dayList = append(dayList, currDate)
  693. }
  694. case "旬度":
  695. for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); {
  696. nextDate := currDate.AddDate(0, 0, 1)
  697. //每个月的10号、20号、最后一天,那么就写入
  698. if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
  699. dayList = append(dayList, currDate)
  700. }
  701. currDate = nextDate
  702. }
  703. case "月度":
  704. for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
  705. currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
  706. if !currDate.After(endDate) && !currDate.Equal(startDate) {
  707. dayList = append(dayList, currDate)
  708. }
  709. currDate = currDate.AddDate(0, 0, 1)
  710. }
  711. case "季度":
  712. for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
  713. // 每月的最后一天
  714. currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
  715. if !currDate.After(endDate) && !currDate.Equal(startDate) {
  716. // 季度日期就写入,否则不写入
  717. if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
  718. dayList = append(dayList, currDate)
  719. }
  720. }
  721. currDate = currDate.AddDate(0, 0, 1)
  722. }
  723. case "半年度":
  724. for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
  725. // 每月的最后一天
  726. currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
  727. if !currDate.After(endDate) && !currDate.Equal(startDate) {
  728. // 半年度日期就写入,否则不写入
  729. if currDate.Month() == 6 || currDate.Month() == 12 {
  730. dayList = append(dayList, currDate)
  731. }
  732. }
  733. currDate = currDate.AddDate(0, 0, 1)
  734. }
  735. case "年度":
  736. for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
  737. currDate = time.Date(currDate.Year()+1, 12, 31, 0, 0, 0, 0, time.Now().Location())
  738. if !currDate.After(endDate) && !currDate.Equal(startDate) {
  739. dayList = append(dayList, currDate)
  740. }
  741. }
  742. }
  743. return
  744. }
  745. // GetPredictDataListByPredictEdbInfo 根据预测指标信息获取预测指标的数据,order:1升序,其余值为降序
  746. func GetPredictDataListByPredictEdbInfo(edbInfo *EdbInfo, order int, startDate string) (dataList []*EdbInfoSearchData, sourceEdbInfoItem *EdbInfo, err error, errMsg string) {
  747. // 查找该预测指标配置
  748. predictEdbConfList, err := GetPredictEdbConfAndDataListById(edbInfo.EdbInfoId)
  749. if err != nil && err.Error() != utils.ErrNoRow() {
  750. errMsg = "获取预测指标配置信息失败"
  751. return
  752. }
  753. if len(predictEdbConfList) == 0 {
  754. errMsg = "获取预测指标配置信息失败"
  755. err = errors.New(errMsg)
  756. return
  757. }
  758. predictEdbConf := predictEdbConfList[0]
  759. // 来源指标
  760. sourceEdbInfoItem, err = GetEdbInfoById(predictEdbConf.SourceEdbInfoId)
  761. if err != nil {
  762. if err.Error() == utils.ErrNoRow() {
  763. errMsg = "找不到来源指标信息"
  764. err = errors.New(errMsg)
  765. }
  766. return
  767. }
  768. dataList, err, errMsg = GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem, predictEdbConfList, order, startDate)
  769. return
  770. }
  771. // GetPredictDataListByPredictEdbConfList 根据预测指标信息获取预测指标的数据,order:1升序,其余值为降序
  772. func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo, predictEdbConfList []*PredictEdbConfAndData, order int, startDate string) (dataList []*EdbInfoSearchData, err error, errMsg string) {
  773. allDataList := make([]*EdbInfoSearchData, 0)
  774. //获取指标数据(实际已生成)
  775. var condition string
  776. var pars []interface{}
  777. condition += " AND edb_info_id=? "
  778. pars = append(pars, sourceEdbInfoItem.EdbInfoId)
  779. if startDate != "" {
  780. condition += " AND data_time>=? "
  781. pars = append(pars, startDate)
  782. }
  783. tmpDataList, err := GetEdbDataListAll(condition, pars, sourceEdbInfoItem.Source, 1)
  784. if err != nil {
  785. return
  786. }
  787. // 如果选择了日期,那么需要筛选所有的数据,用于未来指标的生成
  788. if startDate != `` {
  789. allDataList, err = GetEdbDataListAll(" AND edb_info_id=? ", []interface{}{sourceEdbInfoItem.EdbInfoId}, sourceEdbInfoItem.Source, 1)
  790. if err != nil {
  791. return
  792. }
  793. } else {
  794. allDataList = tmpDataList
  795. }
  796. // 获取预测指标未来的数据
  797. predictDataList := make([]*EdbInfoSearchData, 0)
  798. endDateStr := edbInfo.EndDate //预测指标的结束日期
  799. var predictMinValue, predictMaxValue float64
  800. // 如果有配置的预测规则,那么就进行预测
  801. if len(predictEdbConfList) > 0 {
  802. predictDataList, predictMinValue, predictMaxValue, err = GetChartPredictEdbInfoDataListByConfList(predictEdbConfList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, edbInfo.Frequency, allDataList)
  803. if err != nil {
  804. return
  805. }
  806. }
  807. //order:1升序,其余值为降序
  808. if order == 1 {
  809. dataList = append(tmpDataList, predictDataList...)
  810. } else {
  811. // 先倒序预测数据
  812. lenPredictDataList := len(predictDataList)
  813. if lenPredictDataList > 0 {
  814. for k := range predictDataList {
  815. dataList = append(dataList, predictDataList[lenPredictDataList-k-1])
  816. }
  817. }
  818. // 接着倒序实际指标
  819. lenDataList := len(tmpDataList)
  820. for k := range tmpDataList {
  821. dataList = append(dataList, tmpDataList[lenDataList-k-1])
  822. }
  823. }
  824. if len(predictDataList) > 0 {
  825. // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
  826. if edbInfo.MinValue > predictMinValue {
  827. edbInfo.MinValue = predictMinValue
  828. }
  829. // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
  830. if edbInfo.MaxValue < predictMaxValue {
  831. edbInfo.MaxValue = predictMaxValue
  832. }
  833. }
  834. return
  835. }
  836. // GetPredictEdbDataListAll 获取该预测指标所有的数据 ,order:1升序,其余值为降序
  837. func GetPredictEdbDataListAll(edbInfo *EdbInfo, order int) (items []*EdbInfoSearchData, err error) {
  838. if edbInfo.Source == utils.DATA_SOURCE_PREDICT { //普通的预测指标是没有入库数据的,直接往配置里面获取
  839. items, _, err, _ = GetPredictDataListByPredictEdbInfo(edbInfo, 1, "")
  840. } else {
  841. var condition string
  842. var pars []interface{}
  843. condition += " AND edb_info_id=? "
  844. pars = append(pars, edbInfo.EdbInfoId)
  845. items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, order)
  846. }
  847. return
  848. }
  849. // GetPredictEdbDataListAllByStartDate 根据开始日期获取该预测指标所有的数据 ,order:1升序,其余值为降序
  850. func GetPredictEdbDataListAllByStartDate(edbInfo *EdbInfo, order int, startDate string) (items []*EdbInfoSearchData, err error) {
  851. if edbInfo.Source == utils.DATA_SOURCE_PREDICT { //普通的预测指标是没有入库数据的,直接往配置里面获取
  852. items, _, err, _ = GetPredictDataListByPredictEdbInfo(edbInfo, order, startDate)
  853. } else {
  854. var condition string
  855. var pars []interface{}
  856. condition += " AND edb_info_id=? "
  857. pars = append(pars, edbInfo.EdbInfoId)
  858. if startDate != "" {
  859. condition += " AND data_time>=? "
  860. pars = append(pars, startDate)
  861. }
  862. items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, order)
  863. }
  864. return
  865. }
  866. // ModifyPredictEdbInfoMaxAndMinInfo 修改预测指标的最新数据信息
  867. func ModifyPredictEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  868. o := orm.NewOrm()
  869. sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,modify_time=NOW() WHERE edb_info_id=? `
  870. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.LatestDate, item.LatestValue, edbInfoId).Exec()
  871. return
  872. }
  873. // ModifyCalculateEdbInfo 修改计算指标信息
  874. func ModifyCalculateEdbInfo(edbName, frequency, unit, calculateFormula string, classifyId, edbInfoId int) (err error) {
  875. o := orm.NewOrm()
  876. sql := ` UPDATE edb_info
  877. SET
  878. edb_name =?,
  879. edb_name_source =?,
  880. frequency = ?,
  881. unit = ?,
  882. classify_id = ?,
  883. calculate_formula=?,
  884. modify_time = NOW()
  885. WHERE edb_info_id = ?`
  886. _, err = o.Raw(sql, edbName, edbName, frequency, unit, classifyId, calculateFormula, edbInfoId).Exec()
  887. return
  888. }
  889. func GetEdbInfoItemByCondition(condition string, pars []interface{}) (item *EdbInfoList, err error) {
  890. o := orm.NewOrm()
  891. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  892. if condition != "" {
  893. sql += condition
  894. }
  895. err = o.Raw(sql, pars).QueryRow(&item)
  896. return
  897. }
  898. // EdbInfoDetailReq 指标详情请求
  899. type EdbInfoDetailReq struct {
  900. UniqueCode string `description:"指标唯一编码"`
  901. }
  902. // EdbInfoDetailResp 指标详情返回
  903. type EdbInfoDetailResp struct {
  904. SourceName string `description:"来源名称"`
  905. EdbCode string `description:"指标编码"`
  906. EdbName string `description:"指标名称"`
  907. EdbNameSource string `description:"指标名称来源"`
  908. Frequency string `description:"频率"`
  909. Unit string `description:"单位"`
  910. StartDate string `description:"起始日期"`
  911. EndDate string `description:"终止日期"`
  912. UniqueCode string `description:"指标唯一编码"`
  913. CreateTime time.Time
  914. ModifyTime time.Time
  915. MinValue float64 `description:"指标最小值"`
  916. MaxValue float64 `description:"指标最大值"`
  917. EdbNameEn string `description:"英文指标名称"`
  918. UnitEn string `description:"英文单位"`
  919. LatestDate string `description:"数据最新日期"`
  920. LatestValue float64 `description:"数据最新值"`
  921. ChartImage string `description:"图表图片"`
  922. DataList []*EdbInfoSearchData
  923. }