143 lines
4.0 KiB
Go
143 lines
4.0 KiB
Go
|
package repository
|
|||
|
|
|||
|
import (
|
|||
|
"code.freebrio.com/fb-go/lib/context"
|
|||
|
"code.freebrio.com/fb-go/lib/fbl"
|
|||
|
"time"
|
|||
|
)
|
|||
|
|
|||
|
// FThirdAgentInfoDO 三方代理 信息表
|
|||
|
type FThirdAgentInfoDO struct {
|
|||
|
Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
|
|||
|
Sn string `gorm:"column:sn;type:varchar(64);comment:sn" json:"sn"`
|
|||
|
Name string `gorm:"column:name;type:varchar(64);comment:名称" json:"name"`
|
|||
|
Account string `gorm:"column:account;type:varchar(64);comment:帐号" json:"account"`
|
|||
|
Pwd string `gorm:"column:pwd;type:varchar(128);comment:密码" json:"pwd"`
|
|||
|
Iphone string `gorm:"column:iphone;type:varchar(32);comment:联系方式" json:"iphone"`
|
|||
|
Email string `gorm:"column:email;type:varchar(64);comment:email" json:"email"`
|
|||
|
Remark string `gorm:"column:remark;type:varchar(64);comment:备注" json:"remark"`
|
|||
|
Status int `gorm:"column:status;type:tinyint(1) unsigned;default:1;comment:是否有效。0:否;1:是;NOT NULL" json:"status"`
|
|||
|
Deleted uint `gorm:"column:deleted;type:tinyint(1) unsigned;default:0;comment:逻辑删除。 0:未删除;1:已删除;NOT NULL" json:"deleted"`
|
|||
|
CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;NOT NULL" json:"create_time"`
|
|||
|
UpdateTime time.Time `gorm:"column:update_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:更新时间;NOT NULL" json:"update_time"`
|
|||
|
}
|
|||
|
|
|||
|
func (m *FThirdAgentInfoDO) TableName() string {
|
|||
|
return "f_third_agent_info"
|
|||
|
}
|
|||
|
|
|||
|
type thirdAgentInfoRepositoryImpl struct {
|
|||
|
}
|
|||
|
|
|||
|
func (thirdAgentInfoRepositoryImpl) QueryPage(ctx context.GormWithZap, page, size int) *[]FThirdAgentInfoDO {
|
|||
|
db, err := ctx.GormWithContext()
|
|||
|
if err != nil {
|
|||
|
return nil
|
|||
|
}
|
|||
|
|
|||
|
offset := (page - 1) * size
|
|||
|
offset = fbl.If(offset >= 0, offset, 0)
|
|||
|
var dataList []FThirdAgentInfoDO
|
|||
|
sqlErr := db.Model(&FThirdAgentInfoDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
|||
|
if sqlErr != nil {
|
|||
|
ctx.Zap().Sugar().Errorf("QueryPage_sqlErr page:%d %+v", page, sqlErr)
|
|||
|
return nil
|
|||
|
}
|
|||
|
|
|||
|
if len(dataList) == 0 {
|
|||
|
return nil
|
|||
|
}
|
|||
|
|
|||
|
return &dataList
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
func (thirdAgentInfoRepositoryImpl) FindById(ctx context.GormWithZap, id uint64) *FThirdAgentInfoDO {
|
|||
|
db, err := ctx.GormWithContext()
|
|||
|
if err != nil {
|
|||
|
return nil
|
|||
|
}
|
|||
|
|
|||
|
var model FThirdAgentInfoDO
|
|||
|
sqlErr := db.Where("id=?", id).First(&model).Error
|
|||
|
if sqlErr != nil {
|
|||
|
ctx.Zap().Sugar().Errorf("FindById_sqlErr id:%d %+v", id, sqlErr)
|
|||
|
return nil
|
|||
|
}
|
|||
|
|
|||
|
return &model
|
|||
|
}
|
|||
|
|
|||
|
func (thirdAgentInfoRepositoryImpl) Count(ctx context.GormWithZap) int64 {
|
|||
|
db, err := ctx.GormWithContext()
|
|||
|
if err != nil {
|
|||
|
return 0
|
|||
|
}
|
|||
|
|
|||
|
var total int64
|
|||
|
sqlErr := db.Model(&FThirdAgentInfoDO{}).Select("count(*)").First(&total).Error
|
|||
|
if sqlErr != nil {
|
|||
|
ctx.Zap().Sugar().Errorf("Count_sqlErr %+v", sqlErr)
|
|||
|
return 0
|
|||
|
}
|
|||
|
|
|||
|
return total
|
|||
|
}
|
|||
|
|
|||
|
func (thirdAgentInfoRepositoryImpl) Create(ctx context.GormWithZap, data *FThirdAgentInfoDO) error {
|
|||
|
db, err := ctx.GormWithContext()
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
//保存数据
|
|||
|
return db.Create(data).Error
|
|||
|
}
|
|||
|
|
|||
|
func (thirdAgentInfoRepositoryImpl) UpdateById(ctx context.GormWithZap, data FThirdAgentInfoDO) error {
|
|||
|
db, err := ctx.GormWithContext()
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
//更新数据
|
|||
|
return db.Updates(&data).Error
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
func (thirdAgentInfoRepositoryImpl) UpdateStatusById(ctx context.GormWithZap, id uint64, status int, operator string) error {
|
|||
|
db, err := ctx.GormWithContext()
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
data := FThirdAgentInfoDO{}
|
|||
|
sqlErr := db.Model(&data).
|
|||
|
Select("status").
|
|||
|
Where("id=?", id).
|
|||
|
Updates(FThirdAgentInfoDO{Status: status}).Error
|
|||
|
if sqlErr != nil {
|
|||
|
return sqlErr
|
|||
|
}
|
|||
|
|
|||
|
return nil
|
|||
|
}
|
|||
|
|
|||
|
func (thirdAgentInfoRepositoryImpl) deleteById(ctx context.GormWithZap, id uint64, operator string) error {
|
|||
|
db, err := ctx.GormWithContext()
|
|||
|
if err != nil {
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
data := FThirdAgentInfoDO{}
|
|||
|
sqlErr := db.Model(&data).
|
|||
|
Select("deleted").
|
|||
|
Where("id=?", id).
|
|||
|
Updates(FThirdAgentInfoDO{Deleted: 1}).Error
|
|||
|
if sqlErr != nil {
|
|||
|
return sqlErr
|
|||
|
}
|
|||
|
|
|||
|
return nil
|
|||
|
}
|