base_from_oilchem.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  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 := orm.NewOrmUsingDB("data")
  39. sql := "SELECT * FROM base_from_oilchem_classify ORDER BY sort ASC"
  40. _, err = o.Raw(sql).QueryRows(&list)
  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 := orm.NewOrmUsingDB("data")
  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).QueryRow(&item)
  67. return
  68. }
  69. func GetOilchemIndexByCode(indexCode string) (item *BaseFromOilchemIndexView, err error) {
  70. o := orm.NewOrmUsingDB("data")
  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).QueryRow(&item)
  77. return
  78. }
  79. func GetOilchemIndexList(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromOilchemIndex, err error) {
  80. o := orm.NewOrmUsingDB("data")
  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).QueryRows(&items)
  87. return
  88. }
  89. func GetOilchemIndexListCount(condition string, pars interface{}) (count int, err error) {
  90. o := orm.NewOrmUsingDB("data")
  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).QueryRow(&count)
  96. return
  97. }
  98. func GetOilchemDataListCount(condition string, pars interface{}) (count int, err error) {
  99. o := orm.NewOrmUsingDB("data")
  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).QueryRow(&count)
  105. return
  106. }
  107. func GetOilchemIndexData(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromOilchemData, err error) {
  108. o := orm.NewOrmUsingDB("data")
  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).QueryRows(&items)
  115. return
  116. }
  117. // GetOilchemItemList 模糊查询隆众资讯数据库指标列表
  118. func GetOilchemItemList(keyword string) (items []*BaseFromOilchemIndex, err error) {
  119. o := orm.NewOrmUsingDB("data")
  120. sql := "SELECT * FROM base_from_oilchem_index WHERE CONCAT(index_name,index_code) LIKE ? "
  121. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
  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 := orm.NewOrmUsingDB("data")
  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).QueryRows(&items)
  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. o := orm.NewOrmUsingDB("data")
  149. 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 `
  150. if condition != "" {
  151. sql += condition
  152. }
  153. sql += ` ORDER BY sort ASC `
  154. _, err = o.Raw(sql, utils.DATA_SOURCE_OILCHEM, pars).QueryRows(&items)
  155. return
  156. }
  157. type BaseFromOilchemIndexView struct {
  158. BaseFromOilchemIndexId int `orm:"pk"`
  159. EdbInfoId int `description:"指标库id"`
  160. ClassifyId int `description:"指标分类id"`
  161. IndexCode string `description:"指标编码"`
  162. IndexName string `description:"指标名称"`
  163. UniqueCode string `description:"唯一code"`
  164. Frequency string `description:"频度"`
  165. Unit string `description:"单位"`
  166. StartDate string `description:"开始日期"`
  167. EndDate string `description:"结束日期"`
  168. Sort int `description:"排序"`
  169. EdbExist int `description:"edb是否存在"`
  170. EdbClassifyId int `description:"edb分类id"`
  171. ModifyTime string
  172. DataTime string `description:"数据时间"`
  173. Value string `description:"值"`
  174. }
  175. // ExportOilchemExcelReq 导出隆众资讯excel指标
  176. type ExportOilchemExcelReq struct {
  177. KeyWord string `description:"关键字, 指标编码或指标ID"`
  178. IndexCode []string `description:"指标编码,全选时,表示反选"`
  179. IsSelectedAll bool `description:"是否全选:true:全选|false: 无"`
  180. ClassifyId int `description:"指标id"`
  181. }
  182. // GetOilchemIndexByConditionAndFrequency 根据条件获取隆众资讯指标列表
  183. func GetOilchemIndexByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromOilchemIndex, err error) {
  184. o := orm.NewOrmUsingDB("data")
  185. sql := ` SELECT * FROM base_from_oilchem_index WHERE 1=1 `
  186. if condition != "" {
  187. sql += condition
  188. }
  189. sql += ` AND frequency=?`
  190. sql += ` ORDER BY sort ASC, base_from_oilchem_index_id ASC`
  191. _, err = o.Raw(sql, pars, frequency).QueryRows(&items)
  192. return
  193. }
  194. func GetOilchemDataMaxCount(classifyId int) (count int, err error) {
  195. o := orm.NewOrmUsingDB("data")
  196. sql := `SELECT MAX(t.num) AS count FROM (
  197. SELECT COUNT(1) AS num FROM base_from_oilchem_index AS a
  198. INNER JOIN base_from_oilchem_data AS b ON a.index_code=b.index_code
  199. WHERE a.classify_id=?
  200. GROUP BY a.base_from_oilchem_index_id
  201. )AS t `
  202. err = o.Raw(sql, classifyId).QueryRow(&count)
  203. return
  204. }
  205. func GetOilchemIndexDataByCode(indexCode string) (items []*BaseFromOilchemData, err error) {
  206. o := orm.NewOrmUsingDB("data")
  207. sql := ` SELECT * FROM base_from_oilchem_data WHERE index_code=? ORDER BY data_time DESC `
  208. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  209. return
  210. }
  211. func GetOilchemFrequencyByCondition(condition string, pars []interface{}) (items []*string, err error) {
  212. sql := `SELECT DISTINCT frequency FROM base_from_oilchem_index WHERE 1=1 `
  213. if condition != "" {
  214. sql += condition
  215. }
  216. sql += ` ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
  217. o := orm.NewOrmUsingDB("data")
  218. _, err = o.Raw(sql, pars...).QueryRows(&items)
  219. return
  220. }
  221. // GetOilchemIndexViewList 根据分类id获取隆众资讯指标列表
  222. func GetOilchemIndexViewList(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromOilchemIndexView, err error) {
  223. o := orm.NewOrmUsingDB("data")
  224. sql := ` SELECT b.*, e.edb_info_id,
  225. CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
  226. FROM base_from_oilchem_index AS b
  227. LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=89
  228. WHERE 1=1 `
  229. if condition != "" {
  230. sql += condition
  231. }
  232. sql += ` ORDER BY b.modify_time ASC LIMIT ?,? `
  233. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  234. return
  235. }
  236. // GetOilchemIndexViewListCount 根据分类id获取隆众资讯指标列表
  237. func GetOilchemIndexViewListCount(condition string, pars []interface{}) (count int, err error) {
  238. o := orm.NewOrmUsingDB("data")
  239. sql := ` SELECT COUNT(1) AS count
  240. FROM base_from_oilchem_index AS b
  241. LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=89
  242. WHERE 1=1 `
  243. if condition != "" {
  244. sql += condition
  245. }
  246. sql += ` ORDER BY b.modify_time ASC `
  247. err = o.Raw(sql, pars).QueryRow(&count)
  248. return
  249. }
  250. // GetOilchemDataViewList 根据指标id获取隆众资讯指标列表
  251. func GetOilchemDataViewList(indexIds []int) (items []*BaseFromOilchemData, err error) {
  252. o := orm.NewOrmUsingDB("data")
  253. sql := ` SELECT * FROM base_from_oilchem_data WHERE base_from_oilchem_index_id IN (` + utils.GetOrmInReplace(len(indexIds)) + `)ORDER BY data_time desc `
  254. _, err = o.Raw(sql, indexIds).QueryRows(&items)
  255. return
  256. }
  257. // GetOilchemDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  258. func GetOilchemDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  259. if len(indexIdList) == 0 {
  260. return
  261. }
  262. o := orm.NewOrmUsingDB("data")
  263. 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`
  264. _, err = o.Raw(sql, indexIdList).QueryRows(&items)
  265. return
  266. }