chart_info.go 101 KB

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