edb_info.go 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  1. package data
  2. import (
  3. "errors"
  4. "eta/eta_chart_lib/models"
  5. "eta/eta_chart_lib/models/data_manage"
  6. "eta/eta_chart_lib/services/alarm_msg"
  7. "eta/eta_chart_lib/utils"
  8. "fmt"
  9. "github.com/shopspring/decimal"
  10. "math"
  11. "sort"
  12. "time"
  13. )
  14. // EdbInfoRefreshAllFromBaseBak
  15. // @author Roc
  16. // @datetime 2022-09-16 11:04:44
  17. // @description 全部刷新指标(切换到edb_lib服务),将原有的单个指标刷新,调整为批量多个指标刷新
  18. // DeprecatedTime 2023-10-23 09:38:19废弃
  19. // Deprecated
  20. func EdbInfoRefreshAllFromBaseBak(edbInfoIdList []int, refreshAll bool) (err error, errmsg string) {
  21. defer func() {
  22. if err != nil {
  23. fmt.Println("EdbInfoRefreshAllFromBaseV2 Err:" + err.Error() + ";errmsg:" + errmsg)
  24. go alarm_msg.SendAlarmMsg("EdbInfoRefreshFromBaseV2,Err"+err.Error()+";errMsg:"+errmsg, 3)
  25. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
  26. }
  27. }()
  28. // 获取关联的基础指标
  29. newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr, err, errmsg := getRefreshEdbInfoListByIds(edbInfoIdList)
  30. if err != nil {
  31. return
  32. }
  33. var startDate string
  34. for _, bv := range newBaseEdbInfoArr {
  35. //source := bv.Source
  36. //edbInfoId := bv.EdbInfoId
  37. //edbCode := bv.EdbCode
  38. if bv.StartDate == "0000-00-00" {
  39. continue
  40. }
  41. //开始时间
  42. startDate = ``
  43. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  44. sTime, tmpErr := time.Parse(utils.FormatDate, bv.StartDate)
  45. if tmpErr != nil {
  46. err = tmpErr
  47. errmsg = err.Error()
  48. return
  49. }
  50. startDate = sTime.Format(utils.FormatDate)
  51. } else {
  52. sTime, tmpErr := time.Parse(utils.FormatDate, bv.EndDate)
  53. if tmpErr != nil {
  54. err = tmpErr
  55. errmsg = err.Error()
  56. return
  57. }
  58. frequency := bv.Frequency
  59. var limitDay int
  60. switch frequency {
  61. case "日度":
  62. limitDay = utils.DATA_REFRESH
  63. case "周度":
  64. limitDay = utils.DATA_REFRESH * 7
  65. case "月度":
  66. limitDay = utils.DATA_REFRESH * 30
  67. case "季度":
  68. limitDay = utils.DATA_REFRESH * 90
  69. case "年度":
  70. limitDay = utils.DATA_REFRESH * 365
  71. default:
  72. limitDay = utils.DATA_REFRESH
  73. }
  74. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  75. }
  76. result, tmpErr := RefreshEdbData(bv.EdbInfoId, bv.Source, bv.SubSource, bv.EdbCode, startDate)
  77. if tmpErr != nil {
  78. err = tmpErr
  79. fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err", time.Now())
  80. errmsg = "RefreshBaseEdbData Err:" + tmpErr.Error()
  81. return
  82. }
  83. if result.Ret != 200 {
  84. fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  85. errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  86. err = fmt.Errorf("刷新失败, err:", errmsg)
  87. return
  88. }
  89. //maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  90. //if err != nil {
  91. // if err.Error() == utils.ErrNoRow() { //找不到数据,那么就进入到下一条数据做处理
  92. // continue
  93. // }
  94. // return err
  95. //}
  96. //if maxAndMinItem != nil {
  97. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
  98. // if err != nil {
  99. // return err
  100. // }
  101. //}
  102. fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
  103. }
  104. //刷新相关普通计算指标
  105. for _, v := range calculateArr {
  106. edbInfo := newCalculateMap[v]
  107. if edbInfo == nil {
  108. return
  109. }
  110. startDate = edbInfo.StartDate
  111. source := edbInfo.Source
  112. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  113. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  114. } else {
  115. if source == utils.DATA_SOURCE_CALCULATE {
  116. startDate = ``
  117. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  118. startDate = edbInfo.StartDate
  119. } else {
  120. sTime, tmpErr := time.Parse(utils.FormatDate, edbInfo.EndDate)
  121. if tmpErr != nil {
  122. err = tmpErr
  123. errmsg = tmpErr.Error()
  124. return
  125. }
  126. frequency := edbInfo.Frequency
  127. var limitDay int
  128. switch frequency {
  129. case "日度":
  130. limitDay = utils.DATA_REFRESH
  131. case "周度":
  132. limitDay = utils.DATA_REFRESH * 7
  133. case "月度":
  134. limitDay = utils.DATA_REFRESH * 30
  135. case "季度":
  136. limitDay = utils.DATA_REFRESH * 90
  137. case "年度":
  138. limitDay = utils.DATA_REFRESH * 365
  139. default:
  140. limitDay = utils.DATA_REFRESH
  141. }
  142. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  143. }
  144. }
  145. }
  146. result, tmpErr := RefreshEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  147. if tmpErr != nil {
  148. err = tmpErr
  149. fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
  150. errmsg = "RefreshEdbCalculateData Err:" + tmpErr.Error()
  151. return
  152. }
  153. if result.Ret != 200 {
  154. fmt.Println(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  155. errmsg = fmt.Sprint(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  156. err = fmt.Errorf("刷新失败")
  157. return
  158. }
  159. }
  160. //刷新相关预测计算指标
  161. for _, v := range predictCalculateArr {
  162. edbInfo := newPredictCalculateMap[v]
  163. if edbInfo == nil {
  164. return
  165. }
  166. startDate = edbInfo.StartDate
  167. source := edbInfo.Source
  168. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  169. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  170. } else {
  171. if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
  172. startDate = ``
  173. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  174. startDate = edbInfo.StartDate
  175. } else {
  176. sTime, tmpErr := time.Parse(utils.FormatDate, edbInfo.EndDate)
  177. if tmpErr != nil {
  178. err = tmpErr
  179. errmsg = tmpErr.Error()
  180. return
  181. }
  182. frequency := edbInfo.Frequency
  183. var limitDay int
  184. switch frequency {
  185. case "日度":
  186. limitDay = utils.DATA_REFRESH
  187. case "周度":
  188. limitDay = utils.DATA_REFRESH * 7
  189. case "月度":
  190. limitDay = utils.DATA_REFRESH * 30
  191. case "季度":
  192. limitDay = utils.DATA_REFRESH * 90
  193. case "年度":
  194. limitDay = utils.DATA_REFRESH * 365
  195. default:
  196. limitDay = utils.DATA_REFRESH
  197. }
  198. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  199. }
  200. }
  201. }
  202. result, tmpErr := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  203. if tmpErr != nil {
  204. err = tmpErr
  205. fmt.Println(v, "RefreshPredictEdbCalculateData err", time.Now())
  206. errmsg = "RefreshPredictEdbCalculateData Err:" + tmpErr.Error()
  207. return
  208. }
  209. if result.Ret != 200 {
  210. fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  211. errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  212. err = fmt.Errorf("刷新失败")
  213. return
  214. }
  215. }
  216. // 4、更新动态环差值
  217. {
  218. predictEdbInfoIdList := make([]int, 0)
  219. for _, v := range newBasePredictEdbInfoArr {
  220. predictEdbInfoIdList = append(predictEdbInfoIdList, v.EdbInfoId)
  221. }
  222. fmt.Println("predictEdbConfCalculateMappingDetailList:", predictEdbInfoIdList)
  223. predictEdbConfCalculateMappingDetailList, tmpErr := data_manage.GetPredictEdbConfCalculateMappingDetailListByEdbInfoId(predictEdbInfoIdList)
  224. if tmpErr != nil {
  225. err = tmpErr
  226. errmsg = fmt.Sprint("更新动态环差值时,获取数据失败:" + err.Error())
  227. return
  228. }
  229. for _, bv := range predictEdbConfCalculateMappingDetailList {
  230. result, tmpErr := RefreshEdbData(bv.EdbInfoId, utils.DATA_SOURCE_PREDICT, utils.DATA_SUB_SOURCE_EDB, bv.EdbCode, "")
  231. if tmpErr != nil {
  232. err = tmpErr
  233. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err", time.Now())
  234. errmsg = "RefreshBasePredictEdbData Err:" + err.Error()
  235. return
  236. }
  237. if result.Ret != 200 {
  238. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  239. errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  240. err = errors.New("刷新失败:" + errmsg)
  241. return
  242. }
  243. fmt.Println("end predictEdbConfCalculateMappingDetailList:", bv, time.Now())
  244. }
  245. }
  246. //5、刷新相关预测计算指标
  247. for _, v := range predictCalculateArr {
  248. edbInfo := newPredictCalculateMap[v]
  249. if edbInfo == nil {
  250. return
  251. }
  252. startDate = edbInfo.StartDate
  253. source := edbInfo.Source
  254. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  255. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  256. } else {
  257. if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
  258. startDate = ``
  259. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  260. startDate = edbInfo.StartDate
  261. } else {
  262. sTime, tmpErr := time.Parse(utils.FormatDate, edbInfo.EndDate)
  263. if tmpErr != nil {
  264. err = tmpErr
  265. errmsg = tmpErr.Error()
  266. return
  267. }
  268. frequency := edbInfo.Frequency
  269. var limitDay int
  270. switch frequency {
  271. case "日度":
  272. limitDay = utils.DATA_REFRESH
  273. case "周度":
  274. limitDay = utils.DATA_REFRESH * 7
  275. case "月度":
  276. limitDay = utils.DATA_REFRESH * 30
  277. case "季度":
  278. limitDay = utils.DATA_REFRESH * 90
  279. case "年度":
  280. limitDay = utils.DATA_REFRESH * 365
  281. default:
  282. limitDay = utils.DATA_REFRESH
  283. }
  284. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  285. }
  286. }
  287. }
  288. result, tmpErr := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  289. if tmpErr != nil {
  290. err = tmpErr
  291. fmt.Println(v, "RefreshPredictEdbCalculateData err", time.Now())
  292. errmsg = "RefreshPredictEdbCalculateData Err:" + tmpErr.Error()
  293. return
  294. }
  295. if result.Ret != 200 {
  296. fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  297. errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  298. err = fmt.Errorf("刷新失败")
  299. return
  300. }
  301. }
  302. return
  303. }
  304. // getRefreshEdbInfoList 获取待更新的指标(普通基础指标、普通运算指标,预测运算指标)
  305. func getRefreshEdbInfoListByIds(edbInfoIdList []int) (newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int, err error, errMsg string) {
  306. calculateList, err := data_manage.GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList)
  307. if err != nil && err.Error() != utils.ErrNoRow() {
  308. err = errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
  309. return
  310. }
  311. // 获取指标信息
  312. edbInfoList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  313. if err != nil {
  314. err = errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
  315. return
  316. }
  317. baseEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 基础普通指标
  318. calculateInfoArr := make([]*data_manage.EdbInfo, 0) //基础运算指标
  319. basePredictEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 预测普通指标
  320. predictCalculateInfoArr := make([]*data_manage.EdbInfo, 0) //预测运算指标
  321. for _, baseEdbInfo := range edbInfoList {
  322. if baseEdbInfo.EdbInfoType == 0 { //普通指标
  323. switch baseEdbInfo.EdbType {
  324. case 1: //基础指标
  325. baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
  326. case 2: //计算指标
  327. calculateList = append(calculateList, baseEdbInfo)
  328. }
  329. } else { //预测指标
  330. switch baseEdbInfo.EdbType {
  331. case 1: //基础指标
  332. basePredictEdbInfoArr = append(basePredictEdbInfoArr, baseEdbInfo)
  333. case 2: //计算指标
  334. predictCalculateInfoArr = append(predictCalculateInfoArr, baseEdbInfo)
  335. }
  336. }
  337. }
  338. // 计算指标
  339. for _, v := range calculateList {
  340. getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  341. if tmpErr != nil {
  342. err = tmpErr
  343. fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  344. errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  345. return
  346. }
  347. for _, tmpEdbInfo := range getBaseEdbInfoArr {
  348. switch tmpEdbInfo.EdbInfoType {
  349. case 0: //普通基础指标
  350. baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  351. case 1: //预测基础指标
  352. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  353. }
  354. }
  355. for _, tmpEdbInfo := range getCalculateInfoArr {
  356. switch tmpEdbInfo.EdbInfoType {
  357. case 0: //普通运算指标
  358. calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  359. case 1: //预测运算指标
  360. //predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  361. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  362. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  363. } else {
  364. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  365. }
  366. }
  367. }
  368. switch v.EdbInfoType {
  369. case 0: //普通运算指标
  370. calculateInfoArr = append(calculateInfoArr, v)
  371. case 1: //预测运算指标
  372. if v.EdbType == 1 { //预测普通指标
  373. basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
  374. } else {
  375. predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  376. }
  377. }
  378. }
  379. // 预测计算指标
  380. for _, v := range predictCalculateInfoArr {
  381. getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  382. if tmpErr != nil {
  383. err = tmpErr
  384. fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  385. errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  386. return
  387. }
  388. for _, tmpEdbInfo := range getBaseEdbInfoArr {
  389. switch tmpEdbInfo.EdbInfoType {
  390. case 0: //普通基础指标
  391. baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  392. case 1: //预测基础指标
  393. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  394. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  395. } else {
  396. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  397. }
  398. //basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  399. }
  400. }
  401. for _, tmpEdbInfo := range getCalculateInfoArr {
  402. switch tmpEdbInfo.EdbInfoType {
  403. case 0: //普通运算指标
  404. calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  405. case 1: //预测运算指标
  406. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  407. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  408. } else {
  409. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  410. }
  411. //predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  412. }
  413. }
  414. switch v.EdbInfoType {
  415. case 0: //普通运算指标
  416. calculateInfoArr = append(calculateInfoArr, v)
  417. case 1: //预测运算指标
  418. if v.EdbType == 1 { //预测普通指标
  419. basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
  420. } else {
  421. predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  422. }
  423. }
  424. }
  425. // 第一次的计算指标map
  426. newCalculateMap = make(map[int]*data_manage.EdbInfo)
  427. for _, v := range calculateInfoArr {
  428. if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  429. calculateArr = append(calculateArr, v.EdbInfoId)
  430. }
  431. newCalculateMap[v.EdbInfoId] = v
  432. }
  433. // 基础预测指标
  434. if len(basePredictEdbInfoArr) > 0 {
  435. basePredictEdbInfoIdList := make([]int, 0)
  436. for _, v := range basePredictEdbInfoArr {
  437. basePredictEdbInfoIdList = append(basePredictEdbInfoIdList, v.EdbInfoId)
  438. }
  439. baseEdbInfoList, tmpErr := data_manage.GetPredictEdbInfoAllCalculate(basePredictEdbInfoIdList)
  440. if tmpErr != nil {
  441. err = tmpErr
  442. return
  443. }
  444. tmpCalculateList := make([]*data_manage.EdbInfo, 0)
  445. for _, v := range baseEdbInfoList {
  446. switch v.EdbType {
  447. case 1:
  448. baseEdbInfoArr = append(baseEdbInfoArr, v)
  449. case 2:
  450. // 如果不在第一次里面,那么在第二次 刷新预测指标的时候 需要加进去
  451. if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  452. tmpCalculateList = append(tmpCalculateList, v)
  453. }
  454. }
  455. }
  456. // 这里是查询预测指标用到的 普通计算指标
  457. for _, v := range tmpCalculateList {
  458. getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  459. if tmpErr != nil {
  460. err = tmpErr
  461. fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  462. errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  463. return
  464. }
  465. // 基础指标
  466. for _, tmpEdbInfo := range getBaseEdbInfoArr {
  467. switch tmpEdbInfo.EdbInfoType {
  468. case 0: //普通基础指标
  469. baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  470. case 1: //预测基础指标
  471. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  472. }
  473. }
  474. // 计算指标
  475. for _, tmpEdbInfo := range getCalculateInfoArr {
  476. switch tmpEdbInfo.EdbInfoType {
  477. case 0: //普通运算指标
  478. calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  479. case 1: //预测运算指标
  480. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  481. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  482. } else {
  483. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  484. }
  485. }
  486. }
  487. switch v.EdbInfoType {
  488. case 0: //普通运算指标
  489. calculateInfoArr = append(calculateInfoArr, v)
  490. case 1: //预测运算指标
  491. if v.EdbType == 1 { //预测普通指标
  492. basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
  493. } else {
  494. predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  495. }
  496. }
  497. }
  498. // 第二次计算指标的map
  499. for _, v := range calculateInfoArr {
  500. if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  501. calculateArr = append(calculateArr, v.EdbInfoId)
  502. }
  503. newCalculateMap[v.EdbInfoId] = v
  504. }
  505. }
  506. // 普通基础指标去重
  507. newBaseEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  508. baseMap := make(map[int]int)
  509. for _, v := range baseEdbInfoArr {
  510. if _, ok := baseMap[v.EdbInfoId]; !ok {
  511. newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
  512. }
  513. baseMap[v.EdbInfoId] = v.EdbInfoId
  514. }
  515. // 普通计算指标的id
  516. sort.Ints(calculateArr)
  517. // 普通预测指标去重
  518. newBasePredictEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  519. basePredictMap := make(map[int]int)
  520. for _, v := range basePredictEdbInfoArr {
  521. if _, ok := basePredictMap[v.EdbInfoId]; !ok {
  522. newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, v)
  523. }
  524. basePredictMap[v.EdbInfoId] = v.EdbInfoId
  525. }
  526. // 预测计算指标去重
  527. newPredictCalculateMap = make(map[int]*data_manage.EdbInfo)
  528. for _, v := range predictCalculateInfoArr {
  529. if _, ok := newPredictCalculateMap[v.EdbInfoId]; !ok {
  530. predictCalculateArr = append(predictCalculateArr, v.EdbInfoId)
  531. }
  532. newPredictCalculateMap[v.EdbInfoId] = v
  533. }
  534. // 预测计算指标的id
  535. sort.Ints(predictCalculateArr)
  536. return
  537. }
  538. // GetEdbSourceByEdbInfoIdList 获取关联指标的来源
  539. func GetEdbSourceByEdbInfoIdList(chartEdbInfoMappingList []*models.ChartEdbInfoMapping) (sourceNameList, sourceNameEnList []string) {
  540. sourceNameList = make([]string, 0)
  541. sourceNameEnList = make([]string, 0)
  542. sourceMap := make(map[int]string)
  543. for _, v := range chartEdbInfoMappingList {
  544. // 指标类型:1:基础指标,2:计算指标
  545. if v.EdbType == 2 || v.EdbInfoCategoryType == 1 {
  546. //sourceMap[0] = "弘则研究"
  547. baseEdbInfoArr, _, _ := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  548. for _, baseEdbInfo := range baseEdbInfoArr {
  549. if baseEdbInfo.EdbInfoType == 0 { //普通指标才参与,预测指标不参与
  550. sourceMap[baseEdbInfo.Source] = baseEdbInfo.SourceName
  551. }
  552. }
  553. } else {
  554. sourceMap[v.Source] = v.SourceName
  555. }
  556. }
  557. for source, sourceName := range sourceMap {
  558. if utils.InArrayByInt([]int{utils.DATA_SOURCE_MANUAL}, source) {
  559. continue
  560. }
  561. sourceNameList = append(sourceNameList, sourceName)
  562. sourceNameEn, ok := utils.DataSourceEnMap[source]
  563. if !ok {
  564. sourceNameEn = sourceName
  565. }
  566. sourceNameEnList = append(sourceNameEnList, sourceNameEn)
  567. }
  568. //sourceNameList = append(sourceNameList, utils.ChartDefaultNameCn)
  569. //sourceNameEnList = append(sourceNameEnList, utils.ChartDefaultNameEn)
  570. // 图表来源
  571. conf, e := models.GetBusinessConf()
  572. if e != nil {
  573. return
  574. }
  575. if conf[models.BusinessConfCompanyName] != "" {
  576. sourceNameList = append(sourceNameList, conf[models.BusinessConfCompanyName])
  577. sourceNameEnList = append(sourceNameEnList, conf[models.BusinessConfCompanyName])
  578. }
  579. return
  580. }
  581. // edbInfoRefreshAll
  582. //
  583. // @Description: 指标刷新服务
  584. // @author: Roc
  585. // @datetime2023-10-23 11:04:30
  586. // @param refreshAll bool
  587. // @param newBaseEdbInfoArr []*data_manage.EdbInfo
  588. // @param newBasePredictEdbInfoArr []*data_manage.EdbInfo
  589. // @param newCalculateMap map[int]*data_manage.EdbInfo
  590. // @param newPredictCalculateMap map[int]*data_manage.EdbInfo
  591. // @param calculateArr []int
  592. // @param predictCalculateArr []int
  593. // @return err error
  594. // @return errmsg string
  595. func edbInfoRefreshAll(refreshAll bool, newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int) (err error, errmsg string) {
  596. defer func() {
  597. if err != nil {
  598. fmt.Println("EdbInfoRefreshAllFromBaseV2 Err:" + err.Error() + ";errmsg:" + errmsg)
  599. go alarm_msg.SendAlarmMsg("EdbInfoRefreshFromBaseV2,Err"+err.Error()+";errMsg:"+errmsg, 3)
  600. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
  601. }
  602. }()
  603. var startDate string
  604. for _, bv := range newBaseEdbInfoArr {
  605. //source := bv.Source
  606. //edbInfoId := bv.EdbInfoId
  607. //edbCode := bv.EdbCode
  608. if bv.StartDate == "0000-00-00" {
  609. continue
  610. }
  611. //开始时间
  612. startDate = ``
  613. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  614. sTime, tmpErr := time.Parse(utils.FormatDate, bv.StartDate)
  615. if tmpErr != nil {
  616. err = tmpErr
  617. errmsg = err.Error()
  618. return
  619. }
  620. startDate = sTime.Format(utils.FormatDate)
  621. } else {
  622. sTime, tmpErr := time.Parse(utils.FormatDate, bv.EndDate)
  623. if tmpErr != nil {
  624. err = tmpErr
  625. errmsg = err.Error()
  626. return
  627. }
  628. frequency := bv.Frequency
  629. var limitDay int
  630. switch frequency {
  631. case "日度":
  632. limitDay = utils.DATA_REFRESH
  633. case "周度":
  634. limitDay = utils.DATA_REFRESH * 7
  635. case "月度":
  636. limitDay = utils.DATA_REFRESH * 30
  637. case "季度":
  638. limitDay = utils.DATA_REFRESH * 90
  639. case "年度":
  640. limitDay = utils.DATA_REFRESH * 365
  641. default:
  642. limitDay = utils.DATA_REFRESH
  643. }
  644. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  645. }
  646. result, tmpErr := RefreshEdbData(bv.EdbInfoId, bv.Source, bv.SubSource, bv.EdbCode, startDate)
  647. if tmpErr != nil {
  648. err = tmpErr
  649. fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err", time.Now())
  650. errmsg = "RefreshBaseEdbData Err:" + tmpErr.Error()
  651. return
  652. }
  653. if result.Ret != 200 {
  654. fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  655. errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  656. err = fmt.Errorf("刷新失败, err:", errmsg)
  657. return
  658. }
  659. //maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  660. //if err != nil {
  661. // if err.Error() == utils.ErrNoRow() { //找不到数据,那么就进入到下一条数据做处理
  662. // continue
  663. // }
  664. // return err
  665. //}
  666. //if maxAndMinItem != nil {
  667. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
  668. // if err != nil {
  669. // return err
  670. // }
  671. //}
  672. fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
  673. }
  674. //刷新相关普通计算指标
  675. for _, v := range calculateArr {
  676. edbInfo := newCalculateMap[v]
  677. if edbInfo == nil {
  678. return
  679. }
  680. startDate = edbInfo.StartDate
  681. source := edbInfo.Source
  682. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  683. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  684. } else {
  685. if source == utils.DATA_SOURCE_CALCULATE {
  686. startDate = ``
  687. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  688. startDate = edbInfo.StartDate
  689. } else {
  690. sTime, tmpErr := time.Parse(utils.FormatDate, edbInfo.EndDate)
  691. if tmpErr != nil {
  692. err = tmpErr
  693. errmsg = tmpErr.Error()
  694. return
  695. }
  696. frequency := edbInfo.Frequency
  697. var limitDay int
  698. switch frequency {
  699. case "日度":
  700. limitDay = utils.DATA_REFRESH
  701. case "周度":
  702. limitDay = utils.DATA_REFRESH * 7
  703. case "月度":
  704. limitDay = utils.DATA_REFRESH * 30
  705. case "季度":
  706. limitDay = utils.DATA_REFRESH * 90
  707. case "年度":
  708. limitDay = utils.DATA_REFRESH * 365
  709. default:
  710. limitDay = utils.DATA_REFRESH
  711. }
  712. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  713. }
  714. }
  715. }
  716. result, tmpErr := RefreshEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  717. if tmpErr != nil {
  718. err = tmpErr
  719. fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
  720. errmsg = "RefreshEdbCalculateData Err:" + tmpErr.Error()
  721. return
  722. }
  723. if result.Ret != 200 {
  724. fmt.Println(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  725. errmsg = fmt.Sprint(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  726. err = fmt.Errorf("刷新失败")
  727. return
  728. }
  729. }
  730. //刷新相关预测计算指标
  731. for _, v := range predictCalculateArr {
  732. edbInfo := newPredictCalculateMap[v]
  733. if edbInfo == nil {
  734. return
  735. }
  736. startDate = edbInfo.StartDate
  737. source := edbInfo.Source
  738. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  739. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  740. } else {
  741. if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
  742. startDate = ``
  743. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  744. startDate = edbInfo.StartDate
  745. } else {
  746. sTime, tmpErr := time.Parse(utils.FormatDate, edbInfo.EndDate)
  747. if tmpErr != nil {
  748. err = tmpErr
  749. errmsg = tmpErr.Error()
  750. return
  751. }
  752. frequency := edbInfo.Frequency
  753. var limitDay int
  754. switch frequency {
  755. case "日度":
  756. limitDay = utils.DATA_REFRESH
  757. case "周度":
  758. limitDay = utils.DATA_REFRESH * 7
  759. case "月度":
  760. limitDay = utils.DATA_REFRESH * 30
  761. case "季度":
  762. limitDay = utils.DATA_REFRESH * 90
  763. case "年度":
  764. limitDay = utils.DATA_REFRESH * 365
  765. default:
  766. limitDay = utils.DATA_REFRESH
  767. }
  768. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  769. }
  770. }
  771. }
  772. result, tmpErr := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  773. if tmpErr != nil {
  774. err = tmpErr
  775. fmt.Println(v, "RefreshPredictEdbCalculateData err", time.Now())
  776. errmsg = "RefreshPredictEdbCalculateData Err:" + tmpErr.Error()
  777. return
  778. }
  779. if result.Ret != 200 {
  780. fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  781. errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  782. err = fmt.Errorf("刷新失败")
  783. return
  784. }
  785. }
  786. // 4、更新动态环差值
  787. {
  788. predictEdbInfoIdList := make([]int, 0)
  789. for _, v := range newBasePredictEdbInfoArr {
  790. predictEdbInfoIdList = append(predictEdbInfoIdList, v.EdbInfoId)
  791. }
  792. fmt.Println("predictEdbConfCalculateMappingDetailList:", predictEdbInfoIdList)
  793. predictEdbConfCalculateMappingDetailList, tmpErr := data_manage.GetPredictEdbConfCalculateMappingDetailListByEdbInfoId(predictEdbInfoIdList)
  794. if tmpErr != nil {
  795. err = tmpErr
  796. errmsg = fmt.Sprint("更新动态环差值时,获取数据失败:" + err.Error())
  797. return
  798. }
  799. for _, bv := range predictEdbConfCalculateMappingDetailList {
  800. result, tmpErr := RefreshEdbData(bv.EdbInfoId, utils.DATA_SOURCE_PREDICT, utils.DATA_SUB_SOURCE_EDB, bv.EdbCode, "")
  801. if tmpErr != nil {
  802. err = tmpErr
  803. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err", time.Now())
  804. errmsg = "RefreshBasePredictEdbData Err:" + err.Error()
  805. return
  806. }
  807. if result.Ret != 200 {
  808. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  809. errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  810. err = errors.New("刷新失败:" + errmsg)
  811. return
  812. }
  813. fmt.Println("end predictEdbConfCalculateMappingDetailList:", bv, time.Now())
  814. }
  815. }
  816. //5、刷新相关预测计算指标
  817. for _, v := range predictCalculateArr {
  818. edbInfo := newPredictCalculateMap[v]
  819. if edbInfo == nil {
  820. return
  821. }
  822. startDate = edbInfo.StartDate
  823. source := edbInfo.Source
  824. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  825. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  826. } else {
  827. if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
  828. startDate = ``
  829. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  830. startDate = edbInfo.StartDate
  831. } else {
  832. sTime, tmpErr := time.Parse(utils.FormatDate, edbInfo.EndDate)
  833. if tmpErr != nil {
  834. err = tmpErr
  835. errmsg = tmpErr.Error()
  836. return
  837. }
  838. frequency := edbInfo.Frequency
  839. var limitDay int
  840. switch frequency {
  841. case "日度":
  842. limitDay = utils.DATA_REFRESH
  843. case "周度":
  844. limitDay = utils.DATA_REFRESH * 7
  845. case "月度":
  846. limitDay = utils.DATA_REFRESH * 30
  847. case "季度":
  848. limitDay = utils.DATA_REFRESH * 90
  849. case "年度":
  850. limitDay = utils.DATA_REFRESH * 365
  851. default:
  852. limitDay = utils.DATA_REFRESH
  853. }
  854. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  855. }
  856. }
  857. }
  858. result, tmpErr := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  859. if tmpErr != nil {
  860. err = tmpErr
  861. fmt.Println(v, "RefreshPredictEdbCalculateData err", time.Now())
  862. errmsg = "RefreshPredictEdbCalculateData Err:" + tmpErr.Error()
  863. return
  864. }
  865. if result.Ret != 200 {
  866. fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  867. errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  868. err = fmt.Errorf("刷新失败")
  869. return
  870. }
  871. }
  872. return
  873. }
  874. // EdbInfoRefreshAllFromBaseV3
  875. //
  876. // @Description: 全部刷新指标(切换到edb_lib服务)
  877. // @author: Roc
  878. // @datetime2023-10-23 09:57:55
  879. // @param edbInfoIdList []int
  880. // @param refreshAll bool
  881. // @param isSync bool
  882. // @return err error
  883. // @return isAsync bool
  884. func EdbInfoRefreshAllFromBase(edbInfoIdList []int, refreshAll bool) (err error, errMsg string) {
  885. defer func() {
  886. if err != nil {
  887. fmt.Println("EdbInfoRefreshAllFromBaseV3 Err:" + err.Error() + ";errMsg:" + errMsg)
  888. go alarm_msg.SendAlarmMsg("EdbInfoRefreshAllFromBaseV3,Err"+err.Error()+";errMsg:"+errMsg, 3)
  889. }
  890. }()
  891. traceEdbInfoList, err := TraceEdbInfoByEdbInfoIdList(edbInfoIdList)
  892. if err != nil {
  893. return
  894. }
  895. // existEdbInfoIdMap 已经处理了的指标id map
  896. existEdbInfoIdMap := make(map[int]int)
  897. // 基础指标
  898. newBaseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
  899. newBasePredictEdbInfoArr := make([]*data_manage.EdbInfo, 0)
  900. newBaseMap := make(map[int]*data_manage.EdbInfo)
  901. newPredictBaseMap := make(map[int]*data_manage.EdbInfo)
  902. // 计算指标
  903. newCalculateMap := make(map[int]*data_manage.EdbInfo)
  904. newPredictCalculateMap := make(map[int]*data_manage.EdbInfo)
  905. calculateArr := make([]int, 0)
  906. predictCalculateArr := make([]int, 0)
  907. // 获取关联指标
  908. for _, traceEdbInfo := range traceEdbInfoList {
  909. tmpBaseEdbInfoArr, tmpBasePredictEdbInfoArr, tmpCalculateMap, tmpPredictCalculateMap, _, _ := getRefreshEdbInfoListByTraceEdbInfo(traceEdbInfo, existEdbInfoIdMap)
  910. // 普通基础指标
  911. for _, edbInfo := range tmpBaseEdbInfoArr {
  912. if _, ok := newBaseMap[edbInfo.EdbInfoId]; !ok {
  913. if edbInfo.NoUpdate == 1 {
  914. continue
  915. }
  916. newBaseMap[edbInfo.EdbInfoId] = edbInfo
  917. newBaseEdbInfoArr = append(newBaseEdbInfoArr, edbInfo)
  918. }
  919. }
  920. // 预测基础指标
  921. for _, edbInfo := range tmpBasePredictEdbInfoArr {
  922. if _, ok := newPredictBaseMap[edbInfo.EdbInfoId]; !ok {
  923. newPredictBaseMap[edbInfo.EdbInfoId] = edbInfo
  924. newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, edbInfo)
  925. }
  926. }
  927. // 普通计算指标
  928. for _, edbInfo := range tmpCalculateMap {
  929. if _, ok := newCalculateMap[edbInfo.EdbInfoId]; !ok {
  930. if edbInfo.NoUpdate == 1 {
  931. continue
  932. }
  933. newCalculateMap[edbInfo.EdbInfoId] = edbInfo
  934. calculateArr = append(calculateArr, edbInfo.EdbInfoId)
  935. }
  936. }
  937. // 预测计算指标
  938. for _, edbInfo := range tmpPredictCalculateMap {
  939. if _, ok := newPredictCalculateMap[edbInfo.EdbInfoId]; !ok {
  940. newPredictCalculateMap[edbInfo.EdbInfoId] = edbInfo
  941. predictCalculateArr = append(predictCalculateArr, edbInfo.EdbInfoId)
  942. }
  943. }
  944. }
  945. // 普通计算指标的id
  946. sort.Ints(calculateArr)
  947. // 预测计算指标的id
  948. sort.Ints(predictCalculateArr)
  949. // 需要刷新的指标数量
  950. totalEdbInfo := len(newBaseEdbInfoArr) + len(calculateArr) + len(predictCalculateArr) + len(newBasePredictEdbInfoArr)
  951. if totalEdbInfo == 0 {
  952. return
  953. }
  954. //if totalEdbInfo <= 20{
  955. // err,errMsg = edbInfoRefreshAll(refreshAll, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
  956. //} else {
  957. // go edbInfoRefreshAll(refreshAll, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
  958. //}
  959. err, errMsg = edbInfoRefreshAll(refreshAll, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
  960. return
  961. }
  962. // getRefreshEdbInfoListByTraceEdbInfo
  963. //
  964. // @Description: 根据溯源获取关联指标(去掉重复指标id)
  965. // @author: Roc
  966. // @datetime2023-10-23 11:22:50
  967. // @param traceEdbInfo data_manage.TraceEdbInfoResp
  968. // @param existEdbInfoIdMap map[int]int
  969. // @return newBaseEdbInfoArr []*data_manage.EdbInfo
  970. // @return newBasePredictEdbInfoArr []*data_manage.EdbInfo
  971. // @return newCalculateMap map[int]*data_manage.EdbInfo
  972. // @return newPredictCalculateMap map[int]*data_manage.EdbInfo
  973. // @return calculateArr []int
  974. // @return predictCalculateArr []int
  975. func getRefreshEdbInfoListByTraceEdbInfo(traceEdbInfo data_manage.TraceEdbInfoResp, existEdbInfoIdMap map[int]int) (newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int) {
  976. newBaseEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  977. newBasePredictEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  978. newCalculateMap = make(map[int]*data_manage.EdbInfo)
  979. newPredictCalculateMap = make(map[int]*data_manage.EdbInfo)
  980. calculateArr = make([]int, 0)
  981. predictCalculateArr = make([]int, 0)
  982. _, ok := existEdbInfoIdMap[traceEdbInfo.EdbInfoId]
  983. if ok {
  984. return
  985. }
  986. existEdbInfoIdMap[traceEdbInfo.EdbInfoId] = traceEdbInfo.EdbInfoId
  987. switch traceEdbInfo.EdbInfoType {
  988. //0-普通指标; 1-预测指标
  989. case 0: // 0-普通指标
  990. if traceEdbInfo.EdbType == 1 { //1-基础指标
  991. newBaseEdbInfoArr = append(newBaseEdbInfoArr, traceEdbInfo.EdbInfo)
  992. } else if traceEdbInfo.EdbType == 2 { //2-计算指标
  993. newCalculateMap[traceEdbInfo.EdbInfoId] = traceEdbInfo.EdbInfo
  994. calculateArr = append(calculateArr, traceEdbInfo.EdbInfoId)
  995. }
  996. case 1: // 1-预测指标
  997. if traceEdbInfo.EdbType == 1 { //1-基础指标
  998. newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, traceEdbInfo.EdbInfo)
  999. } else if traceEdbInfo.EdbType == 2 { //2-计算指标
  1000. newPredictCalculateMap[traceEdbInfo.EdbInfoId] = traceEdbInfo.EdbInfo
  1001. predictCalculateArr = append(predictCalculateArr, traceEdbInfo.EdbInfoId)
  1002. }
  1003. }
  1004. if traceEdbInfo.Child != nil && len(traceEdbInfo.Child) > 0 {
  1005. for _, v := range traceEdbInfo.Child {
  1006. tmpBaseEdbInfoArr, tmpPredictEdbInfoArr, tmpCalculateMap, tmpPredictCalculateMap, tmpCalculateArr, tmpPredictCalculateArr := getRefreshEdbInfoListByTraceEdbInfo(v, existEdbInfoIdMap)
  1007. newBaseEdbInfoArr = append(newBaseEdbInfoArr, tmpBaseEdbInfoArr...)
  1008. newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, tmpPredictEdbInfoArr...)
  1009. for k, tmpEdbInfo := range tmpCalculateMap {
  1010. newCalculateMap[k] = tmpEdbInfo
  1011. }
  1012. for k, tmpEdbInfo := range tmpPredictCalculateMap {
  1013. newPredictCalculateMap[k] = tmpEdbInfo
  1014. }
  1015. calculateArr = append(calculateArr, tmpCalculateArr...)
  1016. predictCalculateArr = append(predictCalculateArr, tmpPredictCalculateArr...)
  1017. }
  1018. }
  1019. return
  1020. }
  1021. // TraceEdbInfoByEdbInfoIdList
  1022. //
  1023. // @Description: 根据指标id列表返回指标追溯的列表
  1024. // @author: Roc
  1025. // @datetime2023-10-23 11:22:21
  1026. // @param edbInfoIdList []int
  1027. // @return traceEdbInfoList []data_manage.TraceEdbInfoResp
  1028. // @return err error
  1029. func TraceEdbInfoByEdbInfoIdList(edbInfoIdList []int) (traceEdbInfoList []data_manage.TraceEdbInfoResp, err error) {
  1030. traceEdbInfoList = make([]data_manage.TraceEdbInfoResp, 0)
  1031. edbInfoList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1032. if err != nil {
  1033. return
  1034. }
  1035. edbInfoRuleMap := make(map[int]string, 0)
  1036. edbMappingMap := make(map[int][]*data_manage.EdbInfoCalculateMappingInfo)
  1037. findIdMap := make(map[int]int)
  1038. existMap := make(map[int]data_manage.TraceEdbInfoResp)
  1039. for _, edbInfo := range edbInfoList {
  1040. findIdMap[edbInfo.EdbInfoId] = edbInfo.EdbInfoId
  1041. //edbInfoRuleMap[edbInfoId] = getEdbRuleTitle(edbInfo)
  1042. traceEdbInfo := data_manage.TraceEdbInfoResp{
  1043. //EdbInfoId: edbInfo.EdbInfoId,
  1044. EdbInfoId: edbInfo.EdbInfoId,
  1045. EdbInfoType: edbInfo.EdbInfoType,
  1046. EdbName: edbInfo.EdbName,
  1047. EdbType: edbInfo.EdbType,
  1048. //Source: edbInfo.Source,
  1049. UniqueCode: edbInfo.UniqueCode,
  1050. ClassifyId: edbInfo.ClassifyId,
  1051. EdbInfo: edbInfo,
  1052. }
  1053. traceEdbInfo.Child, err = traceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, traceEdbInfo, edbInfoRuleMap, findIdMap, existMap, edbMappingMap)
  1054. traceEdbInfoList = append(traceEdbInfoList, traceEdbInfo)
  1055. }
  1056. //findEdbInfoIdList := make([]int, 0)
  1057. //for _, v := range findIdMap {
  1058. // findEdbInfoIdList = append(findEdbInfoIdList, v)
  1059. //}
  1060. //findEdbInfoList, err := data_manage.GetEdbInfoByIdList(findEdbInfoIdList)
  1061. //if err != nil {
  1062. // return
  1063. //}
  1064. //edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1065. //for _, tmpEdbInfo := range findEdbInfoList {
  1066. // edbInfoMap[tmpEdbInfo.EdbInfoId] = tmpEdbInfo
  1067. //}
  1068. //for k, traceEdbInfo := range traceEdbInfoList {
  1069. // traceEdbInfoList[k], err = handleTraceEdbInfo(traceEdbInfo, 0, edbInfoMap, edbMappingMap)
  1070. //}
  1071. return
  1072. }
  1073. // traceEdbInfoByEdbInfoId
  1074. //
  1075. // @Description: 指标追溯
  1076. // @author: Roc
  1077. // @datetime2023-10-23 11:21:54
  1078. // @param edbInfoId int
  1079. // @param traceEdbInfo data_manage.TraceEdbInfoResp
  1080. // @param edbInfoRuleMap map[int]string
  1081. // @param findIdMap map[int]int
  1082. // @param existMap map[int]data_manage.TraceEdbInfoResp
  1083. // @param edbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo
  1084. // @return child []data_manage.TraceEdbInfoResp
  1085. // @return err error
  1086. func traceEdbInfoByEdbInfoId(edbInfoId int, traceEdbInfo data_manage.TraceEdbInfoResp, edbInfoRuleMap map[int]string, findIdMap map[int]int, existMap map[int]data_manage.TraceEdbInfoResp, edbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo) (child []data_manage.TraceEdbInfoResp, err error) {
  1087. traceEdbInfo, ok := existMap[edbInfoId]
  1088. if ok {
  1089. return
  1090. }
  1091. child = make([]data_manage.TraceEdbInfoResp, 0)
  1092. edbInfoMappingList, e := data_manage.GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId)
  1093. if e != nil {
  1094. err = fmt.Errorf("GetEdbInfoCalculateMappingListByEdbInfoId err: %s", e.Error())
  1095. return
  1096. }
  1097. // 指标信息map
  1098. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1099. if len(edbInfoMappingList) > 0 {
  1100. fromEdbInfoIdList := make([]int, 0)
  1101. for _, v := range edbInfoMappingList {
  1102. fromEdbInfoIdList = append(fromEdbInfoIdList, v.FromEdbInfoId)
  1103. }
  1104. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(fromEdbInfoIdList)
  1105. if tmpErr != nil {
  1106. err = fmt.Errorf("traceEdbInfoByEdbInfoId GetEdbInfoByIdList err: %s", tmpErr.Error())
  1107. return
  1108. }
  1109. for _, v := range edbInfoList {
  1110. edbInfoMap[v.EdbInfoId] = v
  1111. }
  1112. }
  1113. edbMappingMap[edbInfoId] = edbInfoMappingList
  1114. for _, v := range edbInfoMappingList {
  1115. tmpEdbInfoId := v.FromEdbInfoId
  1116. tmpTraceEdbInfo := data_manage.TraceEdbInfoResp{
  1117. EdbInfoId: tmpEdbInfoId,
  1118. EdbInfoType: v.FromEdbInfoType,
  1119. EdbType: v.FromEdbType,
  1120. UniqueCode: v.FromUniqueCode,
  1121. ClassifyId: v.FromClassifyId,
  1122. EdbInfo: edbInfoMap[v.FromEdbInfoId],
  1123. }
  1124. // 计算指标/预测指标继续溯源
  1125. if edbInfoId != v.FromEdbInfoId && (v.FromEdbType == 2 || v.FromEdbInfoType == 1) {
  1126. // 查过了就不查了
  1127. if _, ok2 := findIdMap[tmpEdbInfoId]; !ok2 {
  1128. tmpTraceEdbInfo.Child, e = traceEdbInfoByEdbInfoId(tmpEdbInfoId, tmpTraceEdbInfo, edbInfoRuleMap, findIdMap, existMap, edbMappingMap)
  1129. if e != nil {
  1130. err = fmt.Errorf("traceEdbInfoByEdbInfoId err: %s", e.Error())
  1131. return
  1132. }
  1133. }
  1134. }
  1135. child = append(child, tmpTraceEdbInfo)
  1136. findIdMap[tmpEdbInfoId] = tmpEdbInfoId
  1137. }
  1138. existMap[edbInfoId] = traceEdbInfo
  1139. return
  1140. }
  1141. // GetEdbSourceByEdbInfoIdListForExcel 获取关联指标的来源
  1142. func GetEdbSourceByEdbInfoIdListForExcel(edbInfoIdList []int) (sourceNameList, sourceNameEnList []string, err error) {
  1143. sourceNameList = make([]string, 0)
  1144. sourceNameEnList = make([]string, 0)
  1145. sourceMap := make(map[int]string)
  1146. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1147. if tmpErr != nil {
  1148. err = tmpErr
  1149. return
  1150. }
  1151. for _, v := range edbInfoList {
  1152. // 指标类型:1:基础指标,2:计算指标
  1153. if v.EdbType == 2 {
  1154. //sourceMap[0] = "弘则研究"
  1155. baseEdbInfoArr, _, _ := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  1156. for _, baseEdbInfo := range baseEdbInfoArr {
  1157. if baseEdbInfo.EdbInfoType == 0 { //普通指标才参与,预测指标不参与
  1158. sourceMap[baseEdbInfo.Source] = baseEdbInfo.SourceName
  1159. }
  1160. }
  1161. } else {
  1162. sourceMap[v.Source] = v.SourceName
  1163. }
  1164. }
  1165. for source, sourceName := range sourceMap {
  1166. if utils.InArrayByInt([]int{utils.DATA_SOURCE_MANUAL, utils.DATA_SOURCE_MYSTEEL_CHEMICAL}, source) {
  1167. continue
  1168. }
  1169. sourceNameList = append(sourceNameList, sourceName)
  1170. sourceNameEn, ok := utils.DataSourceEnMap[source]
  1171. if !ok {
  1172. sourceNameEn = sourceName
  1173. }
  1174. sourceNameEnList = append(sourceNameEnList, sourceNameEn)
  1175. }
  1176. //sourceNameList = append(sourceNameList, utils.ChartDefaultNameCn)
  1177. //sourceNameEnList = append(sourceNameEnList, utils.ChartDefaultNameEn)
  1178. // 图表来源
  1179. conf, e := models.GetBusinessConf()
  1180. if e != nil {
  1181. return
  1182. }
  1183. if conf[models.BusinessConfCompanyName] != "" {
  1184. sourceNameList = append(sourceNameList, conf[models.BusinessConfCompanyName])
  1185. sourceNameEnList = append(sourceNameEnList, conf[models.BusinessConfCompanyName])
  1186. }
  1187. return
  1188. }
  1189. // HandleDataByLinearRegressionToList 插值法补充数据(线性方程式)
  1190. func HandleDataByLinearRegressionToList (edbInfoDataList []*models.EdbDataList, handleDataMap map[string]float64) (dataTimeList []string,valueList []float64, err error) {
  1191. if len(edbInfoDataList) < 2 {
  1192. return
  1193. }
  1194. var startEdbInfoData *models.EdbDataList
  1195. for _, v := range edbInfoDataList {
  1196. handleDataMap[v.DataTime] = v.Value
  1197. dataTimeList = append(dataTimeList, v.DataTime)
  1198. // 第一个数据就给过滤了,给后面的试用
  1199. if startEdbInfoData == nil {
  1200. startEdbInfoData = v
  1201. //startEdbInfoData.DataTime = startEdbInfoData.DataTime[:5]+ "01-01"
  1202. continue
  1203. }
  1204. // 获取两条数据之间相差的天数
  1205. startDataTime, _ := time.ParseInLocation(utils.FormatDate, startEdbInfoData.DataTime, time.Local)
  1206. currDataTime, _ := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  1207. betweenHour := int(currDataTime.Sub(startDataTime).Hours())
  1208. betweenDay := betweenHour / 24
  1209. // 如果相差一天,那么过滤
  1210. if betweenDay <= 1 {
  1211. startEdbInfoData = v
  1212. continue
  1213. }
  1214. // 生成线性方程式
  1215. var a, b float64
  1216. {
  1217. coordinateData := make([]utils.Coordinate, 0)
  1218. tmpCoordinate1 := utils.Coordinate{
  1219. X: 1,
  1220. Y: startEdbInfoData.Value,
  1221. }
  1222. coordinateData = append(coordinateData, tmpCoordinate1)
  1223. tmpCoordinate2 := utils.Coordinate{
  1224. X: float64(betweenDay) + 1,
  1225. Y: v.Value,
  1226. }
  1227. coordinateData = append(coordinateData, tmpCoordinate2)
  1228. a, b = utils.GetLinearResult(coordinateData)
  1229. if math.IsNaN(a) || math.IsNaN(b) {
  1230. err = errors.New("线性方程公式生成失败")
  1231. return
  1232. }
  1233. }
  1234. // 生成对应的值
  1235. {
  1236. for i := 1; i < betweenDay; i++ {
  1237. tmpDataTime := startDataTime.AddDate(0, 0, i)
  1238. aDecimal := decimal.NewFromFloat(a)
  1239. xDecimal := decimal.NewFromInt(int64(i) + 1)
  1240. bDecimal := decimal.NewFromFloat(b)
  1241. val, _ := aDecimal.Mul(xDecimal).Add(bDecimal).Round(4).Float64()
  1242. handleDataMap[tmpDataTime.Format(utils.FormatDate)] = val
  1243. dataTimeList = append(dataTimeList, tmpDataTime.Format(utils.FormatDate))
  1244. valueList = append(valueList, val)
  1245. }
  1246. }
  1247. startEdbInfoData = v
  1248. }
  1249. return
  1250. }
  1251. // HandleDataByLinearRegressionToList 保证生成365个数据点的线性插值法
  1252. func HandleDataByLinearRegressionToListV2(edbInfoDataList []*models.EdbDataList, handleDataMap map[string]float64) (dataTimeList []string, valueList []float64, err error) {
  1253. if len(edbInfoDataList) < 2 {
  1254. return
  1255. }
  1256. // 确保至少有两天数据来生成线性方程
  1257. if len(edbInfoDataList) < 2 {
  1258. err = errors.New("至少需要两天的数据来执行线性插值")
  1259. return
  1260. }
  1261. // 对数据按日期排序,确保顺序正确
  1262. sort.Slice(edbInfoDataList, func(i, j int) bool {
  1263. t1, _ := time.ParseInLocation(utils.FormatDate, edbInfoDataList[i].DataTime, time.Local)
  1264. t2, _ := time.ParseInLocation(utils.FormatDate, edbInfoDataList[j].DataTime, time.Local)
  1265. return t1.Before(t2)
  1266. })
  1267. startEdbInfoData := edbInfoDataList[0]
  1268. endEdbInfoData := edbInfoDataList[len(edbInfoDataList)-1]
  1269. // 计算起始和结束日期间实际的天数
  1270. startDate, _ := time.ParseInLocation(utils.FormatDate, startEdbInfoData.DataTime, time.Local)
  1271. endDate, _ := time.ParseInLocation(utils.FormatDate, endEdbInfoData.DataTime, time.Local)
  1272. actualDays := endDate.Sub(startDate).Hours() / 24
  1273. // 生成365个数据点,首先处理已有数据
  1274. for _, v := range edbInfoDataList {
  1275. handleDataMap[v.DataTime] = v.Value
  1276. dataTimeList = append(dataTimeList, v.DataTime)
  1277. valueList = append(valueList, v.Value)
  1278. }
  1279. // 如果已有数据跨越天数不足365天,则对缺失的日期进行线性插值
  1280. if actualDays < 365 {
  1281. // 使用已有数据点生成线性方程(这里简化处理,实际可能需更细致处理边界情况)
  1282. var a, b float64
  1283. coordinateData := []utils.Coordinate{
  1284. {X: 1, Y: startEdbInfoData.Value},
  1285. {X: float64(len(edbInfoDataList)), Y: endEdbInfoData.Value},
  1286. }
  1287. a, b = utils.GetLinearResult(coordinateData)
  1288. if math.IsNaN(a) || math.IsNaN(b) {
  1289. err = errors.New("线性方程公式生成失败")
  1290. return
  1291. }
  1292. // 对剩余日期进行插值
  1293. for i := 1; i < 365; i++ {
  1294. day := startDate.AddDate(0, 0, i)
  1295. if _, exists := handleDataMap[day.Format(utils.FormatDate)]; !exists {
  1296. aDecimal := decimal.NewFromFloat(a)
  1297. xDecimal := decimal.NewFromInt(int64(i) + 1)
  1298. bDecimal := decimal.NewFromFloat(b)
  1299. val, _ := aDecimal.Mul(xDecimal).Add(bDecimal).Round(4).Float64()
  1300. handleDataMap[day.Format(utils.FormatDate)] = val
  1301. dataTimeList = append(dataTimeList, day.Format(utils.FormatDate))
  1302. valueList = append(valueList, val)
  1303. }
  1304. }
  1305. }
  1306. return
  1307. }
  1308. // HandleDataByLinearRegressionToListV3 插值法补充数据(线性方程式)-直接补充指标起始日期间的所有数据
  1309. func HandleDataByLinearRegressionToListV3 (edbInfoDataList []*models.EdbDataList, handleDataMap map[string]float64) (newEdbInfoDataList []*models.EdbDataList, dataTimeList []string,valueList []float64, err error) {
  1310. if len(edbInfoDataList) < 2 {
  1311. return
  1312. }
  1313. var startEdbInfoData *models.EdbDataList
  1314. for _, v := range edbInfoDataList {
  1315. handleDataMap[v.DataTime] = v.Value
  1316. newEdbInfoDataList = append(newEdbInfoDataList, v)
  1317. dataTimeList = append(dataTimeList, v.DataTime)
  1318. // 第一个数据就给过滤了,给后面的试用
  1319. if startEdbInfoData == nil {
  1320. startEdbInfoData = v
  1321. //startEdbInfoData.DataTime = startEdbInfoData.DataTime[:5]+ "01-01"
  1322. continue
  1323. }
  1324. // 获取两条数据之间相差的天数
  1325. startDataTime, _ := time.ParseInLocation(utils.FormatDate, startEdbInfoData.DataTime, time.Local)
  1326. currDataTime, _ := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  1327. betweenHour := int(currDataTime.Sub(startDataTime).Hours())
  1328. betweenDay := betweenHour / 24
  1329. // 如果相差一天,那么过滤
  1330. if betweenDay <= 1 {
  1331. startEdbInfoData = v
  1332. continue
  1333. }
  1334. // 生成线性方程式
  1335. var a, b float64
  1336. {
  1337. coordinateData := make([]utils.Coordinate, 0)
  1338. tmpCoordinate1 := utils.Coordinate{
  1339. X: 1,
  1340. Y: startEdbInfoData.Value,
  1341. }
  1342. coordinateData = append(coordinateData, tmpCoordinate1)
  1343. tmpCoordinate2 := utils.Coordinate{
  1344. X: float64(betweenDay) + 1,
  1345. Y: v.Value,
  1346. }
  1347. coordinateData = append(coordinateData, tmpCoordinate2)
  1348. a, b = utils.GetLinearResult(coordinateData)
  1349. if math.IsNaN(a) || math.IsNaN(b) {
  1350. err = errors.New("线性方程公式生成失败")
  1351. return
  1352. }
  1353. }
  1354. // 生成对应的值
  1355. {
  1356. for i := 1; i < betweenDay; i++ {
  1357. tmpDataTime := startDataTime.AddDate(0, 0, i)
  1358. aDecimal := decimal.NewFromFloat(a)
  1359. xDecimal := decimal.NewFromInt(int64(i) + 1)
  1360. bDecimal := decimal.NewFromFloat(b)
  1361. val, _ := aDecimal.Mul(xDecimal).Add(bDecimal).Round(4).Float64()
  1362. handleDataMap[tmpDataTime.Format(utils.FormatDate)] = val
  1363. dataTimeList = append(dataTimeList, tmpDataTime.Format(utils.FormatDate))
  1364. valueList = append(valueList, val)
  1365. newEdbInfoDataList = append(newEdbInfoDataList, &models.EdbDataList{
  1366. EdbDataId: v.EdbDataId,
  1367. EdbInfoId: v.EdbInfoId,
  1368. DataTime: tmpDataTime.Format(utils.FormatDate),
  1369. DataTimestamp: tmpDataTime.UnixNano() / 1e6,
  1370. Value: val,
  1371. })
  1372. }
  1373. }
  1374. startEdbInfoData = v
  1375. }
  1376. return
  1377. }