chart_info.go 118 KB

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