excel_classify.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. package excel
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/controllers"
  5. "eta/eta_mobile/models"
  6. "eta/eta_mobile/models/data_manage/excel"
  7. "eta/eta_mobile/models/data_manage/excel/request"
  8. response2 "eta/eta_mobile/models/data_manage/excel/response"
  9. "eta/eta_mobile/services/data/data_manage_permission"
  10. excel2 "eta/eta_mobile/services/data/excel"
  11. "eta/eta_mobile/utils"
  12. "fmt"
  13. "sort"
  14. "strconv"
  15. "time"
  16. )
  17. // ExcelClassifyController ETA表格分类
  18. type ExcelClassifyController struct {
  19. controllers.BaseAuthController
  20. }
  21. // List
  22. // @Title excel表格分类列表
  23. // @Description excel表格分类列表接口
  24. // @Param Source query int true "格来源,1:excel插件的表格,2:自定义表格,3:混合表格,默认:1"
  25. // @Param IsShowMe query bool true "是否只看我的,true、false"
  26. // @Success 200 {object} response.ExcelClassifyListResp
  27. // @router /excel_classify/list [get]
  28. func (this *ExcelClassifyController) List() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. source, _ := this.GetInt("Source")
  35. if source <= 0 {
  36. source = utils.EXCEL_DEFAULT
  37. }
  38. //只看我的
  39. isShowMe, _ := this.GetBool("IsShowMe")
  40. // 自定义分析只看自己的
  41. if source == utils.CUSTOM_ANALYSIS_TABLE {
  42. br = AnalysisClassifyList(this)
  43. return
  44. }
  45. showUserId := 0
  46. if isShowMe {
  47. showUserId = this.SysUser.AdminId
  48. }
  49. classifyList, err := excel.GetExcelClassifyBySource(source)
  50. if err != nil {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  53. return
  54. }
  55. // 分类map
  56. classifyMap := make(map[int]*excel.ExcelClassifyItems)
  57. for _, v := range classifyList {
  58. classifyMap[v.ExcelClassifyId] = v
  59. }
  60. // 获取二级分类
  61. // 获取三级分类
  62. // 根据来源获取所有excel表格(无内容)
  63. allExcelInfo, err := excel.GetNoContentExcelInfoAll(source, showUserId)
  64. if err != nil && err.Error() != utils.ErrNoRow() {
  65. br.Msg = "获取失败"
  66. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  67. return
  68. }
  69. // 获取所有有权限的指标和分类
  70. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserExcelAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  71. if err != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  74. return
  75. }
  76. ExcelInfoMap := make(map[int][]*excel.ExcelClassifyItems)
  77. for _, v := range allExcelInfo {
  78. // 数据权限
  79. if classifyInfo, ok := classifyMap[v.ExcelClassifyId]; ok {
  80. v.HaveOperaAuth = data_manage_permission.CheckExcelPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.ExcelInfoId, v.ExcelClassifyId, permissionEdbIdList, permissionClassifyIdList)
  81. }
  82. ExcelInfoMap[v.ExcelClassifyId] = append(ExcelInfoMap[v.ExcelClassifyId], v)
  83. }
  84. classifyListMap := make(map[int][]*excel.ExcelClassifyItems)
  85. for _, v := range classifyList {
  86. // 数据权限
  87. v.HaveOperaAuth = data_manage_permission.CheckExcelClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ExcelClassifyId, permissionClassifyIdList)
  88. if existItems, ok := ExcelInfoMap[v.ExcelClassifyId]; ok {
  89. v.Children = existItems
  90. }
  91. }
  92. for _, v := range classifyList {
  93. if v.ParentId > 0 {
  94. classifyListMap[v.ParentId] = append(classifyListMap[v.ParentId], v)
  95. }
  96. }
  97. //组装三级分类
  98. for key, classify := range classifyList {
  99. subList, ok := classifyListMap[classify.ExcelClassifyId]
  100. if ok {
  101. classifyList[key].Children = append(classifyList[key].Children, subList...)
  102. sort.Slice(classifyList[key].Children, func(i, j int) bool {
  103. return excel.ExcelClassifyItemBySort(classifyList[key].Children[i], classifyList[key].Children[j])
  104. })
  105. }
  106. }
  107. nodeAll := make([]*excel.ExcelClassifyItems, 0)
  108. for _, v := range classifyList {
  109. if v.ParentId == 0 {
  110. sort.Slice(v.Children, func(i, j int) bool { return excel.ExcelClassifyItemBySort(v.Children[i], v.Children[j]) })
  111. nodeAll = append(nodeAll, v)
  112. }
  113. }
  114. resp := response2.ExcelClassifyListResp{
  115. AllNodes: nodeAll,
  116. }
  117. br.Ret = 200
  118. br.Success = true
  119. br.Msg = "获取成功"
  120. br.Data = resp
  121. }
  122. func AnalysisClassifyList(this *ExcelClassifyController) (br *models.BaseResponse) {
  123. br = new(models.BaseResponse).Init()
  124. defer func() {
  125. this.Data["json"] = br
  126. this.ServeJSON()
  127. }()
  128. source, _ := this.GetInt("Source")
  129. if source <= 0 {
  130. source = utils.EXCEL_DEFAULT
  131. }
  132. //只看我的
  133. showUserId := this.SysUser.AdminId
  134. classifyList, err := excel.GetExcelClassifyBySource(source)
  135. if err != nil {
  136. br.Msg = "获取失败"
  137. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  138. return
  139. }
  140. // 分类map
  141. classifyMap := make(map[int]*excel.ExcelClassifyItems)
  142. for _, v := range classifyList {
  143. classifyMap[v.ExcelClassifyId] = v
  144. }
  145. // 获取二级分类
  146. // 获取三级分类
  147. // 根据来源获取所有excel表格(无内容)
  148. allExcelInfo, err := excel.GetNoContentExcelInfoAll(source, showUserId)
  149. if err != nil && err.Error() != utils.ErrNoRow() {
  150. br.Msg = "获取失败"
  151. br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
  152. return
  153. }
  154. // 获取所有有权限的指标和分类
  155. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserExcelAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  156. if err != nil {
  157. br.Msg = "获取失败"
  158. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  159. return
  160. }
  161. ExcelInfoMap := make(map[int][]*excel.ExcelClassifyItems)
  162. for _, v := range allExcelInfo {
  163. // 数据权限
  164. if classifyInfo, ok := classifyMap[v.ExcelClassifyId]; ok {
  165. v.HaveOperaAuth = data_manage_permission.CheckExcelPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.ExcelInfoId, v.ExcelClassifyId, permissionEdbIdList, permissionClassifyIdList)
  166. }
  167. ExcelInfoMap[v.ExcelClassifyId] = append(ExcelInfoMap[v.ExcelClassifyId], v)
  168. }
  169. classifyListMap := make(map[int][]*excel.ExcelClassifyItems)
  170. for _, v := range classifyList {
  171. // 数据权限
  172. v.HaveOperaAuth = data_manage_permission.CheckExcelClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ExcelClassifyId, permissionClassifyIdList)
  173. if existItems, ok := ExcelInfoMap[v.ExcelClassifyId]; ok {
  174. v.Children = existItems
  175. }
  176. }
  177. for _, v := range classifyList {
  178. if v.ParentId > 0 {
  179. classifyListMap[v.ParentId] = append(classifyListMap[v.ParentId], v)
  180. }
  181. }
  182. //组装三级分类
  183. for key, classify := range classifyList {
  184. subList, ok := classifyListMap[classify.ExcelClassifyId]
  185. if ok {
  186. classifyList[key].Children = append(classifyList[key].Children, subList...)
  187. sort.Slice(classifyList[key].Children, func(i, j int) bool {
  188. return excel.ExcelClassifyItemBySort(classifyList[key].Children[i], classifyList[key].Children[j])
  189. })
  190. }
  191. }
  192. nodeAll := make([]*excel.ExcelClassifyItems, 0)
  193. for _, v := range classifyList {
  194. if v.ParentId == 0 {
  195. sort.Slice(v.Children, func(i, j int) bool { return excel.ExcelClassifyItemBySort(v.Children[i], v.Children[j]) })
  196. nodeAll = append(nodeAll, v)
  197. }
  198. }
  199. // 自定义分析只看自己的分类
  200. nodeAll = removeNodesWithAnalysisClassify(nodeAll, this.SysUser.AdminId)
  201. resp := response2.ExcelClassifyListResp{
  202. AllNodes: nodeAll,
  203. }
  204. br.Ret = 200
  205. br.Success = true
  206. br.Msg = "获取成功"
  207. br.Data = resp
  208. return
  209. }
  210. // removeNodesWithAnalysisClassify
  211. // @Description: 自定义分析只看自己的分类,所以需要移除分类
  212. // @author: Roc
  213. // @datetime 2024-04-09 13:46:51
  214. // @param nodes []*excel.ExcelClassifyItems
  215. // @param adminId int
  216. // @return []*excel.ExcelClassifyItems
  217. func removeNodesWithAnalysisClassify(nodes []*excel.ExcelClassifyItems, adminId int) []*excel.ExcelClassifyItems {
  218. var newListNode []*excel.ExcelClassifyItems
  219. for _, node := range nodes {
  220. if node.Children != nil {
  221. node.Children = removeNodesWithAnalysisClassify(node.Children, adminId)
  222. }
  223. // 如果是ETA表格,那么就保留
  224. if node.ExcelInfoId > 0 {
  225. newListNode = append(newListNode, node)
  226. continue
  227. }
  228. // 如果是公共分类,且名下的ETA表格不为空,那么就保留
  229. if node.SysUserId == 0 && node.Children != nil && len(node.Children) > 0 {
  230. newListNode = append(newListNode, node)
  231. continue
  232. }
  233. // 如果是自己的分类,那么就保留
  234. if node.SysUserId == adminId {
  235. newListNode = append(newListNode, node)
  236. continue
  237. }
  238. }
  239. return newListNode
  240. }
  241. // ExcelClassifyItems
  242. // @Title 获取所有excel表格分类接口-不包含表格
  243. // @Description 获取所有excel表格分类接口-不包含表格
  244. // @Param Source query int true "格来源,1:excel插件的表格,2:自定义表格,3:混合表格,默认:1"
  245. // @Success 200 {object} response.ExcelClassifyListResp
  246. // @router /excel_classify/items [get]
  247. func (this *ExcelClassifyController) ExcelClassifyItems() {
  248. br := new(models.BaseResponse).Init()
  249. defer func() {
  250. this.Data["json"] = br
  251. this.ServeJSON()
  252. }()
  253. source, _ := this.GetInt("Source")
  254. if source <= 0 {
  255. source = utils.EXCEL_DEFAULT
  256. }
  257. classifyList, err := excel.GetExcelClassifyBySource(source)
  258. if err != nil {
  259. br.Msg = "获取失败"
  260. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  261. return
  262. }
  263. // 获取二级分类
  264. // 获取三级分类
  265. classifyMap := make(map[int][]*excel.ExcelClassifyItems)
  266. for _, v := range classifyList {
  267. if v.ParentId > 0 {
  268. classifyMap[v.ParentId] = append(classifyMap[v.ParentId], v)
  269. }
  270. }
  271. //组装三级分类
  272. for key, classify := range classifyList {
  273. subList, ok := classifyMap[classify.ExcelClassifyId]
  274. if ok {
  275. classifyList[key].Children = append(classifyList[key].Children, subList...)
  276. }
  277. }
  278. nodeAll := make([]*excel.ExcelClassifyItems, 0)
  279. for _, v := range classifyList {
  280. if v.ParentId == 0 {
  281. nodeAll = append(nodeAll, v)
  282. }
  283. }
  284. resp := response2.ExcelClassifyListResp{
  285. AllNodes: nodeAll,
  286. }
  287. br.Ret = 200
  288. br.Success = true
  289. br.Msg = "获取成功"
  290. br.Data = resp
  291. }
  292. // AddExcelClassify
  293. // @Title 新增excel表格分类
  294. // @Description 新增excel表格分类接口
  295. // @Param request body request.AddExcelClassifyReq true "type json string"
  296. // @Success 200 Ret=200 保存成功
  297. // @router /excel_classify/add [post]
  298. func (this *ExcelClassifyController) AddExcelClassify() {
  299. br := new(models.BaseResponse).Init()
  300. defer func() {
  301. this.Data["json"] = br
  302. this.ServeJSON()
  303. }()
  304. var req request.AddExcelClassifyReq
  305. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  306. if err != nil {
  307. br.Msg = "参数解析异常!"
  308. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  309. return
  310. }
  311. if req.ExcelClassifyName == "" {
  312. br.Msg = "请输入分类名称"
  313. br.IsSendEmail = false
  314. return
  315. }
  316. if req.ParentId < 0 {
  317. br.Msg = "参数错误"
  318. br.IsSendEmail = false
  319. return
  320. }
  321. source := req.Source
  322. if source <= 0 {
  323. source = utils.EXCEL_DEFAULT
  324. }
  325. // 获取同级分类下存在同名分类的数量
  326. count, err := excel.GetExcelClassifyCount(req.ExcelClassifyName, req.ParentId, source)
  327. if err != nil {
  328. br.Msg = "判断名称是否已存在失败"
  329. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  330. return
  331. }
  332. if count > 0 {
  333. br.Msg = "分类名称已存在,请重新输入"
  334. br.IsSendEmail = false
  335. return
  336. }
  337. //获取该层级下最大的排序数
  338. maxSort, err := excel2.GetExcelClassifyMaxSort(req.ParentId, req.Source)
  339. if err != nil {
  340. br.Msg = "获取失败"
  341. br.ErrMsg = "查询排序信息失败,Err:" + err.Error()
  342. return
  343. }
  344. level := 1
  345. // 查询父级分类是否存在
  346. if req.ParentId > 0 {
  347. var parent *excel.ExcelClassify
  348. parent, err = excel.GetExcelClassifyById(req.ParentId)
  349. if err != nil {
  350. if err.Error() == utils.ErrNoRow() {
  351. br.Msg = "父级分类不存在"
  352. return
  353. }
  354. br.Msg = "获取失败"
  355. br.ErrMsg = "查询父级分类信息失败,Err:" + err.Error()
  356. return
  357. }
  358. level = parent.Level + 1
  359. }
  360. // 入库
  361. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  362. classify := &excel.ExcelClassify{
  363. //ExcelClassifyId: 0,
  364. ExcelClassifyName: req.ExcelClassifyName,
  365. ParentId: req.ParentId,
  366. Source: source,
  367. SysUserId: this.SysUser.AdminId,
  368. SysUserRealName: this.SysUser.RealName,
  369. Level: level,
  370. UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
  371. Sort: maxSort + 1,
  372. CreateTime: time.Now(),
  373. ModifyTime: time.Now(),
  374. }
  375. _, err = excel.AddExcelClassify(classify)
  376. if err != nil {
  377. br.Msg = "保存分类失败"
  378. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  379. return
  380. }
  381. // 继承分类权限
  382. {
  383. go data_manage_permission.InheritParentClassify(6, source, classify.ExcelClassifyId, classify.ParentId, classify.ExcelClassifyName)
  384. }
  385. br.Ret = 200
  386. br.Msg = "保存成功"
  387. br.Success = true
  388. }
  389. // EditExcelClassify
  390. // @Title 修改excel表格分类
  391. // @Description 修改excel表格分类
  392. // @Param request body request.EditExcelClassifyReq true "type json string"
  393. // @Success 200 Ret=200 修改成功
  394. // @router /excel_classify/edit [post]
  395. func (this *ExcelClassifyController) EditExcelClassify() {
  396. br := new(models.BaseResponse).Init()
  397. defer func() {
  398. this.Data["json"] = br
  399. this.ServeJSON()
  400. }()
  401. var req request.EditExcelClassifyReq
  402. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  403. if err != nil {
  404. br.Msg = "参数解析异常!"
  405. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  406. return
  407. }
  408. if req.ExcelClassifyName == "" {
  409. br.Msg = "请输入分类名称"
  410. br.IsSendEmail = false
  411. return
  412. }
  413. if req.ExcelClassifyId <= 0 {
  414. br.Msg = "参数错误"
  415. br.IsSendEmail = false
  416. return
  417. }
  418. item, err := excel.GetExcelClassifyById(req.ExcelClassifyId)
  419. if err != nil {
  420. br.Msg = "保存失败"
  421. br.Msg = "获取分类信息失败,Err:" + err.Error()
  422. return
  423. }
  424. // 名字一致的话,直接返回成功
  425. if item.ExcelClassifyName == req.ExcelClassifyName {
  426. br.Ret = 200
  427. br.Msg = "保存成功"
  428. br.Success = true
  429. return
  430. }
  431. // 获取同级分类下存在同名分类的数量
  432. count, err := excel.GetExcelClassifyCount(req.ExcelClassifyName, item.ParentId, item.Source)
  433. if err != nil {
  434. br.Msg = "判断名称是否已存在失败"
  435. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  436. return
  437. }
  438. if count > 0 {
  439. br.Msg = "分类名称已存在,请重新输入"
  440. br.IsSendEmail = false
  441. return
  442. }
  443. // 修改分类名称
  444. item.ExcelClassifyName = req.ExcelClassifyName
  445. err = item.Update([]string{"ExcelClassifyName"})
  446. if err != nil {
  447. br.Msg = "保存失败"
  448. br.ErrMsg = "保存失败,Err:" + err.Error()
  449. return
  450. }
  451. br.Ret = 200
  452. br.Msg = "修改成功"
  453. br.Success = true
  454. br.IsAddLog = true
  455. }
  456. // DeleteExcelClassifyCheck
  457. // @Title 删除表格检测接口
  458. // @Description 删除表格检测接口
  459. // @Param request body request.ExcelClassifyDeleteCheckReq true "type json string"
  460. // @Success 200 {object} response.ExcelClassifyDeleteCheckResp
  461. // @router /excel_classify/delete/check [post]
  462. func (this *ExcelClassifyController) DeleteExcelClassifyCheck() {
  463. br := new(models.BaseResponse).Init()
  464. defer func() {
  465. this.Data["json"] = br
  466. this.ServeJSON()
  467. }()
  468. var req request.ExcelClassifyDeleteCheckReq
  469. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  470. if err != nil {
  471. br.Msg = "参数解析异常!"
  472. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  473. return
  474. }
  475. if req.ExcelClassifyId < 0 && req.ExcelInfoId <= 0 {
  476. br.Msg = "参数错误"
  477. br.IsSendEmail = false
  478. return
  479. }
  480. var deleteStatus int
  481. var tipsMsg string
  482. // 校验是否存在该分类
  483. ExcelClassifyInfo, err := excel.GetExcelClassifyById(req.ExcelClassifyId)
  484. if err != nil {
  485. if err.Error() == utils.ErrNoRow() {
  486. br.Msg = "该分类不存在"
  487. br.ErrMsg = "该分类不存在"
  488. return
  489. }
  490. br.Msg = "删除失败"
  491. br.ErrMsg = "查询该分类失败,Err:" + err.Error()
  492. return
  493. }
  494. if ExcelClassifyInfo == nil {
  495. br.Msg = "该分类不存在"
  496. br.ErrMsg = "该分类不存在"
  497. br.IsSendEmail = false
  498. return
  499. }
  500. //删除分类
  501. if req.ExcelClassifyId > 0 && req.ExcelInfoId == 0 {
  502. //判断表格分类下,是否含有表格
  503. count, err := excel.GetExcelInfoCountByClassifyId(req.ExcelClassifyId)
  504. if err != nil {
  505. br.Msg = "删除失败"
  506. br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  507. return
  508. }
  509. if count > 0 {
  510. deleteStatus = 1
  511. tipsMsg = "该分类下关联表格不可删除"
  512. } else {
  513. childClassify, e := excel.GetChildClassifyById(req.ExcelClassifyId)
  514. if e != nil && e.Error() != utils.ErrNoRow() {
  515. br.Msg = "获取失败"
  516. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  517. return
  518. }
  519. if len(childClassify) > 0 {
  520. var classifyIds []int
  521. for _, v := range childClassify {
  522. classifyIds = append(classifyIds, v.ExcelClassifyId)
  523. }
  524. condition := fmt.Sprintf(` AND excel_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  525. var pars []interface{}
  526. pars = append(pars, classifyIds)
  527. childCount, err := excel.GetExcelInfoCountByCondition(condition, pars)
  528. if err != nil && err.Error() != utils.ErrNoRow() {
  529. br.Msg = "删除失败"
  530. br.ErrMsg = "查询分类下表格数量失败,Err:" + err.Error()
  531. return
  532. }
  533. if childCount > 0 {
  534. deleteStatus = 1
  535. tipsMsg = "该分类下关联表格不可删除"
  536. }
  537. }
  538. }
  539. }
  540. //if deleteStatus != 1 && req.ExcelInfoId == 0 {
  541. // classifyCount, err := data_manage.GetExcelClassifyCountByClassifyId(req.ExcelClassifyId)
  542. // if err != nil && err.Error() != utils.ErrNoRow() {
  543. // br.Msg = "删除失败"
  544. // br.ErrMsg = "分类下是否含有表格失败,Err:" + err.Error()
  545. // return
  546. // }
  547. // if classifyCount > 0 {
  548. // deleteStatus = 2
  549. // tipsMsg = "确认删除当前目录及包含的子目录吗?"
  550. // }
  551. //}
  552. if deleteStatus == 0 {
  553. tipsMsg = "可删除,进行删除操作"
  554. }
  555. resp := response2.ExcelClassifyDeleteCheckResp{
  556. DeleteStatus: deleteStatus,
  557. TipsMsg: tipsMsg,
  558. }
  559. br.Ret = 200
  560. br.Msg = "检测成功"
  561. br.Success = true
  562. br.Data = resp
  563. }
  564. // DeleteExcelClassify
  565. // @Title 删除表格分类/表格
  566. // @Description 删除表格分类/表格接口
  567. // @Param request body request.DeleteExcelClassifyReq true "type json string"
  568. // @Success 200 Ret=200 删除成功
  569. // @router /excel_classify/delete [post]
  570. func (this *ExcelClassifyController) DeleteExcelClassify() {
  571. br := new(models.BaseResponse).Init()
  572. defer func() {
  573. this.Data["json"] = br
  574. this.ServeJSON()
  575. }()
  576. sysUser := this.SysUser
  577. if sysUser == nil {
  578. br.Msg = "请登录"
  579. br.ErrMsg = "请登录,SysUser Is Empty"
  580. br.Ret = 408
  581. return
  582. }
  583. var req request.DeleteExcelClassifyReq
  584. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  585. if err != nil {
  586. br.Msg = "参数解析异常!"
  587. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  588. return
  589. }
  590. if req.ExcelClassifyId < 0 && req.ExcelInfoId <= 0 {
  591. br.Msg = "参数错误"
  592. br.IsSendEmail = false
  593. return
  594. }
  595. //删除分类
  596. if req.ExcelClassifyId > 0 && req.ExcelInfoId == 0 {
  597. //判断是否含有指标
  598. count, err := excel.GetExcelInfoCountByClassifyId(req.ExcelClassifyId)
  599. if err != nil && err.Error() != utils.ErrNoRow() {
  600. br.Msg = "删除失败"
  601. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  602. return
  603. }
  604. if count > 0 {
  605. br.Msg = "该目录下存在关联ETA表格,不可删除"
  606. br.IsSendEmail = false
  607. return
  608. } else {
  609. childClassify, e := excel.GetChildClassifyById(req.ExcelClassifyId)
  610. if e != nil && e.Error() != utils.ErrNoRow() {
  611. br.Msg = "获取失败"
  612. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  613. return
  614. }
  615. if len(childClassify) > 0 {
  616. var classifyIds []int
  617. for _, v := range childClassify {
  618. classifyIds = append(classifyIds, v.ExcelClassifyId)
  619. }
  620. condition := fmt.Sprintf(` AND excel_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  621. var pars []interface{}
  622. pars = append(pars, classifyIds)
  623. childCount, err := excel.GetExcelInfoCountByCondition(condition, pars)
  624. if err != nil && err.Error() != utils.ErrNoRow() {
  625. br.Msg = "删除失败"
  626. br.ErrMsg = "查询分类下表格数量失败,Err:" + err.Error()
  627. return
  628. }
  629. if childCount > 0 {
  630. br.Msg = "该目录下存在关联ETA表格,不可删除"
  631. br.IsSendEmail = false
  632. return
  633. }
  634. }
  635. }
  636. classifyItem, err := excel.GetExcelClassifyById(req.ExcelClassifyId)
  637. if err != nil {
  638. br.Msg = "删除失败"
  639. br.ErrMsg = "获取分类失败,Err:" + err.Error()
  640. if err.Error() == utils.ErrNoRow() {
  641. br.Msg = "分类不存在"
  642. br.ErrMsg = "分类不存在"
  643. }
  644. return
  645. }
  646. classifyItem.IsDelete = 1
  647. err = classifyItem.Update([]string{"IsDelete"})
  648. if err != nil {
  649. br.Msg = "删除失败"
  650. br.ErrMsg = "删除失败,Err:" + err.Error()
  651. return
  652. }
  653. }
  654. resp := response2.AddExcelInfoResp{}
  655. //删除表格
  656. if req.ExcelInfoId > 0 {
  657. excelInfo, err := excel.GetExcelInfoById(req.ExcelInfoId)
  658. if err != nil {
  659. if err.Error() == utils.ErrNoRow() {
  660. br.Msg = "表格已删除,请刷新页面"
  661. br.ErrMsg = "表格已删除,请刷新页面"
  662. return
  663. } else {
  664. br.Msg = "删除失败"
  665. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  666. return
  667. }
  668. }
  669. if excelInfo == nil {
  670. br.Msg = "表格已删除,请刷新页面"
  671. br.IsSendEmail = false
  672. return
  673. }
  674. // 删除excel
  675. err, errMsg, isSendEmail := excel2.Delete(excelInfo, sysUser)
  676. if err != nil {
  677. br.Msg = "删除失败"
  678. if errMsg != `` {
  679. br.Msg = errMsg
  680. }
  681. br.ErrMsg = "删除失败,Err:" + err.Error()
  682. br.IsSendEmail = isSendEmail
  683. return
  684. }
  685. // 返回下一个表格的信息
  686. {
  687. var nextItem *excel.ExcelInfo
  688. var condition string
  689. var pars []interface{}
  690. condition += " AND excel_classify_id=? "
  691. pars = append(pars, excelInfo.ExcelClassifyId)
  692. condition += " AND (sort>? OR (sort=? AND excel_info_id<?) ) "
  693. pars = append(pars, excelInfo.Sort, excelInfo.Sort, excelInfo.ExcelInfoId)
  694. nextItem, err = excel.GetNextExcelInfoByCondition(condition, pars)
  695. if err != nil && err.Error() != utils.ErrNoRow() {
  696. br.Msg = "删除失败"
  697. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  698. return
  699. }
  700. // 如果没找到,那么查找下一个分类的第一个表格
  701. if nextItem == nil {
  702. currClassifyInfo, err := excel.GetExcelClassifyById(excelInfo.ExcelClassifyId)
  703. if err != nil && err.Error() != utils.ErrNoRow() {
  704. br.Msg = "删除失败"
  705. br.ErrMsg = "获取当前表格分类信息失败,Err:" + err.Error()
  706. return
  707. }
  708. nextItem, err = excel.GetNextExcelInfo(excelInfo.ExcelClassifyId, currClassifyInfo.Sort, currClassifyInfo.Source)
  709. if err != nil && err.Error() != utils.ErrNoRow() {
  710. br.Msg = "删除失败"
  711. br.ErrMsg = "获取下一级表格信息失败,Err:" + err.Error()
  712. return
  713. }
  714. }
  715. // 如果找到下一个表格了,那么就返回
  716. if nextItem != nil {
  717. resp = response2.AddExcelInfoResp{
  718. ExcelInfoId: nextItem.ExcelInfoId,
  719. UniqueCode: nextItem.UniqueCode,
  720. }
  721. }
  722. }
  723. //新增操作日志
  724. //{
  725. // ExcelLog := new(data_manage.ExcelInfoLog)
  726. // ExcelLog.ExcelName = ExcelInfo.ExcelName
  727. // ExcelLog.ExcelInfoId = req.ExcelInfoId
  728. // ExcelLog.ExcelClassifyId = ExcelInfo.ExcelClassifyId
  729. // ExcelLog.SysUserId = sysUser.AdminId
  730. // ExcelLog.SysUserRealName = sysUser.RealName
  731. // ExcelLog.UniqueCode = ExcelInfo.UniqueCode
  732. // ExcelLog.CreateTime = time.Now()
  733. // ExcelLog.Content = string(this.Ctx.Input.RequestBody)
  734. // ExcelLog.Status = "删除表格"
  735. // ExcelLog.Method = this.Ctx.Input.URI()
  736. // go data_manage.AddExcelInfoLog(ExcelLog)
  737. //}
  738. }
  739. br.Ret = 200
  740. br.Msg = "删除成功"
  741. br.Success = true
  742. br.Data = resp
  743. br.IsAddLog = true
  744. }
  745. // ExcelClassifyMove
  746. // @Title 表格分类移动接口
  747. // @Description 表格分类移动接口
  748. // @Success 200 {object} request.MoveExcelClassifyReq
  749. // @router /excel_classify/move [post]
  750. func (this *ExcelClassifyController) ExcelClassifyMove() {
  751. br := new(models.BaseResponse).Init()
  752. defer func() {
  753. this.Data["json"] = br
  754. this.ServeJSON()
  755. }()
  756. sysUser := this.SysUser
  757. if sysUser == nil {
  758. br.Msg = "请登录"
  759. br.ErrMsg = "请登录,SysUser Is Empty"
  760. br.Ret = 408
  761. return
  762. }
  763. var req request.MoveExcelClassifyReq
  764. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  765. if err != nil {
  766. br.Msg = "参数解析异常!"
  767. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  768. return
  769. }
  770. if req.ClassifyId <= 0 && req.ExcelInfoId <= 0 {
  771. br.Msg = "参数错误"
  772. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  773. return
  774. }
  775. //判断分类是否存在
  776. err, errMsg := excel2.MoveExcelClassify(req)
  777. if err != nil {
  778. br.Msg = err.Error()
  779. br.ErrMsg = errMsg
  780. return
  781. }
  782. br.Ret = 200
  783. br.Success = true
  784. br.IsAddLog = true
  785. br.Msg = "移动成功"
  786. }