七月迭代短暂完结,还有很多后端的关键东西没有弄,这是一版赶时间做的东西
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m26s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m26s
This commit is contained in:
@@ -70,6 +70,21 @@ func (s *DeviceStore) GetByIdentifier(ctx context.Context, identifier string) (*
|
||||
return &device, nil
|
||||
}
|
||||
|
||||
// GetByIdentifiers 批量按 VirtualNo、IMEI 或 SN 查询设备,并应用当前数据权限。
|
||||
func (s *DeviceStore) GetByIdentifiers(ctx context.Context, identifiers []string) ([]*model.Device, error) {
|
||||
devices := make([]*model.Device, 0)
|
||||
if len(identifiers) == 0 {
|
||||
return devices, nil
|
||||
}
|
||||
query := s.db.WithContext(ctx).
|
||||
Where("virtual_no IN ? OR imei IN ? OR sn IN ?", identifiers, identifiers, identifiers)
|
||||
query = middleware.ApplyShopFilter(ctx, query)
|
||||
if err := query.Find(&devices).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return devices, nil
|
||||
}
|
||||
|
||||
func (s *DeviceStore) GetByIDs(ctx context.Context, ids []uint) ([]*model.Device, error) {
|
||||
var devices []*model.Device
|
||||
if len(ids) == 0 {
|
||||
@@ -152,6 +167,9 @@ func (s *DeviceStore) applyDeviceFilters(ctx context.Context, query *gorm.DB, fi
|
||||
if activationStatus, ok := filters["activation_status"].(int); ok {
|
||||
query = s.applyActivationStatusFilter(query, activationStatus)
|
||||
}
|
||||
if realNameStatus, ok := filters["real_name_status"].(int); ok {
|
||||
query = s.applyRealNameStatusFilter(query, realNameStatus)
|
||||
}
|
||||
if shopIDs, ok := filters["shop_ids"].([]uint); ok {
|
||||
if len(shopIDs) == 0 {
|
||||
query = query.Where("1 = 0")
|
||||
@@ -206,6 +224,27 @@ func (s *DeviceStore) applyDeviceFilters(ctx context.Context, query *gorm.DB, fi
|
||||
return query
|
||||
}
|
||||
|
||||
// applyRealNameStatusFilter 按设备当前有效绑定卡的实名状态过滤。
|
||||
// 任意有效绑定卡已实名时设备视为已实名,否则视为未实名。
|
||||
func (s *DeviceStore) applyRealNameStatusFilter(query *gorm.DB, realNameStatus int) *gorm.DB {
|
||||
verifiedBindingCondition := `EXISTS (
|
||||
SELECT 1
|
||||
FROM tb_device_sim_binding AS b
|
||||
JOIN tb_iot_card AS c
|
||||
ON c.id = b.iot_card_id
|
||||
AND c.real_name_status = ?
|
||||
AND c.deleted_at IS NULL
|
||||
WHERE b.device_id = tb_device.id
|
||||
AND b.bind_status = ?
|
||||
AND b.deleted_at IS NULL
|
||||
)`
|
||||
args := []any{constants.RealNameStatusVerified, constants.BindStatusBound}
|
||||
if realNameStatus == constants.RealNameStatusVerified {
|
||||
return query.Where(verifiedBindingCondition, args...)
|
||||
}
|
||||
return query.Where("NOT "+verifiedBindingCondition, args...)
|
||||
}
|
||||
|
||||
// applyHasActivePackageFilter 按"是否有生效中主套餐"过滤设备。
|
||||
// true: 设备在 tb_package_usage 中存在生效中(status=PackageUsageStatusActive)的主套餐记录;
|
||||
// false: 不存在上述记录。
|
||||
|
||||
Reference in New Issue
Block a user