123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- 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
- }
|