123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 |
- package v1
- import (
- "fmt"
- "git.getensh.com/common/gopkgs/logger"
- "git.getensh.com/common/gopkgs/tasker/httptasker"
- "git.getensh.com/common/gopkgs/util"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- "net/http"
- "property-household-gateway/errors"
- param_v1 "property-household-gateway/param/v1"
- "property-household-gateway/pb"
- "property-household-gateway/pb/v1"
- "property-household-gateway/utils"
- )
- //
- // @Summary 门禁列表
- // @Description 门禁列表
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param garden_id query int true "小区id"
- // @Success 200 {object} v1.GateListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate [get]
- func (c *Controller) GateList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- if req.GardenId == 0 {
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateListResponse{}
- greq := &v1.GardenHouseholdUnitIdsRequest{GardenId: req.GardenId, Uids: []int64{tokenInfo.Uid}}
- greply, err := pb.Garden.GardenHouseholdUnitIds(ctx, greq)
- if err != nil {
- s, _ := json.MarshalToString(greq)
- logger.Error("func",
- zap.String("call", "Garden.GardenHouseholdUnitIds"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if len(greply.List) == 0 {
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- rpcReq := &v1.GateUnitDeviceRequest{
- GardenId: req.GardenId,
- UnitId: greply.List[0].UnitIds,
- }
- rpcRsp, err := pb.Device.GateUnitDevice(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUnitDevice"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GateItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 录入人脸
- // @Description 录入人脸
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.GateUserPicAddBody true " "
- // @Success 200 {object} v1.GateUserPicAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/face [post]
- func (c *Controller) GateUserPicAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateUserPicAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateUserPicAddBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- if req.GardenId == 0 {
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateUserPicAddResponse{}
- rpcReq := &v1.GateUserPicAddRequest{
- GardenId: req.GardenId,
- PicUrl: req.PicUrl,
- Uid: tokenInfo.Uid,
- Phone: tokenInfo.Phone,
- //todo
- IdNumber: tokenInfo.IdNumber,
- Name: tokenInfo.RealName,
- }
- _, err = pb.Device.GateUserPicAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUserPicAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 人脸信息
- // @Description 人脸信息
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param garden_id query int true "小区id"
- // @Success 200 {object} v1.GateUserPicInfoResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/face [get]
- func (c *Controller) GateUserPicInfo(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateUserPicInfoRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateUserPicInfoQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- if req.GardenId == 0 {
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateUserPicInfoResponse{}
- rpcReq := &v1.GateUserPicInfoRequest{
- GardenId: req.GardenId,
- Uid: tokenInfo.Uid,
- }
- rpcRsp, err := pb.Device.GateUserPicInfo(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUserPicInfo"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 是否有人脸设备
- // @Description 是否有人脸设备
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param garden_id query int true "小区id"
- // @Success 200 {object} v1.GateHasFaceResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/has_face_device [get]
- func (c *Controller) GateHasFace(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateHasFaceRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateHasFaceQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- if req.GardenId == 0 {
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateHasFaceResponse{}
- greq := &v1.GardenHouseholdUnitIdsRequest{GardenId: req.GardenId, Uids: []int64{tokenInfo.Uid}}
- greply, err := pb.Garden.GardenHouseholdUnitIds(ctx, greq)
- if err != nil {
- s, _ := json.MarshalToString(greq)
- logger.Error("func",
- zap.String("call", "Garden.GardenHouseholdUnitIds"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if len(greply.List) == 0 {
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- rpcReq := &v1.GateUnitDeviceRequest{
- GardenId: req.GardenId,
- UnitId: greply.List[0].UnitIds,
- OnlyHas: true,
- }
- rpcRsp, err := pb.Device.GateUnitDevice(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUnitDevice"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data.HasFaceDevice = rpcRsp.HasDevice
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 门禁二维码
- // @Description 门禁二维码
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param garden_id query int true "小区id"
- // @Success 200 {object} v1.GateQcodeResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/qcode [get]
- func (c *Controller) GateQcode(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateQcodeRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateQcodeQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- if req.GardenId == 0 {
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return errors.TokenFailedError
- }
- resp := param_v1.GateQcodeResponse{}
- rpcReq := &v1.GateQcodeRequest{
- GardenId: req.GardenId,
- Uid: tokenInfo.Uid,
- }
- rpcRsp, err := pb.Household.GateQcode(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Household.GateQcode"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 门禁访客邀约二维码
- // @Description 门禁访客邀约二维码
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param device_id query int true "设备id"
- // @Param garden_id query int true "小区id"
- // @Param start query int true "开始时间戳"
- // @Param end query int true "截止时间戳"
- // @Param visitor_name query string true "访客姓名"
- // @Param visitor_phone query string true "访客联系方式"
- // @Param comment query string true "访问是由"
- // @Success 200 {object} v1.GateQcodeVisitorResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/qcode_visitor [get]
- func (c *Controller) GateQcodeVisitor(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateQcodeVisitorRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateQcodeVisitorQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- if req.GardenId == 0 {
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return errors.TokenFailedError
- }
- resp := param_v1.GateQcodeVisitorResponse{}
- rpcReq := &v1.GateQcodeRequest{
- GardenId: req.GardenId,
- DeviceId: req.DeviceId,
- Uid: tokenInfo.Uid,
- Visitor: true,
- VisitorStart: req.Start,
- VisitorEnd: req.End,
- VisitorName: req.VisitorName,
- VisitorPhone: req.VisitorPhone,
- UserName: tokenInfo.RealName,
- Phone: tokenInfo.Phone,
- Comment: req.Comment,
- }
- rpcRsp, err := pb.Household.GateQcode(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Household.GateQcode"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 我的邀约
- // @Description 我的邀约
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param gate_id query int false "门禁id选填"
- // @Success 200 {object} v1.GateVisitorListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/visitor [get]
- func (c *Controller) GateVisitorList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateVisitorListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateVisitorListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateVisitorListResponse{}
- rpcReq := &v1.GateVisitorListRequest{
- Page: req.Page,
- PageSize: req.PageSize,
- DeviceId: req.GateId,
- Uid: tokenInfo.Uid,
- }
- fmt.Printf("token:%v\n", tokenInfo.Uid)
- rpcRsp, err := pb.Device.GateVisitorList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateVisitorList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GateVisitorListItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 删除访客记录
- // @Description 删除访客记录
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param id query int true " 记录id"
- // @Success 200 {object} v1.GateVisitorDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/visitor [delete]
- func (c *Controller) GateVisitorDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateVisitorDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateVisitorDelQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateVisitorDelResponse{}
- rpcReq := &v1.GateVisitorDelRequest{
- Id: req.Id,
- Uid: tokenInfo.Uid,
- }
- _, err = pb.Device.GateVisitorDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateVisitorDel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 访客获取到的分享页面
- // @Description 访客获取到的分享页面
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param id query int true " 访客邀约记录id"
- // @Success 200 {object} v1.GateVisitorPageResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/visitor/share [get]
- func (c *Controller) GateVisitorPage(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateVisitorPageRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GateVisitorPageQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- resp := param_v1.GateVisitorPageResponse{}
- rpcReq := &v1.GateVisitorListRequest{
- Id: req.Id,
- }
- rpcRsp, err := pb.Device.GateVisitorList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateVisitorList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if len(rpcRsp.List) == 0 {
- return errors.ErrRecordNotFound
- }
- resp.Data = *rpcRsp.List[0]
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|