123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660 |
- 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-applete-gateway/errors"
- param_v1 "property-applete-gateway/param/v1"
- "property-applete-gateway/pb"
- "property-applete-gateway/pb/v1"
- "property-applete-gateway/utils"
- )
- //
- // @Summary 门禁列表
- // @Description 门禁列表
- // @Tags 门禁
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param garden_id query int false "小区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
- }
- 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,
- }
- 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,
- }
- _, 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 body body v1.GateWhiteAddBody true " "
- // @Success 200 {object} v1.GateWhiteAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/white [post]
- func (c *Controller) GateWhiteAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateWhiteAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateWhiteAddBody)
- 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.GateWhiteAddResponse{}
- rpcReq := &v1.GateWhiteAddRequest{
- DeviceId:req.DeviceId,
- HouseholdUids:req.HouseholdUids,
- }
- if len(req.CardInfo) > 0 {
- rpcReq.CardInfo = []*v1.GateCardInfo{}
- for _, v := range req.CardInfo {
- rpcReq.CardInfo = append(rpcReq.CardInfo, &v1.GateCardInfo{CardNumber:v.CardNumber, CardOwner:v.CardOwner})
- }
- }
- _, err := pb.Device.GateWhiteAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.DeviceGateWhiteAdd"),
- 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.GateWhiteDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/white [delete]
- func (c *Controller) GateWhiteDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateWhiteDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateWhiteDelQuery, 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.GateWhiteDelResponse{}
- rpcReq := &v1.GateWhiteDelRequest{
- Id:req.Id,
- }
- _, err := pb.Device.GateWhiteDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Device.GateWhiteDel"),
- 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.GateWhiteHouseholdListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/white/household [get]
- func (c *Controller) GateWhiteHouseholdList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateWhiteHouseholdListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateWhiteHouseholdListQuery, 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.GateWhiteHouseholdListResponse{}
- rpcReq := &v1.GateWhiteHouseholdListRequest{
- Page:req.Page,
- PageSize:req.PageSize,
- DeviceId:req.DeviceId,
- }
- rpcRsp, err := pb.Device.GateWhiteHouseholdList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateWhiteHouseholdList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GateWhiteHouseholdItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 白名单列表(ic卡)
- // @Description 白名单列表(ic卡)
- // @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.GateWhiteCardListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/white/card [get]
- func (c *Controller) GateWhiteCardList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateWhiteCardListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GateWhiteCardListQuery, 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.GateWhiteCardListResponse{}
- rpcReq := &v1.GateWhiteCardListRequest{
- Page:req.Page,
- PageSize:req.PageSize,
- DeviceId:req.DeviceId,
- }
- rpcRsp, err := pb.Device.GateWhiteCardList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Device.GateWhiteCardList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GateWhiteCardItem, 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_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 body body v1.GateWhiteSyncBody true " "
- // @Success 200 {object} v1.GateWhiteSyncResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/gate/white/sync [put]
- func (c *Controller) GateWhiteSync(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GateWhiteSyncRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GateWhiteSyncBody)
- 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.GateWhiteSyncResponse{}
- rpcReq := &v1.GateWhiteSyncRequest{
- DeviceId:req.DeviceId,
- }
- _, err := pb.Device.GateWhiteSync(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(rpcReq)
- logger.Error("func",
- zap.String("call", "pb.GateWhiteSync"),
- 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)
- }
|