chart_info.go 109 KB

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