repair.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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 page query int false " "
  23. // @Param page_size query int false " "
  24. // @Param garden_id query int true " "
  25. // @Param area query int false " 1 公区 2 室内"
  26. // @Success 200 {object} v1.RepairClassListResponse
  27. // @Failure 500 {object} base.HTTPError
  28. // @Router /api/v1/repair/class [get]
  29. func (c *Controller) RepairClassList(ctx *gin.Context) {
  30. // 解析参数
  31. req := &param_v1.RepairClassListRequest{}
  32. parseParamTask := func() error {
  33. err := util.ShouldBind(ctx, &req.Header, nil, &req.RepairClassListQuery, nil)
  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.GetJwtTokenInfo(ctx)
  45. //if err != nil {
  46. // return err
  47. //}
  48. // 响应数据
  49. resp := param_v1.RepairClassListResponse{}
  50. rpcReq := &v1.RepairClassListRequest{
  51. GardenId: req.GardenId,
  52. PageSize: req.PageSize,
  53. Page: req.Page,
  54. Area: req.Area,
  55. }
  56. rpcRsp, err := pb.Garden.RepairClassList(ctx, rpcReq)
  57. if err != nil {
  58. s, _ := json.MarshalToString(req)
  59. logger.Error("func",
  60. zap.String("call", "pb.Garden.RepairClassList"),
  61. zap.String("params", s),
  62. zap.String("error", err.Error()))
  63. return errors.ErrorTransForm(err)
  64. }
  65. if rpcRsp.List == nil {
  66. rpcRsp.List = make([]*v1.RepairClassItem, 0)
  67. }
  68. resp.Data = *rpcRsp
  69. ctx.JSON(http.StatusOK, resp)
  70. return nil
  71. }
  72. // 执行任务
  73. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  74. }
  75. //
  76. // @Summary 新增工单
  77. // @Description 新增工单
  78. // @Tags 报事报修
  79. // @Accept json
  80. // @Produce json
  81. // @Param token header string true "token"
  82. // @Param body body v1.RepairOrderAddBody true "信息"
  83. // @Success 200 {object} v1.RepairOrderAddResponse
  84. // @Failure 500 {object} base.HTTPError
  85. // @Router /api/v1/repair/order [post]
  86. func (c *Controller) RepairOrderAdd(ctx *gin.Context) {
  87. // 解析参数
  88. req := &param_v1.RepairOrderAddRequest{}
  89. parseParamTask := func() error {
  90. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.RepairOrderAddBody)
  91. if err != nil {
  92. logger.Error("func",
  93. zap.String("call", "util.ShouldBind"),
  94. zap.String("error", err.Error()))
  95. return errors.ParamsError
  96. }
  97. return nil
  98. }
  99. // 业务处理
  100. handleServiceTask := func() error {
  101. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  102. if err != nil {
  103. return err
  104. }
  105. // 响应数据
  106. resp := param_v1.RepairOrderAddResponse{}
  107. rpcReq := &v1.RepairOrderAddRequest{
  108. GardenId: req.GardenId,
  109. // 分类id
  110. ClassId: req.ClassId,
  111. // 报修人
  112. ApplyPeople: req.ApplyPeople,
  113. // 报修人电话
  114. ApplyPeoplePhone: req.ApplyPeoplePhone,
  115. // 预约时间
  116. Appointment: req.Appointment,
  117. // 房屋id
  118. HouseId: req.HouseId,
  119. // 上级处理人
  120. //LastUid:tokenInfo.Uid,
  121. // 报修内容
  122. ApplyContent: req.ApplyContent,
  123. // 报修图片
  124. ApplyPic: req.ApplyPic,
  125. HouseholdUid: tokenInfo.Uid,
  126. }
  127. rpcRsp, err := pb.Garden.RepairOrderAdd(ctx, rpcReq)
  128. if err != nil {
  129. s, _ := json.MarshalToString(req)
  130. logger.Error("func",
  131. zap.String("call", "pb.Garden.RepairOrderAdd"),
  132. zap.String("params", s),
  133. zap.String("error", err.Error()))
  134. return errors.ErrorTransForm(err)
  135. }
  136. resp.Data = *rpcRsp
  137. ctx.JSON(http.StatusOK, resp)
  138. return nil
  139. }
  140. // 执行任务
  141. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  142. }
  143. //
  144. // @Summary 修改工单
  145. // @Description 修改工单
  146. // @Tags 报事报修
  147. // @Accept json
  148. // @Produce json
  149. // @Param token header string true "token"
  150. // @Param body body v1.RepairOrderUpdateBody true "信息"
  151. // @Success 200 {object} v1.RepairOrderUpdateResponse
  152. // @Failure 500 {object} base.HTTPError
  153. // @Router /api/v1/repair/order [put]
  154. func (c *Controller) RepairOrderUpdate(ctx *gin.Context) {
  155. // 解析参数
  156. req := &param_v1.RepairOrderUpdateRequest{}
  157. parseParamTask := func() error {
  158. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.RepairOrderUpdateBody)
  159. if err != nil {
  160. logger.Error("func",
  161. zap.String("call", "util.ShouldBind"),
  162. zap.String("error", err.Error()))
  163. return errors.ParamsError
  164. }
  165. return nil
  166. }
  167. // 业务处理
  168. handleServiceTask := func() error {
  169. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  170. if err != nil {
  171. return err
  172. }
  173. // 响应数据
  174. resp := param_v1.RepairOrderUpdateResponse{}
  175. rpcReq := &v1.RepairOrderUpdateRequest{
  176. GardenId: req.GardenId,
  177. Id: req.Id,
  178. // 分类id
  179. ClassId: req.ClassId,
  180. // 报修人
  181. ApplyPeople: req.ApplyPeople,
  182. // 报修人电话
  183. ApplyPeoplePhone: req.ApplyPeoplePhone,
  184. // 预约时间
  185. Appointment: req.Appointment,
  186. // 房屋id
  187. HouseId: req.HouseId,
  188. // 报修内容
  189. ApplyContent: req.ApplyContent,
  190. // 报修图片
  191. ApplyPic: req.ApplyPic,
  192. HouseholdUid: tokenInfo.Uid,
  193. }
  194. _, err = pb.Garden.RepairOrderUpdate(ctx, rpcReq)
  195. if err != nil {
  196. s, _ := json.MarshalToString(req)
  197. logger.Error("func",
  198. zap.String("call", "pb.Garden.RepairOrderUpdate"),
  199. zap.String("params", s),
  200. zap.String("error", err.Error()))
  201. return errors.ErrorTransForm(err)
  202. }
  203. ctx.JSON(http.StatusOK, resp)
  204. return nil
  205. }
  206. // 执行任务
  207. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  208. }
  209. //
  210. // @Summary 工单列表
  211. // @Description 工单列表
  212. // @Tags 报事报修
  213. // @Accept json
  214. // @Produce json
  215. // @Param token header string true "token"
  216. // @Param page query int false " "
  217. // @Param page_size query int false " "
  218. // @Param status query int false " 1未派单 2 已派单 3 已完结 "
  219. // @Param apply_people query string false "报修人"
  220. // @Param apply_people_phone query string false "报修人电话"
  221. // @Param garden_id query int true " "
  222. // @Param class_id query int false "分类id"
  223. // @Success 200 {object} v1.RepairOrderListResponse
  224. // @Failure 500 {object} base.HTTPError
  225. // @Router /api/v1/repair/order [get]
  226. func (c *Controller) RepairOrderList(ctx *gin.Context) {
  227. // 解析参数
  228. req := &param_v1.RepairOrderListRequest{}
  229. parseParamTask := func() error {
  230. err := util.ShouldBind(ctx, &req.Header, nil, &req.RepairOrderListQuery, nil)
  231. if err != nil {
  232. logger.Error("func",
  233. zap.String("call", "util.ShouldBind"),
  234. zap.String("error", err.Error()))
  235. return errors.ParamsError
  236. }
  237. return nil
  238. }
  239. // 业务处理
  240. handleServiceTask := func() error {
  241. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  242. if err != nil {
  243. return err
  244. }
  245. // 响应数据
  246. resp := param_v1.RepairOrderListResponse{}
  247. rpcReq := &v1.RepairOrderListRequest{
  248. GardenId: req.GardenId,
  249. PageSize: req.PageSize,
  250. Page: req.Page,
  251. ClassId: req.ClassId,
  252. ApplyPeoplePhone: req.ApplyPeoplePhone,
  253. ApplyPeople: req.ApplyPeople,
  254. Status: req.Status,
  255. HouseholdUid: tokenInfo.Uid,
  256. }
  257. rpcRsp, err := pb.Garden.RepairOrderList(ctx, rpcReq)
  258. if err != nil {
  259. s, _ := json.MarshalToString(req)
  260. logger.Error("func",
  261. zap.String("call", "pb.Garden.RepairOrderList"),
  262. zap.String("params", s),
  263. zap.String("error", err.Error()))
  264. return errors.ErrorTransForm(err)
  265. }
  266. if rpcRsp.List == nil {
  267. rpcRsp.List = make([]*v1.RepairOrderItem, 0)
  268. }
  269. resp.Data = *rpcRsp
  270. ctx.JSON(http.StatusOK, resp)
  271. return nil
  272. }
  273. // 执行任务
  274. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  275. }
  276. //
  277. // @Summary 工单详情
  278. // @Description 工单详情
  279. // @Tags 报事报修
  280. // @Accept json
  281. // @Produce json
  282. // @Param token header string true "token"
  283. // @Param id query int true " "
  284. // @Param garden_id query int true " "
  285. // @Success 200 {object} v1.RepairOrderInfoResponse
  286. // @Failure 500 {object} base.HTTPError
  287. // @Router /api/v1/repair/order/info [get]
  288. func (c *Controller) RepairOrderInfo(ctx *gin.Context) {
  289. // 解析参数
  290. req := &param_v1.RepairOrderInfoRequest{}
  291. parseParamTask := func() error {
  292. err := util.ShouldBind(ctx, &req.Header, nil, &req.RepairOrderInfoQuery, nil)
  293. if err != nil {
  294. logger.Error("func",
  295. zap.String("call", "util.ShouldBind"),
  296. zap.String("error", err.Error()))
  297. return errors.ParamsError
  298. }
  299. return nil
  300. }
  301. // 业务处理
  302. handleServiceTask := func() error {
  303. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  304. //if err != nil {
  305. // return err
  306. //}
  307. // 响应数据
  308. resp := param_v1.RepairOrderInfoResponse{}
  309. rpcReq := &v1.RepairOrderInfoRequest{
  310. GardenId: req.GardenId,
  311. Id: req.Id,
  312. }
  313. rpcRsp, err := pb.Garden.RepairOrderInfo(ctx, rpcReq)
  314. if err != nil {
  315. s, _ := json.MarshalToString(req)
  316. logger.Error("func",
  317. zap.String("call", "pb.Garden.RepairOrderInfo"),
  318. zap.String("params", s),
  319. zap.String("error", err.Error()))
  320. return errors.ErrorTransForm(err)
  321. }
  322. if rpcRsp.List == nil {
  323. rpcRsp.List = make([]*v1.RepairOrderPipelineData, 0)
  324. }
  325. resp.Data = *rpcRsp
  326. ctx.JSON(http.StatusOK, resp)
  327. return nil
  328. }
  329. // 执行任务
  330. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  331. }
  332. //
  333. // @Summary 回访
  334. // @Description 回访
  335. // @Tags 报事报修
  336. // @Accept json
  337. // @Produce json
  338. // @Param token header string true "token"
  339. // @Param body body v1.RepairOrderReturnVisitBody true "信息"
  340. // @Success 200 {object} v1.RepairOrderReturnVisitResponse
  341. // @Failure 500 {object} base.HTTPError
  342. // @Router /api/v1/repair/order/return_visit [put]
  343. func (c *Controller) RepairOrderReturnVisit(ctx *gin.Context) {
  344. // 解析参数
  345. req := &param_v1.RepairOrderReturnVisitRequest{}
  346. parseParamTask := func() error {
  347. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.RepairOrderReturnVisitBody)
  348. if err != nil {
  349. logger.Error("func",
  350. zap.String("call", "util.ShouldBind"),
  351. zap.String("error", err.Error()))
  352. return errors.ParamsError
  353. }
  354. return nil
  355. }
  356. // 业务处理
  357. handleServiceTask := func() error {
  358. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  359. if err != nil {
  360. return err
  361. }
  362. // 响应数据
  363. resp := param_v1.RepairOrderReturnVisitResponse{}
  364. rpcReq := &v1.RepairOrderReturnVisitRequest{
  365. GardenId: req.GardenId,
  366. Id: req.Id,
  367. ReturnVisitLevel: req.ReturnVisitLevel,
  368. ReturnVisitContent: req.ReturnVisitContent,
  369. HouseholdUid: tokenInfo.Uid,
  370. }
  371. _, err = pb.Garden.RepairOrderReturnVisit(ctx, rpcReq)
  372. if err != nil {
  373. s, _ := json.MarshalToString(req)
  374. logger.Error("func",
  375. zap.String("call", "pb.Garden.RepairOrderReturnVisit"),
  376. zap.String("params", s),
  377. zap.String("error", err.Error()))
  378. return errors.ErrorTransForm(err)
  379. }
  380. ctx.JSON(http.StatusOK, resp)
  381. return nil
  382. }
  383. // 执行任务
  384. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  385. }