chart_info.go 107 KB

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