edb_data_calculate_bp.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_index_lib/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "github.com/shopspring/decimal"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // AddCalculateBp 升频
  13. func AddCalculateBp(req *EdbInfoCalculateBatchSaveReq, fromEdbInfo *EdbInfo, edbCode, uniqueCode string, sysUserId int, sysUserRealName string) (edbInfo *EdbInfo, err error) {
  14. o := orm.NewOrm()
  15. to, err := o.Begin()
  16. if err != nil {
  17. return
  18. }
  19. defer func() {
  20. if err != nil {
  21. fmt.Println("AddCalculateBp,Err:" + err.Error())
  22. _ = to.Rollback()
  23. } else {
  24. _ = to.Commit()
  25. }
  26. }()
  27. if req.EdbInfoId <= 0 {
  28. edbInfo = new(EdbInfo)
  29. edbInfo.Source = utils.DATA_SOURCE_CALCULATE_BP
  30. edbInfo.SourceName = utils.DATA_SOURCE_NAME_CALCULATE_BP
  31. edbInfo.EdbCode = edbCode
  32. edbInfo.EdbName = req.EdbName
  33. edbInfo.EdbNameSource = req.EdbName
  34. edbInfo.Frequency = req.Frequency
  35. edbInfo.Unit = req.Unit
  36. edbInfo.ClassifyId = req.ClassifyId
  37. edbInfo.SysUserId = sysUserId
  38. edbInfo.SysUserRealName = sysUserRealName
  39. edbInfo.CreateTime = time.Now()
  40. edbInfo.ModifyTime = time.Now()
  41. edbInfo.UniqueCode = uniqueCode
  42. edbInfo.CalculateFormula = req.Formula
  43. edbInfo.EdbType = 2
  44. newEdbInfoId, tmpErr := to.Insert(edbInfo)
  45. if tmpErr != nil {
  46. err = tmpErr
  47. return
  48. }
  49. edbInfo.EdbInfoId = int(newEdbInfoId)
  50. //关联关系
  51. {
  52. calculateMappingItem := new(EdbInfoCalculateMapping)
  53. calculateMappingItem.CreateTime = time.Now()
  54. calculateMappingItem.ModifyTime = time.Now()
  55. calculateMappingItem.Sort = 1
  56. calculateMappingItem.EdbCode = edbCode
  57. calculateMappingItem.EdbInfoId = edbInfo.EdbInfoId
  58. calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
  59. calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
  60. calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
  61. calculateMappingItem.FromSource = fromEdbInfo.Source
  62. calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
  63. calculateMappingItem.FromTag = ""
  64. calculateMappingItem.Source = edbInfo.Source
  65. calculateMappingItem.SourceName = edbInfo.SourceName
  66. _, err = to.Insert(calculateMappingItem)
  67. if err != nil {
  68. return
  69. }
  70. }
  71. } else {
  72. edbInfo, err = GetEdbInfoById(req.EdbInfoId)
  73. if err != nil {
  74. return
  75. }
  76. dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_CALCULATE_BP)
  77. fmt.Println("dataTableName:" + dataTableName)
  78. deleteSql := ` DELETE FROM %s WHERE edb_info_id=? `
  79. deleteSql = fmt.Sprintf(deleteSql, dataTableName)
  80. _, err = to.Raw(deleteSql, req.EdbInfoId).Exec()
  81. if err != nil {
  82. return
  83. }
  84. }
  85. //计算数据
  86. err = refreshAllCalculateBp(to, edbInfo.EdbInfoId, edbInfo.Source, fromEdbInfo, edbInfo.EdbCode, "", "", 0)
  87. return
  88. }
  89. // EditCalculateBp 修改升频数据
  90. func EditCalculateBp(edbInfo *EdbInfo, req *EdbInfoCalculateBatchEditReq, fromEdbInfo *EdbInfo) (err error) {
  91. o := orm.NewOrm()
  92. to, err := o.Begin()
  93. if err != nil {
  94. return
  95. }
  96. defer func() {
  97. if err != nil {
  98. fmt.Println("EditCalculateBp,Err:" + err.Error())
  99. _ = to.Rollback()
  100. } else {
  101. _ = to.Commit()
  102. }
  103. }()
  104. //修改指标信息
  105. edbInfo.EdbName = req.EdbName
  106. edbInfo.EdbNameSource = req.EdbName
  107. edbInfo.Frequency = req.Frequency
  108. edbInfo.Unit = req.Unit
  109. edbInfo.ClassifyId = req.ClassifyId
  110. edbInfo.ModifyTime = time.Now()
  111. _, err = to.Update(edbInfo, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId", "ModifyTime")
  112. if err != nil {
  113. return
  114. }
  115. //判断计算指标是否被更换
  116. var existCondition string
  117. var existPars []interface{}
  118. existCondition += " AND edb_info_id=? AND from_edb_info_id=? "
  119. existPars = append(existPars, edbInfo.EdbInfoId, req.FromEdbInfoId)
  120. count, err := GetEdbInfoCalculateCountByCondition(existCondition, existPars)
  121. if err != nil {
  122. err = errors.New("判断指标是否改变失败,Err:" + err.Error())
  123. return
  124. }
  125. if count > 0 { // 指标未被替换,无需重新计算
  126. return
  127. }
  128. //删除,计算指标关联的,基础指标的关联关系
  129. sql := ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
  130. _, err = to.Raw(sql, edbInfo.EdbInfoId).Exec()
  131. if err != nil {
  132. err = errors.New("删除计算指标关联关系失败,Err:" + err.Error())
  133. return
  134. }
  135. //清空原有数据
  136. sql = ` DELETE FROM edb_data_calculate_bp WHERE edb_info_id = ? `
  137. _, err = to.Raw(sql, edbInfo.EdbInfoId).Exec()
  138. if err != nil {
  139. return
  140. }
  141. //关联关系
  142. {
  143. calculateMappingItem := &EdbInfoCalculateMapping{
  144. EdbInfoCalculateMappingId: 0,
  145. EdbInfoId: edbInfo.EdbInfoId,
  146. Source: utils.DATA_SOURCE_CALCULATE_BP,
  147. SourceName: utils.DATA_SOURCE_NAME_CALCULATE_BP,
  148. EdbCode: edbInfo.EdbCode,
  149. FromEdbInfoId: fromEdbInfo.EdbInfoId,
  150. FromEdbCode: fromEdbInfo.EdbCode,
  151. FromEdbName: fromEdbInfo.EdbName,
  152. FromSource: fromEdbInfo.Source,
  153. FromSourceName: fromEdbInfo.SourceName,
  154. FromTag: "",
  155. Sort: 1,
  156. CreateTime: time.Now(),
  157. ModifyTime: time.Now(),
  158. }
  159. _, err = to.Insert(calculateMappingItem)
  160. if err != nil {
  161. return
  162. }
  163. }
  164. //计算数据
  165. err = refreshAllCalculateBp(to, edbInfo.EdbInfoId, edbInfo.Source, fromEdbInfo, edbInfo.EdbCode, "", "", 0)
  166. return
  167. }
  168. // RefreshAllCalculateBpBak 刷新所有升频数据
  169. func RefreshAllCalculateBpBak(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
  170. o := orm.NewOrm()
  171. to, err := o.Begin()
  172. if err != nil {
  173. return
  174. }
  175. defer func() {
  176. if err != nil {
  177. fmt.Println("RefreshAllCalculateBp,Err:" + err.Error())
  178. _ = to.Rollback()
  179. } else {
  180. _ = to.Commit()
  181. }
  182. }()
  183. if err != nil {
  184. return
  185. }
  186. edbInfoIdStr := strconv.Itoa(edbInfoId)
  187. //计算数据
  188. //计算数据
  189. var condition string
  190. var pars []interface{}
  191. condition += " AND edb_info_id=? "
  192. pars = append(pars, fromEdbInfo.EdbInfoId)
  193. if startDate != "" {
  194. condition += " AND data_time>=? "
  195. pars = append(pars, startDate)
  196. }
  197. if endDate != "" {
  198. condition += " AND data_time<=? "
  199. pars = append(pars, endDate)
  200. }
  201. dataList, err := GetEdbDataListAllByTo(to, condition, pars, fromEdbInfo.Source, 0)
  202. if err != nil {
  203. return err
  204. }
  205. var dateArr []string
  206. dataMap := make(map[string]*EdbInfoSearchData)
  207. for _, v := range dataList {
  208. dateArr = append(dateArr, v.DataTime)
  209. dataMap[v.DataTime] = v
  210. }
  211. fmt.Println("source:", source)
  212. //获取指标所有数据
  213. existDataList := make([]*EdbData, 0)
  214. dataTableName := GetEdbDataTableName(source)
  215. fmt.Println("dataTableName:", dataTableName)
  216. sql := `SELECT * FROM %s WHERE edb_info_id=? `
  217. sql = fmt.Sprintf(sql, dataTableName)
  218. _, err = to.Raw(sql, edbInfoId).QueryRows(&existDataList)
  219. if err != nil {
  220. return err
  221. }
  222. existDataMap := make(map[string]string)
  223. for _, v := range existDataList {
  224. existDataMap[v.DataTime] = v.Value
  225. }
  226. fmt.Println("existDataMap:", existDataMap)
  227. addSql := ` INSERT INTO edb_data_calculate_bp(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
  228. var isAdd bool
  229. existMap := make(map[string]string)
  230. dataLen := len(dataList)
  231. for i := 0; i < dataLen; i++ {
  232. //当期
  233. currentItem := dataList[i]
  234. currentDate, _ := time.ParseInLocation(utils.FormatDate, currentItem.DataTime, time.Local)
  235. var day int
  236. var preItem *EdbInfoSearchData
  237. var preDate time.Time
  238. if i == 0 {
  239. day = int(time.Now().Sub(currentDate).Hours() / float64(24))
  240. preDate = time.Now()
  241. } else {
  242. j := i + 1
  243. if j < dataLen {
  244. preItem = dataList[j]
  245. preDate, _ = time.ParseInLocation(utils.FormatDate, preItem.DataTime, time.Local)
  246. day = int(currentDate.Sub(preDate).Hours() / float64(24))
  247. }
  248. }
  249. for k := 0; k <= day; k++ {
  250. needDay := preDate.AddDate(0, 0, -k)
  251. needDayStr := needDay.Format(utils.FormatDate)
  252. existKey := edbCode + needDayStr
  253. if _, ok := existMap[existKey]; !ok {
  254. timestamp := needDay.UnixNano() / 1e6
  255. timestampStr := fmt.Sprintf("%d", timestamp)
  256. valStr := decimal.NewFromFloat(currentItem.Value).String()
  257. if existVal, ok := existDataMap[needDayStr]; !ok {
  258. addSql += GetAddSql(edbInfoIdStr, edbCode, needDayStr, timestampStr, valStr)
  259. } else {
  260. if existVal != valStr {
  261. sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
  262. sql = fmt.Sprintf(sql, dataTableName)
  263. _, err = to.Raw(sql, valStr, edbInfoId, needDay).Exec()
  264. if err != nil {
  265. return err
  266. }
  267. }
  268. }
  269. }
  270. existMap[existKey] = needDayStr
  271. }
  272. existKey := edbCode + currentItem.DataTime
  273. if _, ok := existMap[existKey]; !ok {
  274. currentDate, _ := time.ParseInLocation(utils.FormatDate, currentItem.DataTime, time.Local)
  275. timestamp := currentDate.UnixNano() / 1e6
  276. timestampStr := fmt.Sprintf("%d", timestamp)
  277. valStr := decimal.NewFromFloat(currentItem.Value).String()
  278. if existVal, ok := existDataMap[currentItem.DataTime]; !ok {
  279. addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, valStr)
  280. } else {
  281. if existVal != valStr {
  282. sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
  283. sql = fmt.Sprintf(sql, dataTableName)
  284. _, err = to.Raw(sql, valStr, edbInfoId, currentItem.DataTime).Exec()
  285. if err != nil {
  286. return err
  287. }
  288. }
  289. }
  290. }
  291. existMap[existKey] = currentItem.DataTime
  292. }
  293. if isAdd {
  294. addSql = strings.TrimRight(addSql, ",")
  295. _, err = to.Raw(addSql).Exec()
  296. if err != nil {
  297. return err
  298. }
  299. }
  300. return
  301. }
  302. func RefreshAllCalculateBp(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
  303. o := orm.NewOrm()
  304. to, err := o.Begin()
  305. if err != nil {
  306. return
  307. }
  308. defer func() {
  309. if err != nil {
  310. fmt.Println("RefreshAllCalculateBp,Err:" + err.Error())
  311. _ = to.Rollback()
  312. } else {
  313. _ = to.Commit()
  314. }
  315. }()
  316. // 计算数据
  317. err = refreshAllCalculateBp(to, edbInfoId, source, fromEdbInfo, edbCode, startDate, endDate, 1)
  318. return
  319. }
  320. // refreshAllCalculateBp 刷新升频数据
  321. func refreshAllCalculateBp(to orm.TxOrmer, edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string, order int) (err error) {
  322. edbInfoIdStr := strconv.Itoa(edbInfoId)
  323. //计算数据
  324. var condition string
  325. var pars []interface{}
  326. condition += " AND edb_info_id=? "
  327. pars = append(pars, fromEdbInfo.EdbInfoId)
  328. //if startDate != "" {
  329. // condition += " AND data_time>=? "
  330. // pars = append(pars, startDate)
  331. //}
  332. //if endDate != "" {
  333. // condition += " AND data_time<=? "
  334. // pars = append(pars, endDate)
  335. //}
  336. //获取来源指标的数据
  337. dataList, err := GetEdbDataListAllByTo(to, condition, pars, fromEdbInfo.Source, order)
  338. if err != nil {
  339. return err
  340. }
  341. var dateArr []string
  342. dataMap := make(map[string]*EdbInfoSearchData)
  343. fromDataMap := make(map[string]float64)
  344. //来源指指标数据
  345. for _, v := range dataList {
  346. dateArr = append(dateArr, v.DataTime)
  347. dataMap[v.DataTime] = v
  348. fromDataMap[v.DataTime] = v.Value
  349. }
  350. fmt.Println("source:", source)
  351. //获取升频指标所有数据
  352. existDataList, err := GetAllEdbDataListByTo(to, edbInfoId, source)
  353. if err != nil {
  354. return
  355. }
  356. //计算指标的map
  357. existDataMap := make(map[string]*EdbData, 0)
  358. addSql := ` INSERT INTO edb_data_calculate_bp(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
  359. var isAdd bool
  360. var lastValue float64 //最后数据的值(float64)
  361. var lastValueStr string //最后数据的值(string)
  362. //待删除的日期
  363. removeDateList := make([]string, 0)
  364. if len(existDataList) > 0 {
  365. //第一个已经入库的日期
  366. firstExistDataTimeStr := existDataList[0].DataTime //计算指标数据第一条的日期字符串
  367. lenDateArr := len(dateArr)
  368. if lenDateArr > 0 {
  369. firstFromDataTimeStr := dateArr[0] //来源数据第一条的日期字符串
  370. firstExistDataTime, _ := time.ParseInLocation(utils.FormatDate, firstExistDataTimeStr, time.Local) //计算指标数据第一条的日期(time类型)
  371. firstFromDataTime, _ := time.ParseInLocation(utils.FormatDate, firstFromDataTimeStr, time.Local) //来源数据第一条的日期(time类型)
  372. fromEndDateStr := dateArr[lenDateArr-1] //当天日期字符串
  373. fromEndDate, _ := time.ParseInLocation(utils.FormatDate, fromEndDateStr, firstFromDataTime.Location()) //当天日期(time类型)
  374. lastValue = fromDataMap[firstFromDataTimeStr]
  375. lastValueStr = decimal.NewFromFloat(lastValue).String()
  376. //第一步: 判断来源指标的开始时间与计算指标的开始时间是否相等,相等的话,那么就不需要对两个时间之间的数据做处理
  377. if firstExistDataTimeStr != firstFromDataTimeStr {
  378. if firstExistDataTime.Before(firstFromDataTime) { //如果计算指标第一条数据的开始时间 早于 来源指标的第一条开始时间,那么需要对两个时间之间的计算指标数据做 删除处理
  379. for _, v := range existDataList {
  380. if v.DataTime == firstFromDataTimeStr {
  381. if tmpLastValue, ok := fromDataMap[firstFromDataTimeStr]; ok { //来源指标当天的数据
  382. lastValue = tmpLastValue
  383. lastValueStr = decimal.NewFromFloat(lastValue).String()
  384. }
  385. break
  386. }
  387. removeDateList = append(removeDateList, v.DataTime)
  388. }
  389. } else {
  390. for _, v := range dateArr { //如果计算指标第一条数据的开始时间 晚于 来源指标的第一条开始时间,那么需要对两个时间之间的计算指标数据做 新增处理
  391. vDataTime, _ := time.ParseInLocation(utils.FormatDate, v, time.Local) //当前日期(time类型)
  392. if firstExistDataTime.Equal(vDataTime) || firstExistDataTime.Before(vDataTime) {
  393. if tmpLastValue, ok := fromDataMap[v]; ok { //来源指标当天的数据
  394. lastValue = tmpLastValue
  395. lastValueStr = decimal.NewFromFloat(lastValue).String()
  396. }
  397. break
  398. }
  399. currentDate, _ := time.ParseInLocation(utils.FormatDate, v, time.Local)
  400. timestamp := currentDate.UnixNano() / 1e6
  401. timestampStr := fmt.Sprintf("%d", timestamp)
  402. addSql += GetAddSql(edbInfoIdStr, edbCode, v, timestampStr, lastValueStr)
  403. isAdd = true
  404. }
  405. }
  406. }
  407. //第二步 剩余数据每天修改
  408. day := int(fromEndDate.Sub(firstExistDataTime).Hours() / float64(24))
  409. //第三步: 已经入库的数据处理
  410. for _, v := range existDataList {
  411. existDataMap[v.DataTime] = v
  412. }
  413. for k := day; k >= 0; k-- {
  414. needDay := fromEndDate.AddDate(0, 0, -k)
  415. needDayStr := needDay.Format(utils.FormatDate)
  416. tmpExistData, ok := existDataMap[needDayStr]
  417. if ok {
  418. if tmpLastValue, ok := fromDataMap[tmpExistData.DataTime]; ok { //来源指标当天的数据
  419. lastValue = tmpLastValue
  420. //lastValueStr = decimal.NewFromFloat(lastValue).String()
  421. lastValueStr = fmt.Sprintf("%.4f", lastValue)
  422. }
  423. //如果对应的值不匹配
  424. if tmpExistData.Value != lastValueStr {
  425. err = ModifyEdbDataById(source, tmpExistData.EdbDataId, lastValueStr)
  426. if err != nil {
  427. return err
  428. }
  429. }
  430. } else {
  431. timestamp := needDay.UnixNano() / 1e6
  432. timestampStr := fmt.Sprintf("%d", timestamp)
  433. addSql += GetAddSql(edbInfoIdStr, edbCode, needDayStr, timestampStr, lastValueStr)
  434. isAdd = true
  435. }
  436. }
  437. } else {
  438. //如果没有来源指标数据,那么已经入库的计算指标数据需要全部删除
  439. tableName := GetEdbDataTableName(source)
  440. sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ?`, tableName)
  441. _, err = to.Raw(sql, edbInfoId).Exec()
  442. if err != nil {
  443. err = fmt.Errorf("删除所有的升频指标数据失败,Err:" + err.Error())
  444. return
  445. }
  446. //for _, v := range existDataList {
  447. // removeDateList = append(removeDateList, v.DataTime)
  448. //}
  449. }
  450. } else {
  451. existMap := make(map[string]string)
  452. dataLen := len(dataList)
  453. for i := 0; i < dataLen; i++ {
  454. //当期
  455. currentItem := dataList[i]
  456. currentDate, _ := time.ParseInLocation(utils.FormatDate, currentItem.DataTime, time.Local)
  457. var day int
  458. var preItem *EdbInfoSearchData
  459. var preDate time.Time
  460. if i == 0 {
  461. day = int(time.Now().Sub(currentDate).Hours() / float64(24))
  462. preDate = time.Now()
  463. } else {
  464. j := i - 1
  465. if j < dataLen {
  466. preItem = dataList[j]
  467. preDate, _ = time.ParseInLocation(utils.FormatDate, preItem.DataTime, time.Local)
  468. day = int(preDate.Sub(currentDate).Hours() / float64(24))
  469. utils.FileLog.Info("preItem.DataTime:" + preItem.DataTime + ";currentItem.DataTime" + currentItem.DataTime)
  470. }
  471. }
  472. for k := 0; k <= day; k++ {
  473. needDay := preDate.AddDate(0, 0, -k)
  474. needDayStr := needDay.Format(utils.FormatDate)
  475. existKey := edbCode + needDayStr
  476. if _, ok := existMap[existKey]; !ok {
  477. timestamp := needDay.UnixNano() / 1e6
  478. timestampStr := fmt.Sprintf("%d", timestamp)
  479. valStr := decimal.NewFromFloat(currentItem.Value).String()
  480. addSql += GetAddSql(edbInfoIdStr, edbCode, needDayStr, timestampStr, valStr)
  481. isAdd = true
  482. }
  483. existMap[existKey] = needDayStr
  484. }
  485. existKey := edbCode + currentItem.DataTime
  486. if _, ok := existMap[existKey]; !ok {
  487. currentDate, _ := time.ParseInLocation(utils.FormatDate, currentItem.DataTime, time.Local)
  488. timestamp := currentDate.UnixNano() / 1e6
  489. timestampStr := fmt.Sprintf("%d", timestamp)
  490. valStr := decimal.NewFromFloat(currentItem.Value).String()
  491. addSql += GetAddSql(edbInfoIdStr, edbCode, currentItem.DataTime, timestampStr, valStr)
  492. isAdd = true
  493. }
  494. existMap[existKey] = currentItem.DataTime
  495. }
  496. }
  497. // 删除不需要的指标数据
  498. if len(removeDateList) > 0 {
  499. removeDateStr := strings.Join(removeDateList, `","`)
  500. removeDateStr = `"` + removeDateStr + `"`
  501. //如果拼接指标变更了,那么需要删除所有的指标数据
  502. tableName := GetEdbDataTableName(source)
  503. sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (%s) `, tableName, removeDateStr)
  504. _, err = to.Raw(sql, edbInfoId).Exec()
  505. if err != nil {
  506. err = fmt.Errorf("删除不存在的升频指标数据失败,Err:" + err.Error())
  507. return
  508. }
  509. }
  510. if isAdd {
  511. addSql = strings.TrimRight(addSql, ",")
  512. _, err = to.Raw(addSql).Exec()
  513. }
  514. return
  515. }