chart_info.go 106 KB

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