chart_info.go 112 KB

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