chart_info.go 99 KB

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