chart_info.go 110 KB

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