chart_info.go 93 KB

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