float64全部改float32

This commit is contained in:
2025-11-10 21:42:46 +08:00
parent 75306941c2
commit 3e711551e7
21 changed files with 74 additions and 73 deletions

View File

@@ -86,14 +86,14 @@ type ListHistoricalAlarmResponse struct {
type CreateDeviceThresholdAlarmDTO struct {
DeviceID uint `json:"device_id" binding:"required"` // 设备ID
SensorType models.SensorType `json:"sensor_type" binding:"required"` // 传感器类型
Thresholds float64 `json:"thresholds" binding:"required"` // 阈值
Thresholds float32 `json:"thresholds" binding:"required"` // 阈值
Operator models.Operator `json:"operator" binding:"required"` // 操作符 (使用string类型与前端交互更通用)
Level models.SeverityLevel `json:"level,omitempty"` // 告警等级,可选,如果未提供则使用默认值
}
// UpdateDeviceThresholdAlarmDTO 更新设备阈值告警的请求DTO
type UpdateDeviceThresholdAlarmDTO struct {
Thresholds float64 `json:"thresholds" binding:"required"` // 新的阈值
Thresholds float32 `json:"thresholds" binding:"required"` // 新的阈值
Operator models.Operator `json:"operator" binding:"required"` // 新的操作符
Level models.SeverityLevel `json:"level,omitempty"` // 新的告警等级,可选
}
@@ -102,14 +102,14 @@ type UpdateDeviceThresholdAlarmDTO struct {
type CreateAreaThresholdAlarmDTO struct {
AreaControllerID uint `json:"area_controller_id" binding:"required"` // 区域主控ID
SensorType models.SensorType `json:"sensor_type" binding:"required"` // 传感器类型
Thresholds float64 `json:"thresholds" binding:"required"` // 阈值
Thresholds float32 `json:"thresholds" binding:"required"` // 阈值
Operator models.Operator `json:"operator" binding:"required"` // 操作符
Level models.SeverityLevel `json:"level,omitempty"` // 告警等级,可选
}
// UpdateAreaThresholdAlarmDTO 更新区域阈值告警的请求DTO
type UpdateAreaThresholdAlarmDTO struct {
Thresholds float64 `json:"thresholds" binding:"required"` // 新的阈值
Thresholds float32 `json:"thresholds" binding:"required"` // 新的阈值
Operator models.Operator `json:"operator" binding:"required"` // 新的操作符
Level models.SeverityLevel `json:"level,omitempty"` // 新的告警等级,可选
}
@@ -124,7 +124,7 @@ type AreaThresholdAlarmDTO struct {
ID int `json:"id"`
AreaControllerID uint `json:"area_controller_id"`
SensorType models.SensorType `json:"sensor_type"`
Thresholds float64 `json:"thresholds"`
Thresholds float32 `json:"thresholds"`
Operator models.Operator `json:"operator"`
Level models.SeverityLevel `json:"level"`
}
@@ -134,7 +134,7 @@ type DeviceThresholdAlarmDTO struct {
ID int `json:"id"`
DeviceID uint `json:"device_id"`
SensorType models.SensorType `json:"sensor_type"`
Thresholds float64 `json:"thresholds"`
Thresholds float32 `json:"thresholds"`
Operator models.Operator `json:"operator"`
Level models.SeverityLevel `json:"level"`
}

View File

@@ -227,9 +227,9 @@ type RawMaterialPurchaseDTO struct {
RawMaterialID uint `json:"raw_material_id"`
RawMaterial RawMaterialDTO `json:"raw_material"`
Supplier string `json:"supplier"`
Amount float64 `json:"amount"`
UnitPrice float64 `json:"unit_price"`
TotalPrice float64 `json:"total_price"`
Amount float32 `json:"amount"`
UnitPrice float32 `json:"unit_price"`
TotalPrice float32 `json:"total_price"`
PurchaseDate time.Time `json:"purchase_date"`
CreatedAt time.Time `json:"created_at"`
}
@@ -258,7 +258,7 @@ type ListRawMaterialStockLogRequest struct {
type RawMaterialStockLogDTO struct {
ID uint `json:"id"`
RawMaterialID uint `json:"raw_material_id"`
ChangeAmount float64 `json:"change_amount"`
ChangeAmount float32 `json:"change_amount"`
SourceType models.StockLogSourceType `json:"source_type"`
SourceID uint `json:"source_id"`
HappenedAt time.Time `json:"happened_at"`
@@ -304,7 +304,7 @@ type FeedUsageRecordDTO struct {
Pen PenDTO `json:"pen"`
FeedFormulaID uint `json:"feed_formula_id"`
FeedFormula FeedFormulaDTO `json:"feed_formula"`
Amount float64 `json:"amount"`
Amount float32 `json:"amount"`
RecordedAt time.Time `json:"recorded_at"`
OperatorID uint `json:"operator_id"`
Remarks string `json:"remarks"`
@@ -343,7 +343,7 @@ type MedicationLogDTO struct {
PigBatchID uint `json:"pig_batch_id"`
MedicationID uint `json:"medication_id"`
Medication MedicationDTO `json:"medication"`
DosageUsed float64 `json:"dosage_used"`
DosageUsed float32 `json:"dosage_used"`
TargetCount int `json:"target_count"`
Reason models.MedicationReasonType `json:"reason"`
Description string `json:"description"`
@@ -439,7 +439,7 @@ type WeighingRecordDTO struct {
ID uint `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Weight float64 `json:"weight"`
Weight float32 `json:"weight"`
WeighingBatchID uint `json:"weighing_batch_id"`
PenID uint `json:"pen_id"`
OperatorID uint `json:"operator_id"`
@@ -552,8 +552,8 @@ type PigPurchaseDTO struct {
PurchaseDate time.Time `json:"purchase_date"`
Supplier string `json:"supplier"`
Quantity int `json:"quantity"`
UnitPrice float64 `json:"unit_price"`
TotalPrice float64 `json:"total_price"`
UnitPrice float32 `json:"unit_price"`
TotalPrice float32 `json:"total_price"`
Remarks string `json:"remarks"`
OperatorID uint `json:"operator_id"`
}
@@ -587,8 +587,8 @@ type PigSaleDTO struct {
SaleDate time.Time `json:"sale_date"`
Buyer string `json:"buyer"`
Quantity int `json:"quantity"`
UnitPrice float64 `json:"unit_price"`
TotalPrice float64 `json:"total_price"`
UnitPrice float32 `json:"unit_price"`
TotalPrice float32 `json:"total_price"`
Remarks string `json:"remarks"`
OperatorID uint `json:"operator_id"`
}

View File

@@ -74,8 +74,8 @@ type MovePigsIntoPenRequest struct {
type SellPigsRequest struct {
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
Quantity int `json:"quantity" validate:"required,min=1"` // 卖出猪只数量
UnitPrice float64 `json:"unit_price" validate:"required,min=0"` // 单价
TotalPrice float64 `json:"total_price" validate:"required,min=0"` // 总价
UnitPrice float32 `json:"unit_price" validate:"required,min=0"` // 单价
TotalPrice float32 `json:"total_price" validate:"required,min=0"` // 总价
TraderName string `json:"trader_name" validate:"required"` // 交易方名称
TradeDate time.Time `json:"trade_date" validate:"required"` // 交易日期
Remarks string `json:"remarks"` // 备注
@@ -85,8 +85,8 @@ type SellPigsRequest struct {
type BuyPigsRequest struct {
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
Quantity int `json:"quantity" validate:"required,min=1"` // 买入猪只数量
UnitPrice float64 `json:"unit_price" validate:"required,min=0"` // 单价
TotalPrice float64 `json:"total_price" validate:"required,min=0"` // 总价
UnitPrice float32 `json:"unit_price" validate:"required,min=0"` // 单价
TotalPrice float32 `json:"total_price" validate:"required,min=0"` // 总价
TraderName string `json:"trader_name" validate:"required"` // 交易方名称
TradeDate time.Time `json:"trade_date" validate:"required"` // 交易日期
Remarks string `json:"remarks"` // 备注

View File

@@ -25,8 +25,8 @@ type PigBatchService interface {
MovePigsIntoPen(ctx context.Context, batchID uint, toPenID uint, quantity int, operatorID uint, remarks string) error
// Trade Sub-service
SellPigs(ctx context.Context, batchID uint, penID uint, quantity int, unitPrice float64, tatalPrice float64, traderName string, tradeDate time.Time, remarks string, operatorID uint) error
BuyPigs(ctx context.Context, batchID uint, penID uint, quantity int, unitPrice float64, tatalPrice float64, traderName string, tradeDate time.Time, remarks string, operatorID uint) error
SellPigs(ctx context.Context, batchID uint, penID uint, quantity int, unitPrice float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint) error
BuyPigs(ctx context.Context, batchID uint, penID uint, quantity int, unitPrice float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint) error
// Transfer Sub-service
TransferPigsAcrossBatches(ctx context.Context, sourceBatchID uint, destBatchID uint, fromPenID uint, toPenID uint, quantity uint, operatorID uint, remarks string) error
@@ -258,7 +258,7 @@ func (s *pigBatchService) MovePigsIntoPen(ctx context.Context, batchID uint, toP
}
// SellPigs 委托给领域服务
func (s *pigBatchService) SellPigs(ctx context.Context, batchID uint, penID uint, quantity int, unitPrice float64, tatalPrice float64, traderName string, tradeDate time.Time, remarks string, operatorID uint) error {
func (s *pigBatchService) SellPigs(ctx context.Context, batchID uint, penID uint, quantity int, unitPrice float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint) error {
serviceCtx, logger := logs.Trace(ctx, s.ctx, "SellPigs")
err := s.domainService.SellPigs(serviceCtx, batchID, penID, quantity, unitPrice, tatalPrice, traderName, tradeDate, remarks, operatorID)
if err != nil {
@@ -269,7 +269,7 @@ func (s *pigBatchService) SellPigs(ctx context.Context, batchID uint, penID uint
}
// BuyPigs 委托给领域服务
func (s *pigBatchService) BuyPigs(ctx context.Context, batchID uint, penID uint, quantity int, unitPrice float64, tatalPrice float64, traderName string, tradeDate time.Time, remarks string, operatorID uint) error {
func (s *pigBatchService) BuyPigs(ctx context.Context, batchID uint, penID uint, quantity int, unitPrice float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint) error {
serviceCtx, logger := logs.Trace(ctx, s.ctx, "BuyPigs")
err := s.domainService.BuyPigs(serviceCtx, batchID, penID, quantity, unitPrice, tatalPrice, traderName, tradeDate, remarks, operatorID)
if err != nil {

View File

@@ -298,7 +298,7 @@ func (c *ChirpStackListener) handleUpEvent(ctx context.Context, event *UpEvent)
valueDescriptor := valueDescriptors[0]
// 5.3 应用乘数和偏移量计算最终值
parsedValue := float64(rawSensorValue)*valueDescriptor.Multiplier + valueDescriptor.Offset
parsedValue := rawSensorValue*valueDescriptor.Multiplier + valueDescriptor.Offset
// 5.4 根据传感器类型构建具体的数据结构
var dataToRecord interface{}
@@ -312,7 +312,7 @@ func (c *ChirpStackListener) handleUpEvent(ctx context.Context, event *UpEvent)
default:
// TODO 未知传感器的数据需要记录吗
logger.Warnf("未知的传感器类型 '%s',将使用通用格式记录", valueDescriptor.Type)
dataToRecord = map[string]float64{"value": parsedValue}
dataToRecord = map[string]float32{"value": parsedValue}
}
// 5.5 记录传感器数据

View File

@@ -24,9 +24,9 @@ type DeviceInfo struct {
// Location 包含了地理位置信息。
type Location struct {
Latitude float64 `json:"latitude"` // 纬度
Longitude float64 `json:"longitude"` // 经度
Altitude float64 `json:"altitude"` // 海拔
Latitude float32 `json:"latitude"` // 纬度
Longitude float32 `json:"longitude"` // 经度
Altitude float32 `json:"altitude"` // 海拔
}
// --- 可复用的子结构体 ---
@@ -61,7 +61,7 @@ type UplinkRxInfo struct {
UplinkID uint32 `json:"uplink_id"` // 上行ID
Time time.Time `json:"time"` // 接收时间
Rssi int `json:"rssi"` // 接收信号强度指示
Snr float64 `json:"snr"` // 信噪比
Snr float32 `json:"snr"` // 信噪比
Channel int `json:"channel"` // 接收通道
Location *Location `json:"location"` // 网关位置
Context string `json:"context"` // 上下文信息
@@ -96,9 +96,9 @@ type DownlinkTxInfo struct {
// ResolvedLocation 包含了地理位置解析结果。
type ResolvedLocation struct {
Latitude float64 `json:"latitude"` // 纬度
Longitude float64 `json:"longitude"` // 经度
Altitude float64 `json:"altitude"` // 海拔
Latitude float32 `json:"latitude"` // 纬度
Longitude float32 `json:"longitude"` // 经度
Altitude float32 `json:"altitude"` // 海拔
Source string `json:"source"` // 位置来源
Accuracy int `json:"accuracy"` // 精度
}