chart_info.go 109 KB

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