chart_info.go 98 KB

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