chart_info.go 110 KB

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