report_approval.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_hub/models"
  5. "eta/eta_hub/services"
  6. "eta/eta_hub/utils"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. "html"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // ReportController 报告
  14. type ReportController struct {
  15. BaseAuthController
  16. }
  17. // ListReport
  18. // @Title 获取报告列表接口
  19. // @Description 获取报告列表
  20. // @Param PageSize query int true "每页数据条数"
  21. // @Param CurrentIndex query int true "当前页页码,从1开始"
  22. // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间)"
  23. // @Param StartDate query string true "开始时间"
  24. // @Param EndDate query string true "结束时间"
  25. // @Param Frequency query string true "频度"
  26. // @Param ClassifyNameFirst query string true "一级分类名称"
  27. // @Param ClassifyNameSecond query string true "二级分类名称"
  28. // @Param State query int true "状态"
  29. // @Param KeyWord query string true "搜索关键词"
  30. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  31. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  32. // @Success 200 {object} models.ReportListResp
  33. // @router /list [get]
  34. func (this *ReportController) ListReport() {
  35. br := new(models.BaseResponse).Init()
  36. defer func() {
  37. this.Data["json"] = br
  38. this.ServeJSON()
  39. }()
  40. pageSize, _ := this.GetInt("PageSize")
  41. currentIndex, _ := this.GetInt("CurrentIndex")
  42. //timeType := this.GetString("TimeType")
  43. //startDate := this.GetString("StartDate")
  44. //endDate := this.GetString("EndDate")
  45. //frequency := this.GetString("Frequency")
  46. //classifyNameFirst := this.GetString("ClassifyNameFirst")
  47. //classifyNameSecond := this.GetString("ClassifyNameSecond")
  48. //state, _ := this.GetInt("State")
  49. //keyWord := this.GetString("KeyWord")
  50. //companyType := this.GetString("CompanyType")
  51. var startSize int
  52. if pageSize <= 0 {
  53. pageSize = utils.PageSize20
  54. }
  55. if currentIndex <= 0 {
  56. currentIndex = 1
  57. }
  58. startSize = utils.StartIndex(currentIndex, pageSize)
  59. //if timeType == "" {
  60. // timeType = "publish_time"
  61. //}
  62. //if timeType != "publish_time" && timeType != "modify_time" {
  63. // br.Msg = "请选择正确的时间"
  64. // br.ErrMsg = "请选择正确的时间"
  65. // return
  66. //}
  67. var condition string
  68. var pars []interface{}
  69. //if keyWord != "" {
  70. // condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  71. // pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  72. //}
  73. //if startDate != "" {
  74. // condition += ` AND ` + timeType + ` >= ? `
  75. // pars = append(pars, startDate)
  76. //}
  77. //if endDate != "" {
  78. // condition += ` AND ` + timeType + ` <= ? `
  79. // pars = append(pars, endDate)
  80. //}
  81. //if frequency != "" {
  82. // condition += ` AND frequency = ? `
  83. // pars = append(pars, frequency)
  84. //}
  85. //if classifyNameFirst != "" {
  86. // condition += ` AND classify_name_first = ? `
  87. // pars = append(pars, classifyNameFirst)
  88. //}
  89. //
  90. //if classifyNameSecond != "" {
  91. // condition += ` AND classify_name_second = ? `
  92. // pars = append(pars, classifyNameSecond)
  93. //}
  94. //if state > 0 {
  95. // condition += ` AND state = ? `
  96. // pars = append(pars, state)
  97. //}
  98. condition += ` AND state <> 1 `
  99. total, err := models.GetReportListCount(condition, pars, "")
  100. if err != nil {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = "获取失败,Err:" + err.Error()
  103. return
  104. }
  105. list, err := models.GetReportList(condition, pars, "", startSize, pageSize)
  106. if err != nil {
  107. br.Msg = "获取失败"
  108. br.ErrMsg = "获取失败,Err:" + err.Error()
  109. return
  110. }
  111. listLen := len(list)
  112. if listLen > 0 {
  113. for i := 0; i < listLen; i++ {
  114. list[i].Content = html.UnescapeString(list[i].Content)
  115. list[i].ContentSub = html.UnescapeString(list[i].ContentSub)
  116. }
  117. }
  118. page := paging.GetPaging(currentIndex, pageSize, total)
  119. resp := new(models.ReportListResp)
  120. resp.Paging = page
  121. resp.List = list
  122. br.Ret = 200
  123. br.Msg = "获取成功"
  124. br.Data = resp
  125. }
  126. // PublishReport
  127. // @Title 审核报告接口
  128. // @Description 发布报告
  129. // @Param request body models.PublishReq true "type json string"
  130. // @Success 200 Ret=200 发布成功
  131. // @router /publish [post]
  132. func (this *ReportController) PublishReport() {
  133. br := new(models.BaseResponse).Init()
  134. defer func() {
  135. this.Data["json"] = br
  136. this.ServeJSON()
  137. }()
  138. var req models.PublishReq
  139. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  140. if err != nil {
  141. br.Msg = "参数解析异常!"
  142. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  143. return
  144. }
  145. reportIds := req.ReportIds
  146. if reportIds == "" {
  147. br.Msg = "参数错误"
  148. br.ErrMsg = "参数错误,报告id不可为空"
  149. return
  150. }
  151. if req.State != 3 && req.State != 4 {
  152. br.Msg = "参数有误"
  153. return
  154. }
  155. reportArr := strings.Split(reportIds, ",")
  156. for _, v := range reportArr {
  157. vint, err := strconv.Atoi(v)
  158. if err != nil {
  159. br.Msg = "参数错误"
  160. br.ErrMsg = "参数错误,Err:" + err.Error()
  161. return
  162. }
  163. report, err := models.GetReportById(vint)
  164. if err != nil {
  165. br.Msg = "获取报告信息失败"
  166. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  167. return
  168. }
  169. if report == nil {
  170. br.Msg = "报告不存在"
  171. return
  172. }
  173. if report.State != 2 {
  174. br.Msg = "报告状态错误"
  175. br.ErrMsg = "报告状态非待审核状态,Err:" + err.Error()
  176. return
  177. }
  178. publishTime := time.Now()
  179. var tmpErr error
  180. if report.Content == "" {
  181. br.Msg = "报告内容为空"
  182. br.ErrMsg = "报告内容为空,report_id:" + strconv.Itoa(report.Id)
  183. return
  184. }
  185. if tmpErr = models.PublishReportById(report.Id, req.State, publishTime); tmpErr != nil {
  186. br.Msg = "报告审核失败"
  187. br.ErrMsg = "报告审核失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
  188. return
  189. }
  190. recordItem := &models.ReportStateRecord{
  191. ReportId: vint,
  192. ReportType: 1,
  193. State: req.State,
  194. CreateTime: time.Now(),
  195. }
  196. go func() {
  197. _, _ = models.AddReportStateRecord(recordItem)
  198. }()
  199. go func() {
  200. // 更新报告Es
  201. _ = services.UpdateReportEs(report.Id, req.State)
  202. }()
  203. }
  204. if req.State == 3 {
  205. br.Msg = "驳回成功"
  206. } else {
  207. br.Msg = "审批通过"
  208. }
  209. br.Ret = 200
  210. br.Msg = "审批成功"
  211. }
  212. // Detail
  213. // @Title 获取报告详情接口
  214. // @Description 获取报告详情
  215. // @Param request body models.ReportDetailReq true "type json string"
  216. // @Success 200 {object} models.Report
  217. // @router /detail [get]
  218. func (this *ReportController) Detail() {
  219. br := new(models.BaseResponse).Init()
  220. defer func() {
  221. this.Data["json"] = br
  222. this.ServeJSON()
  223. }()
  224. reportId, err := this.GetInt("ReportId")
  225. if err != nil {
  226. br.Msg = "获取参数失败!"
  227. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  228. return
  229. }
  230. if reportId <= 0 {
  231. br.Msg = "参数错误"
  232. return
  233. }
  234. item, err := models.GetReportById(reportId)
  235. if err != nil {
  236. if err.Error() == utils.ErrNoRow() {
  237. br.Msg = "报告已被删除"
  238. return
  239. }
  240. br.Msg = "获取失败"
  241. br.ErrMsg = "获取失败,Err:" + err.Error()
  242. return
  243. }
  244. // 报告状态 2待审核 3已驳回 4已审批
  245. if !utils.InArrayByInt([]int{2,3,4}, item.State) {
  246. br.Msg = "报告状态错误"
  247. br.ErrMsg = "报告状态错误"
  248. return
  249. }
  250. item.Content = html.UnescapeString(item.Content)
  251. item.ContentSub = html.UnescapeString(item.ContentSub)
  252. br.Ret = 200
  253. br.Msg = "获取成功"
  254. br.Data = item
  255. }