123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236 |
- package v1
- import (
- "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-system-gateway/errors"
- param_v1 "property-system-gateway/param/v1"
- "property-system-gateway/pb"
- "property-system-gateway/pb/v1"
- "property-system-gateway/utils"
- "sort"
- )
- //
- // @Summary 门禁单元列表
- // @Description 门禁单元列表
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param device_id query int true "设备id"
- // @Success 200 {object} v1.GateListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/unit [get]
- func (c *Controller) GateUnitList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateUnitListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateUnitListQuery, 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- greq := &v1.UnitListRequest{GardenId: tokenInfo.GardenId, Page: -1, PageSize: -1}
- greply, err := pb.Garden.UnitList(ctx, greq)
- if err != nil {
- s, _ := json.MarshalToString(greq)
- logger.Error("func",
- zap.String("call", "Device.UnitList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp := param_v1.GateUnitListResponse{}
- rpcReq := &v1.GateUnitListRequest{
- GardenId: tokenInfo.GardenId,
- DeviceId: req.DeviceId,
- }
- rpcRsp, err := pb.Device.GateUnitList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUnitList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- // 记录已添加的单元
- selected := map[int64]bool{}
- for _, v := range rpcRsp.UnitId {
- selected[v] = true
- }
- // 解析为返回的格式
- buildingM := map[int64][]param_v1.GateUnitBuildingUnitItem{}
- buildingInfoM := map[int64]param_v1.GateUnitBuildingItem{}
- for _, v := range greply.List {
- buildingInfoM[v.BuildingId] = param_v1.GateUnitBuildingItem{
- BuildingNumber: v.BuildingNumber,
- BuildingName: v.BuildingName,
- }
- unitItem := param_v1.GateUnitBuildingUnitItem{
- UnitId: v.Id,
- UnitNumber: v.UnitNumber,
- UnitName: v.UnitName,
- Selected: selected[v.Id],
- }
- buildingM[v.BuildingId] = append(buildingM[v.BuildingId], unitItem)
- }
- // 填充返回字段
- resp.Data.List = make([]param_v1.GateUnitBuildingItem, len(buildingInfoM))
- i := 0
- for buildingId, binfo := range buildingInfoM {
- resp.Data.List[i] = binfo
- resp.Data.List[i].Units = buildingM[buildingId]
- i++
- }
- // 按编号排序
- for k, _ := range resp.Data.List {
- sort.Slice(resp.Data.List[k].Units, func(i int, j int) bool {
- return resp.Data.List[k].Units[i].UnitNumber < resp.Data.List[k].Units[j].UnitNumber
- })
- }
- sort.Slice(resp.Data.List, func(i int, j int) bool { return resp.Data.List[i].BuildingNumber < resp.Data.List[j].BuildingNumber })
- 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.GateUnitAddBody true " "
- // @Success 200 {object} v1.GateUnitAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/unit [post]
- func (c *Controller) GateUnitAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateUnitAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateUnitAddBody)
- 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateUnitAddResponse{}
- rpcReq := &v1.GateUnitAddRequest{
- GardenId: tokenInfo.GardenId,
- DeviceId: req.DeviceId,
- UnitId: req.UnitIds,
- }
- _, err = pb.Device.GateUnitAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUnitAdd"),
- 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 body body v1.GateCardSyncBody true " "
- // @Success 200 {object} v1.GateCardSyncResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/card [put]
- func (c *Controller) GateCardSync(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateCardSyncRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateCardSyncBody)
- 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateCardSyncResponse{}
- rpcReq := &v1.GateCardSyncRequest{
- GardenId: tokenInfo.GardenId,
- Id: req.Id,
- }
- _, err = pb.Device.GateCardSync(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateCardSync"),
- 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 id query int true "卡记录id"
- // @Success 200 {object} v1.GateCardDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/card [delete]
- func (c *Controller) GateCardDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateCardDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateCardDelQuery, 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateCardDelResponse{}
- rpcReq := &v1.GateCardDelRequest{
- GardenId: tokenInfo.GardenId,
- Id: req.Id,
- }
- _, err = pb.Device.GateCardDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateCardDel"),
- 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 body body v1.GateCardAddBody true " "
- // @Success 200 {object} v1.GateCardAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/card [post]
- func (c *Controller) GateCardAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateCardAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateCardAddBody)
- 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateCardAddResponse{}
- rpcReq := &v1.GateCardAddRequest{
- GardenId: tokenInfo.GardenId,
- CardNumber: req.CardNumber,
- Name: req.Name,
- DeviceIds: req.DeviceIds,
- }
- _, err = pb.Device.GateCardAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateCardAdd"),
- 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 page query int false " "
- // @Param page_size query int false " "
- // @Param name query string false "姓名"
- // @Param down_status query int false "下发状态 0 不过滤 1 待下发 2 下发成功 3 下发失败"
- // @Success 200 {object} v1.GateCardListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/card [get]
- func (c *Controller) GateCardList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateCardListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateCardListQuery, 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateCardListResponse{}
- rpcReq := &v1.GateCardListRequest{
- Page: req.Page,
- PageSize: req.PageSize,
- GardenId: tokenInfo.GardenId,
- Name: req.Name,
- DownStatus: req.DownStatus,
- }
- rpcRsp, err := pb.Device.GateCardList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateCardList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GateCardItem, 0)
- }
- for i, v := range rpcRsp.List {
- if v.GatePermissions == nil {
- rpcRsp.List[i].GatePermissions = make([]*v1.GateCardDevice, 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 card_number query string true "卡号"
- // @Success 200 {object} v1.GateCardCanBindDevicesResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/card/devices [get]
- func (c *Controller) GateCardCanBindDevices(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateCardCanBindDevicesRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateCardCanBindDevicesQuery, 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateCardCanBindDevicesResponse{}
- rpcReq := &v1.GateCardCanBindDevicesRequest{
- GardenId: tokenInfo.GardenId,
- CardNumber: req.CardNumber,
- }
- rpcRsp, err := pb.Device.GateCardCanBindDevices(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateCardCanBindDevices"),
- 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.GateUserPicSyncBody true " "
- // @Success 200 {object} v1.GateUserPicSyncResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/pic [put]
- func (c *Controller) GateUserPicSync(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateUserPicSyncRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateUserPicSyncBody)
- 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateUserPicSyncResponse{}
- rpcReq := &v1.GateUserPicSyncRequest{
- GardenId: tokenInfo.GardenId,
- Id: req.Id,
- }
- _, err = pb.Device.GateUserPicSync(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUserPicSync"),
- 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 id query int true "人脸记录id"
- // @Success 200 {object} v1.GateUserPicDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/pic [delete]
- func (c *Controller) GateUserPicDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateUserPicDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateUserPicDelQuery, 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateUserPicDelResponse{}
- rpcReq := &v1.GateUserPicDelRequest{
- GardenId: tokenInfo.GardenId,
- Id: req.Id,
- }
- _, err = pb.Device.GateUserPicDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUserPicDel"),
- 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 body body v1.GateUserPicApproveBody true " "
- // @Success 200 {object} v1.GateUserPicApproveResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/pic/approve [put]
- func (c *Controller) GateUserPicApprove(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateUserPicApproveRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateUserPicApproveBody)
- 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateUserPicApproveResponse{}
- rpcReq := &v1.GateUserPicApproveRequest{
- GardenId: tokenInfo.GardenId,
- Id: req.Id,
- Status: req.Status,
- }
- _, err = pb.Device.GateUserPicApprove(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUserPicApprove"),
- 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 page query int false " "
- // @Param page_size query int false " "
- // @Param name query string false "姓名"
- // @Param down_status query int false "下发状态 0 不过滤 1 待下发 2 下发成功 3 下发失败"
- // @Success 200 {object} v1.GateUserPicListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/pic [get]
- func (c *Controller) GateUserPicList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateUserPicListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateUserPicListQuery, 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateUserPicListResponse{}
- rpcReq := &v1.GateUserPicListRequest{
- Page: req.Page,
- PageSize: req.PageSize,
- GardenId: tokenInfo.GardenId,
- Name: req.Name,
- DownStatus: req.DownStatus,
- }
- rpcRsp, err := pb.Device.GateUserPicList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateUserPicList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GateUserPicItem, 0)
- }
- for i, v := range rpcRsp.List {
- if v.GatePermissions == nil {
- rpcRsp.List[i].GatePermissions = make([]*v1.GateUserPicDevice, 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 page query int false " "
- // @Param page_size query int false " "
- // @Param device_name query string false "设备名"
- // @Param manufactor query string false "厂商"
- // @Param sn query string false "序列号"
- // @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
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateListResponse{}
- rpcReq := &v1.GateListRequest{
- Page: req.Page,
- PageSize: req.PageSize,
- GardenId: tokenInfo.GardenId,
- Sn: req.Sn,
- DeviceName: req.DeviceName,
- Manufactor: req.Manufactor,
- }
- rpcRsp, err := pb.Device.GateList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateList"),
- 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.GateEnableBody true " "
- // @Success 200 {object} v1.GateEnableResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/enable [put]
- func (c *Controller) GateEnable(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateEnableRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateEnableBody)
- 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateEnableResponse{}
- rpcReq := &v1.GateEnableRequest{
- DeviceId: req.DeviceId,
- Enable: req.Enable,
- GardenId: tokenInfo.GardenId,
- }
- _, err = pb.Device.GateEnable(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Device.GateEnable"),
- 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 body body v1.GateSetBody true " "
- // @Success 200 {object} v1.GateSetResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/set [put]
- func (c *Controller) GateSet(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateSetRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateSetBody)
- 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GateSetResponse{}
- rpcReq := &v1.GateSetRequest{
- DeviceId: req.DeviceId,
- GardenId: tokenInfo.GardenId,
- Location: req.Location,
- Direction: req.Direction,
- GateName: req.GateName,
- Ip: req.Ip,
- Mac: req.Mac,
- UserName: req.User,
- Password: req.Password,
- }
- _, err = pb.Device.GateSet(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Device.GateSet"),
- 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 page query int false " "
- // @Param page_size query int false " "
- // @Param device_id query int true "设备id"
- // @Success 200 {object} v1.GateCommandListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/command [get]
- func (c *Controller) GateCommandList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateCommandListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateCommandListQuery, 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.GateCommandListResponse{}
- rpcReq := &v1.GateCommandListRequest{
- Page: req.Page,
- PageSize: req.PageSize,
- DeviceId: req.DeviceId,
- }
- rpcRsp, err := pb.Device.GateCommandList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateCommandList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GateCommandItem, 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.GateOpenBody true " "
- // @Success 200 {object} v1.GateOpenResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/command/open [post]
- func (c *Controller) GateOpen(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateOpenRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateOpenBody)
- 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.GateOpenResponse{}
- rpcReq := &v1.GateCommandAddRequest{
- DeviceId: req.DeviceId,
- CmdCode: 1,
- }
- _, err := pb.Device.GateCommandAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(rpcReq)
- logger.Error("func",
- zap.String("call", "pb.GateCommandAdd"),
- 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 body body v1.GateRestartBody true " "
- // @Success 200 {object} v1.GateRestartResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/command/restart [post]
- func (c *Controller) GateRestart(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateRestartRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateRestartBody)
- 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.GateRestartResponse{}
- rpcReq := &v1.GateCommandAddRequest{
- DeviceId: req.DeviceId,
- CmdCode: 2,
- }
- _, err := pb.Device.GateCommandAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(rpcReq)
- logger.Error("func",
- zap.String("call", "pb.GateCommandAdd"),
- 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 page query int false " "
- // @Param page_size query int false " "
- // @Param device_id query string false "设备id必传"
- // @Param start query int false "开始时间"
- // @Param end query int false "结束时间"
- // @Param is_visitor query int false "0不过滤 1 访客 2 非访客"
- // @Success 200 {object} v1.GateRecordListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/record [get]
- func (c *Controller) GateRecordList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateRecordListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateRecordListQuery, 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.GetSubjectValue(ctx)
- //if err != nil {
- // return err
- //}
- resp := param_v1.GateRecordListResponse{}
- rpcReq := &v1.GateRecordListRequest{
- Page: req.Page,
- PageSize: req.PageSize,
- DeviceId: req.DeviceId,
- Start: req.Start,
- End: req.End,
- IsVisitor: req.IsVisitor,
- }
- rpcRsp, err := pb.Device.GateRecordList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateRecordList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GateRecordItem, 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 page query int false " "
- // @Param page_size query int false " "
- // @Param gate_id query int64 false "门禁id必传"
- // @Param start query int false "开始时间"
- // @Param end query int false "结束时间"
- // @Param user query string false "邀请人"
- // @Param visitor query string false "被邀请人"
- // @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.GetSubjectValue(ctx)
- //if err != nil {
- // return err
- //}
- resp := param_v1.GateVisitorListResponse{}
- rpcReq := &v1.GateVisitorListRequest{
- Page: req.Page,
- PageSize: req.PageSize,
- DeviceId: req.GateId,
- Start: req.Start,
- End: req.End,
- Name: req.User,
- Visitor: req.Visitor,
- }
- 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)
- }
|