fix
This commit is contained in:
@@ -20,7 +20,7 @@ database:
|
|||||||
logger:
|
logger:
|
||||||
level: info
|
level: info
|
||||||
format: json
|
format: json
|
||||||
output: "file"
|
output: "console"
|
||||||
log_dir: "logs"
|
log_dir: "logs"
|
||||||
max_size: 100
|
max_size: 100
|
||||||
max_backups: 5
|
max_backups: 5
|
||||||
|
|||||||
@@ -186,6 +186,11 @@ type IVYZ1C9DReq struct {
|
|||||||
Years int64 `json:"years" validate:"omitempty,min=0,max=100"`
|
Years int64 `json:"years" validate:"omitempty,min=0,max=100"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IVYZGZ08Req struct {
|
||||||
|
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||||
|
Name string `json:"name" validate:"required,min=1,validName"`
|
||||||
|
}
|
||||||
|
|
||||||
type FLXG8A3FReq struct {
|
type FLXG8A3FReq struct {
|
||||||
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||||
Name string `json:"name" validate:"required,min=1,validName"`
|
Name string `json:"name" validate:"required,min=1,validName"`
|
||||||
@@ -197,10 +202,11 @@ type FLXG5B2EReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type COMB298YReq struct {
|
type COMB298YReq struct {
|
||||||
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||||
Name string `json:"name" validate:"required,min=1,validName"`
|
Name string `json:"name" validate:"required,min=1,validName"`
|
||||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||||
AuthDate string `json:"auth_date" validate:"required,validAuthDate" encrypt:"false"`
|
AuthDate string `json:"auth_date" validate:"required,validAuthDate" encrypt:"false"`
|
||||||
|
TimeRange string `json:"time_range" validate:"omitempty,validTimeRange"` // 非必填字段
|
||||||
}
|
}
|
||||||
|
|
||||||
type COMB86PMReq struct {
|
type COMB86PMReq struct {
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ func registerAllProcessors(combService *comb.CombService) {
|
|||||||
"FLXGDEC7": flxg.ProcessFLXGDEC7Request,
|
"FLXGDEC7": flxg.ProcessFLXGDEC7Request,
|
||||||
"FLXG8A3F": flxg.ProcessFLXG8A3FRequest,
|
"FLXG8A3F": flxg.ProcessFLXG8A3FRequest,
|
||||||
"FLXG5B2E": flxg.ProcessFLXG5B2ERequest,
|
"FLXG5B2E": flxg.ProcessFLXG5B2ERequest,
|
||||||
|
"FLXG0687": flxg.ProcessFLXG0687Request,
|
||||||
|
|
||||||
// JRZQ系列处理器
|
// JRZQ系列处理器
|
||||||
"JRZQ8203": jrzq.ProcessJRZQ8203Request,
|
"JRZQ8203": jrzq.ProcessJRZQ8203Request,
|
||||||
@@ -117,6 +118,7 @@ func registerAllProcessors(combService *comb.CombService) {
|
|||||||
"IVYZ7F2A": ivyz.ProcessIVYZ7F2ARequest,
|
"IVYZ7F2A": ivyz.ProcessIVYZ7F2ARequest,
|
||||||
"IVYZ4E8B": ivyz.ProcessIVYZ4E8BRequest,
|
"IVYZ4E8B": ivyz.ProcessIVYZ4E8BRequest,
|
||||||
"IVYZ1C9D": ivyz.ProcessIVYZ1C9DRequest,
|
"IVYZ1C9D": ivyz.ProcessIVYZ1C9DRequest,
|
||||||
|
"IVYZGZ08": ivyz.ProcessIVYZGZ08Request,
|
||||||
|
|
||||||
// COMB系列处理器
|
// COMB系列处理器
|
||||||
"COMB298Y": comb.ProcessCOMB298YRequest,
|
"COMB298Y": comb.ProcessCOMB298YRequest,
|
||||||
|
|||||||
@@ -36,19 +36,24 @@ func ProcessFLXG3D56Request(ctx context.Context, params []byte, deps *processors
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
encryptedTimeRange, err := deps.WestDexService.Encrypt(paramsDto.TimeRange)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
|
||||||
}
|
|
||||||
reqData := map[string]interface{}{
|
reqData := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"data": map[string]interface{}{
|
||||||
"name": encryptedName,
|
"name": encryptedName,
|
||||||
"id": encryptedIDCard,
|
"id": encryptedIDCard,
|
||||||
"cell": encryptedMobileNo,
|
"cell": encryptedMobileNo,
|
||||||
"time_range": encryptedTimeRange,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 只有当 TimeRange 不为空时才加密和传参
|
||||||
|
if paramsDto.TimeRange != "" {
|
||||||
|
encryptedTimeRange, err := deps.WestDexService.Encrypt(paramsDto.TimeRange)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
reqData["data"].(map[string]interface{})["time_range"] = encryptedTimeRange
|
||||||
|
}
|
||||||
|
|
||||||
respBytes, err := deps.WestDexService.CallAPI("G26BJ05", reqData)
|
respBytes, err := deps.WestDexService.CallAPI("G26BJ05", reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, westdex.ErrDatasource) {
|
if errors.Is(err, westdex.ErrDatasource) {
|
||||||
|
|||||||
@@ -35,14 +35,18 @@ func ProcessFLXGCA3DRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
reqData := map[string]interface{}{
|
reqData := map[string]interface{}{
|
||||||
"data": map[string]interface{}{
|
"data": map[string]interface{}{
|
||||||
"name": encryptedName,
|
"name": encryptedName,
|
||||||
"idcard": encryptedIDCard,
|
"id_card": encryptedIDCard,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
respBytes, err := deps.WestDexService.CallAPI("G22BJ03", reqData)
|
respBytes, err := deps.WestDexService.CallAPI("G22BJ03", reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, westdex.ErrDatasource) {
|
if errors.Is(err, westdex.ErrDatasource) {
|
||||||
return nil, fmt.Errorf("%s: %w", processors.ErrDatasource, err)
|
if respBytes != nil {
|
||||||
|
return respBytes, nil
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("%s: %w", processors.ErrDatasource, err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package ivyz
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"tyapi-server/internal/domains/api/dto"
|
||||||
|
"tyapi-server/internal/domains/api/services/processors"
|
||||||
|
"tyapi-server/internal/infrastructure/external/westdex"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProcessIVYZGZ08Request IVYZGZ08 API处理方法
|
||||||
|
func ProcessIVYZGZ08Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||||
|
var paramsDto dto.IVYZGZ08Req
|
||||||
|
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||||
|
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||||
|
return nil, fmt.Errorf("%s: %w", processors.ErrInvalidParam, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
encryptedName, err := deps.WestDexService.Encrypt(paramsDto.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
encryptedIDCard, err := deps.WestDexService.Encrypt(paramsDto.IDCard)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
reqData := map[string]interface{}{
|
||||||
|
"data": map[string]interface{}{
|
||||||
|
"xm": encryptedName,
|
||||||
|
"gmsfzhm": encryptedIDCard,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
respBytes, err := deps.WestDexService.CallAPI("G08SC02", reqData)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, westdex.ErrDatasource) {
|
||||||
|
return nil, fmt.Errorf("%s: %w", processors.ErrDatasource, err)
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return respBytes, nil
|
||||||
|
}
|
||||||
@@ -198,7 +198,7 @@ func (r *GormCertificationQueryRepository) ListByUserIDs(ctx context.Context, us
|
|||||||
}
|
}
|
||||||
|
|
||||||
var certifications []*entities.Certification
|
var certifications []*entities.Certification
|
||||||
if err := r.GetDB(ctx).Where("user_id IN ?", userIDs).Find(&certifications).Error; err != nil {
|
if err := r.GetDB(ctx).Where("user_id IN ?", userIDs).Order("created_at DESC").Find(&certifications).Error; err != nil {
|
||||||
return nil, fmt.Errorf("根据用户ID列表查询认证失败: %w", err)
|
return nil, fmt.Errorf("根据用户ID列表查询认证失败: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ func (r *GormCertificationQueryRepository) ListByUserIDs(ctx context.Context, us
|
|||||||
|
|
||||||
// ListByStatus 根据状态查询
|
// ListByStatus 根据状态查询
|
||||||
func (r *GormCertificationQueryRepository) ListByStatus(ctx context.Context, status enums.CertificationStatus, limit int) ([]*entities.Certification, error) {
|
func (r *GormCertificationQueryRepository) ListByStatus(ctx context.Context, status enums.CertificationStatus, limit int) ([]*entities.Certification, error) {
|
||||||
db := r.GetDB(ctx).Where("status = ?", status)
|
db := r.GetDB(ctx).Where("status = ?", status).Order("created_at DESC")
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
db = db.Limit(limit)
|
db = db.Limit(limit)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ func (r *GormWalletRepository) CreateBatch(ctx context.Context, wallets []entiti
|
|||||||
|
|
||||||
func (r *GormWalletRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.Wallet, error) {
|
func (r *GormWalletRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.Wallet, error) {
|
||||||
var wallets []entities.Wallet
|
var wallets []entities.Wallet
|
||||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&wallets).Error
|
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&wallets).Error
|
||||||
return wallets, err
|
return wallets, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +120,9 @@ func (r *GormWalletRepository) List(ctx context.Context, options interfaces.List
|
|||||||
order += " ASC"
|
order += " ASC"
|
||||||
}
|
}
|
||||||
query = query.Order(order)
|
query = query.Order(order)
|
||||||
|
} else {
|
||||||
|
// 默认按创建时间倒序
|
||||||
|
query = query.Order("created_at DESC")
|
||||||
}
|
}
|
||||||
if options.Page > 0 && options.PageSize > 0 {
|
if options.Page > 0 && options.PageSize > 0 {
|
||||||
offset := (options.Page - 1) * options.PageSize
|
offset := (options.Page - 1) * options.PageSize
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func (r *GormProductCategoryRepository) FindByCode(ctx context.Context, code str
|
|||||||
// FindVisible 查找可见分类
|
// FindVisible 查找可见分类
|
||||||
func (r *GormProductCategoryRepository) FindVisible(ctx context.Context) ([]*entities.ProductCategory, error) {
|
func (r *GormProductCategoryRepository) FindVisible(ctx context.Context) ([]*entities.ProductCategory, error) {
|
||||||
var categories []entities.ProductCategory
|
var categories []entities.ProductCategory
|
||||||
err := r.GetDB(ctx).Where("is_visible = ? AND is_enabled = ?", true, true).Find(&categories).Error
|
err := r.GetDB(ctx).Where("is_visible = ? AND is_enabled = ?", true, true).Order("sort ASC, created_at DESC").Find(&categories).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ func (r *GormProductCategoryRepository) FindVisible(ctx context.Context) ([]*ent
|
|||||||
// FindEnabled 查找启用分类
|
// FindEnabled 查找启用分类
|
||||||
func (r *GormProductCategoryRepository) FindEnabled(ctx context.Context) ([]*entities.ProductCategory, error) {
|
func (r *GormProductCategoryRepository) FindEnabled(ctx context.Context) ([]*entities.ProductCategory, error) {
|
||||||
var categories []entities.ProductCategory
|
var categories []entities.ProductCategory
|
||||||
err := r.GetDB(ctx).Where("is_enabled = ?", true).Find(&categories).Error
|
err := r.GetDB(ctx).Where("is_enabled = ?", true).Order("sort ASC, created_at DESC").Find(&categories).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ func (r *GormProductCategoryRepository) ListCategories(ctx context.Context, quer
|
|||||||
dbQuery = dbQuery.Order(order)
|
dbQuery = dbQuery.Order(order)
|
||||||
} else {
|
} else {
|
||||||
// 默认按排序字段和创建时间排序
|
// 默认按排序字段和创建时间排序
|
||||||
dbQuery = dbQuery.Order("sort ASC, created_at ASC")
|
dbQuery = dbQuery.Order("sort ASC, created_at DESC")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用分页
|
// 应用分页
|
||||||
@@ -193,7 +193,7 @@ func (r *GormProductCategoryRepository) Count(ctx context.Context, options inter
|
|||||||
// GetByIDs 根据ID列表获取分类
|
// GetByIDs 根据ID列表获取分类
|
||||||
func (r *GormProductCategoryRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.ProductCategory, error) {
|
func (r *GormProductCategoryRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.ProductCategory, error) {
|
||||||
var categories []entities.ProductCategory
|
var categories []entities.ProductCategory
|
||||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&categories).Error
|
err := r.GetDB(ctx).Where("id IN ?", ids).Order("sort ASC, created_at DESC").Find(&categories).Error
|
||||||
return categories, err
|
return categories, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +238,9 @@ func (r *GormProductCategoryRepository) List(ctx context.Context, options interf
|
|||||||
order += " ASC"
|
order += " ASC"
|
||||||
}
|
}
|
||||||
query = query.Order(order)
|
query = query.Order(order)
|
||||||
|
} else {
|
||||||
|
// 默认按排序字段和创建时间倒序
|
||||||
|
query = query.Order("sort ASC, created_at DESC")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用分页
|
// 应用分页
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func (r *GormProductRepository) FindByOldID(ctx context.Context, oldID string) (
|
|||||||
// FindByCategoryID 根据分类ID查找产品
|
// FindByCategoryID 根据分类ID查找产品
|
||||||
func (r *GormProductRepository) FindByCategoryID(ctx context.Context, categoryID string) ([]*entities.Product, error) {
|
func (r *GormProductRepository) FindByCategoryID(ctx context.Context, categoryID string) ([]*entities.Product, error) {
|
||||||
var productEntities []entities.Product
|
var productEntities []entities.Product
|
||||||
err := r.GetDB(ctx).Preload("Category").Where("category_id = ?", categoryID).Find(&productEntities).Error
|
err := r.GetDB(ctx).Preload("Category").Where("category_id = ?", categoryID).Order("created_at DESC").Find(&productEntities).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ func (r *GormProductRepository) FindByCategoryID(ctx context.Context, categoryID
|
|||||||
// FindVisible 查找可见产品
|
// FindVisible 查找可见产品
|
||||||
func (r *GormProductRepository) FindVisible(ctx context.Context) ([]*entities.Product, error) {
|
func (r *GormProductRepository) FindVisible(ctx context.Context) ([]*entities.Product, error) {
|
||||||
var productEntities []entities.Product
|
var productEntities []entities.Product
|
||||||
err := r.GetDB(ctx).Preload("Category").Where("is_visible = ? AND is_enabled = ?", true, true).Find(&productEntities).Error
|
err := r.GetDB(ctx).Preload("Category").Where("is_visible = ? AND is_enabled = ?", true, true).Order("created_at DESC").Find(&productEntities).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ func (r *GormProductRepository) FindVisible(ctx context.Context) ([]*entities.Pr
|
|||||||
// FindEnabled 查找启用产品
|
// FindEnabled 查找启用产品
|
||||||
func (r *GormProductRepository) FindEnabled(ctx context.Context) ([]*entities.Product, error) {
|
func (r *GormProductRepository) FindEnabled(ctx context.Context) ([]*entities.Product, error) {
|
||||||
var productEntities []entities.Product
|
var productEntities []entities.Product
|
||||||
err := r.GetDB(ctx).Preload("Category").Where("is_enabled = ?", true).Find(&productEntities).Error
|
err := r.GetDB(ctx).Preload("Category").Where("is_enabled = ?", true).Order("created_at DESC").Find(&productEntities).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -303,7 +303,7 @@ func (r *GormProductRepository) ListProductsWithSubscriptionStatus(ctx context.C
|
|||||||
// FindSubscribableProducts 查找可订阅产品
|
// FindSubscribableProducts 查找可订阅产品
|
||||||
func (r *GormProductRepository) FindSubscribableProducts(ctx context.Context, userID string) ([]*entities.Product, error) {
|
func (r *GormProductRepository) FindSubscribableProducts(ctx context.Context, userID string) ([]*entities.Product, error) {
|
||||||
var productEntities []entities.Product
|
var productEntities []entities.Product
|
||||||
err := r.GetDB(ctx).Where("is_enabled = ? AND is_visible = ?", true, true).Find(&productEntities).Error
|
err := r.GetDB(ctx).Where("is_enabled = ? AND is_visible = ?", true, true).Order("created_at DESC").Find(&productEntities).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -318,7 +318,7 @@ func (r *GormProductRepository) FindSubscribableProducts(ctx context.Context, us
|
|||||||
// FindProductsByIDs 根据ID列表查找产品
|
// FindProductsByIDs 根据ID列表查找产品
|
||||||
func (r *GormProductRepository) FindProductsByIDs(ctx context.Context, ids []string) ([]*entities.Product, error) {
|
func (r *GormProductRepository) FindProductsByIDs(ctx context.Context, ids []string) ([]*entities.Product, error) {
|
||||||
var productEntities []entities.Product
|
var productEntities []entities.Product
|
||||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&productEntities).Error
|
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&productEntities).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -379,7 +379,7 @@ func (r *GormProductRepository) Count(ctx context.Context, options interfaces.Co
|
|||||||
// GetByIDs 根据ID列表获取产品
|
// GetByIDs 根据ID列表获取产品
|
||||||
func (r *GormProductRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.Product, error) {
|
func (r *GormProductRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.Product, error) {
|
||||||
var products []entities.Product
|
var products []entities.Product
|
||||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&products).Error
|
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&products).Error
|
||||||
return products, err
|
return products, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,6 +424,9 @@ func (r *GormProductRepository) List(ctx context.Context, options interfaces.Lis
|
|||||||
order += " ASC"
|
order += " ASC"
|
||||||
}
|
}
|
||||||
query = query.Order(order)
|
query = query.Order(order)
|
||||||
|
} else {
|
||||||
|
// 默认按创建时间倒序
|
||||||
|
query = query.Order("created_at DESC")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用分页
|
// 应用分页
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func (r *GormSubscriptionRepository) Update(ctx context.Context, entity entities
|
|||||||
// FindByUserID 根据用户ID查找订阅
|
// FindByUserID 根据用户ID查找订阅
|
||||||
func (r *GormSubscriptionRepository) FindByUserID(ctx context.Context, userID string) ([]*entities.Subscription, error) {
|
func (r *GormSubscriptionRepository) FindByUserID(ctx context.Context, userID string) ([]*entities.Subscription, error) {
|
||||||
var subscriptions []entities.Subscription
|
var subscriptions []entities.Subscription
|
||||||
err := r.GetDB(ctx).WithContext(ctx).Where("user_id = ?", userID).Find(&subscriptions).Error
|
err := r.GetDB(ctx).WithContext(ctx).Where("user_id = ?", userID).Order("created_at DESC").Find(&subscriptions).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ func (r *GormSubscriptionRepository) FindByUserID(ctx context.Context, userID st
|
|||||||
// FindByProductID 根据产品ID查找订阅
|
// FindByProductID 根据产品ID查找订阅
|
||||||
func (r *GormSubscriptionRepository) FindByProductID(ctx context.Context, productID string) ([]*entities.Subscription, error) {
|
func (r *GormSubscriptionRepository) FindByProductID(ctx context.Context, productID string) ([]*entities.Subscription, error) {
|
||||||
var subscriptions []entities.Subscription
|
var subscriptions []entities.Subscription
|
||||||
err := r.GetDB(ctx).WithContext(ctx).Where("product_id = ?", productID).Find(&subscriptions).Error
|
err := r.GetDB(ctx).WithContext(ctx).Where("product_id = ?", productID).Order("created_at DESC").Find(&subscriptions).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -243,7 +243,7 @@ func (r *GormSubscriptionRepository) Count(ctx context.Context, options interfac
|
|||||||
// GetByIDs 根据ID列表获取订阅
|
// GetByIDs 根据ID列表获取订阅
|
||||||
func (r *GormSubscriptionRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.Subscription, error) {
|
func (r *GormSubscriptionRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.Subscription, error) {
|
||||||
var subscriptions []entities.Subscription
|
var subscriptions []entities.Subscription
|
||||||
err := r.GetDB(ctx).WithContext(ctx).Where("id IN ?", ids).Find(&subscriptions).Error
|
err := r.GetDB(ctx).WithContext(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&subscriptions).Error
|
||||||
return subscriptions, err
|
return subscriptions, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,6 +288,9 @@ func (r *GormSubscriptionRepository) List(ctx context.Context, options interface
|
|||||||
order += " ASC"
|
order += " ASC"
|
||||||
}
|
}
|
||||||
query = query.Order(order)
|
query = query.Order(order)
|
||||||
|
} else {
|
||||||
|
// 默认按创建时间倒序
|
||||||
|
query = query.Order("created_at DESC")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用分页
|
// 应用分页
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ func (r *GormEnterpriseInfoRepository) CreateBatch(ctx context.Context, enterpri
|
|||||||
// GetByIDs 根据ID列表获取企业信息
|
// GetByIDs 根据ID列表获取企业信息
|
||||||
func (r *GormEnterpriseInfoRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.EnterpriseInfo, error) {
|
func (r *GormEnterpriseInfoRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.EnterpriseInfo, error) {
|
||||||
var enterpriseInfos []entities.EnterpriseInfo
|
var enterpriseInfos []entities.EnterpriseInfo
|
||||||
err := r.db.WithContext(ctx).Where("id IN ?", ids).Find(&enterpriseInfos).Error
|
err := r.db.WithContext(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&enterpriseInfos).Error
|
||||||
return enterpriseInfos, err
|
return enterpriseInfos, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +246,9 @@ func (r *GormEnterpriseInfoRepository) List(ctx context.Context, options interfa
|
|||||||
order = options.Order
|
order = options.Order
|
||||||
}
|
}
|
||||||
query = query.Order(options.Sort + " " + order)
|
query = query.Order(options.Sort + " " + order)
|
||||||
|
} else {
|
||||||
|
// 默认按创建时间倒序
|
||||||
|
query = query.Order("created_at DESC")
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Page > 0 && options.PageSize > 0 {
|
if options.Page > 0 && options.PageSize > 0 {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func (r *GormSMSCodeRepository) CreateBatch(ctx context.Context, smsCodes []enti
|
|||||||
// GetByIDs 根据ID列表获取短信验证码
|
// GetByIDs 根据ID列表获取短信验证码
|
||||||
func (r *GormSMSCodeRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.SMSCode, error) {
|
func (r *GormSMSCodeRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.SMSCode, error) {
|
||||||
var smsCodes []entities.SMSCode
|
var smsCodes []entities.SMSCode
|
||||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&smsCodes).Error
|
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&smsCodes).Error
|
||||||
return smsCodes, err
|
return smsCodes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func (r *GormUserRepository) CreateBatch(ctx context.Context, users []entities.U
|
|||||||
|
|
||||||
func (r *GormUserRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.User, error) {
|
func (r *GormUserRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.User, error) {
|
||||||
var users []entities.User
|
var users []entities.User
|
||||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&users).Error
|
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&users).Error
|
||||||
return users, err
|
return users, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ func (r *GormUserRepository) GetByUsername(ctx context.Context, username string)
|
|||||||
|
|
||||||
func (r *GormUserRepository) GetByUserType(ctx context.Context, userType string) ([]*entities.User, error) {
|
func (r *GormUserRepository) GetByUserType(ctx context.Context, userType string) ([]*entities.User, error) {
|
||||||
var users []*entities.User
|
var users []*entities.User
|
||||||
err := r.GetDB(ctx).Where("user_type = ?", userType).Find(&users).Error
|
err := r.GetDB(ctx).Where("user_type = ?", userType).Order("created_at DESC").Find(&users).Error
|
||||||
return users, err
|
return users, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +214,9 @@ func (r *GormUserRepository) ListUsers(ctx context.Context, query *queries.ListU
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 应用排序(默认按创建时间倒序)
|
||||||
|
db = db.Order("users.created_at DESC")
|
||||||
|
|
||||||
// 应用分页
|
// 应用分页
|
||||||
offset := (query.Page - 1) * query.PageSize
|
offset := (query.Page - 1) * query.PageSize
|
||||||
if err := db.Offset(offset).Limit(query.PageSize).Find(&users).Error; err != nil {
|
if err := db.Offset(offset).Limit(query.PageSize).Find(&users).Error; err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user