// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package house_rent 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 checkHouseRentChangeFieldParam(req *pb_v1.HouseRentChangeFieldRequest) error { switch { case req.GardenId < 1: return status.Error(10003, "小区不能为空") } return nil } // func HouseRentChangeField(ctx context.Context, req *pb_v1.HouseRentChangeFieldRequest) (reply *pb_v1.HouseRentChangeFieldReply, err error) { reply = &pb_v1.HouseRentChangeFieldReply{} // 捕获各个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 = checkHouseRentChangeFieldParam(req) if err != nil { return nil, err } p := dbmodel.THouseRent{} where := map[string]interface{}{ "garden_id":req.GardenId, } values := map[string]interface{}{} switch { case req.HouseId == 0 && req.UnitId == 0: if req.Lnt > 0 { values["lnt"] = req.Lnt } if req.Lat > 0 { values["lat"] = req.Lat } if req.GardenName != "" { values["garden_name"] = req.GardenName } case req.UnitId > 0: where["unit_id"] = req.UnitId hasLift := int32(1) if !req.HasLift { hasLift = 2 } values["has_lift"] = hasLift case req.HouseId > 0: where["house_id"] = req.HouseId if req.Layer > 0 { values["layer"] = req.Layer } if req.HouseArea > 0 { values["house_area"] = req.HouseArea } if req.RoomCount > 0 { values["room_count"] = req.RoomCount } if req.HallCount > 0 { values["hall_count"] = req.HallCount } } if len(values) == 0 { return reply, nil } db := database.DB() err = p.Update(db, where, values) if err != nil { return nil, errors.DataBaseError } return reply, nil }