manual.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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/utils"
  10. "fmt"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type ManualController struct {
  16. controllers.BaseAuthController
  17. }
  18. // @router /manual/sysuser/search [get]
  19. func (this *ManualController) ManualSysUserSearch() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. sysUser := this.SysUser
  26. if sysUser == nil {
  27. br.Msg = "请登录"
  28. br.Ret = 408
  29. return
  30. }
  31. keyWord := this.GetString("KeyWord")
  32. list, err := data.GetManualSysUser(keyWord)
  33. if err != nil {
  34. br.Msg = "获取失败"
  35. br.ErrMsg = "获取失败,Err:" + err.Error()
  36. return
  37. }
  38. br.Ret = 200
  39. br.Success = true
  40. br.Msg = "获取成功"
  41. br.Data = list
  42. }
  43. // @router /manual/sysuser/all [get]
  44. func (this *ManualController) ManualSysUserAll() {
  45. br := new(models.BaseResponse).Init()
  46. defer func() {
  47. this.Data["json"] = br
  48. this.ServeJSON()
  49. }()
  50. sysUser := this.SysUser
  51. if sysUser == nil {
  52. br.Msg = "请登录"
  53. br.Ret = 408
  54. return
  55. }
  56. fmt.Println("start")
  57. list, err := data_manage.GetManualUserList()
  58. if err != nil {
  59. br.Msg = "获取失败"
  60. br.ErrMsg = "获取失败,Err:" + err.Error()
  61. return
  62. }
  63. fmt.Println("end")
  64. br.Ret = 200
  65. br.Success = true
  66. br.Msg = "获取成功"
  67. br.Data = list
  68. }
  69. // @router /manual/classify/all [get]
  70. func (this *ManualController) ClassifyList() {
  71. br := new(models.BaseResponse).Init()
  72. defer func() {
  73. this.Data["json"] = br
  74. this.ServeJSON()
  75. }()
  76. sysUser := this.SysUser
  77. if sysUser == nil {
  78. br.Msg = "请登录"
  79. br.Ret = 408
  80. return
  81. }
  82. adminId, _ := this.GetInt("AdminId")
  83. list, err := data_manage.GetManualClassifyAll(adminId)
  84. if err != nil {
  85. br.Msg = "获取失败"
  86. br.ErrMsg = "获取失败,Err:" + err.Error()
  87. return
  88. }
  89. br.Ret = 200
  90. br.Success = true
  91. br.Msg = "获取成功"
  92. br.Data = list
  93. }
  94. // @router /manual/sysuser/classify/save [post]
  95. func (this *ManualController) ManualSysUserClassifySave() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. this.Data["json"] = br
  99. this.ServeJSON()
  100. }()
  101. sysUser := this.SysUser
  102. if sysUser == nil {
  103. br.Msg = "请登录"
  104. br.Ret = 408
  105. return
  106. }
  107. var req data_manage.ManualSysUserClassifySaveReq
  108. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  109. if err != nil {
  110. br.Msg = "参数解析异常!"
  111. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  112. return
  113. }
  114. if req.AdminId <= 0 {
  115. br.Msg = "参数错误!"
  116. return
  117. }
  118. sysUserItem, err := system.GetSysUserById(req.AdminId)
  119. if err != nil {
  120. br.Msg = "获取用户信息失败!"
  121. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  122. return
  123. }
  124. err = data_manage.DeleteManualUserClassifyCount(req.AdminId)
  125. if err != nil {
  126. br.Msg = "保存失败!"
  127. br.ErrMsg = "删除用户分类信息失败,Err:" + err.Error()
  128. return
  129. }
  130. list := make([]*data_manage.ManualUserClassify, 0)
  131. for _, v := range req.ClassifyId {
  132. item := new(data_manage.ManualUserClassify)
  133. item.AdminId = req.AdminId
  134. item.ClassifyId = v
  135. item.CreateTime = time.Now()
  136. list = append(list, item)
  137. }
  138. if len(list) > 0 {
  139. err = data_manage.AddManualUserClassifyMulti(list)
  140. if err != nil {
  141. br.Msg = "保存失败!"
  142. br.ErrMsg = "保存失败,Err:" + err.Error()
  143. return
  144. }
  145. }
  146. count, err := data_manage.GetManualUserCount(req.AdminId)
  147. if err != nil {
  148. br.Msg = "保存失败!"
  149. br.ErrMsg = "判断用户是否存在失败,Err:" + err.Error()
  150. return
  151. }
  152. if count <= 0 {
  153. manualUser := new(data_manage.ManualUser)
  154. manualUser.AdminId = req.AdminId
  155. manualUser.CreateTime = time.Now()
  156. manualUser.SysUserId = sysUser.AdminId
  157. manualUser.AdminRealName = sysUserItem.RealName
  158. manualUser.SysUserRealName = sysUser.RealName
  159. err = data_manage.AddManualUser(manualUser)
  160. if err != nil {
  161. br.Msg = "保存失败!"
  162. br.ErrMsg = "保存用户信息失败,Err:" + err.Error()
  163. return
  164. }
  165. }
  166. br.Ret = 200
  167. br.Success = true
  168. br.Msg = "保存成功"
  169. }
  170. // @router /manual/classify/add [post]
  171. func (this *ChartClassifyController) AddManualClassify() {
  172. br := new(models.BaseResponse).Init()
  173. defer func() {
  174. this.Data["json"] = br
  175. this.ServeJSON()
  176. }()
  177. var req data_manage.AddManualClassifyReq
  178. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  179. if err != nil {
  180. br.Msg = "参数解析异常!"
  181. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  182. return
  183. }
  184. if req.ClassifyName == "" {
  185. br.Msg = "请输入分类名称"
  186. br.IsSendEmail = false
  187. return
  188. }
  189. if req.ParentId < 0 {
  190. br.Msg = "参数错误"
  191. br.IsSendEmail = false
  192. return
  193. }
  194. classifyItem, err := data_manage.GetManualClassifyByClassifyName(req.ClassifyName)
  195. if err != nil && !utils.IsErrNoRow(err) {
  196. br.Msg = "判断名称是否已存在失败"
  197. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  198. return
  199. }
  200. if classifyItem != nil {
  201. if classifyItem.IsShow == 1 {
  202. br.Msg = "分类名称已存在,请重新输入"
  203. br.IsSendEmail = false
  204. return
  205. } else {
  206. err = data_manage.ModifyManualClassifyIsShow(1, classifyItem.ClassifyId, req.ParentId)
  207. if err != nil {
  208. br.Msg = "保存失败"
  209. br.ErrMsg = "保存失败,Err:" + err.Error()
  210. br.IsSendEmail = false
  211. return
  212. }
  213. parentItem, _ := data_manage.GetManualClassifyById(req.ParentId)
  214. if parentItem != nil && parentItem.IsShow == 0 {
  215. err = data_manage.ModifyManualClassifyIsShow(1, parentItem.ClassifyId, req.ParentId)
  216. if err != nil {
  217. br.Msg = "保存失败"
  218. br.ErrMsg = "保存失败,Err:" + err.Error()
  219. br.IsSendEmail = false
  220. return
  221. }
  222. }
  223. br.Msg = "保存成功"
  224. br.Success = true
  225. br.Ret = 200
  226. return
  227. }
  228. }
  229. classify := new(data_manage.EdbdataClassify)
  230. classify.IsShow = 1
  231. classify.ClassifyName = req.ClassifyName
  232. classify.ParentId = req.ParentId
  233. classify.CreateTime = time.Now()
  234. classify.Sort = 0
  235. _, err = data_manage.AddEdbdataClassify(classify)
  236. if err != nil {
  237. br.Msg = "保存失败"
  238. br.ErrMsg = "保存失败,Err:" + err.Error()
  239. br.IsSendEmail = false
  240. return
  241. }
  242. br.Ret = 200
  243. br.Msg = "保存成功"
  244. br.Success = true
  245. }
  246. // @router /manual/classify/edit [post]
  247. func (this *ChartClassifyController) ManualClassifyEdit() {
  248. br := new(models.BaseResponse).Init()
  249. defer func() {
  250. this.Data["json"] = br
  251. this.ServeJSON()
  252. }()
  253. var req data_manage.EditManualClassifyReq
  254. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  255. if err != nil {
  256. br.Msg = "参数解析异常!"
  257. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  258. return
  259. }
  260. if req.ClassifyName == "" {
  261. br.Msg = "请输入分类名称"
  262. br.IsSendEmail = false
  263. return
  264. }
  265. if req.ClassifyId <= 0 {
  266. br.Msg = "参数错误"
  267. br.IsSendEmail = false
  268. return
  269. }
  270. item, err := data_manage.GetManualClassifyById(req.ClassifyId)
  271. if err != nil {
  272. br.Msg = "修改失败"
  273. br.ErrMsg = "获取分类失败,Err:" + err.Error()
  274. return
  275. }
  276. classifyItem, err := data_manage.GetManualClassifyByClassifyName(req.ClassifyName)
  277. if err != nil && !utils.IsErrNoRow(err) {
  278. br.Msg = "修改失败"
  279. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  280. return
  281. }
  282. if classifyItem != nil {
  283. if item.ClassifyId != classifyItem.ClassifyId {
  284. br.Msg = "名称已存在,请重新输入"
  285. return
  286. }
  287. }
  288. err = data_manage.ModifyManualClassifyName(req.ClassifyName, req.ClassifyId, req.ParentId)
  289. if err != nil {
  290. br.Msg = "修改失败"
  291. br.ErrMsg = "修改失败,Err:" + err.Error()
  292. return
  293. }
  294. br.Ret = 200
  295. br.Msg = "修改成功"
  296. br.Success = true
  297. }
  298. // @router /manual/classify/delete [post]
  299. func (this *ChartClassifyController) ManualClassifyDel() {
  300. br := new(models.BaseResponse).Init()
  301. defer func() {
  302. this.Data["json"] = br
  303. this.ServeJSON()
  304. }()
  305. var req data_manage.DelManualClassifyReq
  306. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  307. if err != nil {
  308. br.Msg = "参数解析异常!"
  309. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  310. return
  311. }
  312. if req.ClassifyId <= 0 {
  313. br.Msg = "请选择分类"
  314. br.IsSendEmail = false
  315. return
  316. }
  317. classifyItem, err := data_manage.GetManualClassifyById(req.ClassifyId)
  318. if err != nil && !utils.IsErrNoRow(err) {
  319. br.Msg = "查找分类失败"
  320. br.ErrMsg = "查找分类失败,Err:" + err.Error()
  321. return
  322. }
  323. if classifyItem.IsShow == 0 {
  324. br.Msg = "该分类已删除"
  325. br.IsSendEmail = false
  326. return
  327. }
  328. count, err := data_manage.GetChildManualClassifyCount(req.ClassifyId)
  329. if err != nil && !utils.IsErrNoRow(err) {
  330. br.Msg = "删除失败"
  331. br.ErrMsg = "根据分类id获取下面存在的子分类数量失败,Err:" + err.Error()
  332. return
  333. }
  334. if count > 0 {
  335. br.Msg = "该分类下包含子分类,不允许删除!"
  336. br.IsSendEmail = false
  337. return
  338. }
  339. if classifyItem.ParentId > 0 {
  340. count, err = data_manage.GetManualEdbInfoCountByClassifyId(req.ClassifyId)
  341. if err != nil && !utils.IsErrNoRow(err) {
  342. br.Msg = "删除失败"
  343. br.ErrMsg = "根据分类id获取下面存在的指标数量失败,Err:" + err.Error()
  344. return
  345. }
  346. if count > 0 {
  347. br.Msg = "该分类下包含指标,不允许删除!"
  348. br.IsSendEmail = false
  349. return
  350. }
  351. }
  352. err = data_manage.ModifyManualClassifyIsShow(0, classifyItem.ClassifyId, classifyItem.ParentId)
  353. if err != nil {
  354. br.Msg = "删除失败"
  355. br.ErrMsg = "删除失败,Err:" + err.Error()
  356. return
  357. }
  358. br.Ret = 200
  359. br.Msg = "删除成功"
  360. br.Success = true
  361. }
  362. // @router /manual/set_classify/all [get]
  363. func (this *ManualController) ManualSetClassifyAll() {
  364. br := new(models.BaseResponse).Init()
  365. defer func() {
  366. this.Data["json"] = br
  367. this.ServeJSON()
  368. }()
  369. sysUser := this.SysUser
  370. if sysUser == nil {
  371. br.Msg = "请登录"
  372. br.Ret = 408
  373. return
  374. }
  375. adminId := sysUser.AdminId
  376. setList, err := data_manage.GetManualUserSetClassify(adminId)
  377. if err != nil {
  378. br.Msg = "获取失败"
  379. br.ErrMsg = "获取失败,Err:" + err.Error()
  380. return
  381. }
  382. listLen := len(setList)
  383. classifyArr := make([]string, 0)
  384. for i := 0; i < listLen; i++ {
  385. classifyArr = append(classifyArr, strconv.Itoa(setList[i].ClassifyId))
  386. }
  387. classifyIdStr := strings.Join(classifyArr, ",")
  388. condition := ""
  389. items := make([]*data_manage.EdbdataClassifyList, 0)
  390. if classifyIdStr != "" {
  391. condition += ` AND classify_id IN(` + classifyIdStr + `)`
  392. condition += ` AND parent_id<>0 `
  393. items, err = data_manage.GetManualClassifyAllByCondition(condition)
  394. if err != nil {
  395. br.Msg = "获取失败"
  396. br.ErrMsg = "获取失败,Err:" + err.Error()
  397. return
  398. }
  399. }
  400. classifyEdbTotalList, _ := data_manage.GetManualClassifyEdbInfoCount()
  401. edbTotalMap := make(map[int]int)
  402. for _, v := range classifyEdbTotalList {
  403. edbTotalMap[v.ClassifyId] = v.Total
  404. }
  405. itemsLen := len(items)
  406. for i := 0; i < itemsLen; i++ {
  407. items[i].Total = edbTotalMap[items[i].ClassifyId]
  408. }
  409. br.Ret = 200
  410. br.Success = true
  411. br.Msg = "获取成功"
  412. br.Data = items
  413. }
  414. // @router /manual/classify/first [get]
  415. func (this *ManualController) FirstClassifyList() {
  416. br := new(models.BaseResponse).Init()
  417. defer func() {
  418. this.Data["json"] = br
  419. this.ServeJSON()
  420. }()
  421. sysUser := this.SysUser
  422. if sysUser == nil {
  423. br.Msg = "请登录"
  424. br.Ret = 408
  425. return
  426. }
  427. condition := " AND parent_id =0 "
  428. list, err := data_manage.GetManualClassifyAllByCondition(condition)
  429. if err != nil {
  430. br.Msg = "获取失败"
  431. br.ErrMsg = "获取失败,Err:" + err.Error()
  432. return
  433. }
  434. br.Ret = 200
  435. br.Success = true
  436. br.Msg = "获取成功"
  437. br.Data = list
  438. }
  439. // @router /manual/classify/all_list [get]
  440. func (this *ManualController) AllClassifyList() {
  441. br := new(models.BaseResponse).Init()
  442. defer func() {
  443. this.Data["json"] = br
  444. this.ServeJSON()
  445. }()
  446. sysUser := this.SysUser
  447. if sysUser == nil {
  448. br.Msg = "请登录"
  449. br.Ret = 408
  450. return
  451. }
  452. list, err := data_manage.GetManualClassifyAllV2()
  453. if err != nil {
  454. br.Msg = "获取失败"
  455. br.ErrMsg = "获取失败,Err:" + err.Error()
  456. return
  457. }
  458. br.Ret = 200
  459. br.Success = true
  460. br.Msg = "获取成功"
  461. br.Data = list
  462. }