factory.go 761 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
package msg_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"gorm.io/gorm"
	"hilo-user/myerr"
)

func GetMsgSysRecordInit(model *domain.Model, t uint32, msgSysId uint64) *MsgSysRecord {
	return &MsgSysRecord{
		Model:    model,
		Type:     t,
		Status:   mysql.EXIST,
		MsgSysId: msgSysId,
	}
}

func GetMsgSysRecord(model *domain.Model, msgSysId uint64) (*MsgSysRecord, error) {
	msgSysRecord := MsgSysRecord{}
	if err := model.Db.Model(&MsgSysRecord{}).Where(&MsgSysRecord{
		MsgSysId: msgSysId,
	}).First(&msgSysRecord).Error; err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		} else {
			return nil, myerr.WrapErr(err)
		}
	} else {
		msgSysRecord.Model = model
		return &msgSysRecord, nil
	}
}