chart_info.go 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396
  1. package data_manage
  2. import (
  3. "errors"
  4. "eta/eta_api/models/mgo"
  5. "eta/eta_api/utils"
  6. "fmt"
  7. "github.com/beego/beego/v2/client/orm"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "go.mongodb.org/mongo-driver/bson"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. type ChartInfo struct {
  15. ChartInfoId int `orm:"column(chart_info_id);pk"`
  16. ChartName string `description:"图表名称"`
  17. ChartNameEn string `description:"英文图表名称"`
  18. ChartClassifyId int `description:"图表分类id"`
  19. SysUserId int
  20. SysUserRealName string
  21. UniqueCode string `description:"图表唯一编码"`
  22. CreateTime time.Time
  23. ModifyTime time.Time
  24. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  25. StartDate string `description:"自定义开始日期"`
  26. EndDate string `description:"自定义结束日期"`
  27. IsSetName int `description:"设置名称"`
  28. EdbInfoIds string `description:"指标id"`
  29. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图,10:截面散点图, 11:雷达图"`
  30. Calendar string `description:"公历/农历"`
  31. SeasonStartDate string `description:"季节性图开始日期"`
  32. SeasonEndDate string `description:"季节性图开始日期"`
  33. ChartImage string `description:"图表图片"`
  34. Sort int `description:"排序字段,数字越小越排前面"`
  35. XMin string `description:"图表X轴最小值"`
  36. XMax string `description:"图表X轴最大值"`
  37. LeftMin string `description:"图表左侧最小值"`
  38. LeftMax string `description:"图表左侧最大值"`
  39. RightMin string `description:"图表右侧最小值"`
  40. RightMax string `description:"图表右侧最大值"`
  41. Right2Min string `description:"图表右侧2最小值"`
  42. Right2Max string `description:"图表右侧2最大值"`
  43. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  44. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  45. BarConfig string `description:"柱方图的配置,json数据"`
  46. Source int `description:"1:ETA图库;2:商品价格曲线"`
  47. ExtraConfig string `description:"图表额外配置,json数据"`
  48. SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  49. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  50. ChartThemeId int `description:"图表应用主题ID"`
  51. SourcesFrom string `description:"图表来源"`
  52. Instructions string `description:"图表说明"`
  53. MarkersLines string `description:"标识线"`
  54. MarkersAreas string `description:"标识区"`
  55. Unit string `description:"中文单位名称"`
  56. UnitEn string `description:"英文单位名称"`
  57. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  58. ForumChartInfoId int `description:"社区的图表ID"`
  59. }
  60. type ChartInfoMore struct {
  61. ChartInfo
  62. IsEnChart bool `description:"是否展示英文标识"`
  63. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  64. }
  65. func AddChartInfo(item *ChartInfo) (lastId int64, err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. lastId, err = o.Insert(item)
  68. return
  69. }
  70. type ChartInfoItem struct {
  71. ChartInfoId int `description:"图表id"`
  72. ChartName string `description:"图表名称"`
  73. ChartClassifyId int `description:"图表分类"`
  74. }
  75. // GetChartInfoAll 用于分类展示
  76. // @param source int 1:ETA图库;2:商品价格曲线
  77. func GetChartInfoAll(sourceList []int) (items []*ChartClassifyItems, err error) {
  78. num := len(sourceList)
  79. if num <= 0 {
  80. return
  81. }
  82. o := orm.NewOrmUsingDB("data")
  83. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,chart_name_en AS chart_classify_name_en,
  84. 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
  85. FROM chart_info WHERE source in (` + utils.GetOrmInReplace(num) + `) ORDER BY sort asc,chart_info_id ASC `
  86. _, err = o.Raw(sql, sourceList).QueryRows(&items)
  87. return
  88. }
  89. // GetChartInfoByAdminId 获取所有我创建的图表,用于分类展示
  90. func GetChartInfoByAdminId(sourceList []int, adminId int) (items []*ChartClassifyItems, err error) {
  91. num := len(sourceList)
  92. if num <= 0 {
  93. return
  94. }
  95. o := orm.NewOrmUsingDB("data")
  96. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
  97. unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date
  98. FROM chart_info where source in (` + utils.GetOrmInReplace(num) + `) AND sys_user_id = ? ORDER BY sort asc,create_time ASC `
  99. _, err = o.Raw(sql, sourceList, adminId).QueryRows(&items)
  100. return
  101. }
  102. // 用于分类展示
  103. func GetChartInfoAllList() (items []*ChartInfo, err error) {
  104. o := orm.NewOrmUsingDB("data")
  105. sql := ` SELECT *
  106. FROM chart_info ORDER BY create_time ASC `
  107. _, err = o.Raw(sql).QueryRows(&items)
  108. return
  109. }
  110. // 图表检索数据
  111. type ChartInfoSearch struct {
  112. EdbCode string `description:"图表编码"`
  113. StartDate string `description:"起始日期"`
  114. EndDate string `description:"终止日期"`
  115. DataList []*EdbInfoSearchData
  116. }
  117. type ChartInfoSearchData struct {
  118. DataTime string `description:"数据日期"`
  119. Value float64 `description:"数据"`
  120. }
  121. type ChartInfoSearchResp struct {
  122. SearchItem *EdbInfoSearch `description:"图表分类"`
  123. Status int `description:"1:数据已存在于弘则数据库,2:新数据"`
  124. }
  125. func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
  126. o := orm.NewOrmUsingDB("data")
  127. sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  128. err = o.Raw(sql, chartInfoId).QueryRow(&item)
  129. return
  130. }
  131. func GetChartInfoViewById(chartInfoId int) (item *ChartInfoView, err error) {
  132. o := orm.NewOrmUsingDB("data")
  133. sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  134. err = o.Raw(sql, chartInfoId).QueryRow(&item)
  135. return
  136. }
  137. func GetChartInfoViewByIds(chartInfoIds []string) (list []*ChartInfoView, err error) {
  138. o := orm.NewOrmUsingDB("data")
  139. sql := ` SELECT * FROM chart_info WHERE chart_info_id in ("` + strings.Join(chartInfoIds, `","`) + `") `
  140. _, err = o.Raw(sql).QueryRows(&list)
  141. return
  142. }
  143. type SaveChartInfoReq struct {
  144. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  145. ChartInfoId int `description:"图表id,新增时传0"`
  146. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  147. StartDate string `description:"自定义开始日期"`
  148. EndDate string `description:"自定义结束日期"`
  149. Calendar string `description:"公历/农历"`
  150. LeftMin string `description:"图表左侧最小值"`
  151. LeftMax string `description:"图表左侧最大值"`
  152. RightMin string `description:"图表右侧最小值"`
  153. RightMax string `description:"图表右侧最大值"`
  154. Right2Min string `description:"图表右侧最小值"`
  155. Right2Max string `description:"图表右侧最大值"`
  156. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  157. ExtraConfig string `description:"图表额外配置,json数据"`
  158. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  159. }
  160. type ChartSaveItem struct {
  161. EdbInfoId int `description:"指标id"`
  162. MaxData float64 `description:"上限"`
  163. MinData float64 `description:"下限"`
  164. IsOrder bool `description:"true:正序,false:逆序"`
  165. IsAxis int `description:"1:左轴,0:右轴"`
  166. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  167. LeadValue int `description:"领先值"`
  168. LeadUnit string `description:"领先单位"`
  169. ChartStyle string `description:"图表类型"`
  170. ChartColor string `description:"颜色"`
  171. PredictChartColor string `description:"预测数据的颜色"`
  172. ChartWidth float64 `description:"线条大小"`
  173. Source int `description:"1:ETA图库;2:商品价格曲线"`
  174. EdbAliasName string `description:"中文别名"`
  175. IsConvert int `description:"是否数据转换 0不转 1转"`
  176. ConvertType int `description:"数据转换类型 1乘 2除 3对数"`
  177. ConvertValue float64 `description:"数据转换值"`
  178. ConvertUnit string `description:"数据转换单位"`
  179. ConvertEnUnit string `description:"数据转换单位"`
  180. }
  181. func DeleteChartInfoAndData(chartInfoId int) (err error) {
  182. o := orm.NewOrmUsingDB("data")
  183. to, err := o.Begin()
  184. if err != nil {
  185. return
  186. }
  187. defer func() {
  188. if err != nil {
  189. _ = to.Rollback()
  190. } else {
  191. _ = to.Commit()
  192. }
  193. }()
  194. sql := ` DELETE FROM chart_info WHERE chart_info_id=? `
  195. _, err = to.Raw(sql, chartInfoId).Exec()
  196. if err != nil {
  197. return
  198. }
  199. sql = ` DELETE FROM chart_edb_mapping WHERE chart_info_id=? `
  200. _, err = to.Raw(sql, chartInfoId).Exec()
  201. return
  202. }
  203. func GetChartInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  204. o := orm.NewOrmUsingDB("data")
  205. sql := ` SELECT COUNT(1) AS count FROM chart_info WHERE 1=1 `
  206. if condition != "" {
  207. sql += condition
  208. }
  209. err = o.Raw(sql, pars).QueryRow(&count)
  210. return
  211. }
  212. type EditChartInfoReq struct {
  213. ChartInfoId int `description:"图表ID"`
  214. ChartName string `description:"图表名称"`
  215. ChartNameEn string `description:"英文图表名称"`
  216. ChartClassifyId int `description:"分类id"`
  217. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  218. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图,10:截面散点图"`
  219. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今,20:N年至今"`
  220. StartDate string `description:"自定义开始日期"`
  221. EndDate string `description:"自定义结束日期"`
  222. Calendar string `description:"公历/农历"`
  223. LeftMin string `description:"图表左侧最小值"`
  224. LeftMax string `description:"图表左侧最大值"`
  225. RightMin string `description:"图表右侧最小值"`
  226. RightMax string `description:"图表右侧最大值"`
  227. Right2Min string `description:"图表右侧最小值"`
  228. Right2Max string `description:"图表右侧最大值"`
  229. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  230. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  231. CorrelationChartInfo CorrelationChartInfoReq `description:"相关性图表配置"`
  232. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  233. SeasonExtraConfig SeasonExtraItem `description:"季节性图表中的配置,json数据"`
  234. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  235. ChartThemeId int `description:"图表应用主题ID"`
  236. SourcesFrom string `description:"图表来源"`
  237. Instructions string `description:"图表说明"`
  238. MarkersLines string `description:"标识线"`
  239. MarkersAreas string `description:"标识区"`
  240. Unit string `description:"中文单位名称"`
  241. UnitEn string `description:"英文单位名称"`
  242. }
  243. type EditFutureGoodChartInfoReq struct {
  244. EditChartInfoReq
  245. BarChartInfo FutureGoodBarChartInfoReq
  246. }
  247. type EditChartEnInfoReq struct {
  248. ChartInfoId int `description:"图表ID"`
  249. ChartNameEn string `description:"英文图表名称"`
  250. ChartEdbInfoList []*EditChartEnInfoEdbItem `description:"指标及配置信息"`
  251. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  252. }
  253. type EditChartEnInfoEdbItem struct {
  254. EdbInfoId int `description:"指标ID"`
  255. EdbNameEn string `description:"英文指标名称"`
  256. UnitEn string `description:"英文单位"`
  257. }
  258. // EditChartInfoBaseReq
  259. // @Description: 图表基础信息修改
  260. type EditChartInfoBaseReq struct {
  261. ChartInfoId int `description:"图表ID"`
  262. ChartName string `description:"图表名称(根据语言版本区分)"`
  263. ChartEdbInfoList []*EditChartInfoEdbBaseItem `description:"指标及配置信息"`
  264. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  265. }
  266. type EditChartInfoEdbBaseItem struct {
  267. EdbInfoId int `description:"指标ID"`
  268. EdbName string `description:"指标名称(根据语言版本区分)"`
  269. Unit string `description:"单位(根据语言版本区分)"`
  270. }
  271. func ModifyChartInfo(item *EditChartInfoReq) (err error) {
  272. o := orm.NewOrmUsingDB("data")
  273. sql := ` UPDATE chart_info
  274. SET
  275. chart_name =?,
  276. chart_classify_id = ?,
  277. is_set_name=1,
  278. modify_time = NOW()
  279. WHERE chart_info_id = ?`
  280. _, err = o.Raw(sql, item.ChartName, item.ChartClassifyId, item.ChartInfoId).Exec()
  281. return
  282. }
  283. func SetForumChartInfoId(chartInfoId, forumChartInfoId int) (err error) {
  284. o := orm.NewOrmUsingDB("data")
  285. sql := ` UPDATE chart_info
  286. SET
  287. forum_chart_info_id=?,
  288. modify_time = NOW()
  289. WHERE chart_info_id = ?`
  290. _, err = o.Raw(sql, forumChartInfoId, chartInfoId).Exec()
  291. return
  292. }
  293. type ChartInfoList struct {
  294. ChartInfoId int `orm:"column(chart_info_id);pk"`
  295. ChartName string `description:"来源名称"`
  296. ChartChartClassifyId int `description:"图表分类id"`
  297. SysUserId int
  298. SysUserRealName string
  299. UniqueCode string `description:"图表唯一编码"`
  300. CreateTime time.Time
  301. ModifyTime time.Time
  302. EdbInfoList []*EdbInfoList
  303. }
  304. type ChartInfoListResp struct {
  305. Paging *paging.PagingItem
  306. Item *ChartInfoList
  307. }
  308. func GetChartInfoByCondition(condition string, pars []interface{}) (item *ChartInfo, err error) {
  309. o := orm.NewOrmUsingDB("data")
  310. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  311. if condition != "" {
  312. sql += condition
  313. }
  314. err = o.Raw(sql, pars).QueryRow(&item)
  315. return
  316. }
  317. func GetChartInfoByNewest(source int) (item *ChartInfoList, err error) {
  318. o := orm.NewOrmUsingDB("data")
  319. sql := ` SELECT * FROM chart_info WHERE 1=1 AND source = ? ORDER BY modify_time DESC LIMIT 1 `
  320. err = o.Raw(sql, source).QueryRow(&item)
  321. return
  322. }
  323. func ModifyChartInfoModifyTime(chartInfoId int64) (err error) {
  324. o := orm.NewOrmUsingDB("data")
  325. sql := ` UPDATE chart_info SET modify_time = NOW() WHERE chart_info_id = ? `
  326. _, err = o.Raw(sql, chartInfoId).Exec()
  327. return
  328. }
  329. type MoveChartInfoReq struct {
  330. ChartInfoId int `description:"图表ID"`
  331. PrevChartInfoId int `description:"上一个图表ID"`
  332. NextChartInfoId int `description:"下一个图表ID"`
  333. ChartClassifyId int `description:"分类id"`
  334. }
  335. func MoveChartInfo(chartInfoId, classifyId int) (err error) {
  336. o := orm.NewOrmUsingDB("data")
  337. sql := ` UPDATE chart_info
  338. SET
  339. chart_classify_id = ?
  340. WHERE chart_info_id = ?`
  341. _, err = o.Raw(sql, classifyId, chartInfoId).Exec()
  342. return
  343. }
  344. type DeleteChartInfoReq struct {
  345. ChartInfoId int `description:"图表ID"`
  346. }
  347. type EdbDataList struct {
  348. EdbDataId int `description:" 指标数据ID"`
  349. EdbInfoId int `description:"指标ID"`
  350. DataTime string //`json:"-" description:"数据日期"`
  351. DataTimestamp int64 `description:"数据日期"`
  352. Value float64 `description:"数据值"`
  353. }
  354. // GetEdbDataList
  355. // @Description: 获取指标的数据(日期正序返回)
  356. // @author: Roc
  357. // @datetime 2024-05-07 10:48:43
  358. // @param source int
  359. // @param subSource int
  360. // @param edbInfoId int
  361. // @param startDate string
  362. // @param endDate string
  363. // @return list []*EdbDataList
  364. // @return err error
  365. func GetEdbDataList(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  366. // 自有数据需要额外处理(从mongo获取)
  367. if source == utils.DATA_SOURCE_BUSINESS {
  368. return getEdbDataListByMongo(source, subSource, edbInfoId, startDate, endDate)
  369. }
  370. return getEdbDataListByMysql(source, subSource, edbInfoId, startDate, endDate)
  371. }
  372. // getEdbDataListByMysql
  373. // @Description: 通过mysql查询指标数据
  374. // @author: Roc
  375. // @datetime 2024-05-07 10:40:43
  376. // @param source int
  377. // @param subSource int
  378. // @param edbInfoId int
  379. // @param startDate string
  380. // @param endDate string
  381. // @return list []*EdbDataList
  382. // @return err error
  383. func getEdbDataListByMysql(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  384. tableName := GetEdbDataTableName(source, subSource)
  385. if tableName == "" {
  386. err = errors.New("无效的渠道:" + strconv.Itoa(source))
  387. list = make([]*EdbDataList, 0)
  388. return list, err
  389. }
  390. var pars []interface{}
  391. sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
  392. if startDate != "" {
  393. sql += ` AND data_time>=? `
  394. pars = append(pars, startDate)
  395. }
  396. if endDate != "" {
  397. sql += ` AND data_time<=? `
  398. pars = append(pars, endDate)
  399. }
  400. sql += ` ORDER BY data_time ASC `
  401. sql = fmt.Sprintf(sql, tableName)
  402. o := orm.NewOrmUsingDB("data")
  403. _, err = o.Raw(sql, edbInfoId, pars).QueryRows(&list)
  404. return
  405. }
  406. // getEdbDataListByMongo
  407. // @Description: 通过mongo查询指标数据
  408. // @author: Roc
  409. // @datetime 2024-05-07 10:40:43
  410. // @param source int
  411. // @param subSource int
  412. // @param endInfoId int
  413. // @param startDate string
  414. // @param endDate string
  415. // @return list []*EdbDataList
  416. // @return err error
  417. func getEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  418. list = make([]*EdbDataList, 0)
  419. mogDataObj := mgo.EdbDataBusiness{}
  420. // 构建查询条件
  421. queryConditions := bson.M{
  422. "edb_info_id": edbInfoId,
  423. }
  424. // 数据日期
  425. dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
  426. if err != nil {
  427. return
  428. }
  429. if len(dateCondition) > 0 {
  430. queryConditions["data_time"] = dateCondition
  431. }
  432. // 获取列表数据
  433. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
  434. if tmpErr != nil {
  435. err = tmpErr
  436. return
  437. }
  438. for k, v := range tmpDataList {
  439. list = append(list, &EdbDataList{
  440. EdbDataId: k + 1,
  441. EdbInfoId: v.EdbInfoId,
  442. DataTime: v.DataTime.Format(utils.FormatDate),
  443. DataTimestamp: v.DataTimestamp,
  444. Value: v.Value,
  445. })
  446. }
  447. return
  448. }
  449. type EdbDataListByUniqueCode struct {
  450. EdbDataId int `description:" 指标数据ID" json:"-"`
  451. EdbInfoId int `description:"指标ID" json:"-"`
  452. DataTime string //`json:"-" description:"数据日期"`
  453. DataTimestamp int64 `description:"数据日期"`
  454. Value float64 `description:"数据值"`
  455. }
  456. func GetEdbDataLunarList(endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  457. tableName := "edb_data_quarter"
  458. 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 `
  459. sql = fmt.Sprintf(sql, tableName)
  460. o := orm.NewOrmUsingDB("data")
  461. _, err = o.Raw(sql, endInfoId, startDate, endDate).QueryRows(&list)
  462. return
  463. }
  464. // GetEdbDataListMinAndMax
  465. // @Description: 根据条件数据库中获取指标数据最小值和最大值
  466. // @author: Roc
  467. // @datetime 2024-05-07 13:11:32
  468. // @param source int
  469. // @param subSource int
  470. // @param edbInfoId int
  471. // @param startDate string
  472. // @param endDate string
  473. // @return min_data float64
  474. // @return max_data float64
  475. // @return err error
  476. func GetEdbDataListMinAndMax(source, subSource, edbInfoId int, startDate, endDate string) (min_data, max_data float64, err error) {
  477. // 自有数据需要额外处理(从mongo获取)
  478. if source == utils.DATA_SOURCE_BUSINESS {
  479. return getEdbDataListMinAndMaxByMongo(source, subSource, edbInfoId, startDate, endDate)
  480. }
  481. return getEdbDataListMinAndMaxByMysql(source, subSource, edbInfoId, startDate, endDate)
  482. }
  483. // getEdbDataListMinAndMaxByMysql
  484. // @Description: 根据条件从mysql数据库中获取指标数据最小值和最大值
  485. // @author: Roc
  486. // @datetime 2024-05-07 13:11:22
  487. // @param source int
  488. // @param subSource int
  489. // @param edbInfoId int
  490. // @param startDate string
  491. // @param endDate string
  492. // @return minData float64
  493. // @return maxData float64
  494. // @return err error
  495. func getEdbDataListMinAndMaxByMysql(source, subSource, edbInfoId int, startDate, endDate string) (minData, maxData float64, err error) {
  496. tableName := GetEdbDataTableName(source, subSource)
  497. sql := `SELECT min(value) AS min_data,max(value) AS max_data FROM %s WHERE edb_info_id=? `
  498. var pars []interface{}
  499. var condition string
  500. if startDate != "" {
  501. condition += ` AND data_time>=? `
  502. pars = append(pars, startDate)
  503. }
  504. if endDate != "" {
  505. condition += ` AND data_time<=? `
  506. pars = append(pars, endDate)
  507. }
  508. sql = fmt.Sprintf(sql, tableName)
  509. o := orm.NewOrmUsingDB("data")
  510. if condition != "" {
  511. sql += condition
  512. }
  513. err = o.Raw(sql, edbInfoId, pars).QueryRow(&minData, &maxData)
  514. return
  515. }
  516. // getEdbDataListMinAndMaxByMongo
  517. // @Description: 根据条件从mongo数据库中获取指标数据最小值和最大值
  518. // @author: Roc
  519. // @datetime 2024-05-07 13:10:26
  520. // @param source int
  521. // @param subSource int
  522. // @param edbInfoId int
  523. // @param startDate string
  524. // @param endDate string
  525. // @return minData float64
  526. // @return maxData float64
  527. // @return err error
  528. func getEdbDataListMinAndMaxByMongo(source, subSource, edbInfoId int, startDate, endDate string) (minData, maxData float64, err error) {
  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. pipeline := []bson.M{
  543. {"$match": queryConditions},
  544. {"$group": bson.M{
  545. "_id": nil,
  546. "min_value": bson.M{"$min": "$value"},
  547. "max_value": bson.M{"$max": "$value"},
  548. }},
  549. {"$project": bson.M{"_id": 0}}, // 可选,如果不需要_id字段
  550. }
  551. result, err := mogDataObj.GetEdbInfoMaxAndMinInfo(pipeline)
  552. if err != nil {
  553. return
  554. }
  555. minData = result.MinValue
  556. maxData = result.MaxValue
  557. return
  558. }
  559. type ChartEdbInfoMapping struct {
  560. EdbInfoId int `description:"指标id"`
  561. SourceName string `description:"来源名称"`
  562. Source int `description:"来源id"`
  563. SubSource int `description:"来源id"`
  564. EdbCode string `description:"指标编码"`
  565. EdbName string `description:"指标名称"`
  566. EdbAliasName string `description:"指标名称(别名)"`
  567. EdbNameEn string `description:"英文指标名称"`
  568. EdbAliasNameEn string `description:"英文指标名称(别名)"`
  569. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  570. Frequency string `description:"频率"`
  571. FrequencyEn string `description:"英文频率"`
  572. Unit string `description:"单位"`
  573. UnitEn string `description:"英文单位"`
  574. StartDate string `description:"起始日期"`
  575. EndDate string `description:"终止日期"`
  576. ModifyTime string `description:"指标最后更新时间"`
  577. ChartEdbMappingId int `description:"图表指标id"`
  578. ChartInfoId int `description:"图表id"`
  579. MaxData float64 `description:"上限"`
  580. MinData float64 `description:"下限"`
  581. IsOrder bool `description:"true:正序,false:逆序"`
  582. IsAxis int `description:"1:左轴,0:右轴"`
  583. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  584. EdbInfoCategoryType int `description:"0:普通指标,1:预测指标"`
  585. LeadValue int `description:"领先值"`
  586. LeadUnit string `description:"领先单位"`
  587. LeadUnitEn string `description:"领先英文单位"`
  588. ChartStyle string `description:"图表类型"`
  589. ChartColor string `description:"颜色"`
  590. PredictChartColor string `description:"预测数据的颜色"`
  591. ChartWidth float64 `description:"线条大小"`
  592. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图"`
  593. LatestDate string `description:"数据最新日期"`
  594. LatestValue float64 `description:"数据最新值"`
  595. MoveLatestDate string `description:"移动后的数据最新日期"`
  596. UniqueCode string `description:"指标唯一编码"`
  597. MinValue float64 `json:"-" description:"最小值"`
  598. MaxValue float64 `json:"-" description:"最大值"`
  599. DataList interface{}
  600. IsNullData bool `json:"-" description:"是否空数据"`
  601. MappingSource int `description:"1:ETA图库;2:商品价格曲线"`
  602. RegionType string `description:"交易所来源,海外还是国内" json:"-"`
  603. ClassifyId int `description:"分类id"`
  604. SubSourceName string `description:"子数据来源名称"`
  605. IndicatorCode string `description:"指标代码"`
  606. IsConvert int `description:"是否数据转换 0不转 1转"`
  607. ConvertType int `description:"数据转换类型 1乘 2除 3对数"`
  608. ConvertValue float64 `description:"数据转换值"`
  609. ConvertUnit string `description:"数据转换单位"`
  610. ConvertEnUnit string `description:"数据转换单位"`
  611. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  612. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  613. }
  614. type QuarterData struct {
  615. Year int
  616. DataList []*EdbDataList
  617. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  618. ChartLegend string
  619. Years string
  620. }
  621. type QuarterXDateItem struct {
  622. StartDate time.Time
  623. EndDate time.Time
  624. ShowName string
  625. ChartLegend string
  626. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  627. }
  628. type QuarterDataByUniqueCode struct {
  629. Year int
  630. DataList []*EdbDataListByUniqueCode
  631. }
  632. type ChartEdbInfoDetailResp struct {
  633. EdbInfo *ChartEdbInfoMapping
  634. }
  635. type ChartInfoDetailResp struct {
  636. ChartInfo *ChartInfoView
  637. EdbInfoList []*ChartEdbInfoMapping
  638. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  639. YDataList []YData `description:"柱方图的y轴数据"`
  640. XDataList []XData `description:"商品价格曲线的X轴数据"`
  641. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  642. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  643. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  644. }
  645. type FutureGoodChartInfoDetailResp struct {
  646. ChartInfo *ChartInfoView
  647. EdbInfoList []*ChartEdbInfoMapping
  648. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  649. YDataList []YData `description:"柱方图的y轴数据"`
  650. XDataList []XData `description:"商品价格曲线的X轴数据"`
  651. BarChartInfo FutureGoodBarChartInfoReq `description:"柱方图的配置"`
  652. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  653. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  654. }
  655. type BalanceTableChartListResp struct {
  656. List []*BalanceChartInfoDetailResp
  657. }
  658. type BalanceChartInfoDetailResp struct {
  659. *ChartInfoDetailResp
  660. ExcelEdbList []*ExcelChartEdbView
  661. }
  662. type ExcelChartEdbView struct {
  663. ExcelChartEdbId int
  664. DateSequenceStr string `description:"日期序列选区"`
  665. DataSequenceStr string `description:"数据序列选区"`
  666. FromTag string `description:"标签"`
  667. }
  668. // XData 商品价格曲线的的x轴数据
  669. type XData struct {
  670. Name string `description:"别名"`
  671. NameEn string `description:"英文别名"`
  672. IsHide int `description:"是否隐藏,0不隐藏,1隐藏"`
  673. }
  674. // YData 柱方图的y轴数据
  675. type YData struct {
  676. Date string `description:"数据日期"`
  677. ConfigDate time.Time `description:"配置的日期" json:"-"`
  678. Color string `description:"数据颜色"`
  679. Name string `description:"别名"`
  680. NameEn string `description:"英文别名"`
  681. Value []float64 `description:"每个指标的值"`
  682. NoDataEdbList []int `description:"没有数据的指标列表"`
  683. XEdbInfoIdList []int `description:"对应X轴的指标id列表"`
  684. NameList []string `description:"每个值对应的名称"`
  685. EnNameList []string `description:"每个值对应的英文名称"`
  686. EdbValMap map[int]float64 `description:"指标与值的对应" json:"-"`
  687. M []int `description:"对应开始日期的间隔值" json:"-"`
  688. Unit string `description:"中文单位名称"`
  689. UnitEn string `description:"英文单位名称"`
  690. }
  691. func ModifyChartInfoAndMapping(edbInfoIdStr string, req *SaveChartInfoReq, chartType int) (err error) {
  692. o := orm.NewOrmUsingDB("data")
  693. to, err := o.Begin()
  694. if err != nil {
  695. return
  696. }
  697. defer func() {
  698. if err != nil {
  699. _ = to.Rollback()
  700. } else {
  701. _ = to.Commit()
  702. }
  703. }()
  704. //非季节图
  705. if chartType != 2 {
  706. updateStr := `edb_info_ids=?,
  707. modify_time = NOW(),
  708. date_type=?,
  709. start_date=?,
  710. end_date=?,
  711. left_min=?,
  712. left_max=?,
  713. right_min=?,
  714. right_max=?,
  715. right2_min=?,
  716. right2_max=?,
  717. min_max_save=?,
  718. start_year=?`
  719. 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}
  720. if req.ExtraConfig != `` {
  721. updateStr += `,extra_config=? `
  722. pars = append(pars, req.ExtraConfig)
  723. }
  724. pars = append(pars, req.ChartInfoId)
  725. sql := ` UPDATE chart_info SET ` + updateStr + ` WHERE chart_info_id = ?`
  726. _, err = to.Raw(sql, pars).Exec()
  727. if err != nil {
  728. fmt.Println("UPDATE chart_info Err:", err.Error())
  729. return err
  730. }
  731. } else {
  732. sql := ` UPDATE chart_info
  733. SET
  734. edb_info_ids=?,
  735. modify_time = NOW(),
  736. calendar=?,
  737. date_type=?,
  738. start_date=?,
  739. end_date=?,
  740. season_start_date=?,
  741. season_end_date=?,
  742. left_min=?,
  743. left_max=?,
  744. right_min=?,
  745. right_max=?,
  746. right2_min=?,
  747. right2_max=?,
  748. min_max_save=?,
  749. start_year=?
  750. WHERE chart_info_id = ?`
  751. _, err = to.Raw(sql, edbInfoIdStr, req.Calendar, req.DateType, req.StartDate, req.EndDate, req.StartDate, req.EndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax, req.Right2Min, req.Right2Max, req.MinMaxSave, req.StartYear, req.ChartInfoId).Exec()
  752. if err != nil {
  753. fmt.Println("UPDATE chart_info Err:", err.Error())
  754. return err
  755. }
  756. }
  757. var edbInfoIdArr []string
  758. mapList := make([]*ChartEdbMapping, 0)
  759. for _, v := range req.ChartEdbInfoList {
  760. edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
  761. var count int
  762. csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
  763. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
  764. if err != nil {
  765. fmt.Println("QueryRow Err:", err.Error())
  766. return err
  767. }
  768. if count > 0 {
  769. msql := `UPDATE chart_edb_mapping
  770. SET
  771. modify_time = NOW(),
  772. max_data = ?,
  773. min_data = ?,
  774. is_order = ?,
  775. is_axis = ?,
  776. edb_info_type = ?,
  777. lead_value = ?,
  778. lead_unit = ?,
  779. chart_style = ?,
  780. chart_color = ?,
  781. predict_chart_color = ?,
  782. chart_width = ?
  783. WHERE chart_info_id =? AND edb_info_id=? `
  784. _, err = to.Raw(msql, v.MaxData, v.MinData, v.IsOrder, v.IsAxis, v.EdbInfoType, v.LeadValue, v.LeadUnit, v.ChartStyle, v.ChartColor, v.PredictChartColor, v.ChartWidth, req.ChartInfoId, v.EdbInfoId).Exec()
  785. if err != nil {
  786. fmt.Println("chart_edb_mapping Err:" + err.Error())
  787. return err
  788. }
  789. } else {
  790. mapItem := new(ChartEdbMapping)
  791. mapItem.ChartInfoId = req.ChartInfoId
  792. mapItem.EdbInfoId = v.EdbInfoId
  793. mapItem.CreateTime = time.Now()
  794. mapItem.ModifyTime = time.Now()
  795. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  796. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
  797. mapItem.MaxData = v.MaxData
  798. mapItem.MinData = v.MinData
  799. mapItem.IsOrder = v.IsOrder
  800. mapItem.IsAxis = v.IsAxis
  801. mapItem.EdbInfoType = v.EdbInfoType
  802. mapItem.LeadValue = v.LeadValue
  803. mapItem.LeadUnit = v.LeadUnit
  804. mapItem.ChartStyle = v.ChartStyle
  805. mapItem.ChartColor = v.ChartColor
  806. mapItem.PredictChartColor = v.PredictChartColor
  807. mapItem.ChartWidth = v.ChartWidth
  808. mapList = append(mapList, mapItem)
  809. }
  810. }
  811. if len(mapList) > 0 {
  812. _, err = to.InsertMulti(1, mapList)
  813. if err != nil {
  814. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  815. return err
  816. }
  817. }
  818. if len(edbInfoIdArr) > 0 {
  819. edbInfoIdStr := strings.Join(edbInfoIdArr, ",")
  820. if edbInfoIdStr != "" {
  821. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id NOT IN(` + edbInfoIdStr + `)`
  822. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  823. if err != nil {
  824. fmt.Println("delete err:" + err.Error())
  825. return err
  826. }
  827. }
  828. }
  829. return
  830. }
  831. // EditChartInfoAndMapping 修改 ETA图库 的 图表与指标 的关系
  832. func EditChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string, chartEdbInfoList []*ChartSaveItem, seasonExtra string) (err error) {
  833. o := orm.NewOrmUsingDB("data")
  834. to, err := o.Begin()
  835. if err != nil {
  836. return
  837. }
  838. defer func() {
  839. if err != nil {
  840. _ = to.Rollback()
  841. } else {
  842. _ = to.Commit()
  843. }
  844. }()
  845. var pars []interface{}
  846. pars = append(pars, req.ChartName)
  847. pars = append(pars, req.ChartNameEn)
  848. pars = append(pars, edbInfoIdStr)
  849. pars = append(pars, req.ChartType)
  850. pars = append(pars, req.ChartClassifyId)
  851. pars = append(pars, disabled)
  852. pars = append(pars, barChartConf)
  853. pars = append(pars, req.ExtraConfig)
  854. pars = append(pars, seasonExtra)
  855. pars = append(pars, req.StartYear)
  856. pars = append(pars, req.ChartThemeId)
  857. pars = append(pars, req.SourcesFrom)
  858. pars = append(pars, req.Instructions)
  859. pars = append(pars, req.MarkersLines)
  860. pars = append(pars, req.MarkersAreas)
  861. pars = append(pars, req.Unit)
  862. pars = append(pars, req.UnitEn)
  863. sql := ` UPDATE chart_info
  864. SET
  865. chart_name =?,
  866. chart_name_en =?,
  867. edb_info_ids=?,
  868. chart_type=?,
  869. chart_classify_id = ?,
  870. modify_time = NOW(),
  871. disabled = ?,
  872. bar_config = ?,
  873. extra_config = ?,
  874. season_extra_config = ?,
  875. start_year = ?,
  876. chart_theme_id = ?,
  877. sources_from = ?,
  878. instructions = ?,
  879. markers_lines = ?,
  880. markers_areas = ?,
  881. unit = ?,
  882. unit_en = ?
  883. `
  884. if calendar != "" {
  885. sql += `,calendar = ? `
  886. pars = append(pars, calendar)
  887. }
  888. if dateType > 0 {
  889. sql += `,date_type = ? `
  890. pars = append(pars, dateType)
  891. }
  892. sql += `,start_date = ? `
  893. pars = append(pars, req.StartDate)
  894. sql += `,end_date = ? `
  895. pars = append(pars, req.EndDate)
  896. sql += `,season_start_date = ? `
  897. pars = append(pars, req.StartDate)
  898. sql += `,season_end_date = ? `
  899. pars = append(pars, req.EndDate)
  900. sql += `,left_min = ? `
  901. pars = append(pars, req.LeftMin)
  902. sql += `,left_max = ? `
  903. pars = append(pars, req.LeftMax)
  904. sql += `,right_min = ? `
  905. pars = append(pars, req.RightMin)
  906. sql += `,right_max = ? `
  907. pars = append(pars, req.RightMax)
  908. sql += `,right2_min = ? `
  909. pars = append(pars, req.Right2Min)
  910. sql += `,right2_max = ? `
  911. pars = append(pars, req.Right2Max)
  912. sql += `,min_max_save = ? `
  913. pars = append(pars, req.MinMaxSave)
  914. sql += `WHERE chart_info_id = ?`
  915. pars = append(pars, req.ChartInfoId)
  916. _, err = to.Raw(sql, pars).Exec()
  917. if err != nil {
  918. fmt.Println("UPDATE chart_info Err:", err.Error())
  919. return err
  920. }
  921. chartEdbMappingIdList := make([]string, 0)
  922. for _, v := range chartEdbInfoList {
  923. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  924. var tmpChartEdbMapping *ChartEdbMapping
  925. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  926. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, utils.CHART_SOURCE_DEFAULT).QueryRow(&tmpChartEdbMapping)
  927. if err != nil && err.Error() != utils.ErrNoRow() {
  928. fmt.Println("QueryRow Err:", err.Error())
  929. return err
  930. }
  931. if tmpChartEdbMapping != nil {
  932. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  933. tmpChartEdbMapping.ModifyTime = time.Now()
  934. tmpChartEdbMapping.MaxData = v.MaxData
  935. tmpChartEdbMapping.MinData = v.MinData
  936. tmpChartEdbMapping.IsOrder = v.IsOrder
  937. tmpChartEdbMapping.IsAxis = v.IsAxis
  938. tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  939. tmpChartEdbMapping.LeadValue = v.LeadValue
  940. tmpChartEdbMapping.LeadUnit = v.LeadUnit
  941. tmpChartEdbMapping.ChartStyle = v.ChartStyle
  942. tmpChartEdbMapping.ChartColor = v.ChartColor
  943. tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  944. tmpChartEdbMapping.ChartWidth = v.ChartWidth
  945. tmpChartEdbMapping.EdbAliasName = v.EdbAliasName
  946. tmpChartEdbMapping.IsConvert = v.IsConvert
  947. tmpChartEdbMapping.ConvertType = v.ConvertType
  948. tmpChartEdbMapping.ConvertValue = v.ConvertValue
  949. tmpChartEdbMapping.ConvertUnit = v.ConvertUnit
  950. tmpChartEdbMapping.ConvertEnUnit = v.ConvertEnUnit
  951. _, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth", "EdbAliasName",
  952. "IsConvert", "ConvertType", "ConvertValue", "ConvertUnit", "ConvertEnUnit")
  953. if err != nil {
  954. fmt.Println("chart_edb_mapping Err:" + err.Error())
  955. return err
  956. }
  957. } else {
  958. mapItem := new(ChartEdbMapping)
  959. mapItem.ChartInfoId = req.ChartInfoId
  960. mapItem.EdbInfoId = v.EdbInfoId
  961. mapItem.CreateTime = time.Now()
  962. mapItem.ModifyTime = time.Now()
  963. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  964. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  965. mapItem.MaxData = v.MaxData
  966. mapItem.MinData = v.MinData
  967. mapItem.IsOrder = v.IsOrder
  968. mapItem.IsAxis = v.IsAxis
  969. mapItem.EdbInfoType = v.EdbInfoType
  970. mapItem.LeadValue = v.LeadValue
  971. mapItem.LeadUnit = v.LeadUnit
  972. mapItem.ChartStyle = v.ChartStyle
  973. mapItem.ChartColor = v.ChartColor
  974. mapItem.PredictChartColor = v.PredictChartColor
  975. mapItem.ChartWidth = v.ChartWidth
  976. mapItem.Source = utils.CHART_SOURCE_DEFAULT
  977. mapItem.EdbAliasName = v.EdbAliasName
  978. mapItem.IsConvert = v.IsConvert
  979. mapItem.ConvertType = v.ConvertType
  980. mapItem.ConvertValue = v.ConvertValue
  981. mapItem.ConvertUnit = v.ConvertUnit
  982. mapItem.ConvertEnUnit = v.ConvertEnUnit
  983. tmpId, err := to.Insert(mapItem)
  984. if err != nil {
  985. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  986. return err
  987. }
  988. mapItem.ChartEdbMappingId = int(tmpId)
  989. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  990. }
  991. }
  992. if len(chartEdbMappingIdList) > 0 {
  993. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  994. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  995. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  996. if err != nil {
  997. fmt.Println("delete err:" + err.Error())
  998. return err
  999. }
  1000. }
  1001. return
  1002. }
  1003. // EditFutureGoodChartInfoAndMapping 修改商品价格曲线的 图表与指标 的关系
  1004. func EditFutureGoodChartInfoAndMapping(req *EditFutureGoodChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string) (err error) {
  1005. o := orm.NewOrmUsingDB("data")
  1006. to, err := o.Begin()
  1007. if err != nil {
  1008. return
  1009. }
  1010. defer func() {
  1011. if err != nil {
  1012. _ = to.Rollback()
  1013. } else {
  1014. _ = to.Commit()
  1015. }
  1016. }()
  1017. var pars []interface{}
  1018. pars = append(pars, req.ChartName)
  1019. pars = append(pars, edbInfoIdStr)
  1020. pars = append(pars, req.ChartType)
  1021. pars = append(pars, req.ChartClassifyId)
  1022. pars = append(pars, disabled)
  1023. pars = append(pars, barChartConf)
  1024. sql := ` UPDATE chart_info
  1025. SET
  1026. chart_name =?,
  1027. edb_info_ids=?,
  1028. chart_type=?,
  1029. chart_classify_id = ?,
  1030. modify_time = NOW(),
  1031. disabled = ?,
  1032. bar_config = ?
  1033. `
  1034. if calendar != "" {
  1035. sql += `,calendar = ? `
  1036. pars = append(pars, calendar)
  1037. }
  1038. if dateType > 0 {
  1039. sql += `,date_type = ? `
  1040. pars = append(pars, dateType)
  1041. }
  1042. sql += `,start_date = ? `
  1043. pars = append(pars, req.StartDate)
  1044. sql += `,end_date = ? `
  1045. pars = append(pars, req.EndDate)
  1046. sql += `,season_start_date = ? `
  1047. pars = append(pars, req.StartDate)
  1048. sql += `,season_end_date = ? `
  1049. pars = append(pars, req.EndDate)
  1050. sql += `,left_min = ? `
  1051. pars = append(pars, req.LeftMin)
  1052. sql += `,left_max = ? `
  1053. pars = append(pars, req.LeftMax)
  1054. sql += `,right_min = ? `
  1055. pars = append(pars, req.RightMin)
  1056. sql += `,right_max = ? `
  1057. pars = append(pars, req.RightMax)
  1058. sql += `,right2_min = ? `
  1059. pars = append(pars, req.Right2Min)
  1060. sql += `,right2_max = ? `
  1061. pars = append(pars, req.Right2Max)
  1062. sql += `WHERE chart_info_id = ?`
  1063. pars = append(pars, req.ChartInfoId)
  1064. _, err = to.Raw(sql, pars).Exec()
  1065. if err != nil {
  1066. fmt.Println("UPDATE chart_info Err:", err.Error())
  1067. return err
  1068. }
  1069. chartEdbMappingIdList := make([]string, 0)
  1070. for _, v := range req.BarChartInfo.EdbInfoIdList {
  1071. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  1072. var tmpChartEdbMapping *ChartEdbMapping
  1073. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  1074. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, v.Source).QueryRow(&tmpChartEdbMapping)
  1075. if err != nil && err.Error() != utils.ErrNoRow() {
  1076. fmt.Println("QueryRow Err:", err.Error())
  1077. return err
  1078. }
  1079. if tmpChartEdbMapping != nil {
  1080. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  1081. //tmpChartEdbMapping.ModifyTime = time.Now()
  1082. //tmpChartEdbMapping.MaxData = v.MaxData
  1083. //tmpChartEdbMapping.MinData = v.MinData
  1084. //tmpChartEdbMapping.IsOrder = v.IsOrder
  1085. //tmpChartEdbMapping.IsAxis = v.IsAxis
  1086. //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  1087. //tmpChartEdbMapping.LeadValue = v.LeadValue
  1088. //tmpChartEdbMapping.LeadUnit = v.LeadUnit
  1089. //tmpChartEdbMapping.ChartStyle = v.ChartStyle
  1090. //tmpChartEdbMapping.ChartColor = v.ChartColor
  1091. //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  1092. //tmpChartEdbMapping.ChartWidth = v.ChartWidth
  1093. //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  1094. //if err != nil {
  1095. // fmt.Println("chart_edb_mapping Err:" + err.Error())
  1096. // return err
  1097. //}
  1098. } else {
  1099. mapItem := new(ChartEdbMapping)
  1100. mapItem.ChartInfoId = req.ChartInfoId
  1101. mapItem.EdbInfoId = v.EdbInfoId
  1102. mapItem.CreateTime = time.Now()
  1103. mapItem.ModifyTime = time.Now()
  1104. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  1105. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  1106. //mapItem.MaxData = v.MaxData
  1107. //mapItem.MinData = v.MinData
  1108. mapItem.IsOrder = true
  1109. mapItem.IsAxis = 1
  1110. mapItem.EdbInfoType = 1
  1111. //mapItem.LeadValue = v.LeadValue
  1112. //mapItem.LeadUnit = v.LeadUnit
  1113. //mapItem.ChartStyle = v.ChartStyle
  1114. //mapItem.ChartColor = v.ChartColor
  1115. //mapItem.PredictChartColor = v.PredictChartColor
  1116. //mapItem.ChartWidth = v.ChartWidth
  1117. mapItem.Source = v.Source
  1118. tmpId, err := to.Insert(mapItem)
  1119. if err != nil {
  1120. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  1121. return err
  1122. }
  1123. mapItem.ChartEdbMappingId = int(tmpId)
  1124. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  1125. }
  1126. }
  1127. if len(chartEdbMappingIdList) > 0 {
  1128. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  1129. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  1130. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  1131. if err != nil {
  1132. fmt.Println("delete err:" + err.Error())
  1133. return err
  1134. }
  1135. }
  1136. return
  1137. }
  1138. // EditChartEnInfoAndEdbEnInfo
  1139. // @Description: 修改图表和指标的英文信息
  1140. // @author: Roc
  1141. // @datetime 2024-04-18 13:58:13
  1142. // @param req *EditChartEnInfoReq
  1143. // @return err error
  1144. func EditChartEnInfoAndEdbEnInfo(req *EditChartEnInfoReq) (err error) {
  1145. o := orm.NewOrmUsingDB("data")
  1146. to, err := o.Begin()
  1147. if err != nil {
  1148. return
  1149. }
  1150. defer func() {
  1151. if err != nil {
  1152. _ = to.Rollback()
  1153. } else {
  1154. _ = to.Commit()
  1155. }
  1156. }()
  1157. var pars []interface{}
  1158. updateField := ` chart_name_en =?, `
  1159. pars = append(pars, req.ChartNameEn)
  1160. if req.ExtraConfig != `` {
  1161. updateField += ` extra_config =?, `
  1162. pars = append(pars, req.ExtraConfig)
  1163. }
  1164. sql := ` UPDATE chart_info
  1165. SET ` + updateField + ` modify_time = NOW()
  1166. WHERE chart_info_id = ?`
  1167. pars = append(pars, req.ChartInfoId)
  1168. _, err = to.Raw(sql, pars).Exec()
  1169. if err != nil {
  1170. fmt.Println("UPDATE chart_info Err:", err.Error())
  1171. return err
  1172. }
  1173. var edbInfoIdArr []string
  1174. for _, v := range req.ChartEdbInfoList {
  1175. edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
  1176. var count int
  1177. csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
  1178. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
  1179. if err != nil {
  1180. fmt.Println("QueryRow Err:", err.Error())
  1181. return err
  1182. }
  1183. if count > 0 {
  1184. msql := ` UPDATE edb_info
  1185. SET
  1186. edb_name_en =?,
  1187. unit_en = ?,
  1188. modify_time = NOW()
  1189. WHERE edb_info_id = ? `
  1190. _, err = to.Raw(msql, v.EdbNameEn, v.UnitEn, v.EdbInfoId).Exec()
  1191. if err != nil {
  1192. fmt.Println("edb_info Err:" + err.Error())
  1193. return err
  1194. }
  1195. }
  1196. }
  1197. return
  1198. }
  1199. // EditChartBaseInfoAndEdbEnInfo
  1200. // @Description: 修改图表和指标的基础信息
  1201. // @author: Roc
  1202. // @datetime 2024-04-18 13:28:16
  1203. // @param req *EditChartInfoBaseReq
  1204. // @param chartItem *ChartInfo
  1205. // @param lang string
  1206. // @return err error
  1207. func EditChartBaseInfoAndEdbEnInfo(req *EditChartInfoBaseReq, chartItem *ChartInfo, lang string) (err error) {
  1208. o := orm.NewOrmUsingDB("data")
  1209. to, err := o.Begin()
  1210. if err != nil {
  1211. return
  1212. }
  1213. defer func() {
  1214. if err != nil {
  1215. _ = to.Rollback()
  1216. } else {
  1217. _ = to.Commit()
  1218. }
  1219. }()
  1220. updateChartCols := make([]string, 0)
  1221. switch lang {
  1222. case utils.EnLangVersion:
  1223. chartItem.ChartNameEn = req.ChartName
  1224. updateChartCols = append(updateChartCols, "ChartNameEn")
  1225. default:
  1226. chartItem.ChartName = req.ChartName
  1227. updateChartCols = append(updateChartCols, "ChartName")
  1228. }
  1229. if req.ExtraConfig != `` {
  1230. chartItem.ExtraConfig = req.ExtraConfig
  1231. updateChartCols = append(updateChartCols, "ExtraConfig")
  1232. }
  1233. chartItem.ModifyTime = time.Now()
  1234. updateChartCols = append(updateChartCols, "ModifyTime")
  1235. _, err = to.Update(chartItem, updateChartCols...)
  1236. if err != nil {
  1237. fmt.Println("UPDATE chart_info Err:", err.Error())
  1238. return err
  1239. }
  1240. var edbInfoIdArr []string
  1241. for _, v := range req.ChartEdbInfoList {
  1242. edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
  1243. var count int
  1244. csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
  1245. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
  1246. if err != nil {
  1247. fmt.Println("QueryRow Err:", err.Error())
  1248. return err
  1249. }
  1250. if count > 0 {
  1251. msql := ` UPDATE edb_info SET modify_time = NOW() `
  1252. pars := make([]interface{}, 0)
  1253. switch lang {
  1254. case utils.EnLangVersion:
  1255. msql += ` ,edb_name_en = ? `
  1256. pars = append(pars, v.EdbName)
  1257. // 如果有传单位
  1258. if v.Unit != `` {
  1259. msql += ` ,unit_en = ? `
  1260. pars = append(pars, v.Unit)
  1261. }
  1262. default:
  1263. msql += ` ,edb_name = ? `
  1264. pars = append(pars, v.EdbName)
  1265. // 如果有传单位
  1266. if v.Unit != `` {
  1267. msql += ` ,unit = ? `
  1268. pars = append(pars, v.Unit)
  1269. }
  1270. }
  1271. msql += ` WHERE edb_info_id = ? `
  1272. pars = append(pars, v.EdbInfoId)
  1273. _, err = to.Raw(msql, pars...).Exec()
  1274. if err != nil {
  1275. fmt.Println("edb_info Err:" + err.Error())
  1276. return err
  1277. }
  1278. }
  1279. }
  1280. return
  1281. }
  1282. type AddChartInfoReq struct {
  1283. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  1284. ChartClassifyId int `description:"分类id"`
  1285. ChartName string `description:"图表名称"`
  1286. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图"`
  1287. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  1288. StartDate string `description:"自定义开始日期"`
  1289. EndDate string `description:"自定义结束日期"`
  1290. Calendar string `description:"公历/农历"`
  1291. LeftMin string `description:"图表左侧最小值"`
  1292. LeftMax string `description:"图表左侧最大值"`
  1293. RightMin string `description:"图表右侧最小值"`
  1294. RightMax string `description:"图表右侧最大值"`
  1295. Right2Min string `description:"图表右侧2最小值"`
  1296. Right2Max string `description:"图表右侧2最大值"`
  1297. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  1298. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  1299. CorrelationChartInfo CorrelationChartInfoReq `description:"相关性图表配置"`
  1300. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1301. ChartImage string `description:"封面图" json:"-"`
  1302. SeasonExtraConfig SeasonExtraItem `description:"季节性图表中的配置,json数据"`
  1303. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1304. ChartThemeId int `description:"图表应用主题ID"`
  1305. SourcesFrom string `description:"图表来源"`
  1306. Instructions string `description:"图表说明"`
  1307. MarkersLines string `description:"标识线"`
  1308. MarkersAreas string `description:"标识区"`
  1309. Unit string `description:"中文单位名称"`
  1310. UnitEn string `description:"英文单位名称"`
  1311. }
  1312. type AddFutureGoodChartInfoReq struct {
  1313. AddChartInfoReq
  1314. BarChartInfo FutureGoodBarChartInfoReq
  1315. }
  1316. type PreviewChartInfoReq struct {
  1317. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  1318. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今 20:最近N年"`
  1319. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图"`
  1320. StartDate string `description:"自定义开始日期"`
  1321. EndDate string `description:"自定义结束日期"`
  1322. Calendar string `description:"公历/农历"`
  1323. SeasonExtraConfig SeasonExtraItem `description:"季节性图表中的配置,json数据"`
  1324. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1325. ChartSource int
  1326. }
  1327. type SeasonExtraItem struct {
  1328. ChartLegend []SeasonChartLegend `description:"自定义的图例名称"`
  1329. XStartDate string `description:"横坐标显示的起始日"`
  1330. XEndDate string `description:"横坐标显示的截止日"`
  1331. JumpYear int `description:"横坐标日期是否跨年,1跨年,0不跨年"`
  1332. }
  1333. type SeasonChartLegend struct {
  1334. Name string
  1335. Value string
  1336. }
  1337. type AddChartInfoResp struct {
  1338. ChartInfoId int `description:"图表id"`
  1339. UniqueCode string `description:"图表唯一编码"`
  1340. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  1341. }
  1342. type QuarterDataList []*QuarterData
  1343. func (m QuarterDataList) Len() int {
  1344. return len(m)
  1345. }
  1346. func (m QuarterDataList) Less(i, j int) bool {
  1347. return m[i].Years < m[j].Years
  1348. }
  1349. func (m QuarterDataList) Swap(i, j int) {
  1350. m[i], m[j] = m[j], m[i]
  1351. }
  1352. // BalanceSeasonChartLegendPreviewResp 表格中季节性图表预览接口
  1353. type BalanceSeasonChartLegendPreviewResp struct {
  1354. List QuarterDataList
  1355. }
  1356. // 判断图表指标是否已经存在
  1357. func ChartInfoExist(condition, edbInfoIdStr string) (count int, err error) {
  1358. sql := `SELECT COUNT(1) AS count FROM (
  1359. SELECT GROUP_CONCAT(edb_info_id ORDER BY edb_info_id ASC SEPARATOR ',') AS edb_info_id_str
  1360. FROM chart_edb_mapping AS a
  1361. WHERE 1=1`
  1362. if condition != "" {
  1363. sql += condition
  1364. }
  1365. sql += ` GROUP BY chart_info_id
  1366. )AS t
  1367. WHERE t.edb_info_id_str=?
  1368. GROUP BY t.edb_info_id_str `
  1369. o := orm.NewOrmUsingDB("data")
  1370. err = o.Raw(sql, edbInfoIdStr).QueryRow(&count)
  1371. return
  1372. }
  1373. func ChartInfoSearchByKeyWord(keyword string, showSysId int) (searchList []*ChartInfo, err error) {
  1374. o := orm.NewOrmUsingDB("data")
  1375. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  1376. var pars []interface{}
  1377. if keyword != "" {
  1378. sql += `AND chart_name LIKE ? `
  1379. pars = append(pars, utils.GetLikeKeyword(keyword))
  1380. }
  1381. if showSysId > 0 {
  1382. sql += ` AND sys_user_id = ? `
  1383. pars = append(pars, showSysId)
  1384. }
  1385. sql += ` ORDER BY create_time DESC `
  1386. if keyword == "" {
  1387. sql += ` LIMIT 100 `
  1388. }
  1389. _, err = o.Raw(sql, pars).QueryRows(&searchList)
  1390. return
  1391. }
  1392. // ChartInfoSearchByEmptyKeyWord 没有关键字的时候获取默认100条数据
  1393. func ChartInfoSearchByEmptyKeyWord(showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int) (total int64, searchList []*ChartInfo, err error) {
  1394. num := len(sourceList)
  1395. o := orm.NewOrmUsingDB("data")
  1396. baseSql := ` FROM chart_info WHERE 1=1 AND source in (` + utils.GetOrmInReplace(num) + `)`
  1397. var basePars []interface{}
  1398. basePars = append(basePars, sourceList)
  1399. if showSysId > 0 {
  1400. baseSql += ` AND sys_user_id = ? `
  1401. basePars = append(basePars, showSysId)
  1402. }
  1403. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  1404. if lenNoPermissionChartIdList > 0 {
  1405. baseSql += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  1406. basePars = append(basePars, noPermissionChartIdList)
  1407. }
  1408. // 查找数量
  1409. totalSql := " SELECT count(1) as total " + baseSql
  1410. err = o.Raw(totalSql, basePars).QueryRow(&total)
  1411. if err != nil {
  1412. return
  1413. }
  1414. // 查找列表数据
  1415. sql := " SELECT * " + baseSql + ` ORDER BY create_time DESC LIMIT ?,? `
  1416. basePars = append(basePars, startSize, pageSize)
  1417. _, err = o.Raw(sql, basePars).QueryRows(&searchList)
  1418. return
  1419. }
  1420. func GetNextChartInfo(classifyId int) (item *ChartInfo, err error) {
  1421. o := orm.NewOrmUsingDB("data")
  1422. sql := ` SELECT b.* FROM chart_classify AS a
  1423. INNER JOIN chart_info AS b ON a.chart_classify_id=b.chart_classify_id
  1424. WHERE a.chart_classify_id>?
  1425. ORDER BY a.chart_classify_id ASC
  1426. LIMIT 1 `
  1427. err = o.Raw(sql, classifyId).QueryRow(&item)
  1428. return
  1429. }
  1430. // GetChartInfoRefreshData 获取图表关联的指标信息
  1431. func GetChartInfoRefreshData(chartInfoId int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1432. o := orm.NewOrmUsingDB("data")
  1433. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  1434. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  1435. WHERE a.chart_info_id=? `
  1436. edbInfoList := make([]*EdbInfo, 0)
  1437. _, err = o.Raw(sql, chartInfoId).QueryRows(&edbInfoList)
  1438. if err != nil {
  1439. return
  1440. }
  1441. for _, v := range edbInfoList {
  1442. fmt.Println(v.EdbInfoId, v.EdbType)
  1443. if v.EdbType == 1 {
  1444. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1445. } else {
  1446. calculateInfoArr = append(calculateInfoArr, v)
  1447. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  1448. if err != nil {
  1449. return baseEdbInfoArr, calculateInfoArr, err
  1450. }
  1451. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1452. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1453. }
  1454. }
  1455. return
  1456. }
  1457. func GetChartRefreshEdbInfo(edbInfoId, source, n int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1458. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  1459. if err != nil && err.Error() != utils.ErrNoRow() {
  1460. return
  1461. }
  1462. n++
  1463. for _, item := range calculateList {
  1464. fmt.Println(item.EdbInfoId)
  1465. if item.EdbType == 1 {
  1466. baseEdbInfoArr = append(baseEdbInfoArr, item)
  1467. } else {
  1468. calculateInfoArr = append(calculateInfoArr, item)
  1469. if n > 10 {
  1470. return
  1471. }
  1472. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetChartRefreshEdbInfo(item.EdbInfoId, item.Source, n)
  1473. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1474. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1475. }
  1476. }
  1477. return
  1478. }
  1479. type SetChartInfoImageReq struct {
  1480. ChartInfoId int `description:"图表ID"`
  1481. ImageUrl string `description:"图表图片地址"`
  1482. }
  1483. func EditChartInfoImage(req *SetChartInfoImageReq) (err error) {
  1484. o := orm.NewOrmUsingDB("data")
  1485. sql := ` UPDATE chart_info SET chart_image=?, modify_time = NOW() WHERE chart_info_id = ? `
  1486. _, err = o.Raw(sql, req.ImageUrl, req.ChartInfoId).Exec()
  1487. if err != nil {
  1488. fmt.Println("EditChartInfoImage Err:", err.Error())
  1489. return err
  1490. }
  1491. return
  1492. }
  1493. type ChartInfoDetailFromUniqueCodeResp struct {
  1494. ChartInfo *ChartInfoView
  1495. Status bool `description:"true:图表存在,false:图表不存在"`
  1496. EdbInfoList []*ChartEdbInfoMapping
  1497. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  1498. YDataList []YData `description:"柱方图的y轴数据"`
  1499. XDataList []XData `description:"商品价格曲线的X轴数据"`
  1500. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  1501. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  1502. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  1503. }
  1504. type FutureChartInfoDetailFromUniqueCodeResp struct {
  1505. ChartInfo *ChartInfoView
  1506. Status bool `description:"true:图表存在,false:图表不存在"`
  1507. EdbInfoList []*ChartEdbInfoMapping
  1508. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  1509. YDataList []YData `description:"柱方图的y轴数据"`
  1510. XDataList []XData `description:"商品价格曲线的X轴数据"`
  1511. BarChartInfo FutureGoodBarChartInfoReq `description:"柱方图的配置"`
  1512. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  1513. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  1514. }
  1515. func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
  1516. o := orm.NewOrmUsingDB("data")
  1517. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  1518. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  1519. return
  1520. }
  1521. func GetChartInfoViewByUniqueCode(uniqueCode string) (item *ChartInfoView, err error) {
  1522. o := orm.NewOrmUsingDB("data")
  1523. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  1524. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  1525. return
  1526. }
  1527. // GetFirstChartInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  1528. func GetFirstChartInfoByClassifyId(classifyId int) (item *ChartInfo, err error) {
  1529. o := orm.NewOrmUsingDB("data")
  1530. sql := ` SELECT * FROM chart_info WHERE chart_classify_id=? order by sort asc,chart_info_id asc limit 1`
  1531. err = o.Raw(sql, classifyId).QueryRow(&item)
  1532. return
  1533. }
  1534. // UpdateChartInfoSortByClassifyId 根据图表id更新排序
  1535. func UpdateChartInfoSortByClassifyId(classifyId, nowSort, prevChartInfoId int, sourceList []int, updateSort string) (err error) {
  1536. o := orm.NewOrmUsingDB("data")
  1537. num := len(sourceList)
  1538. if num <= 0 {
  1539. return
  1540. }
  1541. sql := ` update chart_info set sort = ` + updateSort + ` WHERE chart_classify_id=? AND source in (` + utils.GetOrmInReplace(num) + `) AND `
  1542. if prevChartInfoId > 0 {
  1543. sql += ` (sort > ? or (chart_info_id > ` + fmt.Sprint(prevChartInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  1544. }
  1545. _, err = o.Raw(sql, classifyId, sourceList, nowSort).Exec()
  1546. return
  1547. }
  1548. // Update 更新图表基础信息
  1549. func (chartInfo *ChartInfo) Update(cols []string) (err error) {
  1550. o := orm.NewOrmUsingDB("data")
  1551. _, err = o.Update(chartInfo, cols...)
  1552. return
  1553. }
  1554. type ChartInfoView struct {
  1555. ChartInfoId int `orm:"column(chart_info_id);pk"`
  1556. ChartName string `description:"来源名称"`
  1557. ChartNameEn string `description:"英文图表名称"`
  1558. Unit string `description:"中文单位名称"`
  1559. UnitEn string `description:"英文单位名称"`
  1560. ChartClassifyId int `description:"图表分类id"`
  1561. ChartClassifyName string `description:"图表名称"`
  1562. SysUserId int
  1563. SysUserRealName string
  1564. UniqueCode string `description:"图表唯一编码"`
  1565. CreateTime time.Time
  1566. ModifyTime time.Time
  1567. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  1568. StartDate string `description:"自定义开始日期"`
  1569. EndDate string `description:"自定义结束日期"`
  1570. IsSetName int `description:"设置名称"`
  1571. EdbInfoIds string `description:"指标id"`
  1572. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  1573. Calendar string `description:"公历/农历"`
  1574. SeasonStartDate string `description:"季节性图开始日期"`
  1575. SeasonEndDate string `description:"季节性图开始日期"`
  1576. ChartImage string `description:"图表图片"`
  1577. Sort int `description:"排序字段,数字越小越排前面"`
  1578. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1579. MyChartId int
  1580. MyChartClassifyId string `description:"我的图表分类,多个用逗号隔开"`
  1581. ChartClassify []*ChartClassifyView
  1582. EdbEndDate string `description:"指标最新更新日期"`
  1583. XMin string `description:"图表X轴最小值"`
  1584. XMax string `description:"图表X轴最大值"`
  1585. LeftMin string `description:"图表左侧最小值"`
  1586. LeftMax string `description:"图表左侧最大值"`
  1587. RightMin string `description:"图表右侧最小值"`
  1588. RightMax string `description:"图表右侧最大值"`
  1589. Right2Min string `description:"图表右侧最小值"`
  1590. Right2Max string `description:"图表右侧最大值"`
  1591. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  1592. IsEdit bool `description:"是否有编辑权限"`
  1593. IsEnChart bool `description:"是否展示英文标识"`
  1594. WarnMsg string `description:"错误信息"`
  1595. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  1596. BarConfig string `description:"柱方图的配置,json数据" json:"-"`
  1597. Source int `description:"1:ETA图库;2:商品价格曲线;3:相关性图表"`
  1598. //CorrelationLeadUnit string `description:"相关性图表-领先单位"`
  1599. ExtraConfig string `description:"图表额外配置,json数据"`
  1600. ChartSource string `description:"图表来源str"`
  1601. ChartSourceEn string `description:"图表来源(英文)"`
  1602. Button ChartViewButton `description:"操作按钮"`
  1603. SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  1604. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1605. ChartThemeId int `description:"图表应用主题ID"`
  1606. ChartThemeStyle string `description:"图表应用主题样式"`
  1607. SourcesFrom string `description:"图表来源"`
  1608. Instructions string `description:"图表说明"`
  1609. MarkersLines string `description:"标识线"`
  1610. MarkersAreas string `description:"标识区"`
  1611. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  1612. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  1613. ForumChartInfoId int `description:"社区的图表ID"`
  1614. }
  1615. type ChartViewButton struct {
  1616. IsEdit bool `description:"是否有编辑权限"`
  1617. IsEnChart bool `description:"是否展示英文标识"`
  1618. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1619. IsCopy bool `description:"是否有另存为按钮"`
  1620. IsSetName int `description:"设置名称"`
  1621. }
  1622. type ImageSvgToPngResp struct {
  1623. Data struct {
  1624. ResourceURL string `json:"ResourceUrl"`
  1625. } `json:"Data"`
  1626. ErrCode string `json:"ErrCode"`
  1627. ErrMsg string `json:"ErrMsg"`
  1628. IsSendEmail bool `json:"IsSendEmail"`
  1629. Msg string `json:"Msg"`
  1630. Ret int64 `json:"Ret"`
  1631. Success bool `json:"Success"`
  1632. }
  1633. // GetChartInfoByClassifyIdAndName 根据分类id和图表名获取图表信息
  1634. func GetChartInfoByClassifyIdAndName(classifyId int, chartName string) (item *ChartInfo, err error) {
  1635. o := orm.NewOrmUsingDB("data")
  1636. sql := ` SELECT * FROM chart_info WHERE chart_classify_id = ? and chart_name=? `
  1637. err = o.Raw(sql, classifyId, chartName).QueryRow(&item)
  1638. return
  1639. }
  1640. // BatchChartRefreshReq 批量刷新图表请求
  1641. type BatchChartRefreshReq struct {
  1642. ChartInfoCode []string `description:"图表编码数组"`
  1643. PrimaryId int `description:"研报/智能研报/PPT主键"`
  1644. SubId int `description:"报告章节ID"`
  1645. Source string `description:"来源,枚举值:report、english_report、smart_report、ppt"`
  1646. }
  1647. // GetChartInfoListByUniqueCodeSlice 根据图表编码获取图表列表数据
  1648. func GetChartInfoListByUniqueCodeSlice(uniqueCodeSlice []string) (total int64, items []*ChartInfo, err error) {
  1649. if len(uniqueCodeSlice) <= 0 {
  1650. return
  1651. }
  1652. o := orm.NewOrmUsingDB("data")
  1653. sql := ` SELECT * FROM chart_info WHERE unique_code in ("` + strings.Join(uniqueCodeSlice, `","`) + `") `
  1654. total, err = o.Raw(sql).QueryRows(&items)
  1655. return
  1656. }
  1657. // GetChartInfoRefreshDataByChartInfoIdSlice 根据图表id切片获取对应的指标数据
  1658. func GetChartInfoRefreshDataByChartInfoIdSlice(chartInfoIdSlice []string) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1659. o := orm.NewOrmUsingDB("data")
  1660. if len(chartInfoIdSlice) <= 0 {
  1661. return
  1662. }
  1663. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  1664. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  1665. WHERE a.chart_info_id in (` + strings.Join(chartInfoIdSlice, ",") + `) `
  1666. edbInfoList := make([]*EdbInfo, 0)
  1667. _, err = o.Raw(sql).QueryRows(&edbInfoList)
  1668. if err != nil {
  1669. return
  1670. }
  1671. for _, v := range edbInfoList {
  1672. if v.EdbType == 1 {
  1673. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1674. } else {
  1675. calculateInfoArr = append(calculateInfoArr, v)
  1676. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  1677. if err != nil {
  1678. return baseEdbInfoArr, calculateInfoArr, err
  1679. }
  1680. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1681. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1682. }
  1683. }
  1684. return
  1685. }
  1686. // CopyAddChartInfoReq 复制并新增图表
  1687. type CopyAddChartInfoReq struct {
  1688. ChartInfoId int `description:"待复制的图表id"`
  1689. ChartClassifyId int `description:"分类id"`
  1690. ChartName string `description:"图表名称"`
  1691. }
  1692. // ChartInfoListByEsResp 图表数据Es搜索返回
  1693. type ChartInfoListByEsResp struct {
  1694. Paging *paging.PagingItem
  1695. List []*ChartInfoMore
  1696. }
  1697. // GetChartInfoListByCondition 根据条件获取图表数据了列表
  1698. func GetChartInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ChartInfo, err error) {
  1699. o := orm.NewOrmUsingDB("data")
  1700. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  1701. if condition != "" {
  1702. sql += condition
  1703. }
  1704. sql += ` ORDER BY chart_info_id DESC LIMIT ?,? `
  1705. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1706. return
  1707. }
  1708. // GetChartInfoListGroupByUserId 根据指标id列表、用户分组获取指标信息
  1709. func GetChartInfoListGroupByUserId(edbIdList []string) (items []*ChartInfo, err error) {
  1710. num := len(edbIdList)
  1711. if num <= 0 {
  1712. return
  1713. }
  1714. o := orm.NewOrmUsingDB("data")
  1715. sql := ` SELECT * FROM chart_info WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) ORDER BY chart_info_id desc `
  1716. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  1717. return
  1718. }
  1719. // GetChartInfoListByChartIdList
  1720. // @Description: 根据图表id列表获取列表信息
  1721. // @param edbIdList
  1722. // @return items
  1723. // @return err
  1724. func GetChartInfoListByChartIdList(charIdList []string) (items []*ChartInfo, err error) {
  1725. num := len(charIdList)
  1726. if num <= 0 {
  1727. return
  1728. }
  1729. o := orm.NewOrmUsingDB("data")
  1730. sql := ` SELECT * FROM chart_info WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) ORDER BY chart_info_id desc `
  1731. _, err = o.Raw(sql, charIdList).QueryRows(&items)
  1732. return
  1733. }
  1734. // GetChartInfoListByUserId
  1735. // @Description: 根据图表id列表获取列表信息
  1736. // @param userIdList []int
  1737. // @param source int
  1738. // @return items
  1739. // @return err
  1740. func GetChartInfoListByUserId(userIdList []int, source int) (items []*ChartInfo, err error) {
  1741. num := len(userIdList)
  1742. if num <= 0 {
  1743. return
  1744. }
  1745. o := orm.NewOrmUsingDB("data")
  1746. sql := ` SELECT * FROM chart_info WHERE source = ? AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) ORDER BY chart_info_id desc `
  1747. _, err = o.Raw(sql, source, userIdList).QueryRows(&items)
  1748. return
  1749. }
  1750. // ModifyChartInfoUserIdByCodeList 根据指标code列表修改创建人
  1751. func ModifyChartInfoUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  1752. num := len(edbIdList)
  1753. if num <= 0 {
  1754. return
  1755. }
  1756. o := orm.NewOrmUsingDB("data")
  1757. sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1758. _, err = o.Raw(sql, userId, userName, edbIdList).Exec()
  1759. return
  1760. }
  1761. // ModifyChartInfoUserIdByOldUserId
  1762. // @Description: 根据旧的用户id修改创建人
  1763. // @author: Roc
  1764. // @datetime 2024-03-25 19:14:59
  1765. // @param oldUserId int
  1766. // @param userId int
  1767. // @param userName string
  1768. // @return err error
  1769. func ModifyChartInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName string) (err error) {
  1770. num := len(oldUserIdList)
  1771. if num <= 0 {
  1772. return
  1773. }
  1774. o := orm.NewOrmUsingDB("data")
  1775. sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  1776. _, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
  1777. return
  1778. }
  1779. // BarChartInfoReq 柱方图预览请求数据
  1780. type BarChartInfoReq struct {
  1781. EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
  1782. DateList []BarChartInfoDateReq `description:"日期配置"`
  1783. Sort BarChartInfoSortReq `description:"排序"`
  1784. XEdbList []BarChartInfoEdbItemReq `description:"X轴选择的指标列表"`
  1785. YEdbList []BarChartInfoEdbItemReq `description:"Y轴选择的指标列表"`
  1786. Unit string `description:"中文单位"`
  1787. UnitEn string `description:"英文单位"`
  1788. }
  1789. type FutureGoodBarChartInfoReq struct {
  1790. EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
  1791. DateList []BarChartInfoDateReq `description:"日期配置"`
  1792. XDataList []XData `description:"横轴配置"`
  1793. BaseEdbInfoId int `description:"日期基准指标id"`
  1794. }
  1795. // BarChartInfoEdbItemReq 柱方图预览请求数据(指标相关)
  1796. type BarChartInfoEdbItemReq struct {
  1797. EdbInfoId int `description:"指标ID"`
  1798. Name string `description:"别名"`
  1799. NameEn string `description:"英文别名"`
  1800. Source int `description:"1:ETA图库;2:商品价格"`
  1801. IsConvert int `description:"是否数据转换 0不转 1转"`
  1802. ConvertType int `description:"数据转换类型 1乘 2除 3对数"`
  1803. ConvertValue float64 `description:"数据转换值"`
  1804. ConvertUnit string `description:"数据转换单位"`
  1805. ConvertEnUnit string `description:"数据转换单位"`
  1806. IsHide int `description:"是否隐藏该项,0不隐藏,1隐藏"`
  1807. }
  1808. // BarChartInfoDateReq 柱方图预览请求数据(日期相关)
  1809. type BarChartInfoDateReq struct {
  1810. Type int `description:"配置类型"`
  1811. Date string `description:"固定日期"`
  1812. Value int `description:"N天的值"`
  1813. Color string `description:"颜色"`
  1814. Name string `description:"别名"`
  1815. }
  1816. // BarChartInfoSortReq 柱方图预览请求数据(排序相关)
  1817. type BarChartInfoSortReq struct {
  1818. Sort int `description:"排序类型,0:默认,1:升序,2:降序"`
  1819. DateIndex int `description:"日期数据的下标,从0开始"`
  1820. }
  1821. // CorrelationChartInfoReq 相关性图表请求体
  1822. type CorrelationChartInfoReq struct {
  1823. LeadValue int `description:"领先期数"`
  1824. LeadUnit string `description:"频度"`
  1825. CalculateValue int `description:"计算窗口"`
  1826. CalculateUnit string `description:"计算频度"`
  1827. BaseCalculateValue int `description:"基础计算窗口(滚动相关性的时候用到)"`
  1828. BaseCalculateUnit string `description:"基础计算频度(滚动相关性的时候用到)"`
  1829. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  1830. StartDate string `description:"开始日期"`
  1831. EndDate string `description:"结束日期"`
  1832. EdbInfoIdList []CorrelationChartInfoEdbItemReq `description:"指标信息"`
  1833. }
  1834. // CorrelationChartInfoEdbItemReq 相关性图表请求指标
  1835. type CorrelationChartInfoEdbItemReq struct {
  1836. EdbInfoId int `description:"指标ID"`
  1837. Name string `description:"别名"`
  1838. NameEn string `description:"英文别名"`
  1839. //Source int `description:"1:ETA图库;2:商品价格"`
  1840. }
  1841. // EditCorrelationChartInfoAndMapping 修改相关性图表的 图表与指标 的关系
  1842. func EditCorrelationChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string, correlationChart *ChartInfoCorrelation, correlationUpdateCols []string) (err error) {
  1843. o := orm.NewOrmUsingDB("data")
  1844. to, err := o.Begin()
  1845. if err != nil {
  1846. return
  1847. }
  1848. defer func() {
  1849. if err != nil {
  1850. _ = to.Rollback()
  1851. } else {
  1852. _ = to.Commit()
  1853. }
  1854. }()
  1855. var pars []interface{}
  1856. pars = append(pars, req.ChartName)
  1857. pars = append(pars, edbInfoIdStr)
  1858. pars = append(pars, req.ChartType)
  1859. pars = append(pars, req.ChartClassifyId)
  1860. pars = append(pars, disabled)
  1861. pars = append(pars, barChartConf)
  1862. sql := ` UPDATE chart_info
  1863. SET
  1864. chart_name =?,
  1865. edb_info_ids=?,
  1866. chart_type=?,
  1867. chart_classify_id = ?,
  1868. modify_time = NOW(),
  1869. disabled = ?,
  1870. bar_config = ?
  1871. `
  1872. if calendar != "" {
  1873. sql += `,calendar = ? `
  1874. pars = append(pars, calendar)
  1875. }
  1876. if dateType > 0 {
  1877. sql += `,date_type = ? `
  1878. pars = append(pars, dateType)
  1879. }
  1880. sql += `,start_date = ? `
  1881. pars = append(pars, req.StartDate)
  1882. sql += `,end_date = ? `
  1883. pars = append(pars, req.EndDate)
  1884. sql += `,season_start_date = ? `
  1885. pars = append(pars, req.StartDate)
  1886. sql += `,season_end_date = ? `
  1887. pars = append(pars, req.EndDate)
  1888. sql += `,left_min = ? `
  1889. pars = append(pars, req.LeftMin)
  1890. sql += `,left_max = ? `
  1891. pars = append(pars, req.LeftMax)
  1892. sql += `,right_min = ? `
  1893. pars = append(pars, req.RightMin)
  1894. sql += `,right_max = ? `
  1895. pars = append(pars, req.RightMax)
  1896. sql += `WHERE chart_info_id = ?`
  1897. pars = append(pars, req.ChartInfoId)
  1898. _, err = to.Raw(sql, pars).Exec()
  1899. if err != nil {
  1900. fmt.Println("UPDATE chart_info Err:", err.Error())
  1901. return err
  1902. }
  1903. chartEdbMappingIdList := make([]string, 0)
  1904. for _, v := range req.CorrelationChartInfo.EdbInfoIdList {
  1905. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  1906. var tmpChartEdbMapping *ChartEdbMapping
  1907. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  1908. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, utils.CHART_SOURCE_CORRELATION).QueryRow(&tmpChartEdbMapping)
  1909. if err != nil && err.Error() != utils.ErrNoRow() {
  1910. fmt.Println("QueryRow Err:", err.Error())
  1911. return err
  1912. }
  1913. if tmpChartEdbMapping != nil {
  1914. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  1915. //tmpChartEdbMapping.ModifyTime = time.Now()
  1916. //tmpChartEdbMapping.MaxData = v.MaxData
  1917. //tmpChartEdbMapping.MinData = v.MinData
  1918. //tmpChartEdbMapping.IsOrder = v.IsOrder
  1919. //tmpChartEdbMapping.IsAxis = v.IsAxis
  1920. //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  1921. //tmpChartEdbMapping.LeadValue = v.LeadValue
  1922. //tmpChartEdbMapping.LeadUnit = v.LeadUnit
  1923. //tmpChartEdbMapping.ChartStyle = v.ChartStyle
  1924. //tmpChartEdbMapping.ChartColor = v.ChartColor
  1925. //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  1926. //tmpChartEdbMapping.ChartWidth = v.ChartWidth
  1927. //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  1928. //if err != nil {
  1929. // fmt.Println("chart_edb_mapping Err:" + err.Error())
  1930. // return err
  1931. //}
  1932. } else {
  1933. mapItem := new(ChartEdbMapping)
  1934. mapItem.ChartInfoId = req.ChartInfoId
  1935. mapItem.EdbInfoId = v.EdbInfoId
  1936. mapItem.CreateTime = time.Now()
  1937. mapItem.ModifyTime = time.Now()
  1938. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  1939. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  1940. //mapItem.MaxData = v.MaxData
  1941. //mapItem.MinData = v.MinData
  1942. mapItem.IsOrder = true
  1943. mapItem.IsAxis = 1
  1944. mapItem.EdbInfoType = 1
  1945. //mapItem.LeadValue = v.LeadValue
  1946. //mapItem.LeadUnit = v.LeadUnit
  1947. //mapItem.ChartStyle = v.ChartStyle
  1948. //mapItem.ChartColor = v.ChartColor
  1949. //mapItem.PredictChartColor = v.PredictChartColor
  1950. //mapItem.ChartWidth = v.ChartWidth
  1951. mapItem.Source = utils.CHART_SOURCE_CORRELATION
  1952. tmpId, err := to.Insert(mapItem)
  1953. if err != nil {
  1954. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  1955. return err
  1956. }
  1957. mapItem.ChartEdbMappingId = int(tmpId)
  1958. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  1959. }
  1960. }
  1961. if len(chartEdbMappingIdList) > 0 {
  1962. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  1963. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  1964. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  1965. if err != nil {
  1966. fmt.Println("delete err:" + err.Error())
  1967. return err
  1968. }
  1969. }
  1970. // 相关性图表
  1971. _, err = to.Update(correlationChart, correlationUpdateCols...)
  1972. return
  1973. }
  1974. // PreviewSectionScatterChartReq 预览截面散点图的请求
  1975. type PreviewSectionScatterChartReq struct {
  1976. ChartName string `description:"图表名称"`
  1977. ChartClassifyId int `description:"分类id"`
  1978. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1979. }
  1980. // SectionScatterReq 截面散点请求
  1981. type SectionScatterReq struct {
  1982. XName string `description:"x轴名称"`
  1983. XNameEn string `description:"x轴名称(英文)"`
  1984. XUnitName string `description:"x轴单位名称"`
  1985. XUnitNameEn string `description:"x轴单位名称(英文)"`
  1986. YName string `description:"y轴名称"`
  1987. YNameEn string `description:"y轴名称(英文)"`
  1988. YUnitName string `description:"y轴单位名称"`
  1989. YUnitNameEn string `description:"y轴单位名称(英文)"`
  1990. XMinValue string `description:"X轴的最小值"`
  1991. XMaxValue string `description:"X轴的最大值"`
  1992. YMinValue string `description:"Y轴的最小值"`
  1993. YMaxValue string `description:"Y轴的最大值"`
  1994. //EdbList []SectionScatterEdbItemReq `description:"指标数据"`
  1995. SeriesList []SectionScatterSeriesItemReq `description:"系列数据"`
  1996. }
  1997. // SectionScatterSeriesItemReq 系列的请求
  1998. type SectionScatterSeriesItemReq struct {
  1999. Name string `description:"系列名"`
  2000. NameEn string `description:"系列名(英文名)"`
  2001. IsNameDefault bool `description:"是否使用默认的系列名 false修改过 true默认 影响自动更新"`
  2002. Color string `description:"颜色"`
  2003. EdbInfoList []SectionScatterEdbItemReq
  2004. ShowTrendLine bool `description:"是否展示趋势线"`
  2005. ShowFitEquation bool `description:"是否展示方程式"`
  2006. ShowRSquare bool `description:"是否展示R平方"`
  2007. }
  2008. // SectionScatterEdbItemReq 截面散点请求的指标
  2009. type SectionScatterEdbItemReq struct {
  2010. XEdbInfoId int `description:"X轴的指标ID"`
  2011. YEdbInfoId int `description:"Y轴的指标ID"`
  2012. Name string `description:"别名"`
  2013. NameEn string `description:"英文别名"`
  2014. XDateType int `description:"X轴的日期配置类型"`
  2015. XDate string `description:"X轴的日期固定日期"`
  2016. XDateValue int `description:"X轴的日期N天的值"`
  2017. YDateType int `description:"Y轴的日期配置类型"`
  2018. YDate string `description:"Y轴的日期固定日期"`
  2019. YDateValue int `description:"Y轴的日期N天的值"`
  2020. IsShow bool `description:"是否展示"`
  2021. }
  2022. // SectionScatterInfoResp 截面散点图数据
  2023. type SectionScatterInfoResp struct {
  2024. XName string `description:"x轴名称"`
  2025. XNameEn string `description:"x轴名称(英文)"`
  2026. XUnitName string `description:"x轴单位名称"`
  2027. XUnitNameEn string `description:"x轴单位名称(英文)"`
  2028. YName string `description:"y轴名称"`
  2029. YNameEn string `description:"y轴名称(英文)"`
  2030. YUnitName string `description:"y轴单位名称"`
  2031. YUnitNameEn string `description:"y轴单位名称(英文)"`
  2032. XMinValue string `description:"X轴的最小值"`
  2033. XMaxValue string `description:"X轴的最大值"`
  2034. YMinValue string `description:"Y轴的最小值"`
  2035. YMaxValue string `description:"Y轴的最大值"`
  2036. DataList []SectionScatterSeriesItemResp `description:"数据列"`
  2037. }
  2038. // SectionScatterSeriesItemResp 系列的返回
  2039. type SectionScatterSeriesItemResp struct {
  2040. Name string `description:"系列名"`
  2041. NameEn string `description:"系列名(英文)"`
  2042. IsNameDefault bool `description:"是否使用默认的系列名 false修改过 true默认 影响自动更新"`
  2043. Color string `description:"颜色"`
  2044. EdbInfoList []SectionScatterEdbItemResp
  2045. ShowTrendLine bool `description:"是否展示趋势线"`
  2046. ShowFitEquation bool `description:"是否展示方程式"`
  2047. ShowRSquare bool `description:"是否展示R平方"`
  2048. TrendLine string `description:"方程式"`
  2049. RSquare string `description:"R平方的值(决定系数R2)"`
  2050. TrendLimitData []CoordinatePoint `description:"趋势线的前后坐标点"`
  2051. }
  2052. // SectionScatterEdbItemResp 截面散点的返回参数
  2053. type SectionScatterEdbItemResp struct {
  2054. XEdbInfoId int `description:"X轴指标id"`
  2055. XDate string `description:"X轴指标实际日期"`
  2056. XName string `description:"X轴指标名称"`
  2057. XNameEn string `description:"X轴指标英文名称"`
  2058. XValue float64 `description:"X轴实际值"`
  2059. YEdbInfoId int `description:"Y轴指标id"`
  2060. YDate string `description:"Y轴指标实际日期"`
  2061. YName string `description:"Y轴指标名称"`
  2062. YNameEn string `description:"Y轴指标英文名称"`
  2063. YValue float64 `description:"Y轴实际值"`
  2064. IsShow bool `description:"是否展示"`
  2065. Name string `description:"标签名称"`
  2066. NameEn string `description:"英文标签名称"`
  2067. }
  2068. // CoordinatePoint 坐标点
  2069. type CoordinatePoint struct {
  2070. X float64
  2071. Y float64
  2072. }
  2073. // RollingCorrelationChartDataResp 滚动相关性图
  2074. type RollingCorrelationChartDataResp struct {
  2075. XDateTimeValue []string `description:"滚动相关性图的x轴数据,日期数据"`
  2076. YDataList []YData `description:"滚动相关性图的y轴数据"`
  2077. }
  2078. // GetChartInfoAll 用于分类展示
  2079. // @param source int 1:ETA图库;2:商品价格曲线
  2080. func GetChartInfoAllByClassifyId(source, classifyId int) (items []*ChartClassifyItems, err error) {
  2081. o := orm.NewOrmUsingDB("data")
  2082. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,chart_name_en AS chart_classify_name_en,
  2083. 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
  2084. FROM chart_info WHERE chart_classify_id = ? AND source = ? ORDER BY sort asc,create_time DESC `
  2085. _, err = o.Raw(sql, classifyId, source).QueryRows(&items)
  2086. return
  2087. }
  2088. // ProfitFutureGoodChartResp 商品利润图
  2089. type ProfitFutureGoodChartResp struct {
  2090. XDataList []XData
  2091. YDataList []YData
  2092. ProfitName string `description:"利润的名称"`
  2093. ProfitNameEn string `description:"利润的英文名称"`
  2094. }
  2095. func FIXChartClassifyId(newId, oldId int) (err error) {
  2096. o := orm.NewOrmUsingDB("data")
  2097. sql := ` UPDATE chart_info SET chart_classify_id=? WHERE chart_classify_id=? `
  2098. _, err = o.Raw(sql, newId, oldId).Exec()
  2099. return
  2100. }
  2101. // GetChartInfoByAdminIdAndClassify 获取所有我创建的图表,用于分类展示
  2102. func GetChartInfoByAdminIdAndClassify(sourceList []int, adminId, classifyId int) (items []*ChartClassifyItems, err error) {
  2103. num := len(sourceList)
  2104. if num <= 0 {
  2105. return
  2106. }
  2107. o := orm.NewOrmUsingDB("data")
  2108. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
  2109. 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
  2110. FROM chart_info where source in (` + utils.GetOrmInReplace(num) + `) AND sys_user_id = ? AND chart_classify_id = ? ORDER BY sort asc,create_time ASC `
  2111. _, err = o.Raw(sql, sourceList, adminId, classifyId).QueryRows(&items)
  2112. return
  2113. }
  2114. // GetChartInfoAdminList 根据条件获取图表数据了列表
  2115. func GetChartInfoAdminList() (items []int, err error) {
  2116. o := orm.NewOrmUsingDB("data")
  2117. sql := ` SELECT sys_user_id FROM chart_info GROUP BY sys_user_id `
  2118. _, err = o.Raw(sql).QueryRows(&items)
  2119. return
  2120. }
  2121. // EditChartInfoExtraConfig 修改 ETA图库 的 图表额外配置
  2122. func EditChartInfoExtraConfig(chartId int, extraConfig string) (err error) {
  2123. o := orm.NewOrmUsingDB("data")
  2124. var pars []interface{}
  2125. pars = append(pars, extraConfig)
  2126. sql := ` UPDATE chart_info
  2127. SET
  2128. modify_time = NOW(),
  2129. extra_config = ?
  2130. `
  2131. sql += `WHERE chart_info_id = ?`
  2132. pars = append(pars, chartId)
  2133. _, err = o.Raw(sql, pars).Exec()
  2134. if err != nil {
  2135. fmt.Println("UPDATE chart_info Err:", err.Error())
  2136. return err
  2137. }
  2138. return
  2139. }
  2140. // PreviewRadarChartReq 预览雷达图的请求入参
  2141. type PreviewRadarChartReq struct {
  2142. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  2143. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  2144. }
  2145. // RadarChartInfoReq 雷达图预览请求数据
  2146. type RadarChartInfoReq struct {
  2147. DateList []RadarChartInfoDateReq `description:"日期配置"`
  2148. }
  2149. // RadarChartInfoEdbItemReq 雷达图预览请求数据(指标相关)
  2150. type RadarChartInfoEdbItemReq struct {
  2151. EdbInfoId int `description:"指标ID"`
  2152. Name string `description:"别名"`
  2153. //NameEn string `description:"英文别名"`
  2154. //Source int `description:"1:ETA图库;2:商品价格"`
  2155. }
  2156. // RadarChartInfoDateReq 雷达图预览请求数据(日期相关)
  2157. type RadarChartInfoDateReq struct {
  2158. Type int `description:"配置类型"`
  2159. Date string `description:"固定日期"`
  2160. Value int `description:"N天的值"`
  2161. Color string `description:"颜色"`
  2162. Name string `description:"别名"`
  2163. }
  2164. // RadarChartInfoResp 雷达图数据
  2165. type RadarChartInfoResp struct {
  2166. YDataList []RadarYData `description:"数据列"`
  2167. XEdbIdValue []int
  2168. }
  2169. // RadarYData 雷达图的y轴数据
  2170. type RadarYData struct {
  2171. Date string `description:"数据日期"`
  2172. Color string `description:"数据颜色"`
  2173. Name string `description:"别名"`
  2174. Value []float64 `description:"每个指标的值"`
  2175. }