classify.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. package line_feature
  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/utils"
  10. "time"
  11. )
  12. // LineFeaturesChartClassifyController 统计特征图表分类
  13. type LineFeaturesChartClassifyController struct {
  14. controllers.BaseAuthController
  15. }
  16. // ChartClassifyList
  17. // @Title 统计特征图表分类列表
  18. // @Description 统计特征图表分类列表接口
  19. // @Param IsShowMe query bool true "是否只看我的,true、false"
  20. // @Param Source query int true "图表类型,3:统计特征,4:滚动统计特征"
  21. // @Success 200 {object} data_manage.ChartClassifyListResp
  22. // @router /chart_classify/list [get]
  23. func (this *LineFeaturesChartClassifyController) ChartClassifyList() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. resp := new(data_manage.ChartClassifyListResp)
  30. // 获取当前账号的不可见指标
  31. noPermissionChartIdMap := make(map[int]bool)
  32. {
  33. obj := data_manage.EdbInfoNoPermissionAdmin{}
  34. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  35. if err != nil && !utils.IsErrNoRow(err) {
  36. br.Msg = "获取失败"
  37. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  38. return
  39. }
  40. for _, v := range confList {
  41. noPermissionChartIdMap[v.ChartInfoId] = true
  42. }
  43. }
  44. isShowMe, _ := this.GetBool("IsShowMe")
  45. if isShowMe {
  46. errMsg, err := getChartClassifyListForMe(*this.SysUser, resp)
  47. if err != nil {
  48. br.Msg = errMsg
  49. br.ErrMsg = err.Error()
  50. return
  51. }
  52. br.Ret = 200
  53. br.Success = true
  54. br.Msg = "获取成功"
  55. br.Data = resp
  56. return
  57. }
  58. source := utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION
  59. rootList, err := data_manage.GetChartClassifyByParentId(0, source)
  60. if err != nil && !utils.IsErrNoRow(err) {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  63. return
  64. }
  65. allChartInfo, err := data_manage.GetChartInfoAll([]int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY})
  66. if err != nil && !utils.IsErrNoRow(err) {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  69. return
  70. }
  71. chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
  72. for _, v := range allChartInfo {
  73. if !isShowMe {
  74. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  75. continue
  76. }
  77. if v.SysUserId != this.SysUser.AdminId {
  78. continue
  79. }
  80. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  81. }
  82. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  83. for _, v := range rootList {
  84. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  85. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  86. v.Children = existItems
  87. } else {
  88. items := make([]*data_manage.ChartClassifyItems, 0)
  89. v.Children = items
  90. }
  91. }
  92. // 移除没有权限的图表
  93. allNodes := data.HandleNoPermissionChart(rootList, noPermissionChartIdMap, this.SysUser.AdminId)
  94. resp.AllNodes = allNodes
  95. br.Ret = 200
  96. br.Success = true
  97. br.Msg = "获取成功"
  98. br.Data = resp
  99. }
  100. // getChartClassifyListForMe 获取我创建的图表
  101. func getChartClassifyListForMe(adminInfo system.Admin, resp *data_manage.ChartClassifyListResp) (errMsg string, err error) {
  102. // 获取所有的分类
  103. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION)
  104. if err != nil && !utils.IsErrNoRow(err) {
  105. errMsg = "获取失败"
  106. return
  107. }
  108. // /获取所有的图表
  109. allChartInfo, err := data_manage.GetChartInfoByAdminId([]int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, adminInfo.AdminId)
  110. if err != nil && !utils.IsErrNoRow(err) {
  111. errMsg = "获取失败"
  112. return
  113. }
  114. chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
  115. for _, v := range allChartInfo {
  116. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  117. }
  118. for k, v := range rootList {
  119. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  120. v.Children = existItems
  121. } else {
  122. items := make([]*data_manage.ChartClassifyItems, 0)
  123. v.Children = items
  124. }
  125. rootList[k] = v
  126. }
  127. resp.AllNodes = rootList
  128. return
  129. }
  130. // ChartClassifyItems
  131. // @Title 获取所有统计特征图表分类接口-不包含图表
  132. // @Description 获取所有统计特征图表分类接口-不包含图表
  133. // @Success 200 {object} data_manage.ChartClassifyListResp
  134. // @router /chart_classify/items [get]
  135. func (this *LineFeaturesChartClassifyController) ChartClassifyItems() {
  136. br := new(models.BaseResponse).Init()
  137. defer func() {
  138. this.Data["json"] = br
  139. this.ServeJSON()
  140. }()
  141. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION)
  142. if err != nil {
  143. br.Msg = "获取失败"
  144. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  145. return
  146. }
  147. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  148. for k := range rootList {
  149. rootNode := rootList[k]
  150. nodeAll = append(nodeAll, rootNode)
  151. }
  152. resp := new(data_manage.ChartClassifyListResp)
  153. resp.AllNodes = nodeAll
  154. br.Ret = 200
  155. br.Success = true
  156. br.Msg = "获取成功"
  157. br.Data = resp
  158. }
  159. // AddChartClassify
  160. // @Title 新增统计特征图表分类
  161. // @Description 新增统计特征图表分类接口
  162. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  163. // @Success 200 Ret=200 保存成功
  164. // @router /chart_classify/add [post]
  165. func (this *LineFeaturesChartClassifyController) AddChartClassify() {
  166. br := new(models.BaseResponse).Init()
  167. defer func() {
  168. this.Data["json"] = br
  169. this.ServeJSON()
  170. }()
  171. var req data_manage.AddChartClassifyReq
  172. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  173. if err != nil {
  174. br.Msg = "参数解析异常!"
  175. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  176. return
  177. }
  178. if req.ChartClassifyName == "" {
  179. br.Msg = "请输入分类名称"
  180. br.IsSendEmail = false
  181. return
  182. }
  183. if req.ParentId < 0 {
  184. br.Msg = "参数错误"
  185. br.IsSendEmail = false
  186. return
  187. }
  188. // 新增图表分类
  189. _, err, errMsg, isSendEmail := data.AddChartClassify(req.ChartClassifyName, req.ParentId, req.Level, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, this.Lang, this.SysUser)
  190. if err != nil {
  191. br.Msg = errMsg
  192. br.ErrMsg = "添加分类失败,Err:" + err.Error()
  193. br.IsSendEmail = isSendEmail
  194. return
  195. }
  196. br.Ret = 200
  197. br.Msg = "添加成功"
  198. br.Success = true
  199. }
  200. // EditChartClassify
  201. // @Title 修改统计特征图表分类
  202. // @Description 修改统计特征图表分类接口
  203. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  204. // @Success 200 Ret=200 修改成功
  205. // @router /chart_classify/edit [post]
  206. func (this *LineFeaturesChartClassifyController) EditChartClassify() {
  207. br := new(models.BaseResponse).Init()
  208. defer func() {
  209. this.Data["json"] = br
  210. this.ServeJSON()
  211. }()
  212. var req data_manage.EditChartClassifyReq
  213. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  214. if err != nil {
  215. br.Msg = "参数解析异常!"
  216. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  217. return
  218. }
  219. if req.ChartClassifyName == "" {
  220. br.Msg = "请输入分类名称"
  221. br.IsSendEmail = false
  222. return
  223. }
  224. if req.ChartClassifyId <= 0 {
  225. br.Msg = "参数错误"
  226. br.IsSendEmail = false
  227. return
  228. }
  229. // 编辑图表分类
  230. _, err, errMsg, isSendEmail := data.EditChartClassify(req.ChartClassifyId, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, req.ChartClassifyName, this.Lang, this.SysUser)
  231. if err != nil {
  232. br.Msg = errMsg
  233. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  234. br.IsSendEmail = isSendEmail
  235. return
  236. }
  237. br.Ret = 200
  238. br.Msg = "修改成功"
  239. br.Success = true
  240. br.IsAddLog = true
  241. }
  242. // DeleteChartClassifyCheck
  243. // @Title 删除图表检测接口
  244. // @Description 删除图表检测接口
  245. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  246. // @Success 200 Ret=200 检测成功
  247. // @router /chart_classify/delete/check [post]
  248. func (this *LineFeaturesChartClassifyController) DeleteChartClassifyCheck() {
  249. br := new(models.BaseResponse).Init()
  250. defer func() {
  251. this.Data["json"] = br
  252. this.ServeJSON()
  253. }()
  254. var req data_manage.ChartClassifyDeleteCheckReq
  255. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  256. if err != nil {
  257. br.Msg = "参数解析异常!"
  258. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  259. return
  260. }
  261. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  262. br.Msg = "参数错误"
  263. br.IsSendEmail = false
  264. return
  265. }
  266. var deleteStatus int
  267. var tipsMsg string
  268. childIds := make([]int, 0)
  269. //删除分类
  270. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  271. //判断统计特征图表分类下,是否含有图表
  272. classifyAll, err := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION)
  273. if err != nil {
  274. br.Msg = "删除失败"
  275. br.ErrMsg = "获取分类数据失败,Err:" + err.Error()
  276. return
  277. }
  278. classifyAllMap := make(map[int]*data_manage.ChartClassifyItems)
  279. for _, v := range classifyAll {
  280. classifyAllMap[v.ChartClassifyId] = v
  281. }
  282. data.GetChartClassifyChildIds(req.ChartClassifyId, classifyAllMap, &childIds)
  283. condition := ``
  284. pars := make([]interface{}, 0)
  285. if len(childIds) > 0 {
  286. ids := utils.IntArr2joinString(childIds, ",")
  287. condition = ` AND chart_classify_id IN (` + ids + `) `
  288. } else {
  289. condition = ` AND chart_classify_id = ? `
  290. pars = append(pars, req.ChartClassifyId)
  291. }
  292. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  293. if err != nil {
  294. br.Msg = "判断图表名称是否存在失败"
  295. br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
  296. return
  297. }
  298. //count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  299. //if err != nil {
  300. // br.Msg = "删除失败"
  301. // br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  302. // return
  303. //}
  304. if count > 0 {
  305. deleteStatus = 1
  306. tipsMsg = "该分类下关联图表不可删除"
  307. }
  308. }
  309. if deleteStatus != 1 && req.ChartInfoId == 0 {
  310. //classifyCount, err := data_manage.GetChartClassifyCountByClassifyId(req.ChartClassifyId)
  311. //if err != nil && !utils.IsErrNoRow(err) {
  312. // br.Msg = "删除失败"
  313. // br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  314. // return
  315. //}
  316. if len(childIds) > 0 {
  317. deleteStatus = 2
  318. tipsMsg = "确认删除当前目录及包含的子目录吗"
  319. }
  320. }
  321. if deleteStatus == 0 {
  322. tipsMsg = "可删除,进行删除操作"
  323. }
  324. resp := new(data_manage.ChartClassifyDeleteCheckResp)
  325. resp.DeleteStatus = deleteStatus
  326. resp.TipsMsg = tipsMsg
  327. br.Ret = 200
  328. br.Msg = "检测成功"
  329. br.Success = true
  330. br.Data = resp
  331. }
  332. // DeleteChartClassify
  333. // @Title 删除统计特征图表分类/图表
  334. // @Description 删除统计特征图表分类/图表接口
  335. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  336. // @Success 200 Ret=200 删除成功
  337. // @router /chart_classify/delete [post]
  338. func (this *LineFeaturesChartClassifyController) DeleteChartClassify() {
  339. br := new(models.BaseResponse).Init()
  340. defer func() {
  341. this.Data["json"] = br
  342. this.ServeJSON()
  343. }()
  344. sysUser := this.SysUser
  345. if sysUser == nil {
  346. br.Msg = "请登录"
  347. br.ErrMsg = "请登录,SysUser Is Empty"
  348. br.Ret = 408
  349. return
  350. }
  351. var req data_manage.DeleteChartClassifyReq
  352. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  353. if err != nil {
  354. br.Msg = "参数解析异常!"
  355. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  356. return
  357. }
  358. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  359. br.Msg = "参数错误"
  360. br.IsSendEmail = false
  361. return
  362. }
  363. //删除分类
  364. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  365. //判断是否含有指标
  366. childIds := make([]int, 0)
  367. classifyAll, err := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION)
  368. if err != nil {
  369. br.Msg = "删除失败"
  370. br.ErrMsg = "获取分类数据失败,Err:" + err.Error()
  371. return
  372. }
  373. classifyAllMap := make(map[int]*data_manage.ChartClassifyItems)
  374. for _, v := range classifyAll {
  375. classifyAllMap[v.ChartClassifyId] = v
  376. }
  377. data.GetChartClassifyChildIds(req.ChartClassifyId, classifyAllMap, &childIds)
  378. condition := ``
  379. pars := make([]interface{}, 0)
  380. if len(childIds) > 0 {
  381. ids := utils.IntArr2joinString(childIds, ",")
  382. condition = ` AND chart_classify_id IN (` + ids + `) `
  383. } else {
  384. condition = ` AND chart_classify_id = ? `
  385. pars = append(pars, req.ChartClassifyId)
  386. }
  387. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  388. if err != nil {
  389. br.Msg = "判断图表名称是否存在失败"
  390. br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
  391. return
  392. }
  393. //count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  394. //if err != nil && !utils.IsErrNoRow(err) {
  395. // br.Msg = "删除失败"
  396. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  397. // return
  398. //}
  399. if count > 0 {
  400. br.Msg = "该目录下存在关联指标,不可删除"
  401. br.IsSendEmail = false
  402. return
  403. }
  404. delIds := append(childIds, req.ChartClassifyId)
  405. err = data_manage.DeleteChartClassifyByIds(delIds)
  406. //err = data_manage.DeleteChartClassify(req.ChartClassifyId)
  407. if err != nil {
  408. br.Msg = "删除失败"
  409. br.ErrMsg = "删除失败,Err:" + err.Error()
  410. return
  411. }
  412. }
  413. resp := new(data_manage.AddChartInfoResp)
  414. //删除图表
  415. if req.ChartInfoId > 0 {
  416. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  417. if err != nil {
  418. if utils.IsErrNoRow(err) {
  419. br.Msg = "图表已删除,请刷新页面"
  420. br.ErrMsg = "指标不存在,Err:" + err.Error()
  421. return
  422. } else {
  423. br.Msg = "删除失败"
  424. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  425. return
  426. }
  427. }
  428. if chartInfo == nil {
  429. br.Msg = "图表已删除,请刷新页面"
  430. return
  431. }
  432. //图表操作权限
  433. ok := data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  434. if !ok {
  435. br.Msg = "没有该图表的操作权限"
  436. br.ErrMsg = "没有该图表的操作权限"
  437. return
  438. }
  439. myIds := make([]int, 0)
  440. {
  441. // 获取引用该图表的MyCharts, 用于ES删除
  442. var myCond string
  443. var myPars []interface{}
  444. myCond += ` AND a.chart_info_id = ? `
  445. myPars = append(myPars, req.ChartInfoId)
  446. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  447. if e != nil {
  448. br.Msg = "删除失败"
  449. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  450. return
  451. }
  452. for _, m := range myCharts {
  453. myIds = append(myIds, m.MyChartId)
  454. }
  455. }
  456. //删除图表及关联指标
  457. err = data_manage.DeleteChartInfoAndData(chartInfo.ChartInfoId)
  458. if err != nil {
  459. br.Msg = "删除失败"
  460. br.ErrMsg = "删除失败,Err:" + err.Error()
  461. return
  462. }
  463. //删除ES
  464. {
  465. go data.EsDeleteChartInfo(chartInfo.ChartInfoId)
  466. // 删除MY ETA 图表 es数据
  467. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  468. }
  469. source := chartInfo.Source // 统计特征图表
  470. var condition string
  471. var pars []interface{}
  472. condition += " AND chart_classify_id=? AND source = ? "
  473. pars = append(pars, chartInfo.ChartClassifyId, source)
  474. condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
  475. pars = append(pars, req.ChartInfoId)
  476. nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  477. if err != nil && !utils.IsErrNoRow(err) {
  478. br.Msg = "删除失败"
  479. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  480. return
  481. }
  482. if nextItem != nil {
  483. resp.UniqueCode = nextItem.UniqueCode
  484. resp.ChartInfoId = nextItem.ChartInfoId
  485. } else {
  486. var condition string
  487. var pars []interface{}
  488. condition += " AND level=1 "
  489. //pars = append(pars, chartInfo.ChartClassifyId)
  490. condition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
  491. pars = append(pars, chartInfo.ChartClassifyId)
  492. classifyItem, err := data_manage.GetChartClassifyByCondition(condition, pars)
  493. if err != nil && !utils.IsErrNoRow(err) {
  494. br.Msg = "删除失败"
  495. br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
  496. return
  497. }
  498. if classifyItem != nil {
  499. nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
  500. if err != nil && !utils.IsErrNoRow(err) {
  501. br.Msg = "删除失败"
  502. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  503. return
  504. }
  505. if nextItem != nil {
  506. resp.UniqueCode = nextItem.UniqueCode
  507. resp.ChartInfoId = nextItem.ChartInfoId
  508. }
  509. }
  510. }
  511. //新增操作日志
  512. {
  513. chartLog := new(data_manage.ChartInfoLog)
  514. chartLog.ChartName = chartInfo.ChartName
  515. chartLog.ChartInfoId = req.ChartInfoId
  516. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  517. chartLog.SysUserId = sysUser.AdminId
  518. chartLog.SysUserRealName = sysUser.RealName
  519. chartLog.UniqueCode = chartInfo.UniqueCode
  520. chartLog.CreateTime = time.Now()
  521. chartLog.Content = string(this.Ctx.Input.RequestBody)
  522. chartLog.Status = "删除图表"
  523. chartLog.Method = this.Ctx.Input.URI()
  524. go data_manage.AddChartInfoLog(chartLog)
  525. }
  526. }
  527. br.Ret = 200
  528. br.Msg = "删除成功"
  529. br.Success = true
  530. br.Data = resp
  531. br.IsAddLog = true
  532. }
  533. // ChartClassifyMove
  534. // @Title 统计特征图表分类移动接口
  535. // @Description 统计特征图表分类移动接口
  536. // @Success 200 {object} data_manage.MoveChartClassifyReq
  537. // @router /chart_classify/move [post]
  538. func (this *LineFeaturesChartClassifyController) ChartClassifyMove() {
  539. br := new(models.BaseResponse).Init()
  540. defer func() {
  541. this.Data["json"] = br
  542. this.ServeJSON()
  543. }()
  544. sysUser := this.SysUser
  545. if sysUser == nil {
  546. br.Msg = "请登录"
  547. br.ErrMsg = "请登录,SysUser Is Empty"
  548. br.Ret = 408
  549. return
  550. }
  551. var req data_manage.MoveChartClassifyReq
  552. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  553. if err != nil {
  554. br.Msg = "参数解析异常!"
  555. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  556. return
  557. }
  558. if req.ClassifyId <= 0 {
  559. br.Msg = "参数错误"
  560. br.ErrMsg = "分类id小于等于0"
  561. return
  562. }
  563. //判断分类是否存在
  564. chartClassifyInfo, err := data_manage.GetChartClassifyById(req.ClassifyId)
  565. if err != nil {
  566. br.Msg = "移动失败"
  567. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  568. return
  569. }
  570. if chartClassifyInfo.Source != utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION {
  571. br.Msg = "分类异常"
  572. br.ErrMsg = "分类异常,不是统计特征图表的分类"
  573. return
  574. }
  575. updateCol := make([]string, 0)
  576. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  577. if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  578. parentChartClassifyInfo, err := data_manage.GetChartClassifyById(req.ParentClassifyId)
  579. if err != nil {
  580. br.Msg = "移动失败"
  581. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  582. return
  583. }
  584. chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  585. chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  586. chartClassifyInfo.ModifyTime = time.Now()
  587. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  588. }
  589. //如果有传入 上一个兄弟节点分类id
  590. if req.PrevClassifyId > 0 {
  591. //上一个兄弟节点
  592. prevClassify, err := data_manage.GetChartClassifyById(req.PrevClassifyId)
  593. if err != nil {
  594. br.Msg = "移动失败"
  595. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  596. return
  597. }
  598. //如果是移动在两个兄弟节点之间
  599. if req.NextClassifyId > 0 {
  600. //下一个兄弟节点
  601. nextClassify, err := data_manage.GetChartClassifyById(req.NextClassifyId)
  602. if err != nil {
  603. br.Msg = "移动失败"
  604. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  605. return
  606. }
  607. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  608. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
  609. //变更兄弟节点的排序
  610. updateSortStr := `sort + 2`
  611. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
  612. } else {
  613. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  614. if nextClassify.Sort-prevClassify.Sort == 1 {
  615. //变更兄弟节点的排序
  616. updateSortStr := `sort + 1`
  617. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  618. }
  619. }
  620. }
  621. chartClassifyInfo.Sort = prevClassify.Sort + 1
  622. chartClassifyInfo.ModifyTime = time.Now()
  623. updateCol = append(updateCol, "Sort", "ModifyTime")
  624. } else {
  625. firstClassify, err := data_manage.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
  626. if err != nil && !utils.IsErrNoRow(err) {
  627. br.Msg = "移动失败"
  628. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  629. return
  630. }
  631. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  632. if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
  633. updateSortStr := ` sort + 1 `
  634. _ = data_manage.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
  635. }
  636. chartClassifyInfo.Sort = 0 //那就是排在第一位
  637. chartClassifyInfo.ModifyTime = time.Now()
  638. updateCol = append(updateCol, "Sort", "ModifyTime")
  639. }
  640. //更新
  641. if len(updateCol) > 0 {
  642. err = chartClassifyInfo.Update(updateCol)
  643. if err != nil {
  644. br.Msg = "移动失败"
  645. br.ErrMsg = "修改失败,Err:" + err.Error()
  646. return
  647. }
  648. }
  649. br.Ret = 200
  650. br.Success = true
  651. br.Msg = "移动成功"
  652. }