chart_info.go 112 KB

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