chart_info.go 74 KB

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