jt_program.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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/program [post]
  29. func (c *Controller) JtProgramAdd(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.OperationModuleProgram,
  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/program [put]
  85. func (c *Controller) JtProgramUpdate(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.OperationModuleProgram,
  109. Content: req.Content,
  110. SelfId: tokenInfo.Uid,
  111. SelfName: tokenInfo.User,
  112. Id: req.Id,
  113. PublishStatus: req.PublishStatus,
  114. Title: req.Title,
  115. }
  116. _, err = jt.JtContentUpdate(ctx, rpcReq)
  117. if err != nil {
  118. s, _ := json.MarshalToString(req)
  119. logger.Error("func",
  120. zap.String("call", "jt.JtContentUpdate"),
  121. zap.String("params", s),
  122. zap.String("error", err.Error()))
  123. return errors.ErrorTransForm(err)
  124. }
  125. ctx.JSON(http.StatusOK, resp)
  126. return nil
  127. }
  128. // 执行任务
  129. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  130. }
  131. //
  132. // @Summary 发布或下架项目展示
  133. // @Description 发布或下架项目展示
  134. // @Tags 项目展示
  135. // @Accept json
  136. // @Produce json
  137. // @Param token header string true " "
  138. // @Param body body v1.JtContentPublishBody true " "
  139. // @Success 200 {object} v1.JtContentPublishResponse
  140. // @Failure 500 {object} base.HTTPError
  141. // @Router /api/v1/jt/program/publish [put]
  142. func (c *Controller) JtProgramPublish(ctx *gin.Context) {
  143. // 解析参数
  144. req := &param_v1.JtContentPublishRequest{}
  145. parseParamTask := func() error {
  146. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentPublishBody)
  147. if err != nil {
  148. logger.Error("func",
  149. zap.String("call", "util.ShouldBind"),
  150. zap.String("error", err.Error()))
  151. return errors.ParamsError
  152. }
  153. return nil
  154. }
  155. // 业务处理
  156. handleServiceTask := func() error {
  157. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  158. if err != nil {
  159. return err
  160. }
  161. // 响应数据
  162. resp := param_v1.JtContentPublishResponse{}
  163. rpcReq := &apis.JtContentPublishRequest{
  164. ContentType: consts.OperationModuleProgram,
  165. SelfId: tokenInfo.Uid,
  166. SelfName: tokenInfo.User,
  167. Id: req.Id,
  168. PublishStatus: req.PublishStatus,
  169. }
  170. _, err = jt.JtContentPublish(ctx, rpcReq)
  171. if err != nil {
  172. s, _ := json.MarshalToString(req)
  173. logger.Error("func",
  174. zap.String("call", "jt.JtContentPublish"),
  175. zap.String("params", s),
  176. zap.String("error", err.Error()))
  177. return errors.ErrorTransForm(err)
  178. }
  179. ctx.JSON(http.StatusOK, resp)
  180. return nil
  181. }
  182. // 执行任务
  183. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  184. }
  185. //
  186. // @Summary 删除项目
  187. // @Description 删除项目
  188. // @Tags 项目展示
  189. // @Accept json
  190. // @Produce json
  191. // @Param token header string true " "
  192. // @Param id query int true " 记录id"
  193. // @Success 200 {object} v1.JtContentDelResponse
  194. // @Failure 500 {object} base.HTTPError
  195. // @Router /api/v1/jt/program [delete]
  196. func (c *Controller) JtProgramDel(ctx *gin.Context) {
  197. // 解析参数
  198. req := &param_v1.JtContentDelRequest{}
  199. parseParamTask := func() error {
  200. err := util.ShouldBind(ctx, &req.Header, nil, &req.JtContentDelQuery, nil)
  201. if err != nil {
  202. logger.Error("func",
  203. zap.String("call", "util.ShouldBind"),
  204. zap.String("error", err.Error()))
  205. return errors.ParamsError
  206. }
  207. return nil
  208. }
  209. // 业务处理
  210. handleServiceTask := func() error {
  211. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  212. if err != nil {
  213. return err
  214. }
  215. // 响应数据
  216. resp := param_v1.JtContentDelResponse{}
  217. rpcReq := &apis.JtContentDelRequest{
  218. ContentType: consts.OperationModuleProgram,
  219. SelfId: tokenInfo.Uid,
  220. SelfName: tokenInfo.User,
  221. Id: req.Id,
  222. }
  223. _, err = jt.JtContentDel(ctx, rpcReq)
  224. if err != nil {
  225. s, _ := json.MarshalToString(req)
  226. logger.Error("func",
  227. zap.String("call", "jt.JtContentDel"),
  228. zap.String("params", s),
  229. zap.String("error", err.Error()))
  230. return errors.ErrorTransForm(err)
  231. }
  232. ctx.JSON(http.StatusOK, resp)
  233. return nil
  234. }
  235. // 执行任务
  236. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  237. }
  238. //
  239. // @Summary 项目展示列表
  240. // @Description 项目展示列表
  241. // @Tags 项目展示
  242. // @Accept json
  243. // @Produce json
  244. // @Param token header string true " "
  245. // @Param page query int false " "
  246. // @Param page_size query int false " "
  247. // @Success 200 {object} v1.JtContentListResponse
  248. // @Failure 500 {object} base.HTTPError
  249. // @Router /api/v1/jt/program [get]
  250. func (c *Controller) JtProgramList(ctx *gin.Context) {
  251. // 解析参数
  252. req := &param_v1.JtContentListRequest{}
  253. parseParamTask := func() error {
  254. err := util.ShouldBind(ctx, &req.Header, nil, &req.JtContentListQuery, nil)
  255. if err != nil {
  256. logger.Error("func",
  257. zap.String("call", "util.ShouldBind"),
  258. zap.String("error", err.Error()))
  259. return errors.ParamsError
  260. }
  261. return nil
  262. }
  263. // 业务处理
  264. handleServiceTask := func() error {
  265. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  266. if err != nil {
  267. return err
  268. }
  269. // 响应数据
  270. resp := param_v1.JtContentListResponse{}
  271. rpcReq := &apis.JtContentListRequest{
  272. ContentType: consts.OperationModuleProgram,
  273. PageSize: req.PageSize,
  274. Page: req.Page,
  275. SelfId: tokenInfo.Uid,
  276. }
  277. rpcRsp, err := jt.JtContentList(ctx, rpcReq)
  278. if err != nil {
  279. s, _ := json.MarshalToString(req)
  280. logger.Error("func",
  281. zap.String("call", "jt.JtContentList"),
  282. zap.String("params", s),
  283. zap.String("error", err.Error()))
  284. return errors.ErrorTransForm(err)
  285. }
  286. if rpcRsp.List == nil {
  287. rpcRsp.List = make([]*apis.JtContentItem, 0)
  288. }
  289. resp.Data = *rpcRsp
  290. ctx.JSON(http.StatusOK, resp)
  291. return nil
  292. }
  293. // 执行任务
  294. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  295. }