account_destroy_record.go 2.0 KB
package domain

import (
	"fmt"
	"time"
)

// 账号注销记录
type AccountDestroyRecord struct {
	// 用户基础数据id
	UserBaseId int64 `json:"userBaseId,string"`
	// 账号注销记录ID
	AccountDestroyRecordId int64 `json:"accountDestroyRecordId,string"`
	// 注销时间
	DestroyTime time.Time `json:"destroyTime"`
	// 账号修改后
	AccountAfter string `json:"accountAfter"`
	// 账号修改前
	AccountBefore string `json:"accountBefore"`
}

type AccountDestroyRecordRepository interface {
	Save(accountDestroyRecord *AccountDestroyRecord) (*AccountDestroyRecord, error)
	Remove(accountDestroyRecord *AccountDestroyRecord) (*AccountDestroyRecord, error)
	FindOne(queryOptions map[string]interface{}) (*AccountDestroyRecord, error)
	Find(queryOptions map[string]interface{}) (int64, []*AccountDestroyRecord, error)
}

func (accountDestroyRecord *AccountDestroyRecord) Identify() interface{} {
	if accountDestroyRecord.AccountDestroyRecordId == 0 {
		return nil
	}
	return accountDestroyRecord.AccountDestroyRecordId
}

func (accountDestroyRecord *AccountDestroyRecord) Update(data map[string]interface{}) error {
	//if userBaseId, ok := data["userBaseId"]; ok {
	//	accountDestroyRecord.UserBaseId = userBaseId.(int64)
	//}
	//if accountDestroyRecordId, ok := data["accountDestroyRecordId"]; ok {
	//	accountDestroyRecord.AccountDestroyRecordId = accountDestroyRecordId.(int64)
	//}
	//if destroyTime, ok := data["destroyTime"]; ok {
	//	accountDestroyRecord.DestroyTime = destroyTime.(string)
	//}
	//if accountAfter, ok := data["accountAfter"]; ok {
	//	accountDestroyRecord.AccountAfter = accountAfter.(string)
	//}
	//if accountBefore, ok := data["accountBefore"]; ok {
	//	accountDestroyRecord.AccountBefore = accountBefore.(string)
	//}
	return nil
}

func NewAccountDestroyRecord(userBaseId int64, num int64, account string) *AccountDestroyRecord {
	return &AccountDestroyRecord{
		UserBaseId:    userBaseId,
		DestroyTime:   time.Now(),
		AccountBefore: account,
		AccountAfter:  fmt.Sprintf("%v-%v", account, num+1),
	}
}