refactor: reorganize modules and add Linux build tooling
This commit is contained in:
29
module/ec/mall/internal/logic/ads/by_pos.go
Normal file
29
module/ec/mall/internal/logic/ads/by_pos.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package ads
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bsm/full/module/ec/mall/internal/impl"
|
||||
"bsm/full/module/ec/mall/internal/models"
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
)
|
||||
|
||||
// 通过广告位获取广告信息
|
||||
func ByPos(ctx context.Context, in *pb.ByPosRequest) (reply *pb.AdsListReply, err error) {
|
||||
if in.GetStoreIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
result := make([]*pb.AdsItem, 0)
|
||||
|
||||
err = impl.DBService.Model(&models.MallAds{}).Where("store_identity=? and pos_key in ?", in.StoreIdentity, in.PosKey).Find(&result).Error
|
||||
if err != nil {
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.AdsListReply{
|
||||
Data: result,
|
||||
Count: int64(len(result)),
|
||||
}, nil
|
||||
}
|
||||
54
module/ec/mall/internal/logic/ads/create.go
Normal file
54
module/ec/mall/internal/logic/ads/create.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package ads
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/mall/internal/impl"
|
||||
"bsm/full/module/ec/mall/internal/models"
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 新建广告
|
||||
func Create(ctx context.Context, in *pb.AdsItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
AUTH, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetTitle() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 参数转换
|
||||
data := models.MallAds{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID(), Status: 1},
|
||||
Title: in.Title,
|
||||
PosKey: in.PosKey,
|
||||
Content: in.Content,
|
||||
Type: models.ContentType(in.Type),
|
||||
ToUrl: in.ToUrl,
|
||||
}
|
||||
owner := AUTH.Owner.(map[string]any)
|
||||
data.Store_ID = uint(owner["store_id"].(float64))
|
||||
data.Store_Identity = owner["store_identity"].(string)
|
||||
|
||||
err = impl.DBService.Create(&data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Identity: data.Identity,
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
40
module/ec/mall/internal/logic/ads/delete.go
Normal file
40
module/ec/mall/internal/logic/ads/delete.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package ads
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/mall/internal/impl"
|
||||
"bsm/full/module/ec/mall/internal/models"
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 删除广告
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).Delete(&models.MallAds{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
50
module/ec/mall/internal/logic/ads/fetch.go
Normal file
50
module/ec/mall/internal/logic/ads/fetch.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package ads
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bsm/full/module/ec/mall/internal/impl"
|
||||
"bsm/full/module/ec/mall/internal/models"
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
)
|
||||
|
||||
// 广告列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.AdsListReply, err error) {
|
||||
if in.GetStoreIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
pageNo int64 = in.GetPageNo()
|
||||
pageSize int64 = in.GetPageSize()
|
||||
offset int64 = (pageNo - 1) * pageSize
|
||||
params = map[string]string{
|
||||
"store_identity": in.GetStoreIdentity(),
|
||||
}
|
||||
)
|
||||
|
||||
// vlidate request page_no,page_size.
|
||||
if pageNo < 1 {
|
||||
pageNo = 1
|
||||
offset = 0
|
||||
}
|
||||
if pageSize < 50 {
|
||||
pageSize = 50
|
||||
offset = (pageNo - 1) * pageSize
|
||||
}
|
||||
|
||||
var data []*models.MallAds
|
||||
if err := impl.DBService.Model(&models.MallAds{}).Where(params).Order("created_at desc").Count(&cnt).Offset(int(offset)).
|
||||
Limit(int(pageSize)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.AdsListReply{
|
||||
Count: cnt,
|
||||
Data: ref(data),
|
||||
}, nil
|
||||
}
|
||||
50
module/ec/mall/internal/logic/ads/modify.go
Normal file
50
module/ec/mall/internal/logic/ads/modify.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package ads
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/mall/internal/impl"
|
||||
"bsm/full/module/ec/mall/internal/models"
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// 修改广告
|
||||
func Modify(ctx context.Context, in *pb.AdsItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valid must params.
|
||||
if in.GetId() == 0 {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
data := models.MallAds{
|
||||
Title: in.Title,
|
||||
PosKey: in.PosKey,
|
||||
Content: in.Content,
|
||||
Type: models.ContentType(in.Type),
|
||||
ToUrl: in.ToUrl,
|
||||
Std_IICUDS: types.Std_IICUDS{Status: int8(in.GetStatus())},
|
||||
}
|
||||
|
||||
err = impl.DBService.Select("title", "pos_key", "content", "type", "to_url").Where("id=?", in.GetId()).Updates(&data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
28
module/ec/mall/internal/logic/ads/ref.go
Normal file
28
module/ec/mall/internal/logic/ads/ref.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package ads
|
||||
|
||||
import (
|
||||
"bsm/full/module/ec/mall/internal/models"
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
func ref(data []*models.MallAds) (list []*pb.AdsItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.AdsItem{
|
||||
Id: int64(in.ID),
|
||||
Title: in.Title,
|
||||
PosKey: in.PosKey,
|
||||
Content: in.Content,
|
||||
Type: int32(in.Type),
|
||||
ToUrl: in.ToUrl,
|
||||
CreatedAt: in.CreatedAt.Format(vars.YYYY_MM_DD_HH_MM_SS),
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user