suggestion.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-household-gateway/errors"
  10. param_v1 "property-household-gateway/param/v1"
  11. "property-household-gateway/pb"
  12. "property-household-gateway/pb/v1"
  13. "property-household-gateway/utils"
  14. )
  15. //
  16. // @Summary 新增工单
  17. // @Description 新增工单
  18. // @Tags 投诉与建议
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "token"
  22. // @Param body body v1.SuggestionOrderAddBody true "信息"
  23. // @Success 200 {object} v1.SuggestionOrderAddResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/suggestion/order [post]
  26. func (c *Controller) SuggestionOrderAdd(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.SuggestionOrderAddRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.SuggestionOrderAddBody)
  31. if err != nil {
  32. logger.Error("func",
  33. zap.String("call", "util.ShouldBind"),
  34. zap.String("error", err.Error()))
  35. return errors.ParamsError
  36. }
  37. return nil
  38. }
  39. // 业务处理
  40. handleServiceTask := func() error {
  41. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  42. if err != nil {
  43. return err
  44. }
  45. // 响应数据
  46. resp := param_v1.SuggestionOrderAddResponse{}
  47. rpcReq := &v1.SuggestionOrderAddRequest{
  48. GardenId: req.GardenId,
  49. SuggestionType: req.SuggestionType,
  50. // 报修人
  51. ApplyPeople: req.ApplyPeople,
  52. // 报修人电话
  53. ApplyPeoplePhone: req.ApplyPeoplePhone,
  54. // 上级处理人
  55. //LastUid:tokenInfo.Uid,
  56. // 报修内容
  57. ApplyContent: req.ApplyContent,
  58. // 报修图片
  59. ApplyPic: req.ApplyPic,
  60. HouseholdUid: tokenInfo.Uid,
  61. }
  62. rpcRsp, err := pb.Garden.SuggestionOrderAdd(ctx, rpcReq)
  63. if err != nil {
  64. s, _ := json.MarshalToString(req)
  65. logger.Error("func",
  66. zap.String("call", "pb.Garden.SuggestionOrderAdd"),
  67. zap.String("params", s),
  68. zap.String("error", err.Error()))
  69. return errors.ErrorTransForm(err)
  70. }
  71. resp.Data = *rpcRsp
  72. ctx.JSON(http.StatusOK, resp)
  73. return nil
  74. }
  75. // 执行任务
  76. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  77. }
  78. //
  79. // @Summary 修改工单
  80. // @Description 修改工单
  81. // @Tags 投诉与建议
  82. // @Accept json
  83. // @Produce json
  84. // @Param token header string true "token"
  85. // @Param body body v1.SuggestionOrderUpdateBody true "信息"
  86. // @Success 200 {object} v1.SuggestionOrderUpdateResponse
  87. // @Failure 500 {object} base.HTTPError
  88. // @Router /api/v1/suggestion/order [put]
  89. func (c *Controller) SuggestionOrderUpdate(ctx *gin.Context) {
  90. // 解析参数
  91. req := &param_v1.SuggestionOrderUpdateRequest{}
  92. parseParamTask := func() error {
  93. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.SuggestionOrderUpdateBody)
  94. if err != nil {
  95. logger.Error("func",
  96. zap.String("call", "util.ShouldBind"),
  97. zap.String("error", err.Error()))
  98. return errors.ParamsError
  99. }
  100. return nil
  101. }
  102. // 业务处理
  103. handleServiceTask := func() error {
  104. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  105. if err != nil {
  106. return err
  107. }
  108. // 响应数据
  109. resp := param_v1.SuggestionOrderUpdateResponse{}
  110. rpcReq := &v1.SuggestionOrderUpdateRequest{
  111. GardenId: req.GardenId,
  112. Id: req.Id,
  113. SuggestionType: req.SuggestionType,
  114. // 报修人
  115. ApplyPeople: req.ApplyPeople,
  116. // 报修人电话
  117. ApplyPeoplePhone: req.ApplyPeoplePhone,
  118. // 报修内容
  119. ApplyContent: req.ApplyContent,
  120. // 报修图片
  121. ApplyPic: req.ApplyPic,
  122. HouseholdUid: tokenInfo.Uid,
  123. }
  124. _, err = pb.Garden.SuggestionOrderUpdate(ctx, rpcReq)
  125. if err != nil {
  126. s, _ := json.MarshalToString(req)
  127. logger.Error("func",
  128. zap.String("call", "pb.Garden.SuggestionOrderUpdate"),
  129. zap.String("params", s),
  130. zap.String("error", err.Error()))
  131. return errors.ErrorTransForm(err)
  132. }
  133. ctx.JSON(http.StatusOK, resp)
  134. return nil
  135. }
  136. // 执行任务
  137. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  138. }
  139. //
  140. // @Summary 工单列表
  141. // @Description 工单列表
  142. // @Tags 投诉与建议
  143. // @Accept json
  144. // @Produce json
  145. // @Param token header string true "token"
  146. // @Param page query int false " "
  147. // @Param page_size query int false " "
  148. // @Param status query int false " 1未派单 2 已派单 3 已完结 "
  149. // @Param apply_people query string false "报修人"
  150. // @Param apply_people_phone query string false "报修人电话"
  151. // @Param garden_id query int true " "
  152. // @Param suggestion_type query int false "投诉类型 1 投诉 2 建议"
  153. // @Success 200 {object} v1.SuggestionOrderListResponse
  154. // @Failure 500 {object} base.HTTPError
  155. // @Router /api/v1/suggestion/order [get]
  156. func (c *Controller) SuggestionOrderList(ctx *gin.Context) {
  157. // 解析参数
  158. req := &param_v1.SuggestionOrderListRequest{}
  159. parseParamTask := func() error {
  160. err := util.ShouldBind(ctx, &req.Header, nil, &req.SuggestionOrderListQuery, nil)
  161. if err != nil {
  162. logger.Error("func",
  163. zap.String("call", "util.ShouldBind"),
  164. zap.String("error", err.Error()))
  165. return errors.ParamsError
  166. }
  167. return nil
  168. }
  169. // 业务处理
  170. handleServiceTask := func() error {
  171. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  172. if err != nil {
  173. return err
  174. }
  175. // 响应数据
  176. resp := param_v1.SuggestionOrderListResponse{}
  177. rpcReq := &v1.SuggestionOrderListRequest{
  178. GardenId: req.GardenId,
  179. PageSize: req.PageSize,
  180. Page: req.Page,
  181. SuggestionType: req.SuggestionType,
  182. ApplyPeoplePhone: req.ApplyPeoplePhone,
  183. ApplyPeople: req.ApplyPeople,
  184. Status: req.Status,
  185. HouseholdUid: tokenInfo.Uid,
  186. }
  187. rpcRsp, err := pb.Garden.SuggestionOrderList(ctx, rpcReq)
  188. if err != nil {
  189. s, _ := json.MarshalToString(req)
  190. logger.Error("func",
  191. zap.String("call", "pb.Garden.SuggestionOrderList"),
  192. zap.String("params", s),
  193. zap.String("error", err.Error()))
  194. return errors.ErrorTransForm(err)
  195. }
  196. if rpcRsp.List == nil {
  197. rpcRsp.List = make([]*v1.SuggestionOrderItem, 0)
  198. }
  199. resp.Data = *rpcRsp
  200. ctx.JSON(http.StatusOK, resp)
  201. return nil
  202. }
  203. // 执行任务
  204. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  205. }
  206. //
  207. // @Summary 工单详情
  208. // @Description 工单详情
  209. // @Tags 投诉与建议
  210. // @Accept json
  211. // @Produce json
  212. // @Param token header string true "token"
  213. // @Param id query int true " "
  214. // @Param garden_id query int true " "
  215. // @Success 200 {object} v1.SuggestionOrderInfoResponse
  216. // @Failure 500 {object} base.HTTPError
  217. // @Router /api/v1/suggestion/order/info [get]
  218. func (c *Controller) SuggestionOrderInfo(ctx *gin.Context) {
  219. // 解析参数
  220. req := &param_v1.SuggestionOrderInfoRequest{}
  221. parseParamTask := func() error {
  222. err := util.ShouldBind(ctx, &req.Header, nil, &req.SuggestionOrderInfoQuery, nil)
  223. if err != nil {
  224. logger.Error("func",
  225. zap.String("call", "util.ShouldBind"),
  226. zap.String("error", err.Error()))
  227. return errors.ParamsError
  228. }
  229. return nil
  230. }
  231. // 业务处理
  232. handleServiceTask := func() error {
  233. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  234. //if err != nil {
  235. // return err
  236. //}
  237. // 响应数据
  238. resp := param_v1.SuggestionOrderInfoResponse{}
  239. rpcReq := &v1.SuggestionOrderInfoRequest{
  240. GardenId: req.GardenId,
  241. Id: req.Id,
  242. }
  243. rpcRsp, err := pb.Garden.SuggestionOrderInfo(ctx, rpcReq)
  244. if err != nil {
  245. s, _ := json.MarshalToString(req)
  246. logger.Error("func",
  247. zap.String("call", "pb.Garden.SuggestionOrderInfo"),
  248. zap.String("params", s),
  249. zap.String("error", err.Error()))
  250. return errors.ErrorTransForm(err)
  251. }
  252. if rpcRsp.List == nil {
  253. rpcRsp.List = make([]*v1.SuggestionOrderPipelineData, 0)
  254. }
  255. resp.Data = *rpcRsp
  256. ctx.JSON(http.StatusOK, resp)
  257. return nil
  258. }
  259. // 执行任务
  260. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  261. }
  262. //
  263. // @Summary 回访
  264. // @Description 回访
  265. // @Tags 投诉与建议
  266. // @Accept json
  267. // @Produce json
  268. // @Param token header string true "token"
  269. // @Param body body v1.SuggestionOrderReturnVisitBody true "信息"
  270. // @Success 200 {object} v1.SuggestionOrderReturnVisitResponse
  271. // @Failure 500 {object} base.HTTPError
  272. // @Router /api/v1/suggestion/order/return_visit [put]
  273. func (c *Controller) SuggestionOrderReturnVisit(ctx *gin.Context) {
  274. // 解析参数
  275. req := &param_v1.SuggestionOrderReturnVisitRequest{}
  276. parseParamTask := func() error {
  277. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.SuggestionOrderReturnVisitBody)
  278. if err != nil {
  279. logger.Error("func",
  280. zap.String("call", "util.ShouldBind"),
  281. zap.String("error", err.Error()))
  282. return errors.ParamsError
  283. }
  284. return nil
  285. }
  286. // 业务处理
  287. handleServiceTask := func() error {
  288. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  289. if err != nil {
  290. return err
  291. }
  292. // 响应数据
  293. resp := param_v1.SuggestionOrderReturnVisitResponse{}
  294. rpcReq := &v1.SuggestionOrderReturnVisitRequest{
  295. GardenId: req.GardenId,
  296. Id: req.Id,
  297. ReturnVisitLevel: req.ReturnVisitLevel,
  298. ReturnVisitContent: req.ReturnVisitContent,
  299. HouseholdUid: tokenInfo.Uid,
  300. }
  301. _, err = pb.Garden.SuggestionOrderReturnVisit(ctx, rpcReq)
  302. if err != nil {
  303. s, _ := json.MarshalToString(req)
  304. logger.Error("func",
  305. zap.String("call", "pb.Garden.SuggestionOrderReturnVisit"),
  306. zap.String("params", s),
  307. zap.String("error", err.Error()))
  308. return errors.ErrorTransForm(err)
  309. }
  310. ctx.JSON(http.StatusOK, resp)
  311. return nil
  312. }
  313. // 执行任务
  314. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  315. }