service/app/mix/service/logic/streamerauthapproval_basic.go

156 lines
5.4 KiB
Go

package logic
import (
"service/api/consts"
streamerauthapprovalbasicproto "service/api/proto/streamerauthapprovalbasic/proto"
"service/app/mix/dao"
"service/dbstruct"
"service/library/logger"
"time"
"github.com/gin-gonic/gin"
"github.com/qiniu/qmgo"
goproto "google.golang.org/protobuf/proto"
)
type StreamerAuthApprovalBasic struct {
store *dao.Store
}
func NewStreamerAuthApprovalBasic(store *dao.Store) (a *StreamerAuthApprovalBasic) {
a = &StreamerAuthApprovalBasic{
store: store,
}
return
}
func (p *StreamerAuthApprovalBasic) OpCreate(ctx *gin.Context, req *streamerauthapprovalbasicproto.OpCreateReq) error {
//生成自增id
idSeq, err := p.store.GetAndUpdateStreamerAuthApprovalBasicIdSeq(ctx)
if err != nil {
logger.Error("GetAndUpdateStreamerAuthApprovalBasicIdSeq fail, err: %v", err)
return err
}
req.StreamerAuthApprovalBasic.Id = goproto.Int64(idSeq.Seq)
req.StreamerAuthApprovalBasic.Ct = goproto.Int64(time.Now().Unix())
req.StreamerAuthApprovalBasic.Ut = goproto.Int64(time.Now().Unix())
req.StreamerAuthApprovalBasic.DelFlag = goproto.Int64(consts.Exist)
req.StreamerAuthApprovalBasic.ApproveStatus = goproto.Int64(consts.StreamerAuthApprovalBasicApprove_Waiting) //默认已创建
err = p.store.CreateStreamerAuthApprovalBasic(ctx, req.StreamerAuthApprovalBasic)
if err != nil {
logger.Error("CreateStreamerAuthApprovalBasic fail, err: %v", err)
return err
}
return nil
}
func (p *StreamerAuthApprovalBasic) OpUpdate(ctx *gin.Context, req *streamerauthapprovalbasicproto.OpUpdateReq) error {
err := p.store.UpdateStreamerAuthApprovalBasic(ctx, req.StreamerAuthApprovalBasic)
if err != nil {
logger.Error("UpdateStreamerAuthApprovalBasic fail, err: %v", err)
return err
}
return nil
}
func (p *StreamerAuthApprovalBasic) OpDelete(ctx *gin.Context, req *streamerauthapprovalbasicproto.OpDeleteReq) error {
//1.查出原有审核申请
streamerauthapprovalbasic, err := p.store.GetStreamerAuthApprovalBasicListByMid(ctx, &streamerauthapprovalbasicproto.OpListByMidReq{
Uid: req.Uid,
})
if streamerauthapprovalbasic == nil {
logger.Error("GetStreamerAuthApprovalBasicListByMid fail, err: %v", qmgo.ErrNoSuchDocuments)
return qmgo.ErrNoSuchDocuments
}
if err != nil {
logger.Error("GetStreamerAuthApprovalBasicListByMid fail, err: %v", err)
return err
}
//2.原有审核申请标记删除后转存到历史表
streamerauthapprovalbasic.DelFlag = goproto.Int64(consts.Deleted)
err = p.store.CreateStreamerAuthApprovalBasicHis(ctx, streamerauthapprovalbasic)
if err != nil {
logger.Error("CreateStreamerAuthApprovalBasicHis fail, err: %v", err)
return err
}
//3.真删除原有审核申请
err = p.store.DeleteStreamerAuthApprovalBasic(ctx, streamerauthapprovalbasic.GetId())
if err != nil {
logger.Error("DeleteStreamerAuthApprovalBasic fail, err: %v", err)
return err
}
return nil
}
func (p *StreamerAuthApprovalBasic) OpDeleteBatch(ctx *gin.Context, ids []int64) error {
//1.查出原有审核申请
list, err := p.store.GetStreamerAuthApprovalBasicListByIds(ctx, ids)
if len(list) == 0 {
logger.Error("GetStreamerAuthApprovalBasicListByIds fail, err: %v", qmgo.ErrNoSuchDocuments)
return qmgo.ErrNoSuchDocuments
}
if err != nil {
logger.Error("GetStreamerAuthApprovalBasicListByIds fail, err: %v", err)
return err
}
//2.原有审核申请标记删除后转存到历史表
for _, streamerauthapprovalbasic := range list {
streamerauthapprovalbasic.DelFlag = goproto.Int64(consts.Deleted)
}
err = p.store.CreateBatchStreamerAuthApprovalBasicHis(ctx, list)
if err != nil {
logger.Error("CreateBatchStreamerAuthApprovalBasicHis fail, err: %v", err)
return err
}
//3.真删除原有审核申请
err = p.store.DeleteStreamerAuthApprovalBasicByIds(ctx, ids)
if err != nil {
logger.Error("DeleteStreamerAuthApprovalBasicByIds fail, err: %v", err)
return err
}
return nil
}
func (p *StreamerAuthApprovalBasic) OpList(ctx *gin.Context, req *streamerauthapprovalbasicproto.OpListReq) ([]*dbstruct.StreamerAuthApprovalBasic, error) {
list, err := p.store.GetStreamerAuthApprovalBasicList(ctx, req)
if err != nil {
logger.Error("GetStreamerAuthApprovalBasicList fail, err: %v", err)
return make([]*dbstruct.StreamerAuthApprovalBasic, 0), err
}
return list, nil
}
func (p *StreamerAuthApprovalBasic) OpListByMid(ctx *gin.Context, req *streamerauthapprovalbasicproto.OpListByMidReq) (*dbstruct.StreamerAuthApprovalBasic, error) {
streamerauthapprovalbasic, err := p.store.GetStreamerAuthApprovalBasicListByMid(ctx, req)
if err != nil {
logger.Error("GetStreamerAuthApprovalBasicList fail, err: %v", err)
return nil, err
}
return streamerauthapprovalbasic, nil
}
func (p *StreamerAuthApprovalBasic) OpUpdateStreamerAuthApprovalBasicByIdsAndApproveStatus(ctx *gin.Context, req *streamerauthapprovalbasicproto.OpUpdateByIdsReq) error {
err := p.store.UpdateStreamerAuthApprovalBasicByIdsAndApproveStatus(ctx, req.StreamerAuthApprovalBasic, req.Ids, req.ApproveStatus)
if err != nil {
logger.Error("UpdateStreamerAuthApprovalBasicByIds fail, err: %v", err)
return err
}
return nil
}
func (p *StreamerAuthApprovalBasic) GetStreamerAuthApprovalBasicListByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.StreamerAuthApprovalBasic, error) {
list, err := p.store.GetStreamerAuthApprovalBasicListByIds(ctx, ids)
if err != nil {
logger.Error("GetBannerListByIds fail, ids: %v, err: %v", ids, err)
return make([]*dbstruct.StreamerAuthApprovalBasic, 0), err
}
return list, nil
}