my_chart.go 56 KB

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