refactor: reorganize modules and add Linux build tooling
This commit is contained in:
82
module/ec/delivery/internal/logic/car/car_add_logic.go
Normal file
82
module/ec/delivery/internal/logic/car/car_add_logic.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package deliverylogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
"git.apinb.com/bsm-sdk/engine/service"
|
||||
"git.apinb.com/bsm-sdk/engine/utils"
|
||||
"bsm/full/module/ec/delivery/external/pb/delivery"
|
||||
"bsm/full/module/ec/delivery/internal/models"
|
||||
"bsm/full/module/ec/delivery/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CarAddLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCarAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarAddLogic {
|
||||
return &CarAddLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 添加配送车辆信息
|
||||
func (l *CarAddLogic) CarAdd(in *delivery.CarItem) (*delivery.StatusReply, error) {
|
||||
_, err := service.ParseMetaCtx(l.ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = carAddChick(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := models.DeliveryCar{
|
||||
Identity: utils.ULID(),
|
||||
Brand: in.Brand,
|
||||
Version: in.Version,
|
||||
TeamIdentity: in.TeamIdentity,
|
||||
LicenseNumber: in.LicenseNumber,
|
||||
Contacts: in.Contacts,
|
||||
Phone: in.Phone,
|
||||
Picture: in.Picture,
|
||||
}
|
||||
|
||||
err = models.DBService.Create(&data).Error
|
||||
if err != nil {
|
||||
l.Logger.Error(err.Error())
|
||||
return nil, exception.ErrDBFatal
|
||||
}
|
||||
|
||||
return &delivery.StatusReply{Status: 200, Identity: data.Identity, Message: ""}, nil
|
||||
}
|
||||
func carAddChick(in *delivery.CarItem) error {
|
||||
if in.GetBrand() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
if in.GetPhone() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
// if in.GetTeamIdentity() == "" {
|
||||
// return exception.ErrInvalidArgument
|
||||
// }
|
||||
if in.GetContacts() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
if in.GetVersion() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
if in.GetPicture() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
if in.GetLicenseNumber() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
return nil
|
||||
}
|
||||
46
module/ec/delivery/internal/logic/car/car_del_logic.go
Normal file
46
module/ec/delivery/internal/logic/car/car_del_logic.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package deliverylogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
"git.apinb.com/bsm-sdk/engine/service"
|
||||
"bsm/full/module/ec/delivery/external/pb/delivery"
|
||||
"bsm/full/module/ec/delivery/internal/models"
|
||||
"bsm/full/module/ec/delivery/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CarDelLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCarDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarDelLogic {
|
||||
return &CarDelLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 删除配送车辆信息
|
||||
func (l *CarDelLogic) CarDel(in *delivery.IdentRequest) (*delivery.StatusReply, error) {
|
||||
_, err := service.ParseMetaCtx(l.ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, exception.ErrInvalidArgument
|
||||
}
|
||||
//Todo: 删除是是否判定有未完成订单不能删除
|
||||
|
||||
err = models.DBService.Where("identity = ?", in.Identity).Delete(&models.DeliveryCar{}).Error
|
||||
if err != nil {
|
||||
l.Logger.Error(err.Error())
|
||||
return nil, exception.ErrDBFatal
|
||||
}
|
||||
return &delivery.StatusReply{Status: 200, Identity: in.Identity, Message: ""}, nil
|
||||
}
|
||||
51
module/ec/delivery/internal/logic/car/car_get_logic.go
Normal file
51
module/ec/delivery/internal/logic/car/car_get_logic.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package deliverylogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
"git.apinb.com/bsm-sdk/engine/service"
|
||||
"bsm/full/module/ec/delivery/external/pb/delivery"
|
||||
"bsm/full/module/ec/delivery/internal/models"
|
||||
"bsm/full/module/ec/delivery/internal/svc"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CarGetLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCarGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarGetLogic {
|
||||
return &CarGetLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 获取配送车辆信息
|
||||
func (l *CarGetLogic) CarGet(in *delivery.IdentRequest) (*delivery.CarItem, error) {
|
||||
_, err := service.ParseMetaCtx(l.ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, exception.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var data = delivery.CarItem{}
|
||||
err = models.DBService.Model(&models.DeliveryCar{}).Where("identity = ?", in.Identity).Find(&data).Error
|
||||
if err != nil {
|
||||
l.Logger.Error(err.Error())
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, exception.ErrNotFound
|
||||
}
|
||||
return nil, exception.ErrDBFatal
|
||||
}
|
||||
return &data, nil
|
||||
}
|
||||
82
module/ec/delivery/internal/logic/car/car_list_logic.go
Normal file
82
module/ec/delivery/internal/logic/car/car_list_logic.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package deliverylogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
"git.apinb.com/bsm-sdk/engine/service"
|
||||
"bsm/full/module/ec/delivery/external/pb/delivery"
|
||||
"bsm/full/module/ec/delivery/internal/models"
|
||||
"bsm/full/module/ec/delivery/internal/svc"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CarListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCarListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarListLogic {
|
||||
return &CarListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 配送车辆列表
|
||||
func (l *CarListLogic) CarList(in *delivery.FetchRequest) (*delivery.CarListReply, error) {
|
||||
_, err := service.ParseMetaCtx(l.ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
teamIdentity string = ""
|
||||
identity string = ""
|
||||
licenseNumber string = ""
|
||||
status int64 = 1
|
||||
cnt int64 = 0
|
||||
data = make([]*delivery.CarItem, 0)
|
||||
)
|
||||
|
||||
if in.GetParams()["identity"] != "" {
|
||||
identity = in.Params["identity"]
|
||||
}
|
||||
if in.GetParams()["team_identity"] != "" {
|
||||
teamIdentity = in.Params["team_identity"]
|
||||
}
|
||||
if in.GetParams()["license_number"] != "" {
|
||||
licenseNumber = in.Params["license_number"]
|
||||
}
|
||||
|
||||
if in.GetParams()["status"] == "-1" {
|
||||
status = -1
|
||||
}
|
||||
cnt, res, err := models.DeliverycarList(identity, teamIdentity, licenseNumber, status, int(in.PageSize), int(in.PageNo))
|
||||
if err != nil {
|
||||
l.Logger.Error(err.Error())
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, exception.ErrNotFound
|
||||
}
|
||||
return nil, exception.ErrDBFatal
|
||||
}
|
||||
for _, v := range res {
|
||||
item := delivery.CarItem{
|
||||
Identity: v.Identity,
|
||||
Brand: v.Brand,
|
||||
LicenseNumber: v.LicenseNumber,
|
||||
TeamIdentity: v.TeamIdentity,
|
||||
Contacts: v.Contacts,
|
||||
Picture: v.Picture,
|
||||
Phone: v.Phone,
|
||||
Status: v.Status,
|
||||
Version: v.Version,
|
||||
}
|
||||
data = append(data, &item)
|
||||
}
|
||||
return &delivery.CarListReply{Count: cnt, List: data}, nil
|
||||
}
|
||||
83
module/ec/delivery/internal/logic/car/car_set_logic.go
Normal file
83
module/ec/delivery/internal/logic/car/car_set_logic.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package deliverylogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
"git.apinb.com/bsm-sdk/engine/service"
|
||||
"bsm/full/module/ec/delivery/external/pb/delivery"
|
||||
"bsm/full/module/ec/delivery/internal/models"
|
||||
"bsm/full/module/ec/delivery/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CarSetLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCarSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarSetLogic {
|
||||
return &CarSetLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 修改配送车辆信息
|
||||
func (l *CarSetLogic) CarSet(in *delivery.CarItem) (*delivery.StatusReply, error) {
|
||||
_, err := service.ParseMetaCtx(l.ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = carSetChick(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := models.DeliveryCar{
|
||||
Brand: in.Brand,
|
||||
Version: in.Version,
|
||||
TeamIdentity: in.TeamIdentity,
|
||||
LicenseNumber: in.LicenseNumber,
|
||||
Contacts: in.Contacts,
|
||||
Phone: in.Phone,
|
||||
Picture: in.Picture,
|
||||
}
|
||||
|
||||
err = models.DBService.Where("identity = ?", in.Identity).Updates(&data).Error
|
||||
if err != nil {
|
||||
l.Logger.Error(err.Error())
|
||||
return nil, exception.ErrDBFatal
|
||||
}
|
||||
|
||||
return &delivery.StatusReply{Status: 200, Identity: in.Identity, Message: ""}, nil
|
||||
}
|
||||
func carSetChick(in *delivery.CarItem) error {
|
||||
if in.GetIdentity() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
if in.GetBrand() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
if in.GetPhone() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
// if in.GetTeamIdentity() == "" {
|
||||
// return exception.ErrInvalidArgument
|
||||
// }
|
||||
if in.GetContacts() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
if in.GetVersion() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
if in.GetPicture() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
if in.GetLicenseNumber() == "" {
|
||||
return exception.ErrInvalidArgument
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user