reportController.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * @Author: lilig
  3. * @Date: 2023-10-10 15:22:58
  4. * @LastEditors: lilifor
  5. * @LastEditTime: 2023-10-10 15:22:58
  6. * @FilePath: \SCD\controllers\ReportController.go
  7. * @Description:
  8. *
  9. * Copyright (c) 2023 by lilig/jujutong, All Rights Reserved.
  10. */
  11. package controllers
  12. import (
  13. "scd_check_tools/models/bo"
  14. )
  15. //检测报告服务
  16. type ReportController struct {
  17. BaseController
  18. }
  19. func init() {
  20. }
  21. // @Summary 查询检测任务的报告列表
  22. // @Description 查询检测任务的报告列表
  23. // @Tags 检测报告服务接口
  24. // @Accept x-www-form-urlencoded
  25. // @Produce json
  26. // @Param pageno query int true "当前页码。默认为1"
  27. // @Param pagesize query int true "每页显示数据数。默认为20"
  28. // @Param task_id formData int false "任务ID"
  29. // @Param name formData string false "任务名称。"
  30. // @Param code formData string false "任务编号。支持模糊匹配。"
  31. // @Success 200 {object} ResultOK 成功
  32. // @Failure 500 {object} ResultError 失败
  33. // @router /report/list [get]
  34. func (c *ReportController) GetReportList() {
  35. id, _ := c.GetInt("task_id")
  36. pi, _ := c.GetInt("pagesize", 20)
  37. po, _ := c.GetInt("pageno", 0)
  38. if po == 0 {
  39. po, _ = c.GetInt("pageindex", 0)
  40. }
  41. if po == 0 {
  42. po = 1
  43. }
  44. obj := new(bo.TaskReportMgr)
  45. obj.SetUserInfo(c.GetCurrentUserInfo())
  46. obj.Model = bo.T_data_task_report{TaskId: id, Name: c.GetString("name"), Code: c.GetString("code")}
  47. lst, cnt, err := obj.List(po, pi)
  48. if err != nil {
  49. c.Data["json"] = c.ResultError(err.Error())
  50. c.ServeJSON()
  51. return
  52. }
  53. c.Data["json"] = c.ResultOK(lst, cnt)
  54. c.ServeJSON()
  55. }
  56. // @Summary 删除指定的检测报告
  57. // @Description 删除指定的检测报告
  58. // @Tags 检测报告服务接口
  59. // @Accept x-www-form-urlencoded
  60. // @Produce json
  61. // @Param id formData int true "检测报告ID"
  62. // @Success 200 {object} ResultOK 成功
  63. // @Failure 500 {object} ResultError 失败
  64. // @router /report/delete [post]
  65. func (c *ReportController) DeleteReport() {
  66. id, _ := c.GetInt("id")
  67. if id == 0 {
  68. c.Data["json"] = c.ResultError("报告编号不能为空!")
  69. c.ServeJSON()
  70. return
  71. }
  72. obj := new(bo.TaskReportMgr)
  73. obj.SetUserInfo(c.GetCurrentUserInfo())
  74. obj.Model = bo.T_data_task_report{}
  75. obj.Model.Id = id
  76. err := obj.Delete()
  77. if err != nil {
  78. c.Data["json"] = c.ResultError(err.Error())
  79. c.ServeJSON()
  80. return
  81. }
  82. c.Data["json"] = c.ResultOK("", 0)
  83. c.ServeJSON()
  84. }
  85. // @Summary 生成指定检测任务的报告
  86. // @Description 生成指定检测任务的报告
  87. // @Tags 检测报告服务接口
  88. // @Accept x-www-form-urlencoded
  89. // @Produce json
  90. // @Param task_id formData int true "任务ID"
  91. // @Success 200 {object} ResultOK 成功
  92. // @Failure 500 {object} ResultError 失败
  93. // @router /report/make [post]
  94. func (c *ReportController) MakeReport() {
  95. id, _ := c.GetInt("task_id")
  96. if id == 0 {
  97. c.Data["json"] = c.ResultError("检测任务ID不能为空")
  98. c.ServeJSON()
  99. return
  100. }
  101. obj := new(bo.TaskReportMgr)
  102. obj.SetUserInfo(c.GetCurrentUserInfo())
  103. obj.Model = bo.T_data_task_report{TaskId: id, State: 1}
  104. reportid, err := obj.Make()
  105. if err != nil {
  106. c.Data["json"] = c.ResultError(err.Error())
  107. c.ServeJSON()
  108. return
  109. }
  110. obj.Model.Id = reportid
  111. info, _ := obj.One(id)
  112. c.Data["json"] = c.ResultOK(info, 1)
  113. c.ServeJSON()
  114. }
  115. // @Summary 创建新的检测报告模板
  116. // @Description 创建新的检测报告模板
  117. // @Tags 检测报告服务接口
  118. // @Accept x-www-form-urlencoded
  119. // @Produce json
  120. // @Param id formData int false "报告模板ID。指定id值大于0时为编辑操作;否则为新增操作"
  121. // @Param name formData string true "报告模板名称"
  122. // @Param doc_id formData int true "报告模板附件ID"
  123. // @Param memo formData string false "报告模板说明"
  124. // @Param state formData int true "启用状态。1 启用 2 禁用。默认为1"
  125. // @Success 200 {object} ResultOK 成功
  126. // @Failure 500 {object} ResultError 失败
  127. // @router /report/tpl/save [post]
  128. func (c *ReportController) SavereportTplInfo() {
  129. id, _ := c.GetInt("id")
  130. obj := new(bo.ReportTplMgr)
  131. obj.SetUserInfo(c.GetCurrentUserInfo())
  132. obj.Model = bo.T_data_report_tpl{Id: id}
  133. obj.Model.Name = c.GetString("name")
  134. obj.Model.Memo = c.GetString("memo")
  135. obj.Model.DocId, _ = c.GetInt("doc_id")
  136. obj.Model.State, _ = c.GetInt("state")
  137. if obj.Model.Id == 0 && obj.Model.State == 0 {
  138. obj.Model.State = 1
  139. }
  140. if obj.Model.Name == "" {
  141. c.Data["json"] = c.ResultError("检测报告模板名称不能为空")
  142. c.ServeJSON()
  143. return
  144. }
  145. if obj.Model.DocId == 0 {
  146. c.Data["json"] = c.ResultError("检测报告附件不能为空")
  147. c.ServeJSON()
  148. return
  149. }
  150. err := obj.Save()
  151. if err != nil {
  152. c.Data["json"] = c.ResultError(err.Error())
  153. c.ServeJSON()
  154. return
  155. }
  156. c.Data["json"] = c.ResultOK("", 0)
  157. c.ServeJSON()
  158. }
  159. // @Summary 删除指定的检测报告模板
  160. // @Description 删除指定的检测报告模板
  161. // @Tags 检测报告服务接口
  162. // @Accept x-www-form-urlencoded
  163. // @Produce json
  164. // @Param id formData int true "检测报告模板ID"
  165. // @Success 200 {object} ResultOK 成功
  166. // @Failure 500 {object} ResultError 失败
  167. // @router /report/tpl/delete [post]
  168. func (c *ReportController) DeleteTpl() {
  169. id, _ := c.GetInt("id")
  170. if id == 0 {
  171. c.Data["json"] = c.ResultError("报告模板编号不能为空!")
  172. c.ServeJSON()
  173. return
  174. }
  175. obj := new(bo.ReportTplMgr)
  176. obj.SetUserInfo(c.GetCurrentUserInfo())
  177. obj.Model = bo.T_data_report_tpl{}
  178. obj.Model.Id = id
  179. err := obj.Delete()
  180. if err != nil {
  181. c.Data["json"] = c.ResultError(err.Error())
  182. c.ServeJSON()
  183. return
  184. }
  185. c.Data["json"] = c.ResultOK("", 0)
  186. c.ServeJSON()
  187. }
  188. // @Summary 查询检测报告模板
  189. // @Description 查询检测报告模板。支持报告模板名称、状态等过滤条件
  190. // @Tags 检测报告服务接口
  191. // @Accept x-www-form-urlencoded
  192. // @Produce json
  193. // @Param pageno query int true "当前页码。默认为1"
  194. // @Param pagesize query int true "每页显示数据数。默认为20"
  195. // @Param id query int false "报告模板ID"
  196. // @Param name query string false "名称"
  197. // @Param state query int false "状态。空:全部 1:启用 2:禁用"
  198. // @Success 200 {object} ResultOK 成功
  199. // @Failure 500 {object} ResultError 失败
  200. // @router /report/tpl/list [get]
  201. func (c *ReportController) GetreportTplList() {
  202. obj := new(bo.ReportTplMgr)
  203. obj.SetUserInfo(c.GetCurrentUserInfo())
  204. obj.Model = bo.T_data_report_tpl{}
  205. obj.Model.Id, _ = c.GetInt("id")
  206. obj.Model.Name = c.GetString("name")
  207. obj.Model.State, _ = c.GetInt("state", 0)
  208. pi, _ := c.GetInt("pagesize", 20)
  209. po, _ := c.GetInt("pageno", 0)
  210. if po == 0 {
  211. po, _ = c.GetInt("pageindex", 0)
  212. }
  213. if po == 0 {
  214. po = 1
  215. }
  216. lst, cnt, err := obj.List(po, pi)
  217. if err != nil {
  218. c.Data["json"] = c.ResultError(err.Error())
  219. c.ServeJSON()
  220. return
  221. }
  222. c.Data["json"] = c.ResultOK(lst, cnt)
  223. c.ServeJSON()
  224. }