document_manage_controller.go 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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_api/controllers"
  7. "eta/eta_api/models"
  8. "eta/eta_api/models/document_manage_model"
  9. "eta/eta_api/services/document_manage_service"
  10. "eta/eta_api/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. classifyList, err := document_manage_service.DocumentClassifyList()
  48. if err != nil {
  49. br.Msg = "获取分类列表失败"
  50. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  51. return
  52. }
  53. br.Ret = 200
  54. br.Success = true
  55. br.Msg = "获取成功"
  56. br.Data = classifyList
  57. return
  58. }
  59. // DocumentVarietyList
  60. // @Title 文档品种列表
  61. // @Description 文档品种列表
  62. // @Success 200 {object} []models.ChartPermission
  63. // @router /document/variety/list [get]
  64. func (this *DocumentManageController) DocumentVarietyList() {
  65. br := new(models.BaseResponse).Init()
  66. defer func() {
  67. if br.ErrMsg == "" {
  68. br.IsSendEmail = false
  69. }
  70. this.Data["json"] = br
  71. this.ServeJSON()
  72. }()
  73. if !ValidateUser(this, br) {
  74. return
  75. }
  76. chartPermissionList, err := document_manage_service.DocumentVarietyList()
  77. if err != nil {
  78. br.Msg = "获取品种列表失败"
  79. br.ErrMsg = "获取品种列表失败,Err:" + err.Error()
  80. return
  81. }
  82. br.Ret = 200
  83. br.Success = true
  84. br.Msg = "获取成功"
  85. br.Data = chartPermissionList
  86. return
  87. }
  88. // DocumentReportList
  89. // @Title 文档管理库报告列表
  90. // @Description 文档管理库报告列表
  91. // @Success 200 {object} document_manage_model.OutsideReportPage
  92. // @router /document/report/list [get]
  93. func (this *DocumentManageController) DocumentReportList() {
  94. br := new(models.BaseResponse).Init()
  95. defer func() {
  96. if br.ErrMsg == "" {
  97. br.IsSendEmail = false
  98. }
  99. this.Data["json"] = br
  100. this.ServeJSON()
  101. }()
  102. if !ValidateUser(this, br) {
  103. return
  104. }
  105. // 文档类型 1-文档管理库 2-战研中心-pci
  106. documentType, err := this.GetInt("DocumentType")
  107. if err != nil {
  108. br.Msg = "获取文档类型失败"
  109. br.ErrMsg = "获取文档类型失败,Err:" + err.Error()
  110. return
  111. }
  112. if documentType == 0 {
  113. br.Msg = "文档类型不能为空"
  114. br.ErrMsg = "文档类型不能为空"
  115. return
  116. }
  117. chartPermissionIdString := this.GetString("ChartPermissionIdList")
  118. var chartPermissionIdList []string
  119. if strings.TrimSpace(chartPermissionIdString) != "" {
  120. chartPermissionIdList = strings.Split(chartPermissionIdString, ",")
  121. }
  122. classifyIdString := this.GetString("ClassifyIdList")
  123. var classifyIdList []string
  124. if strings.TrimSpace(classifyIdString) != "" {
  125. classifyIdList = strings.Split(classifyIdString, ",")
  126. }
  127. keyword := this.GetString("Keyword")
  128. orderField := this.GetString("OrderField")
  129. orderType := this.GetString("OrderType")
  130. pageSize, _ := this.GetInt("PageSize")
  131. currentIndex, _ := this.GetInt("CurrentIndex")
  132. if pageSize <= 0 {
  133. pageSize = utils.PageSize20
  134. }
  135. if currentIndex <= 0 {
  136. currentIndex = 1
  137. }
  138. documentReportPage, err := document_manage_service.DocumentReportList(documentType, chartPermissionIdList, classifyIdList, keyword, orderField, orderType, currentIndex, pageSize)
  139. if err != nil {
  140. br.Msg = "获取报告列表失败"
  141. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  142. return
  143. }
  144. br.Ret = 200
  145. br.Success = true
  146. br.Msg = "获取成功"
  147. br.Data = documentReportPage
  148. return
  149. }
  150. // RuiSiReportList
  151. // @Title 睿思报告列表
  152. // @Description 睿思报告列表
  153. // @Success 200 {object} models.ReportListResp
  154. // @router /document/rui/si/report/list [get]
  155. func (this *DocumentManageController) RuiSiReportList() {
  156. br := new(models.BaseResponse).Init()
  157. defer func() {
  158. if br.ErrMsg == "" {
  159. br.IsSendEmail = false
  160. }
  161. this.Data["json"] = br
  162. this.ServeJSON()
  163. }()
  164. if !ValidateUser(this, br) {
  165. return
  166. }
  167. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
  168. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
  169. classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
  170. chartPermissionIdString := this.GetString("ChartPermissionIdList")
  171. var chartPermissionIdList []string
  172. if strings.TrimSpace(chartPermissionIdString) != "" {
  173. chartPermissionIdList = strings.Split(chartPermissionIdString, ",")
  174. }
  175. keyword := this.GetString("Keyword")
  176. orderField := this.GetString("OrderField")
  177. orderType := this.GetString("OrderType")
  178. pageSize, _ := this.GetInt("PageSize")
  179. currentIndex, _ := this.GetInt("CurrentIndex")
  180. if pageSize <= 0 {
  181. pageSize = utils.PageSize20
  182. }
  183. if currentIndex <= 0 {
  184. currentIndex = 1
  185. }
  186. RuiSiReportPage, err := document_manage_service.RuiSiReportList(classifyIdFirst, classifyIdSecond, classifyIdThird, chartPermissionIdList, keyword, orderField, orderType, currentIndex, pageSize)
  187. if err != nil {
  188. br.Msg = "获取报告列表失败"
  189. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  190. return
  191. }
  192. br.Ret = 200
  193. br.Success = true
  194. br.Msg = "获取成功"
  195. br.Data = RuiSiReportPage
  196. return
  197. }
  198. // DocumentRuiSiDetail
  199. // @Title 睿思报告详情
  200. // @Description 睿思报告详情
  201. // @Success 200 “获取成功”
  202. // @router /document/rui/si/detail [get]
  203. func (this *DocumentManageController) DocumentRuiSiDetail() {
  204. br := new(models.BaseResponse).Init()
  205. defer func() {
  206. if br.ErrMsg == "" {
  207. br.IsSendEmail = false
  208. }
  209. this.Data["json"] = br
  210. this.ServeJSON()
  211. }()
  212. if !ValidateUser(this, br) {
  213. return
  214. }
  215. // 获取指标数据列表
  216. this.GetString("DocumentRuiSiDetail")
  217. reportId, err := this.GetInt("ReportId")
  218. if err != nil {
  219. br.Msg = "获取报告ID失败"
  220. br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
  221. return
  222. }
  223. reportDetail, err := document_manage_service.DocumentRuiSiDetail(reportId)
  224. if err != nil {
  225. if err.Error() == utils.ErrNoRow() {
  226. br.Msg = "报告已被删除"
  227. return
  228. }
  229. return
  230. }
  231. br.Ret = 200
  232. br.Success = true
  233. br.Msg = "获取成功"
  234. br.Data = &reportDetail
  235. return
  236. }
  237. // DocumentSave
  238. // @Title 新建文档
  239. // @Description 新建文档
  240. // @Success 200 “操作成功”
  241. // @router /document/save [post]
  242. func (this *DocumentManageController) DocumentSave() {
  243. br := new(models.BaseResponse).Init()
  244. defer func() {
  245. if br.ErrMsg == "" {
  246. br.IsSendEmail = false
  247. }
  248. this.Data["json"] = br
  249. this.ServeJSON()
  250. }()
  251. if !ValidateUser(this, br) {
  252. return
  253. }
  254. sysUser := this.SysUser
  255. var req *document_manage_model.OutsideReportBO
  256. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  257. br.Msg = "参数解析异常!"
  258. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  259. return
  260. }
  261. req.SysUserId = sysUser.AdminId
  262. req.SysUserName = sysUser.RealName
  263. err := document_manage_service.DocumentSave(req)
  264. if err != nil {
  265. br.Msg = "保存文档失败"
  266. br.ErrMsg = "保存文档失败,Err:" + err.Error()
  267. return
  268. }
  269. br.Ret = 200
  270. br.Success = true
  271. br.Msg = "操作成功"
  272. return
  273. }
  274. // DocumentDetail
  275. // @Title 文档详情
  276. // @Description 文档详情
  277. // @Success 200 “操作成功”
  278. // @router /document/detail [get]
  279. func (this *DocumentManageController) DocumentDetail() {
  280. br := new(models.BaseResponse).Init()
  281. defer func() {
  282. if br.ErrMsg == "" {
  283. br.IsSendEmail = false
  284. }
  285. this.Data["json"] = br
  286. this.ServeJSON()
  287. }()
  288. if !ValidateUser(this, br) {
  289. return
  290. }
  291. // 获取指标数据列表
  292. outsideReportId, err := this.GetInt("OutsideReportId")
  293. if err != nil {
  294. br.Msg = "获取报告ID失败"
  295. br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
  296. return
  297. }
  298. reportDetail, err := document_manage_service.DocumentReportDetail(outsideReportId)
  299. if err != nil {
  300. return
  301. }
  302. br.Ret = 200
  303. br.Success = true
  304. br.Msg = "获取成功"
  305. br.Data = &reportDetail
  306. return
  307. }
  308. // DocumentUpdate
  309. // @Title 编辑文档
  310. // @Description 编辑文档
  311. // @Success 200 “操作成功”
  312. // @router /document/update [post]
  313. func (this *DocumentManageController) DocumentUpdate() {
  314. br := new(models.BaseResponse).Init()
  315. defer func() {
  316. if br.ErrMsg == "" {
  317. br.IsSendEmail = false
  318. }
  319. this.Data["json"] = br
  320. this.ServeJSON()
  321. }()
  322. if !ValidateUser(this, br) {
  323. return
  324. }
  325. var req *document_manage_model.OutsideReportBO
  326. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  327. br.Msg = "参数解析异常!"
  328. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  329. return
  330. }
  331. err := document_manage_service.DocumentUpdate(req)
  332. if err != nil {
  333. br.Msg = "修改文档失败"
  334. br.ErrMsg = "修改文档失败,Err:" + err.Error()
  335. return
  336. }
  337. br.Ret = 200
  338. br.Success = true
  339. br.Msg = "操作成功"
  340. return
  341. }
  342. // DocumentDelete
  343. // @Title 删除文档
  344. // @Description 删除文档
  345. // @Success 200 “操作成功”
  346. // @router /document/delete [post]
  347. func (this *DocumentManageController) DocumentDelete() {
  348. br := new(models.BaseResponse).Init()
  349. defer func() {
  350. if br.ErrMsg == "" {
  351. br.IsSendEmail = false
  352. }
  353. this.Data["json"] = br
  354. this.ServeJSON()
  355. }()
  356. if !ValidateUser(this, br) {
  357. return
  358. }
  359. type DocumentDelete struct {
  360. OutsideReportId int `json:"OutsideReportId"`
  361. }
  362. var req *DocumentDelete
  363. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  364. br.Msg = "参数解析异常!"
  365. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  366. return
  367. }
  368. err := document_manage_service.DocumentDelete(req.OutsideReportId)
  369. if err != nil {
  370. br.Msg = "删除文档失败"
  371. br.ErrMsg = "删除文档失败,Err:" + err.Error()
  372. return
  373. }
  374. br.Ret = 200
  375. br.Success = true
  376. br.Msg = "操作成功"
  377. return
  378. }