excel_info.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/shopspring/decimal"
  7. "github.com/yidane/formula"
  8. "hongze/hz_eta_api/models/data_manage"
  9. "hongze/hz_eta_api/models/data_manage/request"
  10. "hongze/hz_eta_api/models/data_manage/response"
  11. "hongze/hz_eta_api/models/system"
  12. "hongze/hz_eta_api/utils"
  13. "sort"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // GetExcelDetailInfoByExcelInfoId 根据表格id获取表格详情
  19. func GetExcelDetailInfoByExcelInfoId(excelInfoId int) (excelDetail response.ExcelInfoDetail, errMsg string, err error) {
  20. errMsg = `获取失败`
  21. //获取eta表格信息
  22. excelInfo, err := data_manage.GetExcelInfoById(excelInfoId)
  23. if err != nil {
  24. err = errors.New("获取ETA表格信息失败,Err:" + err.Error())
  25. if err.Error() == utils.ErrNoRow() {
  26. errMsg = "ETA表格被删除,请刷新页面"
  27. err = errors.New("ETA表格被删除,请刷新页面,Err:" + err.Error())
  28. }
  29. return
  30. }
  31. excelDetail = response.ExcelInfoDetail{
  32. ExcelInfoId: excelInfo.ExcelInfoId,
  33. Source: excelInfo.Source,
  34. ExcelType: excelInfo.ExcelType,
  35. ExcelName: excelInfo.ExcelName,
  36. UniqueCode: excelInfo.UniqueCode,
  37. ExcelClassifyId: excelInfo.ExcelClassifyId,
  38. SysUserId: excelInfo.SysUserId,
  39. SysUserRealName: excelInfo.SysUserRealName,
  40. Content: excelInfo.Content,
  41. ExcelImage: excelInfo.ExcelImage,
  42. FileUrl: excelInfo.FileUrl,
  43. Sort: excelInfo.Sort,
  44. IsDelete: excelInfo.IsDelete,
  45. ModifyTime: excelInfo.ModifyTime,
  46. CreateTime: excelInfo.CreateTime,
  47. TableData: nil,
  48. }
  49. switch excelInfo.Source {
  50. case 2: // 自定义表格
  51. var tableDataConfig TableDataConfig
  52. err = json.Unmarshal([]byte(excelDetail.Content), &tableDataConfig)
  53. if err != nil {
  54. err = errors.New("表格json转结构体失败,Err:" + err.Error())
  55. return
  56. }
  57. result, tmpErr := GetDataByTableDataConfig(tableDataConfig)
  58. if tmpErr != nil {
  59. err = errors.New("获取最新的表格数据失败,Err:" + tmpErr.Error())
  60. return
  61. }
  62. excelDetail.TableData = result
  63. case 3: // 混合表格
  64. var result request.MixedTableReq
  65. err = json.Unmarshal([]byte(excelDetail.Content), &result)
  66. if err != nil {
  67. err = errors.New("表格json转结构体失败,Err:" + err.Error())
  68. return
  69. }
  70. newData, tmpErr := GetMixedTableCellData(result.Data)
  71. if tmpErr != nil {
  72. err = errors.New("获取最新的数据失败,Err:" + tmpErr.Error())
  73. return
  74. }
  75. result.Data = newData
  76. excelDetail.TableData = result
  77. }
  78. return
  79. }
  80. // GetExcelInfoOpButton 获取ETA表格的操作权限
  81. func GetExcelInfoOpButton(sysUser *system.Admin, belongUserId, source int) (button response.ExcelInfoDetailButton) {
  82. //非管理员角色查看其他用户创建的表格,可刷新、另存为、下载表格;
  83. button.RefreshButton = true
  84. button.CopyButton = true
  85. button.DownloadButton = true
  86. if source == 1 {
  87. button.OpButton = true
  88. }
  89. // 1、本用户创建的表格,可编辑、刷新、另存为、下载、删除,删除需二次确认;
  90. // 2、管理员角色对所有表格有如上权限;
  91. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId {
  92. button.OpButton = true
  93. button.DeleteButton = true
  94. }
  95. return
  96. }
  97. // GetFirstEdbDataList 获取第一列的数据
  98. func GetFirstEdbDataList(edbInfo *data_manage.EdbInfo, num int, manualDateList []string) (resultDataList []request.ManualDataReq, err error) {
  99. var dataList []*data_manage.EdbDataList
  100. switch edbInfo.EdbInfoType {
  101. case 0:
  102. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.EdbInfoId, ``, ``)
  103. case 1:
  104. _, dataList, _, _, err, _ = GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  105. default:
  106. err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
  107. }
  108. if err != nil {
  109. return
  110. }
  111. // 获取需要的期数
  112. lenData := len(dataList)
  113. if lenData <= 0 {
  114. return
  115. }
  116. tmpManualDateNum := 0 // 手工数据的期数
  117. lenManualDate := len(manualDateList)
  118. if lenManualDate > 0 {
  119. sortDateList := manualDateList
  120. baseDateList := utils.StrArr{}
  121. baseDateList = append(baseDateList, sortDateList...)
  122. sort.Sort(baseDateList)
  123. sortDateList = append([]string{}, baseDateList...)
  124. lastData := dataList[lenData-1]
  125. lastDataDate, tmpErr := time.ParseInLocation(utils.FormatDate, lastData.DataTime, time.Local)
  126. if tmpErr != nil {
  127. err = tmpErr
  128. return
  129. }
  130. // 遍历倒序后的日期,然后匹配在实际数据之后日期的个数
  131. for _, tmpDateStr := range sortDateList {
  132. tmpDate, tmpErr := time.ParseInLocation(utils.FormatDate, tmpDateStr, time.Local)
  133. if tmpErr != nil {
  134. err = tmpErr
  135. return
  136. }
  137. if tmpDate.After(lastDataDate) {
  138. tmpManualDateNum++
  139. continue
  140. }
  141. break
  142. }
  143. }
  144. // 需要的期数减去手工数据的期数,这才是A列指标需要的数据
  145. num = num - tmpManualDateNum
  146. if num > lenData {
  147. num = lenData
  148. }
  149. for i := 1; i <= num; i++ {
  150. resultDataList = append(resultDataList, request.ManualDataReq{
  151. DataType: 1,
  152. DataTime: dataList[lenData-i].DataTime,
  153. ShowValue: fmt.Sprint(dataList[lenData-i].Value),
  154. Value: fmt.Sprint(dataList[lenData-i].Value),
  155. DataTimeType: 1,
  156. })
  157. }
  158. return
  159. }
  160. // GetOtherEdbDataList 获取其他列的数据
  161. func GetOtherEdbDataList(edbInfo *data_manage.EdbInfo, dateList []string) (resultDataList []request.ManualDataReq, err error) {
  162. lenDate := len(dateList)
  163. if lenDate <= 0 {
  164. return
  165. }
  166. sortDateList := dateList
  167. baseDateList := utils.StrArr{}
  168. baseDateList = append(baseDateList, sortDateList...)
  169. sort.Sort(baseDateList)
  170. sortDateList = append([]string{}, baseDateList...)
  171. endDateTime, err := time.ParseInLocation(utils.FormatDate, sortDateList[0], time.Local)
  172. if err != nil {
  173. return
  174. }
  175. firstDateTime, err := time.ParseInLocation(utils.FormatDate, sortDateList[lenDate-1], time.Local)
  176. if err != nil {
  177. return
  178. }
  179. var dataList []*data_manage.EdbDataList
  180. switch edbInfo.EdbInfoType {
  181. case 0:
  182. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.EdbInfoId, ``, ``)
  183. case 1:
  184. _, dataList, _, _, err, _ = GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  185. default:
  186. err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
  187. }
  188. if err != nil {
  189. return
  190. }
  191. // 获取日期内的数据(包含开始日期前一个日期,以及 结束日期后一个日期,目的为了做空日期时的 插值法兼容)
  192. baseDataList := make([]*data_manage.EdbDataList, 0)
  193. var lastData *data_manage.EdbDataList
  194. var isInsert bool
  195. for _, data := range dataList {
  196. tmpDate := data.DataTime
  197. tmpDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, tmpDate, time.Local)
  198. if tmpErr != nil {
  199. err = tmpErr
  200. return
  201. }
  202. if tmpDateTime.Before(firstDateTime) {
  203. lastData = data
  204. continue
  205. }
  206. // 如果是第一次写入数据
  207. if !isInsert && lastData != nil {
  208. baseDataList = append(baseDataList, lastData)
  209. }
  210. if tmpDateTime.After(endDateTime) {
  211. baseDataList = append(baseDataList, data)
  212. break
  213. }
  214. baseDataList = append(baseDataList, data)
  215. isInsert = true
  216. }
  217. // 实际数据的日期map
  218. realValMap := make(map[string]string)
  219. for _, v := range baseDataList {
  220. realValMap[v.DataTime] = v.DataTime
  221. }
  222. // 插值法处理
  223. handleDataMap := make(map[string]float64)
  224. err = handleDataByLinearRegression(baseDataList, handleDataMap)
  225. if err != nil {
  226. return
  227. }
  228. // 对于不存在的数据做补充
  229. for _, date := range sortDateList {
  230. dataType := 1
  231. if _, ok := realValMap[date]; !ok {
  232. dataType = 2
  233. }
  234. var value, showValue string
  235. if tmpVal, ok := handleDataMap[date]; ok {
  236. value = fmt.Sprint(tmpVal)
  237. showValue = value
  238. } else {
  239. dataType = 3
  240. }
  241. resultDataList = append(resultDataList, request.ManualDataReq{
  242. DataType: dataType,
  243. DataTime: date,
  244. ShowValue: showValue,
  245. Value: value,
  246. })
  247. }
  248. return
  249. }
  250. // GetFirstHistoryEdbDataList 获取指标的历史的数据
  251. func GetFirstHistoryEdbDataList(edbInfo *data_manage.EdbInfo, num int, endDate string) (resultDataList []request.ManualDataReq, err error) {
  252. endDateTime, err := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  253. if err != nil {
  254. return
  255. }
  256. var dataList []*data_manage.EdbDataList
  257. switch edbInfo.EdbInfoType {
  258. case 0:
  259. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.EdbInfoId, ``, endDate)
  260. case 1:
  261. _, dataList, _, _, err, _ = GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, endDate, true)
  262. default:
  263. err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
  264. }
  265. if err != nil {
  266. return
  267. }
  268. // 获取需要的期数
  269. lenData := len(dataList)
  270. if lenData <= 0 {
  271. return
  272. }
  273. lastData := dataList[lenData-1]
  274. lastDataDateTime, err := time.ParseInLocation(utils.FormatDate, lastData.DataTime, time.Local)
  275. if err != nil {
  276. return
  277. }
  278. if endDateTime.Equal(lastDataDateTime) || lastDataDateTime.After(endDateTime) {
  279. dataList = dataList[:lenData-1]
  280. lenData = len(dataList)
  281. }
  282. if num > lenData {
  283. num = lenData
  284. }
  285. for i := 1; i <= num; i++ {
  286. resultDataList = append(resultDataList, request.ManualDataReq{
  287. DataType: 1,
  288. DataTime: dataList[lenData-i].DataTime,
  289. ShowValue: fmt.Sprint(dataList[lenData-i].Value),
  290. Value: fmt.Sprint(dataList[lenData-i].Value),
  291. })
  292. }
  293. return
  294. }
  295. type TableDataConfig struct {
  296. EdbInfoIdList []int `description:"指标id列表,从左至右,从上到下的顺序"`
  297. Sort int `description:"日期排序,0:倒序,1:正序"`
  298. Data []ManualData `description:"数据列表"`
  299. Num int `description:"实际数据需要列出来的期数"`
  300. RemoveDate []string `description:"不展示的日期"`
  301. ManualDate []string `description:"手动配置的日期(未来的日期)"`
  302. TableEdbInfoList []TableEdbInfo `description:"表格内指标信息"`
  303. TextRowData [][]request.ManualDataReq `description:"文本列表"`
  304. }
  305. type TableEdbInfo struct {
  306. EdbInfoId int `description:"指标ID"`
  307. Tag string `description:"标签"`
  308. EdbName string `description:"指标名称"`
  309. EdbAliasName string `description:"指标别名"`
  310. Frequency string `description:"频度"`
  311. Unit string `description:"单位"`
  312. }
  313. type ManualData struct {
  314. DataType int `description:"数据类型,1:普通的,2:插值法,3:手动输入,4:公式计算"`
  315. DataTime string `description:"所属日期"`
  316. DataTimeType int `description:"日期类型,1:实际日期;2:未来日期"`
  317. ShowValue string `description:"展示值"`
  318. Value string `description:"实际值(计算公式)"`
  319. EdbInfoId int `description:"指标id"`
  320. Tag string `description:"下标"`
  321. RelationEdbInfoList []request.RelationEdbInfo `description:"关联指标(计算公式中关联的指标,用于计算的时候去匹配)"`
  322. }
  323. // GetTableDataConfig 根据TableDataReq配置获取相关数据配置
  324. func GetTableDataConfig(reqData request.TableDataReq) (tableDataConfig TableDataConfig, err error) {
  325. // 指标数据
  326. tableDataConfig.EdbInfoIdList = reqData.EdbInfoIdList
  327. tableDataConfig.Sort = reqData.Sort
  328. if len(reqData.Data) <= 0 {
  329. err = errors.New("数据不能为空")
  330. return
  331. }
  332. // 开始日期
  333. var startDate string
  334. // A列的指标id
  335. var firstEdbInfoId int
  336. // 手工操作的数据列
  337. manualDataList := make([]ManualData, 0)
  338. // 指标配置列表
  339. tableEdbInfoList := make([]TableEdbInfo, 0)
  340. // 第一列的日期map
  341. firstDateMap := make(map[string]string)
  342. manualDateMap := make(map[string]string)
  343. for _, v := range reqData.Data {
  344. // 指标信息
  345. tmpTableEdbInfo := TableEdbInfo{
  346. EdbInfoId: v.EdbInfoId,
  347. Tag: v.Tag,
  348. EdbName: v.EdbName,
  349. EdbAliasName: v.EdbAliasName,
  350. Frequency: v.Frequency,
  351. Unit: v.Unit,
  352. }
  353. tableEdbInfoList = append(tableEdbInfoList, tmpTableEdbInfo)
  354. // 确定数据A列
  355. if v.Tag == "A" {
  356. firstEdbInfoId = v.EdbInfoId
  357. lenData := len(v.Data)
  358. if lenData <= 0 {
  359. err = errors.New("A列不能为空")
  360. return
  361. }
  362. index := 0
  363. if reqData.Sort == 1 {
  364. // 倒序
  365. index = lenData - 1
  366. }
  367. startDate = v.Data[index].DataTime
  368. // 存在的日期列表
  369. for _, data := range v.Data {
  370. firstDateMap[data.DataTime] = data.DataTime
  371. if data.DataTimeType == 2 {
  372. manualDateMap[data.DataTime] = data.DataTime
  373. }
  374. }
  375. }
  376. for _, data := range v.Data {
  377. if data.DataType == 3 || data.DataType == 4 {
  378. tmpManualData := ManualData{
  379. DataType: data.DataType,
  380. DataTime: data.DataTime,
  381. DataTimeType: data.DataTimeType,
  382. ShowValue: data.ShowValue,
  383. Value: data.Value,
  384. EdbInfoId: v.EdbInfoId,
  385. Tag: v.Tag,
  386. RelationEdbInfoList: data.RelationEdbInfoList,
  387. }
  388. if data.DataType == 4 {
  389. tmpManualData.ShowValue = ``
  390. }
  391. manualDataList = append(manualDataList, tmpManualData)
  392. }
  393. }
  394. }
  395. // 总共需要的期数
  396. num := len(reqData.Data[0].Data)
  397. removeDate := make([]string, 0)
  398. // 获取期数
  399. {
  400. firstDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  401. if tmpErr != nil {
  402. err = tmpErr
  403. return
  404. }
  405. edbInfo, tmpErr := data_manage.GetEdbInfoById(firstEdbInfoId)
  406. if tmpErr != nil {
  407. err = tmpErr
  408. return
  409. }
  410. var firstDataList []*data_manage.EdbDataList
  411. switch edbInfo.EdbInfoType {
  412. case 0:
  413. firstDataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.EdbInfoId, ``, ``)
  414. case 1:
  415. _, firstDataList, _, _, err, _ = GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  416. default:
  417. err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
  418. }
  419. if err != nil {
  420. return
  421. }
  422. // 获取日期内的数据(包含开始日期前一个日期,以及 结束日期后一个日期,目的为了做空日期时的 插值法兼容)
  423. baseDataList := make([]*data_manage.EdbDataList, 0)
  424. for _, data := range firstDataList {
  425. tmpDate := data.DataTime
  426. tmpDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, tmpDate, time.Local)
  427. if tmpErr != nil {
  428. err = tmpErr
  429. return
  430. }
  431. if tmpDateTime.Before(firstDateTime) {
  432. continue
  433. }
  434. baseDataList = append(baseDataList, data)
  435. }
  436. // 筛选出需要删除的日期
  437. for _, tmpData := range baseDataList {
  438. //firstDateMap{}
  439. if _, ok := firstDateMap[tmpData.DataTime]; !ok {
  440. removeDate = append(removeDate, tmpData.DataTime)
  441. }
  442. }
  443. }
  444. tableDataConfig.Num = num
  445. tableDataConfig.RemoveDate = removeDate
  446. tableDataConfig.Data = manualDataList
  447. tableDataConfig.TableEdbInfoList = tableEdbInfoList
  448. tableDataConfig.TextRowData = reqData.TextRowData
  449. return
  450. }
  451. // GetDataByTableDataConfig 根据数据配置获取表格数据
  452. func GetDataByTableDataConfig(tableDataConfig TableDataConfig) (resultResp request.TableDataReq, err error) {
  453. // 没有选择指标的情况下,直接返回吧
  454. if len(tableDataConfig.EdbInfoIdList) <= 0 {
  455. return
  456. }
  457. // 实际期数没有的情况下,直接返回吧
  458. if tableDataConfig.Num <= 0 {
  459. return
  460. }
  461. // 获取所有的指标信息
  462. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  463. edbInfoIdList := make([]int, 0)
  464. // 标签与指标id的map
  465. tagEdbInfoIdMap := make(map[string]int)
  466. {
  467. for _, tableEdbInfo := range tableDataConfig.TableEdbInfoList {
  468. edbInfoIdList = append(edbInfoIdList, tableEdbInfo.EdbInfoId)
  469. tagEdbInfoIdMap[tableEdbInfo.Tag] = tableEdbInfo.EdbInfoId
  470. }
  471. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  472. if tmpErr != nil {
  473. err = tmpErr
  474. return
  475. }
  476. for _, v := range edbInfoList {
  477. edbInfoMap[v.EdbInfoId] = v
  478. }
  479. }
  480. manualDateMap := make(map[string]string, 0)
  481. manualDateList := make([]string, 0)
  482. for _, v := range tableDataConfig.Data {
  483. if _, ok := manualDateMap[v.DataTime]; !ok {
  484. manualDateMap[v.DataTime] = v.DataTime
  485. manualDateList = append(manualDateList, v.DataTime)
  486. }
  487. }
  488. // 寻找A列的数据列表
  489. firstEdbInfo, ok := edbInfoMap[tableDataConfig.TableEdbInfoList[0].EdbInfoId]
  490. if !ok {
  491. err = errors.New("找不到A列指标")
  492. return
  493. }
  494. baseFirstEdbInfoDataList, err := GetFirstEdbDataList(firstEdbInfo, tableDataConfig.Num, manualDateList)
  495. if err != nil {
  496. return
  497. }
  498. // A列找不到数据,那么就直接返回吧
  499. if len(baseFirstEdbInfoDataList) <= 0 {
  500. return
  501. }
  502. firstEdbInfoDataList := make([]request.ManualDataReq, 0)
  503. if tableDataConfig.RemoveDate != nil && len(tableDataConfig.RemoveDate) > 0 {
  504. for _, v := range baseFirstEdbInfoDataList {
  505. if utils.InArrayByStr(tableDataConfig.RemoveDate, v.DataTime) {
  506. continue
  507. }
  508. firstEdbInfoDataList = append(firstEdbInfoDataList, v)
  509. }
  510. } else {
  511. firstEdbInfoDataList = baseFirstEdbInfoDataList
  512. }
  513. if len(firstEdbInfoDataList) <= 0 {
  514. return
  515. }
  516. // 实际数据的最后一天
  517. lastRealDateTime, err := time.ParseInLocation(utils.FormatDate, firstEdbInfoDataList[0].DataTime, time.Local)
  518. if err != nil {
  519. return
  520. }
  521. dateMap := make(map[string]string)
  522. dateList := make([]string, 0)
  523. edbInfoIdDateDataMap := make(map[int]map[string]request.ManualDataReq)
  524. firstDateDataMap := make(map[string]request.ManualDataReq)
  525. for _, v := range firstEdbInfoDataList {
  526. dateList = append(dateList, v.DataTime)
  527. dateMap[v.DataTime] = v.DataTime
  528. firstDateDataMap[v.DataTime] = v
  529. }
  530. // 将手工数据的日期填补进去(未来的日期,过去的就不管了)
  531. for _, manualData := range tableDataConfig.Data {
  532. if !utils.InArrayByStr(dateList, manualData.DataTime) {
  533. tmpDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, manualData.DataTime, time.Local)
  534. if tmpErr != nil {
  535. err = tmpErr
  536. return
  537. }
  538. if tmpDateTime.After(lastRealDateTime) {
  539. dateList = append(dateList, manualData.DataTime)
  540. }
  541. }
  542. }
  543. edbInfoIdDateDataMap[firstEdbInfo.EdbInfoId] = firstDateDataMap
  544. for k, edbInfoId := range tableDataConfig.EdbInfoIdList {
  545. if k == 0 {
  546. continue
  547. }
  548. tmpEdbInfo, ok := edbInfoMap[edbInfoId]
  549. if !ok {
  550. err = errors.New("找不到A列指标")
  551. return
  552. }
  553. otherDataList, tmpErr := GetOtherEdbDataList(tmpEdbInfo, dateList)
  554. if tmpErr != nil {
  555. err = tmpErr
  556. return
  557. }
  558. tmpDateDataMap := make(map[string]request.ManualDataReq)
  559. for _, v := range otherDataList {
  560. tmpDateDataMap[v.DataTime] = v
  561. }
  562. edbInfoIdDateDataMap[tmpEdbInfo.EdbInfoId] = tmpDateDataMap
  563. }
  564. for _, v := range tableDataConfig.Data {
  565. tmpDate := v.DataTime
  566. if _, ok := dateMap[tmpDate]; !ok {
  567. dateMap[v.DataTime] = tmpDate
  568. }
  569. edbInfoIdDateData, ok := edbInfoIdDateDataMap[v.EdbInfoId]
  570. if !ok {
  571. edbInfoIdDateData = make(map[string]request.ManualDataReq)
  572. }
  573. // 判断是否存在该日期的数据(不存在,那么插入数据吧,存在就不管了)
  574. tmpManualData, ok := edbInfoIdDateData[tmpDate]
  575. if !ok {
  576. edbInfoIdDateData[tmpDate] = request.ManualDataReq{
  577. DataType: v.DataType,
  578. DataTime: v.DataTime,
  579. ShowValue: v.ShowValue,
  580. Value: v.Value,
  581. }
  582. } else {
  583. if (tmpManualData.DataType == 3 || tmpManualData.DataType == 4) && tmpManualData.ShowValue == `` {
  584. tmpManualData.DataType = v.DataType
  585. tmpManualData.ShowValue = v.ShowValue
  586. tmpManualData.Value = v.Value
  587. tmpManualData.RelationEdbInfoList = v.RelationEdbInfoList
  588. edbInfoIdDateData[tmpDate] = tmpManualData
  589. }
  590. }
  591. edbInfoIdDateDataMap[v.EdbInfoId] = edbInfoIdDateData
  592. }
  593. // 获取数据的日期排序
  594. sortDateTimeList := make([]time.Time, 0)
  595. {
  596. sortDateList := dateList
  597. if tableDataConfig.Sort == 1 {
  598. baseDateList := utils.StrArr{}
  599. baseDateList = append(baseDateList, sortDateList...)
  600. sort.Sort(baseDateList)
  601. sortDateList = append([]string{}, baseDateList...)
  602. } else {
  603. sort.Strings(sortDateList)
  604. }
  605. for _, v := range sortDateList {
  606. tmpDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, v, time.Local)
  607. if tmpErr != nil {
  608. err = tmpErr
  609. return
  610. }
  611. sortDateTimeList = append(sortDateTimeList, tmpDateTime)
  612. }
  613. }
  614. // 数据处理,处理成表格的数据格式
  615. tableDataMap, textRowListDataResp := handleTable(tagEdbInfoIdMap, lastRealDateTime, sortDateTimeList, edbInfoIdDateDataMap, tableDataConfig.Data, tableDataConfig.TextRowData)
  616. data := make([]request.EdbInfoData, 0)
  617. for _, tableEdbInfo := range tableDataConfig.TableEdbInfoList {
  618. tagEdbInfoIdMap[tableEdbInfo.Tag] = tableEdbInfo.EdbInfoId
  619. manualDataReqList := make([]request.ManualDataReq, 0)
  620. tmpEdbInfoData := request.EdbInfoData{
  621. EdbInfoId: tableEdbInfo.EdbInfoId,
  622. Tag: tableEdbInfo.Tag,
  623. EdbName: tableEdbInfo.EdbName,
  624. EdbAliasName: tableEdbInfo.EdbAliasName,
  625. Frequency: tableEdbInfo.Frequency,
  626. Unit: tableEdbInfo.Unit,
  627. Data: manualDataReqList,
  628. }
  629. edbInfo, ok := edbInfoMap[tableEdbInfo.EdbInfoId]
  630. if ok {
  631. tmpEdbInfoData.EdbName = edbInfo.EdbName
  632. tmpEdbInfoData.Frequency = edbInfo.Frequency
  633. tmpEdbInfoData.Unit = edbInfo.Unit
  634. }
  635. for index, dateTime := range sortDateTimeList {
  636. dataTimeType := 1
  637. if dateTime.After(lastRealDateTime) {
  638. dataTimeType = 2
  639. }
  640. tmpDateTimeStr := dateTime.Format(utils.FormatDate)
  641. rowData, ok := tableDataMap[index+1]
  642. if !ok {
  643. manualDataReqList = append(manualDataReqList, request.ManualDataReq{
  644. DataType: 3,
  645. DataTime: tmpDateTimeStr,
  646. DataTimeType: dataTimeType,
  647. ShowValue: "",
  648. Value: "",
  649. RelationEdbInfoList: nil,
  650. })
  651. continue
  652. }
  653. tmpData, ok := rowData[tableEdbInfo.Tag]
  654. if !ok {
  655. manualDataReqList = append(manualDataReqList, request.ManualDataReq{
  656. DataType: 3,
  657. DataTime: tmpDateTimeStr,
  658. DataTimeType: dataTimeType,
  659. ShowValue: "",
  660. Value: "",
  661. RelationEdbInfoList: nil,
  662. })
  663. continue
  664. }
  665. tmpData.DataTimeType = dataTimeType
  666. manualDataReqList = append(manualDataReqList, tmpData)
  667. }
  668. tmpEdbInfoData.Data = manualDataReqList
  669. data = append(data, tmpEdbInfoData)
  670. }
  671. resultResp = request.TableDataReq{
  672. EdbInfoIdList: edbInfoIdList,
  673. Sort: tableDataConfig.Sort,
  674. TextRowData: textRowListDataResp,
  675. Data: data,
  676. }
  677. return
  678. }
  679. // handleTable 表格数据处理
  680. func handleTable(tagEdbInfoIdMap map[string]int, lastRealDateTime time.Time, sortDateTimeList []time.Time, edbInfoIdDateDataMap map[int]map[string]request.ManualDataReq, manualDataList []ManualData, textRowData [][]request.ManualDataReq) (tableDataMap map[int]map[string]request.ManualDataReq, textRowListDataResp [][]request.ManualDataReq) {
  681. tagList := make([]string, 0)
  682. for tag, _ := range tagEdbInfoIdMap {
  683. tagList = append(tagList, tag)
  684. }
  685. sort.Strings(tagList)
  686. tableDataMap = make(map[int]map[string]request.ManualDataReq) //行、列数据
  687. // 日期与行的关系
  688. dateIndexMap := make(map[string]int)
  689. for k, dateTime := range sortDateTimeList {
  690. rowDataMap := make(map[string]request.ManualDataReq)
  691. dataTimeType := 1
  692. if dateTime.After(lastRealDateTime) {
  693. dataTimeType = 2
  694. }
  695. tmpDateTimeStr := dateTime.Format(utils.FormatDate)
  696. dateIndexMap[tmpDateTimeStr] = k + 1
  697. for _, tag := range tagList {
  698. edbInfoId, ok := tagEdbInfoIdMap[tag]
  699. if !ok { // 没有找到该指标的映射关系,那么就用空串填补
  700. rowDataMap[tag] = request.ManualDataReq{
  701. DataType: 3,
  702. DataTime: tmpDateTimeStr,
  703. DataTimeType: dataTimeType,
  704. ShowValue: "",
  705. Value: "",
  706. RelationEdbInfoList: nil,
  707. }
  708. continue
  709. }
  710. // 获取指标的数据map
  711. dateDataMap, ok := edbInfoIdDateDataMap[edbInfoId]
  712. if !ok { // 没有找到该指标的数据,那么就用空串填补
  713. rowDataMap[tag] = request.ManualDataReq{
  714. DataType: 3,
  715. DataTime: tmpDateTimeStr,
  716. DataTimeType: dataTimeType,
  717. ShowValue: "",
  718. Value: "",
  719. RelationEdbInfoList: nil,
  720. }
  721. continue
  722. }
  723. // 获取指标该日期的数据
  724. tmpData, ok := dateDataMap[tmpDateTimeStr]
  725. if !ok { // 该指标没有找到对应日期的数据,那么就用空串填补
  726. rowDataMap[tag] = request.ManualDataReq{
  727. DataType: 3,
  728. DataTime: tmpDateTimeStr,
  729. DataTimeType: dataTimeType,
  730. ShowValue: "",
  731. Value: "",
  732. RelationEdbInfoList: nil,
  733. }
  734. continue
  735. }
  736. tmpData.DataTimeType = dataTimeType
  737. rowDataMap[tag] = tmpData
  738. }
  739. tableDataMap[k+1] = rowDataMap
  740. }
  741. // 替换手工设置的数据
  742. for _, manualData := range manualDataList {
  743. // 找不到该日期,说明这日期过期了,不处理
  744. index, ok := dateIndexMap[manualData.DataTime]
  745. if !ok {
  746. continue
  747. }
  748. // 获取对应行的数据
  749. rowDataMap, ok := tableDataMap[index]
  750. if !ok {
  751. continue
  752. }
  753. // 找到对应的单元格
  754. tmpData, ok := rowDataMap[manualData.Tag]
  755. if !ok {
  756. continue
  757. }
  758. // 如果该单元格实际有数据,或者插值法补充了数据的话,那么就不用手动填入的数据
  759. if tmpData.DataType == 1 || tmpData.DataType == 2 {
  760. continue
  761. }
  762. // 手工填写的数字
  763. if tmpData.DataType == 3 {
  764. tmpData.ShowValue = manualData.ShowValue
  765. tmpData.Value = manualData.Value
  766. tableDataMap[index][manualData.Tag] = tmpData
  767. //edbInfoIdDateDataMap[manualData.EdbInfoId][manualData.DataTime] = tmpData
  768. continue
  769. }
  770. // 公式
  771. tmpData.DataType = manualData.DataType
  772. tmpData.ShowValue = ``
  773. tmpData.Value = manualData.Value
  774. tmpData.RelationEdbInfoList = manualData.RelationEdbInfoList
  775. tableDataMap[index][manualData.Tag] = tmpData
  776. }
  777. // 文本行的列表插入
  778. lenTableData := len(tableDataMap)
  779. // 文本行第一列的数据列表(可能多行)
  780. firstColTextRowList := make([]request.ManualDataReq, 0)
  781. // 参与计算的文本行列表数据
  782. tmpTextRowList := make([][]request.ManualDataReq, 0)
  783. for k, textRowList := range textRowData {
  784. // 判断列数是否匹配,不匹配的话那么过滤
  785. if len(tagList)+1 != len(textRowList) {
  786. continue
  787. }
  788. rowDataMap := make(map[string]request.ManualDataReq)
  789. tmpTextRow := make([]request.ManualDataReq, 0)
  790. for index, textRow := range textRowList {
  791. // 移除第一列,因为第一列是日期列
  792. if index == 0 {
  793. firstColTextRowList = append(firstColTextRowList, textRow)
  794. continue
  795. }
  796. rowDataMap[tagList[index-1]] = textRow
  797. tmpTextRow = append(tmpTextRow, textRow)
  798. }
  799. tableDataMap[lenTableData+k+1] = rowDataMap
  800. tmpTextRowList = append(tmpTextRowList, tmpTextRow)
  801. }
  802. // 参与计算的单元格
  803. calculateCellMap := make(map[string]string)
  804. // 计算手工填写的单元格
  805. for _, manualData := range manualDataList {
  806. // 找不到该日期,说明这日期过期了,不处理
  807. index, ok := dateIndexMap[manualData.DataTime]
  808. if !ok {
  809. continue
  810. }
  811. // 获取对应行的数据
  812. rowDataMap, ok := tableDataMap[index]
  813. if !ok {
  814. continue
  815. }
  816. // 找到对应的单元格
  817. colData, ok := rowDataMap[manualData.Tag]
  818. if !ok {
  819. continue
  820. }
  821. // 如果该单元格不是计算公式的单元格,那么直接退出当前循环即可
  822. if colData.DataType != 4 {
  823. continue
  824. }
  825. tagMap := make(map[string]float64)
  826. lenRelation := len(colData.RelationEdbInfoList)
  827. replaceNum := 0
  828. for _, relation := range colData.RelationEdbInfoList {
  829. relationCellTagName := strings.ToUpper(relation.Tag) + relation.Row
  830. valStr, tmpErr := getCalculateValue(tableDataMap, relation.Tag, relation.Row, calculateCellMap)
  831. if tmpErr != nil {
  832. continue
  833. }
  834. tmpValDecimal, tmpErr := decimal.NewFromString(valStr)
  835. if tmpErr != nil {
  836. continue
  837. }
  838. tagMap[relationCellTagName], _ = tmpValDecimal.Float64()
  839. replaceNum++
  840. }
  841. // 如果替换的数据与关联的不一致,那么就退出当前循环
  842. if lenRelation != replaceNum {
  843. continue
  844. }
  845. // 计算
  846. val, _, err := calculate(strings.ToUpper(colData.Value), tagMap)
  847. // 计算失败,退出循环
  848. if err != nil {
  849. continue
  850. }
  851. // 重新赋值
  852. colData.ShowValue = val
  853. tableDataMap[index][manualData.Tag] = colData
  854. }
  855. // 计算文本行的单元格
  856. for k, textRow := range tmpTextRowList {
  857. // 获取对应行的数据
  858. index := lenTableData + k + 1
  859. rowDataMap, ok := tableDataMap[index]
  860. if !ok {
  861. continue
  862. }
  863. for colIndex, _ := range textRow {
  864. currTag := tagList[colIndex]
  865. // 找到对应的单元格
  866. colData, ok := rowDataMap[currTag]
  867. if !ok {
  868. continue
  869. }
  870. // 如果该单元格不是计算公式的单元格,那么直接退出当前循环即可
  871. if colData.DataType != 4 {
  872. continue
  873. }
  874. tagMap := make(map[string]float64)
  875. lenRelation := len(colData.RelationEdbInfoList)
  876. replaceNum := 0
  877. for _, relation := range colData.RelationEdbInfoList {
  878. relationCellTagName := strings.ToUpper(relation.Tag) + relation.Row
  879. valStr, tmpErr := getCalculateValue(tableDataMap, relation.Tag, relation.Row, calculateCellMap)
  880. if tmpErr != nil {
  881. continue
  882. }
  883. tmpValDecimal, tmpErr := decimal.NewFromString(valStr)
  884. if tmpErr != nil {
  885. continue
  886. }
  887. tagMap[relationCellTagName], _ = tmpValDecimal.Float64()
  888. replaceNum++
  889. }
  890. // 如果替换的数据与关联的不一致,那么就退出当前循环
  891. if lenRelation != replaceNum {
  892. continue
  893. }
  894. // 计算
  895. val, _, err := calculate(strings.ToUpper(colData.Value), tagMap)
  896. // 计算失败,退出循环
  897. if err != nil {
  898. continue
  899. }
  900. // 重新赋值
  901. colData.ShowValue = val
  902. tableDataMap[index][currTag] = colData
  903. }
  904. }
  905. // 计算文本行第一列的数据值(多行)
  906. for k, colData := range firstColTextRowList {
  907. // 如果该单元格不是计算公式的单元格,那么直接退出当前循环即可
  908. if colData.DataType != 4 {
  909. continue
  910. }
  911. tagMap := make(map[string]float64)
  912. lenRelation := len(colData.RelationEdbInfoList)
  913. replaceNum := 0
  914. for _, relation := range colData.RelationEdbInfoList {
  915. relationCellTagName := strings.ToUpper(relation.Tag) + relation.Row
  916. valStr, tmpErr := getCalculateValue(tableDataMap, relation.Tag, relation.Row, calculateCellMap)
  917. if tmpErr != nil {
  918. continue
  919. }
  920. tmpValDecimal, tmpErr := decimal.NewFromString(valStr)
  921. if tmpErr != nil {
  922. continue
  923. }
  924. tagMap[relationCellTagName], _ = tmpValDecimal.Float64()
  925. replaceNum++
  926. }
  927. // 如果替换的数据与关联的不一致,那么就退出当前循环
  928. if lenRelation != replaceNum {
  929. continue
  930. }
  931. // 计算
  932. val, _, err := calculate(strings.ToUpper(colData.Value), tagMap)
  933. // 计算失败,退出循环
  934. if err != nil {
  935. continue
  936. }
  937. // 重新赋值
  938. colData.ShowValue = val
  939. firstColTextRowList[k] = colData
  940. }
  941. {
  942. // 文本行的数据处理返回
  943. textRowListDataResp = make([][]request.ManualDataReq, 0)
  944. newLenTableDataMap := len(tableDataMap)
  945. // 文本行的第一行所在的位置
  946. firstTextRow := lenTableData + 1
  947. for i := firstTextRow; i <= newLenTableDataMap; i++ {
  948. textRowDataResp := make([]request.ManualDataReq, 0)
  949. textRowDataResp = append(textRowDataResp, firstColTextRowList[i-firstTextRow])
  950. for _, tmpTag := range tagList {
  951. textRowDataResp = append(textRowDataResp, tableDataMap[i][tmpTag])
  952. }
  953. textRowListDataResp = append(textRowListDataResp, textRowDataResp)
  954. }
  955. }
  956. return
  957. }
  958. // getCalculateValue 获取公式计算的结果
  959. func getCalculateValue(tableDataMap map[int]map[string]request.ManualDataReq, tag, row string, calculateCellMap map[string]string) (val string, err error) {
  960. rowInt, err := strconv.Atoi(row)
  961. if err != nil {
  962. return
  963. }
  964. // 单元格的标签名
  965. cellTagName := strings.ToUpper(tag) + row
  966. val, ok := calculateCellMap[cellTagName]
  967. if ok {
  968. return
  969. }
  970. // 查找行数据
  971. rowData, ok := tableDataMap[rowInt]
  972. if !ok {
  973. err = errors.New("查找" + row + "行的数据失败")
  974. return
  975. }
  976. // 查找单元格数据
  977. colData, ok := rowData[tag]
  978. if !ok {
  979. err = errors.New("查找单元格" + tag + row + "的数据失败")
  980. return
  981. }
  982. // 如果不是计算单元格
  983. if colData.DataType != 4 {
  984. val = colData.ShowValue
  985. return
  986. }
  987. // 如果是计算单元格
  988. calculateCellMap[cellTagName] = ``
  989. tagMap := make(map[string]float64)
  990. for _, relation := range colData.RelationEdbInfoList {
  991. relationCellTagName := strings.ToUpper(relation.Tag) + relation.Row
  992. valStr, tmpErr := getCalculateValue(tableDataMap, relation.Tag, relation.Row, calculateCellMap)
  993. if tmpErr != nil {
  994. err = tmpErr
  995. return
  996. }
  997. tmpValDecimal, tmpErr := decimal.NewFromString(valStr)
  998. if tmpErr != nil {
  999. err = tmpErr
  1000. return
  1001. }
  1002. tagMap[relationCellTagName], _ = tmpValDecimal.Float64()
  1003. }
  1004. // 计算
  1005. val, _, err = calculate(strings.ToUpper(colData.Value), tagMap)
  1006. if err != nil {
  1007. return
  1008. }
  1009. // 重新赋值
  1010. colData.ShowValue = val
  1011. tableDataMap[rowInt][tag] = colData
  1012. calculateCellMap[cellTagName] = val
  1013. return
  1014. }
  1015. // calculate 公式计算
  1016. func calculate(calculateFormula string, TagMap map[string]float64) (calVal, errMsg string, err error) {
  1017. if calculateFormula == "" {
  1018. errMsg = "公式异常"
  1019. err = errors.New(errMsg)
  1020. return
  1021. }
  1022. calculateFormula = strings.TrimPrefix(calculateFormula, "=")
  1023. calculateFormula = strings.Replace(calculateFormula, "(", "(", -1)
  1024. calculateFormula = strings.Replace(calculateFormula, ")", ")", -1)
  1025. calculateFormula = strings.Replace(calculateFormula, ",", ",", -1)
  1026. calculateFormula = strings.Replace(calculateFormula, "。", ".", -1)
  1027. calculateFormula = strings.Replace(calculateFormula, "%", "*0.01", -1)
  1028. formulaFormStr := utils.ReplaceFormula(TagMap, calculateFormula)
  1029. //计算公式异常,那么就移除该指标
  1030. if formulaFormStr == `` {
  1031. errMsg = "公式异常"
  1032. err = errors.New(errMsg)
  1033. return
  1034. }
  1035. expression := formula.NewExpression(formulaFormStr)
  1036. calResult, err := expression.Evaluate()
  1037. if err != nil {
  1038. errMsg = "计算失败"
  1039. err = errors.New("计算失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
  1040. // 分母为0的报错
  1041. if strings.Contains(err.Error(), "divide by zero") {
  1042. errMsg = "分母不能为0"
  1043. err = errors.New("分母不能为空,计算公式:" + formulaFormStr)
  1044. }
  1045. return
  1046. }
  1047. // 如果计算结果是NAN,那么就提示报错
  1048. if calResult.IsNan() {
  1049. errMsg = "计算失败"
  1050. err = errors.New("计算失败:计算结果是:NAN;formulaStr:" + formulaFormStr)
  1051. return
  1052. }
  1053. calVal = calResult.String()
  1054. // 转Decimal然后四舍五入
  1055. valDecimal, err := decimal.NewFromString(calVal)
  1056. if err != nil {
  1057. errMsg = "计算失败"
  1058. err = errors.New("计算失败,结果转 Decimal 失败:Err:" + err.Error() + ";formulaStr:" + formulaFormStr)
  1059. return
  1060. }
  1061. calVal = valDecimal.Round(4).String()
  1062. return
  1063. }
  1064. // GetMixedTableCellData 获取混合表格数据
  1065. func GetMixedTableCellData(config [][]request.MixedTableCellDataReq) (newMixedTableCellDataList [][]request.MixedTableCellDataReq, err error) {
  1066. newMixedTableCellDataList = config
  1067. edbInfoIdList := make([]int, 0)
  1068. dataEdbInfoIdList := make([]int, 0)
  1069. for _, row := range config {
  1070. for _, cell := range row {
  1071. if cell.DataType == 2 {
  1072. edbInfoIdList = append(edbInfoIdList, cell.EdbInfoId)
  1073. } else if cell.DataType == 4 {
  1074. dataEdbInfoIdList = append(dataEdbInfoIdList, cell.EdbInfoId)
  1075. }
  1076. }
  1077. }
  1078. edbInfoList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1079. if err != nil {
  1080. return
  1081. }
  1082. // 指标信息map
  1083. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1084. // 指标数据map
  1085. edbDataListMap := make(map[int]map[string]float64)
  1086. for _, edbInfo := range edbInfoList {
  1087. edbInfoMap[edbInfo.EdbInfoId] = edbInfo
  1088. dataList := make([]*data_manage.EdbDataList, 0)
  1089. switch edbInfo.EdbInfoType {
  1090. case 0:
  1091. dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.EdbInfoId, ``, ``)
  1092. case 1:
  1093. _, dataList, _, _, _, _ = GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  1094. default:
  1095. err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
  1096. }
  1097. dateValMap := make(map[string]float64)
  1098. for _, data := range dataList {
  1099. dateValMap[data.DataTime] = data.Value
  1100. }
  1101. edbDataListMap[edbInfo.EdbInfoId] = dateValMap
  1102. }
  1103. for k, row := range newMixedTableCellDataList {
  1104. for i, cell := range row {
  1105. if cell.DataType == 2 {
  1106. if edbInfo, ok := edbInfoMap[cell.EdbInfoId]; ok {
  1107. cell.ShowValue = edbInfo.EdbName
  1108. }
  1109. } else if cell.DataType == 4 {
  1110. if dateValMap, ok := edbDataListMap[cell.EdbInfoId]; ok {
  1111. if val, ok2 := dateValMap[cell.DataTime]; ok2 {
  1112. cell.ShowValue = fmt.Sprint(val)
  1113. }
  1114. }
  1115. }
  1116. row[i] = cell
  1117. }
  1118. newMixedTableCellDataList[k] = row
  1119. }
  1120. return
  1121. }