refactor: 将 DTO 文件从 internal/model 移动到 internal/model/dto 目录
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m22s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m22s
- 移动 17 个 DTO 文件到 internal/model/dto/ 目录 - 更新所有 DTO 文件的 package 声明从 model 改为 dto - 更新所有引用文件的 import 和类型引用 - Handler 层:admin 和 h5 所有处理器 - Service 层:所有业务服务 - Routes 层:所有路由定义 - Tests 层:单元测试和集成测试 - 清理未使用的 import 语句 - 验证:项目构建成功,测试编译通过,LSP 无错误
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
@@ -31,7 +32,7 @@ func New(
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, req *model.AllocateCardsPreviewReq) (*model.AllocateCardsPreviewResp, error) {
|
||||
func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, req *dto.AllocateCardsPreviewReq) (*dto.AllocateCardsPreviewResp, error) {
|
||||
currentUserID := middleware.GetUserIDFromContext(ctx)
|
||||
if currentUserID == 0 {
|
||||
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
|
||||
@@ -84,10 +85,10 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
|
||||
}
|
||||
}
|
||||
|
||||
resp := &model.AllocateCardsPreviewResp{
|
||||
StandaloneCards: make([]model.StandaloneCard, 0),
|
||||
DeviceBundles: make([]model.DeviceBundle, 0),
|
||||
FailedItems: make([]model.FailedItem, 0),
|
||||
resp := &dto.AllocateCardsPreviewResp{
|
||||
StandaloneCards: make([]dto.StandaloneCard, 0),
|
||||
DeviceBundles: make([]dto.DeviceBundle, 0),
|
||||
FailedItems: make([]dto.FailedItem, 0),
|
||||
}
|
||||
|
||||
processedDevices := make(map[uint]bool)
|
||||
@@ -95,7 +96,7 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
|
||||
for _, iccid := range req.ICCIDs {
|
||||
card, exists := cardMap[iccid]
|
||||
if !exists {
|
||||
resp.FailedItems = append(resp.FailedItems, model.FailedItem{
|
||||
resp.FailedItems = append(resp.FailedItems, dto.FailedItem{
|
||||
ICCID: iccid,
|
||||
Reason: "卡不存在",
|
||||
})
|
||||
@@ -104,7 +105,7 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
|
||||
|
||||
deviceID, hasDevice := cardToDevice[card.ID]
|
||||
if !hasDevice {
|
||||
resp.StandaloneCards = append(resp.StandaloneCards, model.StandaloneCard{
|
||||
resp.StandaloneCards = append(resp.StandaloneCards, dto.StandaloneCard{
|
||||
ICCID: card.ICCID,
|
||||
IotCardID: card.ID,
|
||||
MSISDN: card.MSISDN,
|
||||
@@ -123,10 +124,10 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
|
||||
}
|
||||
|
||||
bundleCardIDs := deviceCards[deviceID]
|
||||
bundle := model.DeviceBundle{
|
||||
bundle := dto.DeviceBundle{
|
||||
DeviceID: deviceID,
|
||||
DeviceNo: device.DeviceNo,
|
||||
BundleCards: make([]model.DeviceBundleCard, 0),
|
||||
BundleCards: make([]dto.DeviceBundleCard, 0),
|
||||
}
|
||||
|
||||
for _, bundleCardID := range bundleCardIDs {
|
||||
@@ -135,13 +136,13 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
|
||||
continue
|
||||
}
|
||||
if bundleCard.ID == card.ID {
|
||||
bundle.TriggerCard = model.DeviceBundleCard{
|
||||
bundle.TriggerCard = dto.DeviceBundleCard{
|
||||
ICCID: bundleCard.ICCID,
|
||||
IotCardID: bundleCard.ID,
|
||||
MSISDN: bundleCard.MSISDN,
|
||||
}
|
||||
} else {
|
||||
bundle.BundleCards = append(bundle.BundleCards, model.DeviceBundleCard{
|
||||
bundle.BundleCards = append(bundle.BundleCards, dto.DeviceBundleCard{
|
||||
ICCID: bundleCard.ICCID,
|
||||
IotCardID: bundleCard.ID,
|
||||
MSISDN: bundleCard.MSISDN,
|
||||
@@ -158,7 +159,7 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
|
||||
deviceCardCount += 1 + len(bundle.BundleCards)
|
||||
}
|
||||
|
||||
resp.Summary = model.AllocatePreviewSummary{
|
||||
resp.Summary = dto.AllocatePreviewSummary{
|
||||
StandaloneCardCount: len(resp.StandaloneCards),
|
||||
DeviceCount: len(resp.DeviceBundles),
|
||||
DeviceCardCount: deviceCardCount,
|
||||
@@ -169,7 +170,7 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *model.AllocateCardsReq) (*model.AllocateCardsResp, error) {
|
||||
func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *dto.AllocateCardsReq) (*dto.AllocateCardsResp, error) {
|
||||
currentUserID := middleware.GetUserIDFromContext(ctx)
|
||||
currentShopID := middleware.GetShopIDFromContext(ctx)
|
||||
if currentUserID == 0 {
|
||||
@@ -181,7 +182,7 @@ func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *mod
|
||||
return nil, errors.New(errors.CodeEnterpriseNotFound, "企业不存在")
|
||||
}
|
||||
|
||||
preview, err := s.AllocateCardsPreview(ctx, enterpriseID, &model.AllocateCardsPreviewReq{ICCIDs: req.ICCIDs})
|
||||
preview, err := s.AllocateCardsPreview(ctx, enterpriseID, &dto.AllocateCardsPreviewReq{ICCIDs: req.ICCIDs})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -190,10 +191,10 @@ func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *mod
|
||||
return nil, errors.New(errors.CodeInvalidParam, "存在设备包,请确认整体授权设备下所有卡")
|
||||
}
|
||||
|
||||
resp := &model.AllocateCardsResp{
|
||||
resp := &dto.AllocateCardsResp{
|
||||
FailedItems: preview.FailedItems,
|
||||
FailCount: len(preview.FailedItems),
|
||||
AllocatedDevices: make([]model.AllocatedDevice, 0),
|
||||
AllocatedDevices: make([]dto.AllocatedDevice, 0),
|
||||
}
|
||||
|
||||
cardIDsToAllocate := make([]uint, 0)
|
||||
@@ -209,7 +210,7 @@ func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *mod
|
||||
for _, card := range bundle.BundleCards {
|
||||
iccids = append(iccids, card.ICCID)
|
||||
}
|
||||
resp.AllocatedDevices = append(resp.AllocatedDevices, model.AllocatedDevice{
|
||||
resp.AllocatedDevices = append(resp.AllocatedDevices, dto.AllocatedDevice{
|
||||
DeviceID: bundle.DeviceID,
|
||||
DeviceNo: bundle.DeviceNo,
|
||||
CardCount: 1 + len(bundle.BundleCards),
|
||||
@@ -248,7 +249,7 @@ func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *mod
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *Service) RecallCards(ctx context.Context, enterpriseID uint, req *model.RecallCardsReq) (*model.RecallCardsResp, error) {
|
||||
func (s *Service) RecallCards(ctx context.Context, enterpriseID uint, req *dto.RecallCardsReq) (*dto.RecallCardsResp, error) {
|
||||
currentUserID := middleware.GetUserIDFromContext(ctx)
|
||||
if currentUserID == 0 {
|
||||
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
|
||||
@@ -278,23 +279,23 @@ func (s *Service) RecallCards(ctx context.Context, enterpriseID uint, req *model
|
||||
return nil, fmt.Errorf("查询已有授权失败: %w", err)
|
||||
}
|
||||
|
||||
resp := &model.RecallCardsResp{
|
||||
FailedItems: make([]model.FailedItem, 0),
|
||||
RecalledDevices: make([]model.RecalledDevice, 0),
|
||||
resp := &dto.RecallCardsResp{
|
||||
FailedItems: make([]dto.FailedItem, 0),
|
||||
RecalledDevices: make([]dto.RecalledDevice, 0),
|
||||
}
|
||||
|
||||
cardIDsToRecall := make([]uint, 0)
|
||||
for _, iccid := range req.ICCIDs {
|
||||
card, exists := cardMap[iccid]
|
||||
if !exists {
|
||||
resp.FailedItems = append(resp.FailedItems, model.FailedItem{
|
||||
resp.FailedItems = append(resp.FailedItems, dto.FailedItem{
|
||||
ICCID: iccid,
|
||||
Reason: "卡不存在",
|
||||
})
|
||||
continue
|
||||
}
|
||||
if !existingAuths[card.ID] {
|
||||
resp.FailedItems = append(resp.FailedItems, model.FailedItem{
|
||||
resp.FailedItems = append(resp.FailedItems, dto.FailedItem{
|
||||
ICCID: iccid,
|
||||
Reason: "该卡未授权给此企业",
|
||||
})
|
||||
@@ -314,7 +315,7 @@ func (s *Service) RecallCards(ctx context.Context, enterpriseID uint, req *model
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *model.EnterpriseCardListReq) (*model.EnterpriseCardPageResult, error) {
|
||||
func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *dto.EnterpriseCardListReq) (*dto.EnterpriseCardPageResult, error) {
|
||||
_, err := s.enterpriseStore.GetByID(ctx, enterpriseID)
|
||||
if err != nil {
|
||||
return nil, errors.New(errors.CodeEnterpriseNotFound, "企业不存在")
|
||||
@@ -326,8 +327,8 @@ func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *model.E
|
||||
}
|
||||
|
||||
if len(cardIDs) == 0 {
|
||||
return &model.EnterpriseCardPageResult{
|
||||
Items: make([]model.EnterpriseCardItem, 0),
|
||||
return &dto.EnterpriseCardPageResult{
|
||||
Items: make([]dto.EnterpriseCardItem, 0),
|
||||
Total: 0,
|
||||
Page: req.Page,
|
||||
Size: req.PageSize,
|
||||
@@ -366,9 +367,9 @@ func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *model.E
|
||||
return nil, fmt.Errorf("查询卡列表失败: %w", err)
|
||||
}
|
||||
|
||||
items := make([]model.EnterpriseCardItem, 0, len(cards))
|
||||
items := make([]dto.EnterpriseCardItem, 0, len(cards))
|
||||
for _, card := range cards {
|
||||
items = append(items, model.EnterpriseCardItem{
|
||||
items = append(items, dto.EnterpriseCardItem{
|
||||
ID: card.ID,
|
||||
ICCID: card.ICCID,
|
||||
MSISDN: card.MSISDN,
|
||||
@@ -380,7 +381,7 @@ func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *model.E
|
||||
})
|
||||
}
|
||||
|
||||
return &model.EnterpriseCardPageResult{
|
||||
return &dto.EnterpriseCardPageResult{
|
||||
Items: items,
|
||||
Total: total,
|
||||
Page: page,
|
||||
|
||||
Reference in New Issue
Block a user