chart_info.go 95 KB

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