chart_info.go 109 KB

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