chart_info.go 95 KB

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