excel_info.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. package excel
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/data_manage/excel"
  8. "eta/eta_api/models/data_manage/excel/request"
  9. "eta/eta_api/models/data_manage/excel/response"
  10. "eta/eta_api/models/system"
  11. "eta/eta_api/services/data"
  12. "eta/eta_api/services/data/data_manage_permission"
  13. "eta/eta_api/utils"
  14. "fmt"
  15. "sort"
  16. "time"
  17. )
  18. // GetExcelDetailInfoByExcelInfoId 根据表格id获取表格详情
  19. func GetExcelDetailInfoByExcelInfoId(excelInfoId, sysUserId int, lang string) (excelDetail response.ExcelInfoDetail, errMsg string, err error) {
  20. errMsg = `获取失败`
  21. //获取eta表格信息
  22. excelInfo, err := excel.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. return formatExcelInfo2Detail(excelInfo, sysUserId, lang)
  32. }
  33. // GetExcelDetailInfoByUnicode 根据表格编码获取表格详情
  34. func GetExcelDetailInfoByUnicode(unicode string, sysUserId int, lang string) (excelDetail response.ExcelInfoDetail, errMsg string, err error) {
  35. errMsg = `获取失败`
  36. // 获取eta表格信息
  37. excelInfo, err := excel.GetExcelInfoByUnicode(unicode)
  38. if err != nil {
  39. err = errors.New("获取ETA表格信息失败,Err:" + err.Error())
  40. if err.Error() == utils.ErrNoRow() {
  41. errMsg = "ETA表格被删除,请刷新页面"
  42. err = errors.New("ETA表格被删除,请刷新页面,Err:" + err.Error())
  43. }
  44. return
  45. }
  46. return formatExcelInfo2Detail(excelInfo, sysUserId, lang)
  47. }
  48. func formatExcelInfo2Detail(excelInfo *excel.ExcelInfo, sysUserId int, lang string) (excelDetail response.ExcelInfoDetail, errMsg string, err error) {
  49. checkExcelInfo := excelInfo
  50. if excelInfo.Source == utils.BALANCE_TABLE {
  51. checkExcelInfoId := excelInfo.ExcelInfoId
  52. if excelInfo.BalanceType == 1 {
  53. checkExcelInfoId = excelInfo.RelExcelInfoId
  54. } else {
  55. if excelInfo.ParentId > 0 {
  56. checkExcelInfoId = excelInfo.ParentId
  57. }
  58. }
  59. if checkExcelInfoId != excelInfo.ExcelInfoId {
  60. checkExcelInfo, err = excel.GetExcelInfoById(checkExcelInfoId)
  61. if err != nil {
  62. errMsg = "获取平衡表格信息失败"
  63. err = errors.New("获取平衡表格信息失败,Err:" + err.Error())
  64. return
  65. }
  66. }
  67. }
  68. // 数据权限
  69. haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, sysUserId)
  70. if err != nil {
  71. err = errors.New("获取表格权限信息失败,Err" + err.Error())
  72. return
  73. }
  74. excelDetail = response.ExcelInfoDetail{
  75. ExcelInfoId: excelInfo.ExcelInfoId,
  76. Source: excelInfo.Source,
  77. ExcelType: excelInfo.ExcelType,
  78. ExcelName: excelInfo.ExcelName,
  79. UniqueCode: excelInfo.UniqueCode,
  80. ExcelClassifyId: excelInfo.ExcelClassifyId,
  81. SysUserId: excelInfo.SysUserId,
  82. SysUserRealName: excelInfo.SysUserRealName,
  83. Content: excelInfo.Content,
  84. ExcelImage: excelInfo.ExcelImage,
  85. FileUrl: excelInfo.FileUrl,
  86. Sort: excelInfo.Sort,
  87. IsDelete: excelInfo.IsDelete,
  88. ModifyTime: excelInfo.ModifyTime,
  89. CreateTime: excelInfo.CreateTime,
  90. TableData: nil,
  91. HaveOperaAuth: haveOperaAuth,
  92. ParentId: excelInfo.ParentId,
  93. BalanceType: excelInfo.BalanceType,
  94. UpdateUserId: excelInfo.UpdateUserId,
  95. UpdateUserRealName: excelInfo.UpdateUserRealName,
  96. RelExcelInfoId: excelInfo.RelExcelInfoId,
  97. SourcesFrom: excelInfo.SourcesFrom,
  98. }
  99. // 无权限,不需要返回数据
  100. if !haveOperaAuth {
  101. return
  102. }
  103. switch excelInfo.Source {
  104. case utils.TIME_TABLE: // 时间序列表格
  105. var tableDataConfig TableDataConfig
  106. err = json.Unmarshal([]byte(excelDetail.Content), &tableDataConfig)
  107. if err != nil {
  108. err = errors.New("表格json转结构体失败,Err:" + err.Error())
  109. return
  110. }
  111. result, tmpErr := GetDataByTableDataConfig(tableDataConfig)
  112. if tmpErr != nil {
  113. err = errors.New("获取最新的表格数据失败,Err:" + tmpErr.Error())
  114. return
  115. }
  116. if len(result.EdbInfoIdList) > 0 {
  117. classifyIdList := make([]int, 0)
  118. for _, v := range result.Data {
  119. classifyIdList = append(classifyIdList, v.ClassifyId)
  120. }
  121. classifyMap := make(map[int]*data_manage.EdbClassify)
  122. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  123. if tmpErr != nil {
  124. err = errors.New("获取分类列表失败,Err:" + tmpErr.Error())
  125. return
  126. }
  127. for _, v := range classifyList {
  128. classifyMap[v.ClassifyId] = v
  129. }
  130. // 获取所有有权限的指标和分类
  131. permissionEdbIdList, permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUserId, 0, 0)
  132. if err != nil {
  133. err = errors.New("获取所有有权限的指标和分类失败,Err:" + tmpErr.Error())
  134. return
  135. }
  136. for i, v := range result.Data {
  137. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  138. result.Data[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  139. }
  140. }
  141. }
  142. excelDetail.TableData = result
  143. case utils.MIXED_TABLE, utils.BALANCE_TABLE: // 混合表格 平衡表
  144. var result request.MixedTableReq
  145. err = json.Unmarshal([]byte(excelDetail.Content), &result)
  146. if err != nil {
  147. err = errors.New("表格json转结构体失败,Err:" + err.Error())
  148. return
  149. }
  150. newData, tmpErr, tmpErrMsg := GetMixedTableCellData(result, lang)
  151. if tmpErr != nil {
  152. errMsg = "获取失败"
  153. if tmpErrMsg != `` {
  154. errMsg = tmpErrMsg
  155. }
  156. err = errors.New("获取最新的数据失败,Err:" + tmpErr.Error())
  157. return
  158. }
  159. result.Data = newData
  160. excelDetail.TableData = result
  161. }
  162. if excelDetail.Source == utils.BALANCE_TABLE {
  163. excelDetail.Button = GetBalanceExcelInfoOpButton(sysUserId, checkExcelInfo.SysUserId, excelDetail.HaveOperaAuth, checkExcelInfo.ExcelInfoId)
  164. }
  165. return
  166. }
  167. // GetExcelInfoOpButton 获取ETA表格的操作权限
  168. func GetExcelInfoOpButton(sysUser *system.Admin, belongUserId, source int, haveOperaAuth bool) (button excel.ExcelInfoDetailButton) {
  169. // 如果没有数据权限,那么直接返回
  170. if !haveOperaAuth {
  171. return
  172. }
  173. //非管理员角色查看其他用户创建的表格,可刷新、另存为、下载表格;
  174. button.RefreshButton = true
  175. button.CopyButton = true
  176. button.DownloadButton = true
  177. // 1、本用户创建的表格,可编辑、刷新、另存为、下载、删除,删除需二次确认;
  178. // 2、管理员角色对所有表格有如上权限;
  179. // 3、在线excel所有人都能编辑
  180. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || source == utils.EXCEL_DEFAULT {
  181. button.OpButton = true
  182. button.DeleteButton = true
  183. }
  184. // 自定义分析
  185. if source == utils.CUSTOM_ANALYSIS_TABLE {
  186. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId {
  187. button.OpEdbButton = true // 生成、查看指标按钮
  188. button.RefreshEdbButton = true // 刷新指标按钮
  189. }
  190. }
  191. return
  192. }
  193. // GetFirstEdbDataList 获取第一列的数据
  194. func GetFirstEdbDataList(edbInfo *data_manage.EdbInfo, num int, manualDateList []string) (resultDataList []request.ManualDataReq, err error) {
  195. var dataList []*data_manage.EdbDataList
  196. switch edbInfo.EdbInfoType {
  197. case 0:
  198. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
  199. case 1:
  200. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  201. default:
  202. err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
  203. }
  204. if err != nil {
  205. return
  206. }
  207. // 获取需要的期数
  208. lenData := len(dataList)
  209. if lenData <= 0 {
  210. return
  211. }
  212. tmpManualDateNum := 0 // 手工数据的期数
  213. lenManualDate := len(manualDateList)
  214. if lenManualDate > 0 {
  215. sortDateList := manualDateList
  216. baseDateList := utils.StrArr{}
  217. baseDateList = append(baseDateList, sortDateList...)
  218. sort.Sort(baseDateList)
  219. sortDateList = append([]string{}, baseDateList...)
  220. lastData := dataList[lenData-1]
  221. lastDataDate, tmpErr := time.ParseInLocation(utils.FormatDate, lastData.DataTime, time.Local)
  222. if tmpErr != nil {
  223. err = tmpErr
  224. return
  225. }
  226. // 遍历倒序后的日期,然后匹配在实际数据之后日期的个数
  227. for _, tmpDateStr := range sortDateList {
  228. tmpDate, tmpErr := time.ParseInLocation(utils.FormatDate, tmpDateStr, time.Local)
  229. if tmpErr != nil {
  230. err = tmpErr
  231. return
  232. }
  233. if tmpDate.After(lastDataDate) {
  234. tmpManualDateNum++
  235. continue
  236. }
  237. break
  238. }
  239. }
  240. // 需要的期数减去手工数据的期数,这才是A列指标需要的数据
  241. num = num - tmpManualDateNum
  242. if num > lenData {
  243. num = lenData
  244. }
  245. latestDateTime, _ := time.ParseInLocation(utils.FormatDate, edbInfo.LatestDate, time.Local)
  246. for i := 1; i <= num; i++ {
  247. dataTime, _ := time.ParseInLocation(utils.FormatDate, dataList[lenData-i].DataTime, time.Local)
  248. dataType := 1
  249. // 如果是预测指标,且当前值的日期,晚于实际日期,那么是预测值
  250. if edbInfo.EdbInfoType == 1 && dataTime.After(latestDateTime) {
  251. dataType = 5
  252. }
  253. resultDataList = append(resultDataList, request.ManualDataReq{
  254. DataType: dataType,
  255. DataTime: dataList[lenData-i].DataTime,
  256. ShowValue: fmt.Sprint(dataList[lenData-i].Value),
  257. Value: fmt.Sprint(dataList[lenData-i].Value),
  258. DataTimeType: 1,
  259. })
  260. }
  261. return
  262. }
  263. // PadFirstEdbDataList 补齐第一列的数据
  264. func PadFirstEdbDataList(resultDataList []request.ManualDataReq, dateList []string, sortType string) []request.ManualDataReq {
  265. originDataNum := len(resultDataList)
  266. requsetDateNum := len(dateList)
  267. if originDataNum >= requsetDateNum {
  268. return resultDataList
  269. }
  270. padNum := requsetDateNum - originDataNum
  271. if sortType == "asc" {
  272. for i := 0; i < padNum; i++ {
  273. resultDataList = append(resultDataList, request.ManualDataReq{
  274. DataType: 0,
  275. DataTime: dateList[originDataNum+i],
  276. ShowValue: ``,
  277. Value: ``,
  278. DataTimeType: 1,
  279. })
  280. }
  281. } else {
  282. var tmpDateList []request.ManualDataReq
  283. for i := padNum - 1; i <= 0; i-- {
  284. tmpDateList = append(tmpDateList, request.ManualDataReq{
  285. DataType: 0,
  286. DataTime: dateList[originDataNum+i],
  287. ShowValue: ``,
  288. Value: ``,
  289. DataTimeType: 1,
  290. })
  291. resultDataList = append(tmpDateList, resultDataList...)
  292. }
  293. }
  294. return resultDataList
  295. }
  296. // GetOtherEdbDataList 获取其他列的数据
  297. func GetOtherEdbDataList(edbInfo *data_manage.EdbInfo, dateList []string) (resultDataList []request.ManualDataReq, err error) {
  298. lenDate := len(dateList)
  299. if lenDate <= 0 {
  300. return
  301. }
  302. sortDateList := dateList
  303. baseDateList := utils.StrArr{}
  304. baseDateList = append(baseDateList, sortDateList...)
  305. sort.Sort(baseDateList)
  306. sortDateList = append([]string{}, baseDateList...)
  307. endDateTime, err := time.ParseInLocation(utils.FormatDate, sortDateList[0], time.Local)
  308. if err != nil {
  309. return
  310. }
  311. firstDateTime, err := time.ParseInLocation(utils.FormatDate, sortDateList[lenDate-1], time.Local)
  312. if err != nil {
  313. return
  314. }
  315. var dataList []*data_manage.EdbDataList
  316. switch edbInfo.EdbInfoType {
  317. case 0:
  318. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
  319. case 1:
  320. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  321. default:
  322. err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
  323. }
  324. if err != nil {
  325. return
  326. }
  327. // 获取日期内的数据(包含开始日期前一个日期,以及 结束日期后一个日期,目的为了做空日期时的 插值法兼容)
  328. baseDataList := make([]*data_manage.EdbDataList, 0)
  329. var lastData *data_manage.EdbDataList
  330. var isInsert bool
  331. for _, data := range dataList {
  332. tmpDate := data.DataTime
  333. tmpDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, tmpDate, time.Local)
  334. if tmpErr != nil {
  335. err = tmpErr
  336. return
  337. }
  338. if tmpDateTime.Before(firstDateTime) {
  339. lastData = data
  340. continue
  341. }
  342. // 如果是第一次写入数据
  343. if !isInsert && lastData != nil {
  344. baseDataList = append(baseDataList, lastData)
  345. }
  346. if tmpDateTime.After(endDateTime) {
  347. baseDataList = append(baseDataList, data)
  348. break
  349. }
  350. baseDataList = append(baseDataList, data)
  351. isInsert = true
  352. }
  353. // 实际数据的日期map
  354. realValMap := make(map[string]string)
  355. for _, v := range baseDataList {
  356. realValMap[v.DataTime] = v.DataTime
  357. }
  358. // 插值法处理
  359. handleDataMap := make(map[string]float64)
  360. err = data.HandleDataByLinearRegression(baseDataList, handleDataMap)
  361. if err != nil {
  362. return
  363. }
  364. latestDateTime, _ := time.ParseInLocation(utils.FormatDate, edbInfo.LatestDate, time.Local)
  365. // 对于不存在的数据做补充
  366. for _, date := range sortDateList {
  367. dataType := 1
  368. if _, ok := realValMap[date]; !ok {
  369. dataType = 2
  370. } else {
  371. dataTime, _ := time.ParseInLocation(utils.FormatDate, date, time.Local)
  372. // 如果是预测指标,且当前值的日期,晚于实际日期,那么是预测值
  373. if edbInfo.EdbInfoType == 1 && dataTime.After(latestDateTime) {
  374. dataType = 5
  375. }
  376. }
  377. var value, showValue string
  378. if tmpVal, ok := handleDataMap[date]; ok {
  379. value = fmt.Sprint(tmpVal)
  380. showValue = value
  381. } else {
  382. dataType = 3
  383. }
  384. resultDataList = append(resultDataList, request.ManualDataReq{
  385. DataType: dataType,
  386. DataTime: date,
  387. ShowValue: showValue,
  388. Value: value,
  389. })
  390. }
  391. return
  392. }
  393. // GetFirstHistoryEdbDataList 获取指标的历史的数据
  394. func GetFirstHistoryEdbDataList(edbInfo *data_manage.EdbInfo, num int, endDate string) (resultDataList []request.ManualDataReq, err error) {
  395. endDateTime, err := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  396. if err != nil {
  397. return
  398. }
  399. var dataList []*data_manage.EdbDataList
  400. switch edbInfo.EdbInfoType {
  401. case 0:
  402. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, endDate)
  403. case 1:
  404. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, endDate, true)
  405. default:
  406. err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
  407. }
  408. if err != nil {
  409. return
  410. }
  411. // 获取需要的期数
  412. lenData := len(dataList)
  413. if lenData <= 0 {
  414. return
  415. }
  416. lastData := dataList[lenData-1]
  417. lastDataDateTime, err := time.ParseInLocation(utils.FormatDate, lastData.DataTime, time.Local)
  418. if err != nil {
  419. return
  420. }
  421. if endDateTime.Equal(lastDataDateTime) || lastDataDateTime.After(endDateTime) {
  422. dataList = dataList[:lenData-1]
  423. lenData = len(dataList)
  424. }
  425. if num > lenData {
  426. num = lenData
  427. }
  428. latestDateTime, _ := time.ParseInLocation(utils.FormatDate, edbInfo.LatestDate, time.Local)
  429. for i := 1; i <= num; i++ {
  430. dataTime, _ := time.ParseInLocation(utils.FormatDate, dataList[lenData-i].DataTime, time.Local)
  431. dataType := 1
  432. // 如果是预测指标,且当前值的日期,晚于实际日期,那么是预测值
  433. if edbInfo.EdbInfoType == 1 && dataTime.After(latestDateTime) {
  434. dataType = 5
  435. }
  436. resultDataList = append(resultDataList, request.ManualDataReq{
  437. DataType: dataType,
  438. DataTime: dataList[lenData-i].DataTime,
  439. ShowValue: fmt.Sprint(dataList[lenData-i].Value),
  440. Value: fmt.Sprint(dataList[lenData-i].Value),
  441. })
  442. }
  443. return
  444. }
  445. // GetEdbIdsFromExcelCodes 获取表格中的指标IDs
  446. func GetEdbIdsFromExcelCodes(excelCodes []string, sysUserId int, lang string) (edbIds []int, err error) {
  447. edbIds = make([]int, 0)
  448. edbIdExist := make(map[int]bool)
  449. for _, v := range excelCodes {
  450. // 表格详情
  451. detail, msg, e := GetExcelDetailInfoByUnicode(v, sysUserId, lang)
  452. if e != nil {
  453. err = fmt.Errorf("GetExcelDetailInfoByExcelInfoId err: %s, errMsg: %s", e.Error(), msg)
  454. return
  455. }
  456. // 自定义表格
  457. if detail.Source == utils.TIME_TABLE {
  458. jsonByte, e := json.Marshal(detail.TableData)
  459. if e != nil {
  460. err = fmt.Errorf("JSON格式化自定义表格数据失败, Err: %s", e.Error())
  461. return
  462. }
  463. var tableData request.TableDataReq
  464. if e = json.Unmarshal(jsonByte, &tableData); e != nil {
  465. err = fmt.Errorf("解析自定义表格数据失败, Err: %s", e.Error())
  466. return
  467. }
  468. for _, tv := range tableData.EdbInfoIdList {
  469. if edbIdExist[tv] {
  470. continue
  471. }
  472. edbIdExist[tv] = true
  473. edbIds = append(edbIds, tv)
  474. }
  475. }
  476. // 混合表格
  477. if detail.Source == utils.MIXED_TABLE {
  478. jsonByte, e := json.Marshal(detail.TableData)
  479. if e != nil {
  480. err = fmt.Errorf("JSON格式化混合表格数据失败, Err: %s", e.Error())
  481. return
  482. }
  483. var tableData request.MixedTableReq
  484. if e = json.Unmarshal(jsonByte, &tableData); e != nil {
  485. err = fmt.Errorf("解析混合表格数据失败, Err: %s", e.Error())
  486. return
  487. }
  488. if len(tableData.Data) > 0 {
  489. for _, td := range tableData.Data {
  490. for _, tv := range td {
  491. if tv.EdbInfoId > 0 && !edbIdExist[tv.EdbInfoId] {
  492. edbIdExist[tv.EdbInfoId] = true
  493. edbIds = append(edbIds, tv.EdbInfoId)
  494. }
  495. }
  496. }
  497. }
  498. }
  499. }
  500. return
  501. }
  502. // GetExcelEdbBatchRefreshKey 获取批量刷新表格指标缓存key
  503. func GetExcelEdbBatchRefreshKey(source string, primaryId, subId int) string {
  504. if source == `` {
  505. return ``
  506. }
  507. return fmt.Sprint("batch_refresh_excel_edb:", source, ":", primaryId, ":", subId)
  508. }
  509. // GetEdbSourceByEdbInfoIdList 获取关联指标的来源
  510. func GetEdbSourceByEdbInfoIdList(edbInfoIdList []int) (sourceNameList, sourceNameEnList []string, err error) {
  511. sourceNameList = make([]string, 0)
  512. sourceNameEnList = make([]string, 0)
  513. sourceMap := make(map[int]string)
  514. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  515. if tmpErr != nil {
  516. err = tmpErr
  517. return
  518. }
  519. for _, v := range edbInfoList {
  520. // 指标类型:1:基础指标,2:计算指标
  521. if v.EdbType == 2 {
  522. //sourceMap[0] = "弘则研究"
  523. baseEdbInfoArr, _, _ := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  524. for _, baseEdbInfo := range baseEdbInfoArr {
  525. if baseEdbInfo.EdbInfoType == 0 { //普通指标才参与,预测指标不参与
  526. sourceMap[baseEdbInfo.Source] = baseEdbInfo.SourceName
  527. }
  528. }
  529. } else {
  530. sourceMap[v.Source] = v.SourceName
  531. }
  532. }
  533. for source, sourceName := range sourceMap {
  534. if utils.InArrayByInt([]int{utils.DATA_SOURCE_MANUAL, utils.DATA_SOURCE_MYSTEEL_CHEMICAL}, source) {
  535. continue
  536. }
  537. sourceNameList = append(sourceNameList, sourceName)
  538. sourceNameEn, ok := utils.DataSourceEnMap[source]
  539. if !ok {
  540. sourceNameEn = sourceName
  541. }
  542. sourceNameEnList = append(sourceNameEnList, sourceNameEn)
  543. }
  544. //sourceNameList = append(sourceNameList, utils.ChartDefaultNameCn)
  545. //sourceNameEnList = append(sourceNameEnList, utils.ChartDefaultNameEn)
  546. // 图表来源
  547. conf, e := models.GetBusinessConf()
  548. if e != nil {
  549. return
  550. }
  551. if conf[models.BusinessConfCompanyName] != "" {
  552. sourceNameList = append(sourceNameList, conf[models.BusinessConfCompanyName])
  553. sourceNameEnList = append(sourceNameEnList, conf[models.BusinessConfCompanyName])
  554. }
  555. return
  556. }
  557. // GetCustomAnalysisOpButton 获取自定义分析按钮权限
  558. func GetCustomAnalysisOpButton(sysUser *system.Admin, belongUserId int, permissionType []int) (button excel.ExcelInfoDetailButton) {
  559. // 管理员/所属人所有权限
  560. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId {
  561. button.RefreshButton = true
  562. button.CopyButton = true
  563. button.DownloadButton = true
  564. button.OpEdbButton = true
  565. button.RefreshEdbButton = true
  566. button.OpButton = true
  567. button.DeleteButton = true
  568. return
  569. }
  570. // 非管理员-被分享人
  571. for _, v := range permissionType {
  572. if v == 1 {
  573. button.RefreshButton = true
  574. button.CopyButton = true
  575. button.DownloadButton = true
  576. }
  577. if v == 2 {
  578. button.OpEdbButton = true
  579. button.RefreshEdbButton = true
  580. button.OpButton = true
  581. button.CopyButton = true
  582. button.DownloadButton = true
  583. }
  584. }
  585. return
  586. }