chart_info.go 114 KB

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