chart_info.go 81 KB

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