chart_info.go 114 KB

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