123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package garden
- import (
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgs/cache"
- "git.getensh.com/common/gopkgs/database"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "gorm.io/gorm"
- "property-system/errors"
- dbmodel "property-system/model"
- "property-system/pb"
- pb_v1 "property-system/pb/v1"
- )
- const (
- HouseholdApproveStatusWait = 1
- HouseholdApproveStatusSuccess = 2
- HouseholdApproveStatusFail = 3
- )
- func RefuseHouseApply(gardenId int64, buildingId int64, unitId int64, houseId int64) error {
- mreq := pb_v1.HouseholdRefuseRequest{
- GardenId:gardenId,
- HouseId:houseId,
- BuildingId:buildingId,
- UnitId:unitId,
- Feedback:"房屋变更,请重新申请",
- }
- _, err := pb.Household.HouseholdRefuse(context.Background(), &mreq)
- if err != nil {
- return err
- }
- return nil
- }
- //
- func GardenDel(ctx context.Context, req *pb_v1.GardenDelRequest) (reply *pb_v1.GardenDelReply, err error) {
- return nil, status.Error(10003, "小区不支持删除")
- reply = &pb_v1.GardenDelReply{}
- // 捕获各个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"))
- }
- }
- }()
- if req.Id < 1 || req.Cid < 1{
- return nil, errors.ParamsError
- }
- mreq := pb_v1.GardenHouseIsInRequest{GardenId:req.Id}
- mreply, err := pb.Garden.GardenHouseIsIn(ctx, &mreq)
- if err != nil {
- return nil, err
- }
- if mreply.In {
- return nil, status.Error(10003, "已入住房屋, 不能删除小区")
- }
- old := &dbmodel.TGardenApproved{}
- p := &dbmodel.TGardenApproved{}
- where := map[string]interface{}{
- "id":req.Id,
- "cid":req.Cid,
- }
- values := map[string]interface{}{
- "in_use":nil,
- "pay_mode":1,
- "mch_id":2,
- }
- err = old.Find(database.DB(), where)
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, errors.DataBaseError
- }
- if old.ID == 0 {
- return nil, errors.ErrRecordNotFound
- }
- reply.Origin = &pb_v1.GardenUpdateRequest{
- Id:req.Id,
- GardenName:old.GardenName,
- GardenDesc:old.GardenDesc,
- StreetCode:old.StreetCode,
- CommitteeCode:old.CommitteeCode,
- ProvinceCode:old.ProvinceCode,
- CityCode:old.CityCode,
- AreaCode:old.AreaCode,
- Cid:old.Cid,
- PropertyPerson:old.PropertyPerson,
- PropertyPhone:old.PropertyPhone,
- GardenPic:old.GardenPic,
- GardenAddr:old.GardenAddr,
- }
- db := database.DB().Begin()
- err = p.Update(db, where, values)
- if err != nil {
- db.Rollback()
- return nil, errors.DataBaseError
- }
- _, err = cache.Redis().SAdd("garden_del", fmt.Sprintf("%d"), req.Id)
- if err != nil {
- db.Rollback()
- return nil, errors.RedisError
- }
- if err = RefuseHouseApply(req.Id, 0, 0, 0); err != nil {
- db.Rollback()
- return nil, err
- }
- db.Commit()
- return reply, nil
- }
|