edb_data_calculate_ljz.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. "reflect"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // Ljz 累计值
  14. type Ljz struct {
  15. }
  16. // Add 添加
  17. func (obj Ljz) Add(params AddCalculateBatchParams) (edbInfo *EdbInfo, err error, errMsg string) {
  18. req := params.Req
  19. fromEdbInfo := params.FromEdbInfo
  20. edbCode := params.EdbCode
  21. frequencyInt := utils.CheckFrequency(fromEdbInfo.Frequency, req.Frequency)
  22. if frequencyInt < 0 {
  23. errMsg = "频度异常,不允许低频转为高频"
  24. err = errors.New(errMsg)
  25. return
  26. }
  27. if frequencyInt == 0 {
  28. errMsg = "频度异常,不允许同频计算累计值"
  29. err = errors.New(errMsg)
  30. return
  31. }
  32. o := orm.NewOrm()
  33. to, err := o.Begin()
  34. if err != nil {
  35. return
  36. }
  37. defer func() {
  38. if err != nil {
  39. _ = to.Rollback()
  40. fmt.Println(reflect.TypeOf(obj).Name(), ";Add,Err:"+err.Error())
  41. } else {
  42. _ = to.Commit()
  43. }
  44. }()
  45. edbInfo = &EdbInfo{
  46. //EdbInfoId: 0,
  47. SourceName: obj.GetSourceName(),
  48. Source: obj.GetSource(),
  49. EdbCode: edbCode,
  50. EdbName: req.EdbName,
  51. EdbNameSource: req.EdbName,
  52. Frequency: req.Frequency,
  53. Unit: req.Unit,
  54. StartDate: "",
  55. EndDate: "",
  56. ClassifyId: req.ClassifyId,
  57. SysUserId: params.SysUserId,
  58. SysUserRealName: params.SysUserRealName,
  59. UniqueCode: params.UniqueCode,
  60. CreateTime: time.Now(),
  61. ModifyTime: time.Now(),
  62. MinValue: 0,
  63. MaxValue: 0,
  64. CalculateFormula: req.Formula,
  65. EdbType: 2,
  66. Sort: 0,
  67. MoveType: 0,
  68. MoveFrequency: "",
  69. NoUpdate: 0,
  70. ServerUrl: "",
  71. EdbInfoType: 0,
  72. EdbNameEn: "",
  73. UnitEn: "",
  74. LatestDate: "",
  75. LatestValue: 0,
  76. ChartImage: "",
  77. Calendar: "",
  78. }
  79. newEdbInfoId, tmpErr := to.Insert(edbInfo)
  80. if tmpErr != nil {
  81. err = tmpErr
  82. return
  83. }
  84. edbInfo.EdbInfoId = int(newEdbInfoId)
  85. //关联关系
  86. {
  87. calculateMappingItem := new(EdbInfoCalculateMapping)
  88. calculateMappingItem.CreateTime = time.Now()
  89. calculateMappingItem.ModifyTime = time.Now()
  90. calculateMappingItem.Sort = 1
  91. calculateMappingItem.EdbCode = edbCode
  92. calculateMappingItem.EdbInfoId = edbInfo.EdbInfoId
  93. calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
  94. calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
  95. calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
  96. calculateMappingItem.FromSource = fromEdbInfo.Source
  97. calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
  98. calculateMappingItem.FromTag = ""
  99. calculateMappingItem.Source = edbInfo.Source
  100. calculateMappingItem.SourceName = edbInfo.SourceName
  101. _, err = to.Insert(calculateMappingItem)
  102. if err != nil {
  103. return
  104. }
  105. }
  106. //计算数据
  107. err = obj.refresh(to, edbInfo.EdbInfoId, edbInfo.Source, edbInfo, fromEdbInfo, edbInfo.EdbCode, "")
  108. return
  109. }
  110. // Edit 编辑
  111. func (obj Ljz) Edit(params EditCalculateBatchParams) (err error, errMsg string) {
  112. req := params.Req
  113. edbInfo := params.EdbInfo
  114. fromEdbInfo := params.FromEdbInfo
  115. frequencyInt := utils.CheckFrequency(fromEdbInfo.Frequency, req.Frequency)
  116. if frequencyInt < 0 {
  117. errMsg = "频度异常,不允许低频转为高频"
  118. err = errors.New(errMsg)
  119. return
  120. }
  121. if frequencyInt == 0 {
  122. errMsg = "频度异常,不允许同频计算累计值"
  123. err = errors.New(errMsg)
  124. return
  125. }
  126. o := orm.NewOrm()
  127. to, err := o.Begin()
  128. if err != nil {
  129. return
  130. }
  131. defer func() {
  132. if err != nil {
  133. _ = to.Rollback()
  134. fmt.Println(reflect.TypeOf(obj).Name(), ";Edit,Err:"+err.Error())
  135. } else {
  136. _ = to.Commit()
  137. }
  138. }()
  139. tableName := GetEdbDataTableName(edbInfo.Source)
  140. var isRecalculate bool
  141. if edbInfo.Frequency != req.Frequency {
  142. isRecalculate = true
  143. }
  144. //修改指标信息
  145. edbInfo.EdbName = req.EdbName
  146. edbInfo.EdbNameSource = req.EdbName
  147. edbInfo.Frequency = req.Frequency
  148. edbInfo.Unit = req.Unit
  149. edbInfo.ClassifyId = req.ClassifyId
  150. edbInfo.ModifyTime = time.Now()
  151. _, err = to.Update(edbInfo, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId", "ModifyTime")
  152. if err != nil {
  153. return
  154. }
  155. var existCondition string
  156. var existPars []interface{}
  157. existCondition += " AND edb_info_id=? AND from_edb_info_id=? "
  158. existPars = append(existPars, edbInfo.EdbInfoId, req.FromEdbInfoId)
  159. //判断计算指标是否被更换
  160. count, err := GetEdbInfoCalculateCountByCondition(existCondition, existPars)
  161. if err != nil {
  162. err = errors.New("判断指标是否改变失败,Err:" + err.Error())
  163. return
  164. }
  165. if count > 0 { // 指标未被替换,无需删除关联数据
  166. // 频度被换了,需要重新计算
  167. if isRecalculate {
  168. err = obj.refresh(to, edbInfo.EdbInfoId, edbInfo.Source, edbInfo, fromEdbInfo, edbInfo.EdbCode, "")
  169. }
  170. return
  171. }
  172. //删除,计算指标关联的,基础指标的关联关系
  173. sql := ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? `
  174. _, err = to.Raw(sql, edbInfo.EdbInfoId).Exec()
  175. if err != nil {
  176. return
  177. }
  178. //清空原有数据
  179. sql = ` DELETE FROM ` + tableName + ` WHERE edb_info_id = ? `
  180. _, err = to.Raw(sql, edbInfo.EdbInfoId).Exec()
  181. if err != nil {
  182. return
  183. }
  184. //关联关系
  185. {
  186. calculateMappingItem := &EdbInfoCalculateMapping{
  187. EdbInfoCalculateMappingId: 0,
  188. EdbInfoId: edbInfo.EdbInfoId,
  189. Source: obj.GetSource(),
  190. SourceName: obj.GetSourceName(),
  191. EdbCode: edbInfo.EdbCode,
  192. FromEdbInfoId: fromEdbInfo.EdbInfoId,
  193. FromEdbCode: fromEdbInfo.EdbCode,
  194. FromEdbName: fromEdbInfo.EdbName,
  195. FromSource: fromEdbInfo.Source,
  196. FromSourceName: fromEdbInfo.SourceName,
  197. FromTag: "",
  198. Sort: 1,
  199. CreateTime: time.Now(),
  200. ModifyTime: time.Now(),
  201. }
  202. _, err = to.Insert(calculateMappingItem)
  203. if err != nil {
  204. return
  205. }
  206. }
  207. //计算数据
  208. err = obj.refresh(to, edbInfo.EdbInfoId, edbInfo.Source, edbInfo, fromEdbInfo, edbInfo.EdbCode, "")
  209. return
  210. }
  211. // Refresh 刷新
  212. func (obj Ljz) Refresh(params RefreshParams) (err error, errMsg string) {
  213. calculateMapping, err := GetEdbInfoCalculateMappingDetail(params.EdbInfo.EdbInfoId)
  214. if err != nil {
  215. errMsg = "GetEdbInfoCalculateLjzDetail Err:" + err.Error()
  216. return
  217. }
  218. fromEdbInfo, err := GetEdbInfoById(calculateMapping.FromEdbInfoId)
  219. if err != nil {
  220. errMsg = "GetEdbInfoById Err:" + err.Error()
  221. return
  222. }
  223. o := orm.NewOrm()
  224. to, err := o.Begin()
  225. if err != nil {
  226. return
  227. }
  228. defer func() {
  229. if err != nil {
  230. _ = to.Rollback()
  231. fmt.Println(reflect.TypeOf(obj).Name(), ";Refresh,Err:"+err.Error())
  232. } else {
  233. _ = to.Commit()
  234. }
  235. }()
  236. // 计算数据
  237. err = obj.refresh(to, params.EdbInfo.EdbInfoId, params.EdbInfo.Source, params.EdbInfo, fromEdbInfo, params.EdbInfo.EdbCode, params.StartDate)
  238. return
  239. }
  240. // GetSource 获取来源编码id
  241. func (obj Ljz) GetSource() int {
  242. return utils.DATA_SOURCE_CALCULATE_LJZ
  243. }
  244. // GetSourceName 获取来源名称
  245. func (obj Ljz) GetSourceName() string {
  246. return utils.DATA_SOURCE_NAME_CALCULATE_LJZ
  247. }
  248. func (obj Ljz) refresh(to orm.TxOrmer, edbInfoId, source int, edbInfo, fromEdbInfo *EdbInfo, edbCode, startDate string) (err error) {
  249. dataTableName := GetEdbDataTableName(source)
  250. edbInfoIdStr := strconv.Itoa(edbInfoId)
  251. //计算数据
  252. var condition string
  253. var pars []interface{}
  254. condition += " AND edb_info_id=? "
  255. pars = append(pars, fromEdbInfo.EdbInfoId)
  256. //if startDate != "" {
  257. // condition += " AND data_time>=? "
  258. // pars = append(pars, startDate)
  259. //}
  260. var isWeekData bool // 是否周度数据,如果是周度数据的话,是需要变频的,最后结果还需要除以7
  261. // 周度数据需要先变成日度的
  262. if fromEdbInfo.Frequency == `周度` {
  263. isWeekData = true
  264. }
  265. dataList, err := GetEdbDataListAllByTo(to, condition, pars, fromEdbInfo.Source, 1)
  266. if err != nil {
  267. return err
  268. }
  269. fromEdbDataMap := make(map[string]float64)
  270. if isWeekData {
  271. dataList, err = HandleDataByLinearRegression(dataList, fromEdbDataMap)
  272. if err != nil {
  273. return
  274. }
  275. }
  276. //日度转周度:日期选周五,计算上周六到本周五的日度值的加总,最新日期为最新值对应的周五。
  277. //日度转月度:日期选每个月最后一天,计算当月所有日度值的加总,最新日期为最新值对应当月最后一天。
  278. //日度转季度、年度:方法类似转月度。
  279. //周度转月度/季度/年度:将周度值转成日度,空值用插值法插值,计算当月/当季/当年所有值的加总,然后除以7。
  280. //月度转季度/年度: 当季/当年月度值相加。
  281. dateList := make([]time.Time, 0)
  282. valueMap := make(map[time.Time]float64)
  283. switch edbInfo.Frequency {
  284. case "年度":
  285. yearMap := make(map[int]float64)
  286. yearList := make([]int, 0)
  287. for _, item := range dataList {
  288. itemDate, tmpErr := time.ParseInLocation(utils.FormatDate, item.DataTime, time.Local)
  289. if tmpErr != nil {
  290. err = tmpErr
  291. return
  292. }
  293. year := itemDate.Year()
  294. yearVal, ok := yearMap[year]
  295. if ok {
  296. yearMap[year] = item.Value + yearVal
  297. } else {
  298. yearList = append(yearList, year)
  299. yearMap[year] = item.Value
  300. }
  301. }
  302. for _, v := range yearList {
  303. currTime := time.Date(v, 12, 31, 0, 0, 0, 0, time.Local)
  304. dateList = append(dateList, currTime)
  305. valueMap[currTime] = yearMap[v]
  306. }
  307. case "半年度":
  308. yearMonthMap := make(map[string]float64)
  309. yearMonthList := make([]string, 0)
  310. for _, item := range dataList {
  311. itemDate, tmpErr := time.ParseInLocation(utils.FormatDate, item.DataTime, time.Local)
  312. if tmpErr != nil {
  313. err = tmpErr
  314. return
  315. }
  316. year := itemDate.Year()
  317. var tmpK string
  318. if itemDate.Month() <= 6 {
  319. tmpK = fmt.Sprint(year, "06")
  320. } else {
  321. tmpK = fmt.Sprint(year, "12")
  322. }
  323. yearVal, ok := yearMonthMap[tmpK]
  324. if ok {
  325. yearMonthMap[tmpK] = item.Value + yearVal
  326. } else {
  327. yearMonthList = append(yearMonthList, tmpK)
  328. yearMonthMap[tmpK] = item.Value
  329. }
  330. }
  331. for _, v := range yearMonthList {
  332. currTime, tmpErr := time.ParseInLocation(utils.FormatYearMonthUnSpace, v, time.Local)
  333. if tmpErr != nil {
  334. err = tmpErr
  335. return
  336. }
  337. currTime = currTime.AddDate(0, 1, -1)
  338. dateList = append(dateList, currTime)
  339. valueMap[currTime] = yearMonthMap[v]
  340. }
  341. case "季度":
  342. yearMonthMap := make(map[string]float64)
  343. yearMonthList := make([]string, 0)
  344. for _, item := range dataList {
  345. itemDate, tmpErr := time.ParseInLocation(utils.FormatDate, item.DataTime, time.Local)
  346. if tmpErr != nil {
  347. err = tmpErr
  348. return
  349. }
  350. year := itemDate.Year()
  351. var tmpK string
  352. if itemDate.Month() <= 3 {
  353. tmpK = fmt.Sprint(year, "03")
  354. } else if itemDate.Month() <= 6 {
  355. tmpK = fmt.Sprint(year, "06")
  356. } else if itemDate.Month() <= 9 {
  357. tmpK = fmt.Sprint(year, "09")
  358. } else {
  359. tmpK = fmt.Sprint(year, "12")
  360. }
  361. yearVal, ok := yearMonthMap[tmpK]
  362. if ok {
  363. yearMonthMap[tmpK] = item.Value + yearVal
  364. } else {
  365. yearMonthList = append(yearMonthList, tmpK)
  366. yearMonthMap[tmpK] = item.Value
  367. }
  368. }
  369. for _, v := range yearMonthList {
  370. currTime, tmpErr := time.ParseInLocation(utils.FormatYearMonthUnSpace, v, time.Local)
  371. if tmpErr != nil {
  372. err = tmpErr
  373. return
  374. }
  375. currTime = currTime.AddDate(0, 1, -1)
  376. dateList = append(dateList, currTime)
  377. valueMap[currTime] = yearMonthMap[v]
  378. }
  379. case "月度":
  380. yearMonthMap := make(map[string]float64)
  381. yearMonthList := make([]string, 0)
  382. for _, item := range dataList {
  383. itemDate, tmpErr := time.ParseInLocation(utils.FormatDate, item.DataTime, time.Local)
  384. if tmpErr != nil {
  385. err = tmpErr
  386. return
  387. }
  388. year := itemDate.Year()
  389. var tmpK string
  390. tmpK = fmt.Sprint(year*100 + int(itemDate.Month()))
  391. yearVal, ok := yearMonthMap[tmpK]
  392. if ok {
  393. yearMonthMap[tmpK] = item.Value + yearVal
  394. } else {
  395. yearMonthList = append(yearMonthList, tmpK)
  396. yearMonthMap[tmpK] = item.Value
  397. }
  398. }
  399. for _, v := range yearMonthList {
  400. currTime, tmpErr := time.ParseInLocation(utils.FormatYearMonthUnSpace, v, time.Local)
  401. if tmpErr != nil {
  402. err = tmpErr
  403. return
  404. }
  405. currTime = currTime.AddDate(0, 1, -1)
  406. dateList = append(dateList, currTime)
  407. valueMap[currTime] = yearMonthMap[v]
  408. }
  409. case "旬度":
  410. tmpDateDataMap := make(map[time.Time]float64)
  411. tmpDateList := make([]time.Time, 0)
  412. for _, item := range dataList {
  413. itemDate, tmpErr := time.ParseInLocation(utils.FormatDate, item.DataTime, time.Local)
  414. if tmpErr != nil {
  415. err = tmpErr
  416. return
  417. }
  418. dayInt := itemDate.Year()*100 + int(itemDate.Month())
  419. var currTime time.Time
  420. if itemDate.Month() <= 10 {
  421. tmpK := fmt.Sprint(dayInt*100, "10")
  422. currTime, err = time.ParseInLocation(utils.FormatDateUnSpace, tmpK, time.Local)
  423. if err != nil {
  424. return
  425. }
  426. } else if itemDate.Month() <= 20 {
  427. tmpK := fmt.Sprint(dayInt*100, "20")
  428. currTime, err = time.ParseInLocation(utils.FormatDateUnSpace, tmpK, time.Local)
  429. if err != nil {
  430. return
  431. }
  432. } else {
  433. currTime, err = time.ParseInLocation(utils.FormatYearMonthUnSpace, fmt.Sprint(dayInt), time.Local)
  434. if err != nil {
  435. return
  436. }
  437. currTime = currTime.AddDate(0, 1, -1)
  438. }
  439. yearVal, ok := tmpDateDataMap[currTime]
  440. if ok {
  441. tmpDateDataMap[currTime] = item.Value + yearVal
  442. } else {
  443. tmpDateList = append(tmpDateList, currTime)
  444. tmpDateDataMap[currTime] = item.Value
  445. }
  446. }
  447. for _, currTime := range tmpDateList {
  448. dateList = append(dateList, currTime)
  449. valueMap[currTime] = tmpDateDataMap[currTime]
  450. }
  451. case "周度":
  452. tmpDateDataMap := make(map[time.Time]float64)
  453. tmpDateList := make([]time.Time, 0)
  454. for _, item := range dataList {
  455. itemDate, tmpErr := time.ParseInLocation(utils.FormatDate, item.DataTime, time.Local)
  456. if tmpErr != nil {
  457. err = tmpErr
  458. return
  459. }
  460. var currTime time.Time
  461. // 周六周日,这是下一个周五的数据
  462. if itemDate.Weekday() == 0 {
  463. currTime = itemDate.AddDate(0, 0, 5)
  464. } else if itemDate.Weekday() == 6 {
  465. currTime = itemDate.AddDate(0, 0, 6)
  466. } else {
  467. currTime = itemDate.AddDate(0, 0, 5-int(itemDate.Weekday()))
  468. }
  469. yearVal, ok := tmpDateDataMap[currTime]
  470. if ok {
  471. tmpDateDataMap[currTime] = item.Value + yearVal
  472. } else {
  473. tmpDateList = append(tmpDateList, currTime)
  474. tmpDateDataMap[currTime] = item.Value
  475. }
  476. }
  477. for _, currTime := range tmpDateList {
  478. dateList = append(dateList, currTime)
  479. valueMap[currTime] = tmpDateDataMap[currTime]
  480. }
  481. }
  482. //获取指标所有数据
  483. existDataList := make([]*EdbData, 0)
  484. sql := `SELECT * FROM %s WHERE edb_info_id=? `
  485. sql = fmt.Sprintf(sql, dataTableName)
  486. _, err = to.Raw(sql, edbInfoId).QueryRows(&existDataList)
  487. if err != nil {
  488. return err
  489. }
  490. existDataMap := make(map[string]string)
  491. removeDataTimeMap := make(map[string]int) //需要移除的日期数据
  492. for _, v := range existDataList {
  493. existDataMap[v.DataTime] = v.Value
  494. removeDataTimeMap[v.DataTime] = 1
  495. }
  496. needAddDateMap := make(map[time.Time]int)
  497. addSql := ` INSERT INTO ` + dataTableName + `(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
  498. var isAdd bool
  499. for _, currTime := range dateList {
  500. currDateStr := currTime.Format(utils.FormatDate)
  501. existVal, ok := existDataMap[currDateStr]
  502. tmpVal, ok2 := valueMap[currTime]
  503. if !ok2 {
  504. err = errors.New("数据异常,date:" + currDateStr)
  505. return
  506. }
  507. var saveValue string
  508. if isWeekData { //周度指标转的话,最后结果要除以7
  509. saveValue = decimal.NewFromFloat(tmpVal).Div(decimal.NewFromInt(7)).Round(4).String()
  510. } else {
  511. saveValue = decimal.NewFromFloat(tmpVal).Round(4).String()
  512. }
  513. // 如果库中已经存在该数据的话,那么就进行值的变更操作
  514. if ok {
  515. //校验待删除日期数据里面是否存在该元素,如果存在的话,那么移除该日期
  516. delete(removeDataTimeMap, currDateStr)
  517. if existVal != saveValue {
  518. sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
  519. sql = fmt.Sprintf(sql, dataTableName)
  520. _, err = to.Raw(sql, saveValue, edbInfoId, currDateStr).Exec()
  521. if err != nil {
  522. return
  523. }
  524. }
  525. continue
  526. }
  527. // 库中不存在该日期的数据
  528. timestamp := currTime.UnixNano() / 1e6
  529. timeStr := fmt.Sprintf("%d", timestamp)
  530. if _, existOk := needAddDateMap[currTime]; !existOk {
  531. addSql += GetAddSql(edbInfoIdStr, edbCode, currDateStr, timeStr, saveValue)
  532. isAdd = true
  533. }
  534. needAddDateMap[currTime] = 1
  535. }
  536. //删除已经不存在的指标数据(由于该指标当日的数据删除了)
  537. {
  538. removeDateList := make([]string, 0)
  539. for dateTime := range removeDataTimeMap {
  540. removeDateList = append(removeDateList, dateTime)
  541. }
  542. removeNum := len(removeDateList)
  543. if removeNum > 0 {
  544. sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (`+utils.GetOrmInReplace(removeNum)+`) `, dataTableName)
  545. _, err = to.Raw(sql, edbInfo.EdbInfoId, removeDateList).Exec()
  546. if err != nil {
  547. fmt.Println(reflect.TypeOf(obj).Name(), " add data ;delete Err", err.Error())
  548. err = fmt.Errorf("删除不存在的指标数据失败,Err:" + err.Error())
  549. return
  550. }
  551. }
  552. }
  553. if isAdd {
  554. addSql = strings.TrimRight(addSql, ",")
  555. _, err = to.Raw(addSql).Exec()
  556. if err != nil {
  557. fmt.Println(reflect.TypeOf(obj).Name(), " add data Err", err.Error())
  558. return
  559. }
  560. }
  561. return
  562. }