chart_info.go 110 KB

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