refactor: reorganize modules and add Linux build tooling
This commit is contained in:
48
module/ec/market/internal/logic/supply/create.go
Normal file
48
module/ec/market/internal/logic/supply/create.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 新增供应商
|
||||
func Create(ctx context.Context, in *pb.MarketSupplyItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
// _, err = service.ParseMetaCtx(ctx, nil)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
if in.GetName() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
salt := utils.RandomString(8)
|
||||
mktModel := &models.MarketSupply{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.ULID(), Status: 1},
|
||||
Name: in.GetName(),
|
||||
// Avatar: in.GetAvatar(),
|
||||
Account: in.GetAccount(),
|
||||
Phone: in.GetPhone(),
|
||||
Password: utils.Md5(in.Password + salt),
|
||||
Salt: salt,
|
||||
OrgName: in.GetOrgName(),
|
||||
Remark: in.GetRemark(),
|
||||
CommissionRate: in.GetCommissionRate(),
|
||||
}
|
||||
if err := models.DBService.Create(&mktModel).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: mktModel.Identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
38
module/ec/market/internal/logic/supply/delete.go
Normal file
38
module/ec/market/internal/logic/supply/delete.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/ec/market/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, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
if err := models.DBService.Where("id = ? or identity = ?", in.GetId(), in.GetIdentity()).Delete(&models.MarketSupply{}).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
43
module/ec/market/internal/logic/supply/fetch.go
Normal file
43
module/ec/market/internal/logic/supply/fetch.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 供应商列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.SupplyReply, err error) {
|
||||
var (
|
||||
cnt int64 = 0
|
||||
Offset int64 = (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
data = make([]*models.MarketSupply, 0)
|
||||
)
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
tx := models.DBService.Model(&models.MarketSupply{}).Where("status = ?", 1)
|
||||
if in.GetIdentity() != "" {
|
||||
tx.Where("identity = ?", in.GetIdentity())
|
||||
}
|
||||
if err := tx.Order("created_at desc").Count(&cnt).Limit(int(in.GetPageSize())).Offset(int(Offset)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.SupplyReply{
|
||||
Data: ref(data),
|
||||
Count: int64(len(data)),
|
||||
}, nil
|
||||
}
|
||||
40
module/ec/market/internal/logic/supply/get.go
Normal file
40
module/ec/market/internal/logic/supply/get.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取一个供应商
|
||||
func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.MarketSupplyItem, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mktModel := models.MarketSupply{}
|
||||
if err := models.DBService.Where("identity=?", in.GetIdentity()).First(&mktModel).Error; err != nil {
|
||||
log.Println("获取供应商数据失败:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.MarketSupplyItem{
|
||||
Id: int32(mktModel.ID),
|
||||
Identity: mktModel.Identity,
|
||||
Name: mktModel.Name,
|
||||
Avatar: mktModel.Avatar,
|
||||
Account: mktModel.Account,
|
||||
Phone: mktModel.Phone,
|
||||
OrgName: mktModel.OrgName,
|
||||
OrgPhoto: mktModel.OrgPhoto,
|
||||
IdName: mktModel.IDName,
|
||||
IdBefore: mktModel.IDBefore,
|
||||
IdAfter: mktModel.IDAfter,
|
||||
Remark: mktModel.Remark,
|
||||
}, nil
|
||||
}
|
||||
48
module/ec/market/internal/logic/supply/modify.go
Normal file
48
module/ec/market/internal/logic/supply/modify.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 更新供应商数据
|
||||
func Modify(ctx context.Context, in *pb.MarketSupplyItem) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
mktModel := &models.MarketSupply{
|
||||
Name: in.GetName(),
|
||||
Avatar: in.GetAvatar(),
|
||||
Account: in.GetAccount(),
|
||||
Phone: in.GetPhone(),
|
||||
OrgName: in.GetOrgName(),
|
||||
OrgPhoto: in.GetOrgPhoto(),
|
||||
IDName: in.GetIdName(),
|
||||
IDBefore: in.GetIdBefore(),
|
||||
IDAfter: in.GetIdAfter(),
|
||||
Remark: in.GetRemark(),
|
||||
CommissionRate: in.GetCommissionRate(),
|
||||
}
|
||||
if err := models.DBService.Where("identity=?", in.GetIdentity()).Updates(&mktModel).Error; err != nil {
|
||||
log.Println("更新供应商数据失败:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: mktModel.Identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
34
module/ec/market/internal/logic/supply/ref.go
Normal file
34
module/ec/market/internal/logic/supply/ref.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
)
|
||||
|
||||
func ref(data []*models.MarketSupply) (list []*pb.MarketSupplyItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.MarketSupplyItem{
|
||||
Id: int32(in.ID),
|
||||
Identity: in.Identity,
|
||||
Name: in.Name,
|
||||
Avatar: in.Avatar,
|
||||
Account: in.Account,
|
||||
Phone: in.Phone,
|
||||
OrgName: in.OrgName,
|
||||
OrgPhoto: in.OrgPhoto,
|
||||
IdName: in.IDName,
|
||||
IdBefore: in.IDBefore,
|
||||
IdAfter: in.IDAfter,
|
||||
Remark: in.Remark,
|
||||
CommissionRate: in.CommissionRate,
|
||||
Status: int32(in.Status),
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user