chart_info.go 110 KB

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