// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package house import ( "context" "encoding/json" "fmt" "git.getensh.com/common/gopkgs/database" "git.getensh.com/common/gopkgs/logger" "go.uber.org/zap" "google.golang.org/grpc/status" "property-household/errors" dbmodel "property-household/model" pb_v1 "property-household/pb/v1" ) func checkHouseholdWaitCountParam(req *pb_v1.HouseholdWaitCountRequest) error { switch { case req.GardenId < 1: return status.Error(10003, "id不能为空") case req.BuildingId < 0 && req.UnitId < 0 && req.HouseId < 0: return status.Error(10003, "id 不能为空") } return nil } // func HouseholdWaitCount(ctx context.Context, req *pb_v1.HouseholdWaitCountRequest) (reply *pb_v1.HouseholdWaitCountReply, err error) { reply = &pb_v1.HouseholdWaitCountReply{} // 捕获各个task中的异常并返回给调用者 defer func() { if r := recover(); r != nil { err = fmt.Errorf("%+v", r) e := &status.Status{} if er := json.Unmarshal([]byte(err.Error()), e); er != nil { logger.Error("err", zap.String("system_err", err.Error()), zap.Stack("stacktrace")) } } }() err = checkHouseholdWaitCountParam(req) if err != nil { return nil, err } p := dbmodel.THouse{} where := map[string]interface{}{ "approve_status":HouseholdApproveStatusWait, } if req.GardenId > 0 { where["garden_id"] = req.GardenId } if req.BuildingId > 0 { where["building_id"] = req.BuildingId } if req.UnitId > 0 { where["unit_id"] = req.UnitId } if req.HouseId > 0 { where["house_id"] = req.HouseId } reply.Count, err = p.CountDistinct(database.DB(), where, nil, "uid") if err != nil { return nil, errors.DataBaseError } return reply, nil }