document_manage_controller.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. keyword := this.GetString("Keyword")
  171. orderField := this.GetString("OrderField")
  172. orderType := this.GetString("OrderType")
  173. pageSize, _ := this.GetInt("PageSize")
  174. currentIndex, _ := this.GetInt("CurrentIndex")
  175. if pageSize <= 0 {
  176. pageSize = utils.PageSize20
  177. }
  178. if currentIndex <= 0 {
  179. currentIndex = 1
  180. }
  181. RuiSiReportPage, err := document_manage_service.RuiSiReportList(classifyIdFirst, classifyIdSecond, classifyIdThird, keyword, orderField, orderType, currentIndex, pageSize)
  182. if err != nil {
  183. br.Msg = "获取报告列表失败"
  184. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  185. return
  186. }
  187. br.Ret = 200
  188. br.Success = true
  189. br.Msg = "获取成功"
  190. br.Data = RuiSiReportPage
  191. return
  192. }
  193. // DocumentRuiSiDetail
  194. // @Title 睿思报告详情
  195. // @Description 睿思报告详情
  196. // @Success 200 “获取成功”
  197. // @router /document/rui/si/detail [get]
  198. func (this *DocumentManageController) DocumentRuiSiDetail() {
  199. br := new(models.BaseResponse).Init()
  200. defer func() {
  201. if br.ErrMsg == "" {
  202. br.IsSendEmail = false
  203. }
  204. this.Data["json"] = br
  205. this.ServeJSON()
  206. }()
  207. if !ValidateUser(this, br) {
  208. return
  209. }
  210. // 获取指标数据列表
  211. this.GetString("DocumentRuiSiDetail")
  212. reportId, err := this.GetInt("ReportId")
  213. if err != nil {
  214. br.Msg = "获取报告ID失败"
  215. br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
  216. return
  217. }
  218. reportDetail, err := document_manage_service.DocumentRuiSiDetail(reportId)
  219. if err != nil {
  220. if err.Error() == utils.ErrNoRow() {
  221. br.Msg = "报告已被删除"
  222. return
  223. }
  224. return
  225. }
  226. br.Ret = 200
  227. br.Success = true
  228. br.Msg = "获取成功"
  229. br.Data = &reportDetail
  230. return
  231. }
  232. // DocumentSave
  233. // @Title 新建文档
  234. // @Description 新建文档
  235. // @Success 200 “操作成功”
  236. // @router /document/save [post]
  237. func (this *DocumentManageController) DocumentSave() {
  238. br := new(models.BaseResponse).Init()
  239. defer func() {
  240. if br.ErrMsg == "" {
  241. br.IsSendEmail = false
  242. }
  243. this.Data["json"] = br
  244. this.ServeJSON()
  245. }()
  246. if !ValidateUser(this, br) {
  247. return
  248. }
  249. sysUser := this.SysUser
  250. var req *document_manage_model.OutsideReportBO
  251. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  252. br.Msg = "参数解析异常!"
  253. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  254. return
  255. }
  256. req.SysUserId = sysUser.AdminId
  257. req.SysUserName = sysUser.RealName
  258. err := document_manage_service.DocumentSave(req)
  259. if err != nil {
  260. br.Msg = "保存文档失败"
  261. br.ErrMsg = "保存文档失败,Err:" + err.Error()
  262. return
  263. }
  264. br.Ret = 200
  265. br.Success = true
  266. br.Msg = "操作成功"
  267. return
  268. }
  269. // DocumentDetail
  270. // @Title 文档详情
  271. // @Description 文档详情
  272. // @Success 200 “操作成功”
  273. // @router /document/detail [get]
  274. func (this *DocumentManageController) DocumentDetail() {
  275. br := new(models.BaseResponse).Init()
  276. defer func() {
  277. if br.ErrMsg == "" {
  278. br.IsSendEmail = false
  279. }
  280. this.Data["json"] = br
  281. this.ServeJSON()
  282. }()
  283. if !ValidateUser(this, br) {
  284. return
  285. }
  286. // 获取指标数据列表
  287. outsideReportId, err := this.GetInt("OutsideReportId")
  288. if err != nil {
  289. br.Msg = "获取报告ID失败"
  290. br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
  291. return
  292. }
  293. reportDetail, err := document_manage_service.DocumentReportDetail(outsideReportId)
  294. if err != nil {
  295. return
  296. }
  297. br.Ret = 200
  298. br.Success = true
  299. br.Msg = "获取成功"
  300. br.Data = &reportDetail
  301. return
  302. }
  303. // DocumentUpdate
  304. // @Title 编辑文档
  305. // @Description 编辑文档
  306. // @Success 200 “操作成功”
  307. // @router /document/update [post]
  308. func (this *DocumentManageController) DocumentUpdate() {
  309. br := new(models.BaseResponse).Init()
  310. defer func() {
  311. if br.ErrMsg == "" {
  312. br.IsSendEmail = false
  313. }
  314. this.Data["json"] = br
  315. this.ServeJSON()
  316. }()
  317. if !ValidateUser(this, br) {
  318. return
  319. }
  320. var req *document_manage_model.OutsideReportBO
  321. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  322. br.Msg = "参数解析异常!"
  323. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  324. return
  325. }
  326. err := document_manage_service.DocumentUpdate(req)
  327. if err != nil {
  328. br.Msg = "修改文档失败"
  329. br.ErrMsg = "修改文档失败,Err:" + err.Error()
  330. return
  331. }
  332. br.Ret = 200
  333. br.Success = true
  334. br.Msg = "操作成功"
  335. return
  336. }
  337. // DocumentDelete
  338. // @Title 删除文档
  339. // @Description 删除文档
  340. // @Success 200 “操作成功”
  341. // @router /document/delete [post]
  342. func (this *DocumentManageController) DocumentDelete() {
  343. br := new(models.BaseResponse).Init()
  344. defer func() {
  345. if br.ErrMsg == "" {
  346. br.IsSendEmail = false
  347. }
  348. this.Data["json"] = br
  349. this.ServeJSON()
  350. }()
  351. if !ValidateUser(this, br) {
  352. return
  353. }
  354. type DocumentDelete struct {
  355. OutsideReportId int `json:"OutsideReportId"`
  356. }
  357. var req *DocumentDelete
  358. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  359. br.Msg = "参数解析异常!"
  360. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  361. return
  362. }
  363. err := document_manage_service.DocumentDelete(req.OutsideReportId)
  364. if err != nil {
  365. br.Msg = "删除文档失败"
  366. br.ErrMsg = "删除文档失败,Err:" + err.Error()
  367. return
  368. }
  369. br.Ret = 200
  370. br.Success = true
  371. br.Msg = "操作成功"
  372. return
  373. }