chart_info.go 107 KB

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