edb_info_refresh.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/edb_refresh"
  7. "eta/eta_api/models/data_manage/edb_refresh/request"
  8. "eta/eta_api/services/elastic"
  9. "eta/eta_api/utils"
  10. "fmt"
  11. "strings"
  12. "time"
  13. )
  14. // 所有刷新配置key
  15. var allDefaultEdbRefreshConfigKey = `edb_refresh_config:default:all:`
  16. // GetAllDefaultEdbRefreshConfigListBySourceList
  17. // @Description: 获取默认的所有刷新配置列表
  18. // @author: Roc
  19. // @datetime 2024-01-10 15:03:36
  20. // @param source int
  21. // @param subSource int
  22. // @return list []*edb_refresh.EdbRefreshDefaultConfig
  23. // @return err error
  24. func GetAllDefaultEdbRefreshConfigListBySourceList(source, subSource int) (list []*edb_refresh.EdbRefreshDefaultConfig, err error) {
  25. key := getAllDefaultEdbRefreshConfigKey(source, subSource)
  26. if utils.Re == nil {
  27. if utils.Re == nil && utils.Rc.IsExist(key) {
  28. if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  29. err = json.Unmarshal(data, &list)
  30. return
  31. }
  32. }
  33. }
  34. list, err = edb_refresh.GetAllListBySourceList(source, subSource)
  35. if err != nil {
  36. return
  37. }
  38. // 将数据加入缓存
  39. if utils.Re == nil {
  40. data, _ := json.Marshal(list)
  41. utils.Rc.Put(key, data, 2*time.Hour)
  42. }
  43. return
  44. }
  45. // SaveEdbRefreshDefaultConfig
  46. // @Description: 设置默认的指标刷新配置接口
  47. // @author: Roc
  48. // @datetime 2024-01-10 15:11:19
  49. // @param source int
  50. // @param subSource int
  51. // @param frequency string
  52. // @param list []request.RefreshConfigReq
  53. // @return err error
  54. // @return errMsg string
  55. // @return isSendEmail bool
  56. func SaveEdbRefreshDefaultConfig(source, subSource int, frequency string, list []request.RefreshConfigReq) (err error, errMsg string, isSendEmail bool) {
  57. isSendEmail = true
  58. errMsg = `保存失败`
  59. if source <= 0 {
  60. errMsg = "来源不能为空"
  61. err = errors.New(errMsg)
  62. isSendEmail = false
  63. return
  64. }
  65. // 非有色的来源,频度不能为空
  66. if source != utils.DATA_SOURCE_YS && frequency == `` {
  67. errMsg = "频度不能为空"
  68. err = errors.New(errMsg)
  69. isSendEmail = false
  70. return
  71. }
  72. lenConf := len(list)
  73. if lenConf == 0 {
  74. errMsg = "至少需要一个刷新配置"
  75. err = errors.New(errMsg)
  76. isSendEmail = false
  77. return
  78. }
  79. if lenConf > 5 {
  80. errMsg = "刷新时间设置最多不超过5个"
  81. err = errors.New(errMsg)
  82. isSendEmail = false
  83. return
  84. }
  85. tmpArr := []string{"每周", "每旬", "每月", "每季", "每半年", "每年"}
  86. // 配置的map,避免同一种类型配置同一个时间
  87. configMap := make(map[string]string)
  88. for _, v := range list {
  89. if utils.InArrayByStr(tmpArr, v.RefreshFrequency) && v.RefreshFrequencyDay < 0 {
  90. errMsg = "请选择具体日期"
  91. err = errors.New(errMsg)
  92. isSendEmail = false
  93. return
  94. }
  95. if v.RefreshTime == "" {
  96. errMsg = "请选择具体时间"
  97. err = errors.New(errMsg)
  98. isSendEmail = false
  99. return
  100. }
  101. // 配置的map,避免同一种类型配置同一个时间
  102. key := fmt.Sprint(v.RefreshFrequency, "_", v.RefreshFrequencyDay, "_", v.RefreshTime)
  103. if _, ok := configMap[key]; ok {
  104. errMsg = "刷新频率和日期不能重复"
  105. err = errors.New(errMsg)
  106. isSendEmail = false
  107. return
  108. }
  109. configMap[key] = key
  110. }
  111. addList := make([]*edb_refresh.EdbRefreshDefaultConfig, 0)
  112. for _, v := range list {
  113. addList = append(addList, &edb_refresh.EdbRefreshDefaultConfig{
  114. Source: source,
  115. SubSource: subSource,
  116. Frequency: frequency,
  117. RefreshFrequency: v.RefreshFrequency,
  118. RefreshFrequencyDay: v.RefreshFrequencyDay,
  119. RefreshAllData: v.RefreshAllData,
  120. RefreshTime: v.RefreshTime,
  121. RefreshDataNum: v.RefreshDataNum,
  122. ModifyTime: time.Now(),
  123. CreateTime: time.Now(),
  124. })
  125. }
  126. // 保存
  127. err = edb_refresh.SaveEdbRefreshDefaultConfig(source, subSource, frequency, addList)
  128. // 清除缓存
  129. {
  130. key := getAllDefaultEdbRefreshConfigKey(source, subSource)
  131. if utils.Re == nil {
  132. _ = utils.Rc.Delete(key)
  133. }
  134. }
  135. return
  136. }
  137. // SaveEdbRefreshConfig
  138. // @Description: 设置指标刷新配置接口
  139. // @author: Roc
  140. // @datetime 2024-01-10 15:41:45
  141. // @param source int
  142. // @param subSource int
  143. // @param classifyId string
  144. // @param terminalCode string
  145. // @param frequency string
  146. // @param keyword string
  147. // @param status string
  148. // @param sysUserIdStr string
  149. // @param isSelectAll bool
  150. // @param list []request.RefreshConfigReq
  151. // @param edbSelectIdList []int
  152. // @param sysUserId int
  153. // @param sysUserRealName string
  154. // @return err error
  155. // @return errMsg string
  156. // @return isSendEmail bool
  157. func SaveEdbRefreshConfig(source, subSource int, classifyId, terminalCode, frequency, keyword, status, sysUserIdStr string, isSelectAll bool, list []request.RefreshConfigReq, edbSelectIdList []int, sysUserId int, sysUserRealName string) (err error, errMsg string, isSendEmail bool) {
  158. isSendEmail = true
  159. errMsg = `保存失败`
  160. if source <= 0 {
  161. errMsg = "来源不能为空"
  162. err = errors.New(errMsg)
  163. isSendEmail = false
  164. return
  165. }
  166. lenConf := len(list)
  167. if lenConf == 0 {
  168. errMsg = "至少需要一个刷新配置"
  169. err = errors.New(errMsg)
  170. isSendEmail = false
  171. return
  172. }
  173. if lenConf > 5 {
  174. errMsg = "刷新时间设置最多不超过5个"
  175. err = errors.New(errMsg)
  176. isSendEmail = false
  177. return
  178. }
  179. tmpArr := []string{"每周", "每旬", "每月", "每季", "每半年", "每年"}
  180. // 配置的map,避免同一种类型配置同一个时间
  181. configMap := make(map[string]string)
  182. for _, v := range list {
  183. if utils.InArrayByStr(tmpArr, v.RefreshFrequency) && v.RefreshFrequencyDay < 0 {
  184. errMsg = "请选择具体日期"
  185. err = errors.New(errMsg)
  186. isSendEmail = false
  187. return
  188. }
  189. if v.RefreshTime == "" {
  190. errMsg = "请选择具体时间"
  191. err = errors.New(errMsg)
  192. isSendEmail = false
  193. return
  194. }
  195. // 配置的map,避免同一种类型配置同一个时间
  196. key := fmt.Sprint(v.RefreshFrequency, "_", v.RefreshFrequencyDay, "_", v.RefreshTime)
  197. if _, ok := configMap[key]; ok {
  198. errMsg = "刷新频率和日期不能重复"
  199. err = errors.New(errMsg)
  200. isSendEmail = false
  201. return
  202. }
  203. configMap[key] = key
  204. }
  205. edbIdList := make([]int, 0)
  206. // 指标id列表
  207. if isSelectAll {
  208. // 如果是列表全选
  209. _, edbList, tmpErr := GetList(source, subSource, classifyId, terminalCode, sysUserIdStr, frequency, keyword, status, 0, 100000, "", "")
  210. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  211. err = tmpErr
  212. return
  213. }
  214. // 不配置的指标id
  215. notIdMap := make(map[int]int, 0)
  216. for _, v := range edbSelectIdList {
  217. notIdMap[v] = v
  218. }
  219. for _, v := range edbList {
  220. _, ok := notIdMap[v.EdbInfoId]
  221. // 在不配置的指标id列表内的话,那就过滤
  222. if ok {
  223. continue
  224. }
  225. // 加入到待配置的指标列表id
  226. edbIdList = append(edbIdList, v.EdbInfoId)
  227. }
  228. } else {
  229. edbIdList = edbSelectIdList
  230. }
  231. if len(edbIdList) <= 0 {
  232. errMsg = "指标不能为空"
  233. err = errors.New(errMsg)
  234. isSendEmail = false
  235. return
  236. }
  237. // 待添加的配置关系数据
  238. addMappingList := make([]*edb_refresh.EdbRefreshMapping, 0)
  239. // 待添加的日期配置项
  240. addConfigList := make([]*edb_refresh.EdbRefreshConfig, 0)
  241. for _, v := range list {
  242. item, tmpErr := edb_refresh.GetEdbRefreshConfigListByCondition(v.RefreshFrequency, v.RefreshTime, v.RefreshFrequencyDay, v.RefreshAllData, v.RefreshDataNum)
  243. if tmpErr != nil {
  244. if tmpErr.Error() != utils.ErrNoRow() {
  245. err = tmpErr
  246. return
  247. }
  248. addConfigList = append(addConfigList, &edb_refresh.EdbRefreshConfig{
  249. RefreshFrequency: v.RefreshFrequency,
  250. RefreshFrequencyDay: v.RefreshFrequencyDay,
  251. RefreshTime: v.RefreshTime,
  252. RefreshAllData: v.RefreshAllData,
  253. RefreshDataNum: v.RefreshDataNum,
  254. ModifyTime: time.Now(),
  255. CreateTime: time.Now(),
  256. })
  257. continue
  258. }
  259. for _, edbId := range edbIdList {
  260. addMappingList = append(addMappingList, &edb_refresh.EdbRefreshMapping{
  261. EdbRefreshMappingId: 0,
  262. Source: source,
  263. SubSource: subSource,
  264. EdbInfoId: edbId,
  265. EdbRefreshConfigId: item.EdbRefreshConfigId,
  266. SysUserId: sysUserId,
  267. SysUserRealName: sysUserRealName,
  268. ModifyTime: time.Now(),
  269. CreateTime: time.Now(),
  270. })
  271. }
  272. }
  273. // 保存
  274. err = edb_refresh.SaveEdbRefreshConfig(source, subSource, sysUserId, sysUserRealName, addConfigList, addMappingList, edbIdList)
  275. return
  276. }
  277. // HandleRefreshTime
  278. // @Description: 处理刷新时间的显示
  279. // @author: Roc
  280. // @datetime 2024-01-10 17:00:03
  281. // @param source int
  282. // @param subSource int
  283. // @param list []*data_manage.BaseRefreshEdbInfo
  284. // @return newList []*data_manage.BaseRefreshEdbInfo
  285. // @return err error
  286. // @return errMsg string
  287. // @return isSendEmail bool
  288. func HandleRefreshTime(source, subSource int, list []*data_manage.BaseRefreshEdbInfo) (newList []*data_manage.BaseRefreshEdbInfo, err error, errMsg string, isSendEmail bool) {
  289. isSendEmail = true
  290. errMsg = "获取失败"
  291. newList = list
  292. // 默认刷新配置
  293. defaultEdbRefreshConfigMap := make(map[string]string)
  294. {
  295. // 获取默认配置
  296. allDefaultEdbRefreshConfigList, tmpErr := GetAllDefaultEdbRefreshConfigListBySourceList(source, subSource)
  297. if tmpErr != nil {
  298. err = tmpErr
  299. return
  300. }
  301. defaultEdbRefreshConfigListMap := make(map[string][]string)
  302. for _, v := range allDefaultEdbRefreshConfigList {
  303. tmp, ok := defaultEdbRefreshConfigListMap[v.Frequency]
  304. if !ok {
  305. tmp = make([]string, 0)
  306. }
  307. defaultEdbRefreshConfigListMap[v.Frequency] = append(tmp, GetRefreshStr(v.RefreshFrequency, v.RefreshFrequencyDay, v.RefreshTime))
  308. }
  309. for k, v := range defaultEdbRefreshConfigListMap {
  310. defaultEdbRefreshConfigMap[k] = strings.Join(v, ",")
  311. }
  312. }
  313. edbInfoIdList := make([]int, 0)
  314. for _, v := range newList {
  315. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  316. }
  317. // 指标的刷新时间配置
  318. edbRefreshConfigMap := make(map[int]string)
  319. {
  320. // 获取指标的单独配置
  321. configList, tmpErr := edb_refresh.GetEdbRefreshConfigAndEdbListBySourceAndeEdbInfoId(source, subSource, edbInfoIdList)
  322. if tmpErr != nil {
  323. err = tmpErr
  324. return
  325. }
  326. edbRefreshConfigListMap := make(map[int][]string)
  327. for _, v := range configList {
  328. tmp, ok := edbRefreshConfigListMap[v.EdbInfoId]
  329. if !ok {
  330. tmp = make([]string, 0)
  331. }
  332. edbRefreshConfigListMap[v.EdbInfoId] = append(tmp, GetRefreshStr(v.RefreshFrequency, v.RefreshFrequencyDay, v.RefreshTime))
  333. }
  334. for k, v := range edbRefreshConfigListMap {
  335. edbRefreshConfigMap[k] = strings.Join(v, ",")
  336. }
  337. }
  338. // 处理刷新时间
  339. for _, v := range newList {
  340. refreshTime, ok := edbRefreshConfigMap[v.EdbInfoId]
  341. if ok {
  342. v.RefreshTime = refreshTime
  343. continue
  344. }
  345. if source == utils.DATA_SOURCE_YS {
  346. v.RefreshTime = defaultEdbRefreshConfigMap[``]
  347. } else {
  348. v.RefreshTime = defaultEdbRefreshConfigMap[v.Frequency]
  349. }
  350. }
  351. return
  352. }
  353. // GetList
  354. // @Description: 获取指标列表
  355. // @author: Roc
  356. // @datetime 2024-01-08 15:14:16
  357. // @param source int
  358. // @param subSource int
  359. // @param classifyId string
  360. // @param terminalCode string
  361. // @param sysUserId string
  362. // @param frequency string
  363. // @param keyword string
  364. // @param startSize int
  365. // @param pageSize int
  366. // @return total int
  367. // @return list []*data_manage.BaseRefreshEdbInfo
  368. // @return err error
  369. func GetList(source, subSource int, classifyId, terminalCode, sysUserId, frequency, keyword, status string, startSize, pageSize int, sortParam, sortType string) (total int, list []*data_manage.BaseRefreshEdbInfo, err error) {
  370. var pars []interface{}
  371. var condition string
  372. list = make([]*data_manage.BaseRefreshEdbInfo, 0)
  373. isStop := -1
  374. if status == `暂停` {
  375. isStop = 1
  376. } else if status == "启用" {
  377. isStop = 0
  378. }
  379. keyword = strings.TrimSpace(keyword)
  380. switch source {
  381. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
  382. if classifyId != `` {
  383. classifyIdSlice := strings.Split(classifyId, ",")
  384. condition += ` AND base_from_mysteel_chemical_classify_id IN (` + utils.GetOrmInReplace(len(classifyIdSlice)) + `)`
  385. pars = append(pars, classifyIdSlice)
  386. }
  387. if terminalCode != `` {
  388. condition += " AND terminal_code = ? "
  389. pars = append(pars, terminalCode)
  390. }
  391. if sysUserId != `` {
  392. sysUserIdSlice := strings.Split(sysUserId, ",")
  393. condition += ` AND sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)`
  394. pars = append(pars, sysUserIdSlice)
  395. }
  396. if frequency != `` {
  397. frequencySlice := strings.Split(frequency, ",")
  398. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
  399. pars = append(pars, frequencySlice)
  400. }
  401. if keyword != `` {
  402. //keywordSlice := strings.Split(keyword, " ")
  403. //if len(keywordSlice) > 0 {
  404. // tmpConditionSlice := make([]string, 0)
  405. // tmpConditionSlice = append(tmpConditionSlice, ` index_name like ? or index_code like ? `)
  406. // pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  407. //
  408. // for _, v := range keywordSlice {
  409. // if v == ` ` || v == `` {
  410. // continue
  411. // }
  412. // tmpConditionSlice = append(tmpConditionSlice, ` index_name like ? or index_code like ? `)
  413. // pars = utils.GetLikeKeywordPars(pars, v, 2)
  414. // }
  415. // condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
  416. //
  417. //} else {
  418. // condition += ` index_name like ? or index_code like ? `
  419. // pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  420. //}
  421. // 走ES搜
  422. _, esList, e := elastic.SearchDataSourceIndex(utils.EsDataSourceIndexName, keyword, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, []int{}, []int{}, []string{}, startSize, pageSize)
  423. if e != nil {
  424. err = fmt.Errorf("ES-搜索钢联原始指标失败, %v", e)
  425. return
  426. }
  427. var codes []string
  428. for _, v := range esList {
  429. codes = append(codes, v.IndexCode)
  430. }
  431. if len(codes) == 0 {
  432. total = 0
  433. list = make([]*data_manage.BaseRefreshEdbInfo, 0)
  434. return
  435. }
  436. condition += fmt.Sprintf(` AND index_code IN (%s)`, utils.GetOrmInReplace(len(codes)))
  437. pars = append(pars, codes)
  438. }
  439. if isStop >= 0 {
  440. condition += " AND is_stop = ? "
  441. pars = append(pars, isStop)
  442. }
  443. sortStr := ``
  444. if sortParam != `` {
  445. sortStr = fmt.Sprintf("%s %s,base_from_mysteel_chemical_index_id desc ", sortParam, sortType)
  446. }
  447. total, list, err = data_manage.GetMysteelChemicalBaseInfoList(condition, pars, sortStr, startSize, pageSize)
  448. case utils.DATA_SOURCE_YS: // 有色
  449. if classifyId != `` {
  450. classifyIdSlice := strings.Split(classifyId, ",")
  451. condition += ` AND classify_id IN (` + utils.GetOrmInReplace(len(classifyIdSlice)) + `)`
  452. pars = append(pars, classifyIdSlice)
  453. }
  454. if terminalCode != `` {
  455. condition += " AND terminal_code = ? "
  456. pars = append(pars, terminalCode)
  457. }
  458. if frequency != `` {
  459. frequencySlice := strings.Split(frequency, ",")
  460. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
  461. pars = append(pars, frequencySlice)
  462. }
  463. if keyword != `` {
  464. //keywordSlice := strings.Split(keyword, " ")
  465. //if len(keywordSlice) > 0 {
  466. // tmpConditionSlice := make([]string, 0)
  467. // tmpConditionSlice = append(tmpConditionSlice, ` index_name like ? or index_code like ? `)
  468. // pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  469. //
  470. // for _, v := range keywordSlice {
  471. // if v == ` ` || v == `` {
  472. // continue
  473. // }
  474. // tmpConditionSlice = append(tmpConditionSlice, ` index_name like ? or index_code like ? `)
  475. // pars = utils.GetLikeKeywordPars(pars, v, 2)
  476. // }
  477. // condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
  478. //
  479. //} else {
  480. // condition += ` index_name like ? or index_code like ? `
  481. // pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  482. //}
  483. // 走ES搜
  484. _, esList, e := elastic.SearchDataSourceIndex(utils.EsDataSourceIndexName, keyword, utils.DATA_SOURCE_YS, 0, []int{}, []int{}, []string{}, startSize, pageSize)
  485. if e != nil {
  486. err = fmt.Errorf("ES-搜索SMM原始指标失败, %v", e)
  487. return
  488. }
  489. var codes []string
  490. for _, v := range esList {
  491. codes = append(codes, v.IndexCode)
  492. }
  493. if len(codes) == 0 {
  494. total = 0
  495. list = make([]*data_manage.BaseRefreshEdbInfo, 0)
  496. return
  497. }
  498. condition += fmt.Sprintf(` AND index_code IN (%s)`, utils.GetOrmInReplace(len(codes)))
  499. pars = append(pars, codes)
  500. }
  501. if isStop >= 0 {
  502. condition += " AND is_stop = ? "
  503. pars = append(pars, isStop)
  504. }
  505. sortStr := ``
  506. if sortParam != `` {
  507. sortStr = fmt.Sprintf("%s %s,base_from_smm_index_id desc ", sortParam, sortType)
  508. }
  509. total, list, err = data_manage.GetSmmBaseInfoList(condition, pars, sortStr, startSize, pageSize)
  510. default:
  511. condition += ` AND source = ? AND sub_source = ? `
  512. pars = append(pars, source, subSource)
  513. if isStop >= 0 {
  514. condition += " AND no_update = ? "
  515. pars = append(pars, isStop)
  516. }
  517. if classifyId != `` {
  518. classifyIdSlice := strings.Split(classifyId, ",")
  519. condition += ` AND classify_id IN (` + utils.GetOrmInReplace(len(classifyIdSlice)) + `)`
  520. pars = append(pars, classifyIdSlice)
  521. }
  522. if terminalCode != `` {
  523. condition += " AND terminal_code = ? "
  524. pars = append(pars, terminalCode)
  525. }
  526. if sysUserId != `` {
  527. sysUserIdSlice := strings.Split(sysUserId, ",")
  528. condition += ` AND sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)`
  529. pars = append(pars, sysUserIdSlice)
  530. }
  531. if frequency != `` {
  532. frequencySlice := strings.Split(frequency, ",")
  533. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
  534. pars = append(pars, frequencySlice)
  535. }
  536. if keyword != `` {
  537. //keywordSlice := strings.Split(keyword, " ")
  538. //if len(keywordSlice) > 0 {
  539. // tmpConditionSlice := make([]string, 0)
  540. // tmpConditionSlice = append(tmpConditionSlice, ` edb_name like ? or edb_code like ? `)
  541. // pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  542. //
  543. // for _, v := range keywordSlice {
  544. // if v == ` ` || v == `` {
  545. // continue
  546. // }
  547. // tmpConditionSlice = append(tmpConditionSlice, ` edb_name like ? or edb_code like ? `)
  548. // pars = utils.GetLikeKeywordPars(pars, v, 2)
  549. // }
  550. // condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
  551. //
  552. //} else {
  553. // condition += ` edb_name like ? or edb_code like ? `
  554. // pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  555. //}
  556. // 走ES搜
  557. _, esList, e := elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyword, startSize, pageSize, 0, source, 0, frequency, []int{})
  558. if e != nil {
  559. err = fmt.Errorf("ES-搜索指标失败, %v", e)
  560. return
  561. }
  562. var codes []string
  563. for _, v := range esList {
  564. codes = append(codes, v.EdbCode)
  565. }
  566. if len(codes) == 0 {
  567. total = 0
  568. list = make([]*data_manage.BaseRefreshEdbInfo, 0)
  569. return
  570. }
  571. condition += fmt.Sprintf(` AND edb_code IN (%s)`, utils.GetOrmInReplace(len(codes)))
  572. pars = append(pars, codes)
  573. }
  574. sortStr := ``
  575. if sortParam != `` {
  576. sortStr = fmt.Sprintf("%s %s,edb_info_id desc ", sortParam, sortType)
  577. }
  578. total, list, err = data_manage.GetEdbBaseInfoList(condition, pars, sortStr, startSize, pageSize)
  579. }
  580. return
  581. }
  582. // getAllDefaultEdbRefreshConfigKey
  583. // @Description: 获取默认的所有刷新配置key
  584. // @author: Roc
  585. // @datetime 2024-01-10 15:02:49
  586. // @param source int
  587. // @param subSource int
  588. // @return string
  589. func getAllDefaultEdbRefreshConfigKey(source, subSource int) string {
  590. return allDefaultEdbRefreshConfigKey + fmt.Sprintf("%d_%d", source, subSource)
  591. }
  592. // GetRefreshStr
  593. // @Description: 获取刷新配置的中文字符串
  594. // @author: Roc
  595. // @datetime 2024-01-10 16:05:10
  596. // @param refreshFrequency string
  597. // @param refreshFrequencyDay int
  598. // @param refreshTime string
  599. // @return string
  600. func GetRefreshStr(refreshFrequency string, refreshFrequencyDay int, refreshTime string) string {
  601. refreshDayStr := ``
  602. //if refreshFrequency != "每自然日" && refreshFrequency != "每交易日"
  603. switch refreshFrequency {
  604. case "每自然日", "每交易日":
  605. case "每周":
  606. switch refreshFrequencyDay {
  607. case 0:
  608. refreshDayStr = "日"
  609. case 1:
  610. refreshDayStr = "一"
  611. case 2:
  612. refreshDayStr = "二"
  613. case 3:
  614. refreshDayStr = "三"
  615. case 4:
  616. refreshDayStr = "四"
  617. case 5:
  618. refreshDayStr = "五"
  619. case 6:
  620. refreshDayStr = "六"
  621. case 7:
  622. refreshDayStr = "日"
  623. }
  624. default:
  625. if refreshFrequencyDay > 0 {
  626. refreshDayStr = fmt.Sprintf("第%d天", refreshFrequencyDay)
  627. } else {
  628. refreshDayStr = `最后一天`
  629. }
  630. }
  631. return refreshFrequency + refreshDayStr + " " + refreshTime
  632. }