chart_info.go 107 KB

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