104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"service/api/consts"
|
|
accountpunishmentproto "service/api/proto/accountpunishment/proto"
|
|
"service/app/mix/dao"
|
|
"service/bizcommon/util"
|
|
"service/dbstruct"
|
|
"service/library/logger"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
goproto "google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type AccountPunishment struct {
|
|
store *dao.Store
|
|
}
|
|
|
|
func NewAccountPunishment(store *dao.Store) (a *AccountPunishment) {
|
|
a = &AccountPunishment{
|
|
store: store,
|
|
}
|
|
return
|
|
}
|
|
|
|
func (p *AccountPunishment) OpCreate(ctx *gin.Context, req *accountpunishmentproto.OpCreateReq) error {
|
|
|
|
//产生id
|
|
accountpunishmentIdSeq, err := p.store.GetAndUpdateAccountPunishmentIdSeq(ctx)
|
|
if err != nil {
|
|
logger.Error("GetAndUpdateAccountPunishmentIdSeq failed : %v", err)
|
|
return err
|
|
}
|
|
|
|
nowTime := time.Now().Unix()
|
|
req.AccountPunishment.Id = goproto.Int64(accountpunishmentIdSeq.Seq)
|
|
req.AccountPunishment.Status = goproto.Int64(consts.AccountPunishment_Punishing)
|
|
req.AccountPunishment.EndTime = goproto.Int64(nowTime + util.DerefInt64(req.Duration))
|
|
req.AccountPunishment.Ct = goproto.Int64(nowTime)
|
|
req.AccountPunishment.Ut = goproto.Int64(nowTime)
|
|
req.AccountPunishment.DelFlag = goproto.Int64(consts.Exist)
|
|
err = p.store.CreateAccountPunishment(ctx, req.AccountPunishment)
|
|
if err != nil {
|
|
logger.Error("CreateAccountPunishment fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *AccountPunishment) OpUpdate(ctx *gin.Context, req *accountpunishmentproto.OpUpdateReq) error {
|
|
err := p.store.UpdateAccountPunishment(ctx, req.AccountPunishment)
|
|
if err != nil {
|
|
logger.Error("UpdateAccountPunishment fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *AccountPunishment) OpDelete(ctx *gin.Context, id int64) error {
|
|
err := p.store.DeleteAccountPunishment(ctx, id)
|
|
if err != nil {
|
|
logger.Error("DeleteAccountPunishment fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *AccountPunishment) OpList(ctx *gin.Context, req *accountpunishmentproto.OpListReq) ([]*dbstruct.AccountPunishment, error) {
|
|
list, err := p.store.GetAccountPunishmentList(ctx, req)
|
|
if err != nil {
|
|
logger.Error("GetAccountPunishmentList fail, err: %v", err)
|
|
return make([]*dbstruct.AccountPunishment, 0), err
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func (p *AccountPunishment) OpListTerminated(ctx *gin.Context, req *accountpunishmentproto.OpListTerminatedReq) ([]*dbstruct.AccountPunishment, error) {
|
|
list, err := p.store.GetTerminatedAccountPunishmentList(ctx, req)
|
|
if err != nil {
|
|
logger.Error("GetTerminatedAccountPunishmentList fail, err: %v", err)
|
|
return make([]*dbstruct.AccountPunishment, 0), err
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func (p *AccountPunishment) OpListById(ctx *gin.Context, id int64) (*dbstruct.AccountPunishment, error) {
|
|
accountpunishment, err := p.store.GetAccountPunishmentListById(ctx, id)
|
|
if err != nil {
|
|
logger.Error("GetAccountPunishmentListById fail, err: %v", err)
|
|
return nil, err
|
|
}
|
|
return accountpunishment, nil
|
|
}
|
|
|
|
func (p *AccountPunishment) OpListByMidAndType(ctx *gin.Context, mid int64, typ int64) (*dbstruct.AccountPunishment, error) {
|
|
accountpunishment, err := p.store.GetAccountPunishmentListByMidAndType(ctx, mid, typ)
|
|
if err != nil {
|
|
logger.Error("GetAccountPunishmentListByMid fail, err: %v", err)
|
|
return nil, err
|
|
}
|
|
return accountpunishment, nil
|
|
}
|