document_manage_controller.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. // Package document_manage
  2. // @Author gmy 2024/9/19 14:09:00
  3. package document_manage
  4. import (
  5. "encoding/json"
  6. "eta/eta_mobile/controllers"
  7. "eta/eta_mobile/models"
  8. "eta/eta_mobile/models/document_manage_model"
  9. "eta/eta_mobile/services/document_manage_service"
  10. "eta/eta_mobile/utils"
  11. "strings"
  12. )
  13. // DocumentManageController 文档管理库
  14. type DocumentManageController struct {
  15. controllers.BaseAuthController
  16. }
  17. // ValidateUser
  18. // 处理响应和校验
  19. func ValidateUser(this *DocumentManageController, br *models.BaseResponse) bool {
  20. // 验证用户是否已登录
  21. sysUser := this.SysUser
  22. if sysUser == nil {
  23. br.Msg = "请登录"
  24. br.ErrMsg = "请登录,SysUser Is Empty"
  25. br.Ret = 408
  26. return false
  27. }
  28. return true
  29. }
  30. // DocumentClassifyList
  31. // @Title 文档分类列表
  32. // @Description 文档分类列表
  33. // @Success 200 {object} []models.ClassifyVO
  34. // @router /document/classify/list [get]
  35. func (this *DocumentManageController) DocumentClassifyList() {
  36. br := new(models.BaseResponse).Init()
  37. defer func() {
  38. if br.ErrMsg == "" {
  39. br.IsSendEmail = false
  40. }
  41. this.Data["json"] = br
  42. this.ServeJSON()
  43. }()
  44. if !ValidateUser(this, br) {
  45. return
  46. }
  47. sysUser := this.SysUser
  48. classifyList, err := document_manage_service.DocumentClassifyList(sysUser.AdminId)
  49. if err != nil {
  50. br.Msg = "获取分类列表失败"
  51. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  52. return
  53. }
  54. br.Ret = 200
  55. br.Success = true
  56. br.Msg = "获取成功"
  57. br.Data = classifyList
  58. return
  59. }
  60. // DocumentCollectClassify
  61. // @Title 收藏/取消分类
  62. // @Description 收藏/取消分类
  63. // @Success 200 “操作成功”
  64. // @router /document/collect/classify [post]
  65. func (this *DocumentManageController) DocumentCollectClassify() {
  66. br := new(models.BaseResponse).Init()
  67. defer func() {
  68. if br.ErrMsg == "" {
  69. br.IsSendEmail = false
  70. }
  71. this.Data["json"] = br
  72. this.ServeJSON()
  73. }()
  74. if !ValidateUser(this, br) {
  75. return
  76. }
  77. sysUser := this.SysUser
  78. type collectClassify struct {
  79. ClassifyId int `json:"ClassifyId"`
  80. }
  81. var req *collectClassify
  82. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  83. br.Msg = "参数解析异常!"
  84. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  85. return
  86. }
  87. err := document_manage_service.DocumentCollectClassify(req.ClassifyId, sysUser.AdminId)
  88. if err != nil {
  89. br.Msg = "收藏分类失败"
  90. br.ErrMsg = "收藏分类失败,Err:" + err.Error()
  91. return
  92. }
  93. br.Ret = 200
  94. br.Success = true
  95. br.Msg = "操作成功"
  96. return
  97. }
  98. // DocumentVarietyList
  99. // @Title 文档品种列表
  100. // @Description 文档品种列表
  101. // @Success 200 {object} []models.ChartPermission
  102. // @router /document/variety/list [get]
  103. func (this *DocumentManageController) DocumentVarietyList() {
  104. br := new(models.BaseResponse).Init()
  105. defer func() {
  106. if br.ErrMsg == "" {
  107. br.IsSendEmail = false
  108. }
  109. this.Data["json"] = br
  110. this.ServeJSON()
  111. }()
  112. if !ValidateUser(this, br) {
  113. return
  114. }
  115. chartPermissionList, err := document_manage_service.DocumentVarietyList()
  116. if err != nil {
  117. br.Msg = "获取品种列表失败"
  118. br.ErrMsg = "获取品种列表失败,Err:" + err.Error()
  119. return
  120. }
  121. br.Ret = 200
  122. br.Success = true
  123. br.Msg = "获取成功"
  124. br.Data = chartPermissionList
  125. return
  126. }
  127. // DocumentReportList
  128. // @Title 文档管理库报告列表
  129. // @Description 文档管理库报告列表
  130. // @Success 200 {object} document_manage_model.OutsideReportPage
  131. // @router /document/report/list [get]
  132. func (this *DocumentManageController) DocumentReportList() {
  133. br := new(models.BaseResponse).Init()
  134. defer func() {
  135. if br.ErrMsg == "" {
  136. br.IsSendEmail = false
  137. }
  138. this.Data["json"] = br
  139. this.ServeJSON()
  140. }()
  141. if !ValidateUser(this, br) {
  142. return
  143. }
  144. // 文档类型 1-文档管理库 2-战研中心-pci
  145. documentType, err := this.GetInt("DocumentType")
  146. if err != nil {
  147. br.Msg = "获取文档类型失败"
  148. br.ErrMsg = "获取文档类型失败,Err:" + err.Error()
  149. return
  150. }
  151. if documentType == 0 {
  152. br.Msg = "文档类型不能为空"
  153. br.ErrMsg = "文档类型不能为空"
  154. return
  155. }
  156. chartPermissionIdString := this.GetString("ChartPermissionIdList")
  157. var chartPermissionIdList []string
  158. if strings.TrimSpace(chartPermissionIdString) != "" {
  159. chartPermissionIdList = strings.Split(chartPermissionIdString, ",")
  160. }
  161. classifyIdString := this.GetString("ClassifyIdList")
  162. var classifyIdList []string
  163. if strings.TrimSpace(classifyIdString) != "" {
  164. classifyIdList = strings.Split(classifyIdString, ",")
  165. }
  166. keyword := this.GetString("Keyword")
  167. orderField := this.GetString("OrderField")
  168. orderType := this.GetString("OrderType")
  169. pageSize, _ := this.GetInt("PageSize")
  170. currentIndex, _ := this.GetInt("CurrentIndex")
  171. if pageSize <= 0 {
  172. pageSize = utils.PageSize20
  173. }
  174. if currentIndex <= 0 {
  175. currentIndex = 1
  176. }
  177. documentReportPage, err := document_manage_service.DocumentReportList(this.SysUser.AdminId, documentType, chartPermissionIdList, classifyIdList, keyword, orderField, orderType, currentIndex, pageSize)
  178. if err != nil {
  179. br.Msg = "获取报告列表失败"
  180. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  181. return
  182. }
  183. br.Ret = 200
  184. br.Success = true
  185. br.Msg = "获取成功"
  186. br.Data = documentReportPage
  187. return
  188. }
  189. // RuiSiReportList
  190. // @Title 睿思报告列表
  191. // @Description 睿思报告列表
  192. // @Success 200 {object} models.ReportListResp
  193. // @router /document/rui/si/report/list [get]
  194. func (this *DocumentManageController) RuiSiReportList() {
  195. br := new(models.BaseResponse).Init()
  196. defer func() {
  197. if br.ErrMsg == "" {
  198. br.IsSendEmail = false
  199. }
  200. this.Data["json"] = br
  201. this.ServeJSON()
  202. }()
  203. if !ValidateUser(this, br) {
  204. return
  205. }
  206. classifyIdListStr := this.GetString("ClassifyIdList")
  207. var classifyIdList []string
  208. if strings.TrimSpace(classifyIdListStr) != "" {
  209. classifyIdList = strings.Split(classifyIdListStr, ",")
  210. }
  211. chartPermissionIdString := this.GetString("ChartPermissionIdList")
  212. var chartPermissionIdList []string
  213. if strings.TrimSpace(chartPermissionIdString) != "" {
  214. chartPermissionIdList = strings.Split(chartPermissionIdString, ",")
  215. }
  216. keyword := this.GetString("Keyword")
  217. orderField := this.GetString("OrderField")
  218. orderType := this.GetString("OrderType")
  219. pageSize, _ := this.GetInt("PageSize")
  220. currentIndex, _ := this.GetInt("CurrentIndex")
  221. if pageSize <= 0 {
  222. pageSize = utils.PageSize20
  223. }
  224. if currentIndex <= 0 {
  225. currentIndex = 1
  226. }
  227. RuiSiReportPage, err := document_manage_service.RuiSiReportListV2(classifyIdList, chartPermissionIdList, keyword, orderField, orderType, this.SysUser.AdminId, currentIndex, pageSize)
  228. if err != nil {
  229. br.Msg = "获取报告列表失败"
  230. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  231. return
  232. }
  233. br.Ret = 200
  234. br.Success = true
  235. br.Msg = "获取成功"
  236. br.Data = RuiSiReportPage
  237. return
  238. }
  239. // DocumentRuiSiDetail
  240. // @Title 睿思报告详情
  241. // @Description 睿思报告详情
  242. // @Success 200 “获取成功”
  243. // @router /document/rui/si/detail [get]
  244. func (this *DocumentManageController) DocumentRuiSiDetail() {
  245. br := new(models.BaseResponse).Init()
  246. defer func() {
  247. if br.ErrMsg == "" {
  248. br.IsSendEmail = false
  249. }
  250. this.Data["json"] = br
  251. this.ServeJSON()
  252. }()
  253. if !ValidateUser(this, br) {
  254. return
  255. }
  256. // 获取指标数据列表
  257. reportId, err := this.GetInt("ReportId")
  258. if err != nil {
  259. br.Msg = "获取报告ID失败"
  260. br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
  261. return
  262. }
  263. reportDetail, err := document_manage_service.DocumentRuiSiDetail(reportId)
  264. if err != nil {
  265. return
  266. }
  267. br.Ret = 200
  268. br.Success = true
  269. br.Msg = "获取成功"
  270. br.Data = &reportDetail
  271. return
  272. }
  273. // DocumentSave
  274. // @Title 新建文档
  275. // @Description 新建文档
  276. // @Success 200 “操作成功”
  277. // @router /document/save [post]
  278. func (this *DocumentManageController) DocumentSave() {
  279. br := new(models.BaseResponse).Init()
  280. defer func() {
  281. if br.ErrMsg == "" {
  282. br.IsSendEmail = false
  283. }
  284. this.Data["json"] = br
  285. this.ServeJSON()
  286. }()
  287. if !ValidateUser(this, br) {
  288. return
  289. }
  290. sysUser := this.SysUser
  291. var req *document_manage_model.OutsideReportBO
  292. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  293. br.Msg = "参数解析异常!"
  294. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  295. return
  296. }
  297. req.SysUserId = sysUser.AdminId
  298. req.SysUserName = sysUser.AdminName
  299. err := document_manage_service.DocumentSave(req)
  300. if err != nil {
  301. br.Msg = "保存文档失败"
  302. br.ErrMsg = "保存文档失败,Err:" + err.Error()
  303. return
  304. }
  305. br.Ret = 200
  306. br.Success = true
  307. br.Msg = "操作成功"
  308. return
  309. }
  310. // DocumentDetail
  311. // @Title 文档详情
  312. // @Description 文档详情
  313. // @Success 200 “操作成功”
  314. // @router /document/detail [get]
  315. func (this *DocumentManageController) DocumentDetail() {
  316. br := new(models.BaseResponse).Init()
  317. defer func() {
  318. if br.ErrMsg == "" {
  319. br.IsSendEmail = false
  320. }
  321. this.Data["json"] = br
  322. this.ServeJSON()
  323. }()
  324. if !ValidateUser(this, br) {
  325. return
  326. }
  327. // 获取指标数据列表
  328. outsideReportId, err := this.GetInt("OutsideReportId")
  329. if err != nil {
  330. br.Msg = "获取报告ID失败"
  331. br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
  332. return
  333. }
  334. reportDetail, err := document_manage_service.DocumentReportDetail(outsideReportId)
  335. if err != nil {
  336. return
  337. }
  338. br.Ret = 200
  339. br.Success = true
  340. br.Msg = "获取成功"
  341. br.Data = &reportDetail
  342. return
  343. }
  344. // DocumentUpdate
  345. // @Title 编辑文档
  346. // @Description 编辑文档
  347. // @Success 200 “操作成功”
  348. // @router /document/update [post]
  349. func (this *DocumentManageController) DocumentUpdate() {
  350. br := new(models.BaseResponse).Init()
  351. defer func() {
  352. if br.ErrMsg == "" {
  353. br.IsSendEmail = false
  354. }
  355. this.Data["json"] = br
  356. this.ServeJSON()
  357. }()
  358. if !ValidateUser(this, br) {
  359. return
  360. }
  361. var req *document_manage_model.OutsideReportBO
  362. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  363. br.Msg = "参数解析异常!"
  364. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  365. return
  366. }
  367. err := document_manage_service.DocumentUpdate(req)
  368. if err != nil {
  369. br.Msg = "修改文档失败"
  370. br.ErrMsg = "修改文档失败,Err:" + err.Error()
  371. return
  372. }
  373. br.Ret = 200
  374. br.Success = true
  375. br.Msg = "操作成功"
  376. return
  377. }
  378. // DocumentDelete
  379. // @Title 删除文档
  380. // @Description 删除文档
  381. // @Success 200 “操作成功”
  382. // @router /document/delete [post]
  383. func (this *DocumentManageController) DocumentDelete() {
  384. br := new(models.BaseResponse).Init()
  385. defer func() {
  386. if br.ErrMsg == "" {
  387. br.IsSendEmail = false
  388. }
  389. this.Data["json"] = br
  390. this.ServeJSON()
  391. }()
  392. if !ValidateUser(this, br) {
  393. return
  394. }
  395. type DocumentDelete struct {
  396. OutsideReportId int `json:"OutsideReportId"`
  397. }
  398. var req *DocumentDelete
  399. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  400. br.Msg = "参数解析异常!"
  401. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  402. return
  403. }
  404. err := document_manage_service.DocumentDelete(req.OutsideReportId)
  405. if err != nil {
  406. br.Msg = "删除文档失败"
  407. br.ErrMsg = "删除文档失败,Err:" + err.Error()
  408. return
  409. }
  410. br.Ret = 200
  411. br.Success = true
  412. br.Msg = "操作成功"
  413. return
  414. }