123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- 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-management-gateway/errors"
- param_v1 "property-management-gateway/param/v1"
- "property-management-gateway/pb"
- "property-management-gateway/pb/v1"
- "property-management-gateway/utils"
- )
- //
- // @Summary 小区列表
- // @Description 小区列表
- // @Tags 小区
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param committee_code query string false "社区代码"
- // @Param street_code query string false "街道代码"
- // @Param garden_name query string false "小区名字"
- // @Param page query int true "第几页,1为起始页, -1 不分页返回所有"
- // @Param page_size query int false "每页条数,-1 不分页返回所有"
- // @Param not_approved query bool false "true 待审批或未通过的数据 false 审批通过的数据"
- // @Success 200 {object} v1.GardenListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/garden [get]
- func (c *Controller) GardenList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GardenListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenListQuery, 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.GardenListResponse{}
- rpcReq := &v1.GardenListRequest{
- Page: req.Page,
- PageSize: req.PageSize,
- CommitteeCode: req.CommitteeCode,
- NotApproved: req.NotApproved,
- NeedAppendix: true,
- StreetCode: req.StreetCode,
- GardenName: req.GardenName,
- Management: true,
- }
- rpcRsp, err := pb.System.GardenList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Garden.GardenList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- for i, v := range rpcRsp.List {
- if len(v.WaterType) == 0 {
- rpcRsp.List[i].WaterType = []int32{}
- }
- if len(v.ElectricType) == 0 {
- rpcRsp.List[i].ElectricType = []int32{}
- }
- if len(v.GardenPics) == 0 {
- rpcRsp.List[i].GardenPics = []string{}
- }
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GardenItem, 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.GardenEnableSetBody true "信息"
- // @Success 200 {object} v1.GardenEnableSetResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/garden/enable [put]
- func (c *Controller) GardenEnableSet(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GardenEnableSetRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenEnableSetBody)
- 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.GetJwtTokenFromCtx(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.GardenEnableSetResponse{}
- rpcReq := &v1.GardenEnableSetRequest{
- Enable: req.Enable,
- GardenId: req.GardenId,
- }
- _, err := pb.System.GardenEnableSet(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.GardenEnableSet"),
- 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.GardenChangeCompanyBody true " "
- // @Success 200 {object} v1.GardenChangeCompanyResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/garden/company [put]
- func (c *Controller) GardenChangeCompany(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GardenChangeCompanyRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenChangeCompanyBody)
- 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.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- resp := param_v1.GardenChangeCompanyResponse{}
- rpcReq := &v1.GardenChangeCompanyRequest{
- GardenId: req.GardenId,
- Cid: req.Cid,
- }
- rpcRsp, err := pb.System.GardenChangeCompany(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Garden.GardenChangeCompany"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- logReq := OperationLogRequest{
- Module: ModuleGarden,
- Action: ActionGardenChangeCompany,
- Origin: rpcRsp.Origin,
- Target: req.GardenChangeCompanyBody,
- UserName: tokenInfo.User,
- Uid: tokenInfo.Uid,
- }
- go OperationLogAdd(&logReq)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 新增小区审核
- // @Description 新增小区审核
- // @Tags 小区
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.GardenApproveBody true "小区信息"
- // @Success 200 {object} v1.GardenApproveResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/garden [put]
- func (c *Controller) GardenApprove(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GardenApproveRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenApproveBody)
- 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.GardenApproveResponse{}
- rpcReq := &v1.GardenApproveRequest{
- Id: req.Id,
- Status: req.Status,
- Feedback: req.Feedback,
- }
- _, err := pb.System.GardenApprove(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.GardenApprove"),
- 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.GardenKeyInfoApproveBody true "小区信息"
- // @Success 200 {object} v1.GardenKeyInfoApproveResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/garden/key_info [put]
- func (c *Controller) GardenKeyInfoApprove(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GardenKeyInfoApproveRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenKeyInfoApproveBody)
- 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.GardenKeyInfoApproveResponse{}
- rpcReq := &v1.GardenKeyInfoApproveRequest{
- Id: req.Id,
- Status: req.Status,
- Feedback: req.Feedback,
- }
- _, err := pb.System.GardenKeyInfoApprove(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.GardenKeyInfoApprove"),
- 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 status query int false "0不过率 1 待审核 2 审核通过 3 未通过 "
- // @Success 200 {object} v1.GardenKeyInfoChangeListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/garden/key_info [get]
- func (c *Controller) GardenKeyInfoChangeList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GardenKeyInfoChangeListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenKeyInfoChangeListQuery, 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.GardenKeyInfoChangeListResponse{}
- rpcReq := &v1.GardenKeyInfoChangeListRequest{
- Status: req.Status,
- Page: req.Page,
- PageSize: req.PageSize,
- }
- rpcRsp, err := pb.System.GardenKeyInfoChangeList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.GardenKeyInfoChangeList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GardenKeyInfoData, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|