123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529 |
- 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"
- )
- //
- // @Summary 添加分类
- // @Description 添加分类
- // @Tags 服务电话
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.ServicePhoneClassAddBody true "信息"
- // @Success 200 {object} v1.ServicePhoneClassAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service_phone/class [post]
- func (c *Controller) ServicePhoneClassAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ServicePhoneClassAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ServicePhoneClassAddBody)
- 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.ServicePhoneClassAddResponse{}
- rpcReq := &v1.ServicePhoneClassAddRequest{
- GardenId:tokenInfo.GardenId,
- ClassName:req.ClassName,
- Enable:req.Enable,
- }
- rpcRsp, err := pb.Garden.ServicePhoneClassAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ServicePhoneClassAdd"),
- 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 "token"
- // @Param body body v1.ServicePhoneClassUpdateBody true "信息"
- // @Success 200 {object} v1.ServicePhoneClassUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service_phone/class [put]
- func (c *Controller) ServicePhoneClassUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ServicePhoneClassUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ServicePhoneClassUpdateBody)
- 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.ServicePhoneClassUpdateResponse{}
- rpcReq := &v1.ServicePhoneClassUpdateRequest{
- GardenId:tokenInfo.GardenId,
- ClassName:req.ClassName,
- Enable:req.Enable,
- Id:req.Id,
- }
- _, err = pb.Garden.ServicePhoneClassUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ServicePhoneClassUpdate"),
- 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 "token"
- // @Param id query int true " "
- // @Success 200 {object} v1.ServicePhoneClassDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service_phone/class [delete]
- func (c *Controller) ServicePhoneClassDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ServicePhoneClassDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ServicePhoneClassDelQuery, 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.ServicePhoneClassDelResponse{}
- rpcReq := &v1.ServicePhoneClassDelRequest{
- GardenId:tokenInfo.GardenId,
- Id:req.Id,
- }
- _, err = pb.Garden.ServicePhoneClassDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ServicePhoneClassDel"),
- 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 "token"
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Success 200 {object} v1.ServicePhoneClassListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service_phone/class [get]
- func (c *Controller) ServicePhoneClassList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ServicePhoneClassListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ServicePhoneClassListQuery, 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.ServicePhoneClassListResponse{}
- rpcReq := &v1.ServicePhoneClassListRequest{
- GardenId:tokenInfo.GardenId,
- PageSize:req.PageSize,
- Page:req.Page,
- }
- rpcRsp, err := pb.Garden.ServicePhoneClassList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ServicePhoneClassList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.ServicePhoneClassItem, 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 "token"
- // @Param body body v1.ServicePhoneAddBody true "信息"
- // @Success 200 {object} v1.ServicePhoneAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service_phone [post]
- func (c *Controller) ServicePhoneAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ServicePhoneAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ServicePhoneAddBody)
- 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.ServicePhoneAddResponse{}
- rpcReq := &v1.ServicePhoneAddRequest{
- GardenId:tokenInfo.GardenId,
- Phone:req.Phone,
- ClassId:req.ClassId,
- Name:req.Name,
- Enable:req.Enable,
- }
- rpcRsp, err := pb.Garden.ServicePhoneAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ServicePhoneAdd"),
- 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 "token"
- // @Param body body v1.ServicePhoneUpdateBody true "信息"
- // @Success 200 {object} v1.ServicePhoneUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service_phone [put]
- func (c *Controller) ServicePhoneUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ServicePhoneUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ServicePhoneUpdateBody)
- 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.ServicePhoneUpdateResponse{}
- rpcReq := &v1.ServicePhoneUpdateRequest{
- GardenId:tokenInfo.GardenId,
- Phone:req.Phone,
- Name:req.Name,
- Enable:req.Enable,
- Id:req.Id,
- }
- _, err = pb.Garden.ServicePhoneUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ServicePhoneUpdate"),
- 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 "token"
- // @Param id query int true " "
- // @Success 200 {object} v1.ServicePhoneDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service_phone [delete]
- func (c *Controller) ServicePhoneDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ServicePhoneDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ServicePhoneDelQuery, 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.ServicePhoneDelResponse{}
- rpcReq := &v1.ServicePhoneDelRequest{
- GardenId:tokenInfo.GardenId,
- Id:req.Id,
- }
- _, err = pb.Garden.ServicePhoneDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ServicePhoneDel"),
- 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 "token"
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param class_id query int false "分类id"
- // @Success 200 {object} v1.ServicePhoneListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service_phone [get]
- func (c *Controller) ServicePhoneList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ServicePhoneListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ServicePhoneListQuery, 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.ServicePhoneListResponse{}
- rpcReq := &v1.ServicePhoneListRequest{
- GardenId:tokenInfo.GardenId,
- PageSize:req.PageSize,
- Page:req.Page,
- ClassId:req.ClassId,
- }
- rpcRsp, err := pb.Garden.ServicePhoneList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ServicePhoneList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.ServicePhoneItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|