chart_info.go 114 KB

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