base_from_oilchem.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/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. sql := "SELECT * FROM base_from_oilchem_classify ORDER BY sort ASC"
  39. err = global.DmSQL["data"].Raw(sql).Scan(&list).Error
  40. return
  41. }
  42. type BaseFromOilchemIndexList struct {
  43. BaseFromOilchemIndexId int // 主键ID
  44. IndexCode string // 指标编码
  45. IndexName string // 指标名称
  46. ClassifyId int // 分类ID
  47. Unit string // 单位
  48. Frequency string // 频度
  49. Describe string // 指标描述
  50. Sort int // 排序
  51. CreateTime string // 创建时间
  52. ModifyTime string // 修改时间
  53. EdbExist int `description:"edb是否存在"`
  54. DataList []*BaseFromOilchemData
  55. Paging *paging.PagingItem `description:"分页数据"`
  56. }
  57. type BaseFromOilchemIndexListResp struct {
  58. List []*BaseFromOilchemIndexView
  59. Paging *paging.PagingItem `description:"分页数据"`
  60. }
  61. func GetOilchemIndexByCode(indexCode string) (item *BaseFromOilchemIndexView, err error) {
  62. o := global.DmSQL["data"]
  63. sql := ` SELECT a.*,CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
  64. FROM base_from_oilchem_index as a
  65. LEFT JOIN edb_info AS e ON a.index_code=e.edb_code AND e.source=89
  66. WHERE 1=1 and a.index_code = ? `
  67. sql += `ORDER BY a.base_from_oilchem_index_id ASC `
  68. err = o.Raw(sql, indexCode).Scan(&item).Error
  69. return
  70. }
  71. func GetOilchemIndexListCount(condition string, pars []interface{}) (count int, err error) {
  72. sql := ` SELECT COUNT(1) AS count FROM base_from_oilchem_index WHERE 1=1 `
  73. if condition != "" {
  74. sql += condition
  75. }
  76. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
  77. return
  78. }
  79. func GetOilchemDataListCount(condition string, pars []interface{}) (count int, err error) {
  80. sql := ` SELECT COUNT(1) AS count FROM base_from_oilchem_data WHERE 1=1 `
  81. if condition != "" {
  82. sql += condition
  83. }
  84. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
  85. return
  86. }
  87. func GetOilchemIndexData(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromOilchemData, err error) {
  88. sql := ` SELECT * FROM base_from_oilchem_data WHERE 1=1 `
  89. if condition != "" {
  90. sql += condition
  91. }
  92. sql += ` order by data_time DESC LIMIT ?,? `
  93. err = global.DmSQL["data"].Raw(sql, pars, startSize, pageSize).Scan(&items).Error
  94. return
  95. }
  96. // GetOilchemItemList 模糊查询隆众资讯数据库指标列表
  97. func GetOilchemItemList(keyword string) (items []*BaseFromOilchemIndex, err error) {
  98. sql := "SELECT * FROM base_from_oilchem_index WHERE CONCAT(index_name,index_code) LIKE ? "
  99. err = global.DmSQL["data"].Raw(sql, utils.GetLikeKeyword(keyword)).Scan(&items).Error
  100. return
  101. }
  102. // OilchemDataBatchListReq 隆众资讯指标批量列表
  103. type OilchemDataBatchListReq struct {
  104. ClassifyId int `description:"分类id"`
  105. KeyWord string `description:"关键字"`
  106. SelectedId []int `description:"已选指标id, 为true时表示反选"`
  107. IsSelectAll bool `description:"是否查询全部, 默认false, true:全选, false:查询已选"`
  108. }
  109. // GetOilchemIndexByCondition 根据条件获取隆众资讯指标列表
  110. func GetOilchemIndexByCondition(condition string, pars []interface{}) (items []*BaseFromOilchemIndex, err error) {
  111. sql := ` SELECT * FROM base_from_oilchem_index WHERE 1=1 `
  112. if condition != "" {
  113. sql += condition
  114. }
  115. sql += ` ORDER BY sort ASC, base_from_oilchem_index_id ASC`
  116. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&items).Error
  117. return
  118. }
  119. // OilchemDataBatchAddCheckReq 隆众资讯指标批量添加校验
  120. type OilchemDataBatchAddCheckReq struct {
  121. IndexCodes []string `description:"指标编码"`
  122. }
  123. // GetOilchemIndexAndEdbInfoByCondition 根据条件获取隆众资讯index和指标库的信息
  124. func GetOilchemIndexAndEdbInfoByCondition(condition string, pars []interface{}) (items []*BaseFromOilchemIndexView, err error) {
  125. 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 `
  126. if condition != "" {
  127. sql += condition
  128. }
  129. sql += ` ORDER BY sort ASC `
  130. err = global.DmSQL["data"].Raw(sql, utils.ForwardPars(pars, utils.DATA_SOURCE_OILCHEM)...).Scan(&items).Error
  131. return
  132. }
  133. type BaseFromOilchemIndexView struct {
  134. BaseFromOilchemIndexId int `orm:"pk" gorm:"primaryKey" `
  135. EdbInfoId int `description:"指标库id"`
  136. ClassifyId int `description:"指标分类id"`
  137. IndexCode string `description:"指标编码"`
  138. IndexName string `description:"指标名称"`
  139. UniqueCode string `description:"唯一code"`
  140. Frequency string `description:"频度"`
  141. Unit string `description:"单位"`
  142. StartDate string `description:"开始日期"`
  143. EndDate string `description:"结束日期"`
  144. Sort int `description:"排序"`
  145. EdbExist int `description:"edb是否存在"`
  146. EdbClassifyId int `description:"edb分类id"`
  147. ModifyTime string
  148. DataTime string `description:"数据时间"`
  149. Value string `description:"值"`
  150. }
  151. // ExportOilchemExcelReq 导出隆众资讯excel指标
  152. type ExportOilchemExcelReq struct {
  153. KeyWord string `description:"关键字, 指标编码或指标ID"`
  154. IndexCode []string `description:"指标编码,全选时,表示反选"`
  155. IsSelectedAll bool `description:"是否全选:true:全选|false: 无"`
  156. ClassifyId int `description:"指标id"`
  157. }
  158. // GetOilchemIndexByConditionAndFrequency 根据条件获取隆众资讯指标列表
  159. func GetOilchemIndexByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromOilchemIndex, err error) {
  160. sql := ` SELECT * FROM base_from_oilchem_index WHERE 1=1 `
  161. if condition != "" {
  162. sql += condition
  163. }
  164. sql += ` AND frequency=?`
  165. sql += ` ORDER BY sort ASC, base_from_oilchem_index_id ASC`
  166. err = global.DmSQL["data"].Raw(sql, pars, frequency).Scan(&items).Error
  167. return
  168. }
  169. func GetOilchemIndexDataByCode(indexCode string) (items []*BaseFromOilchemData, err error) {
  170. sql := ` SELECT * FROM base_from_oilchem_data WHERE index_code=? ORDER BY data_time DESC `
  171. err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&items).Error
  172. return
  173. }
  174. func GetOilchemFrequencyByCondition(condition string, pars []interface{}) (items []*string, err error) {
  175. sql := `SELECT DISTINCT frequency FROM base_from_oilchem_index WHERE 1=1 `
  176. if condition != "" {
  177. sql += condition
  178. }
  179. sql += ` ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
  180. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&items).Error
  181. return
  182. }
  183. // GetOilchemIndexViewList 根据分类id获取隆众资讯指标列表
  184. func GetOilchemIndexViewList(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromOilchemIndexView, err error) {
  185. o := global.DmSQL["data"]
  186. sql := ` SELECT b.*, e.edb_info_id,
  187. CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
  188. FROM base_from_oilchem_index AS b
  189. LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=89
  190. WHERE 1=1 `
  191. if condition != "" {
  192. sql += condition
  193. }
  194. sql += ` ORDER BY b.modify_time ASC LIMIT ?,? `
  195. pars = append(pars, startSize)
  196. pars = append(pars, pageSize)
  197. err = o.Raw(sql, pars...).Scan(&items).Error
  198. return
  199. }
  200. // GetOilchemIndexViewListCount 根据分类id获取隆众资讯指标列表
  201. func GetOilchemIndexViewListCount(condition string, pars []interface{}) (count int, err error) {
  202. o := global.DmSQL["data"]
  203. sql := ` SELECT COUNT(1) AS count
  204. FROM base_from_oilchem_index AS b
  205. LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=89
  206. WHERE 1=1 `
  207. if condition != "" {
  208. sql += condition
  209. }
  210. sql += ` ORDER BY b.modify_time ASC `
  211. err = o.Raw(sql, pars...).Scan(&count).Error
  212. return
  213. }
  214. // GetOilchemDataViewList 根据指标id获取隆众资讯指标列表
  215. func GetOilchemDataViewList(indexIds []int) (items []*BaseFromOilchemData, err error) {
  216. sql := ` SELECT * FROM base_from_oilchem_data WHERE base_from_oilchem_index_id IN (` + utils.GetOrmInReplace(len(indexIds)) + `)ORDER BY data_time desc `
  217. err = global.DmSQL["data"].Raw(sql, indexIds).Scan(&items).Error
  218. return
  219. }
  220. // GetOilchemDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  221. func GetOilchemDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  222. if len(indexIdList) == 0 {
  223. return
  224. }
  225. 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`
  226. err = global.DmSQL["data"].Raw(sql, indexIdList).Scan(&items).Error
  227. return
  228. }