chart_info.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. package line_feature
  2. import (
  3. "errors"
  4. "github.com/shopspring/decimal"
  5. "hongze/hz_crm_api/models/data_manage"
  6. "hongze/hz_crm_api/models/data_manage/line_feature"
  7. "hongze/hz_crm_api/models/data_manage/line_feature/response"
  8. "hongze/hz_crm_api/models/system"
  9. "hongze/hz_crm_api/services/data"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // GetStandardDeviationData 获取标准差图表的指标数据
  16. func GetStandardDeviationData(chartInfoId int, mappingInfo *data_manage.ChartEdbInfoMapping, calculateValue int) (edbList []*data_manage.ChartEdbInfoMapping, dataResp response.LineFeatureDataResp, err error, errMsg string) {
  17. edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
  18. // 指标对应的所有数据
  19. _, edbList, err = data.GetEdbDataMapList(chartInfoId, 1, `公历`, ``, ``, []*data_manage.ChartEdbInfoMapping{mappingInfo})
  20. if err != nil {
  21. return
  22. }
  23. if len(edbList) != 1 {
  24. errMsg = `指标异常`
  25. err = errors.New(errMsg)
  26. return
  27. }
  28. edb := edbList[0]
  29. dataList := edb.DataList.([]*data_manage.EdbDataList)
  30. newDataList := make([]data_manage.EdbDataList, 0)
  31. lenData := len(dataList)
  32. var minVal, maxVal float64
  33. if lenData >= calculateValue {
  34. tmpDataList := make([]float64, 0)
  35. for _, tmpData := range dataList {
  36. tmpDataList = append(tmpDataList, tmpData.Value)
  37. }
  38. for i := calculateValue; i <= lenData; i++ {
  39. tmpV := utils.CalculateStandardDeviation(tmpDataList[i-calculateValue : i])
  40. tmpV, _ = decimal.NewFromFloat(tmpV).Round(4).Float64()
  41. newDataList = append(newDataList, data_manage.EdbDataList{
  42. EdbDataId: i,
  43. EdbInfoId: edb.EdbInfoId,
  44. DataTime: dataList[i-1].DataTime,
  45. DataTimestamp: dataList[i-1].DataTimestamp,
  46. Value: tmpV,
  47. })
  48. if tmpV > maxVal {
  49. maxVal = tmpV
  50. }
  51. if tmpV < minVal {
  52. minVal = tmpV
  53. }
  54. }
  55. }
  56. dataResp = response.LineFeatureDataResp{
  57. MaxData: maxVal,
  58. MinData: minVal,
  59. LatestDate: edb.LatestDate,
  60. EdbInfoCategoryType: edb.EdbInfoCategoryType,
  61. ChartColor: `#00F`,
  62. ChartStyle: `spline`,
  63. PredictChartColor: `#00F`,
  64. ChartType: 0,
  65. ChartWidth: 3,
  66. EdbName: "标准差",
  67. EdbNameEn: "standard deviation",
  68. Unit: edb.Unit,
  69. UnitEn: edb.UnitEn,
  70. IsAxis: 1,
  71. DataList: newDataList,
  72. }
  73. return
  74. }
  75. // GetPercentileData 获取百分位图表的指标数据
  76. func GetPercentileData(chartInfoId int, mappingInfo *data_manage.ChartEdbInfoMapping, calculateValue int, calculateUnit string) (edbList []*data_manage.ChartEdbInfoMapping, dataResp response.LineFeatureDataResp, err error, errMsg string) {
  77. edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
  78. moveUnitDays, ok := utils.FrequencyDaysMap[calculateUnit]
  79. if !ok {
  80. errMsg = `错误的周期`
  81. err = errors.New(errMsg)
  82. return
  83. }
  84. calculateDay := calculateValue * moveUnitDays
  85. // 指标对应的所有数据
  86. _, edbList, err = data.GetEdbDataMapList(chartInfoId, 1, `公历`, ``, ``, []*data_manage.ChartEdbInfoMapping{mappingInfo})
  87. if err != nil {
  88. return
  89. }
  90. if len(edbList) != 1 {
  91. errMsg = `指标异常`
  92. err = errors.New(errMsg)
  93. return
  94. }
  95. edb := edbList[0]
  96. dataList := edb.DataList.([]*data_manage.EdbDataList)
  97. newDataList := make([]data_manage.EdbDataList, 0)
  98. var edbMinVal, edbMaxVal float64
  99. dataMap := make(map[time.Time]float64, 0)
  100. for _, tmpData := range dataList {
  101. currDateTime, _ := time.ParseInLocation(utils.FormatDate, tmpData.DataTime, time.Local)
  102. dataMap[currDateTime] = tmpData.Value
  103. }
  104. //百分位:对所选指标滚动地取对应时间长度的数据值,取最大值Max,最小值Min,计算Max-Min,百分位=(现值-Min)/(Max-Min),Max=Min时不予计算。
  105. for i, tmpData := range dataList {
  106. currDateTime, _ := time.ParseInLocation(utils.FormatDate, tmpData.DataTime, time.Local)
  107. maxVal := tmpData.Value
  108. minVal := tmpData.Value
  109. for k := 0; k < calculateDay; k++ {
  110. preVal, ok2 := dataMap[currDateTime.AddDate(0, 0, -k)]
  111. if ok2 {
  112. if preVal > maxVal {
  113. maxVal = preVal
  114. }
  115. if preVal < minVal {
  116. minVal = preVal
  117. }
  118. }
  119. }
  120. if maxVal == minVal {
  121. continue
  122. }
  123. //百分位=(现值-Min)/(Max-Min)
  124. tmpV := (tmpData.Value - minVal) / (maxVal - minVal) * 100
  125. tmpV, _ = decimal.NewFromFloat(tmpV).Round(4).Float64()
  126. newDataList = append(newDataList, data_manage.EdbDataList{
  127. EdbDataId: i,
  128. EdbInfoId: edb.EdbInfoId,
  129. DataTime: dataList[i].DataTime,
  130. DataTimestamp: dataList[i].DataTimestamp,
  131. Value: tmpV,
  132. })
  133. if tmpV < edbMinVal {
  134. edbMinVal = tmpV
  135. }
  136. if tmpV > edbMaxVal {
  137. edbMaxVal = tmpV
  138. }
  139. }
  140. dataResp = response.LineFeatureDataResp{
  141. MaxData: edbMaxVal,
  142. MinData: edbMinVal,
  143. LatestDate: edb.LatestDate,
  144. EdbInfoCategoryType: edb.EdbInfoCategoryType,
  145. ChartColor: `#00F`,
  146. ChartStyle: `spline`,
  147. PredictChartColor: `#00F`,
  148. ChartType: 0,
  149. ChartWidth: 3,
  150. EdbName: "百分位",
  151. EdbNameEn: "percentile",
  152. Unit: "%",
  153. UnitEn: "%",
  154. IsAxis: 1,
  155. DataList: newDataList,
  156. }
  157. return
  158. }
  159. // GetFrequencyDistributionData 获取频率分布的图表数据
  160. func GetFrequencyDistributionData(chartInfoId int, mappingInfo *data_manage.ChartEdbInfoMapping, dateType, stepVal int, startDate, endDate string) (edbList []*data_manage.ChartEdbInfoMapping, dataResp response.FrequencyDistributionResp, err error, errMsg string) {
  161. XDataList := make([]float64, 0)
  162. // 频度
  163. Y1DataList := make([]response.FrequencyDistributionYData, 0)
  164. // 累计频率
  165. Y2DataList := make([]response.FrequencyDistributionYData, 0)
  166. edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
  167. // 指标对应的所有数据
  168. _, edbList, err = data.GetEdbDataMapList(chartInfoId, 1, `公历`, startDate, endDate, []*data_manage.ChartEdbInfoMapping{mappingInfo})
  169. if err != nil {
  170. return
  171. }
  172. if len(edbList) != 1 {
  173. err = errors.New("指标异常")
  174. return
  175. }
  176. startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  177. var endDateTime time.Time
  178. if endDate != `` {
  179. endDateTime, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  180. }
  181. edb := edbList[0]
  182. dataList := edb.DataList.([]*data_manage.EdbDataList)
  183. if len(dataList) <= 0 {
  184. return
  185. }
  186. // 非自定义
  187. if dateType != 8 {
  188. endDate = dataList[len(dataList)-1].DataTime
  189. endDateTime, err = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  190. if err != nil {
  191. return
  192. }
  193. //日期类型:1:最近3月;2:最近6月;3:最近1年;4:最近2年;5:最近3年;6:最近5年;7:最近10年,8:自定义时间
  194. startDateTime = utils.GetDateByDateType2(dateType, endDateTime)
  195. startDate = startDateTime.Format(utils.FormatDate)
  196. newDataList := make([]*data_manage.EdbDataList, 0)
  197. for _, v := range dataList {
  198. tmpDataTime, tmpErr := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  199. if tmpErr != nil {
  200. err = tmpErr
  201. return
  202. }
  203. if tmpDataTime.Equal(startDateTime) || tmpDataTime.After(startDateTime) {
  204. newDataList = append(newDataList, v)
  205. }
  206. }
  207. dataList = newDataList
  208. }
  209. maxVal := dataList[0].Value
  210. minVal := dataList[0].Value
  211. dataValMap := make(map[float64]int)
  212. total := 0 // 数据总量
  213. for _, tmpData := range dataList {
  214. currDateTime, _ := time.ParseInLocation(utils.FormatDate, tmpData.DataTime, time.Local)
  215. if (currDateTime.Equal(startDateTime) || currDateTime.After(startDateTime)) && (endDateTime.IsZero() || currDateTime.Before(endDateTime)) {
  216. if maxVal < tmpData.Value {
  217. maxVal = tmpData.Value
  218. }
  219. if minVal > tmpData.Value {
  220. minVal = tmpData.Value
  221. }
  222. num, ok := dataValMap[tmpData.Value]
  223. if ok {
  224. dataValMap[tmpData.Value] = num + 1
  225. } else {
  226. dataValMap[tmpData.Value] = 1
  227. }
  228. total++
  229. }
  230. }
  231. if total <= 0 {
  232. errMsg = `没有数据`
  233. err = errors.New(errMsg)
  234. return
  235. }
  236. // 最大最小值 向上/下取整
  237. minVal = utils.GetFloorNewNum(minVal, 2)
  238. maxVal = utils.GetCeilNewNum(maxVal, 2)
  239. //间距
  240. spacing, _ := (decimal.NewFromFloat(maxVal).Sub(decimal.NewFromFloat(minVal))).Div(decimal.NewFromInt(int64(stepVal))).Float64()
  241. distributionDataNumMap := make(map[float64]int)
  242. for i := 1; i <= stepVal; i++ {
  243. tmpMinVal, _ := decimal.NewFromFloat(minVal).Add((decimal.NewFromFloat(spacing)).Mul(decimal.NewFromInt(int64(i - 1)))).Float64()
  244. tmpMaxVal, _ := decimal.NewFromFloat(minVal).Add((decimal.NewFromFloat(spacing)).Mul(decimal.NewFromInt(int64(i)))).Float64()
  245. XDataList = append(XDataList, tmpMinVal)
  246. distributionDataNumMap[tmpMinVal] = 0
  247. for tmpVal, num := range dataValMap {
  248. if tmpMinVal <= tmpVal {
  249. // 最后一期数据是要小于等于
  250. if i == stepVal {
  251. if tmpVal <= tmpMaxVal {
  252. distributionDataNumMap[tmpMinVal] += num
  253. }
  254. } else {
  255. if tmpVal < tmpMaxVal {
  256. distributionDataNumMap[tmpMinVal] += num
  257. }
  258. }
  259. }
  260. }
  261. }
  262. var minFrequency, maxFrequency float64
  263. tmpNum := 0
  264. for k, tmpMinVal := range XDataList {
  265. // 数量
  266. frequencyYNum := distributionDataNumMap[tmpMinVal]
  267. // 频率
  268. tmpFrequency, _ := decimal.NewFromInt(int64(frequencyYNum)).Div(decimal.NewFromInt(int64(total))).Mul(decimal.NewFromInt(100)).Round(4).Float64()
  269. Y1DataList = append(Y1DataList, response.FrequencyDistributionYData{
  270. X: tmpMinVal,
  271. Y: tmpFrequency,
  272. })
  273. if k == 0 {
  274. minFrequency = tmpFrequency
  275. maxFrequency = tmpFrequency
  276. } else {
  277. if tmpFrequency < minFrequency {
  278. minFrequency = tmpFrequency
  279. }
  280. if tmpFrequency > maxFrequency {
  281. maxFrequency = tmpFrequency
  282. }
  283. }
  284. // 累计数
  285. tmpNum += frequencyYNum
  286. // 累计频率
  287. tmpTotalFrequency, _ := decimal.NewFromInt(int64(tmpNum)).Div(decimal.NewFromInt(int64(total))).Mul(decimal.NewFromInt(100)).Round(4).Float64()
  288. Y2DataList = append(Y2DataList, response.FrequencyDistributionYData{
  289. X: tmpMinVal,
  290. Y: tmpTotalFrequency,
  291. })
  292. }
  293. newDataList := []response.FrequencyDistributionData{
  294. {
  295. Name: "频率",
  296. NameEn: "Frequency",
  297. Unit: "%",
  298. UnitEn: "%",
  299. Value: Y1DataList,
  300. Color: "#00F",
  301. IsAxis: 1,
  302. }, {
  303. Name: "累计频率",
  304. NameEn: "Total Frequency",
  305. Unit: "%",
  306. UnitEn: "%",
  307. Value: Y2DataList,
  308. Color: "#F00",
  309. IsAxis: 0,
  310. },
  311. }
  312. edbList[0].DataList = nil
  313. dataResp = response.FrequencyDistributionResp{
  314. LeftMinValue: minFrequency,
  315. LeftMaxValue: maxFrequency,
  316. RightMinValue: 0,
  317. RightMaxValue: 100,
  318. DataList: newDataList,
  319. }
  320. return
  321. }
  322. // AddChartInfo 添加图表
  323. func AddChartInfo(req data_manage.AddChartInfoReq, edbInfoMapping *data_manage.ChartEdbInfoMapping, source int, sysUser *system.Admin) (chartInfo *data_manage.ChartInfo, err error, errMsg string, isSendEmail bool) {
  324. isSendEmail = true
  325. req.ChartName = strings.Trim(req.ChartName, " ")
  326. if req.ChartName == "" {
  327. errMsg = "请填写图表名称!"
  328. err = errors.New(errMsg)
  329. isSendEmail = false
  330. return
  331. }
  332. if req.ChartClassifyId <= 0 {
  333. errMsg = "分类参数错误!"
  334. err = errors.New(errMsg)
  335. isSendEmail = false
  336. return
  337. }
  338. chartClassify, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  339. if err != nil {
  340. if err.Error() == utils.ErrNoRow() {
  341. errMsg = "分类不存在"
  342. err = errors.New(errMsg)
  343. isSendEmail = false
  344. return
  345. }
  346. errMsg = "获取分类信息失败"
  347. err = errors.New("获取分类信息失败,Err:" + err.Error())
  348. return
  349. }
  350. if chartClassify == nil {
  351. errMsg = "分类不存在"
  352. err = errors.New(errMsg)
  353. isSendEmail = false
  354. return
  355. }
  356. edbInfoIdArr := []int{edbInfoMapping.EdbInfoId}
  357. var edbInfoIdArrStr []string
  358. for _, v := range edbInfoIdArr {
  359. edbInfoIdArrStr = append(edbInfoIdArrStr, strconv.Itoa(v))
  360. }
  361. edbInfoIdStr := strings.Join(edbInfoIdArrStr, ",")
  362. var chartInfoId int
  363. // 判断图表是否存在
  364. var condition string
  365. var pars []interface{}
  366. condition += " AND chart_name=? AND source = ? "
  367. pars = append(pars, req.ChartName, source)
  368. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  369. if err != nil {
  370. errMsg = "判断图表名称是否存在失败"
  371. err = errors.New("判断图表名称是否存在失败,Err:" + err.Error())
  372. return
  373. }
  374. if count > 0 {
  375. errMsg = "图表已存在,请重新填写"
  376. err = errors.New(errMsg)
  377. isSendEmail = false
  378. return
  379. }
  380. disableVal := data.CheckIsDisableChart(edbInfoIdArr)
  381. chartInfo = new(data_manage.ChartInfo)
  382. chartInfo.ChartName = req.ChartName
  383. chartInfo.EdbInfoIds = edbInfoIdStr
  384. chartInfo.ChartClassifyId = req.ChartClassifyId
  385. chartInfo.SysUserId = sysUser.AdminId
  386. chartInfo.SysUserRealName = sysUser.RealName
  387. chartInfo.CreateTime = time.Now()
  388. chartInfo.ModifyTime = time.Now()
  389. chartInfo.IsSetName = 0
  390. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  391. chartInfo.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
  392. chartInfo.ChartType = 9 // 相关性图
  393. chartInfo.Calendar = "公历"
  394. chartInfo.DateType = 6
  395. chartInfo.StartDate = req.StartDate
  396. chartInfo.EndDate = req.EndDate
  397. chartInfo.SeasonStartDate = req.SeasonStartDate
  398. chartInfo.SeasonEndDate = req.SeasonEndDate
  399. chartInfo.ChartImage = req.ChartImage
  400. chartInfo.LeftMin = req.LeftMin
  401. chartInfo.LeftMax = req.LeftMax
  402. chartInfo.RightMin = req.RightMin
  403. chartInfo.RightMax = req.RightMax
  404. chartInfo.Disabled = disableVal
  405. chartInfo.Source = source
  406. chartInfo.ExtraConfig = req.ExtraConfig
  407. // 指标信息
  408. mapList := make([]*data_manage.ChartEdbMapping, 0)
  409. {
  410. mapItem := new(data_manage.ChartEdbMapping)
  411. mapItem.EdbInfoId = edbInfoMapping.EdbInfoId
  412. mapItem.CreateTime = time.Now()
  413. mapItem.ModifyTime = time.Now()
  414. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + strconv.FormatInt(time.Now().UnixNano(), 10) + "_" + strconv.Itoa(edbInfoMapping.EdbInfoId))
  415. mapItem.IsOrder = true
  416. mapItem.IsAxis = 1
  417. mapItem.EdbInfoType = 1
  418. mapItem.Source = utils.CHART_SOURCE_CORRELATION
  419. mapList = append(mapList, mapItem)
  420. }
  421. // 新增图表和指标mapping
  422. chartInfoId, e := line_feature.CreateLineFeatureChartAndEdb(chartInfo, mapList)
  423. if e != nil {
  424. errMsg = "操作失败"
  425. err = errors.New("新增相关性图表失败, Err: " + e.Error())
  426. return
  427. }
  428. //添加es数据
  429. go data.EsAddOrEditChartInfo(chartInfoId)
  430. return
  431. }
  432. // EditChartInfo 编辑图表
  433. func EditChartInfo(req data_manage.EditChartInfoReq, edbInfoMapping *data_manage.ChartEdbInfoMapping, sysUser *system.Admin) (chartItem *data_manage.ChartInfo, err error, errMsg string, isSendEmail bool) {
  434. isSendEmail = true
  435. chartItem, err = data_manage.GetChartInfoById(req.ChartInfoId)
  436. if err != nil {
  437. if err.Error() == utils.ErrNoRow() {
  438. errMsg = "图表已被删除,请刷新页面"
  439. err = errors.New(errMsg)
  440. isSendEmail = false
  441. return
  442. }
  443. errMsg = "获取图表信息失败"
  444. err = errors.New("获取图表信息失败,Err:" + err.Error())
  445. return
  446. }
  447. if !utils.InArrayByInt([]int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, chartItem.Source) {
  448. errMsg = "该图不是统计分析图表!"
  449. err = errors.New(errMsg)
  450. isSendEmail = false
  451. return
  452. }
  453. req.ChartName = strings.Trim(req.ChartName, " ")
  454. if req.ChartClassifyId <= 0 {
  455. errMsg = "分类参数错误!"
  456. err = errors.New(errMsg)
  457. isSendEmail = false
  458. return
  459. }
  460. chartClassify, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  461. if err != nil {
  462. if err.Error() == utils.ErrNoRow() {
  463. errMsg = "分类不存在"
  464. err = errors.New(errMsg)
  465. isSendEmail = false
  466. return
  467. }
  468. errMsg = "获取分类信息失败"
  469. err = errors.New("获取分类信息失败,Err:" + err.Error())
  470. return
  471. }
  472. if chartClassify == nil {
  473. errMsg = "分类不存在"
  474. err = errors.New(errMsg)
  475. isSendEmail = false
  476. return
  477. }
  478. // 图表操作权限
  479. ok := data.CheckOpChartPermission(sysUser, chartItem.SysUserId)
  480. if !ok {
  481. errMsg = "没有该图表的操作权限"
  482. err = errors.New(errMsg)
  483. isSendEmail = false
  484. return
  485. }
  486. edbInfoIdArr := []int{edbInfoMapping.EdbInfoId}
  487. var edbInfoIdArrStr []string
  488. for _, v := range edbInfoIdArr {
  489. edbInfoIdArrStr = append(edbInfoIdArrStr, strconv.Itoa(v))
  490. }
  491. edbInfoIdStr := strings.Join(edbInfoIdArrStr, ",")
  492. //判断图表是否存在
  493. var condition string
  494. var pars []interface{}
  495. condition += " AND chart_info_id <> ? "
  496. pars = append(pars, req.ChartInfoId)
  497. condition += " AND chart_name=? AND source = ? "
  498. pars = append(pars, req.ChartName, chartItem.Source)
  499. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  500. if err != nil {
  501. errMsg = "判断图表名称是否存在失败"
  502. err = errors.New("判断图表名称是否存在失败,Err:" + err.Error())
  503. return
  504. }
  505. if count > 0 {
  506. errMsg = "图表已存在,请重新填写"
  507. err = errors.New(errMsg)
  508. isSendEmail = false
  509. return
  510. }
  511. // 图表启用与否
  512. disableVal := data.CheckIsDisableChart(edbInfoIdArr)
  513. // 修改图表与指标mapping
  514. err = line_feature.EditLineFeatureChartAndMapping(&req, edbInfoIdStr, "公历", 6, disableVal, req.ExtraConfig)
  515. if err != nil {
  516. errMsg = "保存失败"
  517. err = errors.New("保存失败,Err:" + err.Error())
  518. return
  519. }
  520. resp := new(data_manage.AddChartInfoResp)
  521. resp.ChartInfoId = chartItem.ChartInfoId
  522. resp.UniqueCode = chartItem.UniqueCode
  523. resp.ChartType = req.ChartType
  524. //添加es数据
  525. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  526. //修改my eta es数据
  527. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  528. return
  529. }
  530. // CopyChartInfo 复制图表
  531. func CopyChartInfo(configId, configSource, classifyId int, chartName string, edbInfoMapping *data_manage.ChartEdbInfoMapping, oldChartInfo *data_manage.ChartInfo, sysUser *system.Admin) (chartInfo *data_manage.ChartInfo, err error, errMsg string, isSendEmail bool) {
  532. isSendEmail = true
  533. multipleGraphConfig, err := data_manage.GetMultipleGraphConfigById(configId)
  534. if err != nil {
  535. return
  536. }
  537. multipleGraphConfig.MultipleGraphConfigId = 0
  538. err = data_manage.AddMultipleGraphConfig(multipleGraphConfig)
  539. if err != nil {
  540. return
  541. }
  542. // 添加图
  543. addChartReq := data_manage.AddChartInfoReq{
  544. ChartClassifyId: classifyId,
  545. ChartName: chartName,
  546. ChartType: utils.CHART_TYPE_CURVE,
  547. Calendar: "公历",
  548. ExtraConfig: oldChartInfo.ExtraConfig,
  549. ChartImage: oldChartInfo.ChartImage,
  550. }
  551. chartSource := oldChartInfo.Source // 默认是相关性图
  552. chartInfo, err, errMsg, isSendEmail = AddChartInfo(addChartReq, edbInfoMapping, chartSource, sysUser)
  553. if err != nil {
  554. return
  555. }
  556. // 添加关系
  557. multipleGraphConfigChartMapping := &data_manage.MultipleGraphConfigChartMapping{
  558. //Id: 0,
  559. MultipleGraphConfigId: multipleGraphConfig.MultipleGraphConfigId,
  560. ChartInfoId: chartInfo.ChartInfoId,
  561. Source: configSource,
  562. ModifyTime: time.Now(),
  563. CreateTime: time.Now(),
  564. }
  565. err = data_manage.AddMultipleGraphConfigChartMapping(multipleGraphConfigChartMapping)
  566. if err != nil {
  567. return
  568. }
  569. //添加es数据
  570. go data.EsAddOrEditChartInfo(chartInfo.ChartInfoId)
  571. return
  572. }