reportController.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 id formData int false "报告模板ID。指定id值大于0时为编辑操作;否则为新增操作"
  27. // @Param name formData string true "报告模板名称"
  28. // @Param doc_id formData int true "报告模板附件ID"
  29. // @Param memo formData string false "报告模板说明"
  30. // @Param state formData int true "启用状态。1 启用 2 禁用。默认为1"
  31. // @Success 200 {object} ResultOK 成功
  32. // @Failure 500 {object} ResultError 失败
  33. // @router /report/tpl/save [post]
  34. func (c *ReportController) SavereportTplInfo() {
  35. id, _ := c.GetInt("id")
  36. obj := new(bo.ReportTplMgr)
  37. obj.SetUserInfo(c.GetCurrentUserInfo())
  38. obj.Model = bo.T_data_report_tpl{Id: id}
  39. obj.Model.Name = c.GetString("name")
  40. obj.Model.Memo = c.GetString("memo")
  41. obj.Model.DocId, _ = c.GetInt("doc_id")
  42. obj.Model.State, _ = c.GetInt("state")
  43. if obj.Model.Id == 0 && obj.Model.State == 0 {
  44. obj.Model.State = 1
  45. }
  46. if obj.Model.Name == "" {
  47. c.Data["json"] = c.ResultError("检测报告模板名称不能为空")
  48. c.ServeJSON()
  49. return
  50. }
  51. if obj.Model.DocId == 0 {
  52. c.Data["json"] = c.ResultError("检测报告附件不能为空")
  53. c.ServeJSON()
  54. return
  55. }
  56. err := obj.Save()
  57. if err != nil {
  58. c.Data["json"] = c.ResultError(err.Error())
  59. c.ServeJSON()
  60. return
  61. }
  62. c.Data["json"] = c.ResultOK("", 0)
  63. c.ServeJSON()
  64. }
  65. // @Summary 删除指定的检测报告模板
  66. // @Description 删除指定的检测报告模板
  67. // @Tags 检测报告服务接口
  68. // @Accept x-www-form-urlencoded
  69. // @Produce json
  70. // @Param id formData int true "检测报告ID"
  71. // @Success 200 {object} ResultOK 成功
  72. // @Failure 500 {object} ResultError 失败
  73. // @router /report/tpl/delete [post]
  74. func (c *ReportController) DeleteTpl() {
  75. id, _ := c.GetInt("id")
  76. if id == 0 {
  77. c.Data["json"] = c.ResultError("报告模板编号不能为空!")
  78. c.ServeJSON()
  79. return
  80. }
  81. obj := new(bo.ReportTplMgr)
  82. obj.SetUserInfo(c.GetCurrentUserInfo())
  83. obj.Model = bo.T_data_report_tpl{}
  84. obj.Model.Id = id
  85. err := obj.Delete()
  86. if err != nil {
  87. c.Data["json"] = c.ResultError(err.Error())
  88. c.ServeJSON()
  89. return
  90. }
  91. c.Data["json"] = c.ResultOK("", 0)
  92. c.ServeJSON()
  93. }
  94. // @Summary 查询检测报告模板
  95. // @Description 查询检测报告模板。支持报告模板名称、状态等过滤条件
  96. // @Tags 检测报告服务接口
  97. // @Accept x-www-form-urlencoded
  98. // @Produce json
  99. // @Param pageno query int true "当前页码。默认为1"
  100. // @Param pagesize query int true "每页显示数据数。默认为20"
  101. // @Param id query int false "报告模板ID"
  102. // @Param name query string false "名称"
  103. // @Param state query int false "状态。空:全部 1:启用 2:禁用"
  104. // @Success 200 {object} ResultOK 成功
  105. // @Failure 500 {object} ResultError 失败
  106. // @router /report/tpl/list [get]
  107. func (c *ReportController) GetreportTplList() {
  108. obj := new(bo.ReportTplMgr)
  109. obj.SetUserInfo(c.GetCurrentUserInfo())
  110. obj.Model = bo.T_data_report_tpl{}
  111. obj.Model.Id, _ = c.GetInt("id")
  112. obj.Model.Name = c.GetString("name")
  113. obj.Model.State, _ = c.GetInt("state", 0)
  114. pi, _ := c.GetInt("pagesize", 20)
  115. po, _ := c.GetInt("pageno", 0)
  116. if po == 0 {
  117. po, _ = c.GetInt("pageindex", 0)
  118. }
  119. if po == 0 {
  120. po = 1
  121. }
  122. lst, cnt, err := obj.List(po, pi)
  123. if err != nil {
  124. c.Data["json"] = c.ResultError(err.Error())
  125. c.ServeJSON()
  126. return
  127. }
  128. c.Data["json"] = c.ResultOK(lst, cnt)
  129. c.ServeJSON()
  130. }