jt_vision.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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/vision [post]
  29. func (c *Controller) JtVisionAdd(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.OperationModuleVision,
  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.JtContentPublishBody true " "
  82. // @Success 200 {object} v1.JtContentPublishResponse
  83. // @Failure 500 {object} base.HTTPError
  84. // @Router /api/v1/jt/vision/publish [put]
  85. func (c *Controller) JtVisionPublish(ctx *gin.Context) {
  86. // 解析参数
  87. req := &param_v1.JtContentPublishRequest{}
  88. parseParamTask := func() error {
  89. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentPublishBody)
  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.JtContentPublishResponse{}
  106. rpcReq := &apis.JtContentPublishRequest{
  107. ContentType: consts.OperationModuleVision,
  108. SelfId: tokenInfo.Uid,
  109. SelfName: tokenInfo.User,
  110. Id: req.Id,
  111. PublishStatus: req.PublishStatus,
  112. }
  113. _, err = jt.JtContentPublish(ctx, rpcReq)
  114. if err != nil {
  115. s, _ := json.MarshalToString(req)
  116. logger.Error("func",
  117. zap.String("call", "jt.JtContentPublish"),
  118. zap.String("params", s),
  119. zap.String("error", err.Error()))
  120. return errors.ErrorTransForm(err)
  121. }
  122. ctx.JSON(http.StatusOK, resp)
  123. return nil
  124. }
  125. // 执行任务
  126. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  127. }
  128. //
  129. // @Summary 修改发展愿景
  130. // @Description 修改发展愿景
  131. // @Tags 发展愿景
  132. // @Accept json
  133. // @Produce json
  134. // @Param token header string true " "
  135. // @Param body body v1.JtContentUpdateBody true " "
  136. // @Success 200 {object} v1.JtContentUpdateResponse
  137. // @Failure 500 {object} base.HTTPError
  138. // @Router /api/v1/jt/vision [put]
  139. func (c *Controller) JtVisionUpdate(ctx *gin.Context) {
  140. // 解析参数
  141. req := &param_v1.JtContentUpdateRequest{}
  142. parseParamTask := func() error {
  143. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentUpdateBody)
  144. if err != nil {
  145. logger.Error("func",
  146. zap.String("call", "util.ShouldBind"),
  147. zap.String("error", err.Error()))
  148. return errors.ParamsError
  149. }
  150. return nil
  151. }
  152. // 业务处理
  153. handleServiceTask := func() error {
  154. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  155. if err != nil {
  156. return err
  157. }
  158. // 响应数据
  159. resp := param_v1.JtContentUpdateResponse{}
  160. rpcReq := &apis.JtContentUpdateRequest{
  161. FirstPics: req.FirstPics,
  162. ContentType: consts.OperationModuleVision,
  163. Content: req.Content,
  164. SelfId: tokenInfo.Uid,
  165. SelfName: tokenInfo.User,
  166. Id: req.Id,
  167. PublishStatus: req.PublishStatus,
  168. Title: req.Title,
  169. }
  170. _, err = jt.JtContentUpdate(ctx, rpcReq)
  171. if err != nil {
  172. s, _ := json.MarshalToString(req)
  173. logger.Error("func",
  174. zap.String("call", "jt.JtContentUpdate"),
  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/vision [delete]
  196. func (c *Controller) JtVisionDel(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.OperationModuleVision,
  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. // @Success 200 {object} v1.JtContentInfoResponse
  246. // @Failure 500 {object} base.HTTPError
  247. // @Router /api/v1/jt/vision [get]
  248. func (c *Controller) JtVisionInfo(ctx *gin.Context) {
  249. // 解析参数
  250. req := &param_v1.JtContentInfoRequest{}
  251. parseParamTask := func() error {
  252. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  253. if err != nil {
  254. logger.Error("func",
  255. zap.String("call", "util.ShouldBind"),
  256. zap.String("error", err.Error()))
  257. return errors.ParamsError
  258. }
  259. return nil
  260. }
  261. // 业务处理
  262. handleServiceTask := func() error {
  263. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  264. if err != nil {
  265. return err
  266. }
  267. // 响应数据
  268. resp := param_v1.JtContentInfoResponse{}
  269. rpcReq := &apis.JtContentListRequest{
  270. ContentType: consts.OperationModuleVision,
  271. SelfId: tokenInfo.Uid,
  272. }
  273. rpcRsp, err := jt.JtContentList(ctx, rpcReq)
  274. if err != nil {
  275. s, _ := json.MarshalToString(req)
  276. logger.Error("func",
  277. zap.String("call", "jt.JtContentList"),
  278. zap.String("params", s),
  279. zap.String("error", err.Error()))
  280. return errors.ErrorTransForm(err)
  281. }
  282. if len(rpcRsp.List) == 0 {
  283. if len(resp.Data.FirstPics) == 0 {
  284. resp.Data.FirstPics = make([]string, 0)
  285. }
  286. ctx.JSON(http.StatusOK, resp)
  287. return nil
  288. }
  289. resp.Data.FirstPics = rpcRsp.List[0].FirstPics
  290. resp.Data.Title = rpcRsp.List[0].Title
  291. resp.Data.Content = rpcRsp.List[0].Content
  292. resp.Data.CreatedAt = rpcRsp.List[0].CreatedAt
  293. resp.Data.Id = rpcRsp.List[0].Id
  294. resp.Data.PublishStatus = rpcRsp.List[0].PublishStatus
  295. ctx.JSON(http.StatusOK, resp)
  296. return nil
  297. }
  298. // 执行任务
  299. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  300. }