edb_info_updates.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_eta_api/models"
  6. "hongze/hz_eta_api/models/data_manage"
  7. "hongze/hz_eta_api/services/data"
  8. "hongze/hz_eta_api/utils"
  9. "time"
  10. )
  11. // @Title 指标一键刷新-统计
  12. // @Description 指标一键刷新-统计接口
  13. // @Success 200 {object} data_manage.UpdatesStatisticalResp
  14. // @router /edb_info/updates/statistical [get]
  15. func (this *EdbInfoController) EdbInfoUpdatesStatistical() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. var condition string
  22. var pars []interface{}
  23. condition += ` AND is_update=? AND edb_info_type = ?`
  24. pars = append(pars, 2, 0)
  25. updateList, _ := data_manage.GetUpdatesStatistical(condition, pars)
  26. resp := new(data_manage.UpdatesStatisticalResp)
  27. for _, v := range updateList {
  28. if v.Source == utils.DATA_SOURCE_THS {
  29. resp.ThsUpdate = v.Total
  30. }
  31. if v.Source == utils.DATA_SOURCE_WIND {
  32. resp.WindUpdate = v.Total
  33. }
  34. if v.Source == utils.DATA_SOURCE_PB {
  35. resp.PbUpdate = v.Total
  36. }
  37. if v.Source == utils.DATA_SOURCE_PB_FINANCE {
  38. resp.PbFinanceUpdate = v.Total
  39. }
  40. if v.Source == utils.DATA_SOURCE_LZ {
  41. resp.LzUpdate = v.Total
  42. }
  43. if v.Source == utils.DATA_SOURCE_YS {
  44. resp.SmmUpdate = v.Total
  45. }
  46. if v.Source == utils.DATA_SOURCE_GL {
  47. resp.MysteelUpdate = v.Total
  48. }
  49. if v.Source == utils.DATA_SOURCE_MANUAL {
  50. resp.ManualUpdate = v.Total
  51. }
  52. if v.Source == utils.DATA_SOURCE_ZZ {
  53. resp.ZzUpdate = v.Total
  54. }
  55. if v.Source == utils.DATA_SOURCE_DL {
  56. resp.DlUpdate = v.Total
  57. }
  58. if v.Source == utils.DATA_SOURCE_SH {
  59. resp.ShUpdate = v.Total
  60. }
  61. if v.Source == utils.DATA_SOURCE_CFFEX {
  62. resp.CffexUpdate = v.Total
  63. }
  64. if v.Source == utils.DATA_SOURCE_SHFE {
  65. resp.ShfeUpdate = v.Total
  66. }
  67. if v.Source == utils.DATA_SOURCE_GIE {
  68. resp.GieUpdate = v.Total
  69. }
  70. //if v.Source == utils.DATA_SOURCE_CALCULATE ||
  71. // v.Source == utils.DATA_SOURCE_CALCULATE_LJZZY ||
  72. // v.Source == utils.DATA_SOURCE_CALCULATE_TBZ ||
  73. // v.Source == utils.DATA_SOURCE_CALCULATE_TCZ ||
  74. // v.Source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS ||
  75. // v.Source == utils.DATA_SOURCE_CALCULATE_HBZ ||
  76. // v.Source == utils.DATA_SOURCE_CALCULATE_HCZ ||
  77. // v.Source == utils.DATA_SOURCE_CALCULATE_BP ||
  78. // v.Source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT ||
  79. // v.Source == utils.DATA_SOURCE_CALCULATE_ZJPJ ||
  80. // v.Source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ ||
  81. // v.Source == utils.DATA_SOURCE_CALCULATE_CJJX ||
  82. // v.Source == utils.DATA_SOURCE_CALCULATE_NHCC {
  83. // resp.CalculateUpdate += v.Total
  84. //}
  85. if v.EdbType == 2 {
  86. resp.CalculateUpdate += v.Total
  87. }
  88. if v.Source == utils.DATA_SOURCE_LT {
  89. resp.LtUpdate = v.Total
  90. }
  91. if v.Source == utils.DATA_SOURCE_COAL {
  92. resp.CoalUpdate = v.Total
  93. }
  94. if v.Source == utils.DATA_SOURCE_GOOGLE_TRAVEL {
  95. resp.GoogleTravelUpdate = v.Total
  96. }
  97. if v.Source == utils.DATA_SOURCE_EIA_STEO {
  98. resp.EiaSteoUpdate = v.Total
  99. }
  100. if v.Source == utils.DATA_SOURCE_COM_TRADE {
  101. resp.UNUpdate = v.Total
  102. }
  103. if v.Source == utils.DATA_SOURCE_SCI {
  104. resp.SciUpdate = v.Total
  105. }
  106. if v.Source == utils.DATA_SOURCE_BAIINFO {
  107. resp.BaiinfoUpdate = v.Total
  108. }
  109. if v.Source == utils.DATA_SOURCE_NATIONAL_STATISTICS {
  110. resp.NationalStatisticsUpdate = v.Total
  111. }
  112. if v.Source == utils.DATA_SOURCE_FUBAO {
  113. resp.FubaoUpdate = v.Total
  114. }
  115. }
  116. var notUpdateCondition string
  117. var notUpdatePars []interface{}
  118. notUpdateCondition += ` AND is_update=? AND edb_info_type = ? `
  119. notUpdatePars = append(notUpdatePars, 1, 0)
  120. notUpdateList, _ := data_manage.GetUpdatesStatistical(notUpdateCondition, notUpdatePars)
  121. for _, v := range notUpdateList {
  122. if v.Source == utils.DATA_SOURCE_THS {
  123. resp.ThsNotUpdate = v.Total
  124. }
  125. if v.Source == utils.DATA_SOURCE_WIND {
  126. resp.WindNotUpdate = v.Total
  127. }
  128. if v.Source == utils.DATA_SOURCE_PB {
  129. resp.PbNotUpdate = v.Total
  130. }
  131. if v.Source == utils.DATA_SOURCE_PB_FINANCE {
  132. resp.PbFinanceNotUpdate = v.Total
  133. }
  134. if v.Source == utils.DATA_SOURCE_LZ {
  135. resp.LzNotUpdate = v.Total
  136. }
  137. if v.Source == utils.DATA_SOURCE_YS {
  138. resp.SmmNotUpdate = v.Total
  139. }
  140. if v.Source == utils.DATA_SOURCE_GL {
  141. resp.MysteelNotUpdate = v.Total
  142. }
  143. if v.Source == utils.DATA_SOURCE_MANUAL {
  144. resp.ManualNotUpdate = v.Total
  145. }
  146. if v.Source == utils.DATA_SOURCE_ZZ {
  147. resp.ZzNotUpdate = v.Total
  148. }
  149. if v.Source == utils.DATA_SOURCE_DL {
  150. resp.DlNotUpdate = v.Total
  151. }
  152. if v.Source == utils.DATA_SOURCE_SH {
  153. resp.ShNotUpdate = v.Total
  154. }
  155. if v.Source == utils.DATA_SOURCE_CFFEX {
  156. resp.CffexNotUpdate = v.Total
  157. }
  158. if v.Source == utils.DATA_SOURCE_SHFE {
  159. resp.ShfeNotUpdate = v.Total
  160. }
  161. if v.Source == utils.DATA_SOURCE_GIE {
  162. resp.GieNotUpdate = v.Total
  163. }
  164. //if v.Source == utils.DATA_SOURCE_CALCULATE ||
  165. // v.Source == utils.DATA_SOURCE_CALCULATE_LJZZY ||
  166. // v.Source == utils.DATA_SOURCE_CALCULATE_TBZ ||
  167. // v.Source == utils.DATA_SOURCE_CALCULATE_TCZ ||
  168. // v.Source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS ||
  169. // v.Source == utils.DATA_SOURCE_CALCULATE_HBZ ||
  170. // v.Source == utils.DATA_SOURCE_CALCULATE_HCZ ||
  171. // v.Source == utils.DATA_SOURCE_CALCULATE_BP ||
  172. // v.Source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT ||
  173. // v.Source == utils.DATA_SOURCE_CALCULATE_ZJPJ ||
  174. // v.Source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ ||
  175. // v.Source == utils.DATA_SOURCE_CALCULATE_CJJX ||
  176. // v.Source == utils.DATA_SOURCE_CALCULATE_NHCC {
  177. // resp.CalculateNotUpdate += v.Total
  178. //}
  179. if v.EdbType == 2 {
  180. resp.CalculateNotUpdate += v.Total
  181. }
  182. if v.Source == utils.DATA_SOURCE_LT {
  183. resp.LtNotUpdate = v.Total
  184. }
  185. if v.Source == utils.DATA_SOURCE_COAL {
  186. resp.CoalNotUpdate = v.Total
  187. }
  188. if v.Source == utils.DATA_SOURCE_GOOGLE_TRAVEL {
  189. resp.GoogleTravelNotUpdate = v.Total
  190. }
  191. if v.Source == utils.DATA_SOURCE_EIA_STEO {
  192. resp.EiaSteoNotUpdate = v.Total
  193. }
  194. if v.Source == utils.DATA_SOURCE_COM_TRADE {
  195. resp.UNNotUpdate = v.Total
  196. }
  197. if v.Source == utils.DATA_SOURCE_SCI {
  198. resp.SciNotUpdate = v.Total
  199. }
  200. if v.Source == utils.DATA_SOURCE_BAIINFO {
  201. resp.BaiinfoNotUpdate = v.Total
  202. }
  203. if v.Source == utils.DATA_SOURCE_NATIONAL_STATISTICS {
  204. resp.NationalStatisticsNotUpdate = v.Total
  205. }
  206. if v.Source == utils.DATA_SOURCE_FUBAO {
  207. resp.FubaoNotUpdate = v.Total
  208. }
  209. }
  210. br.Ret = 200
  211. br.Success = true
  212. br.Msg = "获取成功"
  213. br.Data = resp
  214. }
  215. // @Title 指标一键刷新->列表接口
  216. // @Description 指标一键刷新->列表接口
  217. // @Param Status query int true "1:未更新,2:已更新"
  218. // @Param Source query int true "来源:0:全部,1:同花顺,2:wind,3:彭博,9:手工指标,10:隆众,11:有色,99:计算指标"
  219. // @Param PageSize query int true "每页数据条数"
  220. // @Param CurrentIndex query int true "当前页页码,从1开始"
  221. // @Success Ret=200 刷新成功
  222. // @router /edb_info/updates/list [get]
  223. func (this *EdbInfoController) EdbInfoUpdatesList() {
  224. br := new(models.BaseResponse).Init()
  225. defer func() {
  226. this.Data["json"] = br
  227. this.ServeJSON()
  228. }()
  229. sysUser := this.SysUser
  230. if sysUser == nil {
  231. br.Msg = "请登录"
  232. br.ErrMsg = "请登录,SysUser Is Empty"
  233. br.Ret = 408
  234. return
  235. }
  236. status, _ := this.GetInt("Status")
  237. source, _ := this.GetInt("Source")
  238. pageSize, _ := this.GetInt("PageSize")
  239. currentIndex, _ := this.GetInt("CurrentIndex")
  240. var startSize int
  241. if pageSize <= 0 {
  242. pageSize = utils.PageSize20
  243. }
  244. if currentIndex <= 0 {
  245. currentIndex = 1
  246. }
  247. startSize = paging.StartIndex(currentIndex, pageSize)
  248. var condition string
  249. var pars []interface{}
  250. condition += ` AND edb_info_type = ? `
  251. pars = append(pars, 0)
  252. if status > 0 {
  253. condition += ` AND is_update=?`
  254. pars = append(pars, status)
  255. }
  256. if source == 99 {
  257. condition += ` AND edb_type=? `
  258. pars = append(pars, 2)
  259. }
  260. if source > 0 && source != 99 {
  261. condition += ` AND source=?`
  262. pars = append(pars, source)
  263. }
  264. condition += ` ORDER BY modify_time ASC `
  265. list, err := data_manage.GetUpdatesList(condition, pars, startSize, pageSize)
  266. if err != nil {
  267. br.Msg = "获取数据失败"
  268. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  269. return
  270. }
  271. total, err := data_manage.GetUpdatesListTotal(condition, pars)
  272. if err != nil {
  273. br.Msg = "获取数据失败"
  274. br.ErrMsg = "获取更新数据总数失败,Err:" + err.Error()
  275. return
  276. }
  277. page := paging.GetPaging(currentIndex, pageSize, total)
  278. resp := new(data_manage.UpdatesListResp)
  279. resp.List = list
  280. resp.Total = total
  281. resp.Paging = page
  282. br.Ret = 200
  283. br.Success = true
  284. br.Msg = "获取成功"
  285. br.Data = resp
  286. }
  287. // EdbInfoUpdates
  288. // @Title 指标一键刷新接口
  289. // @Description 指标一键刷新接口
  290. // @Success Ret=200 更新成功
  291. // @router /edb_info/updates [post]
  292. func (this *EdbInfoController) EdbInfoUpdates() {
  293. br := new(models.BaseResponse).Init()
  294. setNxKey := "EDB_INFO_UPDATES"
  295. deleteCache := true
  296. defer func() {
  297. if deleteCache {
  298. utils.Rc.Delete(setNxKey)
  299. }
  300. this.Data["json"] = br
  301. this.ServeJSON()
  302. }()
  303. sysUser := this.SysUser
  304. if sysUser == nil {
  305. br.Msg = "请登录"
  306. br.ErrMsg = "请登录,SysUser Is Empty"
  307. br.Ret = 408
  308. return
  309. }
  310. if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
  311. deleteCache = false
  312. br.Msg = "系统处理中,请勿重复操作!"
  313. br.IsSendEmail = false
  314. return
  315. }
  316. list, err := data_manage.GetAllUpdatesList()
  317. if err != nil {
  318. br.Msg = "获取数据失败"
  319. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  320. return
  321. }
  322. for _, v := range list {
  323. err = data.EdbInfoRefresh(v, false)
  324. if err != nil {
  325. br.Msg = "刷新失败"
  326. br.ErrMsg = "刷新指标失败,指标id:" + fmt.Sprint(v.EdbInfoId) + ", Err:" + err.Error()
  327. return
  328. }
  329. }
  330. br.Ret = 200
  331. br.Success = true
  332. br.Msg = "更新成功"
  333. }
  334. // @Title 指标一键刷新接口
  335. // @Description 指标一键刷新接口
  336. // @Success Ret=200 更新成功
  337. // @router /edb_info/updates/check [post]
  338. func (this *EdbInfoController) EdbInfoUpdatesCheck() {
  339. br := new(models.BaseResponse).Init()
  340. setNxKey := "EDB_INFO_UPDATES"
  341. defer func() {
  342. this.Data["json"] = br
  343. this.ServeJSON()
  344. }()
  345. status := 0
  346. if utils.Rc.IsExist(setNxKey) {
  347. status = 1
  348. } else {
  349. status = 2
  350. }
  351. br.Ret = 200
  352. br.Success = true
  353. br.Msg = "检测成功"
  354. br.Data = status
  355. }