my_chart.go 68 KB

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