base_from_oilchem.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package data_manage
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. )
  7. type BaseFromOilchemClassify struct {
  8. BaseFromOilchemClassifyId int // 分类ID
  9. ClassifyName string // 分类名称
  10. ParentID int // 上级ID
  11. Level int // 层级
  12. Sort int // 排序
  13. CreateTime string // 创建时间
  14. ModifyTime string // 修改时间
  15. }
  16. type BaseFromOilchemIndex struct {
  17. BaseFromOilchemIndexId int // 主键ID
  18. IndexCode string // 指标编码
  19. IndexName string // 指标名称
  20. ClassifyId uint // 分类ID
  21. Unit string // 单位
  22. Frequency string // 频度
  23. Describe string // 指标描述
  24. Sort int // 排序
  25. CreateTime string // 创建时间
  26. ModifyTime string // 修改时间
  27. }
  28. type BaseFromOilchemData struct {
  29. BaseFromOilchemDataId int // 数据表ID
  30. BaseFromOilchemIndexId int // 指标ID
  31. IndexCode string // 指标编码
  32. DataTime string
  33. Value string
  34. CreateTime string
  35. ModifyTime string
  36. }
  37. func GetOilchemClassifyList() (list []*BaseFromOilchemClassify, err error) {
  38. o := global.DbMap[utils.DbNameIndex]
  39. sql := "SELECT * FROM base_from_oilchem_classify ORDER BY sort ASC"
  40. err = o.Raw(sql).Find(&list).Error
  41. return
  42. }
  43. type BaseFromOilchemIndexList struct {
  44. BaseFromOilchemIndexId int // 主键ID
  45. IndexCode string // 指标编码
  46. IndexName string // 指标名称
  47. ClassifyId int // 分类ID
  48. Unit string // 单位
  49. Frequency string // 频度
  50. Describe string // 指标描述
  51. Sort int // 排序
  52. CreateTime string // 创建时间
  53. ModifyTime string // 修改时间
  54. EdbExist int `description:"edb是否存在"`
  55. DataList []*BaseFromOilchemData
  56. Paging *paging.PagingItem `description:"分页数据"`
  57. }
  58. type BaseFromOilchemIndexListResp struct {
  59. List []*BaseFromOilchemIndexView
  60. Paging *paging.PagingItem `description:"分页数据"`
  61. }
  62. func GetOilchemIndexById(indexId int) (item *BaseFromOilchemIndex, err error) {
  63. o := global.DbMap[utils.DbNameIndex]
  64. sql := ` SELECT * FROM base_from_oilchem_index WHERE 1=1 base_from_oilchem_index_id = ? `
  65. sql += `ORDER BY base_from_oilchem_index_id ASC `
  66. err = o.Raw(sql, indexId).First(&item).Error
  67. return
  68. }
  69. func GetOilchemIndexByCode(indexCode string) (item *BaseFromOilchemIndexView, err error) {
  70. o := global.DbMap[utils.DbNameIndex]
  71. sql := ` SELECT a.*,CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
  72. FROM base_from_oilchem_index as a
  73. LEFT JOIN edb_info AS e ON a.index_code=e.edb_code AND e.source=89
  74. WHERE 1=1 and a.index_code = ? `
  75. sql += `ORDER BY a.base_from_oilchem_index_id ASC `
  76. err = o.Raw(sql, indexCode).First(&item).Error
  77. return
  78. }
  79. func GetOilchemIndexList(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromOilchemIndex, err error) {
  80. o := global.DbMap[utils.DbNameIndex]
  81. sql := ` SELECT * FROM base_from_oilchem_index WHERE 1=1 `
  82. if condition != "" {
  83. sql += condition
  84. }
  85. sql += `group BY index_code ASC order by create_time DESC LIMIT ?,? `
  86. err = o.Raw(sql, pars, startSize, pageSize).Find(&items).Error
  87. return
  88. }
  89. func GetOilchemIndexListCount(condition string, pars interface{}) (count int, err error) {
  90. o := global.DbMap[utils.DbNameIndex]
  91. sql := ` SELECT COUNT(1) AS count FROM base_from_oilchem_index WHERE 1=1 `
  92. if condition != "" {
  93. sql += condition
  94. }
  95. err = o.Raw(sql, pars).Scan(&count).Error
  96. return
  97. }
  98. func GetOilchemDataListCount(condition string, pars interface{}) (count int, err error) {
  99. o := global.DbMap[utils.DbNameIndex]
  100. sql := ` SELECT COUNT(1) AS count FROM base_from_oilchem_data WHERE 1=1 `
  101. if condition != "" {
  102. sql += condition
  103. }
  104. err = o.Raw(sql, pars).Scan(&count).Error
  105. return
  106. }
  107. func GetOilchemIndexData(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromOilchemData, err error) {
  108. o := global.DbMap[utils.DbNameIndex]
  109. sql := ` SELECT * FROM base_from_oilchem_data WHERE 1=1 `
  110. if condition != "" {
  111. sql += condition
  112. }
  113. sql += ` order by data_time DESC LIMIT ?,? `
  114. err = o.Raw(sql, pars, startSize, pageSize).Find(&items).Error
  115. return
  116. }
  117. // GetOilchemItemList 模糊查询隆众资讯数据库指标列表
  118. func GetOilchemItemList(keyword string) (items []*BaseFromOilchemIndex, err error) {
  119. o := global.DbMap[utils.DbNameIndex]
  120. sql := "SELECT * FROM base_from_oilchem_index WHERE CONCAT(index_name,index_code) LIKE ? "
  121. err = o.Raw(sql, utils.GetLikeKeyword(keyword)).Find(&items).Error
  122. return
  123. }
  124. // OilchemDataBatchListReq 隆众资讯指标批量列表
  125. type OilchemDataBatchListReq struct {
  126. ClassifyId int `description:"分类id"`
  127. KeyWord string `description:"关键字"`
  128. SelectedId []int `description:"已选指标id, 为true时表示反选"`
  129. IsSelectAll bool `description:"是否查询全部, 默认false, true:全选, false:查询已选"`
  130. }
  131. // GetOilchemIndexByCondition 根据条件获取隆众资讯指标列表
  132. func GetOilchemIndexByCondition(condition string, pars []interface{}) (items []*BaseFromOilchemIndex, err error) {
  133. o := global.DbMap[utils.DbNameIndex]
  134. sql := ` SELECT * FROM base_from_oilchem_index WHERE 1=1 `
  135. if condition != "" {
  136. sql += condition
  137. }
  138. sql += ` ORDER BY sort ASC, base_from_oilchem_index_id ASC`
  139. err = o.Raw(sql, pars...).Find(&items).Error
  140. return
  141. }
  142. // OilchemDataBatchAddCheckReq 隆众资讯指标批量添加校验
  143. type OilchemDataBatchAddCheckReq struct {
  144. IndexCodes []string `description:"指标编码"`
  145. }
  146. // GetOilchemIndexAndEdbInfoByCondition 根据条件获取隆众资讯index和指标库的信息
  147. func GetOilchemIndexAndEdbInfoByCondition(condition string, pars []interface{}) (items []*BaseFromOilchemIndexView, err error) {
  148. wherePars := make([]interface{}, 0)
  149. wherePars = append(wherePars, utils.DATA_SOURCE_OILCHEM)
  150. wherePars = append(wherePars, pars...)
  151. o := global.DbMap[utils.DbNameIndex]
  152. sql := ` SELECT b.*, e.edb_info_id, e.unique_code, e.classify_id AS edb_classify_id FROM base_from_oilchem_index AS b LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=? WHERE 1=1 `
  153. if condition != "" {
  154. sql += condition
  155. }
  156. sql += ` ORDER BY sort ASC `
  157. err = o.Raw(sql, wherePars...).Find(&items).Error
  158. return
  159. }
  160. type BaseFromOilchemIndexView struct {
  161. BaseFromOilchemIndexId int `orm:"pk" gorm:"primaryKey"`
  162. EdbInfoId int `description:"指标库id"`
  163. ClassifyId int `description:"指标分类id"`
  164. IndexCode string `description:"指标编码"`
  165. IndexName string `description:"指标名称"`
  166. UniqueCode string `description:"唯一code"`
  167. Frequency string `description:"频度"`
  168. Unit string `description:"单位"`
  169. StartDate string `description:"开始日期"`
  170. EndDate string `description:"结束日期"`
  171. Sort int `description:"排序"`
  172. EdbExist int `description:"edb是否存在"`
  173. EdbClassifyId int `description:"edb分类id"`
  174. ModifyTime string
  175. DataTime string `description:"数据时间"`
  176. Value string `description:"值"`
  177. }
  178. // ExportOilchemExcelReq 导出隆众资讯excel指标
  179. type ExportOilchemExcelReq struct {
  180. KeyWord string `description:"关键字, 指标编码或指标ID"`
  181. IndexCode []string `description:"指标编码,全选时,表示反选"`
  182. IsSelectedAll bool `description:"是否全选:true:全选|false: 无"`
  183. ClassifyId int `description:"指标id"`
  184. }
  185. // GetOilchemIndexByConditionAndFrequency 根据条件获取隆众资讯指标列表
  186. func GetOilchemIndexByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromOilchemIndex, err error) {
  187. o := global.DbMap[utils.DbNameIndex]
  188. sql := ` SELECT * FROM base_from_oilchem_index WHERE 1=1 `
  189. if condition != "" {
  190. sql += condition
  191. }
  192. sql += ` AND frequency=?`
  193. sql += ` ORDER BY sort ASC, base_from_oilchem_index_id ASC`
  194. err = o.Raw(sql, pars, frequency).Find(&items).Error
  195. return
  196. }
  197. func GetOilchemDataMaxCount(classifyId int) (count int, err error) {
  198. o := global.DbMap[utils.DbNameIndex]
  199. sql := `SELECT COALESCE(MAX(t.num), 0) AS count FROM (
  200. SELECT COUNT(1) AS num FROM base_from_oilchem_index AS a
  201. INNER JOIN base_from_oilchem_data AS b ON a.index_code=b.index_code
  202. WHERE a.classify_id=?
  203. GROUP BY a.base_from_oilchem_index_id
  204. )AS t `
  205. err = o.Raw(sql, classifyId).Scan(&count).Error
  206. return
  207. }
  208. func GetOilchemIndexDataByCode(indexCode string) (items []*BaseFromOilchemData, err error) {
  209. o := global.DbMap[utils.DbNameIndex]
  210. sql := ` SELECT * FROM base_from_oilchem_data WHERE index_code=? ORDER BY data_time DESC `
  211. err = o.Raw(sql, indexCode).Find(&items).Error
  212. return
  213. }
  214. func GetOilchemFrequencyByCondition(condition string, pars []interface{}) (items []*string, err error) {
  215. sql := `SELECT DISTINCT frequency FROM base_from_oilchem_index WHERE 1=1 `
  216. if condition != "" {
  217. sql += condition
  218. }
  219. sql += ` ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
  220. o := global.DbMap[utils.DbNameIndex]
  221. err = o.Raw(sql, pars...).Find(&items).Error
  222. return
  223. }
  224. // GetOilchemIndexViewList 根据分类id获取隆众资讯指标列表
  225. func GetOilchemIndexViewList(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromOilchemIndexView, err error) {
  226. o := global.DbMap[utils.DbNameIndex]
  227. sql := ` SELECT b.*, e.edb_info_id,
  228. CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
  229. FROM base_from_oilchem_index AS b
  230. LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=89
  231. WHERE 1=1 `
  232. if condition != "" {
  233. sql += condition
  234. }
  235. sql += ` ORDER BY b.modify_time ASC LIMIT ?,? `
  236. pars = append(pars, startSize, pageSize)
  237. err = o.Raw(sql, pars...).Find(&items).Error
  238. return
  239. }
  240. // GetOilchemIndexViewListCount 根据分类id获取隆众资讯指标列表
  241. func GetOilchemIndexViewListCount(condition string, pars []interface{}) (count int, err error) {
  242. o := global.DbMap[utils.DbNameIndex]
  243. sql := ` SELECT COUNT(1) AS count
  244. FROM base_from_oilchem_index AS b
  245. LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=89
  246. WHERE 1=1 `
  247. if condition != "" {
  248. sql += condition
  249. }
  250. sql += ` ORDER BY b.modify_time ASC `
  251. err = o.Raw(sql, pars...).Scan(&count).Error
  252. return
  253. }
  254. // GetOilchemDataViewList 根据指标id获取隆众资讯指标列表
  255. func GetOilchemDataViewList(indexIds []int) (items []*BaseFromOilchemData, err error) {
  256. o := global.DbMap[utils.DbNameIndex]
  257. sql := ` SELECT * FROM base_from_oilchem_data WHERE base_from_oilchem_index_id IN (` + utils.GetOrmInReplace(len(indexIds)) + `)ORDER BY data_time desc `
  258. err = o.Raw(sql, indexIds).Find(&items).Error
  259. return
  260. }
  261. // GetOilchemDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  262. func GetOilchemDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  263. if len(indexIdList) == 0 {
  264. return
  265. }
  266. o := global.DbMap[utils.DbNameIndex]
  267. sql := ` SELECT DISTINCT data_time FROM base_from_oilchem_data WHERE base_from_oilchem_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
  268. err = o.Raw(sql, indexIdList).Find(&items).Error
  269. return
  270. }