excel_classify.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/data_manage"
  7. "hongze/hz_crm_api/models/data_manage/request"
  8. "hongze/hz_crm_api/models/data_manage/response"
  9. "hongze/hz_crm_api/utils"
  10. "strconv"
  11. "time"
  12. )
  13. // ExcelClassifyController ETA表格分类
  14. type ExcelClassifyController struct {
  15. controllers.BaseAuthController
  16. }
  17. // List
  18. // @Title excel表格分类列表
  19. // @Description excel表格分类列表接口
  20. // @Success 200 {object} response.ExcelClassifyListResp
  21. // @router /excel_classify/list [get]
  22. func (this *ExcelClassifyController) List() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. // 获取一级分类
  29. rootList, err := data_manage.GetExcelClassifyByParentId(0)
  30. if err != nil && err.Error() != utils.ErrNoRow() {
  31. br.Msg = "获取失败"
  32. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  33. return
  34. }
  35. // 获取所有excel表格分类
  36. allExcelInfo, err := data_manage.GetNoContentExcelInfoAll()
  37. if err != nil && err.Error() != utils.ErrNoRow() {
  38. br.Msg = "获取失败"
  39. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  40. return
  41. }
  42. ExcelInfoMap := make(map[int][]*data_manage.ExcelClassifyItems)
  43. for _, v := range allExcelInfo {
  44. ExcelInfoMap[v.ExcelClassifyId] = append(ExcelInfoMap[v.ExcelClassifyId], v)
  45. }
  46. //rootChildMap := make(map[int][]*data_manage.ExcelClassifyItems)
  47. //for _, v := range classifyAll {
  48. // rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  49. // if existItems, ok := ExcelInfoMap[v.ExcelClassifyId]; ok {
  50. // v.Children = existItems
  51. // } else {
  52. // items := make([]*data_manage.ExcelClassifyItems, 0)
  53. // v.Children = items
  54. // }
  55. //}
  56. nodeAll := make([]*data_manage.ExcelClassifyItems, 0)
  57. for _, v := range rootList {
  58. var items []*data_manage.ExcelClassifyItems
  59. if tmpItem, ok := ExcelInfoMap[v.ExcelClassifyId]; ok {
  60. items = tmpItem
  61. } else {
  62. items = make([]*data_manage.ExcelClassifyItems, 0)
  63. }
  64. v.Children = items
  65. nodeAll = append(nodeAll, v)
  66. }
  67. resp := response.ExcelClassifyListResp{
  68. AllNodes: nodeAll,
  69. }
  70. br.Ret = 200
  71. br.Success = true
  72. br.Msg = "获取成功"
  73. br.Data = resp
  74. }
  75. // ExcelClassifyItems
  76. // @Title 获取所有excel表格分类接口-不包含表格
  77. // @Description 获取所有excel表格分类接口-不包含表格
  78. // @Success 200 {object} response.ExcelClassifyListResp
  79. // @router /excel_classify/items [get]
  80. func (this *ExcelClassifyController) ExcelClassifyItems() {
  81. br := new(models.BaseResponse).Init()
  82. defer func() {
  83. this.Data["json"] = br
  84. this.ServeJSON()
  85. }()
  86. rootList, err := data_manage.GetExcelClassifyByParentId(0)
  87. if err != nil {
  88. br.Msg = "获取失败"
  89. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  90. return
  91. }
  92. resp := response.ExcelClassifyListResp{
  93. AllNodes: rootList,
  94. }
  95. br.Ret = 200
  96. br.Success = true
  97. br.Msg = "获取成功"
  98. br.Data = resp
  99. }
  100. // AddExcelClassify
  101. // @Title 新增excel表格分类
  102. // @Description 新增excel表格分类接口
  103. // @Param request body request.AddExcelClassifyReq true "type json string"
  104. // @Success 200 Ret=200 保存成功
  105. // @router /excel_classify/add [post]
  106. func (this *ExcelClassifyController) AddExcelClassify() {
  107. br := new(models.BaseResponse).Init()
  108. defer func() {
  109. this.Data["json"] = br
  110. this.ServeJSON()
  111. }()
  112. var req request.AddExcelClassifyReq
  113. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  114. if err != nil {
  115. br.Msg = "参数解析异常!"
  116. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  117. return
  118. }
  119. if req.ExcelClassifyName == "" {
  120. br.Msg = "请输入分类名称"
  121. br.IsSendEmail = false
  122. return
  123. }
  124. if req.ParentId < 0 {
  125. br.Msg = "参数错误"
  126. br.IsSendEmail = false
  127. return
  128. }
  129. // 获取同级分类下存在同名分类的数量
  130. count, err := data_manage.GetExcelClassifyCount(req.ExcelClassifyName, req.ParentId)
  131. if err != nil {
  132. br.Msg = "判断名称是否已存在失败"
  133. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  134. return
  135. }
  136. if count > 0 {
  137. br.Msg = "分类名称已存在,请重新输入"
  138. br.IsSendEmail = false
  139. return
  140. }
  141. //获取该层级下最大的排序数
  142. maxSort, err := data_manage.GetExcelClassifyMaxSort(req.ParentId)
  143. // 入库
  144. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  145. classify := &data_manage.ExcelClassify{
  146. //ExcelClassifyId: 0,
  147. ExcelClassifyName: req.ExcelClassifyName,
  148. ParentId: req.ParentId,
  149. SysUserId: this.SysUser.AdminId,
  150. SysUserRealName: this.SysUser.RealName,
  151. Level: req.Level + 1,
  152. UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
  153. Sort: maxSort + 1,
  154. CreateTime: time.Now(),
  155. ModifyTime: time.Now(),
  156. }
  157. _, err = data_manage.AddExcelClassify(classify)
  158. if err != nil {
  159. br.Msg = "保存分类失败"
  160. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  161. return
  162. }
  163. br.Ret = 200
  164. br.Msg = "保存成功"
  165. br.Success = true
  166. }
  167. // EditExcelClassify
  168. // @Title 修改excel表格分类
  169. // @Description 修改excel表格分类
  170. // @Param request body request.EditExcelClassifyReq true "type json string"
  171. // @Success 200 Ret=200 修改成功
  172. // @router /excel_classify/edit [post]
  173. func (this *ExcelClassifyController) EditExcelClassify() {
  174. br := new(models.BaseResponse).Init()
  175. defer func() {
  176. this.Data["json"] = br
  177. this.ServeJSON()
  178. }()
  179. var req request.EditExcelClassifyReq
  180. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  181. if err != nil {
  182. br.Msg = "参数解析异常!"
  183. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  184. return
  185. }
  186. if req.ExcelClassifyName == "" {
  187. br.Msg = "请输入分类名称"
  188. br.IsSendEmail = false
  189. return
  190. }
  191. if req.ExcelClassifyId <= 0 {
  192. br.Msg = "参数错误"
  193. br.IsSendEmail = false
  194. return
  195. }
  196. item, err := data_manage.GetExcelClassifyById(req.ExcelClassifyId)
  197. if err != nil {
  198. br.Msg = "保存失败"
  199. br.Msg = "获取分类信息失败,Err:" + err.Error()
  200. return
  201. }
  202. // 名字一致的话,直接返回成功
  203. if item.ExcelClassifyName == req.ExcelClassifyName {
  204. br.Ret = 200
  205. br.Msg = "保存成功"
  206. br.Success = true
  207. return
  208. }
  209. // 获取同级分类下存在同名分类的数量
  210. count, err := data_manage.GetExcelClassifyCount(req.ExcelClassifyName, item.ParentId)
  211. if err != nil {
  212. br.Msg = "判断名称是否已存在失败"
  213. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  214. return
  215. }
  216. if count > 0 {
  217. br.Msg = "分类名称已存在,请重新输入"
  218. br.IsSendEmail = false
  219. return
  220. }
  221. // 修改分类名称
  222. item.ExcelClassifyName = req.ExcelClassifyName
  223. err = item.Update([]string{"ExcelClassifyName"})
  224. if err != nil {
  225. br.Msg = "保存失败"
  226. br.ErrMsg = "保存失败,Err:" + err.Error()
  227. return
  228. }
  229. br.Ret = 200
  230. br.Msg = "修改成功"
  231. br.Success = true
  232. br.IsAddLog = true
  233. }
  234. // DeleteExcelClassifyCheck
  235. // @Title 删除表格检测接口
  236. // @Description 删除表格检测接口
  237. // @Param request body request.ExcelClassifyDeleteCheckReq true "type json string"
  238. // @Success 200 {object} response.ExcelClassifyDeleteCheckResp
  239. // @router /excel_classify/delete/check [post]
  240. func (this *ExcelClassifyController) DeleteExcelClassifyCheck() {
  241. br := new(models.BaseResponse).Init()
  242. defer func() {
  243. this.Data["json"] = br
  244. this.ServeJSON()
  245. }()
  246. var req request.ExcelClassifyDeleteCheckReq
  247. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  248. if err != nil {
  249. br.Msg = "参数解析异常!"
  250. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  251. return
  252. }
  253. if req.ExcelClassifyId < 0 && req.ExcelInfoId <= 0 {
  254. br.Msg = "参数错误"
  255. br.IsSendEmail = false
  256. return
  257. }
  258. var deleteStatus int
  259. var tipsMsg string
  260. // 校验是否存在该分类
  261. ExcelClassifyInfo, err := data_manage.GetExcelClassifyById(req.ExcelClassifyId)
  262. if err != nil {
  263. if err.Error() == utils.ErrNoRow() {
  264. br.Msg = "该分类不存在"
  265. br.ErrMsg = "该分类不存在"
  266. return
  267. }
  268. br.Msg = "删除失败"
  269. br.ErrMsg = "查询该分类失败,Err:" + err.Error()
  270. return
  271. }
  272. if ExcelClassifyInfo == nil {
  273. br.Msg = "该分类不存在"
  274. br.ErrMsg = "该分类不存在"
  275. br.IsSendEmail = false
  276. return
  277. }
  278. //删除分类
  279. if req.ExcelClassifyId > 0 && req.ExcelInfoId == 0 {
  280. //判断表格分类下,是否含有表格
  281. count, err := data_manage.GetExcelInfoCountByClassifyId(req.ExcelClassifyId)
  282. if err != nil {
  283. br.Msg = "删除失败"
  284. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  285. return
  286. }
  287. if count > 0 {
  288. deleteStatus = 1
  289. tipsMsg = "该分类下关联表格不可删除"
  290. }
  291. }
  292. //if deleteStatus != 1 && req.ExcelInfoId == 0 {
  293. // classifyCount, err := data_manage.GetExcelClassifyCountByClassifyId(req.ExcelClassifyId)
  294. // if err != nil && err.Error() != utils.ErrNoRow() {
  295. // br.Msg = "删除失败"
  296. // br.ErrMsg = "分类下是否含有表格失败,Err:" + err.Error()
  297. // return
  298. // }
  299. // if classifyCount > 0 {
  300. // deleteStatus = 2
  301. // tipsMsg = "确认删除当前目录及包含的子目录吗?"
  302. // }
  303. //}
  304. if deleteStatus == 0 {
  305. tipsMsg = "可删除,进行删除操作"
  306. }
  307. resp := response.ExcelClassifyDeleteCheckResp{
  308. DeleteStatus: deleteStatus,
  309. TipsMsg: tipsMsg,
  310. }
  311. br.Ret = 200
  312. br.Msg = "检测成功"
  313. br.Success = true
  314. br.Data = resp
  315. }
  316. // DeleteExcelClassify
  317. // @Title 删除表格分类/表格
  318. // @Description 删除表格分类/表格接口
  319. // @Param request body request.DeleteExcelClassifyReq true "type json string"
  320. // @Success 200 Ret=200 删除成功
  321. // @router /excel_classify/delete [post]
  322. func (this *ExcelClassifyController) DeleteExcelClassify() {
  323. br := new(models.BaseResponse).Init()
  324. defer func() {
  325. this.Data["json"] = br
  326. this.ServeJSON()
  327. }()
  328. sysUser := this.SysUser
  329. if sysUser == nil {
  330. br.Msg = "请登录"
  331. br.ErrMsg = "请登录,SysUser Is Empty"
  332. br.Ret = 408
  333. return
  334. }
  335. var req request.DeleteExcelClassifyReq
  336. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  337. if err != nil {
  338. br.Msg = "参数解析异常!"
  339. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  340. return
  341. }
  342. if req.ExcelClassifyId < 0 && req.ExcelInfoId <= 0 {
  343. br.Msg = "参数错误"
  344. br.IsSendEmail = false
  345. return
  346. }
  347. //删除分类
  348. if req.ExcelClassifyId > 0 && req.ExcelInfoId == 0 {
  349. //判断是否含有指标
  350. count, err := data_manage.GetExcelInfoCountByClassifyId(req.ExcelClassifyId)
  351. if err != nil && err.Error() != utils.ErrNoRow() {
  352. br.Msg = "删除失败"
  353. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  354. return
  355. }
  356. if count > 0 {
  357. br.Msg = "该目录下存在关联ETA表格,不可删除"
  358. br.IsSendEmail = false
  359. return
  360. }
  361. classifyItem, err := data_manage.GetExcelClassifyById(req.ExcelClassifyId)
  362. if err != nil {
  363. br.Msg = "删除失败"
  364. br.ErrMsg = "获取分类失败,Err:" + err.Error()
  365. if err.Error() == utils.ErrNoRow() {
  366. br.Msg = "分类不存在"
  367. br.ErrMsg = "分类不存在"
  368. }
  369. return
  370. }
  371. classifyItem.IsDelete = 1
  372. err = classifyItem.Update([]string{"IsDelete"})
  373. if err != nil {
  374. br.Msg = "删除失败"
  375. br.ErrMsg = "删除失败,Err:" + err.Error()
  376. return
  377. }
  378. }
  379. resp := response.AddExcelInfoResp{}
  380. //删除表格
  381. if req.ExcelInfoId > 0 {
  382. excelInfo, err := data_manage.GetExcelInfoById(req.ExcelInfoId)
  383. if err != nil {
  384. if err.Error() == utils.ErrNoRow() {
  385. br.Msg = "表格已删除,请刷新页面"
  386. br.ErrMsg = "表格已删除,请刷新页面"
  387. return
  388. } else {
  389. br.Msg = "删除失败"
  390. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  391. return
  392. }
  393. }
  394. if excelInfo == nil {
  395. br.Msg = "表格已删除,请刷新页面"
  396. br.IsSendEmail = false
  397. return
  398. }
  399. //删除表格及关联指标
  400. excelInfo.IsDelete = 1
  401. err = excelInfo.Update([]string{"IsDelete"})
  402. if err != nil {
  403. br.Msg = "删除失败"
  404. br.ErrMsg = "删除失败,Err:" + err.Error()
  405. return
  406. }
  407. // 返回下一个表格的信息
  408. {
  409. var nextItem *data_manage.ExcelInfo
  410. var condition string
  411. var pars []interface{}
  412. condition += " AND excel_classify_id=? "
  413. pars = append(pars, excelInfo.ExcelClassifyId)
  414. condition += " AND (sort>? OR (sort=? AND excel_info_id<?) ) "
  415. pars = append(pars, excelInfo.Sort, excelInfo.Sort, excelInfo.ExcelInfoId)
  416. nextItem, err = data_manage.GetNextExcelInfoByCondition(condition, pars)
  417. if err != nil && err.Error() != utils.ErrNoRow() {
  418. br.Msg = "删除失败"
  419. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  420. return
  421. }
  422. // 如果没找到,那么查找下一个分类的第一个表格
  423. if nextItem == nil {
  424. currClassifyInfo, err := data_manage.GetExcelClassifyById(excelInfo.ExcelClassifyId)
  425. if err != nil && err.Error() != utils.ErrNoRow() {
  426. br.Msg = "删除失败"
  427. br.ErrMsg = "获取当前表格分类信息失败,Err:" + err.Error()
  428. return
  429. }
  430. //var condition string
  431. //var pars []interface{}
  432. //condition += " AND level=3 "
  433. //pars = append(pars, chartInfo.ExcelClassifyId)
  434. //condition += " AND (sort>? OR (sort=? and excel_classify_id >?) ) "
  435. //pars = append(pars, currClassifyInfo.Sort, currClassifyInfo.Sort, currClassifyInfo.ExcelClassifyId)
  436. //
  437. //classifyItem, err := data_manage.GetNextExcelClassifyByCondition(condition, pars)
  438. //if err != nil && err.Error() != utils.ErrNoRow() {
  439. // br.Msg = "删除失败"
  440. // br.ErrMsg = "获取下一级表格分类信息失败,Err:" + err.Error()
  441. // return
  442. //}
  443. //if classifyItem != nil {
  444. // nextItem, err = data_manage.GetNextExcelInfo(excelInfo.ExcelClassifyId)
  445. // if err != nil && err.Error() != utils.ErrNoRow() {
  446. // br.Msg = "删除失败"
  447. // br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  448. // return
  449. // }
  450. //}
  451. nextItem, err = data_manage.GetNextExcelInfo(excelInfo.ExcelClassifyId, currClassifyInfo.Sort)
  452. if err != nil && err.Error() != utils.ErrNoRow() {
  453. br.Msg = "删除失败"
  454. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  455. return
  456. }
  457. }
  458. // 如果找到下一个表格了,那么就返回
  459. if nextItem != nil {
  460. resp = response.AddExcelInfoResp{
  461. ExcelInfoId: nextItem.ExcelInfoId,
  462. UniqueCode: nextItem.UniqueCode,
  463. }
  464. }
  465. }
  466. //新增操作日志
  467. //{
  468. // ExcelLog := new(data_manage.ExcelInfoLog)
  469. // ExcelLog.ExcelName = ExcelInfo.ExcelName
  470. // ExcelLog.ExcelInfoId = req.ExcelInfoId
  471. // ExcelLog.ExcelClassifyId = ExcelInfo.ExcelClassifyId
  472. // ExcelLog.SysUserId = sysUser.AdminId
  473. // ExcelLog.SysUserRealName = sysUser.RealName
  474. // ExcelLog.UniqueCode = ExcelInfo.UniqueCode
  475. // ExcelLog.CreateTime = time.Now()
  476. // ExcelLog.Content = string(this.Ctx.Input.RequestBody)
  477. // ExcelLog.Status = "删除表格"
  478. // ExcelLog.Method = this.Ctx.Input.URI()
  479. // go data_manage.AddExcelInfoLog(ExcelLog)
  480. //}
  481. }
  482. br.Ret = 200
  483. br.Msg = "删除成功"
  484. br.Success = true
  485. br.Data = resp
  486. br.IsAddLog = true
  487. }
  488. // ExcelClassifyMove
  489. // @Title 表格分类移动接口
  490. // @Description 表格分类移动接口
  491. // @Success 200 {object} request.MoveExcelClassifyReq
  492. // @router /excel_classify/move [post]
  493. func (this *ExcelClassifyController) ExcelClassifyMove() {
  494. br := new(models.BaseResponse).Init()
  495. defer func() {
  496. this.Data["json"] = br
  497. this.ServeJSON()
  498. }()
  499. sysUser := this.SysUser
  500. if sysUser == nil {
  501. br.Msg = "请登录"
  502. br.ErrMsg = "请登录,SysUser Is Empty"
  503. br.Ret = 408
  504. return
  505. }
  506. var req request.MoveExcelClassifyReq
  507. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  508. if err != nil {
  509. br.Msg = "参数解析异常!"
  510. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  511. return
  512. }
  513. if req.ClassifyId <= 0 {
  514. br.Msg = "参数错误"
  515. br.ErrMsg = "分类id小于等于0"
  516. br.IsSendEmail = false
  517. return
  518. }
  519. //判断分类是否存在
  520. ExcelClassifyInfo, err := data_manage.GetExcelClassifyById(req.ClassifyId)
  521. if err != nil {
  522. br.Msg = "移动失败"
  523. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  524. return
  525. }
  526. updateCol := make([]string, 0)
  527. //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  528. if ExcelClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  529. parentExcelClassifyInfo, err := data_manage.GetExcelClassifyById(req.ParentClassifyId)
  530. if err != nil {
  531. br.Msg = "移动失败"
  532. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  533. return
  534. }
  535. ExcelClassifyInfo.ParentId = parentExcelClassifyInfo.ExcelClassifyId
  536. ExcelClassifyInfo.Level = parentExcelClassifyInfo.Level + 1
  537. ExcelClassifyInfo.ModifyTime = time.Now()
  538. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  539. }
  540. //如果有传入 上一个兄弟节点分类id
  541. if req.PrevClassifyId > 0 {
  542. //上一个兄弟节点
  543. prevClassify, err := data_manage.GetExcelClassifyById(req.PrevClassifyId)
  544. if err != nil {
  545. br.Msg = "移动失败"
  546. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  547. return
  548. }
  549. //如果是移动在两个兄弟节点之间
  550. if req.NextClassifyId > 0 {
  551. //下一个兄弟节点
  552. nextClassify, err := data_manage.GetExcelClassifyById(req.NextClassifyId)
  553. if err != nil {
  554. br.Msg = "移动失败"
  555. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  556. return
  557. }
  558. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  559. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == ExcelClassifyInfo.Sort {
  560. //变更兄弟节点的排序
  561. updateSortStr := `sort + 2`
  562. _ = data_manage.UpdateExcelClassifySortByParentId(prevClassify.ParentId, prevClassify.ExcelClassifyId, prevClassify.Sort, updateSortStr)
  563. } else {
  564. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  565. if nextClassify.Sort-prevClassify.Sort == 1 {
  566. //变更兄弟节点的排序
  567. updateSortStr := `sort + 1`
  568. _ = data_manage.UpdateExcelClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  569. }
  570. }
  571. }
  572. ExcelClassifyInfo.Sort = prevClassify.Sort + 1
  573. ExcelClassifyInfo.ModifyTime = time.Now()
  574. updateCol = append(updateCol, "Sort", "ModifyTime")
  575. } else {
  576. firstClassify, err := data_manage.GetFirstExcelClassifyByParentId(ExcelClassifyInfo.ParentId)
  577. if err != nil && err.Error() != utils.ErrNoRow() {
  578. br.Msg = "移动失败"
  579. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  580. return
  581. }
  582. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  583. if firstClassify != nil && firstClassify.Sort == 0 {
  584. updateSortStr := ` sort + 1 `
  585. _ = data_manage.UpdateExcelClassifySortByParentId(firstClassify.ParentId, firstClassify.ExcelClassifyId-1, 0, updateSortStr)
  586. }
  587. ExcelClassifyInfo.Sort = 0 //那就是排在第一位
  588. ExcelClassifyInfo.ModifyTime = time.Now()
  589. updateCol = append(updateCol, "Sort", "ModifyTime")
  590. }
  591. //更新
  592. if len(updateCol) > 0 {
  593. err = ExcelClassifyInfo.Update(updateCol)
  594. if err != nil {
  595. br.Msg = "移动失败"
  596. br.ErrMsg = "修改失败,Err:" + err.Error()
  597. return
  598. }
  599. }
  600. br.Ret = 200
  601. br.Success = true
  602. br.IsAddLog = true
  603. br.Msg = "移动成功"
  604. }