jt_df.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "net/http"
  6. "xingjia-management-gateway/apis"
  7. "xingjia-management-gateway/consts"
  8. "xingjia-management-gateway/errors"
  9. "xingjia-management-gateway/impl/v1/jt"
  10. param_v1 "xingjia-management-gateway/param/v1"
  11. "xingjia-management-gateway/utils"
  12. "git.getensh.com/common/gopkgs/logger"
  13. "git.getensh.com/common/gopkgs/tasker/httptasker"
  14. "git.getensh.com/common/gopkgs/util"
  15. "github.com/gin-gonic/gin"
  16. "go.uber.org/zap"
  17. )
  18. //
  19. // @Summary 添加党风廉洁
  20. // @Description 添加党风廉洁
  21. // @Tags 党风廉洁
  22. // @Accept json
  23. // @Produce json
  24. // @Param token header string true " "
  25. // @Param body body v1.JtContentAddBody true " "
  26. // @Success 200 {object} v1.JtContentAddResponse
  27. // @Failure 500 {object} base.HTTPError
  28. // @Router /api/v1/jt/df [post]
  29. func (c *Controller) JtDfAdd(ctx *gin.Context) {
  30. // 解析参数
  31. req := &param_v1.JtContentAddRequest{}
  32. parseParamTask := func() error {
  33. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentAddBody)
  34. if err != nil {
  35. logger.Error("func",
  36. zap.String("call", "util.ShouldBind"),
  37. zap.String("error", err.Error()))
  38. return errors.ParamsError
  39. }
  40. return nil
  41. }
  42. // 业务处理
  43. handleServiceTask := func() error {
  44. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  45. if err != nil {
  46. return err
  47. }
  48. // 响应数据
  49. resp := param_v1.JtContentAddResponse{}
  50. rpcReq := &apis.JtContentAddRequest{
  51. FirstPics: req.FirstPics,
  52. ContentType: consts.OperationModuleDangfeng,
  53. Content: req.Content,
  54. SelfId: tokenInfo.Uid,
  55. SelfName: tokenInfo.User,
  56. PublishStatus: req.PublishStatus,
  57. Title: req.Title,
  58. }
  59. _, err = jt.JtContentAdd(ctx, rpcReq)
  60. if err != nil {
  61. s, _ := json.MarshalToString(req)
  62. logger.Error("func",
  63. zap.String("call", "jt.JtContentAdd"),
  64. zap.String("params", s),
  65. zap.String("error", err.Error()))
  66. return errors.ErrorTransForm(err)
  67. }
  68. ctx.JSON(http.StatusOK, resp)
  69. return nil
  70. }
  71. // 执行任务
  72. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  73. }
  74. //
  75. // @Summary 修改党风廉洁
  76. // @Description 修改党风廉洁
  77. // @Tags 党风廉洁
  78. // @Accept json
  79. // @Produce json
  80. // @Param token header string true " "
  81. // @Param body body v1.JtContentUpdateBody true " "
  82. // @Success 200 {object} v1.JtContentUpdateResponse
  83. // @Failure 500 {object} base.HTTPError
  84. // @Router /api/v1/jt/df [put]
  85. func (c *Controller) JtDfUpdate(ctx *gin.Context) {
  86. // 解析参数
  87. req := &param_v1.JtContentUpdateRequest{}
  88. parseParamTask := func() error {
  89. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentUpdateBody)
  90. if err != nil {
  91. logger.Error("func",
  92. zap.String("call", "util.ShouldBind"),
  93. zap.String("error", err.Error()))
  94. return errors.ParamsError
  95. }
  96. return nil
  97. }
  98. // 业务处理
  99. handleServiceTask := func() error {
  100. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  101. if err != nil {
  102. return err
  103. }
  104. // 响应数据
  105. resp := param_v1.JtContentUpdateResponse{}
  106. rpcReq := &apis.JtContentUpdateRequest{
  107. FirstPics: req.FirstPics,
  108. ContentType: consts.OperationModuleDangfeng,
  109. Content: req.Content,
  110. SelfId: tokenInfo.Uid,
  111. SelfName: tokenInfo.User,
  112. Id: req.Id,
  113. PublishStatus: req.PublishStatus,
  114. }
  115. _, err = jt.JtContentUpdate(ctx, rpcReq)
  116. if err != nil {
  117. s, _ := json.MarshalToString(req)
  118. logger.Error("func",
  119. zap.String("call", "jt.JtContentUpdate"),
  120. zap.String("params", s),
  121. zap.String("error", err.Error()))
  122. return errors.ErrorTransForm(err)
  123. }
  124. ctx.JSON(http.StatusOK, resp)
  125. return nil
  126. }
  127. // 执行任务
  128. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  129. }
  130. //
  131. // @Summary 发布或下架党风廉洁
  132. // @Description 发布或下架党风廉洁
  133. // @Tags 党风廉洁
  134. // @Accept json
  135. // @Produce json
  136. // @Param token header string true " "
  137. // @Param body body v1.JtContentPublishBody true " "
  138. // @Success 200 {object} v1.JtContentPublishResponse
  139. // @Failure 500 {object} base.HTTPError
  140. // @Router /api/v1/jt/df/publish [put]
  141. func (c *Controller) JtDfPublish(ctx *gin.Context) {
  142. // 解析参数
  143. req := &param_v1.JtContentPublishRequest{}
  144. parseParamTask := func() error {
  145. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentPublishBody)
  146. if err != nil {
  147. logger.Error("func",
  148. zap.String("call", "util.ShouldBind"),
  149. zap.String("error", err.Error()))
  150. return errors.ParamsError
  151. }
  152. return nil
  153. }
  154. // 业务处理
  155. handleServiceTask := func() error {
  156. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  157. if err != nil {
  158. return err
  159. }
  160. // 响应数据
  161. resp := param_v1.JtContentPublishResponse{}
  162. rpcReq := &apis.JtContentPublishRequest{
  163. ContentType: consts.OperationModuleDangfeng,
  164. SelfId: tokenInfo.Uid,
  165. SelfName: tokenInfo.User,
  166. Id: req.Id,
  167. PublishStatus: req.PublishStatus,
  168. }
  169. _, err = jt.JtContentPublish(ctx, rpcReq)
  170. if err != nil {
  171. s, _ := json.MarshalToString(req)
  172. logger.Error("func",
  173. zap.String("call", "jt.JtContentPublish"),
  174. zap.String("params", s),
  175. zap.String("error", err.Error()))
  176. return errors.ErrorTransForm(err)
  177. }
  178. ctx.JSON(http.StatusOK, resp)
  179. return nil
  180. }
  181. // 执行任务
  182. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  183. }
  184. //
  185. // @Summary 删除党风廉洁
  186. // @Description 删除党风廉洁
  187. // @Tags 党风廉洁
  188. // @Accept json
  189. // @Produce json
  190. // @Param token header string true " "
  191. // @Param id query int true " 记录id"
  192. // @Success 200 {object} v1.JtContentDelResponse
  193. // @Failure 500 {object} base.HTTPError
  194. // @Router /api/v1/jt/df [delete]
  195. func (c *Controller) JtDfDel(ctx *gin.Context) {
  196. // 解析参数
  197. req := &param_v1.JtContentDelRequest{}
  198. parseParamTask := func() error {
  199. err := util.ShouldBind(ctx, &req.Header, nil, &req.JtContentDelQuery, nil)
  200. if err != nil {
  201. logger.Error("func",
  202. zap.String("call", "util.ShouldBind"),
  203. zap.String("error", err.Error()))
  204. return errors.ParamsError
  205. }
  206. return nil
  207. }
  208. // 业务处理
  209. handleServiceTask := func() error {
  210. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  211. if err != nil {
  212. return err
  213. }
  214. // 响应数据
  215. resp := param_v1.JtContentDelResponse{}
  216. rpcReq := &apis.JtContentDelRequest{
  217. ContentType: consts.OperationModuleDangfeng,
  218. SelfId: tokenInfo.Uid,
  219. SelfName: tokenInfo.User,
  220. Id: req.Id,
  221. }
  222. _, err = jt.JtContentDel(ctx, rpcReq)
  223. if err != nil {
  224. s, _ := json.MarshalToString(req)
  225. logger.Error("func",
  226. zap.String("call", "jt.JtContentDel"),
  227. zap.String("params", s),
  228. zap.String("error", err.Error()))
  229. return errors.ErrorTransForm(err)
  230. }
  231. ctx.JSON(http.StatusOK, resp)
  232. return nil
  233. }
  234. // 执行任务
  235. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  236. }
  237. //
  238. // @Summary 党风廉洁列表
  239. // @Description 党风廉洁列表
  240. // @Tags 党风廉洁
  241. // @Accept json
  242. // @Produce json
  243. // @Param token header string true " "
  244. // @Param page query int false " "
  245. // @Param page_size query int false " "
  246. // @Success 200 {object} v1.JtContentListResponse
  247. // @Failure 500 {object} base.HTTPError
  248. // @Router /api/v1/jt/df [get]
  249. func (c *Controller) JtDfList(ctx *gin.Context) {
  250. // 解析参数
  251. req := &param_v1.JtContentListRequest{}
  252. parseParamTask := func() error {
  253. err := util.ShouldBind(ctx, &req.Header, nil, &req.JtContentListQuery, nil)
  254. if err != nil {
  255. logger.Error("func",
  256. zap.String("call", "util.ShouldBind"),
  257. zap.String("error", err.Error()))
  258. return errors.ParamsError
  259. }
  260. return nil
  261. }
  262. // 业务处理
  263. handleServiceTask := func() error {
  264. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  265. if err != nil {
  266. return err
  267. }
  268. // 响应数据
  269. resp := param_v1.JtContentListResponse{}
  270. rpcReq := &apis.JtContentListRequest{
  271. ContentType: consts.OperationModuleDangfeng,
  272. PageSize: req.PageSize,
  273. Page: req.Page,
  274. SelfId: tokenInfo.Uid,
  275. }
  276. rpcRsp, err := jt.JtContentList(ctx, rpcReq)
  277. if err != nil {
  278. s, _ := json.MarshalToString(req)
  279. logger.Error("func",
  280. zap.String("call", "jt.JtContentList"),
  281. zap.String("params", s),
  282. zap.String("error", err.Error()))
  283. return errors.ErrorTransForm(err)
  284. }
  285. if rpcRsp.List == nil {
  286. rpcRsp.List = make([]*apis.JtContentItem, 0)
  287. }
  288. resp.Data = *rpcRsp
  289. ctx.JSON(http.StatusOK, resp)
  290. return nil
  291. }
  292. // 执行任务
  293. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  294. }