chart_info.go 106 KB

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