my_chart.go 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/services/data"
  9. "eta/eta_api/utils"
  10. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // 我的图库
  17. type MyChartController struct {
  18. controllers.BaseAuthController
  19. }
  20. // @Title ETA图表列表接口
  21. // @Description ETA图表列表接口
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码,从1开始"
  24. // @Param ChartClassifyId query int true "分类id"
  25. // @Param KeyWord query string true "搜索关键词"
  26. // @Param IsShowMe query bool true "是否只看我的,true、false"
  27. // @Success 200 {object} data_manage.ChartListResp
  28. // @router /chart/list [get]
  29. func (this *MyChartController) ChartList() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. sysUser := this.SysUser
  36. if sysUser == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,SysUser Is Empty"
  39. br.Ret = 408
  40. return
  41. }
  42. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  43. pageSize, _ := this.GetInt("PageSize")
  44. currentIndex, _ := this.GetInt("CurrentIndex")
  45. keyWord := this.GetString("KeyWord")
  46. var total int
  47. page := paging.GetPaging(currentIndex, pageSize, total)
  48. var startSize int
  49. if pageSize <= 0 {
  50. pageSize = utils.PageSize20
  51. }
  52. if currentIndex <= 0 {
  53. currentIndex = 1
  54. }
  55. startSize = paging.StartIndex(currentIndex, pageSize)
  56. var condition string
  57. var pars []interface{}
  58. // 普通图表
  59. condition += ` AND source = ? `
  60. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  61. if chartClassifyId > 0 {
  62. chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
  63. if err != nil && err.Error() != utils.ErrNoRow() {
  64. br.Msg = "获取图表信息失败"
  65. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  66. return
  67. }
  68. condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  69. //pars = append(pars, chartClassifyId)
  70. }
  71. if keyWord != "" {
  72. condition += ` AND ( chart_name LIKE '%` + keyWord + `%' OR chart_name_en LIKE '%` + keyWord + `%' )`
  73. }
  74. //只看我的
  75. isShowMe, _ := this.GetBool("IsShowMe")
  76. if isShowMe {
  77. condition += ` AND sys_user_id = ? `
  78. pars = append(pars, sysUser.AdminId)
  79. }
  80. // 获取当前账号的不可见指标
  81. noPermissionChartIdList := make([]int, 0)
  82. {
  83. obj := data_manage.EdbInfoNoPermissionAdmin{}
  84. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  85. if err != nil && err.Error() != utils.ErrNoRow() {
  86. br.Msg = "获取失败"
  87. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  88. return
  89. }
  90. for _, v := range confList {
  91. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  92. }
  93. }
  94. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  95. if lenNoPermissionChartIdList > 0 {
  96. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  97. pars = append(pars, noPermissionChartIdList)
  98. }
  99. //获取图表信息
  100. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  101. if err != nil && err.Error() != utils.ErrNoRow() {
  102. br.Success = true
  103. br.Msg = "获取图表信息失败"
  104. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  105. return
  106. }
  107. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  108. if err != nil && err.Error() != utils.ErrNoRow() {
  109. br.Msg = "获取图表信息失败"
  110. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  111. return
  112. }
  113. myChartMap := make(map[int]*data_manage.MyChartView)
  114. for _, v := range myChartList {
  115. myChartMap[v.ChartInfoId] = v
  116. }
  117. listLen := len(list)
  118. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  119. if listLen > 0 {
  120. chartInfoIds := ""
  121. for _, v := range list {
  122. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  123. }
  124. if chartInfoIds != "" {
  125. chartInfoIds = strings.Trim(chartInfoIds, ",")
  126. //判断是否需要展示英文标识
  127. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  128. if e != nil {
  129. br.Msg = "获取失败"
  130. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  131. return
  132. }
  133. for _, v := range edbList {
  134. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  135. }
  136. }
  137. }
  138. for i := 0; i < listLen; i++ {
  139. //判断是否需要展示英文标识
  140. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  141. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  142. }
  143. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  144. list[i].IsAdd = true
  145. list[i].MyChartId = existItem.MyChartId
  146. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  147. }
  148. }
  149. resp := new(data_manage.ChartListResp)
  150. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  151. items := make([]*data_manage.ChartInfoView, 0)
  152. resp.Paging = page
  153. resp.List = items
  154. br.Ret = 200
  155. br.Success = true
  156. br.Msg = "获取成功"
  157. return
  158. }
  159. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  160. if err != nil && err.Error() != utils.ErrNoRow() {
  161. br.Msg = "获取指标信息失败"
  162. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  163. return
  164. }
  165. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  166. resp.Paging = page
  167. resp.List = list
  168. br.Ret = 200
  169. br.Success = true
  170. br.Msg = "获取成功"
  171. br.Data = resp
  172. }
  173. // ClassifyList
  174. // @Title 我的图表-分类列表接口
  175. // @Description 我的图表-分类列表接口
  176. // @Success 200 {object} data_manage.MyChartClassifyResp
  177. // @router /classify/list [get]
  178. func (this *MyChartController) ClassifyList() {
  179. br := new(models.BaseResponse).Init()
  180. defer func() {
  181. this.Data["json"] = br
  182. this.ServeJSON()
  183. }()
  184. sysUser := this.SysUser
  185. if sysUser == nil {
  186. br.Msg = "请登录"
  187. br.ErrMsg = "请登录,SysUser Is Empty"
  188. br.Ret = 408
  189. return
  190. }
  191. //获取图表信息
  192. list, err := data_manage.GetMyChartClassifyAll(sysUser.AdminId)
  193. if err != nil && err.Error() != utils.ErrNoRow() {
  194. br.Success = true
  195. br.Msg = "获取分类信息失败"
  196. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  197. return
  198. }
  199. resp := new(data_manage.MyChartClassifyResp)
  200. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  201. items := make([]*data_manage.MyChartClassifyItem, 0)
  202. resp.List = items
  203. br.Ret = 200
  204. br.Success = true
  205. br.Msg = "获取成功"
  206. return
  207. }
  208. //resp.List = list
  209. // 获取图表分类下各自的图表数
  210. chartsNumMap, e := data.GetMyChartClassifyIdNumMap(sysUser.AdminId)
  211. if e != nil {
  212. br.Msg = "获取失败"
  213. br.ErrMsg = "获取失败, GetMyChartClassifyIdNumMap Err: " + e.Error()
  214. return
  215. }
  216. results := make([]*data_manage.MyChartClassifyItem, 0)
  217. for _, v := range list {
  218. results = append(results, data_manage.FormatMyChartClassify2Item(v, chartsNumMap[v.MyChartClassifyId]))
  219. }
  220. resp.List = results
  221. language := `CN`
  222. // 指标显示的语言
  223. {
  224. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  225. if configDetail != nil {
  226. language = configDetail.ConfigValue
  227. } else {
  228. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  229. if configDetail != nil {
  230. language = configDetail.ConfigValue
  231. }
  232. }
  233. }
  234. resp.Language = language
  235. br.Ret = 200
  236. br.Success = true
  237. br.Msg = "获取成功"
  238. br.Data = resp
  239. }
  240. // @Title 新增我的图表分类
  241. // @Description 新增我的图表接口
  242. // @Param request body data_manage.MyChartClassifyAddReq true "type json string"
  243. // @Success 200 Ret=200 保存成功
  244. // @router /classify/add [post]
  245. func (this *MyChartController) ClassifyAdd() {
  246. br := new(models.BaseResponse).Init()
  247. defer func() {
  248. this.Data["json"] = br
  249. this.ServeJSON()
  250. }()
  251. sysUser := this.SysUser
  252. if sysUser == nil {
  253. br.Msg = "请登录"
  254. br.ErrMsg = "请登录,SysUser Is Empty"
  255. br.Ret = 408
  256. return
  257. }
  258. var req data_manage.MyChartClassifyAddReq
  259. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  260. if err != nil {
  261. br.Msg = "参数解析异常!"
  262. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  263. return
  264. }
  265. if req.MyChartClassifyName == "" {
  266. br.Msg = "请输入分类名称"
  267. br.IsSendEmail = false
  268. return
  269. }
  270. var condition string
  271. var pars []interface{}
  272. condition += " AND admin_id=? "
  273. pars = append(pars, sysUser.AdminId)
  274. condition += " AND my_chart_classify_name=? "
  275. pars = append(pars, req.MyChartClassifyName)
  276. count, err := data_manage.GetMyChartClassifyCountByCondition(condition, pars)
  277. if err != nil {
  278. br.Msg = "保存失败"
  279. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  280. return
  281. }
  282. if count > 0 {
  283. br.Msg = "分类已存在,请重新输入"
  284. br.IsSendEmail = false
  285. return
  286. }
  287. // 获取我的图库分类的最大排序值
  288. sort, err := data_manage.GetMyChartClassifyMinSort(sysUser.AdminId)
  289. if err != nil {
  290. br.Msg = "保存失败"
  291. br.ErrMsg = "保存失败,获取最大排序失败,Err:" + err.Error()
  292. return
  293. }
  294. item := new(data_manage.MyChartClassify)
  295. item.AdminId = sysUser.AdminId
  296. item.MyChartClassifyName = req.MyChartClassifyName
  297. item.Sort = sort - 1
  298. item.ModifyTime = time.Now()
  299. item.CreateTime = time.Now()
  300. err = data_manage.AddMyChartClassify(item)
  301. if err != nil {
  302. br.Msg = "保存失败"
  303. br.ErrMsg = "保存失败,Err:" + err.Error()
  304. return
  305. }
  306. //新增操作日志
  307. {
  308. edbLog := new(data_manage.MyChartLog)
  309. edbLog.MyChartId = 0
  310. edbLog.ChartInfoId = 0
  311. edbLog.SysUserId = sysUser.AdminId
  312. edbLog.SysUserRealName = sysUser.RealName
  313. edbLog.CreateTime = time.Now()
  314. edbLog.Content = string(this.Ctx.Input.RequestBody)
  315. edbLog.Status = "新增分类"
  316. edbLog.Method = this.Ctx.Input.URI()
  317. go data_manage.AddMyChartLog(edbLog)
  318. }
  319. br.Ret = 200
  320. br.Msg = "保存成功"
  321. br.Success = true
  322. br.IsAddLog = true
  323. }
  324. // @Title 编辑我的图表分类
  325. // @Description 编辑我的图表接口
  326. // @Param request body data_manage.MyChartClassifyEditReq true "type json string"
  327. // @Success 200 Ret=200 保存成功
  328. // @router /classify/edit [post]
  329. func (this *MyChartController) ClassifyEdit() {
  330. br := new(models.BaseResponse).Init()
  331. defer func() {
  332. this.Data["json"] = br
  333. this.ServeJSON()
  334. }()
  335. sysUser := this.SysUser
  336. if sysUser == nil {
  337. br.Msg = "请登录"
  338. br.ErrMsg = "请登录,SysUser Is Empty"
  339. br.Ret = 408
  340. return
  341. }
  342. var req data_manage.MyChartClassifyEditReq
  343. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  344. if err != nil {
  345. br.Msg = "参数解析异常!"
  346. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  347. return
  348. }
  349. if req.MyChartClassifyName == "" {
  350. br.Msg = "请输入分类名称"
  351. br.IsSendEmail = false
  352. return
  353. }
  354. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  355. if err != nil && err.Error() != utils.ErrNoRow() {
  356. br.Msg = "保存失败"
  357. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  358. return
  359. }
  360. if item == nil {
  361. br.Msg = "分类不存在"
  362. br.ErrMsg = "分类不存在,Err:" + err.Error()
  363. return
  364. }
  365. var condition string
  366. var pars []interface{}
  367. condition += " AND admin_id=? "
  368. pars = append(pars, sysUser.AdminId)
  369. condition += " AND my_chart_classify_name=? "
  370. pars = append(pars, req.MyChartClassifyName)
  371. condition += " AND my_chart_classify_id<>? "
  372. pars = append(pars, req.MyChartClassifyId)
  373. //判断名称是否已经存在
  374. count, err := data_manage.GetMyChartClassifyCountByCondition(condition, pars)
  375. if err != nil {
  376. br.Msg = "保存失败"
  377. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  378. return
  379. }
  380. if count > 0 {
  381. br.Msg = "分类已存在,请重新输入"
  382. br.IsSendEmail = false
  383. return
  384. }
  385. err = data_manage.ModifyMyChartClassify(req.MyChartClassifyId, req.MyChartClassifyName)
  386. if err != nil {
  387. br.Msg = "保存失败"
  388. br.ErrMsg = "保存失败,Err:" + err.Error()
  389. return
  390. }
  391. //新增操作日志
  392. {
  393. edbLog := new(data_manage.MyChartLog)
  394. edbLog.MyChartId = 0
  395. edbLog.ChartInfoId = 0
  396. edbLog.SysUserId = sysUser.AdminId
  397. edbLog.SysUserRealName = sysUser.RealName
  398. edbLog.CreateTime = time.Now()
  399. edbLog.Content = string(this.Ctx.Input.RequestBody)
  400. edbLog.Status = "编辑分类"
  401. edbLog.Method = this.Ctx.Input.URI()
  402. go data_manage.AddMyChartLog(edbLog)
  403. }
  404. br.Ret = 200
  405. br.Msg = "保存成功"
  406. br.Success = true
  407. br.IsAddLog = true
  408. }
  409. // ClassifyMove
  410. // @Title 移动我的图表分类
  411. // @Description 移动我的图表分类接口
  412. // @Param request body data_manage.MyChartClassifyMoveReq true "type json string"
  413. // @Success 200 Ret=200 移动成功
  414. // @router /classify/move [post]
  415. func (this *MyChartController) ClassifyMove() {
  416. br := new(models.BaseResponse).Init()
  417. defer func() {
  418. this.Data["json"] = br
  419. this.ServeJSON()
  420. }()
  421. sysUser := this.SysUser
  422. if sysUser == nil {
  423. br.Msg = "请登录"
  424. br.ErrMsg = "请登录,SysUser Is Empty"
  425. br.Ret = 408
  426. return
  427. }
  428. var req data_manage.MyChartClassifyMoveReq
  429. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  430. if err != nil {
  431. br.Msg = "参数解析异常!"
  432. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  433. return
  434. }
  435. //查询该分类存不存在
  436. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  437. if err != nil && err.Error() != utils.ErrNoRow() {
  438. br.Msg = "移动失败,找不到该分类"
  439. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  440. return
  441. }
  442. if item == nil {
  443. br.Msg = "分类不存在"
  444. br.ErrMsg = "分类不存在,Err:" + err.Error()
  445. return
  446. }
  447. updateCol := make([]string, 0)
  448. //如果有传入 上一个兄弟节点分类id
  449. if req.PrevClassifyId > 0 {
  450. prevClassify, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.PrevClassifyId)
  451. if err != nil {
  452. br.Msg = "移动失败"
  453. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  454. return
  455. }
  456. //如果是移动在两个兄弟节点之间
  457. if req.NextClassifyId > 0 {
  458. //下一个兄弟节点
  459. nextClassify, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.NextClassifyId)
  460. if err != nil {
  461. br.Msg = "移动失败"
  462. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  463. return
  464. }
  465. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  466. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == item.Sort {
  467. //变更兄弟节点的排序
  468. updateSortStr := `sort + 2`
  469. _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, prevClassify.MyChartClassifyId, prevClassify.Sort, updateSortStr)
  470. } else {
  471. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  472. if nextClassify.Sort-prevClassify.Sort == 1 {
  473. //变更兄弟节点的排序
  474. updateSortStr := `sort + 1`
  475. _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, 0, prevClassify.Sort, updateSortStr)
  476. }
  477. }
  478. }
  479. item.Sort = prevClassify.Sort + 1
  480. item.ModifyTime = time.Now()
  481. updateCol = append(updateCol, "Sort", "ModifyTime")
  482. } else {
  483. firstClassify, err := data_manage.GetFirstMyChartClassifyByAdminId(sysUser.AdminId)
  484. if err != nil && err.Error() != utils.ErrNoRow() {
  485. br.Msg = "移动失败"
  486. br.ErrMsg = "获取获取当前账号下的排序第一条的分类信息失败,Err:" + err.Error()
  487. return
  488. }
  489. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  490. if firstClassify != nil && firstClassify.Sort == 0 {
  491. updateSortStr := ` sort + 1 `
  492. _ = data_manage.UpdateMyChartClassifySortByClassifyId(sysUser.AdminId, firstClassify.MyChartClassifyId-1, 0, updateSortStr)
  493. }
  494. item.Sort = 0 //那就是排在第一位
  495. item.ModifyTime = time.Now()
  496. updateCol = append(updateCol, "Sort", "ModifyTime")
  497. }
  498. //更新
  499. if len(updateCol) > 0 {
  500. err = item.Update(updateCol)
  501. if err != nil {
  502. br.Msg = "移动失败"
  503. br.ErrMsg = "修改失败,Err:" + err.Error()
  504. return
  505. }
  506. }
  507. //新增操作日志
  508. {
  509. edbLog := new(data_manage.MyChartLog)
  510. edbLog.MyChartId = 0
  511. edbLog.ChartInfoId = 0
  512. edbLog.SysUserId = sysUser.AdminId
  513. edbLog.SysUserRealName = sysUser.RealName
  514. edbLog.CreateTime = time.Now()
  515. edbLog.Content = string(this.Ctx.Input.RequestBody)
  516. edbLog.Status = "移动分类"
  517. edbLog.Method = this.Ctx.Input.URI()
  518. go data_manage.AddMyChartLog(edbLog)
  519. }
  520. br.Ret = 200
  521. br.Msg = "保存成功"
  522. br.Success = true
  523. br.IsAddLog = true
  524. }
  525. // @Title 删除我的图表分类
  526. // @Description 删除我的图表接口
  527. // @Param request body data_manage.MyChartClassifyDeleteReq true "type json string"
  528. // @Success 200 Ret=200 保存成功
  529. // @router /classify/delete [post]
  530. func (this *MyChartController) ClassifyDelete() {
  531. br := new(models.BaseResponse).Init()
  532. defer func() {
  533. this.Data["json"] = br
  534. this.ServeJSON()
  535. }()
  536. sysUser := this.SysUser
  537. if sysUser == nil {
  538. br.Msg = "请登录"
  539. br.ErrMsg = "请登录,SysUser Is Empty"
  540. br.Ret = 408
  541. return
  542. }
  543. var req data_manage.MyChartClassifyDeleteReq
  544. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  545. if err != nil {
  546. br.Msg = "参数解析异常!"
  547. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  548. return
  549. }
  550. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  551. if err != nil && err.Error() != utils.ErrNoRow() {
  552. br.Msg = "保存失败"
  553. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  554. return
  555. }
  556. if item == nil {
  557. br.Msg = "分类已被删除"
  558. br.ErrMsg = "分类已被删除,Err:" + err.Error()
  559. return
  560. }
  561. nodeOb := new(data_manage.ChartFrameworkNode)
  562. cond := ` AND my_chart_classify_id = ?`
  563. pars := make([]interface{}, 0)
  564. pars = append(pars, req.MyChartClassifyId)
  565. nodes, e := nodeOb.GetItemsByCondition(cond, pars, []string{}, "")
  566. if e != nil {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取我的图表分类关联的框架节点失败, Err: " + e.Error()
  569. return
  570. }
  571. if len(nodes) > 0 {
  572. br.Msg = "该图分类已添加节点链接, 不允许删除"
  573. return
  574. }
  575. //var condition string
  576. //var pars []interface{}
  577. //
  578. //condition += " AND admin_id=? "
  579. //pars = append(pars, sysUser.AdminId)
  580. //
  581. //condition += " AND my_chart_classify_id=? "
  582. //pars = append(pars, req.MyChartClassifyId)
  583. ////判断是否包含图表
  584. //count, err := data_manage.GetMyChartClassifyMappingCountByCondition(condition, pars)
  585. //if err != nil {
  586. // br.Msg = "保存失败"
  587. // br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  588. // return
  589. //}
  590. //if count > 0 {
  591. // br.Msg = "此分类下含有图表,不可删除"
  592. // br.IsSendEmail = false
  593. // return
  594. //}
  595. err = data_manage.DeleteMyChartClassify(req.MyChartClassifyId)
  596. if err != nil {
  597. br.Msg = "删除失败"
  598. br.ErrMsg = "删除失败,Err:" + err.Error()
  599. return
  600. }
  601. //新增操作日志
  602. {
  603. edbLog := new(data_manage.MyChartLog)
  604. edbLog.MyChartId = 0
  605. edbLog.ChartInfoId = 0
  606. edbLog.SysUserId = sysUser.AdminId
  607. edbLog.SysUserRealName = sysUser.RealName
  608. edbLog.CreateTime = time.Now()
  609. edbLog.Content = string(this.Ctx.Input.RequestBody)
  610. edbLog.Status = "删除分类"
  611. edbLog.Method = this.Ctx.Input.URI()
  612. go data_manage.AddMyChartLog(edbLog)
  613. }
  614. br.Ret = 200
  615. br.Msg = "删除成功"
  616. br.Success = true
  617. br.IsAddLog = true
  618. }
  619. // @Title 新增我的图表
  620. // @Description 新增我的图表接口
  621. // @Param request body data_manage.MyChartAddReq true "type json string"
  622. // @Success 200 Ret=200 保存成功
  623. // @router /add [post]
  624. func (this *MyChartController) MyChartAdd() {
  625. br := new(models.BaseResponse).Init()
  626. defer func() {
  627. this.Data["json"] = br
  628. this.ServeJSON()
  629. }()
  630. sysUser := this.SysUser
  631. if sysUser == nil {
  632. br.Msg = "请登录"
  633. br.ErrMsg = "请登录,SysUser Is Empty"
  634. br.Ret = 408
  635. return
  636. }
  637. var req data_manage.MyChartAddReq
  638. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  639. if err != nil {
  640. br.Msg = "参数解析异常!"
  641. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  642. return
  643. }
  644. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  645. if err != nil && err.Error() != utils.ErrNoRow() {
  646. br.Msg = "获取图表信息失败!"
  647. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  648. return
  649. }
  650. if chartItem == nil {
  651. br.Msg = "此图表已被删除!"
  652. br.ErrMsg = "此图表已被删除,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  653. return
  654. }
  655. var condition string
  656. var pars []interface{}
  657. condition += " AND admin_id=? "
  658. pars = append(pars, sysUser.AdminId)
  659. condition += " AND chart_info_id=? "
  660. pars = append(pars, req.ChartInfoId)
  661. existItem, err := data_manage.GetMyChartDetailByCondition(condition, pars)
  662. if err != nil && err.Error() != utils.ErrNoRow() {
  663. br.Msg = "保存失败"
  664. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  665. return
  666. }
  667. resp := new(data_manage.MyChartAddResp)
  668. var myChartClassifyId string
  669. if existItem != nil { //修改
  670. fmt.Println("modify")
  671. for _, v := range req.MyChartClassifyId {
  672. myChartClassifyId += strconv.Itoa(v) + ","
  673. }
  674. resp.MyChartInfoId = existItem.MyChartId
  675. err = data_manage.MoveMyChartClassify(sysUser.AdminId, existItem.MyChartId, req.MyChartClassifyId)
  676. if err != nil {
  677. br.Msg = "保存失败"
  678. br.ErrMsg = "保存我的图表失败,MoveMyChartClassify,Err:" + err.Error()
  679. return
  680. }
  681. } else {
  682. myChart := &data_manage.MyChart{
  683. //MyChartId: 0,
  684. ChartInfoId: chartItem.ChartInfoId,
  685. Source: chartItem.Source,
  686. AdminId: sysUser.AdminId,
  687. CreateTime: time.Now(),
  688. ModifyTime: time.Now(),
  689. }
  690. newMyChartId, err := data_manage.AddMyChart(myChart)
  691. if err != nil {
  692. br.Msg = "保存失败"
  693. br.ErrMsg = "保存我的图表失败,Err:" + err.Error()
  694. return
  695. }
  696. //step := float64(65536)
  697. for _, v := range req.MyChartClassifyId {
  698. var sort float64
  699. // 查找最小排序值
  700. firstMapItem, _ := data_manage.GetMyChartSort(sysUser.AdminId, v, 0)
  701. if firstMapItem != nil {
  702. sort = firstMapItem.Sort
  703. }
  704. //获取最大的排序字段
  705. //count, _ := data_manage.GetMyChartMaxSort(sysUser.AdminId, v)
  706. mappingItem := new(data_manage.MyChartClassifyMapping)
  707. mappingItem.AdminId = sysUser.AdminId
  708. mappingItem.MyChartId = int(newMyChartId)
  709. mappingItem.MyChartClassifyId = v
  710. mappingItem.CreateTime = time.Now()
  711. mappingItem.ModifyTime = time.Now()
  712. //mappingItem.Sort = (float64(count) + 1) * step
  713. mappingItem.Sort = sort
  714. _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
  715. if err != nil {
  716. br.Msg = "保存失败"
  717. br.ErrMsg = "保存我的图表AddMyChartClassifyMapping失败,Err:" + err.Error()
  718. return
  719. }
  720. myChartClassifyId += strconv.Itoa(v) + ","
  721. }
  722. //新增操作日志
  723. {
  724. edbLog := new(data_manage.MyChartLog)
  725. edbLog.MyChartId = myChart.MyChartId
  726. edbLog.ChartInfoId = myChart.ChartInfoId
  727. edbLog.SysUserId = sysUser.AdminId
  728. edbLog.SysUserRealName = sysUser.RealName
  729. edbLog.CreateTime = time.Now()
  730. edbLog.Content = string(this.Ctx.Input.RequestBody)
  731. edbLog.Status = "新增我的图表"
  732. edbLog.Method = this.Ctx.Input.URI()
  733. go data_manage.AddMyChartLog(edbLog)
  734. }
  735. resp.MyChartInfoId = int(newMyChartId)
  736. }
  737. resp.MyChartClassifyId = strings.Trim(myChartClassifyId, ",")
  738. //更新es
  739. if resp.MyChartInfoId > 0 {
  740. go data.EsAddOrEditMyChartInfoByMyChartId(resp.MyChartInfoId)
  741. }
  742. br.Ret = 200
  743. br.Msg = "保存成功"
  744. br.Success = true
  745. br.Data = resp
  746. br.IsAddLog = true
  747. }
  748. // MyChartAddToClassify
  749. // @Title 将图表加入到我的图表分类
  750. // @Description 新增我的图表接口
  751. // @Param request body data_manage.MyChartAddReq true "type json string"
  752. // @Success 200 Ret=200 保存成功
  753. // @router /add_to_classify [post]
  754. func (this *MyChartController) MyChartAddToClassify() {
  755. br := new(models.BaseResponse).Init()
  756. defer func() {
  757. this.Data["json"] = br
  758. this.ServeJSON()
  759. }()
  760. sysUser := this.SysUser
  761. if sysUser == nil {
  762. br.Msg = "请登录"
  763. br.ErrMsg = "请登录,SysUser Is Empty"
  764. br.Ret = 408
  765. return
  766. }
  767. var req data_manage.MyChartAddReq
  768. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  769. if err != nil {
  770. br.Msg = "参数解析异常!"
  771. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  772. return
  773. }
  774. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  775. if err != nil && err.Error() != utils.ErrNoRow() {
  776. br.Msg = "获取图表信息失败!"
  777. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  778. return
  779. }
  780. if chartItem == nil {
  781. br.Msg = "此图表已被删除!"
  782. br.ErrMsg = "此图表已被删除,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  783. return
  784. }
  785. var condition string
  786. var pars []interface{}
  787. condition += " AND admin_id=? "
  788. pars = append(pars, sysUser.AdminId)
  789. condition += " AND chart_info_id=? "
  790. pars = append(pars, req.ChartInfoId)
  791. existItem, err := data_manage.GetMyChartDetailByCondition(condition, pars)
  792. if err != nil && err.Error() != utils.ErrNoRow() {
  793. br.Msg = "保存失败"
  794. br.ErrMsg = "保存失败,校验名称是否存在失败,Err:" + err.Error()
  795. return
  796. }
  797. resp := new(data_manage.MyChartAddResp)
  798. var myChartClassifyId string
  799. if existItem != nil { //修改
  800. fmt.Println("modify")
  801. for _, v := range req.MyChartClassifyId {
  802. myChartClassifyId += strconv.Itoa(v) + ","
  803. }
  804. resp.MyChartInfoId = existItem.MyChartId
  805. err = data_manage.AddMyChartToMyChartClassify(sysUser.AdminId, existItem.MyChartId, req.MyChartClassifyId)
  806. if err != nil {
  807. br.Msg = "保存失败"
  808. br.ErrMsg = "保存我的图表失败,MoveMyChartClassify,Err:" + err.Error()
  809. return
  810. }
  811. } else {
  812. myChart := &data_manage.MyChart{
  813. //MyChartId: 0,
  814. ChartInfoId: chartItem.ChartInfoId,
  815. Source: chartItem.Source,
  816. AdminId: sysUser.AdminId,
  817. CreateTime: time.Now(),
  818. ModifyTime: time.Now(),
  819. }
  820. newMyChartId, err := data_manage.AddMyChart(myChart)
  821. if err != nil {
  822. br.Msg = "保存失败"
  823. br.ErrMsg = "保存我的图表失败,Err:" + err.Error()
  824. return
  825. }
  826. step := float64(65536)
  827. for _, v := range req.MyChartClassifyId {
  828. //获取最大的排序字段
  829. count, _ := data_manage.GetMyChartMaxSort(sysUser.AdminId, v)
  830. mappingItem := new(data_manage.MyChartClassifyMapping)
  831. mappingItem.AdminId = sysUser.AdminId
  832. mappingItem.MyChartId = int(newMyChartId)
  833. mappingItem.MyChartClassifyId = v
  834. mappingItem.CreateTime = time.Now()
  835. mappingItem.ModifyTime = time.Now()
  836. mappingItem.Sort = (float64(count) + 1) * step
  837. _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
  838. if err != nil {
  839. br.Msg = "保存失败"
  840. br.ErrMsg = "保存我的图表AddMyChartClassifyMapping失败,Err:" + err.Error()
  841. return
  842. }
  843. myChartClassifyId += strconv.Itoa(v) + ","
  844. }
  845. //新增操作日志
  846. {
  847. edbLog := new(data_manage.MyChartLog)
  848. edbLog.MyChartId = myChart.MyChartId
  849. edbLog.ChartInfoId = myChart.ChartInfoId
  850. edbLog.SysUserId = sysUser.AdminId
  851. edbLog.SysUserRealName = sysUser.RealName
  852. edbLog.CreateTime = time.Now()
  853. edbLog.Content = string(this.Ctx.Input.RequestBody)
  854. edbLog.Status = "新增我的图表"
  855. edbLog.Method = this.Ctx.Input.URI()
  856. go data_manage.AddMyChartLog(edbLog)
  857. }
  858. resp.MyChartInfoId = int(newMyChartId)
  859. }
  860. resp.MyChartClassifyId = strings.Trim(myChartClassifyId, ",")
  861. //更新es
  862. if resp.MyChartInfoId > 0 {
  863. go data.EsAddOrEditMyChartInfoByMyChartId(resp.MyChartInfoId)
  864. }
  865. br.Ret = 200
  866. br.Msg = "保存成功"
  867. br.Success = true
  868. br.Data = resp
  869. br.IsAddLog = true
  870. }
  871. // GetMyChartClassifyIdList
  872. // @Title 根据我的图表id获取所属分类列表
  873. // @Description 根据我的图表id获取所属分类列表接口
  874. // @Param query ChartInfoId int `description:"图表id"`
  875. // @Success 200 {object} []int
  876. // @router /get_mychart_classify_id_list [get]
  877. func (this *MyChartController) GetMyChartClassifyIdList() {
  878. br := new(models.BaseResponse).Init()
  879. defer func() {
  880. this.Data["json"] = br
  881. this.ServeJSON()
  882. }()
  883. sysUser := this.SysUser
  884. if sysUser == nil {
  885. br.Msg = "请登录"
  886. br.ErrMsg = "请登录,SysUser Is Empty"
  887. br.Ret = 408
  888. return
  889. }
  890. chartInfoId, _ := this.GetInt("ChartInfoId")
  891. if chartInfoId <= 0 {
  892. br.Msg = "请传入图表id"
  893. br.IsSendEmail = false
  894. return
  895. }
  896. //图表分类id列表
  897. chartClassifyIdList := make([]int, 0)
  898. var condition string
  899. var pars []interface{}
  900. condition += " AND admin_id=? AND chart_info_id=? "
  901. pars = append(pars, sysUser.AdminId, chartInfoId)
  902. existItem, _ := data_manage.GetMyChartDetailByCondition(condition, pars)
  903. if existItem != nil {
  904. myChartClassifyList, err := data_manage.GetMyChartClassifyList(existItem.MyChartId)
  905. if err != nil && err.Error() != utils.ErrNoRow() {
  906. br.Msg = "获取图表信息失败!"
  907. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  908. return
  909. }
  910. for _, v := range myChartClassifyList {
  911. chartClassifyIdList = append(chartClassifyIdList, v.MyChartClassifyId)
  912. }
  913. }
  914. br.Ret = 200
  915. br.Msg = "获取成功"
  916. br.Success = true
  917. br.Data = chartClassifyIdList
  918. }
  919. // @Title 删除-我的图表-中的图表
  920. // @Description 删除-我的图表-中的图表接口
  921. // @Param request body data_manage.MyChartDeleteReq true "type json string"
  922. // @Success 200 Ret=200 保存成功
  923. // @router /delete [post]
  924. func (this *MyChartController) MyChartDelete() {
  925. setNxKey := "MyChartDelete_"
  926. deleteCache := true
  927. br := new(models.BaseResponse).Init()
  928. defer func() {
  929. if deleteCache {
  930. utils.Rc.Delete(setNxKey)
  931. }
  932. this.Data["json"] = br
  933. this.ServeJSON()
  934. }()
  935. sysUser := this.SysUser
  936. if sysUser == nil {
  937. br.Msg = "请登录"
  938. br.ErrMsg = "请登录,SysUser Is Empty"
  939. br.Ret = 408
  940. return
  941. }
  942. var req data_manage.MyChartDeleteReq
  943. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  944. if err != nil {
  945. br.Msg = "参数解析异常!"
  946. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  947. return
  948. }
  949. setNxKey += strconv.Itoa(req.MyChartId) + strconv.Itoa(req.MyChartClassifyId)
  950. if !utils.Rc.SetNX(setNxKey, 1, 3*time.Second) {
  951. deleteCache = false
  952. br.Msg = "系统处理中,请稍后重试!"
  953. br.IsSendEmail = false
  954. return
  955. }
  956. if req.MyChartId <= 0 {
  957. br.Msg = "参数错误!"
  958. br.ErrMsg = "参数错误,Err:" + string(this.Ctx.Input.RequestBody)
  959. return
  960. }
  961. isDelMyChart, err := data_manage.DeleteMyChart(req.MyChartId, req.MyChartClassifyId)
  962. if err != nil {
  963. br.Msg = "移除失败!"
  964. br.ErrMsg = "移除失败,Err:" + err.Error()
  965. return
  966. }
  967. //新增操作日志
  968. {
  969. edbLog := new(data_manage.MyChartLog)
  970. edbLog.MyChartId = 0
  971. edbLog.ChartInfoId = 0
  972. edbLog.SysUserId = sysUser.AdminId
  973. edbLog.SysUserRealName = sysUser.RealName
  974. edbLog.CreateTime = time.Now()
  975. edbLog.Content = string(this.Ctx.Input.RequestBody)
  976. edbLog.Status = "删除-我的图表-中的图表"
  977. edbLog.Method = this.Ctx.Input.URI()
  978. go data_manage.AddMyChartLog(edbLog)
  979. }
  980. if isDelMyChart {
  981. //如果确实删除了,那么就去ES同步删除
  982. go data.EsDeleteMyChartInfoByMyChartId(req.MyChartId)
  983. } else {
  984. //如果只是删除了关系,那么就去ES同步更新数据
  985. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  986. }
  987. br.Ret = 200
  988. br.Msg = "移除成功"
  989. br.Success = true
  990. br.IsAddLog = true
  991. }
  992. // @Title 编辑我的图表
  993. // @Description 编辑我的图表接口
  994. // @Param request body data_manage.MyChartEditReq true "type json string"
  995. // @Success 200 Ret=200 保存成功
  996. // @router /edit [post]
  997. func (this *MyChartController) MyChartEdit() {
  998. br := new(models.BaseResponse).Init()
  999. defer func() {
  1000. this.Data["json"] = br
  1001. this.ServeJSON()
  1002. }()
  1003. sysUser := this.SysUser
  1004. if sysUser == nil {
  1005. br.Msg = "请登录"
  1006. br.ErrMsg = "请登录,SysUser Is Empty"
  1007. br.Ret = 408
  1008. return
  1009. }
  1010. var req data_manage.MyChartEditReq
  1011. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1012. if err != nil {
  1013. br.Msg = "参数解析异常!"
  1014. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1015. return
  1016. }
  1017. for _, v := range req.MyChartClassifyId {
  1018. myChartClassifyId := v
  1019. count, _ := data_manage.GetMyChartClassifyMappingCount(sysUser.AdminId, req.MyChartId, myChartClassifyId)
  1020. if count <= 0 {
  1021. mappingItem := new(data_manage.MyChartClassifyMapping)
  1022. mappingItem.AdminId = sysUser.AdminId
  1023. mappingItem.MyChartId = req.MyChartId
  1024. mappingItem.MyChartClassifyId = myChartClassifyId
  1025. mappingItem.CreateTime = time.Now()
  1026. _, err = data_manage.AddMyChartClassifyMapping(mappingItem)
  1027. }
  1028. }
  1029. err = data_manage.DeleteMyChartClassifyMapping(sysUser.AdminId, req.MyChartId, req.CurrentMyChartClassifyId)
  1030. if err != nil {
  1031. br.Msg = "保存失败!"
  1032. br.ErrMsg = "保存失败,移除分类失败,Err:" + err.Error()
  1033. return
  1034. }
  1035. //新增操作日志
  1036. {
  1037. edbLog := new(data_manage.MyChartLog)
  1038. edbLog.MyChartId = 0
  1039. edbLog.ChartInfoId = 0
  1040. edbLog.SysUserId = sysUser.AdminId
  1041. edbLog.SysUserRealName = sysUser.RealName
  1042. edbLog.CreateTime = time.Now()
  1043. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1044. edbLog.Status = "编辑我的图表"
  1045. edbLog.Method = this.Ctx.Input.URI()
  1046. go data_manage.AddMyChartLog(edbLog)
  1047. }
  1048. //更新es
  1049. if req.MyChartId > 0 {
  1050. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  1051. }
  1052. br.Ret = 200
  1053. br.Msg = "保存成功"
  1054. br.Success = true
  1055. br.IsAddLog = true
  1056. }
  1057. // MyChartList
  1058. // @Title 我的图表-列表接口
  1059. // @Description 我的图表-列表接口
  1060. // @Param PageSize query int true "每页数据条数"
  1061. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1062. // @Param MyChartClassifyId query int true "我的图表分类id"
  1063. // @Param MyChartId query int true "我的图表id"
  1064. // @Success 200 {object} data_manage.MyChartListResp
  1065. // @router /list [get]
  1066. func (this *MyChartController) MyChartList() {
  1067. br := new(models.BaseResponse).Init()
  1068. defer func() {
  1069. this.Data["json"] = br
  1070. this.ServeJSON()
  1071. }()
  1072. sysUser := this.SysUser
  1073. if sysUser == nil {
  1074. br.Msg = "请登录"
  1075. br.ErrMsg = "请登录,SysUser Is Empty"
  1076. br.Ret = 408
  1077. return
  1078. }
  1079. myChartClassifyId, _ := this.GetInt("MyChartClassifyId")
  1080. pageSize, _ := this.GetInt("PageSize")
  1081. currentIndex, _ := this.GetInt("CurrentIndex")
  1082. myChartId, _ := this.GetInt("MyChartId")
  1083. var total int
  1084. page := paging.GetPaging(currentIndex, pageSize, total)
  1085. var startSize int
  1086. if pageSize <= 0 {
  1087. pageSize = utils.PageSize20
  1088. }
  1089. if currentIndex <= 0 {
  1090. currentIndex = 1
  1091. }
  1092. startSize = paging.StartIndex(currentIndex, pageSize)
  1093. var condition string
  1094. var pars []interface{}
  1095. condition += " AND (a.admin_id=? or d.is_public=1)"
  1096. pars = append(pars, sysUser.AdminId)
  1097. if myChartClassifyId > 0 {
  1098. condition += " AND c.my_chart_classify_id=? "
  1099. pars = append(pars, myChartClassifyId)
  1100. }
  1101. if myChartId > 0 {
  1102. condition += " AND a.my_chart_id=? "
  1103. pars = append(pars, myChartId)
  1104. }
  1105. // 获取当前账号的不可见指标
  1106. noPermissionChartIdList := make([]int, 0)
  1107. {
  1108. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1109. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1110. if err != nil && err.Error() != utils.ErrNoRow() {
  1111. br.Msg = "获取失败"
  1112. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1113. return
  1114. }
  1115. for _, v := range confList {
  1116. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1117. }
  1118. }
  1119. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  1120. if lenNoPermissionChartIdList > 0 {
  1121. condition += ` AND b.chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  1122. pars = append(pars, noPermissionChartIdList)
  1123. }
  1124. //获取图表信息
  1125. list, err := data_manage.GetMyChartListByCondition(condition, pars, startSize, pageSize)
  1126. if err != nil && err.Error() != utils.ErrNoRow() {
  1127. br.Success = true
  1128. br.Msg = "获取图表信息失败"
  1129. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1130. return
  1131. }
  1132. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1133. if err != nil && err.Error() != utils.ErrNoRow() {
  1134. br.Msg = "获取图表信息失败"
  1135. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1136. return
  1137. }
  1138. myChartMap := make(map[int]int)
  1139. chartInfoIds := ""
  1140. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1141. for _, v := range myChartList {
  1142. myChartMap[v.ChartInfoId] = v.ChartInfoId
  1143. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1144. }
  1145. if chartInfoIds != "" {
  1146. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1147. //判断是否需要展示英文标识
  1148. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1149. if e != nil {
  1150. br.Msg = "获取失败"
  1151. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1152. return
  1153. }
  1154. for _, v := range edbList {
  1155. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1156. }
  1157. }
  1158. listLen := len(list)
  1159. for i := 0; i < listLen; i++ {
  1160. //判断是否需要展示英文标识
  1161. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  1162. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  1163. }
  1164. if _, ok := myChartMap[list[i].ChartInfoId]; ok {
  1165. list[i].IsAdd = true
  1166. }
  1167. }
  1168. resp := new(data_manage.MyChartListResp)
  1169. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1170. items := make([]*data_manage.MyChartList, 0)
  1171. resp.Paging = page
  1172. resp.List = items
  1173. br.Ret = 200
  1174. br.Success = true
  1175. br.Msg = "获取成功"
  1176. return
  1177. }
  1178. total, err = data_manage.GetMyChartListCountByCondition(condition, pars)
  1179. if err != nil && err.Error() != utils.ErrNoRow() {
  1180. br.Msg = "获取信息失败"
  1181. br.ErrMsg = "获取我的图表数据总数失败,Err:" + err.Error()
  1182. return
  1183. }
  1184. page = paging.GetPaging(currentIndex, pageSize, total)
  1185. resp.Paging = page
  1186. resp.List = list
  1187. br.Ret = 200
  1188. br.Success = true
  1189. br.Msg = "获取成功"
  1190. br.Data = resp
  1191. }
  1192. // @Title 移动我的图表接口
  1193. // @Description 移动我的图表接口
  1194. // @Success 200 {object} data_manage.MoveMyChartReq
  1195. // @router /move [post]
  1196. func (this *MyChartController) MyChartMove() {
  1197. br := new(models.BaseResponse).Init()
  1198. defer func() {
  1199. this.Data["json"] = br
  1200. this.ServeJSON()
  1201. }()
  1202. sysUser := this.SysUser
  1203. if sysUser == nil {
  1204. br.Msg = "请登录"
  1205. br.ErrMsg = "请登录,SysUser Is Empty"
  1206. br.Ret = 408
  1207. return
  1208. }
  1209. adminId := sysUser.AdminId
  1210. var req data_manage.MoveMyChartReq
  1211. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1212. if err != nil {
  1213. br.Msg = "参数解析异常!"
  1214. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1215. return
  1216. }
  1217. //step := float64(65536)
  1218. var newSort float64
  1219. if req.PrevMyChartId <= 0 {
  1220. firstMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 0)
  1221. if err != nil {
  1222. br.Msg = "获取数据失败!"
  1223. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1224. return
  1225. }
  1226. //if firstMapItem.Sort <= 0 {
  1227. // firstSort := step / float64(2)
  1228. // err = data_manage.MyChartMove(firstSort, adminId, firstMapItem.MyChartId, firstMapItem.MyChartClassifyId)
  1229. // if err != nil {
  1230. // br.Msg = "移动失败!"
  1231. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1232. // return
  1233. // }
  1234. // newSort = step / float64(4)
  1235. //} else {
  1236. // newSort = firstMapItem.Sort / float64(2)
  1237. //}
  1238. newSort = firstMapItem.Sort - 1
  1239. } else if req.NextMyChartId <= 0 {
  1240. latestMapItem, err := data_manage.GetMyChartSort(adminId, req.MyChartClassifyId, 1)
  1241. if err != nil {
  1242. br.Msg = "获取数据失败!"
  1243. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1244. return
  1245. }
  1246. //if latestMapItem.Sort <= 0 {
  1247. // latestSort := step / float64(2)
  1248. // err = data_manage.MyChartMove(latestSort, adminId, latestMapItem.MyChartId, latestMapItem.MyChartClassifyId)
  1249. // if err != nil {
  1250. // br.Msg = "移动失败!"
  1251. // br.ErrMsg = "移动失败,Err:" + err.Error()
  1252. // return
  1253. // }
  1254. // newSort = step / float64(4)
  1255. //} else {
  1256. // newSort = latestMapItem.Sort + (step / float64(2)) - 1
  1257. //}
  1258. newSort = latestMapItem.Sort + 1
  1259. } else {
  1260. preMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.PrevMyChartId, req.MyChartClassifyId)
  1261. if err != nil {
  1262. br.Msg = "获取数据失败!"
  1263. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1264. return
  1265. }
  1266. nextMapItem, err := data_manage.GetMyChartClassifyMapping(adminId, req.NextMyChartId, req.MyChartClassifyId)
  1267. if err != nil {
  1268. br.Msg = "获取数据失败!"
  1269. br.ErrMsg = "获取数据失败,GetMyChartClassifyMapping,Err:" + err.Error()
  1270. return
  1271. }
  1272. newSort = (preMapItem.Sort + nextMapItem.Sort) / 2
  1273. newSort = preMapItem.Sort + 1
  1274. var updateSortStr string
  1275. if preMapItem.Sort == nextMapItem.Sort {
  1276. //变更兄弟节点的排序(sort同级)
  1277. updateSortStr = `sort + 2`
  1278. } else if nextMapItem.Sort-preMapItem.Sort == 1 {
  1279. //变更兄弟节点的排序(sort只相差一级)
  1280. updateSortStr = `sort + 1`
  1281. }
  1282. if updateSortStr != `` {
  1283. _ = data_manage.UpdateMyChartSortByClassifyId(req.MyChartClassifyId, int(preMapItem.Sort), preMapItem.MyChartClassifyMappingId, updateSortStr)
  1284. }
  1285. }
  1286. //if newSort >= 0 {
  1287. //
  1288. //} else {
  1289. // utils.FileLog.Info("MyChartMove Sort=0:" + string(this.Ctx.Input.RequestBody))
  1290. //}
  1291. err = data_manage.MyChartMove(newSort, adminId, req.MyChartId, req.MyChartClassifyId)
  1292. if err != nil {
  1293. br.Msg = "移动失败!"
  1294. br.ErrMsg = "移动失败,Err:" + err.Error()
  1295. return
  1296. }
  1297. //新增操作日志
  1298. {
  1299. edbLog := new(data_manage.MyChartLog)
  1300. edbLog.MyChartId = 0
  1301. edbLog.ChartInfoId = 0
  1302. edbLog.SysUserId = sysUser.AdminId
  1303. edbLog.SysUserRealName = sysUser.RealName
  1304. edbLog.CreateTime = time.Now()
  1305. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1306. edbLog.Status = "移动我的图表"
  1307. edbLog.Method = this.Ctx.Input.URI()
  1308. go data_manage.AddMyChartLog(edbLog)
  1309. }
  1310. //更新es
  1311. if req.MyChartId > 0 {
  1312. go data.EsAddOrEditMyChartInfoByMyChartId(req.MyChartId)
  1313. }
  1314. br.Ret = 200
  1315. br.Success = true
  1316. br.Msg = "移动成功"
  1317. br.IsAddLog = true
  1318. }
  1319. // @Title ETA图表-推荐列表接口
  1320. // @Description ETA图表-推荐列表接口
  1321. // @Param ChartClassifyId query int true "分类id"
  1322. // @Success 200 {object} data_manage.ChartRecommendListResp
  1323. // @router /chart/recommend/list [get]
  1324. func (this *MyChartController) ChartRecommendList() {
  1325. br := new(models.BaseResponse).Init()
  1326. defer func() {
  1327. this.Data["json"] = br
  1328. this.ServeJSON()
  1329. }()
  1330. sysUser := this.SysUser
  1331. if sysUser == nil {
  1332. br.Msg = "请登录"
  1333. br.ErrMsg = "请登录,SysUser Is Empty"
  1334. br.Ret = 408
  1335. return
  1336. }
  1337. pageSize := 6
  1338. currentIndex := 1
  1339. var startSize int
  1340. startSize = paging.StartIndex(currentIndex, pageSize)
  1341. var condition string
  1342. var pars []interface{}
  1343. if sysUser.AdminId > 0 {
  1344. condition += " AND a.admin_id=? "
  1345. pars = append(pars, sysUser.AdminId)
  1346. }
  1347. //获取图表信息
  1348. list, err := data_manage.GetRecommendChartListByCondition(condition, pars, startSize, pageSize)
  1349. if err != nil && err.Error() != utils.ErrNoRow() {
  1350. br.Success = true
  1351. br.Msg = "获取图表信息失败"
  1352. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1353. return
  1354. }
  1355. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1356. if err != nil && err.Error() != utils.ErrNoRow() {
  1357. br.Msg = "获取图表信息失败"
  1358. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1359. return
  1360. }
  1361. myChartMap := make(map[int]int)
  1362. for _, v := range myChartList {
  1363. myChartMap[v.ChartInfoId] = v.ChartInfoId
  1364. }
  1365. listLen := len(list)
  1366. for i := 0; i < listLen; i++ {
  1367. if _, ok := myChartMap[list[i].ChartInfoId]; ok {
  1368. list[i].IsAdd = true
  1369. }
  1370. }
  1371. resp := new(data_manage.ChartRecommendListResp)
  1372. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1373. items := make([]*data_manage.ChartInfoView, 0)
  1374. resp.List = items
  1375. br.Ret = 200
  1376. br.Success = true
  1377. br.Msg = "获取成功"
  1378. return
  1379. }
  1380. resp.List = list
  1381. br.Ret = 200
  1382. br.Success = true
  1383. br.Msg = "获取成功"
  1384. br.Data = resp
  1385. }
  1386. // @Title 我的图表-列表接口
  1387. // @Description 我的图表-列表接口
  1388. // @Param KeyWord query string true "搜索关键词"
  1389. // @Success 200 {object} data_manage.MyChartListResp
  1390. // @router /search [get]
  1391. func (this *MyChartController) MyChartSearch() {
  1392. br := new(models.BaseResponse).Init()
  1393. defer func() {
  1394. this.Data["json"] = br
  1395. this.ServeJSON()
  1396. }()
  1397. sysUser := this.SysUser
  1398. if sysUser == nil {
  1399. br.Msg = "请登录"
  1400. br.ErrMsg = "请登录,SysUser Is Empty"
  1401. br.Ret = 408
  1402. return
  1403. }
  1404. var condition string
  1405. var pars []interface{}
  1406. condition += " AND a.admin_id=? "
  1407. pars = append(pars, sysUser.AdminId)
  1408. keyWord := this.GetString("KeyWord")
  1409. if keyWord != "" {
  1410. condition += ` AND chart_name LIKE '%` + keyWord + `%' `
  1411. }
  1412. //获取图表信息
  1413. list, err := data_manage.GetMyChartSearchByCondition(condition, pars)
  1414. if err != nil && err.Error() != utils.ErrNoRow() {
  1415. br.Success = true
  1416. br.Msg = "获取图表信息失败"
  1417. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1418. return
  1419. }
  1420. listLen := len(list)
  1421. for i := 0; i < listLen; i++ {
  1422. list[i].IsAdd = true
  1423. }
  1424. resp := new(data_manage.MyChartSearchListResp)
  1425. if list == nil {
  1426. list = make([]*data_manage.MyChartList, 0)
  1427. }
  1428. resp.List = list
  1429. br.Ret = 200
  1430. br.Success = true
  1431. br.Msg = "获取成功"
  1432. br.Data = resp
  1433. }
  1434. // MyChartSearchByEs
  1435. // @Title 我的图表-列表接口
  1436. // @Description 我的图表-列表接口
  1437. // @Param Keyword query string true "搜索关键词"
  1438. // @Success 200 {object} data_manage.MyChartListResp
  1439. // @router /search_by_es [get]
  1440. func (this *MyChartController) MyChartSearchByEs() {
  1441. br := new(models.BaseResponse).Init()
  1442. defer func() {
  1443. this.Data["json"] = br
  1444. this.ServeJSON()
  1445. }()
  1446. sysUser := this.SysUser
  1447. if sysUser == nil {
  1448. br.Msg = "请登录"
  1449. br.ErrMsg = "请登录,SysUser Is Empty"
  1450. br.Ret = 408
  1451. return
  1452. }
  1453. pageSize, _ := this.GetInt("PageSize")
  1454. currentIndex, _ := this.GetInt("CurrentIndex")
  1455. var startSize int
  1456. if pageSize <= 0 {
  1457. pageSize = utils.PageSize20
  1458. }
  1459. if currentIndex <= 0 {
  1460. currentIndex = 1
  1461. }
  1462. startSize = paging.StartIndex(currentIndex, pageSize)
  1463. keyword := this.GetString("Keyword")
  1464. // 获取当前账号的不可见指标
  1465. noPermissionChartIdList := make([]int, 0)
  1466. {
  1467. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1468. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1469. if err != nil && err.Error() != utils.ErrNoRow() {
  1470. br.Msg = "获取失败"
  1471. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1472. return
  1473. }
  1474. for _, v := range confList {
  1475. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1476. }
  1477. }
  1478. //获取图表信息
  1479. list, total, err := data.EsSearchMyChartInfo(keyword, sysUser.AdminId, noPermissionChartIdList, startSize, pageSize)
  1480. if err != nil {
  1481. br.Msg = "获取失败"
  1482. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1483. return
  1484. }
  1485. if len(list) <= 0 {
  1486. list = make([]*data_manage.MyChartList, 0)
  1487. }
  1488. for _, v := range list {
  1489. v.IsAdd = true
  1490. }
  1491. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1492. resp := data_manage.MyChartSearchListResp{
  1493. List: list,
  1494. Paging: page,
  1495. }
  1496. br.Ret = 200
  1497. br.Success = true
  1498. br.Msg = "获取成功"
  1499. br.Data = resp
  1500. }
  1501. // PublicClassifyList
  1502. // @Title 我的图表-公共分类列表接口
  1503. // @Description 我的图表-公共分类列表接口
  1504. // @Success 200 {object} data_manage.MyChartClassifyResp
  1505. // @router /classify/public_list [get]
  1506. func (this *MyChartController) PublicClassifyList() {
  1507. br := new(models.BaseResponse).Init()
  1508. defer func() {
  1509. this.Data["json"] = br
  1510. this.ServeJSON()
  1511. }()
  1512. sysUser := this.SysUser
  1513. if sysUser == nil {
  1514. br.Msg = "请登录"
  1515. br.ErrMsg = "请登录,SysUser Is Empty"
  1516. br.Ret = 408
  1517. return
  1518. }
  1519. //获取图表信息
  1520. list, err := data_manage.GetPublicChartClassifyAllExceptMy(sysUser.AdminId)
  1521. if err != nil && err.Error() != utils.ErrNoRow() {
  1522. br.Success = true
  1523. br.Msg = "获取公共分类信息失败"
  1524. br.ErrMsg = "获取公共分类信息失败,Err:" + err.Error()
  1525. return
  1526. }
  1527. resp := new(data_manage.PublicChartClassifyResp)
  1528. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1529. resp.List = make([]data_manage.PublicChartClassifyList, 0)
  1530. br.Ret = 200
  1531. br.Success = true
  1532. br.Msg = "获取成功"
  1533. return
  1534. }
  1535. // 创建人姓名
  1536. adminIdStr := make([]string, 0)
  1537. for _, v := range list {
  1538. adminIdStr = append(adminIdStr, fmt.Sprint(v.AdminId))
  1539. }
  1540. adminMap := make(map[int]string)
  1541. adminList, _ := system.GetSysAdminByIdSlice(adminIdStr)
  1542. if len(adminList) > 0 {
  1543. for _, adminInfo := range adminList {
  1544. adminMap[adminInfo.AdminId] = adminInfo.RealName
  1545. }
  1546. }
  1547. respList := make([]data_manage.PublicChartClassifyList, 0)
  1548. existMap := make(map[int]bool, 0)
  1549. itemsMap := make(map[int][]data_manage.PublicChartClassifyItem, 0)
  1550. for _, v := range list {
  1551. realName := adminMap[v.AdminId]
  1552. if realName == "" {
  1553. // 忽略掉被删掉的用户
  1554. continue
  1555. }
  1556. if itemsMap[v.AdminId] == nil {
  1557. itemsMap[v.AdminId] = make([]data_manage.PublicChartClassifyItem, 0)
  1558. }
  1559. itemsMap[v.AdminId] = append(itemsMap[v.AdminId], data_manage.PublicChartClassifyItem{
  1560. MyChartClassifyId: v.MyChartClassifyId,
  1561. MyChartClassifyName: v.MyChartClassifyName,
  1562. AdminId: v.AdminId,
  1563. RealName: realName,
  1564. IsPublic: v.IsPublic,
  1565. IsCompanyPublic: v.IsCompanyPublic,
  1566. })
  1567. var menu data_manage.PublicChartClassifyList
  1568. if existMap[v.AdminId] {
  1569. continue
  1570. }
  1571. existMap[v.AdminId] = true
  1572. menu.MenuAdminId = v.AdminId
  1573. menu.MenuName = fmt.Sprintf("%s的图库", realName)
  1574. respList = append(respList, menu)
  1575. }
  1576. for k, v := range respList {
  1577. respList[k].Items = itemsMap[v.MenuAdminId]
  1578. }
  1579. resp.List = respList
  1580. language := `CN`
  1581. // 指标显示的语言
  1582. {
  1583. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  1584. if configDetail != nil {
  1585. language = configDetail.ConfigValue
  1586. } else {
  1587. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  1588. if configDetail != nil {
  1589. language = configDetail.ConfigValue
  1590. }
  1591. }
  1592. }
  1593. resp.Language = language
  1594. br.Ret = 200
  1595. br.Success = true
  1596. br.Msg = "获取成功"
  1597. br.Data = resp
  1598. }
  1599. // ModifyClassifyPublicStatus
  1600. // @Title 修改我的图表分类的是否可见
  1601. // @Description 修改我的图表分类的是否可见接口
  1602. // @Param request body data_manage.ModifyChartClassifyPublicReq true "type json string"
  1603. // @Success 200 Ret=200 修改成功
  1604. // @router /classify/modify_public [post]
  1605. func (this *MyChartController) ModifyClassifyPublicStatus() {
  1606. br := new(models.BaseResponse).Init()
  1607. defer func() {
  1608. this.Data["json"] = br
  1609. this.ServeJSON()
  1610. }()
  1611. sysUser := this.SysUser
  1612. if sysUser == nil {
  1613. br.Msg = "请登录"
  1614. br.ErrMsg = "请登录,SysUser Is Empty"
  1615. br.Ret = 408
  1616. return
  1617. }
  1618. var req data_manage.ModifyChartClassifyPublicReq
  1619. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1620. if err != nil {
  1621. br.Msg = "参数解析异常!"
  1622. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1623. return
  1624. }
  1625. //查询该分类存不存在
  1626. item, err := data_manage.GetMyChartClassifyById(sysUser.AdminId, req.MyChartClassifyId)
  1627. if err != nil && err.Error() != utils.ErrNoRow() {
  1628. br.Msg = "修改失败,找不到该分类"
  1629. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1630. return
  1631. }
  1632. if item == nil {
  1633. br.Msg = "分类不存在"
  1634. br.ErrMsg = "分类不存在,Err:" + err.Error()
  1635. return
  1636. }
  1637. item.IsPublic = req.IsPublic
  1638. item.PublicTime = time.Now()
  1639. if req.IsPublic == 0 {
  1640. // 取消公开同时取消客户公开
  1641. item.IsCompanyPublic = 0
  1642. }
  1643. err = item.Update([]string{"IsPublic", "PublicTime", "IsCompanyPublic"})
  1644. if err != nil {
  1645. br.Msg = "修改失败"
  1646. br.ErrMsg = "修改是否公开失败,Err:" + err.Error()
  1647. return
  1648. }
  1649. //新增操作日志
  1650. {
  1651. edbLog := new(data_manage.MyChartLog)
  1652. edbLog.MyChartId = 0
  1653. edbLog.ChartInfoId = 0
  1654. edbLog.SysUserId = sysUser.AdminId
  1655. edbLog.SysUserRealName = sysUser.RealName
  1656. edbLog.CreateTime = time.Now()
  1657. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1658. edbLog.Status = "修改分类是否公开"
  1659. edbLog.Method = this.Ctx.Input.URI()
  1660. go data_manage.AddMyChartLog(edbLog)
  1661. }
  1662. br.Ret = 200
  1663. br.Msg = "修改成功"
  1664. br.Success = true
  1665. br.IsAddLog = true
  1666. }
  1667. // CopyClassifyAndChart
  1668. // @Title 复制我的图表分类
  1669. // @Description 复制我的图表分类接口
  1670. // @Param request body data_manage.CopyChartClassifyReq true "type json string"
  1671. // @Success 200 Ret=200 复制成功
  1672. // @router /classify/copy [post]
  1673. func (this *MyChartController) CopyClassifyAndChart() {
  1674. br := new(models.BaseResponse).Init()
  1675. defer func() {
  1676. this.Data["json"] = br
  1677. this.ServeJSON()
  1678. }()
  1679. sysUser := this.SysUser
  1680. if sysUser == nil {
  1681. br.Msg = "请登录"
  1682. br.ErrMsg = "请登录,SysUser Is Empty"
  1683. br.Ret = 408
  1684. return
  1685. }
  1686. var req data_manage.CopyChartClassifyReq
  1687. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1688. if err != nil {
  1689. br.Msg = "参数解析异常!"
  1690. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1691. return
  1692. }
  1693. //查询该公共分类存不存在
  1694. item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
  1695. if err != nil && err.Error() != utils.ErrNoRow() {
  1696. br.Msg = "复制失败,找不到该分类"
  1697. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  1698. return
  1699. }
  1700. if item == nil {
  1701. br.Msg = "分类不存在"
  1702. br.ErrMsg = "分类不存在,Err:" + err.Error()
  1703. return
  1704. }
  1705. //获取所有的分类名称
  1706. chartClassifyList, err := data_manage.GetMyChartClassifyAll(sysUser.AdminId)
  1707. //生成新的分类名称
  1708. newChartClassifyName := generateMyChartClassifyName(item.MyChartClassifyName, 1, chartClassifyList)
  1709. //复制分类
  1710. newMyChartClassify, err := data_manage.CopyPublicMyChartClassifyById(item.MyChartClassifyId, sysUser.AdminId, newChartClassifyName)
  1711. if err != nil {
  1712. br.Msg = "复制失败"
  1713. br.ErrMsg = "复制失败,Err:" + err.Error()
  1714. return
  1715. }
  1716. //新增操作日志
  1717. {
  1718. edbLog := new(data_manage.MyChartLog)
  1719. edbLog.MyChartId = 0
  1720. edbLog.ChartInfoId = 0
  1721. edbLog.SysUserId = sysUser.AdminId
  1722. edbLog.SysUserRealName = sysUser.RealName
  1723. edbLog.CreateTime = time.Now()
  1724. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1725. edbLog.Status = "复制分类"
  1726. edbLog.Method = this.Ctx.Input.URI()
  1727. go data_manage.AddMyChartLog(edbLog)
  1728. }
  1729. br.Data = newMyChartClassify
  1730. br.Ret = 200
  1731. br.Msg = "复制成功"
  1732. br.Success = true
  1733. br.IsAddLog = true
  1734. }
  1735. // generateMyChartClassifyName 生成我的图库分类名称
  1736. func generateMyChartClassifyName(myChartClassifyName string, count int, chartClassifyList []*data_manage.MyChartClassify) (newChartClassifyName string) {
  1737. newChartClassifyName = fmt.Sprint(myChartClassifyName, count)
  1738. for _, v := range chartClassifyList {
  1739. if v.MyChartClassifyName == newChartClassifyName {
  1740. count++
  1741. newChartClassifyName = generateMyChartClassifyName(fmt.Sprint(myChartClassifyName), count, chartClassifyList)
  1742. return
  1743. }
  1744. }
  1745. return
  1746. }
  1747. // ModifyClassifyPublicStatus
  1748. // @Title 修改公共分类是否用户可见
  1749. // @Description 修改公共分类是否用户可见接口
  1750. // @Param request body data_manage.ModifyChartClassifyCompanyPublicReq true "type json string"
  1751. // @Success 200 Ret=200 修改成功
  1752. // @router /classify/modify_company_public [post]
  1753. func (this *MyChartController) ModifyClassifyCompanyPublicStatus() {
  1754. br := new(models.BaseResponse).Init()
  1755. defer func() {
  1756. this.Data["json"] = br
  1757. this.ServeJSON()
  1758. }()
  1759. sysUser := this.SysUser
  1760. if sysUser == nil {
  1761. br.Msg = "请登录"
  1762. br.ErrMsg = "请登录,SysUser Is Empty"
  1763. br.Ret = 408
  1764. return
  1765. }
  1766. var req data_manage.ModifyChartClassifyCompanyPublicReq
  1767. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1768. if err != nil {
  1769. br.Msg = "参数解析异常!"
  1770. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1771. return
  1772. }
  1773. item, err := data_manage.GetPublicMyChartClassifyById(req.MyChartClassifyId)
  1774. if err != nil {
  1775. br.Msg = "找不到该分类"
  1776. br.ErrMsg = "获取分类信息失败, Err:" + err.Error()
  1777. return
  1778. }
  1779. if item.IsPublic != 1 {
  1780. br.Msg = "该分类未公开,不可设置为用户可见"
  1781. br.ErrMsg = "该分类未公开,不可设置为用户可见"
  1782. return
  1783. }
  1784. item.IsCompanyPublic = req.IsCompanyPublic
  1785. item.CompanyPublicTime = time.Now()
  1786. err = item.Update([]string{"IsCompanyPublic", "CompanyPublicTime"})
  1787. if err != nil {
  1788. br.Msg = "修改失败"
  1789. br.ErrMsg = "修改是否用户可见失败, Err:" + err.Error()
  1790. return
  1791. }
  1792. {
  1793. edbLog := new(data_manage.MyChartLog)
  1794. edbLog.MyChartId = 0
  1795. edbLog.ChartInfoId = 0
  1796. edbLog.SysUserId = sysUser.AdminId
  1797. edbLog.SysUserRealName = sysUser.RealName
  1798. edbLog.CreateTime = time.Now()
  1799. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1800. edbLog.Status = "修改用户是否可见"
  1801. edbLog.Method = this.Ctx.Input.URI()
  1802. go data_manage.AddMyChartLog(edbLog)
  1803. }
  1804. br.Ret = 200
  1805. br.Msg = "修改成功"
  1806. br.Success = true
  1807. br.IsAddLog = true
  1808. }
  1809. // CompanyPublicClassifyList
  1810. // @Title 我的图表-用户可见分类列表
  1811. // @Description 我的图表-用户可见分类列表接口
  1812. // @Param Keyword query string false "分类名称关键词"
  1813. // @Success 200 {object} data_manage.MyChartClassifyResp
  1814. // @router /classify/company_public_list [get]
  1815. func (this *MyChartController) CompanyPublicClassifyList() {
  1816. br := new(models.BaseResponse).Init()
  1817. defer func() {
  1818. this.Data["json"] = br
  1819. this.ServeJSON()
  1820. }()
  1821. sysUser := this.SysUser
  1822. if sysUser == nil {
  1823. br.Msg = "请登录"
  1824. br.ErrMsg = "请登录,SysUser Is Empty"
  1825. br.Ret = 408
  1826. return
  1827. }
  1828. var condition string
  1829. var pars []interface{}
  1830. keyword := this.GetString("Keyword")
  1831. if keyword != "" {
  1832. keyword = "%" + keyword + "%"
  1833. condition += ` AND my_chart_classify_name LIKE ? `
  1834. pars = append(pars, keyword)
  1835. }
  1836. list, err := data_manage.GetCompanyPublicClassifyList(condition, pars)
  1837. if err != nil && err.Error() != utils.ErrNoRow() {
  1838. br.Success = true
  1839. br.Msg = "获取用户可见分类列表失败"
  1840. br.ErrMsg = "获取用户可见分类列表失败, Err:" + err.Error()
  1841. return
  1842. }
  1843. resp := new(data_manage.MyChartClassifyResp)
  1844. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1845. items := make([]*data_manage.MyChartClassifyItem, 0)
  1846. resp.List = items
  1847. br.Ret = 200
  1848. br.Success = true
  1849. br.Msg = "获取成功"
  1850. return
  1851. }
  1852. results := make([]*data_manage.MyChartClassifyItem, 0)
  1853. for _, v := range list {
  1854. results = append(results, data_manage.FormatMyChartClassify2Item(v, 0))
  1855. }
  1856. resp.List = results
  1857. //resp.List = list
  1858. br.Ret = 200
  1859. br.Success = true
  1860. br.Msg = "获取成功"
  1861. br.Data = resp
  1862. }
  1863. //func init() {
  1864. // data.AddAllMyChartInfo()
  1865. //}
  1866. // ClassifyFrameworkNodeList
  1867. // @Title 我的图表分类-关联的框架节点列表
  1868. // @Description 我的图表分类-关联的框架节点列表
  1869. // @Param MyChartClassifyId query int false "图表分类ID"
  1870. // @Success 200 Ret=200 获取成功
  1871. // @router /classify/framework_node_list [get]
  1872. func (this *MyChartController) ClassifyFrameworkNodeList() {
  1873. br := new(models.BaseResponse).Init()
  1874. defer func() {
  1875. if br.ErrMsg == "" {
  1876. br.IsSendEmail = true
  1877. }
  1878. this.Data["json"] = br
  1879. this.ServeJSON()
  1880. }()
  1881. sysUser := this.SysUser
  1882. if sysUser == nil {
  1883. br.Msg = "请登录"
  1884. br.ErrMsg = "请登录,SysUser Is Empty"
  1885. br.Ret = 408
  1886. return
  1887. }
  1888. classifyId, _ := this.GetInt("MyChartClassifyId")
  1889. if classifyId <= 0 {
  1890. br.Msg = "参数有误"
  1891. br.ErrMsg = fmt.Sprintf("参数有误, MyChartClassifyId: %d", classifyId)
  1892. return
  1893. }
  1894. _, e := data_manage.GetMyChartClassifyById(sysUser.AdminId, classifyId)
  1895. if e != nil {
  1896. if e.Error() == utils.ErrNoRow() {
  1897. br.Msg = "分类不存在, 请刷新页面"
  1898. return
  1899. }
  1900. br.Msg = "获取失败"
  1901. br.ErrMsg = "获取分类信息失败, Err:" + e.Error()
  1902. return
  1903. }
  1904. nodeOb := new(data_manage.ChartFrameworkNode)
  1905. cond := ` AND my_chart_classify_id = ?`
  1906. pars := make([]interface{}, 0)
  1907. pars = append(pars, classifyId)
  1908. nodes, e := nodeOb.GetItemsByCondition(cond, pars, []string{}, "")
  1909. if e != nil {
  1910. br.Msg = "获取失败"
  1911. br.ErrMsg = "获取我的图表分类关联的框架节点失败, Err: " + e.Error()
  1912. return
  1913. }
  1914. resp := make([]*data_manage.ChartFrameworkNodeItem, 0)
  1915. for _, v := range nodes {
  1916. resp = append(resp, data_manage.FormatChartFrameworkNode2Item(v, 0))
  1917. }
  1918. br.Data = resp
  1919. br.Ret = 200
  1920. br.Msg = "获取成功"
  1921. br.Success = true
  1922. }