edb_info.go 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006
  1. package data
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/http"
  7. "hongze/hongze_task/models/data_manage"
  8. "hongze/hongze_task/services/alarm_msg"
  9. "hongze/hongze_task/utils"
  10. "strings"
  11. "sync"
  12. )
  13. // 刷新同花顺数据
  14. func RefreshDataFromThs(wg *sync.WaitGroup) (err error) {
  15. defer func() {
  16. if err != nil {
  17. fmt.Println("RefreshDataFromThs Err:" + err.Error())
  18. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromThs ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  19. go alarm_msg.SendAlarmMsg("RefreshDataFromThs ErrMsg:"+err.Error(), 3)
  20. }
  21. wg.Done()
  22. }()
  23. var condition string
  24. var pars []interface{}
  25. condition += " AND source=? "
  26. pars = append(pars, utils.DATA_SOURCE_THS)
  27. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  28. if err != nil {
  29. err = errors.New("GetEdbInfoByCondition:" + err.Error())
  30. return
  31. }
  32. //var endDate string
  33. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  34. for _, v := range items {
  35. startDate := ""
  36. if v.Frequency == "日度" {
  37. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  38. } else if v.Frequency == "周度" {
  39. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  40. } else if v.Frequency == "月度" {
  41. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  42. } else if v.Frequency == "季度" {
  43. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  44. } else if v.Frequency == "年度" {
  45. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  46. } else {
  47. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  48. }
  49. //err = SyncEdbDataByThs(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
  50. //if err != nil {
  51. // err = errors.New("SyncEdbDataByThs Err:" + err.Error())
  52. // return err
  53. //}
  54. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  55. if err != nil {
  56. return errors.New("RefreshEdbData Err:" + err.Error())
  57. }
  58. if resp.Ret != 200 {
  59. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  60. }
  61. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  62. //if err != nil {
  63. // err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error())
  64. // return err
  65. //}
  66. //if item != nil {
  67. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  68. // if err != nil {
  69. // err = errors.New("ModifyEdbInfoMaxAndMinInfo Err:" + err.Error())
  70. // return err
  71. // }
  72. //}
  73. }
  74. return err
  75. }
  76. // 刷新万得数据
  77. func RefreshDataFromWind(wg *sync.WaitGroup) (err error) {
  78. defer func() {
  79. if err != nil {
  80. fmt.Println("RefreshDataFromWind Err:" + err.Error())
  81. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromWind ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  82. go alarm_msg.SendAlarmMsg("RefreshDataFromWind ErrMsg:"+err.Error(), 3)
  83. }
  84. wg.Done()
  85. }()
  86. var condition string
  87. var pars []interface{}
  88. condition += ` AND source=? AND no_update = 0 `
  89. pars = append(pars, utils.DATA_SOURCE_WIND)
  90. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  91. if err != nil {
  92. return err
  93. }
  94. //var endDate string
  95. //endDate = time.Now().Format(utils.FormatDate)
  96. for _, v := range items {
  97. startDate := ""
  98. if v.Frequency == "日度" {
  99. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  100. } else if v.Frequency == "周度" {
  101. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  102. } else if v.Frequency == "月度" {
  103. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  104. } else if v.Frequency == "季度" {
  105. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  106. } else if v.Frequency == "年度" {
  107. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  108. } else {
  109. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  110. }
  111. //err = SyncEdbDataByWind(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
  112. //if err != nil {
  113. // return err
  114. //}
  115. //edbInfoId, source int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
  116. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  117. if err != nil {
  118. return errors.New("RefreshEdbData Err:" + err.Error())
  119. }
  120. if resp.Ret != 200 {
  121. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  122. }
  123. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  124. //if err != nil {
  125. // return err
  126. //}
  127. //if item != nil {
  128. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  129. // if err != nil {
  130. // return err
  131. // }
  132. //}
  133. }
  134. return err
  135. }
  136. // 刷新彭博数据
  137. func RefreshDataFromPb(wg *sync.WaitGroup) (err error) {
  138. defer func() {
  139. if err != nil {
  140. fmt.Println("RefreshDataFromPb Err:" + err.Error())
  141. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromPb ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  142. go alarm_msg.SendAlarmMsg("RefreshDataFromPb ErrMsg:"+err.Error(), 3)
  143. }
  144. wg.Done()
  145. }()
  146. var condition string
  147. var pars []interface{}
  148. condition += " AND source=? "
  149. pars = append(pars, utils.DATA_SOURCE_PB)
  150. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  151. if err != nil {
  152. return errors.New("GetEdbInfoByCondition:" + err.Error())
  153. }
  154. //var endDate string
  155. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  156. for _, v := range items {
  157. startDate := ""
  158. if v.Frequency == "日度" {
  159. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  160. } else if v.Frequency == "周度" {
  161. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  162. } else if v.Frequency == "月度" {
  163. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  164. } else if v.Frequency == "季度" {
  165. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  166. } else if v.Frequency == "年度" {
  167. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  168. } else {
  169. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  170. }
  171. //err = SyncEdbDataByPb(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
  172. //if err != nil {
  173. // return errors.New("SyncEdbDataByPb:" + err.Error())
  174. //}
  175. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  176. if err != nil {
  177. return errors.New("RefreshEdbData Err:" + err.Error())
  178. }
  179. if resp.Ret != 200 {
  180. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  181. }
  182. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  183. //if err != nil {
  184. // return err
  185. //}
  186. //if item != nil {
  187. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  188. // if err != nil {
  189. // return err
  190. // }
  191. //}
  192. //minDate, maxDate, err := data.GetEdbDataPbMaxOrMinDate(v.EdbInfoId)
  193. //if err != nil {
  194. // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error())
  195. //}
  196. //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate)
  197. //err = data.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate)
  198. //if err != nil {
  199. // return errors.New("ModifyEdbDataInfoDate:" + err.Error())
  200. //}
  201. }
  202. return err
  203. }
  204. // RefreshDataFromPbFinance 刷新彭博财务指标数据
  205. func RefreshDataFromPbFinance(wg *sync.WaitGroup) (err error) {
  206. defer func() {
  207. if err != nil {
  208. fmt.Println("RefreshDataFromPb Err:" + err.Error())
  209. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromPb ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  210. go alarm_msg.SendAlarmMsg("RefreshDataFromPb ErrMsg:"+err.Error(), 3)
  211. }
  212. wg.Done()
  213. }()
  214. var condition string
  215. var pars []interface{}
  216. condition += " AND source=? "
  217. pars = append(pars, utils.DATA_SOURCE_PB_FINANCE)
  218. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  219. if err != nil {
  220. return errors.New("GetEdbInfoByCondition:" + err.Error())
  221. }
  222. //var endDate string
  223. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  224. for _, v := range items {
  225. startDate := ""
  226. if v.Frequency == "日度" {
  227. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  228. } else if v.Frequency == "周度" {
  229. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  230. } else if v.Frequency == "月度" {
  231. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  232. } else if v.Frequency == "季度" {
  233. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  234. } else if v.Frequency == "年度" {
  235. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  236. } else {
  237. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  238. }
  239. //err = SyncEdbDataByPb(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
  240. //if err != nil {
  241. // return errors.New("SyncEdbDataByPb:" + err.Error())
  242. //}
  243. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  244. if err != nil {
  245. return errors.New("RefreshEdbData Err:" + err.Error())
  246. }
  247. if resp.Ret != 200 {
  248. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  249. }
  250. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  251. //if err != nil {
  252. // return err
  253. //}
  254. //if item != nil {
  255. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  256. // if err != nil {
  257. // return err
  258. // }
  259. //}
  260. //minDate, maxDate, err := data.GetEdbDataPbMaxOrMinDate(v.EdbInfoId)
  261. //if err != nil {
  262. // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error())
  263. //}
  264. //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate)
  265. //err = data.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate)
  266. //if err != nil {
  267. // return errors.New("ModifyEdbDataInfoDate:" + err.Error())
  268. //}
  269. }
  270. return err
  271. }
  272. func CheckPbDataInterface(cont context.Context) (err error) {
  273. go func() {
  274. checkUrl := utils.Hz_Data_PB_Url + `hz_server`
  275. body, err := http.Get(checkUrl)
  276. if err != nil {
  277. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  278. msg := "检测彭博数据服务器失败:CheckPbDataInterface ErrMsg:" + err.Error()
  279. go alarm_msg.SendAlarmMsg(msg, 3)
  280. } else {
  281. result := string(body)
  282. if result != "1" {
  283. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
  284. msg := "检测彭博数据服务器失败:CheckPbDataInterface ErrMsg:" + string(body)
  285. go alarm_msg.SendAlarmMsg(msg, 3)
  286. }
  287. }
  288. }()
  289. return
  290. }
  291. // CheckLtDataInterface 检测路透数据服务器
  292. func CheckLtDataInterface(cont context.Context) (err error) {
  293. go func() {
  294. checkUrl := utils.Hz_Data_LT_Url + `hz_server`
  295. body, err := http.Get(checkUrl)
  296. if err != nil {
  297. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  298. msg := "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:" + err.Error()
  299. go alarm_msg.SendAlarmMsg(msg, 3)
  300. } else {
  301. result := string(body)
  302. if result != `"ek true"` {
  303. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
  304. msg := "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:" + string(body)
  305. go alarm_msg.SendAlarmMsg(msg, 3)
  306. }
  307. }
  308. }()
  309. return
  310. }
  311. // CheckThsDataInterface 检测同花顺数据服务器
  312. func CheckThsDataInterface(cont context.Context) (err error) {
  313. go func() {
  314. checkUrl := utils.Hz_Server_Data_Url + `hz_server`
  315. body, err := http.Get(checkUrl)
  316. if err != nil {
  317. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  318. msg := "检测同花顺数据服务器失败:CheckThsDataInterface ErrMsg:" + err.Error()
  319. go alarm_msg.SendAlarmMsg(msg, 3)
  320. } else {
  321. result := string(body)
  322. if result != "1" {
  323. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
  324. msg := "检测同花顺数据服务器失败:CheckThsDataInterface ErrMsg:" + string(body)
  325. go alarm_msg.SendAlarmMsg(msg, 3)
  326. }
  327. }
  328. }()
  329. return
  330. }
  331. ////刷新所有计算指标
  332. //func RefreshDataFromCalculateAll() (err error) {
  333. // defer func() {
  334. // if err != nil {
  335. // utils.FileLog.Info("RefreshDataFromCalculateAll Err:" + err.Error())
  336. // go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCalculateAll ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  337. // }
  338. // }()
  339. // var condition string
  340. // var pars []interface{}
  341. // condition += " AND edb_type=? "
  342. // pars = append(pars, 2)
  343. //
  344. // //condition += " AND is_update=1 "
  345. //
  346. // items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  347. // if err != nil {
  348. // return err
  349. // }
  350. // for _, v := range items {
  351. // edbInfoId := v.EdbInfoId
  352. // edbCode := v.EdbCode
  353. // source := v.Source
  354. // fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source)
  355. // if source == utils.DATA_SOURCE_CALCULATE {
  356. // startDate := ""
  357. // if v.Frequency == "日度" {
  358. // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  359. // } else if v.Frequency == "周度" {
  360. // startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  361. // } else if v.Frequency == "月度" {
  362. // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  363. // } else if v.Frequency == "季度" {
  364. // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  365. // } else if v.Frequency == "年度" {
  366. // startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  367. // } else {
  368. // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  369. // }
  370. // endDate := time.Now().Format(utils.FormatDate)
  371. // var edbInfoIdBytes []string
  372. // calculateMap, err := data_manage.GetEdbInfoCalculateDetail(int(v.EdbInfoId))
  373. // if err != nil {
  374. // return errors.New("GetEdbInfoCalculateDetail Err:" + err.Error())
  375. // }
  376. // var formulaStr string
  377. // edbInfoList := make([]*data_manage.EdbInfo, 0)
  378. // for _, v := range calculateMap {
  379. // formulaStr += v.FromTag + ","
  380. // edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
  381. // edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
  382. // edbInfoList = append(edbInfoList, edbInfo)
  383. // }
  384. // //endDate = ""
  385. // err = RefreshCalculate(edbInfoList, edbInfoId, edbCode, v.CalculateFormula, startDate, endDate, edbInfoIdBytes)
  386. // if err != nil {
  387. // return errors.New("RefreshCalculate Err:" + err.Error())
  388. // }
  389. // } else if source == utils.DATA_SOURCE_CALCULATE_LJZZY {
  390. // calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
  391. // if err != nil {
  392. // if err.Error() == utils.ErrNoRow() {
  393. // continue
  394. // }
  395. // return errors.New("GetEdbInfoCalculateLjzzyDetail Err:" + err.Error())
  396. // }
  397. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
  398. // if err != nil {
  399. // if err.Error() == utils.ErrNoRow() {
  400. // continue
  401. // }
  402. // return errors.New("GetEdbInfoById Err:" + err.Error())
  403. // }
  404. // year := time.Now().Year() - 1
  405. // startDate := strconv.Itoa(year) + "-01" + "-01"
  406. // endDate := "" //time.Now().Format(utils.FormatDate)
  407. // err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, edbCode, startDate, endDate)
  408. // if err != nil {
  409. // return errors.New("RefreshCalculateLjzzy Err:" + err.Error())
  410. // }
  411. // } else if source == utils.DATA_SOURCE_CALCULATE_TBZ {
  412. // calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
  413. // if err != nil {
  414. // return errors.New("GetEdbInfoCalculateTbzDetail Err:" + err.Error())
  415. // }
  416. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
  417. // if err != nil {
  418. // if err.Error() == utils.ErrNoRow() {
  419. // continue
  420. // }
  421. // return errors.New("GetEdbInfoById Err:" + err.Error())
  422. // }
  423. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  424. // endDate := "" //time.Now().Format(utils.FormatDate)
  425. // err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
  426. // if err != nil {
  427. // return errors.New("RefreshCalculateTbz Err:" + err.Error())
  428. // }
  429. // } else if source == utils.DATA_SOURCE_CALCULATE_TCZ {
  430. // calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
  431. // if err != nil {
  432. // return errors.New("GetEdbInfoCalculateTczDetail Err:" + err.Error())
  433. // }
  434. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
  435. // if err != nil {
  436. // if err.Error() == utils.ErrNoRow() {
  437. // continue
  438. // }
  439. // return errors.New("GetEdbInfoById Err:" + err.Error())
  440. // }
  441. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  442. // endDate := "" //time.Now().Format(utils.FormatDate)
  443. // err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
  444. // if err != nil {
  445. // return errors.New("RefreshCalculateTcz Err:" + err.Error())
  446. // }
  447. // } else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS {
  448. // calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
  449. // if err != nil {
  450. // return errors.New("GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error())
  451. // }
  452. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
  453. // if err != nil {
  454. // if err.Error() == utils.ErrNoRow() {
  455. // continue
  456. // }
  457. // return errors.New("GetEdbInfoById Err:" + err.Error())
  458. // }
  459. // formulaInt, _ := strconv.Atoi(v.CalculateFormula)
  460. // err = data_manage.RefreshCalculateNszydpjjs(edbInfoId, v.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode)
  461. // if err != nil {
  462. // return errors.New("RefreshCalculateNszydpjjs Err:" + err.Error())
  463. // }
  464. // } else if source == utils.DATA_SOURCE_CALCULATE_HBZ {
  465. // calculateHbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
  466. // if err != nil {
  467. // return errors.New("GetEdbInfoCalculateHbzDetail Err:" + err.Error())
  468. // }
  469. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHbz.FromEdbInfoId)
  470. // if err != nil {
  471. // if err.Error() == utils.ErrNoRow() {
  472. // continue
  473. // }
  474. // return errors.New("GetEdbInfoById Err:" + err.Error())
  475. // }
  476. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  477. // endDate := "" //time.Now().Format(utils.FormatDate)
  478. // formulaInt, _ := strconv.Atoi(v.CalculateFormula)
  479. // err = data_manage.RefreshCalculateHbz(edbInfoId, source, fromEdbInfo, calculateHbz.EdbCode, startDate, endDate, formulaInt)
  480. // if err != nil {
  481. // return errors.New("RefreshCalculateTbz Err:" + err.Error())
  482. // }
  483. // } else if source == utils.DATA_SOURCE_CALCULATE_HCZ {
  484. // calculateHcz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
  485. // if err != nil {
  486. // return errors.New("GetEdbInfoCalculateHczDetail Err:" + err.Error())
  487. // }
  488. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHcz.FromEdbInfoId)
  489. // if err != nil {
  490. // if err.Error() == utils.ErrNoRow() {
  491. // continue
  492. // }
  493. // return errors.New("GetEdbInfoById Err:" + err.Error())
  494. // }
  495. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  496. // endDate := "" //time.Now().Format(utils.FormatDate)
  497. // err = data_manage.RefreshCalculateHcz(edbInfoId, source, fromEdbInfo, calculateHcz.EdbCode, startDate, endDate)
  498. // if err != nil {
  499. // return errors.New("RefreshCalculateTbz Err:" + err.Error())
  500. // }
  501. // } else if source == utils.DATA_SOURCE_CALCULATE_BP {
  502. // calculateBp, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
  503. // if err != nil && err.Error() != utils.ErrNoRow() {
  504. // return errors.New("GetEdbInfoCalculateBpDetail Err:" + err.Error())
  505. // }
  506. // if calculateBp != nil {
  507. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateBp.FromEdbInfoId)
  508. // if err != nil {
  509. // if err.Error() == utils.ErrNoRow() {
  510. // continue
  511. // }
  512. // return errors.New("GetEdbInfoById Err:" + err.Error())
  513. // }
  514. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  515. // endDate := "" //time.Now().Format(utils.FormatDate)
  516. // err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateBp.EdbCode, startDate, endDate)
  517. // if err != nil {
  518. // return errors.New("RefreshCalculateTbz Err:" + err.Error())
  519. // }
  520. // }
  521. // } else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT {
  522. // calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId)
  523. // if err != nil {
  524. // return fmt.Errorf("GetEdbInfoCalculateTbzDetail Err:" + err.Error())
  525. // }
  526. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId)
  527. // if err != nil {
  528. // if err.Error() == utils.ErrNoRow() {
  529. // continue
  530. // }
  531. // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
  532. // }
  533. // //startDate := v.StartDate.Format(utils.FormatDate)
  534. // //endDate := time.Now().Format(utils.FormatDate)
  535. // formulaInt, _ := strconv.Atoi(calculate.CalculateFormula)
  536. // err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, calculate.MoveFrequency)
  537. // if err != nil {
  538. // return fmt.Errorf("RefreshAllCalculateTimeShift Err:" + err.Error())
  539. // }
  540. //
  541. // } else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接
  542. // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId)
  543. // if err != nil {
  544. // if err.Error() == utils.ErrNoRow() {
  545. // continue
  546. // }
  547. // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
  548. // }
  549. // err = data_manage.RefreshAllCalculateZjpj(tmpEdbInfo)
  550. // if err != nil {
  551. // return fmt.Errorf("RefreshAllCalculateZjpj Err:" + err.Error())
  552. // }
  553. // } else if source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ { //刷新累计值同比拼接
  554. // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId)
  555. // if err != nil {
  556. // if err.Error() == utils.ErrNoRow() {
  557. // continue
  558. // }
  559. // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
  560. // }
  561. // err = data_manage.RefreshAllCalculateLjztbpj(tmpEdbInfo)
  562. // if err != nil {
  563. // return fmt.Errorf("RefreshAllCalculateLjztbpj Err:" + err.Error())
  564. // }
  565. // } else {
  566. // msg := "刷新失败,无效的指标渠道:source:" + strconv.Itoa(source) + " EdbCode:" + v.EdbCode
  567. // err = errors.New(msg)
  568. // return err
  569. // }
  570. //
  571. // maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  572. // if err != nil {
  573. // fmt.Println("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
  574. // err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
  575. // return err
  576. // }
  577. // if maxAndMinItem != nil {
  578. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
  579. // if err != nil {
  580. // return err
  581. // }
  582. // }
  583. // }
  584. // return err
  585. //}
  586. // RefreshDataFromCalculateAll 刷新所有计算指标
  587. func RefreshDataFromCalculateAll() (err error) {
  588. var errmsg string
  589. defer func() {
  590. if err != nil {
  591. utils.FileLog.Info("RefreshDataFromCalculateAll Err:" + err.Error())
  592. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCalculateAll ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  593. go alarm_msg.SendAlarmMsg("RefreshDataFromCalculateAll ErrMsg:"+err.Error(), 3)
  594. }
  595. }()
  596. var condition string
  597. var pars []interface{}
  598. // 查询 普通指标的计算指标
  599. condition += " AND edb_type=? AND edb_info_type=? "
  600. pars = append(pars, 2, 0)
  601. //condition += " AND modify_time<? "
  602. //pars = append(pars, "2022-03-02 17:03:52")
  603. //condition += " AND is_update=1 "
  604. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  605. if err != nil {
  606. return err
  607. }
  608. for _, v := range items {
  609. //edbInfoId := v.EdbInfoId
  610. //edbCode := v.EdbCode
  611. source := v.Source
  612. startDate := v.StartDate.Format(utils.FormatDate)
  613. if startDate == "0001-01-01" {
  614. continue
  615. }
  616. fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source)
  617. //if source == utils.DATA_SOURCE_CALCULATE {
  618. // startDate := ""
  619. // if v.Frequency == "日度" {
  620. // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  621. // } else if v.Frequency == "周度" {
  622. // startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  623. // } else if v.Frequency == "月度" {
  624. // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  625. // } else if v.Frequency == "季度" {
  626. // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  627. // } else if v.Frequency == "年度" {
  628. // startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  629. // } else {
  630. // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  631. // }
  632. // endDate := time.Now().Format(utils.FormatDate)
  633. // var edbInfoIdBytes []string
  634. // calculateMap, err := data_manage.GetEdbInfoCalculateDetail(int(v.EdbInfoId))
  635. // if err != nil {
  636. // return errors.New("GetEdbInfoCalculateDetail Err:" + err.Error())
  637. // }
  638. // var formulaStr string
  639. // edbInfoList := make([]*data_manage.EdbInfo, 0)
  640. // for _, v := range calculateMap {
  641. // formulaStr += v.FromTag + ","
  642. // edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
  643. // edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
  644. // edbInfoList = append(edbInfoList, edbInfo)
  645. // }
  646. // //endDate = ""
  647. // err = RefreshCalculate(edbInfoList, edbInfoId, edbCode, v.CalculateFormula, startDate, endDate, edbInfoIdBytes)
  648. // if err != nil {
  649. // return errors.New("RefreshCalculate Err:" + err.Error())
  650. // }
  651. //} else if source == utils.DATA_SOURCE_CALCULATE_LJZZY {
  652. // calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
  653. // if err != nil {
  654. // if err.Error() == utils.ErrNoRow() {
  655. // continue
  656. // }
  657. // return errors.New("GetEdbInfoCalculateLjzzyDetail Err:" + err.Error())
  658. // }
  659. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
  660. // if err != nil {
  661. // if err.Error() == utils.ErrNoRow() {
  662. // continue
  663. // }
  664. // return errors.New("GetEdbInfoById Err:" + err.Error())
  665. // }
  666. // year := time.Now().Year() - 1
  667. // startDate := strconv.Itoa(year) + "-01" + "-01"
  668. // endDate := "" //time.Now().Format(utils.FormatDate)
  669. // err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, edbCode, startDate, endDate)
  670. // if err != nil {
  671. // return errors.New("RefreshCalculateLjzzy Err:" + err.Error())
  672. // }
  673. //} else if source == utils.DATA_SOURCE_CALCULATE_TBZ {
  674. // calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
  675. // if err != nil {
  676. // return errors.New("GetEdbInfoCalculateTbzDetail Err:" + err.Error())
  677. // }
  678. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
  679. // if err != nil {
  680. // if err.Error() == utils.ErrNoRow() {
  681. // continue
  682. // }
  683. // return errors.New("GetEdbInfoById Err:" + err.Error())
  684. // }
  685. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  686. // endDate := "" //time.Now().Format(utils.FormatDate)
  687. // err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
  688. // if err != nil {
  689. // return errors.New("RefreshCalculateTbz Err:" + err.Error())
  690. // }
  691. //} else if source == utils.DATA_SOURCE_CALCULATE_TCZ {
  692. // calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
  693. // if err != nil {
  694. // return errors.New("GetEdbInfoCalculateTczDetail Err:" + err.Error())
  695. // }
  696. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
  697. // if err != nil {
  698. // if err.Error() == utils.ErrNoRow() {
  699. // continue
  700. // }
  701. // return errors.New("GetEdbInfoById Err:" + err.Error())
  702. // }
  703. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  704. // endDate := "" //time.Now().Format(utils.FormatDate)
  705. // err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
  706. // if err != nil {
  707. // return errors.New("RefreshCalculateTcz Err:" + err.Error())
  708. // }
  709. //} else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS {
  710. // calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
  711. // if err != nil {
  712. // return errors.New("GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error())
  713. // }
  714. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
  715. // if err != nil {
  716. // if err.Error() == utils.ErrNoRow() {
  717. // continue
  718. // }
  719. // return errors.New("GetEdbInfoById Err:" + err.Error())
  720. // }
  721. // formulaInt, _ := strconv.Atoi(v.CalculateFormula)
  722. // err = data_manage.RefreshCalculateNszydpjjs(edbInfoId, v.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode)
  723. // if err != nil {
  724. // return errors.New("RefreshCalculateNszydpjjs Err:" + err.Error())
  725. // }
  726. //} else if source == utils.DATA_SOURCE_CALCULATE_HBZ {
  727. // calculateHbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
  728. // if err != nil {
  729. // return errors.New("GetEdbInfoCalculateHbzDetail Err:" + err.Error())
  730. // }
  731. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHbz.FromEdbInfoId)
  732. // if err != nil {
  733. // if err.Error() == utils.ErrNoRow() {
  734. // continue
  735. // }
  736. // return errors.New("GetEdbInfoById Err:" + err.Error())
  737. // }
  738. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  739. // endDate := "" //time.Now().Format(utils.FormatDate)
  740. // formulaInt, _ := strconv.Atoi(v.CalculateFormula)
  741. // err = data_manage.RefreshCalculateHbz(edbInfoId, source, fromEdbInfo, calculateHbz.EdbCode, startDate, endDate, formulaInt)
  742. // if err != nil {
  743. // return errors.New("RefreshCalculateTbz Err:" + err.Error())
  744. // }
  745. //} else if source == utils.DATA_SOURCE_CALCULATE_HCZ {
  746. // calculateHcz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
  747. // if err != nil {
  748. // return errors.New("GetEdbInfoCalculateHczDetail Err:" + err.Error())
  749. // }
  750. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHcz.FromEdbInfoId)
  751. // if err != nil {
  752. // if err.Error() == utils.ErrNoRow() {
  753. // continue
  754. // }
  755. // return errors.New("GetEdbInfoById Err:" + err.Error())
  756. // }
  757. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  758. // endDate := "" //time.Now().Format(utils.FormatDate)
  759. // err = data_manage.RefreshCalculateHcz(edbInfoId, source, fromEdbInfo, calculateHcz.EdbCode, startDate, endDate)
  760. // if err != nil {
  761. // return errors.New("RefreshCalculateTbz Err:" + err.Error())
  762. // }
  763. //} else if source == utils.DATA_SOURCE_CALCULATE_BP {
  764. // calculateBp, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
  765. // if err != nil && err.Error() != utils.ErrNoRow() {
  766. // return errors.New("GetEdbInfoCalculateBpDetail Err:" + err.Error())
  767. // }
  768. // if calculateBp != nil {
  769. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateBp.FromEdbInfoId)
  770. // if err != nil {
  771. // if err.Error() == utils.ErrNoRow() {
  772. // continue
  773. // }
  774. // return errors.New("GetEdbInfoById Err:" + err.Error())
  775. // }
  776. // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
  777. // endDate := "" //time.Now().Format(utils.FormatDate)
  778. // err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateBp.EdbCode, startDate, endDate)
  779. // if err != nil {
  780. // return errors.New("RefreshCalculateTbz Err:" + err.Error())
  781. // }
  782. // }
  783. //} else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT {
  784. // calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId)
  785. // if err != nil {
  786. // return fmt.Errorf("GetEdbInfoCalculateTbzDetail Err:" + err.Error())
  787. // }
  788. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId)
  789. // if err != nil {
  790. // if err.Error() == utils.ErrNoRow() {
  791. // continue
  792. // }
  793. // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
  794. // }
  795. // //startDate := v.StartDate.Format(utils.FormatDate)
  796. // //endDate := time.Now().Format(utils.FormatDate)
  797. // formulaInt, _ := strconv.Atoi(calculate.CalculateFormula)
  798. // err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, calculate.MoveFrequency)
  799. // if err != nil {
  800. // return fmt.Errorf("RefreshAllCalculateTimeShift Err:" + err.Error())
  801. // }
  802. //
  803. //} else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接
  804. // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId)
  805. // if err != nil {
  806. // if err.Error() == utils.ErrNoRow() {
  807. // continue
  808. // }
  809. // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
  810. // }
  811. // err = data_manage.RefreshAllCalculateZjpj(tmpEdbInfo)
  812. // if err != nil {
  813. // return fmt.Errorf("RefreshAllCalculateZjpj Err:" + err.Error())
  814. // }
  815. //} else if source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ { //刷新累计值同比拼接
  816. // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId)
  817. // if err != nil {
  818. // if err.Error() == utils.ErrNoRow() {
  819. // continue
  820. // }
  821. // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
  822. // }
  823. // err = data_manage.RefreshAllCalculateLjztbpj(tmpEdbInfo)
  824. // if err != nil {
  825. // return fmt.Errorf("RefreshAllCalculateLjztbpj Err:" + err.Error())
  826. // }
  827. //} else {
  828. // msg := "刷新失败,无效的指标渠道:source:" + strconv.Itoa(source) + " EdbCode:" + v.EdbCode
  829. // err = errors.New(msg)
  830. // return err
  831. //}
  832. fmt.Println("RefreshEdbCalculateData", v.EdbInfoId, v.EdbCode, startDate)
  833. result, err := RefreshEdbCalculateData(v.EdbInfoId, v.EdbCode, startDate)
  834. if err != nil {
  835. errmsg += v.EdbCode + ","
  836. err = errors.New("RefreshEdbCalculateData Err:" + err.Error())
  837. //return err
  838. continue
  839. }
  840. if result.Ret != 200 {
  841. errmsg += v.EdbCode + ","
  842. err = errors.New("RefreshEdbCalculateData err;msg:" + result.Msg + ";errMsg:" + result.ErrMsg)
  843. //return err
  844. continue
  845. }
  846. //maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  847. //if err != nil {
  848. // fmt.Println("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
  849. // err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
  850. // return err
  851. //}
  852. //if maxAndMinItem != nil {
  853. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
  854. // if err != nil {
  855. // return err
  856. // }
  857. //}
  858. }
  859. return err
  860. }
  861. // RefreshPredictDataFromCalculateAll 刷新所有预测计算指标
  862. func RefreshPredictDataFromCalculateAll() (err error) {
  863. defer func() {
  864. if err != nil {
  865. utils.FileLog.Info("RefreshDataFromCalculateAll Err:" + err.Error())
  866. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCalculateAll ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  867. go alarm_msg.SendAlarmMsg("RefreshDataFromCalculateAll ErrMsg:"+err.Error(), 3)
  868. }
  869. }()
  870. var condition string
  871. var pars []interface{}
  872. // 查询 普通指标的计算指标
  873. condition += " AND edb_type=? AND edb_info_type=? "
  874. pars = append(pars, 2, 1)
  875. //condition += " AND modify_time<? "
  876. //pars = append(pars, "2022-03-02 17:03:52")
  877. //condition += " AND is_update=1 "
  878. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  879. if err != nil {
  880. return err
  881. }
  882. for _, v := range items {
  883. //edbInfoId := v.EdbInfoId
  884. //edbCode := v.EdbCode
  885. source := v.Source
  886. startDate := v.StartDate.Format(utils.FormatDate)
  887. if startDate == "0001-01-01" {
  888. continue
  889. }
  890. fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source, "======RefreshPredictEdbCalculateData:", startDate)
  891. result, err := RefreshPredictEdbCalculateData(v.EdbInfoId, v.EdbCode, startDate)
  892. if err != nil {
  893. err = errors.New("RefreshPredictEdbCalculateData Err:" + err.Error())
  894. return err
  895. }
  896. if result.Ret != 200 {
  897. err = errors.New("RefreshPredictEdbCalculateData err;msg:" + result.Msg + ";errMsg:" + result.ErrMsg)
  898. return err
  899. }
  900. }
  901. return err
  902. }
  903. // 刷新手工指标数据
  904. func RefreshDataFromManual(wg *sync.WaitGroup) (err error) {
  905. defer func() {
  906. if err != nil {
  907. fmt.Println("RefreshDataFromManual Err:" + err.Error())
  908. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromManual ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  909. go alarm_msg.SendAlarmMsg("RefreshDataFromManual ErrMsg:"+err.Error(), 3)
  910. }
  911. wg.Done()
  912. }()
  913. var condition string
  914. var pars []interface{}
  915. condition += " AND source=? "
  916. pars = append(pars, utils.DATA_SOURCE_MANUAL)
  917. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  918. if err != nil {
  919. return errors.New("GetEdbInfoByCondition:" + err.Error())
  920. }
  921. for _, v := range items {
  922. //err = data_manage.RefreshManual(v)
  923. //if err != nil {
  924. // return errors.New("RefreshManual:edbCode:" + v.EdbCode + ":" + err.Error())
  925. //}
  926. startDate := ``
  927. if !v.StartDate.IsZero() {
  928. startDate = v.StartDate.Format(utils.FormatDate)
  929. }
  930. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  931. if err != nil {
  932. return errors.New("RefreshEdbData Err:" + err.Error())
  933. }
  934. if resp.Ret != 200 {
  935. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  936. }
  937. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  938. //if err != nil {
  939. // if err.Error() != utils.ErrNoRow() {
  940. // return err
  941. // } else {
  942. // err = nil
  943. // }
  944. //} else {
  945. // if item != nil {
  946. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  947. // if err != nil {
  948. // return err
  949. // }
  950. // }
  951. //}
  952. }
  953. return err
  954. }
  955. // 刷新隆众数据
  956. func RefreshDataFromLz(wg *sync.WaitGroup) (err error) {
  957. defer func() {
  958. if err != nil {
  959. fmt.Println("RefreshDataFromLz Err:" + err.Error())
  960. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromLz ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  961. go alarm_msg.SendAlarmMsg("RefreshDataFromLz ErrMsg:"+err.Error(), 3)
  962. }
  963. wg.Done()
  964. }()
  965. var condition string
  966. var pars []interface{}
  967. condition += " AND source=? "
  968. pars = append(pars, utils.DATA_SOURCE_LZ)
  969. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  970. if err != nil {
  971. return errors.New("GetEdbInfoByCondition:" + err.Error())
  972. }
  973. //var endDate string
  974. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  975. for _, v := range items {
  976. startDate := ""
  977. if v.Frequency == "日度" {
  978. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  979. } else if v.Frequency == "周度" {
  980. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  981. } else if v.Frequency == "月度" {
  982. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  983. } else if v.Frequency == "季度" {
  984. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  985. } else if v.Frequency == "年度" {
  986. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  987. } else {
  988. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  989. }
  990. //fmt.Println(startDate, endDate)
  991. //err = data_manage.RefreshEdbDataByLz(v.EdbInfoId, v.EdbCode, startDate, endDate)
  992. //if err != nil {
  993. // return errors.New("RefreshEdbDataByLz:" + err.Error())
  994. //}
  995. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  996. if err != nil {
  997. return errors.New("RefreshEdbData Err:" + err.Error())
  998. }
  999. if resp.Ret != 200 {
  1000. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1001. }
  1002. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1003. //if err != nil {
  1004. // return err
  1005. //}
  1006. //if item != nil {
  1007. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1008. // if err != nil {
  1009. // return err
  1010. // }
  1011. //}
  1012. }
  1013. return err
  1014. }
  1015. // 刷新有色数据
  1016. func RefreshDataFromYs(wg *sync.WaitGroup) (err error) {
  1017. defer func() {
  1018. if err != nil {
  1019. fmt.Println("RefreshDataFromYs Err:" + err.Error())
  1020. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromYs ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1021. go alarm_msg.SendAlarmMsg("RefreshDataFromYs ErrMsg:"+err.Error(), 3)
  1022. }
  1023. wg.Done()
  1024. }()
  1025. var condition string
  1026. var pars []interface{}
  1027. condition += " AND source=? "
  1028. pars = append(pars, utils.DATA_SOURCE_YS)
  1029. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1030. if err != nil {
  1031. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1032. }
  1033. //var endDate string
  1034. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1035. for _, v := range items {
  1036. startDate := ""
  1037. if v.Frequency == "日度" {
  1038. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1039. } else if v.Frequency == "周度" {
  1040. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1041. } else if v.Frequency == "月度" {
  1042. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1043. } else if v.Frequency == "季度" {
  1044. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1045. } else if v.Frequency == "年度" {
  1046. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1047. } else {
  1048. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1049. }
  1050. //fmt.Println(startDate, endDate)
  1051. //err = data_manage.RefreshEdbDataByYs(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1052. //if err != nil {
  1053. // return errors.New("RefreshEdbDataByYs:" + err.Error())
  1054. //}
  1055. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1056. if err != nil {
  1057. return errors.New("RefreshEdbData Err:" + err.Error())
  1058. }
  1059. if resp.Ret != 200 {
  1060. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1061. }
  1062. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1063. //if err != nil {
  1064. // return err
  1065. //}
  1066. //if item != nil {
  1067. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1068. // if err != nil {
  1069. // return err
  1070. // }
  1071. //}
  1072. }
  1073. return err
  1074. }
  1075. // 刷新钢联数据
  1076. func RefreshDataFromGl(wg *sync.WaitGroup) (err error) {
  1077. defer func() {
  1078. if err != nil {
  1079. fmt.Println("RefreshDataFromGl Err:" + err.Error())
  1080. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1081. go alarm_msg.SendAlarmMsg("RefreshDataFromGl ErrMsg:"+err.Error(), 3)
  1082. }
  1083. wg.Done()
  1084. }()
  1085. var condition string
  1086. var pars []interface{}
  1087. condition += " AND source=? "
  1088. pars = append(pars, utils.DATA_SOURCE_GL)
  1089. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1090. if err != nil {
  1091. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1092. }
  1093. //var endDate string
  1094. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1095. for _, v := range items {
  1096. startDate := ""
  1097. if v.Frequency == "日度" {
  1098. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1099. } else if v.Frequency == "周度" {
  1100. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1101. } else if v.Frequency == "月度" {
  1102. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1103. } else if v.Frequency == "季度" {
  1104. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1105. } else if v.Frequency == "年度" {
  1106. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1107. } else {
  1108. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1109. }
  1110. //fmt.Println(startDate, endDate)
  1111. //err = data_manage.RefreshEdbDataByGl(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1112. //if err != nil {
  1113. // return errors.New("RefreshEdbDataByGl:" + err.Error())
  1114. //}
  1115. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1116. if err != nil {
  1117. return errors.New("RefreshEdbData Err:" + err.Error())
  1118. }
  1119. if resp.Ret != 200 {
  1120. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1121. }
  1122. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1123. //if err != nil {
  1124. // return err
  1125. //}
  1126. //if item != nil {
  1127. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1128. // if err != nil {
  1129. // return err
  1130. // }
  1131. //}
  1132. }
  1133. return err
  1134. }
  1135. // RefreshDataFromSh 刷新上期所数据
  1136. func RefreshDataFromSh(wg *sync.WaitGroup) (err error) {
  1137. defer func() {
  1138. if err != nil {
  1139. fmt.Println("RefreshDataFromSh Err:" + err.Error())
  1140. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromSh ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1141. go alarm_msg.SendAlarmMsg("RefreshDataFromSh ErrMsg:"+err.Error(), 3)
  1142. }
  1143. wg.Done()
  1144. }()
  1145. var condition string
  1146. var pars []interface{}
  1147. condition += " AND source=? "
  1148. pars = append(pars, utils.DATA_SOURCE_SH)
  1149. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1150. if err != nil {
  1151. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1152. }
  1153. //var endDate string
  1154. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1155. for _, v := range items {
  1156. startDate := ""
  1157. if v.Frequency == "日度" {
  1158. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1159. } else if v.Frequency == "周度" {
  1160. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1161. } else if v.Frequency == "月度" {
  1162. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1163. } else if v.Frequency == "季度" {
  1164. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1165. } else if v.Frequency == "年度" {
  1166. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1167. } else {
  1168. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1169. }
  1170. //fmt.Println(startDate, endDate)
  1171. //err = data_manage.RefreshEdbDataBySh(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1172. //if err != nil {
  1173. // return errors.New("RefreshEdbDataBySh:" + err.Error())
  1174. //}
  1175. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1176. if err != nil {
  1177. return errors.New("RefreshEdbData Err:" + err.Error())
  1178. }
  1179. if resp.Ret != 200 {
  1180. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1181. }
  1182. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1183. //if err != nil {
  1184. // return err
  1185. //}
  1186. //if item != nil {
  1187. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1188. // if err != nil {
  1189. // return err
  1190. // }
  1191. //}
  1192. }
  1193. return err
  1194. }
  1195. // RefreshDataFromDl 刷新大商所数据
  1196. func RefreshDataFromDl(wg *sync.WaitGroup) (err error) {
  1197. defer func() {
  1198. if err != nil {
  1199. fmt.Println("RefreshDataFromDl Err:" + err.Error())
  1200. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromDl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1201. go alarm_msg.SendAlarmMsg("RefreshDataFromDl ErrMsg:"+err.Error(), 3)
  1202. }
  1203. wg.Done()
  1204. }()
  1205. var condition string
  1206. var pars []interface{}
  1207. condition += " AND source=? "
  1208. pars = append(pars, utils.DATA_SOURCE_DL)
  1209. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1210. if err != nil {
  1211. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1212. }
  1213. //var endDate string
  1214. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1215. for _, v := range items {
  1216. startDate := ""
  1217. if v.Frequency == "日度" {
  1218. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1219. } else if v.Frequency == "周度" {
  1220. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1221. } else if v.Frequency == "月度" {
  1222. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1223. } else if v.Frequency == "季度" {
  1224. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1225. } else if v.Frequency == "年度" {
  1226. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1227. } else {
  1228. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1229. }
  1230. //fmt.Println(startDate, endDate)
  1231. //err = data_manage.RefreshEdbDataByDl(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1232. //if err != nil {
  1233. // return errors.New("RefreshEdbDataByDl:" + err.Error())
  1234. //}
  1235. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1236. if err != nil {
  1237. return errors.New("RefreshEdbData Err:" + err.Error())
  1238. }
  1239. if resp.Ret != 200 {
  1240. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1241. }
  1242. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1243. //if err != nil {
  1244. // return err
  1245. //}
  1246. //if item != nil {
  1247. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1248. // if err != nil {
  1249. // return err
  1250. // }
  1251. //}
  1252. }
  1253. return err
  1254. }
  1255. // RefreshDataFromShfe 刷新上期能源数据
  1256. func RefreshDataFromShfe(wg *sync.WaitGroup) (err error) {
  1257. defer func() {
  1258. if err != nil {
  1259. fmt.Println("RefreshDataFromShfe Err:" + err.Error())
  1260. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromShfe ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1261. go alarm_msg.SendAlarmMsg("RefreshDataFromShfe ErrMsg:"+err.Error(), 3)
  1262. }
  1263. wg.Done()
  1264. }()
  1265. var condition string
  1266. var pars []interface{}
  1267. condition += " AND source=? "
  1268. pars = append(pars, utils.DATA_SOURCE_SHFE)
  1269. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1270. if err != nil {
  1271. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1272. }
  1273. //var endDate string
  1274. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1275. for _, v := range items {
  1276. startDate := ""
  1277. if v.Frequency == "日度" {
  1278. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1279. } else if v.Frequency == "周度" {
  1280. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1281. } else if v.Frequency == "月度" {
  1282. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1283. } else if v.Frequency == "季度" {
  1284. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1285. } else if v.Frequency == "年度" {
  1286. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1287. } else {
  1288. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1289. }
  1290. //fmt.Println(startDate, endDate)
  1291. //err = data_manage.RefreshEdbDataByShfe(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1292. //if err != nil {
  1293. // return errors.New("RefreshEdbDataByShfe:" + err.Error())
  1294. //}
  1295. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1296. if err != nil {
  1297. return errors.New("RefreshEdbData Err:" + err.Error())
  1298. }
  1299. if resp.Ret != 200 {
  1300. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1301. }
  1302. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1303. //if err != nil {
  1304. // return err
  1305. //}
  1306. //if item != nil {
  1307. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1308. // if err != nil {
  1309. // return err
  1310. // }
  1311. //}
  1312. }
  1313. return err
  1314. }
  1315. // RefreshDataFromCffex 刷新中金所数据
  1316. func RefreshDataFromCffex(wg *sync.WaitGroup) (err error) {
  1317. defer func() {
  1318. if err != nil {
  1319. fmt.Println("RefreshDataFromCffex Err:" + err.Error())
  1320. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCffex ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1321. go alarm_msg.SendAlarmMsg("RefreshDataFromCffex ErrMsg:"+err.Error(), 3)
  1322. }
  1323. wg.Done()
  1324. }()
  1325. var condition string
  1326. var pars []interface{}
  1327. condition += " AND source=? "
  1328. pars = append(pars, utils.DATA_SOURCE_CFFEX)
  1329. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1330. if err != nil {
  1331. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1332. }
  1333. //var endDate string
  1334. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1335. for _, v := range items {
  1336. startDate := ""
  1337. if v.Frequency == "日度" {
  1338. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1339. } else if v.Frequency == "周度" {
  1340. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1341. } else if v.Frequency == "月度" {
  1342. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1343. } else if v.Frequency == "季度" {
  1344. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1345. } else if v.Frequency == "年度" {
  1346. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1347. } else {
  1348. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1349. }
  1350. //fmt.Println(startDate, endDate)
  1351. //err = data_manage.RefreshEdbDataByCffex(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1352. //if err != nil {
  1353. // return errors.New("RefreshEdbDataByCffex:" + err.Error())
  1354. //}
  1355. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1356. if err != nil {
  1357. return errors.New("RefreshEdbData Err:" + err.Error())
  1358. }
  1359. if resp.Ret != 200 {
  1360. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1361. }
  1362. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1363. //if err != nil {
  1364. // return err
  1365. //}
  1366. //if item != nil {
  1367. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1368. // if err != nil {
  1369. // return err
  1370. // }
  1371. //}
  1372. }
  1373. return err
  1374. }
  1375. // RefreshDataFromZz 刷新郑商所数据
  1376. func RefreshDataFromZz(wg *sync.WaitGroup) (err error) {
  1377. defer func() {
  1378. if err != nil {
  1379. fmt.Println("RefreshDataFromZz Err:" + err.Error())
  1380. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromZz ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1381. go alarm_msg.SendAlarmMsg("RefreshDataFromZz ErrMsg:"+err.Error(), 3)
  1382. }
  1383. wg.Done()
  1384. }()
  1385. var condition string
  1386. var pars []interface{}
  1387. condition += " AND source=? "
  1388. pars = append(pars, utils.DATA_SOURCE_ZZ)
  1389. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1390. if err != nil {
  1391. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1392. }
  1393. //var endDate string
  1394. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1395. for _, v := range items {
  1396. startDate := ""
  1397. if v.Frequency == "日度" {
  1398. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1399. } else if v.Frequency == "周度" {
  1400. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1401. } else if v.Frequency == "月度" {
  1402. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1403. } else if v.Frequency == "季度" {
  1404. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1405. } else if v.Frequency == "年度" {
  1406. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1407. } else {
  1408. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1409. }
  1410. //fmt.Println(startDate, endDate)
  1411. //err = data_manage.RefreshEdbDataByZz(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1412. //if err != nil {
  1413. // return errors.New("RefreshEdbDataByZz:" + err.Error())
  1414. //}
  1415. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1416. if err != nil {
  1417. return errors.New("RefreshEdbData Err:" + err.Error())
  1418. }
  1419. if resp.Ret != 200 {
  1420. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1421. }
  1422. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1423. //if err != nil {
  1424. // return err
  1425. //}
  1426. //if item != nil {
  1427. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1428. // if err != nil {
  1429. // return err
  1430. // }
  1431. //}
  1432. }
  1433. return err
  1434. }
  1435. // RefreshDataFromLt 刷新路透数据
  1436. func RefreshDataFromLt(wg *sync.WaitGroup) (err error) {
  1437. errMsgList := make([]string, 0)
  1438. defer func() {
  1439. //if err != nil {
  1440. // fmt.Println("RefreshDataFromLt Err:" + err.Error())
  1441. // //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromLt ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1442. // go alarm_msg.SendAlarmMsg("RefreshDataFromLt ErrMsg:"+err.Error(), 3)
  1443. //}
  1444. if len(errMsgList) > 0 {
  1445. fmt.Println("RefreshDataFromLt Err:", errMsgList)
  1446. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromLt ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1447. go alarm_msg.SendAlarmMsg("RefreshDataFromLt ErrMsg:"+strings.Join(errMsgList, `<br/>`), 3)
  1448. }
  1449. wg.Done()
  1450. }()
  1451. var condition string
  1452. var pars []interface{}
  1453. condition += " AND source=? "
  1454. pars = append(pars, utils.DATA_SOURCE_LT)
  1455. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1456. if err != nil {
  1457. errMsgList = append(errMsgList, "GetEdbInfoByCondition:"+err.Error())
  1458. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1459. }
  1460. //endDate := time.Now().Format(utils.FormatDate)
  1461. for _, v := range items {
  1462. startDate := v.StartDate.Format(utils.FormatDate)
  1463. //err = data_manage.RefreshAllEdbDataByLt(v.EdbInfoId, utils.DATA_SOURCE_LT, v.EdbCode, startDate, endDate)
  1464. //if err != nil {
  1465. // return errors.New("RefreshEdbDataByLt:" + err.Error())
  1466. //}
  1467. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1468. if err != nil {
  1469. errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
  1470. continue
  1471. }
  1472. if resp.Ret != 200 {
  1473. errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
  1474. continue
  1475. }
  1476. //更新指标的最新数据
  1477. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1478. //if err != nil {
  1479. // return err
  1480. //}
  1481. //if item != nil {
  1482. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1483. // if err != nil {
  1484. // return err
  1485. // }
  1486. //}
  1487. }
  1488. return err
  1489. }
  1490. func ResetEdbInfoIsUpdate(cont context.Context) (err error) {
  1491. go data_manage.ResetEdbInfoIsUpdate()
  1492. return nil
  1493. }
  1494. // CheckWindDataInterface 检测wind数据服务器
  1495. func CheckWindDataInterface(cont context.Context) (err error) {
  1496. for _, hzDataWindUrl := range utils.Hz_Data_WIND_Url_List {
  1497. go func(urlStr string) {
  1498. checkUrl := urlStr + `hz_server`
  1499. body, err := http.Get(checkUrl)
  1500. if err != nil {
  1501. msg := fmt.Sprintf("检测:%s ;失败:CheckWindDataInterface ErrMsg:%s", checkUrl, err.Error())
  1502. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1503. go alarm_msg.SendAlarmMsg(msg, 3)
  1504. } else {
  1505. result := string(body)
  1506. if result != `1` {
  1507. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
  1508. //msg := "检测Wind数据服务器2失败:CheckWindDataInterface ErrMsg:" + string(body)
  1509. msg := fmt.Sprintf("检测%s ;失败:CheckWindDataInterface ErrMsg:%s", checkUrl, string(body))
  1510. go alarm_msg.SendAlarmMsg(msg, 3)
  1511. }
  1512. }
  1513. }(hzDataWindUrl)
  1514. }
  1515. return
  1516. }
  1517. // RefreshDataFromCoal 刷新煤炭网数据
  1518. func RefreshDataFromCoal(wg *sync.WaitGroup) (err error) {
  1519. defer func() {
  1520. if err != nil {
  1521. fmt.Println("RefreshDataFromCoal Err:" + err.Error())
  1522. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCoal ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1523. go alarm_msg.SendAlarmMsg("RefreshDataFromCoal ErrMsg:"+err.Error(), 3)
  1524. }
  1525. wg.Done()
  1526. }()
  1527. var condition string
  1528. var pars []interface{}
  1529. condition += " AND source=? "
  1530. pars = append(pars, utils.DATA_SOURCE_COAL)
  1531. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1532. if err != nil {
  1533. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1534. }
  1535. //var endDate string
  1536. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1537. for _, v := range items {
  1538. startDate := ""
  1539. if v.Frequency == "日度" {
  1540. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1541. } else if v.Frequency == "周度" {
  1542. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1543. } else if v.Frequency == "月度" {
  1544. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1545. } else if v.Frequency == "季度" {
  1546. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1547. } else if v.Frequency == "年度" {
  1548. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1549. } else {
  1550. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1551. }
  1552. //fmt.Println(startDate, endDate)
  1553. //err = data_manage.RefreshEdbDataByZz(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1554. //if err != nil {
  1555. // return errors.New("RefreshEdbDataByZz:" + err.Error())
  1556. //}
  1557. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1558. if err != nil {
  1559. return errors.New("RefreshEdbData Err:" + err.Error())
  1560. }
  1561. if resp.Ret != 200 {
  1562. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1563. }
  1564. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1565. //if err != nil {
  1566. // return err
  1567. //}
  1568. //if item != nil {
  1569. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1570. // if err != nil {
  1571. // return err
  1572. // }
  1573. //}
  1574. }
  1575. return err
  1576. }
  1577. // RefreshDataFromEic 刷欧洲天然气数据
  1578. func RefreshDataFromEic(wg *sync.WaitGroup) (err error) {
  1579. defer func() {
  1580. if err != nil {
  1581. fmt.Println("RefreshDataFromEic Err:" + err.Error())
  1582. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCoal ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1583. go alarm_msg.SendAlarmMsg("RefreshDataFromEic ErrMsg:"+err.Error(), 3)
  1584. }
  1585. wg.Done()
  1586. }()
  1587. var condition string
  1588. var pars []interface{}
  1589. condition += " AND source=? "
  1590. pars = append(pars, utils.DATA_SOURCE_GIE)
  1591. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1592. if err != nil {
  1593. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1594. }
  1595. //var endDate string
  1596. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1597. for _, v := range items {
  1598. startDate := ""
  1599. if v.Frequency == "日度" {
  1600. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1601. } else if v.Frequency == "周度" {
  1602. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1603. } else if v.Frequency == "月度" {
  1604. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1605. } else if v.Frequency == "季度" {
  1606. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1607. } else if v.Frequency == "年度" {
  1608. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1609. } else {
  1610. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1611. }
  1612. //fmt.Println(startDate, endDate)
  1613. //err = data_manage.RefreshEdbDataByZz(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1614. //if err != nil {
  1615. // return errors.New("RefreshEdbDataByZz:" + err.Error())
  1616. //}
  1617. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1618. if err != nil {
  1619. return errors.New("RefreshEdbData Err:" + err.Error())
  1620. }
  1621. if resp.Ret != 200 {
  1622. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1623. }
  1624. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1625. //if err != nil {
  1626. // return err
  1627. //}
  1628. //if item != nil {
  1629. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1630. // if err != nil {
  1631. // return err
  1632. // }
  1633. //}
  1634. }
  1635. return err
  1636. }
  1637. // RefreshDataFromEic 刷新谷歌出行数据
  1638. func RefreshDataFromGoogleTravel(wg *sync.WaitGroup) (err error) {
  1639. defer func() {
  1640. if err != nil {
  1641. fmt.Println("RefreshDataFromGoogleTravel Err:" + err.Error())
  1642. go alarm_msg.SendAlarmMsg("RefreshDataFromGoogleTravel ErrMsg:"+err.Error(), 3)
  1643. }
  1644. wg.Done()
  1645. }()
  1646. var condition string
  1647. var pars []interface{}
  1648. condition += " AND source=? "
  1649. pars = append(pars, utils.DATA_SOURCE_GOOGLE_TRAVEL)
  1650. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1651. if err != nil {
  1652. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1653. }
  1654. for _, v := range items {
  1655. startDate := ""
  1656. if v.Frequency == "日度" {
  1657. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1658. } else if v.Frequency == "周度" {
  1659. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1660. } else if v.Frequency == "月度" {
  1661. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1662. } else if v.Frequency == "季度" {
  1663. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1664. } else if v.Frequency == "年度" {
  1665. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1666. } else {
  1667. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1668. }
  1669. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1670. if err != nil {
  1671. return errors.New("RefreshEdbData Err:" + err.Error())
  1672. }
  1673. if resp.Ret != 200 {
  1674. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1675. }
  1676. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1677. //if err != nil {
  1678. // return err
  1679. //}
  1680. //if item != nil {
  1681. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1682. // if err != nil {
  1683. // return err
  1684. // }
  1685. //}
  1686. }
  1687. return err
  1688. }
  1689. // RefreshDataFromMysteelChemical 刷新钢联化工数据
  1690. func RefreshDataFromMysteelChemical(wg *sync.WaitGroup) (err error) {
  1691. defer func() {
  1692. if err != nil {
  1693. fmt.Println("RefreshDataFromMysteelChemical Err:" + err.Error())
  1694. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1695. go alarm_msg.SendAlarmMsg("RefreshDataFromMysteelChemical ErrMsg:"+err.Error(), 3)
  1696. }
  1697. wg.Done()
  1698. }()
  1699. var condition string
  1700. var pars []interface{}
  1701. condition += " AND source=? "
  1702. pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  1703. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1704. if err != nil {
  1705. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1706. }
  1707. //var endDate string
  1708. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1709. for _, v := range items {
  1710. startDate := ""
  1711. if v.Frequency == "日度" {
  1712. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1713. } else if v.Frequency == "周度" {
  1714. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1715. } else if v.Frequency == "月度" {
  1716. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1717. } else if v.Frequency == "季度" {
  1718. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1719. } else if v.Frequency == "年度" {
  1720. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1721. } else {
  1722. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1723. }
  1724. //fmt.Println(startDate, endDate)
  1725. //err = data_manage.RefreshEdbDataByGl(v.EdbInfoId, v.EdbCode, startDate, endDate)
  1726. //if err != nil {
  1727. // return errors.New("RefreshEdbDataByGl:" + err.Error())
  1728. //}
  1729. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1730. if err != nil {
  1731. return errors.New("RefreshEdbData Err:" + err.Error())
  1732. }
  1733. if resp.Ret != 200 {
  1734. return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1735. }
  1736. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1737. //if err != nil {
  1738. // return err
  1739. //}
  1740. //if item != nil {
  1741. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1742. // if err != nil {
  1743. // return err
  1744. // }
  1745. //}
  1746. }
  1747. return err
  1748. }
  1749. // RefreshDataFromEiaSteo 刷新eia steo 报告数据
  1750. func RefreshDataFromEiaSteo(wg *sync.WaitGroup) (err error) {
  1751. defer func() {
  1752. if err != nil {
  1753. fmt.Println("RefreshDataFromEiaSteo Err:" + err.Error())
  1754. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1755. go alarm_msg.SendAlarmMsg("RefreshDataFromEiaSteo ErrMsg:"+err.Error(), 3)
  1756. }
  1757. wg.Done()
  1758. }()
  1759. var condition string
  1760. var pars []interface{}
  1761. condition += " AND source=? "
  1762. pars = append(pars, utils.DATA_SOURCE_EIA_STEO)
  1763. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1764. if err != nil {
  1765. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1766. }
  1767. //var endDate string
  1768. //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  1769. for _, v := range items {
  1770. startDate := ""
  1771. if v.Frequency == "日度" {
  1772. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1773. } else if v.Frequency == "周度" {
  1774. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1775. } else if v.Frequency == "月度" {
  1776. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1777. } else if v.Frequency == "季度" {
  1778. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1779. } else if v.Frequency == "年度" {
  1780. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1781. } else {
  1782. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1783. }
  1784. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1785. if err != nil {
  1786. return errors.New("RefreshDataFromEiaSteoData Err:" + err.Error())
  1787. }
  1788. if resp.Ret != 200 {
  1789. return errors.New("RefreshDataFromEiaSteoData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1790. }
  1791. //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  1792. //if err != nil {
  1793. // return err
  1794. //}
  1795. //if item != nil {
  1796. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  1797. // if err != nil {
  1798. // return err
  1799. // }
  1800. //}
  1801. }
  1802. return err
  1803. }
  1804. // RefreshDataFromComTrade 刷新 UN 数据
  1805. func RefreshDataFromComTrade(wg *sync.WaitGroup) (err error) {
  1806. defer func() {
  1807. if err != nil {
  1808. fmt.Println("RefreshDataFromComTrade Err:" + err.Error())
  1809. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1810. go alarm_msg.SendAlarmMsg("RefreshDataFromComTrade ErrMsg:"+err.Error(), 3)
  1811. }
  1812. wg.Done()
  1813. }()
  1814. var condition string
  1815. var pars []interface{}
  1816. condition += " AND source=? "
  1817. pars = append(pars, utils.DATA_SOURCE_COM_TRADE)
  1818. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1819. if err != nil {
  1820. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1821. }
  1822. for _, v := range items {
  1823. startDate := ""
  1824. if v.Frequency == "日度" {
  1825. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1826. } else if v.Frequency == "周度" {
  1827. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1828. } else if v.Frequency == "月度" {
  1829. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1830. } else if v.Frequency == "季度" {
  1831. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1832. } else if v.Frequency == "年度" {
  1833. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1834. } else {
  1835. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1836. }
  1837. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1838. if err != nil {
  1839. return errors.New("RefreshDataFromComTrade Err:" + err.Error())
  1840. }
  1841. if resp.Ret != 200 {
  1842. return errors.New("RefreshDataFromComTrade Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1843. }
  1844. }
  1845. return err
  1846. }
  1847. // RefreshDataFromSci 刷新 卓创 数据
  1848. func RefreshDataFromSci(wg *sync.WaitGroup) (err error) {
  1849. defer func() {
  1850. if err != nil {
  1851. fmt.Println("RefreshDataFromSci Err:" + err.Error())
  1852. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1853. go alarm_msg.SendAlarmMsg("RefreshDataFromSci ErrMsg:"+err.Error(), 3)
  1854. }
  1855. wg.Done()
  1856. }()
  1857. var condition string
  1858. var pars []interface{}
  1859. condition += " AND source=? "
  1860. pars = append(pars, utils.DATA_SOURCE_SCI)
  1861. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1862. if err != nil {
  1863. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1864. }
  1865. for _, v := range items {
  1866. startDate := ""
  1867. if v.Frequency == "日度" {
  1868. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1869. } else if v.Frequency == "周度" {
  1870. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1871. } else if v.Frequency == "月度" {
  1872. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1873. } else if v.Frequency == "季度" {
  1874. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1875. } else if v.Frequency == "年度" {
  1876. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1877. } else {
  1878. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1879. }
  1880. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1881. if err != nil {
  1882. return errors.New("RefreshDataFromSci Err:" + err.Error())
  1883. }
  1884. if resp.Ret != 200 {
  1885. return errors.New("RefreshDataFromSci Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1886. }
  1887. }
  1888. return err
  1889. }
  1890. // RefreshDataFromNationalStatistics 刷新统计局数据
  1891. func RefreshDataFromNationalStatistics(wg *sync.WaitGroup) (err error) {
  1892. defer func() {
  1893. if err != nil {
  1894. fmt.Println("RefreshDataFromNationalStatistics Err:" + err.Error())
  1895. go alarm_msg.SendAlarmMsg("RefreshDataFromNationalStatistics ErrMsg:"+err.Error(), 3)
  1896. }
  1897. wg.Done()
  1898. }()
  1899. var condition string
  1900. var pars []interface{}
  1901. condition += ` AND source = ? `
  1902. pars = append(pars, utils.DATA_SOURCE_NATIONAL_STATISTICS)
  1903. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
  1904. if err != nil {
  1905. return errors.New("GetEdbInfoByCondition:" + err.Error())
  1906. }
  1907. for _, v := range items {
  1908. startDate := ""
  1909. if v.Frequency == "日度" {
  1910. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1911. } else if v.Frequency == "周度" {
  1912. startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
  1913. } else if v.Frequency == "月度" {
  1914. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
  1915. } else if v.Frequency == "季度" {
  1916. startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
  1917. } else if v.Frequency == "年度" {
  1918. startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
  1919. } else {
  1920. startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
  1921. }
  1922. resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
  1923. if err != nil {
  1924. return errors.New("RefreshDataFromNationalStatistics Err:" + err.Error())
  1925. }
  1926. if resp.Ret != 200 {
  1927. return errors.New("RefreshDataFromNationalStatistics Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
  1928. }
  1929. }
  1930. return err
  1931. }