my_chart.go 57 KB

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