// 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" "property-household/pb" pb_v1 "property-household/pb/v1" "time" ) func checkHouseholdRefuseParam(req *pb_v1.HouseholdRefuseRequest) error { switch { case req.GardenId < 1: return status.Error(10003, "小区不能为空") case req.HouseId < 1 && req.UnitId < 1 && req.BuildingId < 1: return status.Error(10003, "房屋,单元,楼栋不能全空") } return nil } // func HouseholdRefuse(ctx context.Context, req *pb_v1.HouseholdRefuseRequest) (reply *pb_v1.HouseholdRefuseReply, err error) { reply = &pb_v1.HouseholdRefuseReply{} // 捕获各个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 = checkHouseholdRefuseParam(req) if err != nil { return nil, err } p := &dbmodel.THouse{} where := map[string]interface{}{ "approve_status":HouseholdApproveStatusWait, } if req.HouseId > 0 { where["house_id"] = req.HouseId } if req.BuildingId > 0 { where["building_id"] = req.BuildingId } if req.UnitId > 0 { where["unit_id"] = req.UnitId } if req.GardenId > 0 { where["garden_id"] = req.GardenId } now := time.Now() values := map[string]interface{}{ "approve_status":HouseholdApproveStatusFail, "feedback":req.Feedback, "approved_at":now, "updated_at":now, "uniq_flag":nil, } db := database.DB().Begin() affected, err := p.UpdateAffected(db, where, values) if err != nil { db.Rollback() return nil, errors.DataBaseError } if affected > 0 { statisticReq := pb_v1.RepairStatisticSetRequest{ HandleType:3, FinishIncrease:affected, } _, err = pb.Garden.RepairStatisticSet(ctx, &statisticReq) if err != nil { db.Rollback() return nil, err } } db.Commit() householdGardensDelFromRedis(p.Uid) return reply, nil }