// Copyright 2021 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package reminder import ( "context" "encoding/json" "fmt" "git.getensh.com/common/gopkgs/cache" "git.getensh.com/common/gopkgs/logger" "go.uber.org/zap" "property-task/impl/v1/common" "property-task/pb" pb_v1 "property-task/pb/v1" "time" ) // 费用对象类型 const ( ObjTypeHouse = 1 ObjTypeSpace = 2 ObjTypeVehicle = 3 ) // 业主类型(业主,家人,租客) const ( UserTypeHousehold = 1 UserTypeFamily = 2 UserTypeRenter = 3 ) var userTypeM = map[int32][]int32{ 1: []int32{UserTypeHousehold}, 2: []int32{UserTypeHousehold, UserTypeFamily}, 3: []int32{UserTypeHousehold, UserTypeFamily, UserTypeRenter}, } var UrgeTitleM = map[int32]string{ ObjTypeHouse: "您的房屋有欠费账单", ObjTypeSpace: "您的车位有欠费账单", ObjTypeVehicle: "您的车辆有欠费账单", } // 获取催缴配置 func getUrgeConf(gardenId int64) *pb_v1.ChargeUrgeInfoReply { mreq := pb_v1.ChargeUrgeInfoRequest{} mreq.GardenId = gardenId reply, err := pb.Garden.ChargeUrgeInfo(context.Background(), &mreq) if err != nil { logger.Error("func", zap.String("call", "pb.Garden.ChargeUrgeInfo "), zap.String("error", err.Error())) return nil } return reply } // 获取催缴用户的联系方式 func getUrgeObjUserContact(gardenId int64, userType []int32) ([]interface{}, []interface{}) { mreq := pb_v1.GenerateReminderRequest{} mreq.GardenId = gardenId mreq.UserType = userType reply, err := pb.Garden.GenerateReminder(context.Background(), &mreq) if err != nil { logger.Error("func", zap.String("call", "pb.Garden.GenerateReminder "), zap.String("error", err.Error())) return nil, nil } phones := []interface{}{} openIds := []interface{}{} for _, objs := range reply.List { for _, user := range objs.Users { if user.Phone != "" { phones = append(phones, user.Phone) } if user.PublicOpenId != "" { openIds = append(openIds, user.PublicOpenId) } } } return phones, openIds } func isPhoneMsg(msgType int32) bool { return msgType == 1 || msgType == 3 } func isWxMsg(msgType int32) bool { return msgType == 2 || msgType == 3 } func CanUrg(urgeConf *pb_v1.ChargeUrgeInfoReply, nowDay time.Time) bool { if urgeConf == nil { return false } // 不催缴 if urgeConf.UrgeDay == 0 { return false } // 判断是否今天生成催缴 if nowDay.Day() != int(urgeConf.UrgeDay) { return false } return true } // 定时生成催缴单 func GenerateReminder() { fmt.Printf("开始生成催缴信息\n") now := time.Now() nowDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) cache.RedisLock(common.TaskKey) defer cache.RedisUnlock(common.TaskKey) // 获取小区列表 gardens := common.GetGardenList() // 缓存小区信息,发送催缴信息时会用到 if len(gardens) > 0 { bytes, _ := json.Marshal(gardens) cacheGardenInfo(nowDay.Unix(), string(bytes)) } for _, garden := range gardens { // delOldObjUsers(nowDay.Unix(), garden.GardenId) // 获取定时催缴配置 urgeConf := getUrgeConf(garden.GardenId) // 是否能催缴 if !CanUrg(urgeConf, nowDay) { continue } // 查询小区内所有需要催缴的用户的联系方式 phones, openIds := getUrgeObjUserContact(garden.GardenId, userTypeM[urgeConf.UrgeTarget]) fmt.Printf("xxxxy:%v,%v\n", phones, openIds) // 缓存手机号或用户openid等到8点30发送(cronb) if isPhoneMsg(urgeConf.UrgeMsgType) && len(phones) > 0 { cacheAllObjUsersPhone(nowDay.Unix(), garden.GardenId, phones) } if isWxMsg(urgeConf.UrgeMsgType) && len(openIds) > 0 { cacheAllObjUsersOpenid(nowDay.Unix(), garden.GardenId, openIds) } } }