chart_info.go 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005
  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. ChartTypeName string `description:"生成样式的名称,如:曲线图,2:季节性图"`
  1779. Calendar string `description:"公历/农历"`
  1780. SeasonStartDate string `description:"季节性图开始日期"`
  1781. SeasonEndDate string `description:"季节性图开始日期"`
  1782. ChartImage string `description:"图表图片"`
  1783. Sort int `description:"排序字段,数字越小越排前面"`
  1784. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1785. MyChartId int
  1786. MyChartClassifyId string `description:"我的图表分类,多个用逗号隔开"`
  1787. ChartClassify []*ChartClassifyView `gorm:"-"`
  1788. EdbEndDate string `description:"指标最新更新日期"`
  1789. XMin string `description:"图表X轴最小值"`
  1790. XMax string `description:"图表X轴最大值"`
  1791. LeftMin string `description:"图表左侧最小值"`
  1792. LeftMax string `description:"图表左侧最大值"`
  1793. RightMin string `description:"图表右侧最小值"`
  1794. RightMax string `description:"图表右侧最大值"`
  1795. Right2Min string `description:"图表右侧最小值"`
  1796. Right2Max string `description:"图表右侧最大值"`
  1797. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  1798. IsEdit bool `description:"是否有编辑权限"`
  1799. IsEnChart bool `description:"是否展示英文标识"`
  1800. WarnMsg string `description:"错误信息"`
  1801. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  1802. BarConfig string `description:"柱方图的配置,json数据" json:"-"`
  1803. Source int `description:"1:ETA图库;2:商品价格曲线;3:相关性图表"`
  1804. //CorrelationLeadUnit string `description:"相关性图表-领先单位"`
  1805. ExtraConfig string `description:"图表额外配置,json数据"`
  1806. ChartSource string `description:"图表来源str"`
  1807. ChartSourceEn string `description:"图表来源(英文)"`
  1808. Button ChartViewButton `gorm:"-" description:"操作按钮"`
  1809. SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  1810. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1811. ChartThemeId int `description:"图表应用主题ID"`
  1812. ChartThemeStyle string `description:"图表应用主题样式"`
  1813. SourcesFrom string `description:"图表来源"`
  1814. Instructions string `description:"图表说明"`
  1815. MarkersLines string `description:"标识线"`
  1816. MarkersAreas string `description:"标识区"`
  1817. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  1818. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  1819. ForumChartInfoId int `description:"社区的图表ID"`
  1820. ChartAlias string `description:"图表别名"`
  1821. SharedUserIdList []int `description:"共享用户id列表" gorm:"-"`
  1822. SharedUserName string `description:"共享用户姓名,多个用英文,隔开" gorm:"-"`
  1823. PublicStatus int `description:"公开状态;0:未公开;1:审批中;2:已驳回;3:已公开"`
  1824. ChartPublicClassifyId int `description:"图表公开分类id"`
  1825. PublicTime time.Time `description:"设置公开的时间"`
  1826. ClassifyNamePath string `description:"分类完整路径"`
  1827. PublicClassifyNamePath string `description:"公共分类完整路径"`
  1828. CollectClassifyIdList []int `description:"所属收藏分类id列表" gorm:"-"`
  1829. CollectClassifyNameList []string `description:"所属收藏分类名称列表" gorm:"-"`
  1830. }
  1831. type ChartViewButton struct {
  1832. IsEdit bool `description:"是否有编辑权限"`
  1833. IsEnChart bool `description:"是否展示英文标识"`
  1834. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1835. IsCopy bool `description:"是否有另存为按钮"`
  1836. IsSetName int `description:"设置名称"`
  1837. }
  1838. type ImageSvgToPngResp struct {
  1839. Data struct {
  1840. ResourceURL string `json:"ResourceUrl"`
  1841. } `json:"Data"`
  1842. ErrCode string `json:"ErrCode"`
  1843. ErrMsg string `json:"ErrMsg"`
  1844. IsSendEmail bool `json:"IsSendEmail"`
  1845. Msg string `json:"Msg"`
  1846. Ret int64 `json:"Ret"`
  1847. Success bool `json:"Success"`
  1848. }
  1849. // GetChartInfoByClassifyIdAndName 根据分类id和图表名获取图表信息
  1850. func GetChartInfoByClassifyIdAndName(classifyId int, chartName string) (item *ChartInfo, err error) {
  1851. o := global.DmSQL["data"]
  1852. sql := ` SELECT * FROM chart_info WHERE chart_classify_id = ? and chart_name=? `
  1853. err = o.Raw(sql, classifyId, chartName).First(&item).Error
  1854. return
  1855. }
  1856. // BatchChartRefreshReq 批量刷新图表请求
  1857. type BatchChartRefreshReq struct {
  1858. ChartInfoCode []string `description:"图表编码数组"`
  1859. PrimaryId int `description:"研报/智能研报/PPT主键"`
  1860. SubId int `description:"报告章节ID"`
  1861. Source string `description:"来源,枚举值:report、english_report、smart_report、ppt"`
  1862. }
  1863. // GetChartInfoListByUniqueCodeSlice 根据图表编码获取图表列表数据
  1864. func GetChartInfoListByUniqueCodeSlice(uniqueCodeSlice []string) (total int64, items []*ChartInfo, err error) {
  1865. num := len(uniqueCodeSlice)
  1866. if num <= 0 {
  1867. return
  1868. }
  1869. sql := ` SELECT * FROM chart_info WHERE unique_code in (` + utils.GetOrmInReplace(num) + `) `
  1870. err = global.DmSQL["data"].Raw(sql, uniqueCodeSlice).Scan(&items).Error
  1871. if err != nil {
  1872. return
  1873. }
  1874. total = int64(len(items))
  1875. return
  1876. }
  1877. // GetChartInfoRefreshDataByChartInfoIdSlice 根据图表id切片获取对应的指标数据
  1878. func GetChartInfoRefreshDataByChartInfoIdSlice(chartInfoIdSlice []string) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1879. o := global.DmSQL["data"]
  1880. if len(chartInfoIdSlice) <= 0 {
  1881. return
  1882. }
  1883. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  1884. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  1885. WHERE a.chart_info_id in (` + strings.Join(chartInfoIdSlice, ",") + `) `
  1886. edbInfoList := make([]*EdbInfo, 0)
  1887. err = o.Raw(sql).Scan(&edbInfoList).Error
  1888. if err != nil {
  1889. return
  1890. }
  1891. for _, v := range edbInfoList {
  1892. if v.EdbType == 1 {
  1893. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1894. } else {
  1895. calculateInfoArr = append(calculateInfoArr, v)
  1896. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  1897. if err != nil {
  1898. return baseEdbInfoArr, calculateInfoArr, err
  1899. }
  1900. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1901. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1902. }
  1903. }
  1904. return
  1905. }
  1906. // CopyAddChartInfoReq 复制并新增图表
  1907. type CopyAddChartInfoReq struct {
  1908. ChartInfoId int `description:"待复制的图表id"`
  1909. ChartClassifyId int `description:"分类id"`
  1910. ChartName string `description:"图表名称"`
  1911. }
  1912. // ChartInfoListByEsResp 图表数据Es搜索返回
  1913. type ChartInfoListByEsResp struct {
  1914. Paging *paging.PagingItem
  1915. List []*ChartInfoMore
  1916. }
  1917. // ChartInfoListByEsRespV2 图表数据Es搜索返回
  1918. type ChartInfoListByEsRespV2 struct {
  1919. Paging *paging.PagingItem
  1920. List []*ChartInfoView
  1921. }
  1922. // GetChartInfoListByCondition 根据条件获取图表数据了列表
  1923. func GetChartInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ChartInfo, err error) {
  1924. o := global.DmSQL["data"]
  1925. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  1926. if condition != "" {
  1927. sql += condition
  1928. }
  1929. sql += ` ORDER BY chart_info_id DESC LIMIT ?,? `
  1930. pars = append(pars, startSize, pageSize)
  1931. err = o.Raw(sql, pars...).Scan(&items).Error
  1932. return
  1933. }
  1934. // GetChartInfoListGroupByUserId 根据指标id列表、用户分组获取指标信息
  1935. func GetChartInfoListGroupByUserId(edbIdList []string) (items []*ChartInfo, err error) {
  1936. num := len(edbIdList)
  1937. if num <= 0 {
  1938. return
  1939. }
  1940. o := global.DmSQL["data"]
  1941. sql := ` SELECT * FROM chart_info WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) ORDER BY chart_info_id desc `
  1942. err = o.Raw(sql, edbIdList).Scan(&items).Error
  1943. return
  1944. }
  1945. // GetChartInfoListByChartIdList
  1946. // @Description: 根据图表id列表获取列表信息
  1947. // @param edbIdList
  1948. // @return items
  1949. // @return err
  1950. func GetChartInfoListByChartIdList(charIdList []int) (items []*ChartInfo, err error) {
  1951. num := len(charIdList)
  1952. if num <= 0 {
  1953. return
  1954. }
  1955. o := global.DmSQL["data"]
  1956. sql := ` SELECT * FROM chart_info WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) ORDER BY chart_info_id desc `
  1957. err = o.Raw(sql, charIdList).Scan(&items).Error
  1958. return
  1959. }
  1960. // GetChartInfoListByUserId
  1961. // @Description: 根据图表id列表获取列表信息
  1962. // @param userIdList []int
  1963. // @param source int
  1964. // @return items
  1965. // @return err
  1966. func GetChartInfoListByUserId(userIdList []int, source int) (items []*ChartInfo, err error) {
  1967. num := len(userIdList)
  1968. if num <= 0 {
  1969. return
  1970. }
  1971. o := global.DmSQL["data"]
  1972. sql := ` SELECT * FROM chart_info WHERE source = ? AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) ORDER BY chart_info_id desc `
  1973. err = o.Raw(sql, source, userIdList).Scan(&items).Error
  1974. return
  1975. }
  1976. // ModifyChartInfoUserIdByCodeList 根据指标code列表修改创建人
  1977. func ModifyChartInfoUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  1978. num := len(edbIdList)
  1979. if num <= 0 {
  1980. return
  1981. }
  1982. o := global.DmSQL["data"]
  1983. sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1984. err = o.Exec(sql, userId, userName, edbIdList).Error
  1985. return
  1986. }
  1987. // ModifyChartInfoUserIdByOldUserId
  1988. // @Description: 根据旧的用户id修改创建人
  1989. // @author: Roc
  1990. // @datetime 2024-03-25 19:14:59
  1991. // @param oldUserId int
  1992. // @param userId int
  1993. // @param userName string
  1994. // @return err error
  1995. func ModifyChartInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName string) (err error) {
  1996. num := len(oldUserIdList)
  1997. if num <= 0 {
  1998. return
  1999. }
  2000. o := global.DmSQL["data"]
  2001. sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  2002. err = o.Exec(sql, userId, userName, oldUserIdList).Error
  2003. return
  2004. }
  2005. // BarChartInfoReq 柱方图预览请求数据
  2006. type BarChartInfoReq struct {
  2007. EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
  2008. DateList []BarChartInfoDateReq `description:"日期配置"`
  2009. Sort BarChartInfoSortReq `description:"排序"`
  2010. XEdbList []BarChartInfoEdbItemReq `description:"X轴选择的指标列表"`
  2011. YEdbList []BarChartInfoEdbItemReq `description:"Y轴选择的指标列表"`
  2012. Unit string `description:"中文单位"`
  2013. UnitEn string `description:"英文单位"`
  2014. MarkersLines string `description:"标识线"`
  2015. }
  2016. type FutureGoodBarChartInfoReq struct {
  2017. EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
  2018. DateList []BarChartInfoDateReq `description:"日期配置"`
  2019. XDataList []XData `description:"横轴配置"`
  2020. BaseEdbInfoId int `description:"日期基准指标id"`
  2021. }
  2022. // BarChartInfoEdbItemReq 柱方图预览请求数据(指标相关)
  2023. type BarChartInfoEdbItemReq struct {
  2024. EdbInfoId int `description:"指标ID"`
  2025. Name string `description:"别名"`
  2026. NameEn string `description:"英文别名"`
  2027. Source int `description:"1:ETA图库;2:商品价格"`
  2028. IsConvert int `description:"是否数据转换 0不转 1转"`
  2029. ConvertType int `description:"数据转换类型 1乘 2除 3对数"`
  2030. ConvertValue float64 `description:"数据转换值"`
  2031. ConvertUnit string `description:"数据转换单位"`
  2032. ConvertEnUnit string `description:"数据转换单位"`
  2033. IsHide int `description:"是否隐藏该项,0不隐藏,1隐藏"`
  2034. }
  2035. // BarChartInfoDateReq 柱方图预览请求数据(日期相关)
  2036. type BarChartInfoDateReq struct {
  2037. Type int `description:"配置类型"`
  2038. Date string `description:"固定日期"`
  2039. Value int `description:"N天的值"`
  2040. Color string `description:"颜色"`
  2041. Name string `description:"别名"`
  2042. }
  2043. // BarChartInfoSortReq 柱方图预览请求数据(排序相关)
  2044. type BarChartInfoSortReq struct {
  2045. Sort int `description:"排序类型,0:默认,1:升序,2:降序"`
  2046. DateIndex int `description:"日期数据的下标,从0开始"`
  2047. }
  2048. // CorrelationChartInfoReq 相关性图表请求体
  2049. type CorrelationChartInfoReq struct {
  2050. LeadValue int `description:"领先期数"`
  2051. LeadUnit string `description:"频度"`
  2052. CalculateValue int `description:"计算窗口"`
  2053. CalculateUnit string `description:"计算频度"`
  2054. BaseCalculateValue int `description:"基础计算窗口(滚动相关性的时候用到)"`
  2055. BaseCalculateUnit string `description:"基础计算频度(滚动相关性的时候用到)"`
  2056. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  2057. StartDate string `description:"开始日期"`
  2058. EndDate string `description:"结束日期"`
  2059. EdbInfoIdList []CorrelationChartInfoEdbItemReq `description:"指标信息"`
  2060. }
  2061. // CorrelationChartInfoEdbItemReq 相关性图表请求指标
  2062. type CorrelationChartInfoEdbItemReq struct {
  2063. EdbInfoId int `description:"指标ID"`
  2064. Name string `description:"别名"`
  2065. NameEn string `description:"英文别名"`
  2066. //Source int `description:"1:ETA图库;2:商品价格"`
  2067. }
  2068. // EditCorrelationChartInfoAndMapping 修改相关性图表的 图表与指标 的关系
  2069. func EditCorrelationChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string, correlationChart *ChartInfoCorrelation, correlationUpdateCols []string) (err error) {
  2070. to := global.DmSQL["data"].Begin()
  2071. defer func() {
  2072. if err != nil {
  2073. _ = to.Rollback()
  2074. } else {
  2075. _ = to.Commit()
  2076. }
  2077. }()
  2078. var pars []interface{}
  2079. pars = append(pars, req.ChartName)
  2080. pars = append(pars, edbInfoIdStr)
  2081. pars = append(pars, req.ChartType)
  2082. pars = append(pars, req.ChartClassifyId)
  2083. pars = append(pars, disabled)
  2084. pars = append(pars, barChartConf)
  2085. pars = append(pars, req.ExtraConfig)
  2086. pars = append(pars, req.SourcesFrom)
  2087. sql := ` UPDATE chart_info
  2088. SET
  2089. chart_name =?,
  2090. edb_info_ids=?,
  2091. chart_type=?,
  2092. chart_classify_id = ?,
  2093. modify_time = NOW(),
  2094. disabled = ?,
  2095. bar_config = ?,
  2096. extra_config = ?,
  2097. sources_from = ?
  2098. `
  2099. if calendar != "" {
  2100. sql += `,calendar = ? `
  2101. pars = append(pars, calendar)
  2102. }
  2103. if dateType > 0 {
  2104. sql += `,date_type = ? `
  2105. pars = append(pars, dateType)
  2106. }
  2107. sql += `,start_date = ? `
  2108. pars = append(pars, req.StartDate)
  2109. sql += `,end_date = ? `
  2110. pars = append(pars, req.EndDate)
  2111. sql += `,season_start_date = ? `
  2112. pars = append(pars, req.StartDate)
  2113. sql += `,season_end_date = ? `
  2114. pars = append(pars, req.EndDate)
  2115. sql += `,left_min = ? `
  2116. pars = append(pars, req.LeftMin)
  2117. sql += `,left_max = ? `
  2118. pars = append(pars, req.LeftMax)
  2119. sql += `,right_min = ? `
  2120. pars = append(pars, req.RightMin)
  2121. sql += `,right_max = ? `
  2122. pars = append(pars, req.RightMax)
  2123. sql += `WHERE chart_info_id = ?`
  2124. pars = append(pars, req.ChartInfoId)
  2125. err = to.Exec(sql, pars...).Error
  2126. if err != nil {
  2127. fmt.Println("UPDATE chart_info Err:", err.Error())
  2128. return err
  2129. }
  2130. chartEdbMappingIdList := make([]string, 0)
  2131. for _, v := range req.CorrelationChartInfo.EdbInfoIdList {
  2132. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  2133. var tmpChartEdbMapping *ChartEdbMapping
  2134. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  2135. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, utils.CHART_SOURCE_CORRELATION).Scan(&tmpChartEdbMapping).Error
  2136. if err != nil && !utils.IsErrNoRow(err) {
  2137. fmt.Println("QueryRow Err:", err.Error())
  2138. return err
  2139. }
  2140. if tmpChartEdbMapping != nil {
  2141. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  2142. //tmpChartEdbMapping.ModifyTime = time.Now()
  2143. //tmpChartEdbMapping.MaxData = v.MaxData
  2144. //tmpChartEdbMapping.MinData = v.MinData
  2145. //tmpChartEdbMapping.IsOrder = v.IsOrder
  2146. //tmpChartEdbMapping.IsAxis = v.IsAxis
  2147. //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  2148. //tmpChartEdbMapping.LeadValue = v.LeadValue
  2149. //tmpChartEdbMapping.LeadUnit = v.LeadUnit
  2150. //tmpChartEdbMapping.ChartStyle = v.ChartStyle
  2151. //tmpChartEdbMapping.ChartColor = v.ChartColor
  2152. //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  2153. //tmpChartEdbMapping.ChartWidth = v.ChartWidth
  2154. //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  2155. //if err != nil {
  2156. // fmt.Println("chart_edb_mapping Err:" + err.Error())
  2157. // return err
  2158. //}
  2159. } else {
  2160. mapItem := new(ChartEdbMapping)
  2161. mapItem.ChartInfoId = req.ChartInfoId
  2162. mapItem.EdbInfoId = v.EdbInfoId
  2163. mapItem.CreateTime = time.Now()
  2164. mapItem.ModifyTime = time.Now()
  2165. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  2166. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  2167. //mapItem.MaxData = v.MaxData
  2168. //mapItem.MinData = v.MinData
  2169. mapItem.IsOrder = true
  2170. mapItem.IsAxis = 1
  2171. mapItem.EdbInfoType = 1
  2172. //mapItem.LeadValue = v.LeadValue
  2173. //mapItem.LeadUnit = v.LeadUnit
  2174. //mapItem.ChartStyle = v.ChartStyle
  2175. //mapItem.ChartColor = v.ChartColor
  2176. //mapItem.PredictChartColor = v.PredictChartColor
  2177. //mapItem.ChartWidth = v.ChartWidth
  2178. mapItem.Source = utils.CHART_SOURCE_CORRELATION
  2179. err = to.Create(mapItem).Error
  2180. if err != nil {
  2181. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  2182. return err
  2183. }
  2184. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  2185. }
  2186. }
  2187. if len(chartEdbMappingIdList) > 0 {
  2188. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  2189. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  2190. err = to.Exec(dsql, req.ChartInfoId).Error
  2191. if err != nil {
  2192. fmt.Println("delete err:" + err.Error())
  2193. return err
  2194. }
  2195. }
  2196. // 相关性图表
  2197. err = to.Select(correlationUpdateCols).Updates(correlationChart).Error
  2198. return
  2199. }
  2200. // PreviewSectionScatterChartReq 预览截面散点图的请求
  2201. type PreviewSectionScatterChartReq struct {
  2202. ChartName string `description:"图表名称"`
  2203. ChartClassifyId int `description:"分类id"`
  2204. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  2205. }
  2206. // SectionScatterReq 截面散点请求
  2207. type SectionScatterReq struct {
  2208. XName string `description:"x轴名称"`
  2209. XNameEn string `description:"x轴名称(英文)"`
  2210. XUnitName string `description:"x轴单位名称"`
  2211. XUnitNameEn string `description:"x轴单位名称(英文)"`
  2212. YName string `description:"y轴名称"`
  2213. YNameEn string `description:"y轴名称(英文)"`
  2214. YUnitName string `description:"y轴单位名称"`
  2215. YUnitNameEn string `description:"y轴单位名称(英文)"`
  2216. XMinValue string `description:"X轴的最小值"`
  2217. XMaxValue string `description:"X轴的最大值"`
  2218. YMinValue string `description:"Y轴的最小值"`
  2219. YMaxValue string `description:"Y轴的最大值"`
  2220. //EdbList []SectionScatterEdbItemReq `description:"指标数据"`
  2221. SeriesList []SectionScatterSeriesItemReq `description:"系列数据"`
  2222. }
  2223. // SectionScatterSeriesItemReq 系列的请求
  2224. type SectionScatterSeriesItemReq struct {
  2225. Name string `description:"系列名"`
  2226. NameEn string `description:"系列名(英文名)"`
  2227. IsNameDefault bool `description:"是否使用默认的系列名 false修改过 true默认 影响自动更新"`
  2228. Color string `description:"颜色"`
  2229. EdbInfoList []SectionScatterEdbItemReq
  2230. ShowTrendLine bool `description:"是否展示趋势线"`
  2231. ShowFitEquation bool `description:"是否展示方程式"`
  2232. ShowRSquare bool `description:"是否展示R平方"`
  2233. }
  2234. // SectionScatterEdbItemReq 截面散点请求的指标
  2235. type SectionScatterEdbItemReq struct {
  2236. XEdbInfoId int `description:"X轴的指标ID"`
  2237. YEdbInfoId int `description:"Y轴的指标ID"`
  2238. Name string `description:"别名"`
  2239. NameEn string `description:"英文别名"`
  2240. XDateType int `description:"X轴的日期配置类型"`
  2241. XDate string `description:"X轴的日期固定日期"`
  2242. XDateValue int `description:"X轴的日期N天的值"`
  2243. YDateType int `description:"Y轴的日期配置类型"`
  2244. YDate string `description:"Y轴的日期固定日期"`
  2245. YDateValue int `description:"Y轴的日期N天的值"`
  2246. IsShow bool `description:"是否展示"`
  2247. }
  2248. // SectionScatterInfoResp 截面散点图数据
  2249. type SectionScatterInfoResp struct {
  2250. XName string `description:"x轴名称"`
  2251. XNameEn string `description:"x轴名称(英文)"`
  2252. XUnitName string `description:"x轴单位名称"`
  2253. XUnitNameEn string `description:"x轴单位名称(英文)"`
  2254. YName string `description:"y轴名称"`
  2255. YNameEn string `description:"y轴名称(英文)"`
  2256. YUnitName string `description:"y轴单位名称"`
  2257. YUnitNameEn string `description:"y轴单位名称(英文)"`
  2258. XMinValue string `description:"X轴的最小值"`
  2259. XMaxValue string `description:"X轴的最大值"`
  2260. YMinValue string `description:"Y轴的最小值"`
  2261. YMaxValue string `description:"Y轴的最大值"`
  2262. DataList []SectionScatterSeriesItemResp `description:"数据列"`
  2263. }
  2264. // SectionScatterSeriesItemResp 系列的返回
  2265. type SectionScatterSeriesItemResp struct {
  2266. Name string `description:"系列名"`
  2267. NameEn string `description:"系列名(英文)"`
  2268. IsNameDefault bool `description:"是否使用默认的系列名 false修改过 true默认 影响自动更新"`
  2269. Color string `description:"颜色"`
  2270. EdbInfoList []SectionScatterEdbItemResp
  2271. ShowTrendLine bool `description:"是否展示趋势线"`
  2272. ShowFitEquation bool `description:"是否展示方程式"`
  2273. ShowRSquare bool `description:"是否展示R平方"`
  2274. TrendLine string `description:"方程式"`
  2275. RSquare string `description:"R平方的值(决定系数R2)"`
  2276. TrendLimitData []CoordinatePoint `description:"趋势线的前后坐标点"`
  2277. }
  2278. // SectionScatterEdbItemResp 截面散点的返回参数
  2279. type SectionScatterEdbItemResp struct {
  2280. XEdbInfoId int `description:"X轴指标id"`
  2281. XDate string `description:"X轴指标实际日期"`
  2282. XName string `description:"X轴指标名称"`
  2283. XNameEn string `description:"X轴指标英文名称"`
  2284. XValue float64 `description:"X轴实际值"`
  2285. YEdbInfoId int `description:"Y轴指标id"`
  2286. YDate string `description:"Y轴指标实际日期"`
  2287. YName string `description:"Y轴指标名称"`
  2288. YNameEn string `description:"Y轴指标英文名称"`
  2289. YValue float64 `description:"Y轴实际值"`
  2290. IsShow bool `description:"是否展示"`
  2291. Name string `description:"标签名称"`
  2292. NameEn string `description:"英文标签名称"`
  2293. }
  2294. // CoordinatePoint 坐标点
  2295. type CoordinatePoint struct {
  2296. X float64
  2297. Y float64
  2298. }
  2299. // RollingCorrelationChartDataResp 滚动相关性图
  2300. type RollingCorrelationChartDataResp struct {
  2301. XDateTimeValue []string `description:"滚动相关性图的x轴数据,日期数据"`
  2302. YDataList []YData `description:"滚动相关性图的y轴数据"`
  2303. }
  2304. // GetChartInfoAll 用于分类展示
  2305. // @param source int 1:ETA图库;2:商品价格曲线
  2306. func GetChartInfoAllByClassifyId(source, classifyId int) (items []*ChartClassifyItems, err error) {
  2307. o := global.DmSQL["data"]
  2308. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,chart_name_en AS chart_classify_name_en,
  2309. 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
  2310. FROM chart_info WHERE chart_classify_id = ? AND source = ? ORDER BY sort asc,create_time DESC `
  2311. err = o.Raw(sql, classifyId, source).Scan(&items).Error
  2312. return
  2313. }
  2314. // ProfitFutureGoodChartResp 商品利润图
  2315. type ProfitFutureGoodChartResp struct {
  2316. XDataList []XData
  2317. YDataList []YData
  2318. ProfitName string `description:"利润的名称"`
  2319. ProfitNameEn string `description:"利润的英文名称"`
  2320. }
  2321. func FIXChartClassifyId(newId, oldId int) (err error) {
  2322. o := global.DmSQL["data"]
  2323. sql := ` UPDATE chart_info SET chart_classify_id=? WHERE chart_classify_id=? `
  2324. err = o.Exec(sql, newId, oldId).Error
  2325. return
  2326. }
  2327. // GetChartInfoByAdminIdAndClassify 获取所有我创建的图表,用于分类展示
  2328. func GetChartInfoByAdminIdAndClassify(sourceList []int, adminId, classifyId int) (items []*ChartClassifyItems, err error) {
  2329. num := len(sourceList)
  2330. if num <= 0 {
  2331. return
  2332. }
  2333. o := global.DmSQL["data"]
  2334. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
  2335. 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
  2336. FROM chart_info where source in (` + utils.GetOrmInReplace(num) + `) AND sys_user_id = ? AND chart_classify_id = ? ORDER BY sort asc,create_time ASC `
  2337. err = o.Raw(sql, sourceList, adminId, classifyId).Scan(&items).Error
  2338. return
  2339. }
  2340. // GetChartInfoAdminList 根据条件获取图表数据了列表
  2341. func GetChartInfoAdminList() (items []int, err error) {
  2342. o := global.DmSQL["data"]
  2343. sql := ` SELECT sys_user_id FROM chart_info GROUP BY sys_user_id `
  2344. err = o.Raw(sql).Scan(&items).Error
  2345. return
  2346. }
  2347. // EditChartInfoExtraConfig 修改 ETA图库 的 图表额外配置
  2348. func EditChartInfoExtraConfig(chartId int, extraConfig string) (err error) {
  2349. o := global.DmSQL["data"]
  2350. var pars []interface{}
  2351. pars = append(pars, extraConfig)
  2352. sql := ` UPDATE chart_info
  2353. SET
  2354. modify_time = NOW(),
  2355. extra_config = ?
  2356. `
  2357. sql += `WHERE chart_info_id = ?`
  2358. pars = append(pars, chartId)
  2359. err = o.Exec(sql, pars).Error
  2360. if err != nil {
  2361. fmt.Println("UPDATE chart_info Err:", err.Error())
  2362. return err
  2363. }
  2364. return
  2365. }
  2366. // PreviewRadarChartReq 预览雷达图的请求入参
  2367. type PreviewRadarChartReq struct {
  2368. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  2369. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  2370. }
  2371. // RadarChartInfoReq 雷达图预览请求数据
  2372. type RadarChartInfoReq struct {
  2373. DateList []RadarChartInfoDateReq `description:"日期配置"`
  2374. }
  2375. // RadarChartInfoEdbItemReq 雷达图预览请求数据(指标相关)
  2376. type RadarChartInfoEdbItemReq struct {
  2377. EdbInfoId int `description:"指标ID"`
  2378. Name string `description:"别名"`
  2379. //NameEn string `description:"英文别名"`
  2380. //Source int `description:"1:ETA图库;2:商品价格"`
  2381. }
  2382. // RadarChartInfoDateReq 雷达图预览请求数据(日期相关)
  2383. type RadarChartInfoDateReq struct {
  2384. Type int `description:"配置类型"`
  2385. Date string `description:"固定日期"`
  2386. Value int `description:"N天的值"`
  2387. Color string `description:"颜色"`
  2388. Name string `description:"别名"`
  2389. }
  2390. // RadarChartInfoResp 雷达图数据
  2391. type RadarChartInfoResp struct {
  2392. YDataList []RadarYData `description:"数据列"`
  2393. XEdbIdValue []int
  2394. }
  2395. // RadarYData 雷达图的y轴数据
  2396. type RadarYData struct {
  2397. Date string `description:"数据日期"`
  2398. Color string `description:"数据颜色"`
  2399. Name string `description:"别名"`
  2400. Value []float64 `description:"每个指标的值"`
  2401. }
  2402. // 截面组合图额外配置
  2403. type ChartSectionExtraConf struct {
  2404. DateConfList []*ChartSectionDateConfItem
  2405. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  2406. XDataList []XData `description:"横轴名称设置"`
  2407. UnitList *ChartSectionCombineUnit `description:"纵轴单位设置"`
  2408. BaseChartSeriesName string `description:"基准系列名称"`
  2409. SortType int `description:"排序类型,0默认,1升序,2降序"`
  2410. }
  2411. // 截面组合图额外配置
  2412. type ChartSectionAllExtraConf struct {
  2413. ChartSectionExtraConf
  2414. SeriesList []*ChartSectionSeriesItem
  2415. }
  2416. type ChartSectionDateConfItem struct {
  2417. MoveForward int `description:"前移的期数"`
  2418. EdbInfoId int `description:"指标ID"`
  2419. EdbName string `description:"指标名称"`
  2420. EdbNameEn string `description:"指标名称英文"`
  2421. EdbInfoType int `description:"指标类型"`
  2422. Frequency string `description:"频度"`
  2423. EndDate string `description:"最新日期"`
  2424. StaticDate string `description:"固定日期"`
  2425. DateType int `description:"日期类型:0 指标日期,1系统日期, 2固定日期"`
  2426. DateConfName string `description:"引用日期名称"` // 引用日期名称不能重复
  2427. DateConfNameEn string `description:"引用日期英文名称"`
  2428. DateChange []*ChartSectionDateChange
  2429. }
  2430. // 截面组合图引用日期配置
  2431. type ChartSectionDateChange struct {
  2432. Year int
  2433. Month int
  2434. Day int
  2435. Frequency string `description:"频度变换"`
  2436. FrequencyDay string `description:"频度的固定日期"`
  2437. ChangeType int `description:"日期变换类型1日期位移,2指定频率"`
  2438. }
  2439. // 截面组合图系列配置
  2440. type ChartSectionSeriesItem struct {
  2441. ChartSeriesId int `description:"系列ID"`
  2442. SeriesName string `description:"系列名称"` //系列名称不可同名
  2443. SeriesNameEn string `description:"系列英文名称"`
  2444. ChartStyle string `description:"图表类型"`
  2445. ChartColor string `description:"颜色"`
  2446. ChartWidth int `description:"线条大小"`
  2447. IsPoint int `description:"是否用数据点展示(0 否,1是)"`
  2448. IsNumber int `description:"是否用数值展示(0 否,1是)"`
  2449. IsAxis int `description:"1:左轴,0:右轴"`
  2450. MaxData float64 `description:"上限"`
  2451. MinData float64 `description:"下限"`
  2452. //IsOrder bool `description:"true:正序,false:逆序"`
  2453. EdbInfoList []*ChartSectionSeriesEdbConf
  2454. DataList []float64
  2455. NoDataEdbIndex []int
  2456. }
  2457. type ChartSectionSeriesEdbConf struct {
  2458. ChartSeriesEdbMappingId int `description:"映射ID"`
  2459. ChartSeriesId int `description:"系列ID"`
  2460. //ChartInfoId int `description:"图表ID"`
  2461. EdbInfoId int `description:"指标id"`
  2462. DateConf *ChartSectionSeriesDateConfItem
  2463. EdbName string `description:"中文别名"`
  2464. EdbNameEn string `description:"英文别名"`
  2465. EdbInfoType int `description:"指标类型"`
  2466. Unit string `description:"单位"`
  2467. UnitEn string `description:"英文单位"`
  2468. DateConfName string `description:"引用日期名称"`
  2469. DateConfType int `description:"日期类型,0指标最新日期, 1引用日期"`
  2470. }
  2471. type ChartSectionCombineDataResp struct {
  2472. DateConfList []*ChartSectionDateConfItem
  2473. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  2474. XDataList []XData `description:"横轴名称设置"`
  2475. UnitList *ChartSectionCombineUnit `description:"纵轴单位设置"`
  2476. BaseChartSeriesName string `description:"基准系列名称"`
  2477. SortType int `description:"排序类型,0默认,1升序,2降序"`
  2478. SeriesList []*ChartSectionSeriesItem
  2479. LeftMin string `description:"图表左侧最小值"`
  2480. LeftMax string `description:"图表左侧最大值"`
  2481. RightMin string `description:"图表右侧最小值"`
  2482. RightMax string `description:"图表右侧最大值"`
  2483. Right2Min string `description:"图表右侧最小值"`
  2484. Right2Max string `description:"图表右侧最大值"`
  2485. }
  2486. // 系列里的指标日期配置
  2487. type ChartSectionSeriesDateConfItem struct {
  2488. MoveForward int `description:"前移的期数"`
  2489. DateChange []*ChartSectionDateChange
  2490. }
  2491. // PreviewSectionCombineChartReq 预览截面组合图的请求
  2492. type PreviewSectionCombineChartReq struct {
  2493. ChartName string `description:"图表名称"`
  2494. ChartClassifyId int `description:"分类id"`
  2495. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  2496. }
  2497. type ChartSectionCombineUnit struct {
  2498. LeftName string `description:"左轴单位"`
  2499. LeftNameEn string `description:"左轴英文单位"`
  2500. RightName string `description:"右轴单位"`
  2501. RightNameEn string `description:"右轴英文单位"`
  2502. RightTwoName string `description:"右2轴单位"`
  2503. RightTwoNameEn string `description:"右2轴英文单位"`
  2504. }
  2505. // 时序组合图额外配置
  2506. type ChartTimeCombineExtraConf struct {
  2507. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  2508. }
  2509. type ChartTimeCombineDataResp struct {
  2510. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  2511. }
  2512. type PreviewSectionCombineDateCalculateResp struct {
  2513. Date string
  2514. }
  2515. type PreviewSectionCombineDateCalculateReq struct {
  2516. MoveForward int `description:"前移的期数"`
  2517. EdbInfoId int `description:"指标ID"`
  2518. Frequency string `description:"频度"`
  2519. DateConfName string `description:"引用日期名称"` // 引用日期名称不能重复
  2520. DateChange []*ChartSectionDateChange
  2521. DateConfList []*ChartSectionDateConfItem
  2522. DateType int `description:"日期类型,0指标最新日期, 1引用日期"`
  2523. }
  2524. // ChartInfoSourcesFrom 图表来源
  2525. type ChartInfoSourcesFrom struct {
  2526. IsShow bool `description:"是否展示" json:"isShow"`
  2527. Text string `description:"来源文本" json:"text"`
  2528. Color string `description:"来源颜色" json:"color"`
  2529. FontSize int `description:"来源字号" json:"fontSize"`
  2530. }
  2531. // UpdateChartInfoSortByClassifyIdV2 根据分类id更新排序
  2532. func UpdateChartInfoSortByClassifyIdV2(classifyId, nowSort int, prevChartInfoId int, updateSort string) (err error) {
  2533. o := global.DmSQL["data"]
  2534. sql := ` update chart_info set sort = ` + updateSort + ` WHERE chart_classify_id = ?`
  2535. if prevChartInfoId > 0 {
  2536. sql += ` AND ( sort > ? or ( chart_info_id > ` + fmt.Sprint(prevChartInfoId) + ` and sort=` + fmt.Sprint(nowSort) + ` )) `
  2537. } else {
  2538. sql += ` AND ( sort > ? )`
  2539. }
  2540. err = o.Exec(sql, classifyId, nowSort).Error
  2541. return
  2542. }
  2543. // GetChartInfoMaxSortByClassifyId 获取分类下指标的最大的排序数
  2544. func GetChartInfoMaxSortByClassifyId(classifyId int) (sort int, err error) {
  2545. o := global.DmSQL["data"]
  2546. sql := `SELECT COALESCE(MAX(sort),0) AS sort FROM chart_info WHERE chart_classify_id = ? `
  2547. err = o.Raw(sql, classifyId).Scan(&sort).Error
  2548. return
  2549. }
  2550. // GetChartInfoBySourceAndParentId 根据图表来源及父级ID获取图表
  2551. func GetChartInfoBySourceAndParentId(source, parentId, adminId int) (items []*ChartClassifyItems, err error) {
  2552. o := global.DmSQL["data"]
  2553. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,chart_name_en AS chart_classify_name_en,
  2554. 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
  2555. FROM chart_info WHERE source = ? AND chart_classify_id = ?`
  2556. pars := make([]interface{}, 0)
  2557. pars = append(pars, source, parentId)
  2558. if adminId > 0 {
  2559. sql += ` AND sys_user_id = ?`
  2560. pars = append(pars, adminId)
  2561. }
  2562. sql += ` ORDER BY sort asc,chart_info_id ASC `
  2563. err = o.Raw(sql, pars...).Scan(&items).Error
  2564. return
  2565. }
  2566. // PreviewSeasonChartReq 预览季节性图的请求入参
  2567. type PreviewSeasonChartReq struct {
  2568. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  2569. SeasonExtraConfig SeasonExtraItem `description:"季节图额外配置信息,json字符串"`
  2570. }
  2571. // EditChartInfoImageV2
  2572. // @Description: 修改图表的缩略图
  2573. // @author: Roc
  2574. // @datetime 2024-07-09 10:52:34
  2575. // @param chartInfoId int
  2576. // @param imageUrl string
  2577. // @return err error
  2578. func EditChartInfoImageV2(chartInfoId int, imageUrl string) (err error) {
  2579. o := global.DmSQL["data"]
  2580. sql := ` UPDATE chart_info SET chart_image=?, modify_time = NOW() WHERE chart_info_id = ? `
  2581. err = o.Exec(sql, imageUrl, chartInfoId).Error
  2582. if err != nil {
  2583. fmt.Println("EditChartInfoImageV2 Err:", err.Error())
  2584. return err
  2585. }
  2586. return
  2587. }
  2588. func getThsHfEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  2589. list = make([]*EdbDataList, 0)
  2590. mogDataObj := mgo.EdbDataThsHf{}
  2591. // 构建查询条件
  2592. queryConditions := bson.M{
  2593. "edb_info_id": edbInfoId,
  2594. }
  2595. // 数据日期
  2596. dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
  2597. if err != nil {
  2598. return
  2599. }
  2600. if len(dateCondition) > 0 {
  2601. queryConditions["data_time"] = dateCondition
  2602. }
  2603. // 获取列表数据
  2604. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
  2605. if tmpErr != nil {
  2606. err = tmpErr
  2607. return
  2608. }
  2609. for k, v := range tmpDataList {
  2610. list = append(list, &EdbDataList{
  2611. EdbDataId: k + 1,
  2612. EdbInfoId: v.EdbInfoId,
  2613. DataTime: v.DataTime.Format(utils.FormatDate),
  2614. DataTimestamp: v.DataTimestamp,
  2615. Value: v.Value,
  2616. })
  2617. }
  2618. return
  2619. }
  2620. func getThsHfEdbDataListMinAndMaxByMongo(source, subSource, edbInfoId int, startDate, endDate string) (minData, maxData float64, err error) {
  2621. mogDataObj := mgo.EdbDataThsHf{}
  2622. // 构建查询条件
  2623. queryConditions := bson.M{
  2624. "edb_info_id": edbInfoId,
  2625. }
  2626. // 日期
  2627. dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
  2628. if err != nil {
  2629. return
  2630. }
  2631. if len(dateCondition) > 0 {
  2632. queryConditions["data_time"] = dateCondition
  2633. }
  2634. pipeline := []bson.M{
  2635. {"$match": queryConditions},
  2636. {"$group": bson.M{
  2637. "_id": nil,
  2638. "min_value": bson.M{"$min": "$value"},
  2639. "max_value": bson.M{"$max": "$value"},
  2640. }},
  2641. {"$project": bson.M{"_id": 0}}, // 可选,如果不需要_id字段
  2642. }
  2643. result, err := mogDataObj.GetEdbInfoMaxAndMinInfo(pipeline)
  2644. if err != nil {
  2645. return
  2646. }
  2647. minData = result.MinValue
  2648. maxData = result.MaxValue
  2649. return
  2650. }
  2651. // UpdateClassifyIdByChartInfoIdList
  2652. // @Description: 根据图表id列表更新所属分类id
  2653. // @author: Roc
  2654. // @datetime 2024-12-10 13:18:52
  2655. // @param chartInfoIdList int
  2656. // @param chartClassifyId int
  2657. // @return err error
  2658. func UpdateClassifyIdByChartInfoIdList(chartInfoIdList []int, chartClassifyId int) (err error) {
  2659. if len(chartInfoIdList) <= 0 {
  2660. return
  2661. }
  2662. sql := ` UPDATE chart_info SET chart_classify_id = ? WHERE chart_info_id in (?) `
  2663. err = global.DmSQL["data"].Exec(sql, chartClassifyId, chartInfoIdList).Error
  2664. return
  2665. }
  2666. // UpdateChartInfoPublicSortByClassifyId
  2667. // @Description: 根据公共分类id更新图表公共排序
  2668. // @param classifyId
  2669. // @param nowSort
  2670. // @param prevChartInfoId
  2671. // @param updateSort
  2672. // @param source
  2673. // @return err
  2674. func UpdateChartInfoPublicSortByClassifyId(classifyId, nowSort int, prevChartInfoId int, updateSort string, source int) (err error) {
  2675. sql := ` update chart_info set sort = ` + updateSort + ` WHERE chart_public_classify_id=? AND public_status = 3 AND source = ? `
  2676. if prevChartInfoId > 0 {
  2677. sql += ` AND ( public_sort > ? or ( chart_info_id > ` + fmt.Sprint(prevChartInfoId) + ` and public_sort=` + fmt.Sprint(nowSort) + ` )) `
  2678. } else {
  2679. sql += ` AND ( public_sort > ? )`
  2680. }
  2681. err = global.DmSQL["data"].Exec(sql, classifyId, nowSort, source).Error
  2682. return
  2683. }
  2684. // GetFirstChartInfoByPublicClassifyId
  2685. // @Description: 获取当前公共分类下,且排序数相同 的排序第一条的图表数据
  2686. // @param classifyId
  2687. // @return item
  2688. // @return err
  2689. func GetFirstChartInfoByPublicClassifyId(classifyId int) (item *ChartInfo, err error) {
  2690. 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`
  2691. err = global.DmSQL["data"].Raw(sql, classifyId).First(&item).Error
  2692. return
  2693. }