package gate_card import ( "encoding/json" "git.getensh.com/common/gopkgs/database" dbmodel "property-device/model" "property-device/utils/gate_utils" "time" ) type CardSaiboHttpv1Whiter struct { Gcard *dbmodel.TGateCard Device *dbmodel.TGate UCard *dbmodel.TUserCard command bool } func (p *CardSaiboHttpv1Whiter) PersonAdd() { params := make([]gate_utils.WhiteParams, 1) params[0].CodeType = "C" params[0].CodeVal = p.UCard.CardNumber params[0].ValidityStart = time.Now().Format("2006-01-02 15:04:05") params[0].ValidityEnd = "2099-01-02 15:04:05" params[0].DeleteFlag = "0" bytes, _ := json.Marshal(params) now := time.Now() gcmd := &dbmodel.TGateCommand{ CreatedAt: now, UpdatedAt: now, DeviceId: p.Gcard.DeviceId, Param: string(bytes), Desc: gate_utils.CommandCodeMap[gate_utils.DownCommand], Status: gate_utils.CommandStatusWait, ResultStatus: 0, ResultStatusDesc: "", Code: gate_utils.DownCommand, } if err := gcmd.Insert(database.DB()); err != nil { whiteCardSetFail(p.UCard, p.Device, gate_utils.WhiteAddStatusPersonFail, err.Error()) return } gcmd = &dbmodel.TGateCommand{ CreatedAt: now, UpdatedAt: now, DeviceId: p.Gcard.DeviceId, Param: string(bytes), Desc: gate_utils.CommandCodeMap[gate_utils.QueryCommand], Status: gate_utils.CommandStatusWait, ResultStatus: 0, ResultStatusDesc: "", Code: gate_utils.QueryCommand, } if err := gcmd.Insert(database.DB()); err != nil { whiteCardSetFail(p.UCard, p.Device, gate_utils.WhiteAddStatusPersonFail, err.Error()) return } p.command = true return } func (p *CardSaiboHttpv1Whiter) PersonDel() { params := make([]gate_utils.WhiteParams, 1) params[0].CodeType = "C" params[0].CodeVal = p.UCard.CardNumber params[0].ValidityStart = time.Now().Format("2006-01-02 15:04:05") params[0].ValidityEnd = "2099-01-02 15:04:05" params[0].DeleteFlag = "1" bytes, _ := json.Marshal(params) now := time.Now() gcmd := &dbmodel.TGateCommand{ CreatedAt: now, UpdatedAt: now, DeviceId: p.Device.ID, Param: string(bytes), Desc: gate_utils.CommandCodeMap[gate_utils.DownCommand], Status: gate_utils.CommandStatusWait, ResultStatus: 0, ResultStatusDesc: "", Code: gate_utils.DownCommand, } if err := gcmd.Insert(database.DB()); err != nil { return } gcmd = &dbmodel.TGateCommand{ CreatedAt: now, UpdatedAt: now, DeviceId: p.Device.ID, Param: string(bytes), Desc: gate_utils.CommandCodeMap[gate_utils.QueryCommand], Status: gate_utils.CommandStatusWait, ResultStatus: 0, ResultStatusDesc: "", Code: gate_utils.QueryCommand, } if err := gcmd.Insert(database.DB()); err != nil { return } p.command = true return } func (p *CardSaiboHttpv1Whiter) Command() bool { return p.command }