2023-12-21 22:17:40 +08:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"service/api/consts"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
#{moduleName}proto "service/api/proto/#{moduleName}/proto"
|
|
|
|
goproto "google.golang.org/protobuf/proto"
|
|
|
|
"service/app/mix/dao"
|
|
|
|
"service/dbstruct"
|
|
|
|
"service/library/idgenerator"
|
|
|
|
"service/library/logger"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type #{EntityName} struct {
|
|
|
|
store *dao.Store
|
|
|
|
}
|
|
|
|
|
|
|
|
func New#{EntityName}(store *dao.Store) (a *#{EntityName}) {
|
|
|
|
a = &#{EntityName}{
|
|
|
|
store: store,
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *#{EntityName}) OpCreate(ctx *gin.Context, req *#{moduleName}proto.OpCreateReq) error {
|
|
|
|
req.#{EntityName}.Id = goproto.Int64(idgenerator.Gen#{EntityName}Id())
|
|
|
|
req.#{EntityName}.Ct = goproto.Int64(time.Now().Unix())
|
|
|
|
req.#{EntityName}.Ut = goproto.Int64(time.Now().Unix())
|
|
|
|
req.#{EntityName}.DelFlag = goproto.Int64(consts.Exist)
|
|
|
|
err := p.store.Create#{EntityName}(ctx, req.#{EntityName})
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("Create#{EntityName} fail, err: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *#{EntityName}) OpUpdate(ctx *gin.Context, req *#{moduleName}proto.OpUpdateReq) error {
|
|
|
|
err := p.store.Update#{EntityName}(ctx, req.#{EntityName})
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("Update#{EntityName} fail, err: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *#{EntityName}) OpDelete(ctx *gin.Context, id int64) error {
|
|
|
|
err := p.store.Delete#{EntityName}(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("Delete#{EntityName} fail, err: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *#{EntityName}) OpList(ctx *gin.Context, req *#{moduleName}proto.OpListReq) ([]*dbstruct.#{EntityName}, error) {
|
|
|
|
list, err := p.store.Get#{EntityName}List(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("Get#{EntityName}List fail, err: %v", err)
|
|
|
|
return make([]*dbstruct.#{EntityName}, 0), err
|
|
|
|
}
|
|
|
|
return list, nil
|
|
|
|
}
|
|
|
|
|
2024-12-06 13:16:00 +08:00
|
|
|
func (p *#{EntityName}) GetById(ctx *gin.Context, id int64) (*dbstruct.#{EntityName}, error) {
|
|
|
|
one, err := p.store.Get#{EntityName}ById(ctx, id)
|
2023-12-21 22:17:40 +08:00
|
|
|
if err != nil {
|
2024-12-06 13:16:00 +08:00
|
|
|
logger.Error("Get#{EntityName}ByIds fail, ids: %v, err: %v", ids, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return one, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *#{EntityName}) GetByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.#{EntityName}, error) {
|
|
|
|
list, err := p.store.Get#{EntityName}ByIds(ctx, ids)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("Get#{EntityName}ByIds fail, ids: %v, err: %v", ids, err)
|
2023-12-21 22:17:40 +08:00
|
|
|
return make([]*dbstruct.#{EntityName}, 0), err
|
|
|
|
}
|
|
|
|
return list, nil
|
|
|
|
}
|