service/app/mix/service/logic/realname_authentication.go

149 lines
4.7 KiB
Go

package logic
import (
"service/api/consts"
realname_authenticationproto "service/api/proto/realname_authentication/proto"
"service/app/mix/dao"
"service/dbstruct"
"service/library/logger"
interceptor "service/library/taginterceptor"
"time"
"github.com/gin-gonic/gin"
"github.com/qiniu/qmgo"
goproto "google.golang.org/protobuf/proto"
)
type RealNameAuthentication struct {
store *dao.Store
}
func NewRealNameAuthentication(store *dao.Store) (a *RealNameAuthentication) {
a = &RealNameAuthentication{
store: store,
}
return
}
func (p *RealNameAuthentication) OpCreate(ctx *gin.Context, req *realname_authenticationproto.OpCreateReq) error {
//生成自增id
realNameAuthenticationSeqId, err := p.store.GetAndUpdateRealNameAuthenticationIdSeq(ctx)
if err != nil {
logger.Error("GetAndUpdateRealNameAuthenticationIdSeq fail, err: %v", err)
return err
}
req.RealNameAuthentication.Id = goproto.Int64(realNameAuthenticationSeqId.Seq)
req.RealNameAuthentication.Ct = goproto.Int64(time.Now().Unix())
req.RealNameAuthentication.Ut = goproto.Int64(time.Now().Unix())
req.RealNameAuthentication.DelFlag = goproto.Int64(consts.Exist)
req.RealNameAuthentication.Status = goproto.Int64(consts.RealNameAuthentication_Created) //默认已创建
err = interceptor.EncryptTagInterceptorInstance().Intercept(req.RealNameAuthentication, "bcrypto")
if err != nil {
logger.Error("RealNameAuthentication encryption err : %v", err)
return err
}
err = p.store.CreateRealNameAuthentication(ctx, req.RealNameAuthentication)
if err != nil {
logger.Error("CreateRealNameAuthentication fail, err: %v", err)
return err
}
return nil
}
func (p *RealNameAuthentication) OpUpdate(ctx *gin.Context, req *realname_authenticationproto.OpUpdateReq) error {
err := interceptor.EncryptTagInterceptorInstance().Intercept(req.RealNameAuthentication, "bcrypto")
if err != nil {
logger.Error("RealNameAuthentication encryption err : %v", err)
return err
}
err = p.store.UpdateRealNameAuthentication(ctx, req.RealNameAuthentication)
if err != nil {
logger.Error("UpdateRealNameAuthentication fail, err: %v", err)
return err
}
return nil
}
func (p *RealNameAuthentication) OpDeleteBatch(ctx *gin.Context, ids []int64) error {
//1.查出原有实名认证申请
list, err := p.store.GetRealNameAuthenticationListByIds(ctx, ids)
if len(list) == 0 {
logger.Error("GetRealNameAuthenticationListByIds fail, err: %v", qmgo.ErrNoSuchDocuments)
return qmgo.ErrNoSuchDocuments
}
if err != nil {
logger.Error("GetRealNameAuthenticationListByIds fail, err: %v", err)
return err
}
//2.原有实名认证申请标记删除后转存到历史表
for _, realname_authentication := range list {
realname_authentication.DelFlag = goproto.Int64(consts.Deleted)
}
err = p.store.CreateBatchRealNameAuthenticationHis(ctx, list)
if err != nil {
logger.Error("CreateBatchRealNameAuthenticationHis fail, err: %v", err)
return err
}
//3.真删除原有实名认证申请
err = p.store.DeleteRealNameAuthenticationByIds(ctx, ids)
if err != nil {
logger.Error("DeleteRealNameAuthenticationByIds fail, err: %v", err)
return err
}
return nil
}
func (p *RealNameAuthentication) OpUpdateRealNameAuthenticationByIds(ctx *gin.Context, req *realname_authenticationproto.OpUpdateByIdsReq) error {
err := interceptor.EncryptTagInterceptorInstance().Intercept(req.RealNameAuthentication, "bcrypto")
if err != nil {
logger.Error("RealNameAuthentication encryption err : %v", err)
return err
}
err = p.store.UpdateRealNameAuthenticationByIds(ctx, req.RealNameAuthentication, req.Ids)
if err != nil {
logger.Error("UpdateRealNameAuthenticationByIds fail, err: %v", err)
return err
}
return nil
}
func (p *RealNameAuthentication) OpList(ctx *gin.Context, req *realname_authenticationproto.OpListReq) ([]*dbstruct.RealNameAuthentication, error) {
list, err := p.store.GetRealNameAuthenticationList(ctx, req)
if err != nil {
logger.Error("GetRealNameAuthenticationList fail, err: %v", err)
return make([]*dbstruct.RealNameAuthentication, 0), err
}
type CryptoBlock struct {
List []*dbstruct.RealNameAuthentication `bcrypto:"true"`
}
data := &CryptoBlock{
List: list,
}
err = interceptor.DecryptTagInterceptorInstance().Intercept(data, "bcrypto")
if err != nil {
logger.Error("RealNameAuthentication decryption err : %v", err)
return nil, err
}
return data.List, nil
}
func (p *RealNameAuthentication) OpListByMid(ctx *gin.Context, req *realname_authenticationproto.OpListByMidReq) (*dbstruct.RealNameAuthentication, error) {
realname_authentication, err := p.store.GetRealNameAuthenticationListByMid(ctx, req)
if err != nil {
logger.Error("GetRealNameAuthenticationListByMid fail, err: %v", err)
return nil, err
}
return realname_authentication, nil
}