household.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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-system-gateway/errors"
  10. param_v1 "property-system-gateway/param/v1"
  11. "property-system-gateway/pb"
  12. "property-system-gateway/pb/v1"
  13. "property-system-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.HouseholdApproveBody true "信息"
  23. // @Success 200 {object} v1.HouseholdApproveResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/household/approve [put]
  26. func (c *Controller) HouseholdApprove(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.HouseholdApproveRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseholdApproveBody)
  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.GetSubjectValue(ctx)
  42. if err != nil {
  43. return err
  44. }
  45. // 响应数据
  46. resp := param_v1.HouseholdApproveResponse{}
  47. rpcReq := &v1.HouseholdApproveRequest{
  48. Id: req.Id,
  49. Status: req.Status,
  50. Feedback: req.Feedback,
  51. }
  52. _, err = pb.Household.HouseholdApprove(ctx, rpcReq)
  53. if err != nil {
  54. s, _ := json.MarshalToString(req)
  55. logger.Error("func",
  56. zap.String("call", "pb.Household.HouseholdApprove"),
  57. zap.String("params", s),
  58. zap.String("error", err.Error()))
  59. return errors.ErrorTransForm(err)
  60. }
  61. ctx.JSON(http.StatusOK, resp)
  62. logReq := OperationLogRequest{
  63. Module: ModuleHousehold,
  64. Action: ActionHouseholdApprove,
  65. Origin: "",
  66. Target: req.HouseholdApproveBody,
  67. UserName: tokenInfo.UserName,
  68. Uid: tokenInfo.Uid,
  69. Cid: tokenInfo.Cid,
  70. GardenId: tokenInfo.GardenId,
  71. }
  72. go OperationLogAdd(&logReq)
  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 user_type query int false "业主身份类型"
  86. // @Param page query int false " "
  87. // @Param page_size query int false " "
  88. // @Param name query string false "业主姓名"
  89. // @Param approve_status query int false "0 未审核+未通过 1 未审核 2 已通过 3 未通过"
  90. // @Success 200 {object} v1.HouseholdListResponse
  91. // @Failure 500 {object} base.HTTPError
  92. // @Router /api/v1/household/list [get]
  93. func (c *Controller) HouseholdList(ctx *gin.Context) {
  94. // 解析参数
  95. req := &param_v1.HouseholdListRequest{}
  96. parseParamTask := func() error {
  97. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseholdListQuery, nil)
  98. if err != nil {
  99. logger.Error("func",
  100. zap.String("call", "util.ShouldBind"),
  101. zap.String("error", err.Error()))
  102. return errors.ParamsError
  103. }
  104. return nil
  105. }
  106. // 业务处理
  107. handleServiceTask := func() error {
  108. tokenInfo, err := utils.GetSubjectValue(ctx)
  109. if err != nil {
  110. return err
  111. }
  112. // 响应数据
  113. resp := param_v1.HouseholdListResponse{}
  114. if req.ApproveStatus == 2 {
  115. rpcReq := &v1.GardenHouseholdListRequest{
  116. GardenId: tokenInfo.GardenId,
  117. Name: req.Name,
  118. UserType: req.UserType,
  119. PageSize: req.PageSize,
  120. Page: req.Page,
  121. }
  122. rpcRsp, err := pb.Garden.GardenHouseholdList(ctx, rpcReq)
  123. if err != nil {
  124. s, _ := json.MarshalToString(req)
  125. logger.Error("func",
  126. zap.String("call", "pb.Household.HouseholdList"),
  127. zap.String("params", s),
  128. zap.String("error", err.Error()))
  129. return errors.ErrorTransForm(err)
  130. }
  131. if rpcRsp.List == nil {
  132. rpcRsp.List = make([]*v1.GardenHouseholdItem, 0)
  133. }
  134. data := v1.HouseholdListReply{}
  135. data.Page = rpcRsp.Page
  136. data.Total = rpcRsp.Total
  137. data.List = make([]*v1.HouseholdItem, len(rpcRsp.List))
  138. for i, v := range rpcRsp.List {
  139. if v.Appendix == nil {
  140. v.Appendix = make([]string, 0)
  141. }
  142. data.List[i] = &v1.HouseholdItem{
  143. Id: v.Id,
  144. // 1业主 2家人 3租客
  145. UserType: v.UserType,
  146. Phone: v.Phone,
  147. Name: v.Name,
  148. Appendix: v.Appendix,
  149. // 1 身份证 2 护照
  150. IdType: v.IdType,
  151. // 证件号
  152. IdNumber: v.IdNumber,
  153. // 房号
  154. HouseName: v.HouseName,
  155. ApproveStatus: v.ApproveStatus,
  156. GardenName: v.GardenName,
  157. HouseId: v.HouseId,
  158. Uid: v.Uid,
  159. }
  160. }
  161. resp.Data = data
  162. ctx.JSON(http.StatusOK, resp)
  163. return nil
  164. }
  165. rpcReq := &v1.HouseholdListRequest{
  166. GardenId: tokenInfo.GardenId,
  167. Name: req.Name,
  168. UserType: req.UserType,
  169. ApproveStatus: req.ApproveStatus,
  170. PageSize: req.PageSize,
  171. Page: req.Page,
  172. }
  173. rpcRsp, err := pb.Household.HouseholdList(ctx, rpcReq)
  174. if err != nil {
  175. s, _ := json.MarshalToString(req)
  176. logger.Error("func",
  177. zap.String("call", "pb.Household.HouseholdList"),
  178. zap.String("params", s),
  179. zap.String("error", err.Error()))
  180. return errors.ErrorTransForm(err)
  181. }
  182. if rpcRsp.List == nil {
  183. rpcRsp.List = make([]*v1.HouseholdItem, 0)
  184. }
  185. for i, _ := range rpcRsp.List {
  186. if rpcRsp.List[i].Appendix == nil {
  187. rpcRsp.List[i].Appendix = make([]string, 0)
  188. }
  189. }
  190. resp.Data = *rpcRsp
  191. ctx.JSON(http.StatusOK, resp)
  192. return nil
  193. }
  194. // 执行任务
  195. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  196. }
  197. //
  198. // @Summary 业主信息
  199. // @Description 业主信息
  200. // @Tags 业主管理
  201. // @Accept json
  202. // @Produce json
  203. // @Param token header string true "token"
  204. // @Param user_type query int false "业主身份类型"
  205. // @Param page query int false " "
  206. // @Param page_size query int false " "
  207. // @Param name query string false "业主姓名"
  208. // @Param house_id query int false "房屋id"
  209. // @Param building_id query int false "楼栋id"
  210. // @Param unit_id query int false "单元id"
  211. // @Param gate_id query string false "门禁设备id"
  212. // @Success 200 {object} v1.HouseholdListResponse
  213. // @Failure 500 {object} base.HTTPError
  214. // @Router /api/v1/household/user_list [get]
  215. func (c *Controller) HouseholdUserList(ctx *gin.Context) {
  216. // 解析参数
  217. req := &param_v1.HouseholdUserListRequest{}
  218. parseParamTask := func() error {
  219. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseholdUserListQuery, nil)
  220. if err != nil {
  221. logger.Error("func",
  222. zap.String("call", "util.ShouldBind"),
  223. zap.String("error", err.Error()))
  224. return errors.ParamsError
  225. }
  226. return nil
  227. }
  228. // 业务处理
  229. handleServiceTask := func() error {
  230. tokenInfo, err := utils.GetSubjectValue(ctx)
  231. if err != nil {
  232. return err
  233. }
  234. excludeUids := []int64{}
  235. if req.GateId != "" {
  236. /*mReq := &v1.GateWhiteHouseholdListRequest{
  237. Page: -1,
  238. PageSize: -1,
  239. DeviceId: req.GateId,
  240. GardenId: tokenInfo.GardenId,
  241. }
  242. mRsp, err := pb.Device.GateWhiteHouseholdList(ctx, mReq)
  243. if err != nil {
  244. s, _ := json.MarshalToString(req)
  245. logger.Error("func",
  246. zap.String("call", "Device.GateWhiteHouseholdList"),
  247. zap.String("params", s),
  248. zap.String("error", err.Error()))
  249. return errors.ErrorTransForm(err)
  250. }
  251. for _, v := range mRsp.List {
  252. excludeUids = append(excludeUids, v.HouseholdUid)
  253. }*/
  254. }
  255. // 响应数据
  256. resp := param_v1.HouseholdUserListResponse{}
  257. rpcReq := &v1.GardenHouseholdUserListRequest{
  258. GardenId: tokenInfo.GardenId,
  259. Name: req.Name,
  260. UserType: req.UserType,
  261. PageSize: req.PageSize,
  262. Page: req.Page,
  263. HouseId: req.HouseId,
  264. ExcludeUids: excludeUids,
  265. BuildingId: req.BuildingId,
  266. UnitId: req.UnitId,
  267. Phone: req.Phone,
  268. }
  269. rpcRsp, err := pb.Garden.GardenHouseholdUserList(ctx, rpcReq)
  270. if err != nil {
  271. s, _ := json.MarshalToString(req)
  272. logger.Error("func",
  273. zap.String("call", "pb.Garden.GardenHouseholdUserList"),
  274. zap.String("params", s),
  275. zap.String("error", err.Error()))
  276. return errors.ErrorTransForm(err)
  277. }
  278. if rpcRsp.List == nil {
  279. rpcRsp.List = make([]*v1.GardenHouseholdUserItem, 0)
  280. }
  281. resp.Data = *rpcRsp
  282. ctx.JSON(http.StatusOK, resp)
  283. return nil
  284. }
  285. // 执行任务
  286. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  287. }