chart_info.go 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  1. package data_manage
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "hongze/hongze_ETA_mobile_api/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. type ChartInfo struct {
  13. ChartInfoId int `orm:"column(chart_info_id);pk"`
  14. ChartName string `description:"来源名称"`
  15. ChartNameEn string `description:"英文图表名称"`
  16. ChartClassifyId int `description:"图表分类id"`
  17. SysUserId int
  18. SysUserRealName string
  19. UniqueCode string `description:"图表唯一编码"`
  20. CreateTime time.Time
  21. ModifyTime time.Time
  22. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  23. StartDate string `description:"自定义开始日期"`
  24. EndDate string `description:"自定义结束日期"`
  25. IsSetName int `description:"设置名称"`
  26. EdbInfoIds string `description:"指标id"`
  27. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图"`
  28. Calendar string `description:"公历/农历"`
  29. SeasonStartDate string `description:"季节性图开始日期"`
  30. SeasonEndDate string `description:"季节性图开始日期"`
  31. ChartImage string `description:"图表图片"`
  32. Sort int `description:"排序字段,数字越小越排前面"`
  33. LeftMin string `description:"图表左侧最小值"`
  34. LeftMax string `description:"图表左侧最大值"`
  35. RightMin string `description:"图表右侧最小值"`
  36. RightMax string `description:"图表右侧最大值"`
  37. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  38. BarConfig string `description:"柱方图的配置,json数据"`
  39. Source int `description:"1:ETA图库;2:商品价格曲线"`
  40. ExtraConfig string `description:"图表额外配置,json数据"`
  41. }
  42. type ChartInfoMore struct {
  43. ChartInfo
  44. IsEnChart bool `description:"是否展示英文标识"`
  45. }
  46. func AddChartInfo(item *ChartInfo) (lastId int64, err error) {
  47. o := orm.NewOrmUsingDB("data")
  48. lastId, err = o.Insert(item)
  49. return
  50. }
  51. type ChartInfoItem struct {
  52. ChartInfoId int `description:"图表id"`
  53. ChartName string `description:"图表名称"`
  54. ChartClassifyId int `description:"图表分类"`
  55. }
  56. // GetChartInfoAll 用于分类展示
  57. // @param source int 1:ETA图库;2:商品价格曲线
  58. func GetChartInfoAll(source int) (items []*ChartClassifyItems, err error) {
  59. o := orm.NewOrmUsingDB("data")
  60. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
  61. unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date,source
  62. FROM chart_info WHERE source = ? ORDER BY sort asc,create_time ASC `
  63. _, err = o.Raw(sql, source).QueryRows(&items)
  64. return
  65. }
  66. // GetChartInfoByAdminId 获取所有我创建的图表,用于分类展示
  67. func GetChartInfoByAdminId(source, adminId int) (items []*ChartClassifyItems, err error) {
  68. o := orm.NewOrmUsingDB("data")
  69. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
  70. unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date
  71. FROM chart_info where source = ? AND sys_user_id = ? ORDER BY sort asc,create_time ASC `
  72. _, err = o.Raw(sql, source, adminId).QueryRows(&items)
  73. return
  74. }
  75. // 用于分类展示
  76. func GetChartInfoAllList() (items []*ChartInfo, err error) {
  77. o := orm.NewOrmUsingDB("data")
  78. sql := ` SELECT *
  79. FROM chart_info ORDER BY create_time ASC `
  80. _, err = o.Raw(sql).QueryRows(&items)
  81. return
  82. }
  83. // 图表检索数据
  84. type ChartInfoSearch struct {
  85. EdbCode string `description:"图表编码"`
  86. StartDate string `description:"起始日期"`
  87. EndDate string `description:"终止日期"`
  88. DataList []*EdbInfoSearchData
  89. }
  90. type ChartInfoSearchData struct {
  91. DataTime string `description:"数据日期"`
  92. Value float64 `description:"数据"`
  93. }
  94. type ChartInfoSearchResp struct {
  95. SearchItem *EdbInfoSearch `description:"图表分类"`
  96. Status int `description:"1:数据已存在于弘则数据库,2:新数据"`
  97. }
  98. func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
  99. o := orm.NewOrmUsingDB("data")
  100. sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  101. err = o.Raw(sql, chartInfoId).QueryRow(&item)
  102. return
  103. }
  104. func GetChartInfoViewById(chartInfoId int) (item *ChartInfoView, err error) {
  105. o := orm.NewOrmUsingDB("data")
  106. sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  107. err = o.Raw(sql, chartInfoId).QueryRow(&item)
  108. return
  109. }
  110. func GetChartInfoViewByIds(chartInfoIds []string) (list []*ChartInfoView, err error) {
  111. o := orm.NewOrmUsingDB("data")
  112. sql := ` SELECT * FROM chart_info WHERE chart_info_id in ("` + strings.Join(chartInfoIds, `","`) + `") `
  113. _, err = o.Raw(sql).QueryRows(&list)
  114. return
  115. }
  116. type SaveChartInfoReq struct {
  117. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  118. ChartInfoId int `description:"图表id,新增时传0"`
  119. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  120. StartDate string `description:"自定义开始日期"`
  121. EndDate string `description:"自定义结束日期"`
  122. Calendar string `description:"公历/农历"`
  123. SeasonStartDate string `description:"季节性图开始日期"`
  124. SeasonEndDate string `description:"季节性图开始日期"`
  125. LeftMin string `description:"图表左侧最小值"`
  126. LeftMax string `description:"图表左侧最大值"`
  127. RightMin string `description:"图表右侧最小值"`
  128. RightMax string `description:"图表右侧最大值"`
  129. ExtraConfig string `description:"图表额外配置,json数据"`
  130. }
  131. type ChartSaveItem struct {
  132. EdbInfoId int `description:"指标id"`
  133. MaxData float64 `description:"上限"`
  134. MinData float64 `description:"下限"`
  135. IsOrder bool `description:"true:正序,false:逆序"`
  136. IsAxis int `description:"1:左轴,0:右轴"`
  137. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  138. LeadValue int `description:"领先值"`
  139. LeadUnit string `description:"领先单位"`
  140. ChartStyle string `description:"图表类型"`
  141. ChartColor string `description:"颜色"`
  142. PredictChartColor string `description:"预测数据的颜色"`
  143. ChartWidth float64 `description:"线条大小"`
  144. Source int `description:"1:ETA图库;2:商品价格曲线"`
  145. }
  146. func DeleteChartInfoAndData(chartInfoId int) (err error) {
  147. o := orm.NewOrmUsingDB("data")
  148. to, err := o.Begin()
  149. if err != nil {
  150. return
  151. }
  152. defer func() {
  153. if err != nil {
  154. _ = to.Rollback()
  155. } else {
  156. _ = to.Commit()
  157. }
  158. }()
  159. sql := ` DELETE FROM chart_info WHERE chart_info_id=? `
  160. _, err = to.Raw(sql, chartInfoId).Exec()
  161. if err != nil {
  162. return
  163. }
  164. sql = ` DELETE FROM chart_edb_mapping WHERE chart_info_id=? `
  165. _, err = to.Raw(sql, chartInfoId).Exec()
  166. return
  167. }
  168. func GetChartInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  169. o := orm.NewOrmUsingDB("data")
  170. sql := ` SELECT COUNT(1) AS count FROM chart_info WHERE 1=1 `
  171. if condition != "" {
  172. sql += condition
  173. }
  174. err = o.Raw(sql, pars).QueryRow(&count)
  175. return
  176. }
  177. type EditChartInfoReq struct {
  178. ChartInfoId int `description:"图表ID"`
  179. ChartName string `description:"图表名称"`
  180. ChartClassifyId int `description:"分类id"`
  181. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  182. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图,10:截面散点图"`
  183. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  184. StartDate string `description:"自定义开始日期"`
  185. EndDate string `description:"自定义结束日期"`
  186. Calendar string `description:"公历/农历"`
  187. SeasonStartDate string `description:"季节性图开始日期"`
  188. SeasonEndDate string `description:"季节性图开始日期"`
  189. LeftMin string `description:"图表左侧最小值"`
  190. LeftMax string `description:"图表左侧最大值"`
  191. RightMin string `description:"图表右侧最小值"`
  192. RightMax string `description:"图表右侧最大值"`
  193. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  194. CorrelationChartInfo CorrelationChartInfoReq `description:"相关性图表配置"`
  195. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  196. }
  197. type EditChartEnInfoReq struct {
  198. ChartInfoId int `description:"图表ID"`
  199. ChartNameEn string `description:"英文图表名称"`
  200. ChartEdbInfoList []*EditChartEnInfoEdbItem `description:"指标及配置信息"`
  201. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  202. }
  203. type EditChartEnInfoEdbItem struct {
  204. EdbInfoId int `description:"指标ID"`
  205. EdbNameEn string `description:"英文指标名称"`
  206. UnitEn string `description:"英文单位"`
  207. }
  208. func ModifyChartInfo(item *EditChartInfoReq) (err error) {
  209. o := orm.NewOrmUsingDB("data")
  210. sql := ` UPDATE chart_info
  211. SET
  212. chart_name =?,
  213. chart_classify_id = ?,
  214. is_set_name=1,
  215. modify_time = NOW()
  216. WHERE chart_info_id = ?`
  217. _, err = o.Raw(sql, item.ChartName, item.ChartClassifyId, item.ChartInfoId).Exec()
  218. return
  219. }
  220. type ChartInfoList struct {
  221. ChartInfoId int `orm:"column(chart_info_id);pk"`
  222. ChartName string `description:"来源名称"`
  223. ChartChartClassifyId int `description:"图表分类id"`
  224. SysUserId int
  225. SysUserRealName string
  226. UniqueCode string `description:"图表唯一编码"`
  227. CreateTime time.Time
  228. ModifyTime time.Time
  229. EdbInfoList []*EdbInfoList
  230. }
  231. type ChartInfoListResp struct {
  232. Paging *paging.PagingItem
  233. Item *ChartInfoList
  234. }
  235. func GetChartInfoByCondition(condition string, pars []interface{}) (item *ChartInfo, err error) {
  236. o := orm.NewOrmUsingDB("data")
  237. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  238. if condition != "" {
  239. sql += condition
  240. }
  241. err = o.Raw(sql, pars).QueryRow(&item)
  242. return
  243. }
  244. func GetChartInfoByNewest(source int) (item *ChartInfoList, err error) {
  245. o := orm.NewOrmUsingDB("data")
  246. sql := ` SELECT * FROM chart_info WHERE 1=1 AND source = ? ORDER BY modify_time DESC LIMIT 1 `
  247. err = o.Raw(sql, source).QueryRow(&item)
  248. return
  249. }
  250. func ModifyChartInfoModifyTime(chartInfoId int64) (err error) {
  251. o := orm.NewOrmUsingDB("data")
  252. sql := ` UPDATE chart_info SET modify_time = NOW() WHERE chart_info_id = ? `
  253. _, err = o.Raw(sql, chartInfoId).Exec()
  254. return
  255. }
  256. type MoveChartInfoReq struct {
  257. ChartInfoId int `description:"图表ID"`
  258. PrevChartInfoId int `description:"上一个图表ID"`
  259. NextChartInfoId int `description:"下一个图表ID"`
  260. ChartClassifyId int `description:"分类id"`
  261. }
  262. func MoveChartInfo(chartInfoId, classifyId int) (err error) {
  263. o := orm.NewOrmUsingDB("data")
  264. sql := ` UPDATE chart_info
  265. SET
  266. chart_classify_id = ?
  267. WHERE chart_info_id = ?`
  268. _, err = o.Raw(sql, classifyId, chartInfoId).Exec()
  269. return
  270. }
  271. type DeleteChartInfoReq struct {
  272. ChartInfoId int `description:"图表ID"`
  273. }
  274. type EdbDataList struct {
  275. EdbDataId int `description:" 指标数据ID"`
  276. EdbInfoId int `description:"指标ID"`
  277. DataTime string //`json:"-" description:"数据日期"`
  278. DataTimestamp int64 `description:"数据日期"`
  279. Value float64 `description:"数据值"`
  280. }
  281. func GetEdbDataList(source, endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  282. tableName := GetEdbDataTableName(source)
  283. if tableName == "" {
  284. err = errors.New("无效的渠道:" + strconv.Itoa(source))
  285. list = make([]*EdbDataList, 0)
  286. return list, err
  287. }
  288. var pars []interface{}
  289. sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
  290. if startDate != "" {
  291. sql += ` AND data_time>=? `
  292. pars = append(pars, startDate)
  293. }
  294. if endDate != "" {
  295. sql += ` AND data_time<=? `
  296. pars = append(pars, endDate)
  297. }
  298. sql += ` ORDER BY data_time ASC `
  299. sql = fmt.Sprintf(sql, tableName)
  300. o := orm.NewOrmUsingDB("data")
  301. _, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
  302. return
  303. }
  304. type EdbDataListByUniqueCode struct {
  305. EdbDataId int `description:" 指标数据ID" json:"-"`
  306. EdbInfoId int `description:"指标ID" json:"-"`
  307. DataTime string //`json:"-" description:"数据日期"`
  308. DataTimestamp int64 `description:"数据日期"`
  309. Value float64 `description:"数据值"`
  310. }
  311. func GetEdbDataListByByUniqueCode(source, endInfoId int, startDate, endDate string) (list []*EdbDataListByUniqueCode, err error) {
  312. tableName := GetEdbDataTableName(source)
  313. if tableName == "" {
  314. err = errors.New("无效的渠道:" + strconv.Itoa(source))
  315. list = make([]*EdbDataListByUniqueCode, 0)
  316. return list, err
  317. }
  318. var pars []interface{}
  319. sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
  320. if startDate != "" {
  321. sql += ` AND data_time>=? `
  322. pars = append(pars, startDate)
  323. }
  324. if endDate != "" {
  325. sql += ` AND data_time<=? `
  326. pars = append(pars, endDate)
  327. }
  328. sql += ` ORDER BY data_time ASC `
  329. sql = fmt.Sprintf(sql, tableName)
  330. o := orm.NewOrmUsingDB("data")
  331. _, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
  332. return
  333. }
  334. func GetEdbDataLunarList(endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  335. tableName := "edb_data_quarter"
  336. sql := `SELECT edb_data_id,edb_info_id,data_time,TRUNCATE(value,2) AS value,data_timestamp FROM %s WHERE edb_info_id=? AND data_time>=? AND data_time<=? ORDER BY data_time ASC `
  337. sql = fmt.Sprintf(sql, tableName)
  338. o := orm.NewOrmUsingDB("data")
  339. _, err = o.Raw(sql, endInfoId, startDate, endDate).QueryRows(&list)
  340. return
  341. }
  342. func GetEdbDataListMinAndMax(source, endInfoId int, startDate, endDate string) (min_data, max_data float64, err error) {
  343. tableName := GetEdbDataTableName(source)
  344. sql := `SELECT min(value) AS min_data,max(value) AS max_data FROM %s WHERE edb_info_id=? `
  345. var pars []interface{}
  346. var condition string
  347. if startDate != "" {
  348. condition += ` AND data_time>=? `
  349. pars = append(pars, startDate)
  350. }
  351. if endDate != "" {
  352. condition += ` AND data_time<=? `
  353. pars = append(pars, endDate)
  354. }
  355. sql = fmt.Sprintf(sql, tableName)
  356. o := orm.NewOrmUsingDB("data")
  357. if condition != "" {
  358. sql += condition
  359. }
  360. err = o.Raw(sql, endInfoId, pars).QueryRow(&min_data, &max_data)
  361. return
  362. }
  363. type ChartEdbInfoMapping struct {
  364. EdbInfoId int `description:"指标id"`
  365. SourceName string `description:"来源名称"`
  366. Source int `description:"来源id"`
  367. EdbCode string `description:"指标编码"`
  368. EdbName string `description:"指标名称"`
  369. EdbAliasName string `description:"指标名称(别名)"`
  370. EdbNameEn string `description:"英文指标名称"`
  371. EdbAliasNameEn string `description:"英文指标名称(别名)"`
  372. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  373. Frequency string `description:"频率"`
  374. FrequencyEn string `description:"英文频率"`
  375. Unit string `description:"单位"`
  376. UnitEn string `description:"英文单位"`
  377. StartDate string `description:"起始日期"`
  378. EndDate string `description:"终止日期"`
  379. ModifyTime string `description:"指标最后更新时间"`
  380. ChartEdbMappingId int `description:"图表指标id"`
  381. ChartInfoId int `description:"图表id"`
  382. MaxData float64 `description:"上限"`
  383. MinData float64 `description:"下限"`
  384. IsOrder bool `description:"true:正序,false:逆序"`
  385. IsAxis int `description:"1:左轴,0:右轴"`
  386. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  387. EdbInfoCategoryType int `description:"0:普通指标,1:预测指标"`
  388. LeadValue int `description:"领先值"`
  389. LeadUnit string `description:"领先单位"`
  390. LeadUnitEn string `description:"领先英文单位"`
  391. ChartStyle string `description:"图表类型"`
  392. ChartColor string `description:"颜色"`
  393. PredictChartColor string `description:"预测数据的颜色"`
  394. ChartWidth float64 `description:"线条大小"`
  395. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图"`
  396. LatestDate string `description:"数据最新日期"`
  397. LatestValue float64 `description:"数据最新值"`
  398. UniqueCode string `description:"指标唯一编码"`
  399. MinValue float64 `json:"-" description:"最小值"`
  400. MaxValue float64 `json:"-" description:"最大值"`
  401. DataList interface{}
  402. IsNullData bool `json:"-" description:"是否空数据"`
  403. MappingSource int `description:"1:ETA图库;2:商品价格曲线"`
  404. RegionType string `description:"交易所来源,海外还是国内" json:"-"`
  405. ClassifyId int `description:"分类id"`
  406. }
  407. type QuarterData struct {
  408. Year int
  409. DataList []*EdbDataList
  410. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  411. }
  412. type QuarterDataByUniqueCode struct {
  413. Year int
  414. DataList []*EdbDataListByUniqueCode
  415. }
  416. type ChartEdbInfoDetailResp struct {
  417. EdbInfo *ChartEdbInfoMapping
  418. }
  419. type ChartInfoDetailResp struct {
  420. ChartInfo *ChartInfoView
  421. EdbInfoList []*ChartEdbInfoMapping
  422. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  423. YDataList []YData `description:"柱方图的y轴数据"`
  424. XDataList []XData `description:"商品价格曲线的X轴数据"`
  425. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  426. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  427. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  428. }
  429. // XData 商品价格曲线的的x轴数据
  430. type XData struct {
  431. Name string `description:"别名"`
  432. NameEn string `description:"英文别名"`
  433. }
  434. // YData 柱方图的y轴数据
  435. type YData struct {
  436. Date string `description:"数据日期"`
  437. ConfigDate time.Time `description:"配置的日期" json:"-"`
  438. Color string `description:"数据颜色"`
  439. Name string `description:"别名"`
  440. NameEn string `description:"英文别名"`
  441. Value []float64 `description:"每个指标的值"`
  442. NoDataEdbList []int `description:"没有数据的指标列表"`
  443. XEdbInfoIdList []int `description:"对应X轴的指标id列表"`
  444. EdbValMap map[int]float64 `description:"指标与值的对应" json:"-"`
  445. M []int `description:"对应开始日期的间隔值" json:"-"`
  446. }
  447. func ModifyChartInfoAndMapping(edbInfoIdStr string, req *SaveChartInfoReq, chartType int) (err error) {
  448. o := orm.NewOrmUsingDB("data")
  449. to, err := o.Begin()
  450. if err != nil {
  451. return
  452. }
  453. defer func() {
  454. if err != nil {
  455. _ = to.Rollback()
  456. } else {
  457. _ = to.Commit()
  458. }
  459. }()
  460. //非季节图
  461. if chartType != 2 {
  462. updateStr := `edb_info_ids=?,
  463. modify_time = NOW(),
  464. date_type=?,
  465. start_date=?,
  466. end_date=?,
  467. left_min=?,
  468. left_max=?,
  469. right_min=?,
  470. right_max=?`
  471. pars := []interface{}{edbInfoIdStr, req.DateType, req.StartDate, req.EndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax}
  472. if req.ExtraConfig != `` {
  473. updateStr += `,extra_config=? `
  474. pars = append(pars, req.ExtraConfig)
  475. }
  476. pars = append(pars, req.ChartInfoId)
  477. sql := ` UPDATE chart_info SET ` + updateStr + ` WHERE chart_info_id = ?`
  478. _, err = to.Raw(sql, pars).Exec()
  479. if err != nil {
  480. fmt.Println("UPDATE chart_info Err:", err.Error())
  481. return err
  482. }
  483. } else {
  484. sql := ` UPDATE chart_info
  485. SET
  486. edb_info_ids=?,
  487. modify_time = NOW(),
  488. calendar=?,
  489. season_start_date=?,
  490. season_end_date=?,
  491. left_min=?,
  492. left_max=?,
  493. right_min=?,
  494. right_max=?
  495. WHERE chart_info_id = ?`
  496. _, err = to.Raw(sql, edbInfoIdStr, req.Calendar, req.SeasonStartDate, req.SeasonEndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax, req.ChartInfoId).Exec()
  497. if err != nil {
  498. fmt.Println("UPDATE chart_info Err:", err.Error())
  499. return err
  500. }
  501. }
  502. var edbInfoIdArr []string
  503. mapList := make([]*ChartEdbMapping, 0)
  504. for _, v := range req.ChartEdbInfoList {
  505. edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
  506. var count int
  507. csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
  508. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
  509. if err != nil {
  510. fmt.Println("QueryRow Err:", err.Error())
  511. return err
  512. }
  513. if count > 0 {
  514. msql := `UPDATE chart_edb_mapping
  515. SET
  516. modify_time = NOW(),
  517. max_data = ?,
  518. min_data = ?,
  519. is_order = ?,
  520. is_axis = ?,
  521. edb_info_type = ?,
  522. lead_value = ?,
  523. lead_unit = ?,
  524. chart_style = ?,
  525. chart_color = ?,
  526. predict_chart_color = ?,
  527. chart_width = ?
  528. WHERE chart_info_id =? AND edb_info_id=? `
  529. _, err = to.Raw(msql, v.MaxData, v.MinData, v.IsOrder, v.IsAxis, v.EdbInfoType, v.LeadValue, v.LeadUnit, v.ChartStyle, v.ChartColor, v.PredictChartColor, v.ChartWidth, req.ChartInfoId, v.EdbInfoId).Exec()
  530. if err != nil {
  531. fmt.Println("chart_edb_mapping Err:" + err.Error())
  532. return err
  533. }
  534. } else {
  535. mapItem := new(ChartEdbMapping)
  536. mapItem.ChartInfoId = req.ChartInfoId
  537. mapItem.EdbInfoId = v.EdbInfoId
  538. mapItem.CreateTime = time.Now()
  539. mapItem.ModifyTime = time.Now()
  540. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  541. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
  542. mapItem.MaxData = v.MaxData
  543. mapItem.MinData = v.MinData
  544. mapItem.IsOrder = v.IsOrder
  545. mapItem.IsAxis = v.IsAxis
  546. mapItem.EdbInfoType = v.EdbInfoType
  547. mapItem.LeadValue = v.LeadValue
  548. mapItem.LeadUnit = v.LeadUnit
  549. mapItem.ChartStyle = v.ChartStyle
  550. mapItem.ChartColor = v.ChartColor
  551. mapItem.PredictChartColor = v.PredictChartColor
  552. mapItem.ChartWidth = v.ChartWidth
  553. mapList = append(mapList, mapItem)
  554. }
  555. }
  556. if len(mapList) > 0 {
  557. _, err = to.InsertMulti(1, mapList)
  558. if err != nil {
  559. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  560. return err
  561. }
  562. }
  563. if len(edbInfoIdArr) > 0 {
  564. edbInfoIdStr := strings.Join(edbInfoIdArr, ",")
  565. if edbInfoIdStr != "" {
  566. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id NOT IN(` + edbInfoIdStr + `)`
  567. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  568. if err != nil {
  569. fmt.Println("delete err:" + err.Error())
  570. return err
  571. }
  572. }
  573. }
  574. return
  575. }
  576. // EditChartInfoAndMapping 修改 ETA图库 的 图表与指标 的关系
  577. func EditChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string, chartEdbInfoList []*ChartSaveItem) (err error) {
  578. o := orm.NewOrmUsingDB("data")
  579. to, err := o.Begin()
  580. if err != nil {
  581. return
  582. }
  583. defer func() {
  584. if err != nil {
  585. _ = to.Rollback()
  586. } else {
  587. _ = to.Commit()
  588. }
  589. }()
  590. var pars []interface{}
  591. pars = append(pars, req.ChartName)
  592. pars = append(pars, edbInfoIdStr)
  593. pars = append(pars, req.ChartType)
  594. pars = append(pars, req.ChartClassifyId)
  595. pars = append(pars, disabled)
  596. pars = append(pars, barChartConf)
  597. pars = append(pars, req.ExtraConfig)
  598. sql := ` UPDATE chart_info
  599. SET
  600. chart_name =?,
  601. edb_info_ids=?,
  602. chart_type=?,
  603. chart_classify_id = ?,
  604. modify_time = NOW(),
  605. disabled = ?,
  606. bar_config = ?,extra_config = ?
  607. `
  608. if calendar != "" {
  609. sql += `,calendar = ? `
  610. pars = append(pars, calendar)
  611. }
  612. if dateType > 0 {
  613. sql += `,date_type = ? `
  614. pars = append(pars, dateType)
  615. }
  616. sql += `,start_date = ? `
  617. pars = append(pars, req.StartDate)
  618. sql += `,end_date = ? `
  619. pars = append(pars, req.EndDate)
  620. sql += `,season_start_date = ? `
  621. pars = append(pars, req.SeasonStartDate)
  622. sql += `,season_end_date = ? `
  623. pars = append(pars, req.SeasonEndDate)
  624. sql += `,left_min = ? `
  625. pars = append(pars, req.LeftMin)
  626. sql += `,left_max = ? `
  627. pars = append(pars, req.LeftMax)
  628. sql += `,right_min = ? `
  629. pars = append(pars, req.RightMin)
  630. sql += `,right_max = ? `
  631. pars = append(pars, req.RightMax)
  632. sql += `WHERE chart_info_id = ?`
  633. pars = append(pars, req.ChartInfoId)
  634. _, err = to.Raw(sql, pars).Exec()
  635. if err != nil {
  636. fmt.Println("UPDATE chart_info Err:", err.Error())
  637. return err
  638. }
  639. chartEdbMappingIdList := make([]string, 0)
  640. for _, v := range chartEdbInfoList {
  641. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  642. var tmpChartEdbMapping *ChartEdbMapping
  643. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  644. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, utils.CHART_SOURCE_DEFAULT).QueryRow(&tmpChartEdbMapping)
  645. if err != nil && err.Error() != utils.ErrNoRow() {
  646. fmt.Println("QueryRow Err:", err.Error())
  647. return err
  648. }
  649. if tmpChartEdbMapping != nil {
  650. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  651. tmpChartEdbMapping.ModifyTime = time.Now()
  652. tmpChartEdbMapping.MaxData = v.MaxData
  653. tmpChartEdbMapping.MinData = v.MinData
  654. tmpChartEdbMapping.IsOrder = v.IsOrder
  655. tmpChartEdbMapping.IsAxis = v.IsAxis
  656. tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  657. tmpChartEdbMapping.LeadValue = v.LeadValue
  658. tmpChartEdbMapping.LeadUnit = v.LeadUnit
  659. tmpChartEdbMapping.ChartStyle = v.ChartStyle
  660. tmpChartEdbMapping.ChartColor = v.ChartColor
  661. tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  662. tmpChartEdbMapping.ChartWidth = v.ChartWidth
  663. _, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  664. if err != nil {
  665. fmt.Println("chart_edb_mapping Err:" + err.Error())
  666. return err
  667. }
  668. } else {
  669. mapItem := new(ChartEdbMapping)
  670. mapItem.ChartInfoId = req.ChartInfoId
  671. mapItem.EdbInfoId = v.EdbInfoId
  672. mapItem.CreateTime = time.Now()
  673. mapItem.ModifyTime = time.Now()
  674. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  675. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  676. mapItem.MaxData = v.MaxData
  677. mapItem.MinData = v.MinData
  678. mapItem.IsOrder = v.IsOrder
  679. mapItem.IsAxis = v.IsAxis
  680. mapItem.EdbInfoType = v.EdbInfoType
  681. mapItem.LeadValue = v.LeadValue
  682. mapItem.LeadUnit = v.LeadUnit
  683. mapItem.ChartStyle = v.ChartStyle
  684. mapItem.ChartColor = v.ChartColor
  685. mapItem.PredictChartColor = v.PredictChartColor
  686. mapItem.ChartWidth = v.ChartWidth
  687. mapItem.Source = utils.CHART_SOURCE_DEFAULT
  688. tmpId, err := to.Insert(mapItem)
  689. if err != nil {
  690. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  691. return err
  692. }
  693. mapItem.ChartEdbMappingId = int(tmpId)
  694. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  695. }
  696. }
  697. if len(chartEdbMappingIdList) > 0 {
  698. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  699. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  700. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  701. if err != nil {
  702. fmt.Println("delete err:" + err.Error())
  703. return err
  704. }
  705. }
  706. return
  707. }
  708. // EditFutureGoodChartInfoAndMapping 修改商品价格曲线的 图表与指标 的关系
  709. func EditFutureGoodChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string) (err error) {
  710. o := orm.NewOrmUsingDB("data")
  711. to, err := o.Begin()
  712. if err != nil {
  713. return
  714. }
  715. defer func() {
  716. if err != nil {
  717. _ = to.Rollback()
  718. } else {
  719. _ = to.Commit()
  720. }
  721. }()
  722. var pars []interface{}
  723. pars = append(pars, req.ChartName)
  724. pars = append(pars, edbInfoIdStr)
  725. pars = append(pars, req.ChartType)
  726. pars = append(pars, req.ChartClassifyId)
  727. pars = append(pars, disabled)
  728. pars = append(pars, barChartConf)
  729. sql := ` UPDATE chart_info
  730. SET
  731. chart_name =?,
  732. edb_info_ids=?,
  733. chart_type=?,
  734. chart_classify_id = ?,
  735. modify_time = NOW(),
  736. disabled = ?,
  737. bar_config = ?
  738. `
  739. if calendar != "" {
  740. sql += `,calendar = ? `
  741. pars = append(pars, calendar)
  742. }
  743. if dateType > 0 {
  744. sql += `,date_type = ? `
  745. pars = append(pars, dateType)
  746. }
  747. sql += `,start_date = ? `
  748. pars = append(pars, req.StartDate)
  749. sql += `,end_date = ? `
  750. pars = append(pars, req.EndDate)
  751. sql += `,season_start_date = ? `
  752. pars = append(pars, req.SeasonStartDate)
  753. sql += `,season_end_date = ? `
  754. pars = append(pars, req.SeasonEndDate)
  755. sql += `,left_min = ? `
  756. pars = append(pars, req.LeftMin)
  757. sql += `,left_max = ? `
  758. pars = append(pars, req.LeftMax)
  759. sql += `,right_min = ? `
  760. pars = append(pars, req.RightMin)
  761. sql += `,right_max = ? `
  762. pars = append(pars, req.RightMax)
  763. sql += `WHERE chart_info_id = ?`
  764. pars = append(pars, req.ChartInfoId)
  765. _, err = to.Raw(sql, pars).Exec()
  766. if err != nil {
  767. fmt.Println("UPDATE chart_info Err:", err.Error())
  768. return err
  769. }
  770. chartEdbMappingIdList := make([]string, 0)
  771. for _, v := range req.BarChartInfo.EdbInfoIdList {
  772. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  773. var tmpChartEdbMapping *ChartEdbMapping
  774. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  775. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, v.Source).QueryRow(&tmpChartEdbMapping)
  776. if err != nil && err.Error() != utils.ErrNoRow() {
  777. fmt.Println("QueryRow Err:", err.Error())
  778. return err
  779. }
  780. if tmpChartEdbMapping != nil {
  781. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  782. //tmpChartEdbMapping.ModifyTime = time.Now()
  783. //tmpChartEdbMapping.MaxData = v.MaxData
  784. //tmpChartEdbMapping.MinData = v.MinData
  785. //tmpChartEdbMapping.IsOrder = v.IsOrder
  786. //tmpChartEdbMapping.IsAxis = v.IsAxis
  787. //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  788. //tmpChartEdbMapping.LeadValue = v.LeadValue
  789. //tmpChartEdbMapping.LeadUnit = v.LeadUnit
  790. //tmpChartEdbMapping.ChartStyle = v.ChartStyle
  791. //tmpChartEdbMapping.ChartColor = v.ChartColor
  792. //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  793. //tmpChartEdbMapping.ChartWidth = v.ChartWidth
  794. //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  795. //if err != nil {
  796. // fmt.Println("chart_edb_mapping Err:" + err.Error())
  797. // return err
  798. //}
  799. } else {
  800. mapItem := new(ChartEdbMapping)
  801. mapItem.ChartInfoId = req.ChartInfoId
  802. mapItem.EdbInfoId = v.EdbInfoId
  803. mapItem.CreateTime = time.Now()
  804. mapItem.ModifyTime = time.Now()
  805. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  806. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  807. //mapItem.MaxData = v.MaxData
  808. //mapItem.MinData = v.MinData
  809. mapItem.IsOrder = true
  810. mapItem.IsAxis = 1
  811. mapItem.EdbInfoType = 1
  812. //mapItem.LeadValue = v.LeadValue
  813. //mapItem.LeadUnit = v.LeadUnit
  814. //mapItem.ChartStyle = v.ChartStyle
  815. //mapItem.ChartColor = v.ChartColor
  816. //mapItem.PredictChartColor = v.PredictChartColor
  817. //mapItem.ChartWidth = v.ChartWidth
  818. mapItem.Source = v.Source
  819. tmpId, err := to.Insert(mapItem)
  820. if err != nil {
  821. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  822. return err
  823. }
  824. mapItem.ChartEdbMappingId = int(tmpId)
  825. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  826. }
  827. }
  828. if len(chartEdbMappingIdList) > 0 {
  829. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  830. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  831. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  832. if err != nil {
  833. fmt.Println("delete err:" + err.Error())
  834. return err
  835. }
  836. }
  837. return
  838. }
  839. func EditChartEnInfoAndEdbEnInfo(req *EditChartEnInfoReq) (err error) {
  840. o := orm.NewOrmUsingDB("data")
  841. to, err := o.Begin()
  842. if err != nil {
  843. return
  844. }
  845. defer func() {
  846. if err != nil {
  847. _ = to.Rollback()
  848. } else {
  849. _ = to.Commit()
  850. }
  851. }()
  852. var pars []interface{}
  853. updateField := ` chart_name_en =?, `
  854. pars = append(pars, req.ChartNameEn)
  855. if req.ExtraConfig != `` {
  856. updateField += ` extra_config =?, `
  857. pars = append(pars, req.ExtraConfig)
  858. }
  859. sql := ` UPDATE chart_info
  860. SET ` + updateField + ` modify_time = NOW()
  861. WHERE chart_info_id = ?`
  862. pars = append(pars, req.ChartInfoId)
  863. _, err = to.Raw(sql, pars).Exec()
  864. if err != nil {
  865. fmt.Println("UPDATE chart_info Err:", err.Error())
  866. return err
  867. }
  868. var edbInfoIdArr []string
  869. for _, v := range req.ChartEdbInfoList {
  870. edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
  871. var count int
  872. csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
  873. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
  874. if err != nil {
  875. fmt.Println("QueryRow Err:", err.Error())
  876. return err
  877. }
  878. if count > 0 {
  879. msql := ` UPDATE edb_info
  880. SET
  881. edb_name_en =?,
  882. unit_en = ?,
  883. modify_time = NOW()
  884. WHERE edb_info_id = ? `
  885. _, err = to.Raw(msql, v.EdbNameEn, v.UnitEn, v.EdbInfoId).Exec()
  886. if err != nil {
  887. fmt.Println("edb_info Err:" + err.Error())
  888. return err
  889. }
  890. }
  891. }
  892. return
  893. }
  894. func ModifyEdbDatadTimestamp(source, edbDataId int, dataTimestamp int64) (err error) {
  895. tableName := GetEdbDataTableName(source)
  896. sql := `UPDATE %s SET data_timestamp=? WHERE edb_data_id=? `
  897. sql = fmt.Sprintf(sql, tableName)
  898. o := orm.NewOrmUsingDB("data")
  899. _, err = o.Raw(sql, dataTimestamp, edbDataId).Exec()
  900. return
  901. }
  902. type AddChartInfoReq struct {
  903. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  904. ChartClassifyId int `description:"分类id"`
  905. ChartName string `description:"图表名称"`
  906. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图"`
  907. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  908. StartDate string `description:"自定义开始日期"`
  909. EndDate string `description:"自定义结束日期"`
  910. Calendar string `description:"公历/农历"`
  911. SeasonStartDate string `description:"季节性图开始日期"`
  912. SeasonEndDate string `description:"季节性图开始日期"`
  913. LeftMin string `description:"图表左侧最小值"`
  914. LeftMax string `description:"图表左侧最大值"`
  915. RightMin string `description:"图表右侧最小值"`
  916. RightMax string `description:"图表右侧最大值"`
  917. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  918. CorrelationChartInfo CorrelationChartInfoReq `description:"相关性图表配置"`
  919. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  920. }
  921. type AddChartInfoResp struct {
  922. ChartInfoId int `description:"图表id"`
  923. UniqueCode string `description:"图表唯一编码"`
  924. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  925. }
  926. // 判断图表指标是否已经存在
  927. func ChartInfoExist(condition, edbInfoIdStr string) (count int, err error) {
  928. sql := `SELECT COUNT(1) AS count FROM (
  929. SELECT GROUP_CONCAT(edb_info_id ORDER BY edb_info_id ASC SEPARATOR ',') AS edb_info_id_str
  930. FROM chart_edb_mapping AS a
  931. WHERE 1=1`
  932. if condition != "" {
  933. sql += condition
  934. }
  935. sql += ` GROUP BY chart_info_id
  936. )AS t
  937. WHERE t.edb_info_id_str=?
  938. GROUP BY t.edb_info_id_str `
  939. o := orm.NewOrmUsingDB("data")
  940. err = o.Raw(sql, edbInfoIdStr).QueryRow(&count)
  941. return
  942. }
  943. func ChartInfoSearchByKeyWord(KeyWord string, showSysId int) (searchList []*ChartInfo, err error) {
  944. o := orm.NewOrmUsingDB("data")
  945. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  946. var pars []interface{}
  947. if KeyWord != "" {
  948. sql += `AND chart_name LIKE ? `
  949. pars = append(pars, "%"+KeyWord+"%")
  950. }
  951. if showSysId > 0 {
  952. sql += ` AND sys_user_id = ? `
  953. pars = append(pars, showSysId)
  954. }
  955. sql += ` ORDER BY create_time DESC `
  956. if KeyWord == "" {
  957. sql += ` LIMIT 100 `
  958. }
  959. _, err = o.Raw(sql, pars).QueryRows(&searchList)
  960. return
  961. }
  962. // ChartInfoSearchByEmptyKeyWord 没有关键字的时候获取默认100条数据
  963. func ChartInfoSearchByEmptyKeyWord(showSysId int, sourceList []int, noPermissionChartIdList []int) (total int64, searchList []*ChartInfo, err error) {
  964. num := len(sourceList)
  965. o := orm.NewOrmUsingDB("data")
  966. sql := ` SELECT * FROM chart_info WHERE 1=1 AND source in (` + utils.GetOrmInReplace(num) + `)`
  967. var pars []interface{}
  968. pars = append(pars, sourceList)
  969. if showSysId > 0 {
  970. sql += ` AND sys_user_id = ? `
  971. pars = append(pars, showSysId)
  972. }
  973. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  974. if lenNoPermissionChartIdList > 0 {
  975. sql += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  976. pars = append(pars, noPermissionChartIdList)
  977. }
  978. sql += ` ORDER BY create_time DESC LIMIT 100 `
  979. total, err = o.Raw(sql, pars).QueryRows(&searchList)
  980. return
  981. }
  982. func GetNextChartInfo(classifyId int) (item *ChartInfo, err error) {
  983. o := orm.NewOrmUsingDB("data")
  984. sql := ` SELECT b.* FROM chart_classify AS a
  985. INNER JOIN chart_info AS b ON a.chart_classify_id=b.chart_classify_id
  986. WHERE a.chart_classify_id>?
  987. ORDER BY a.chart_classify_id ASC
  988. LIMIT 1 `
  989. err = o.Raw(sql, classifyId).QueryRow(&item)
  990. return
  991. }
  992. // GetChartInfoRefreshData 获取图表关联的指标信息
  993. func GetChartInfoRefreshData(chartInfoId int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  994. o := orm.NewOrmUsingDB("data")
  995. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  996. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  997. WHERE a.chart_info_id=? `
  998. edbInfoList := make([]*EdbInfo, 0)
  999. _, err = o.Raw(sql, chartInfoId).QueryRows(&edbInfoList)
  1000. if err != nil {
  1001. return
  1002. }
  1003. for _, v := range edbInfoList {
  1004. fmt.Println(v.EdbInfoId, v.EdbType)
  1005. if v.EdbType == 1 {
  1006. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1007. } else {
  1008. calculateInfoArr = append(calculateInfoArr, v)
  1009. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  1010. if err != nil {
  1011. return baseEdbInfoArr, calculateInfoArr, err
  1012. }
  1013. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1014. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1015. }
  1016. }
  1017. return
  1018. }
  1019. func GetChartRefreshEdbInfo(edbInfoId, source, n int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1020. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  1021. if err != nil && err.Error() != utils.ErrNoRow() {
  1022. return
  1023. }
  1024. n++
  1025. for _, item := range calculateList {
  1026. fmt.Println(item.EdbInfoId)
  1027. if item.EdbType == 1 {
  1028. baseEdbInfoArr = append(baseEdbInfoArr, item)
  1029. } else {
  1030. calculateInfoArr = append(calculateInfoArr, item)
  1031. if n > 10 {
  1032. return
  1033. }
  1034. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetChartRefreshEdbInfo(item.EdbInfoId, item.Source, n)
  1035. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1036. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1037. }
  1038. }
  1039. return
  1040. }
  1041. type SetChartInfoImageReq struct {
  1042. ChartInfoId int `description:"图表ID"`
  1043. ImageUrl string `description:"图表图片地址"`
  1044. }
  1045. func EditChartInfoImage(req *SetChartInfoImageReq) (err error) {
  1046. o := orm.NewOrmUsingDB("data")
  1047. sql := ` UPDATE chart_info SET chart_image=?, modify_time = NOW() WHERE chart_info_id = ? `
  1048. _, err = o.Raw(sql, req.ImageUrl, req.ChartInfoId).Exec()
  1049. if err != nil {
  1050. fmt.Println("EditChartInfoImage Err:", err.Error())
  1051. return err
  1052. }
  1053. return
  1054. }
  1055. type ChartInfoDetailFromUniqueCodeResp struct {
  1056. ChartInfo *ChartInfoView
  1057. Status bool `description:"true:图表存在,false:图表不存在"`
  1058. EdbInfoList []*ChartEdbInfoMapping
  1059. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  1060. YDataList []YData `description:"柱方图的y轴数据"`
  1061. XDataList []XData `description:"商品价格曲线的X轴数据"`
  1062. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  1063. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  1064. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  1065. }
  1066. func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
  1067. o := orm.NewOrmUsingDB("data")
  1068. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  1069. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  1070. return
  1071. }
  1072. func GetChartInfoViewByUniqueCode(uniqueCode string) (item *ChartInfoView, err error) {
  1073. o := orm.NewOrmUsingDB("data")
  1074. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  1075. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  1076. return
  1077. }
  1078. // GetFirstChartInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  1079. func GetFirstChartInfoByClassifyId(classifyId int) (item *ChartInfo, err error) {
  1080. o := orm.NewOrmUsingDB("data")
  1081. sql := ` SELECT * FROM chart_info WHERE chart_classify_id=? order by sort asc,chart_info_id asc limit 1`
  1082. err = o.Raw(sql, classifyId).QueryRow(&item)
  1083. return
  1084. }
  1085. // UpdateChartInfoSortByClassifyId 根据图表id更新排序
  1086. func UpdateChartInfoSortByClassifyId(classifyId, nowSort, prevChartInfoId, source int, updateSort string) (err error) {
  1087. o := orm.NewOrmUsingDB("data")
  1088. sql := ` update chart_info set sort = ` + updateSort + ` WHERE chart_classify_id=? AND source = ? AND `
  1089. if prevChartInfoId > 0 {
  1090. sql += ` (sort > ? or (chart_info_id > ` + fmt.Sprint(prevChartInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  1091. }
  1092. _, err = o.Raw(sql, classifyId, source, nowSort).Exec()
  1093. return
  1094. }
  1095. // Update 更新图表基础信息
  1096. func (chartInfo *ChartInfo) Update(cols []string) (err error) {
  1097. o := orm.NewOrmUsingDB("data")
  1098. _, err = o.Update(chartInfo, cols...)
  1099. return
  1100. }
  1101. type ChartInfoView struct {
  1102. ChartInfoId int `orm:"column(chart_info_id);pk"`
  1103. ChartName string `description:"来源名称"`
  1104. ChartNameEn string `description:"英文图表名称"`
  1105. UnitEn string `description:"英文单位名称"`
  1106. ChartClassifyId int `description:"图表分类id"`
  1107. ChartClassifyName string `description:"图表名称"`
  1108. SysUserId int
  1109. SysUserRealName string
  1110. UniqueCode string `description:"图表唯一编码"`
  1111. CreateTime time.Time
  1112. ModifyTime time.Time
  1113. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  1114. StartDate string `description:"自定义开始日期"`
  1115. EndDate string `description:"自定义结束日期"`
  1116. IsSetName int `description:"设置名称"`
  1117. EdbInfoIds string `description:"指标id"`
  1118. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  1119. Calendar string `description:"公历/农历"`
  1120. SeasonStartDate string `description:"季节性图开始日期"`
  1121. SeasonEndDate string `description:"季节性图开始日期"`
  1122. ChartImage string `description:"图表图片"`
  1123. Sort int `description:"排序字段,数字越小越排前面"`
  1124. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1125. MyChartId int
  1126. MyChartClassifyId string `description:"我的图表分类,多个用逗号隔开"`
  1127. ChartClassify []*ChartClassifyView
  1128. EdbEndDate string `description:"指标最新更新日期"`
  1129. LeftMin string `description:"图表左侧最小值"`
  1130. LeftMax string `description:"图表左侧最大值"`
  1131. RightMin string `description:"图表右侧最小值"`
  1132. RightMax string `description:"图表右侧最大值"`
  1133. IsEdit bool `description:"是否有编辑权限"`
  1134. IsEnChart bool `description:"是否展示英文标识"`
  1135. WarnMsg string `description:"错误信息"`
  1136. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  1137. BarConfig string `description:"柱方图的配置,json数据" json:"-"`
  1138. Source int `description:"1:ETA图库;2:商品价格曲线;3:相关性图表"`
  1139. //CorrelationLeadUnit string `description:"相关性图表-领先单位"`
  1140. ExtraConfig string `description:"图表额外配置,json数据"`
  1141. Button ChartViewButton `description:"操作按钮"`
  1142. }
  1143. type ChartViewButton struct {
  1144. IsEdit bool `description:"是否有编辑权限"`
  1145. IsEnChart bool `description:"是否展示英文标识"`
  1146. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1147. IsCopy bool `description:"是否有另存为按钮"`
  1148. IsSetName int `description:"设置名称"`
  1149. }
  1150. type ImageSvgToPngResp struct {
  1151. Data struct {
  1152. ResourceURL string `json:"ResourceUrl"`
  1153. } `json:"Data"`
  1154. ErrCode string `json:"ErrCode"`
  1155. ErrMsg string `json:"ErrMsg"`
  1156. IsSendEmail bool `json:"IsSendEmail"`
  1157. Msg string `json:"Msg"`
  1158. Ret int64 `json:"Ret"`
  1159. Success bool `json:"Success"`
  1160. }
  1161. // GetChartInfoByClassifyIdAndName 根据分类id和图表名获取图表信息
  1162. func GetChartInfoByClassifyIdAndName(classifyId int, chartName string) (item *ChartInfo, err error) {
  1163. o := orm.NewOrmUsingDB("data")
  1164. sql := ` SELECT * FROM chart_info WHERE chart_classify_id = ? and chart_name=? `
  1165. err = o.Raw(sql, classifyId, chartName).QueryRow(&item)
  1166. return
  1167. }
  1168. // BatchChartRefreshReq 批量刷新图表请求
  1169. type BatchChartRefreshReq struct {
  1170. ChartInfoCode []string `description:"图表编码数组"`
  1171. }
  1172. // GetChartInfoListByUniqueCodeSlice 根据图表编码获取图表列表数据
  1173. func GetChartInfoListByUniqueCodeSlice(uniqueCodeSlice []string) (total int64, items []*ChartInfo, err error) {
  1174. if len(uniqueCodeSlice) <= 0 {
  1175. return
  1176. }
  1177. o := orm.NewOrmUsingDB("data")
  1178. sql := ` SELECT * FROM chart_info WHERE unique_code in ("` + strings.Join(uniqueCodeSlice, `","`) + `") `
  1179. total, err = o.Raw(sql).QueryRows(&items)
  1180. return
  1181. }
  1182. // GetChartInfoRefreshDataByChartInfoIdSlice 根据图表id切片获取对应的指标数据
  1183. func GetChartInfoRefreshDataByChartInfoIdSlice(chartInfoIdSlice []string) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1184. o := orm.NewOrmUsingDB("data")
  1185. if len(chartInfoIdSlice) <= 0 {
  1186. return
  1187. }
  1188. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  1189. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  1190. WHERE a.chart_info_id in (` + strings.Join(chartInfoIdSlice, ",") + `) `
  1191. edbInfoList := make([]*EdbInfo, 0)
  1192. _, err = o.Raw(sql).QueryRows(&edbInfoList)
  1193. if err != nil {
  1194. return
  1195. }
  1196. for _, v := range edbInfoList {
  1197. if v.EdbType == 1 {
  1198. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1199. } else {
  1200. calculateInfoArr = append(calculateInfoArr, v)
  1201. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  1202. if err != nil {
  1203. return baseEdbInfoArr, calculateInfoArr, err
  1204. }
  1205. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1206. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1207. }
  1208. }
  1209. return
  1210. }
  1211. // CopyAddChartInfoReq 复制并新增图表
  1212. type CopyAddChartInfoReq struct {
  1213. ChartInfoId int `description:"待复制的图表id"`
  1214. ChartClassifyId int `description:"分类id"`
  1215. ChartName string `description:"图表名称"`
  1216. }
  1217. // ChartInfoListByEsResp 图表数据Es搜索返回
  1218. type ChartInfoListByEsResp struct {
  1219. Paging *paging.PagingItem
  1220. List []*ChartInfoMore
  1221. }
  1222. // GetChartInfoListByCondition 根据条件获取图表数据了列表
  1223. func GetChartInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ChartInfo, err error) {
  1224. o := orm.NewOrmUsingDB("data")
  1225. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  1226. if condition != "" {
  1227. sql += condition
  1228. }
  1229. sql += ` ORDER BY chart_info_id DESC LIMIT ?,? `
  1230. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1231. return
  1232. }
  1233. // GetChartInfoListGroupByUserId 根据指标id列表、用户分组获取指标信息
  1234. func GetChartInfoListGroupByUserId(edbIdList []string) (items []*ChartInfo, err error) {
  1235. num := len(edbIdList)
  1236. if num <= 0 {
  1237. return
  1238. }
  1239. o := orm.NewOrmUsingDB("data")
  1240. sql := ` SELECT * FROM chart_info WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY sys_user_id `
  1241. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  1242. return
  1243. }
  1244. // ModifyChartInfoUserIdByCodeList 根据指标code列表修改创建人
  1245. func ModifyChartInfoUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  1246. num := len(edbIdList)
  1247. if num <= 0 {
  1248. return
  1249. }
  1250. o := orm.NewOrmUsingDB("data")
  1251. sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1252. _, err = o.Raw(sql, userId, userName, edbIdList).Exec()
  1253. return
  1254. }
  1255. // BarChartInfoReq 柱方图预览请求数据
  1256. type BarChartInfoReq struct {
  1257. EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
  1258. DateList []BarChartInfoDateReq `description:"日期配置"`
  1259. Sort BarChartInfoSortReq `description:"排序"`
  1260. XEdbList []BarChartInfoEdbItemReq `description:"X轴选择的指标列表"`
  1261. YEdbList []BarChartInfoEdbItemReq `description:"Y轴选择的指标列表"`
  1262. }
  1263. // BarChartInfoEdbItemReq 柱方图预览请求数据(指标相关)
  1264. type BarChartInfoEdbItemReq struct {
  1265. EdbInfoId int `description:"指标ID"`
  1266. Name string `description:"别名"`
  1267. NameEn string `description:"英文别名"`
  1268. Source int `description:"1:ETA图库;2:商品价格"`
  1269. }
  1270. // BarChartInfoDateReq 柱方图预览请求数据(日期相关)
  1271. type BarChartInfoDateReq struct {
  1272. Type int `description:"配置类型"`
  1273. Date string `description:"固定日期"`
  1274. Value int `description:"N天的值"`
  1275. Color string `description:"颜色"`
  1276. Name string `description:"别名"`
  1277. }
  1278. // BarChartInfoSortReq 柱方图预览请求数据(排序相关)
  1279. type BarChartInfoSortReq struct {
  1280. Sort int `description:"排序类型,0:默认,1:升序,2:降序"`
  1281. DateIndex int `description:"日期数据的下标,从0开始"`
  1282. }
  1283. // CorrelationChartInfoReq 相关性图表请求体
  1284. type CorrelationChartInfoReq struct {
  1285. LeadValue int `description:"领先期数"`
  1286. LeadUnit string `description:"频度"`
  1287. CalculateValue int `description:"计算窗口"`
  1288. CalculateUnit string `description:"计算频度"`
  1289. BaseCalculateValue int `description:"基础计算窗口(滚动相关性的时候用到)"`
  1290. BaseCalculateUnit string `description:"基础计算频度(滚动相关性的时候用到)"`
  1291. StartDate string `description:"开始日期"`
  1292. EndDate string `description:"结束日期"`
  1293. EdbInfoIdList []CorrelationChartInfoEdbItemReq `description:"指标信息"`
  1294. }
  1295. // CorrelationChartInfoEdbItemReq 相关性图表请求指标
  1296. type CorrelationChartInfoEdbItemReq struct {
  1297. EdbInfoId int `description:"指标ID"`
  1298. Name string `description:"别名"`
  1299. NameEn string `description:"英文别名"`
  1300. //Source int `description:"1:ETA图库;2:商品价格"`
  1301. }
  1302. // EditCorrelationChartInfoAndMapping 修改相关性图表的 图表与指标 的关系
  1303. func EditCorrelationChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string, correlationChart *ChartInfoCorrelation, correlationUpdateCols []string) (err error) {
  1304. o := orm.NewOrmUsingDB("data")
  1305. to, err := o.Begin()
  1306. if err != nil {
  1307. return
  1308. }
  1309. defer func() {
  1310. if err != nil {
  1311. _ = to.Rollback()
  1312. } else {
  1313. _ = to.Commit()
  1314. }
  1315. }()
  1316. var pars []interface{}
  1317. pars = append(pars, req.ChartName)
  1318. pars = append(pars, edbInfoIdStr)
  1319. pars = append(pars, req.ChartType)
  1320. pars = append(pars, req.ChartClassifyId)
  1321. pars = append(pars, disabled)
  1322. pars = append(pars, barChartConf)
  1323. sql := ` UPDATE chart_info
  1324. SET
  1325. chart_name =?,
  1326. edb_info_ids=?,
  1327. chart_type=?,
  1328. chart_classify_id = ?,
  1329. modify_time = NOW(),
  1330. disabled = ?,
  1331. bar_config = ?
  1332. `
  1333. if calendar != "" {
  1334. sql += `,calendar = ? `
  1335. pars = append(pars, calendar)
  1336. }
  1337. if dateType > 0 {
  1338. sql += `,date_type = ? `
  1339. pars = append(pars, dateType)
  1340. }
  1341. sql += `,start_date = ? `
  1342. pars = append(pars, req.StartDate)
  1343. sql += `,end_date = ? `
  1344. pars = append(pars, req.EndDate)
  1345. sql += `,season_start_date = ? `
  1346. pars = append(pars, req.SeasonStartDate)
  1347. sql += `,season_end_date = ? `
  1348. pars = append(pars, req.SeasonEndDate)
  1349. sql += `,left_min = ? `
  1350. pars = append(pars, req.LeftMin)
  1351. sql += `,left_max = ? `
  1352. pars = append(pars, req.LeftMax)
  1353. sql += `,right_min = ? `
  1354. pars = append(pars, req.RightMin)
  1355. sql += `,right_max = ? `
  1356. pars = append(pars, req.RightMax)
  1357. sql += `WHERE chart_info_id = ?`
  1358. pars = append(pars, req.ChartInfoId)
  1359. _, err = to.Raw(sql, pars).Exec()
  1360. if err != nil {
  1361. fmt.Println("UPDATE chart_info Err:", err.Error())
  1362. return err
  1363. }
  1364. chartEdbMappingIdList := make([]string, 0)
  1365. for _, v := range req.CorrelationChartInfo.EdbInfoIdList {
  1366. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  1367. var tmpChartEdbMapping *ChartEdbMapping
  1368. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  1369. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, utils.CHART_SOURCE_CORRELATION).QueryRow(&tmpChartEdbMapping)
  1370. if err != nil && err.Error() != utils.ErrNoRow() {
  1371. fmt.Println("QueryRow Err:", err.Error())
  1372. return err
  1373. }
  1374. if tmpChartEdbMapping != nil {
  1375. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  1376. //tmpChartEdbMapping.ModifyTime = time.Now()
  1377. //tmpChartEdbMapping.MaxData = v.MaxData
  1378. //tmpChartEdbMapping.MinData = v.MinData
  1379. //tmpChartEdbMapping.IsOrder = v.IsOrder
  1380. //tmpChartEdbMapping.IsAxis = v.IsAxis
  1381. //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  1382. //tmpChartEdbMapping.LeadValue = v.LeadValue
  1383. //tmpChartEdbMapping.LeadUnit = v.LeadUnit
  1384. //tmpChartEdbMapping.ChartStyle = v.ChartStyle
  1385. //tmpChartEdbMapping.ChartColor = v.ChartColor
  1386. //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  1387. //tmpChartEdbMapping.ChartWidth = v.ChartWidth
  1388. //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  1389. //if err != nil {
  1390. // fmt.Println("chart_edb_mapping Err:" + err.Error())
  1391. // return err
  1392. //}
  1393. } else {
  1394. mapItem := new(ChartEdbMapping)
  1395. mapItem.ChartInfoId = req.ChartInfoId
  1396. mapItem.EdbInfoId = v.EdbInfoId
  1397. mapItem.CreateTime = time.Now()
  1398. mapItem.ModifyTime = time.Now()
  1399. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  1400. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  1401. //mapItem.MaxData = v.MaxData
  1402. //mapItem.MinData = v.MinData
  1403. mapItem.IsOrder = true
  1404. mapItem.IsAxis = 1
  1405. mapItem.EdbInfoType = 1
  1406. //mapItem.LeadValue = v.LeadValue
  1407. //mapItem.LeadUnit = v.LeadUnit
  1408. //mapItem.ChartStyle = v.ChartStyle
  1409. //mapItem.ChartColor = v.ChartColor
  1410. //mapItem.PredictChartColor = v.PredictChartColor
  1411. //mapItem.ChartWidth = v.ChartWidth
  1412. mapItem.Source = utils.CHART_SOURCE_CORRELATION
  1413. tmpId, err := to.Insert(mapItem)
  1414. if err != nil {
  1415. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  1416. return err
  1417. }
  1418. mapItem.ChartEdbMappingId = int(tmpId)
  1419. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  1420. }
  1421. }
  1422. if len(chartEdbMappingIdList) > 0 {
  1423. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  1424. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  1425. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  1426. if err != nil {
  1427. fmt.Println("delete err:" + err.Error())
  1428. return err
  1429. }
  1430. }
  1431. // 相关性图表
  1432. _, err = to.Update(correlationChart, correlationUpdateCols...)
  1433. return
  1434. }
  1435. // PreviewSectionScatterChartReq 预览截面散点图的请求
  1436. type PreviewSectionScatterChartReq struct {
  1437. ChartName string `description:"图表名称"`
  1438. ChartClassifyId int `description:"分类id"`
  1439. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1440. }
  1441. // SectionScatterReq 截面散点请求
  1442. type SectionScatterReq struct {
  1443. XName string `description:"x轴名称"`
  1444. XNameEn string `description:"x轴名称(英文)"`
  1445. XUnitName string `description:"x轴单位名称"`
  1446. XUnitNameEn string `description:"x轴单位名称(英文)"`
  1447. YName string `description:"y轴名称"`
  1448. YNameEn string `description:"y轴名称(英文)"`
  1449. YUnitName string `description:"y轴单位名称"`
  1450. YUnitNameEn string `description:"y轴单位名称(英文)"`
  1451. XMinValue string `description:"X轴的最小值"`
  1452. XMaxValue string `description:"X轴的最大值"`
  1453. YMinValue string `description:"Y轴的最小值"`
  1454. YMaxValue string `description:"Y轴的最大值"`
  1455. //EdbList []SectionScatterEdbItemReq `description:"指标数据"`
  1456. SeriesList []SectionScatterSeriesItemReq `description:"系列数据"`
  1457. }
  1458. // SectionScatterSeriesItemReq 系列的请求
  1459. type SectionScatterSeriesItemReq struct {
  1460. Name string `description:"系列名"`
  1461. NameEn string `description:"系列名(英文名)"`
  1462. Color string `description:"颜色"`
  1463. EdbInfoList []SectionScatterEdbItemReq
  1464. ShowTrendLine bool `description:"是否展示趋势线"`
  1465. ShowFitEquation bool `description:"是否展示方程式"`
  1466. ShowRSquare bool `description:"是否展示R平方"`
  1467. }
  1468. // SectionScatterEdbItemReq 截面散点请求的指标
  1469. type SectionScatterEdbItemReq struct {
  1470. XEdbInfoId int `description:"X轴的指标ID"`
  1471. YEdbInfoId int `description:"Y轴的指标ID"`
  1472. Name string `description:"别名"`
  1473. NameEn string `description:"英文别名"`
  1474. XDateType int `description:"X轴的日期配置类型"`
  1475. XDate string `description:"X轴的日期固定日期"`
  1476. XDateValue int `description:"X轴的日期N天的值"`
  1477. YDateType int `description:"Y轴的日期配置类型"`
  1478. YDate string `description:"Y轴的日期固定日期"`
  1479. YDateValue int `description:"Y轴的日期N天的值"`
  1480. IsShow bool `description:"是否展示"`
  1481. }
  1482. // SectionScatterInfoResp 截面散点图数据
  1483. type SectionScatterInfoResp struct {
  1484. XName string `description:"x轴名称"`
  1485. XNameEn string `description:"x轴名称(英文)"`
  1486. XUnitName string `description:"x轴单位名称"`
  1487. XUnitNameEn string `description:"x轴单位名称(英文)"`
  1488. YName string `description:"y轴名称"`
  1489. YNameEn string `description:"y轴名称(英文)"`
  1490. YUnitName string `description:"y轴单位名称"`
  1491. YUnitNameEn string `description:"y轴单位名称(英文)"`
  1492. XMinValue string `description:"X轴的最小值"`
  1493. XMaxValue string `description:"X轴的最大值"`
  1494. YMinValue string `description:"Y轴的最小值"`
  1495. YMaxValue string `description:"Y轴的最大值"`
  1496. DataList []SectionScatterSeriesItemResp `description:"数据列"`
  1497. }
  1498. // SectionScatterSeriesItemResp 系列的返回
  1499. type SectionScatterSeriesItemResp struct {
  1500. Name string `description:"系列名"`
  1501. NameEn string `description:"系列名(英文)"`
  1502. Color string `description:"颜色"`
  1503. EdbInfoList []SectionScatterEdbItemResp
  1504. ShowTrendLine bool `description:"是否展示趋势线"`
  1505. ShowFitEquation bool `description:"是否展示方程式"`
  1506. ShowRSquare bool `description:"是否展示R平方"`
  1507. TrendLine string `description:"方程式"`
  1508. RSquare string `description:"R平方的值(决定系数R2)"`
  1509. TrendLimitData []CoordinatePoint `description:"趋势线的前后坐标点"`
  1510. }
  1511. // SectionScatterEdbItemResp 截面散点的返回参数
  1512. type SectionScatterEdbItemResp struct {
  1513. XEdbInfoId int `description:"X轴指标id"`
  1514. XDate string `description:"X轴指标实际日期"`
  1515. XName string `description:"X轴指标名称"`
  1516. XNameEn string `description:"X轴指标英文名称"`
  1517. XValue float64 `description:"X轴实际值"`
  1518. YEdbInfoId int `description:"Y轴指标id"`
  1519. YDate string `description:"Y轴指标实际日期"`
  1520. YName string `description:"Y轴指标名称"`
  1521. YNameEn string `description:"Y轴指标英文名称"`
  1522. YValue float64 `description:"Y轴实际值"`
  1523. IsShow bool `description:"是否展示"`
  1524. Name string `description:"标签名称"`
  1525. NameEn string `description:"英文标签名称"`
  1526. }
  1527. // CoordinatePoint 坐标点
  1528. type CoordinatePoint struct {
  1529. X float64
  1530. Y float64
  1531. }
  1532. // RollingCorrelationChartDataResp 滚动相关性图
  1533. type RollingCorrelationChartDataResp struct {
  1534. XDateTimeValue []string `description:"滚动相关性图的x轴数据,日期数据"`
  1535. YDataList []YData `description:"滚动相关性图的y轴数据"`
  1536. }