12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- // 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"
- "time"
- )
- func checkHouseholdDelApplyParam(req *pb_v1.HouseholdDelApplyRequest) error {
- switch {
- case req.Id > 0:
- return nil
- case req.HouseId > 0:
- return nil
- case req.GardenId > 0 :
- return nil
- case req.BuildingId > 0:
- return nil
- case req.UnitId > 0:
- return nil
- }
- return errors.ParamsError
- }
- //
- func HouseholdDelApply(ctx context.Context, req *pb_v1.HouseholdDelApplyRequest) (reply *pb_v1.HouseholdDelApplyReply, err error) {
- reply = &pb_v1.HouseholdDelApplyReply{}
- // 捕获各个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 err = checkHouseholdDelApplyParam(req); 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.Id > 0 {
- where["id"] = req.Id
- }
- 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":"房屋变更,请重新申请",
- "approved_at":now,
- "updated_at":now,
- }
- err = p.Update(database.DB(), where, values)
- if err != nil {
- return nil, errors.DataBaseError
- }
- return reply, nil
- }
|