uint/uint64全部改为uint32
This commit is contained in:
@@ -61,7 +61,7 @@ func (t *ThresholdAlarmController) SnoozeThresholdAlarm(ctx echo.Context) error
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的请求体: "+err.Error(), actionType, "请求体绑定失败", req)
|
||||
}
|
||||
|
||||
if err := t.thresholdAlarmService.SnoozeThresholdAlarm(reqCtx, uint(alarmID), req.DurationMinutes); err != nil {
|
||||
if err := t.thresholdAlarmService.SnoozeThresholdAlarm(reqCtx, uint32(alarmID), req.DurationMinutes); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Warnf("%s: 告警不存在, ID: %d", actionType, alarmID)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, "告警未找到", actionType, "告警不存在", alarmID)
|
||||
@@ -96,7 +96,7 @@ func (t *ThresholdAlarmController) CancelSnoozeThresholdAlarm(ctx echo.Context)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的告警ID: "+alarmIDStr, actionType, "无效的告警ID", alarmIDStr)
|
||||
}
|
||||
|
||||
if err := t.thresholdAlarmService.CancelSnoozeThresholdAlarm(reqCtx, uint(alarmID)); err != nil {
|
||||
if err := t.thresholdAlarmService.CancelSnoozeThresholdAlarm(reqCtx, uint32(alarmID)); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Warnf("%s: 告警不存在, ID: %d", actionType, alarmID)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, "告警未找到", actionType, "告警不存在", alarmID)
|
||||
|
||||
@@ -17,7 +17,7 @@ var (
|
||||
|
||||
// GetOperatorIDFromContext 从 echo.Context 中提取操作者ID。
|
||||
// 假设操作者ID是由 AuthMiddleware 存储到 context 中的 *models.User 对象的 ID 字段。
|
||||
func GetOperatorIDFromContext(c echo.Context) (uint, error) {
|
||||
func GetOperatorIDFromContext(c echo.Context) (uint32, error) {
|
||||
userVal := c.Get(models.ContextUserKey.String())
|
||||
if userVal == nil {
|
||||
return 0, ErrUserNotFoundInContext
|
||||
|
||||
@@ -84,7 +84,7 @@ func (c *Controller) GetDevice(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+deviceID, actionType, "无效的ID", deviceID)
|
||||
}
|
||||
|
||||
resp, err := c.deviceService.GetDevice(reqCtx, uint(id))
|
||||
resp, err := c.deviceService.GetDevice(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Warnf("%s: 设备不存在, ID: %s", actionType, deviceID)
|
||||
@@ -149,7 +149,7 @@ func (c *Controller) UpdateDevice(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+deviceID, actionType, "无效的ID", deviceID)
|
||||
}
|
||||
|
||||
resp, err := c.deviceService.UpdateDevice(reqCtx, uint(id), &req)
|
||||
resp, err := c.deviceService.UpdateDevice(reqCtx, uint32(id), &req)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Warnf("%s: 设备不存在, ID: %s", actionType, deviceID)
|
||||
@@ -184,7 +184,7 @@ func (c *Controller) DeleteDevice(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+deviceID, actionType, "无效的ID", deviceID)
|
||||
}
|
||||
|
||||
if err := c.deviceService.DeleteDevice(reqCtx, uint(id)); err != nil {
|
||||
if err := c.deviceService.DeleteDevice(reqCtx, uint32(id)); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, gorm.ErrRecordNotFound):
|
||||
logger.Warnf("%s: 设备不存在, ID: %s", actionType, deviceID)
|
||||
@@ -232,7 +232,7 @@ func (c *Controller) ManualControl(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+deviceID, actionType, "无效的ID", deviceID)
|
||||
}
|
||||
|
||||
if err := c.deviceService.ManualControl(reqCtx, uint(id), &req); err != nil {
|
||||
if err := c.deviceService.ManualControl(reqCtx, uint32(id), &req); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Warnf("%s: 设备不存在, ID: %s", actionType, deviceID)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, "设备未找到", actionType, "设备不存在", deviceID)
|
||||
@@ -297,7 +297,7 @@ func (c *Controller) GetAreaController(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+acID, actionType, "无效的ID", acID)
|
||||
}
|
||||
|
||||
resp, err := c.deviceService.GetAreaController(reqCtx, uint(id))
|
||||
resp, err := c.deviceService.GetAreaController(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Warnf("%s: 区域主控不存在, ID: %s", actionType, acID)
|
||||
@@ -361,7 +361,7 @@ func (c *Controller) UpdateAreaController(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+acID, actionType, "无效的ID", acID)
|
||||
}
|
||||
|
||||
resp, err := c.deviceService.UpdateAreaController(reqCtx, uint(id), &req)
|
||||
resp, err := c.deviceService.UpdateAreaController(reqCtx, uint32(id), &req)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Warnf("%s: 区域主控不存在, ID: %s", actionType, acID)
|
||||
@@ -396,7 +396,7 @@ func (c *Controller) DeleteAreaController(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+acID, actionType, "无效的ID", acID)
|
||||
}
|
||||
|
||||
if err := c.deviceService.DeleteAreaController(reqCtx, uint(id)); err != nil {
|
||||
if err := c.deviceService.DeleteAreaController(reqCtx, uint32(id)); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, gorm.ErrRecordNotFound):
|
||||
logger.Warnf("%s: 区域主控不存在, ID: %s", actionType, acID)
|
||||
@@ -467,7 +467,7 @@ func (c *Controller) GetDeviceTemplate(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+dtID, actionType, "无效的ID", dtID)
|
||||
}
|
||||
|
||||
resp, err := c.deviceService.GetDeviceTemplate(reqCtx, uint(id))
|
||||
resp, err := c.deviceService.GetDeviceTemplate(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Warnf("%s: 设备模板不存在, ID: %s", actionType, dtID)
|
||||
@@ -532,7 +532,7 @@ func (c *Controller) UpdateDeviceTemplate(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+dtID, actionType, "无效的ID", dtID)
|
||||
}
|
||||
|
||||
resp, err := c.deviceService.UpdateDeviceTemplate(reqCtx, uint(id), &req)
|
||||
resp, err := c.deviceService.UpdateDeviceTemplate(reqCtx, uint32(id), &req)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Warnf("%s: 设备模板不存在, ID: %s", actionType, dtID)
|
||||
@@ -567,7 +567,7 @@ func (c *Controller) DeleteDeviceTemplate(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID: "+dtID, actionType, "无效的ID", dtID)
|
||||
}
|
||||
|
||||
if err := c.deviceService.DeleteDeviceTemplate(reqCtx, uint(id)); err != nil {
|
||||
if err := c.deviceService.DeleteDeviceTemplate(reqCtx, uint32(id)); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, gorm.ErrRecordNotFound):
|
||||
logger.Warnf("%s: 设备模板不存在, ID: %s", actionType, dtID)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
// mapAndSendError 统一映射服务层错误并发送响应。
|
||||
// 这个函数将服务层返回的错误转换为控制器层应返回的HTTP状态码和审计信息。
|
||||
func mapAndSendError(reqContext context.Context, c *PigBatchController, ctx echo.Context, action string, err error, id uint) error {
|
||||
func mapAndSendError(reqContext context.Context, c *PigBatchController, ctx echo.Context, action string, err error, id uint32) error {
|
||||
if errors.Is(err, service.ErrPigBatchNotFound) ||
|
||||
errors.Is(err, service.ErrPenNotFound) ||
|
||||
errors.Is(err, service.ErrPenNotAssociatedWithBatch) {
|
||||
@@ -34,7 +34,7 @@ func mapAndSendError(reqContext context.Context, c *PigBatchController, ctx echo
|
||||
}
|
||||
|
||||
// idExtractorFunc 定义了一个函数类型,用于从echo.Context中提取主ID。
|
||||
type idExtractorFunc func(ctx echo.Context) (uint, error)
|
||||
type idExtractorFunc func(ctx echo.Context) (uint32, error)
|
||||
|
||||
// extractOperatorAndPrimaryID 封装了从echo.Context中提取操作员ID和主ID的通用逻辑。
|
||||
// 它负责处理ID提取过程中的错误,并发送相应的HTTP响应。
|
||||
@@ -48,15 +48,15 @@ type idExtractorFunc func(ctx echo.Context) (uint, error)
|
||||
//
|
||||
// 返回值:
|
||||
//
|
||||
// operatorID: uint - 提取到的操作员ID。
|
||||
// primaryID: uint - 提取到的主ID。
|
||||
// operatorID: uint32 - 提取到的操作员ID。
|
||||
// primaryID: uint32 - 提取到的主ID。
|
||||
// err: error - 如果ID提取失败或发送错误响应,则返回错误。
|
||||
func extractOperatorAndPrimaryID(
|
||||
c *PigBatchController,
|
||||
ctx echo.Context,
|
||||
action string,
|
||||
idExtractor idExtractorFunc,
|
||||
) (operatorID uint, primaryID uint, err error) {
|
||||
) (operatorID uint32, primaryID uint32, err error) {
|
||||
// 1. 获取操作员ID
|
||||
operatorID, err = controller.GetOperatorIDFromContext(ctx)
|
||||
if err != nil {
|
||||
@@ -78,7 +78,7 @@ func extractOperatorAndPrimaryID(
|
||||
if err != nil {
|
||||
return 0, 0, controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID格式", action, "ID格式错误", idParam)
|
||||
}
|
||||
primaryID = uint(parsedID)
|
||||
primaryID = uint32(parsedID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func handleAPIRequest[Req any](
|
||||
ctx echo.Context,
|
||||
action string,
|
||||
reqDTO Req,
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint, primaryID uint, req Req) error,
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint32, primaryID uint32, req Req) error,
|
||||
successMsg string,
|
||||
idExtractor idExtractorFunc,
|
||||
) error {
|
||||
@@ -124,7 +124,7 @@ func handleNoBodyAPIRequest(
|
||||
c *PigBatchController,
|
||||
ctx echo.Context,
|
||||
action string,
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint, primaryID uint) error,
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint32, primaryID uint32) error,
|
||||
successMsg string,
|
||||
idExtractor idExtractorFunc,
|
||||
) error {
|
||||
@@ -151,7 +151,7 @@ func handleAPIRequestWithResponse[Req any, Resp any](
|
||||
ctx echo.Context,
|
||||
action string,
|
||||
reqDTO Req,
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint, primaryID uint, req Req) (Resp, error), // serviceExecutor现在返回Resp
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint32, primaryID uint32, req Req) (Resp, error), // serviceExecutor现在返回Resp
|
||||
successMsg string,
|
||||
idExtractor idExtractorFunc,
|
||||
) error {
|
||||
@@ -182,7 +182,7 @@ func handleNoBodyAPIRequestWithResponse[Resp any](
|
||||
c *PigBatchController,
|
||||
ctx echo.Context,
|
||||
action string,
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint, primaryID uint) (Resp, error), // serviceExecutor现在返回Resp
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint32, primaryID uint32) (Resp, error), // serviceExecutor现在返回Resp
|
||||
successMsg string,
|
||||
idExtractor idExtractorFunc,
|
||||
) error {
|
||||
@@ -209,7 +209,7 @@ func handleQueryAPIRequestWithResponse[Query any, Resp any](
|
||||
ctx echo.Context,
|
||||
action string,
|
||||
queryDTO Query,
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint, query Query) (Resp, error), // serviceExecutor现在接收queryDTO
|
||||
serviceExecutor func(ctx echo.Context, operatorID uint32, query Query) (Resp, error), // serviceExecutor现在接收queryDTO
|
||||
successMsg string,
|
||||
) error {
|
||||
// 1. 绑定查询参数
|
||||
|
||||
@@ -43,7 +43,7 @@ func (c *PigBatchController) CreatePigBatch(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequestWithResponse(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.PigBatchCreateDTO) (*dto.PigBatchResponseDTO, error) {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.PigBatchCreateDTO) (*dto.PigBatchResponseDTO, error) {
|
||||
// 对于创建操作,primaryID通常不从路径中获取,而是由服务层生成
|
||||
return c.service.CreatePigBatch(reqCtx, operatorID, req)
|
||||
},
|
||||
@@ -68,7 +68,7 @@ func (c *PigBatchController) GetPigBatch(ctx echo.Context) error {
|
||||
|
||||
return handleNoBodyAPIRequestWithResponse(
|
||||
reqCtx, c, ctx, action,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint) (*dto.PigBatchResponseDTO, error) {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32) (*dto.PigBatchResponseDTO, error) {
|
||||
return c.service.GetPigBatch(reqCtx, primaryID)
|
||||
},
|
||||
"获取成功",
|
||||
@@ -95,7 +95,7 @@ func (c *PigBatchController) UpdatePigBatch(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequestWithResponse(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.PigBatchUpdateDTO) (*dto.PigBatchResponseDTO, error) {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.PigBatchUpdateDTO) (*dto.PigBatchResponseDTO, error) {
|
||||
return c.service.UpdatePigBatch(reqCtx, primaryID, req)
|
||||
},
|
||||
"更新成功",
|
||||
@@ -119,7 +119,7 @@ func (c *PigBatchController) DeletePigBatch(ctx echo.Context) error {
|
||||
|
||||
return handleNoBodyAPIRequest(
|
||||
reqCtx, c, ctx, action,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32) error {
|
||||
return c.service.DeletePigBatch(reqCtx, primaryID)
|
||||
},
|
||||
"删除成功",
|
||||
@@ -144,7 +144,7 @@ func (c *PigBatchController) ListPigBatches(ctx echo.Context) error {
|
||||
|
||||
return handleQueryAPIRequestWithResponse(
|
||||
reqCtx, c, ctx, action, &query,
|
||||
func(ctx echo.Context, operatorID uint, query *dto.PigBatchQueryDTO) ([]*dto.PigBatchResponseDTO, error) {
|
||||
func(ctx echo.Context, operatorID uint32, query *dto.PigBatchQueryDTO) ([]*dto.PigBatchResponseDTO, error) {
|
||||
return c.service.ListPigBatches(reqCtx, query.IsActive)
|
||||
},
|
||||
"获取成功",
|
||||
@@ -170,7 +170,7 @@ func (c *PigBatchController) AssignEmptyPensToBatch(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.AssignEmptyPensToBatchRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.AssignEmptyPensToBatchRequest) error {
|
||||
return c.service.AssignEmptyPensToBatch(reqCtx, primaryID, req.PenIDs, operatorID)
|
||||
},
|
||||
"分配成功",
|
||||
@@ -197,18 +197,18 @@ func (c *PigBatchController) ReclassifyPenToNewBatch(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.ReclassifyPenToNewBatchRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.ReclassifyPenToNewBatchRequest) error {
|
||||
// primaryID 在这里是 fromBatchID
|
||||
return c.service.ReclassifyPenToNewBatch(reqCtx, primaryID, req.ToBatchID, req.PenID, operatorID, req.Remarks)
|
||||
},
|
||||
"划拨成功",
|
||||
func(ctx echo.Context) (uint, error) { // 自定义ID提取器,从 ":fromBatchID" 路径参数提取
|
||||
func(ctx echo.Context) (uint32, error) { // 自定义ID提取器,从 ":fromBatchID" 路径参数提取
|
||||
idParam := ctx.Param("fromBatchID")
|
||||
parsedID, err := strconv.ParseUint(idParam, 10, 32)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint(parsedID), nil
|
||||
return uint32(parsedID), nil
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -230,23 +230,23 @@ func (c *PigBatchController) RemoveEmptyPenFromBatch(ctx echo.Context) error {
|
||||
|
||||
return handleNoBodyAPIRequest(
|
||||
reqCtx, c, ctx, action,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32) error {
|
||||
// primaryID 在这里是 batchID
|
||||
penIDParam := ctx.Param("penID")
|
||||
parsedPenID, err := strconv.ParseUint(penIDParam, 10, 32)
|
||||
if err != nil {
|
||||
return err // 返回错误,因为 penID 格式无效
|
||||
}
|
||||
return c.service.RemoveEmptyPenFromBatch(reqCtx, primaryID, uint(parsedPenID))
|
||||
return c.service.RemoveEmptyPenFromBatch(reqCtx, primaryID, uint32(parsedPenID))
|
||||
},
|
||||
"移除成功",
|
||||
func(ctx echo.Context) (uint, error) { // 自定义ID提取器,从 ":batchID" 路径参数提取
|
||||
func(ctx echo.Context) (uint32, error) { // 自定义ID提取器,从 ":batchID" 路径参数提取
|
||||
idParam := ctx.Param("batchID")
|
||||
parsedID, err := strconv.ParseUint(idParam, 10, 32)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint(parsedID), nil
|
||||
return uint32(parsedID), nil
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -270,7 +270,7 @@ func (c *PigBatchController) MovePigsIntoPen(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.MovePigsIntoPenRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.MovePigsIntoPenRequest) error {
|
||||
return c.service.MovePigsIntoPen(reqCtx, primaryID, req.ToPenID, req.Quantity, operatorID, req.Remarks)
|
||||
},
|
||||
"移入成功",
|
||||
|
||||
@@ -26,7 +26,7 @@ func (c *PigBatchController) RecordSickPigs(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordSickPigsRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.RecordSickPigsRequest) error {
|
||||
return c.service.RecordSickPigs(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.TreatmentLocation, req.HappenedAt, req.Remarks)
|
||||
},
|
||||
"记录成功",
|
||||
@@ -53,7 +53,7 @@ func (c *PigBatchController) RecordSickPigRecovery(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordSickPigRecoveryRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.RecordSickPigRecoveryRequest) error {
|
||||
return c.service.RecordSickPigRecovery(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.TreatmentLocation, req.HappenedAt, req.Remarks)
|
||||
},
|
||||
"记录成功",
|
||||
@@ -80,7 +80,7 @@ func (c *PigBatchController) RecordSickPigDeath(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordSickPigDeathRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.RecordSickPigDeathRequest) error {
|
||||
return c.service.RecordSickPigDeath(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.TreatmentLocation, req.HappenedAt, req.Remarks)
|
||||
},
|
||||
"记录成功",
|
||||
@@ -107,7 +107,7 @@ func (c *PigBatchController) RecordSickPigCull(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordSickPigCullRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.RecordSickPigCullRequest) error {
|
||||
return c.service.RecordSickPigCull(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.TreatmentLocation, req.HappenedAt, req.Remarks)
|
||||
},
|
||||
"记录成功",
|
||||
@@ -134,7 +134,7 @@ func (c *PigBatchController) RecordDeath(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordDeathRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.RecordDeathRequest) error {
|
||||
return c.service.RecordDeath(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.HappenedAt, req.Remarks)
|
||||
},
|
||||
"记录成功",
|
||||
@@ -161,7 +161,7 @@ func (c *PigBatchController) RecordCull(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.RecordCullRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.RecordCullRequest) error {
|
||||
return c.service.RecordCull(reqCtx, operatorID, primaryID, req.PenID, req.Quantity, req.HappenedAt, req.Remarks)
|
||||
},
|
||||
"记录成功",
|
||||
|
||||
@@ -25,7 +25,7 @@ func (c *PigBatchController) SellPigs(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.SellPigsRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.SellPigsRequest) error {
|
||||
return c.service.SellPigs(reqCtx, primaryID, req.PenID, req.Quantity, req.UnitPrice, req.TotalPrice, req.TraderName, req.TradeDate, req.Remarks, operatorID)
|
||||
},
|
||||
"卖猪成功",
|
||||
@@ -51,7 +51,7 @@ func (c *PigBatchController) BuyPigs(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.BuyPigsRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.BuyPigsRequest) error {
|
||||
return c.service.BuyPigs(reqCtx, primaryID, req.PenID, req.Quantity, req.UnitPrice, req.TotalPrice, req.TraderName, req.TradeDate, req.Remarks, operatorID)
|
||||
},
|
||||
"买猪成功",
|
||||
|
||||
@@ -28,18 +28,18 @@ func (c *PigBatchController) TransferPigsAcrossBatches(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.TransferPigsAcrossBatchesRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.TransferPigsAcrossBatchesRequest) error {
|
||||
// primaryID 在这里是 sourceBatchID
|
||||
return c.service.TransferPigsAcrossBatches(reqCtx, primaryID, req.DestBatchID, req.FromPenID, req.ToPenID, req.Quantity, operatorID, req.Remarks)
|
||||
},
|
||||
"调栏成功",
|
||||
func(ctx echo.Context) (uint, error) { // 自定义ID提取器,从 ":sourceBatchID" 路径参数提取
|
||||
func(ctx echo.Context) (uint32, error) { // 自定义ID提取器,从 ":sourceBatchID" 路径参数提取
|
||||
idParam := ctx.Param("sourceBatchID")
|
||||
parsedID, err := strconv.ParseUint(idParam, 10, 32)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint(parsedID), nil
|
||||
return uint32(parsedID), nil
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func (c *PigBatchController) TransferPigsWithinBatch(ctx echo.Context) error {
|
||||
|
||||
return handleAPIRequest(
|
||||
reqCtx, c, ctx, action, &req,
|
||||
func(ctx echo.Context, operatorID uint, primaryID uint, req *dto.TransferPigsWithinBatchRequest) error {
|
||||
func(ctx echo.Context, operatorID uint32, primaryID uint32, req *dto.TransferPigsWithinBatchRequest) error {
|
||||
// primaryID 在这里是 batchID
|
||||
return c.service.TransferPigsWithinBatch(reqCtx, primaryID, req.FromPenID, req.ToPenID, req.Quantity, operatorID, req.Remarks)
|
||||
},
|
||||
|
||||
@@ -76,7 +76,7 @@ func (c *PigFarmController) GetPigHouse(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID格式", action, "ID格式错误", ctx.Param("id"))
|
||||
}
|
||||
|
||||
house, err := c.service.GetPigHouseByID(reqCtx, uint(id))
|
||||
house, err := c.service.GetPigHouseByID(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
if errors.Is(err, service.ErrHouseNotFound) {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, "猪舍不存在", action, "猪舍不存在", id)
|
||||
@@ -132,7 +132,7 @@ func (c *PigFarmController) UpdatePigHouse(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的请求体", action, "请求体绑定失败", req)
|
||||
}
|
||||
|
||||
house, err := c.service.UpdatePigHouse(reqCtx, uint(id), req.Name, req.Description)
|
||||
house, err := c.service.UpdatePigHouse(reqCtx, uint32(id), req.Name, req.Description)
|
||||
if err != nil {
|
||||
if errors.Is(err, service.ErrHouseNotFound) {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, "猪舍不存在", action, "猪舍不存在", id)
|
||||
@@ -161,7 +161,7 @@ func (c *PigFarmController) DeletePigHouse(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID格式", action, "ID格式错误", ctx.Param("id"))
|
||||
}
|
||||
|
||||
if err := c.service.DeletePigHouse(reqCtx, uint(id)); err != nil {
|
||||
if err := c.service.DeletePigHouse(reqCtx, uint32(id)); err != nil {
|
||||
if errors.Is(err, service.ErrHouseNotFound) {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, "猪舍不存在", action, "猪舍不存在", id)
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func (c *PigFarmController) GetPen(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID格式", action, "ID格式错误", ctx.Param("id"))
|
||||
}
|
||||
|
||||
pen, err := c.service.GetPenByID(reqCtx, uint(id))
|
||||
pen, err := c.service.GetPenByID(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
if errors.Is(err, service.ErrPenNotFound) {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, "猪栏不存在", action, "猪栏不存在", id)
|
||||
@@ -282,7 +282,7 @@ func (c *PigFarmController) UpdatePen(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的请求体", action, "请求体绑定失败", req)
|
||||
}
|
||||
|
||||
pen, err := c.service.UpdatePen(reqCtx, uint(id), req.PenNumber, req.HouseID, req.Capacity, req.Status)
|
||||
pen, err := c.service.UpdatePen(reqCtx, uint32(id), req.PenNumber, req.HouseID, req.Capacity, req.Status)
|
||||
if err != nil {
|
||||
if errors.Is(err, service.ErrPenNotFound) {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, "猪栏不存在", action, "猪栏不存在", id)
|
||||
@@ -312,7 +312,7 @@ func (c *PigFarmController) DeletePen(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的ID格式", action, "ID格式错误", ctx.Param("id"))
|
||||
}
|
||||
|
||||
if err := c.service.DeletePen(reqCtx, uint(id)); err != nil {
|
||||
if err := c.service.DeletePen(reqCtx, uint32(id)); err != nil {
|
||||
if errors.Is(err, service.ErrPenNotFound) {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, "猪栏不存在", action, "猪栏不存在", id)
|
||||
}
|
||||
@@ -351,7 +351,7 @@ func (c *PigFarmController) UpdatePenStatus(ctx echo.Context) error {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的请求体", action, "请求体绑定失败", req)
|
||||
}
|
||||
|
||||
pen, err := c.service.UpdatePenStatus(reqCtx, uint(id), req.Status)
|
||||
pen, err := c.service.UpdatePenStatus(reqCtx, uint32(id), req.Status)
|
||||
if err != nil {
|
||||
if errors.Is(err, service.ErrPenNotFound) {
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeNotFound, err.Error(), action, err.Error(), id)
|
||||
|
||||
@@ -81,14 +81,14 @@ func (c *Controller) GetPlan(ctx echo.Context) error {
|
||||
const actionType = "获取计划详情"
|
||||
// 1. 从 URL 路径中获取 ID
|
||||
idStr := ctx.Param("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 32)
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 计划ID格式错误: %v, ID: %s", actionType, err, idStr)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的计划ID格式", actionType, "计划ID格式错误", idStr)
|
||||
}
|
||||
|
||||
// 调用服务层获取计划详情
|
||||
resp, err := c.planService.GetPlanByID(reqCtx, uint(id))
|
||||
resp, err := c.planService.GetPlanByID(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层获取计划详情失败: %v, ID: %d", actionType, err, id)
|
||||
if errors.Is(err, plan.ErrPlanNotFound) { // 修改为 plan.ErrPlanNotFound
|
||||
@@ -147,7 +147,7 @@ func (c *Controller) UpdatePlan(ctx echo.Context) error {
|
||||
const actionType = "更新计划"
|
||||
// 1. 从 URL 路径中获取 ID
|
||||
idStr := ctx.Param("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 32)
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 计划ID格式错误: %v, ID: %s", actionType, err, idStr)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的计划ID格式", actionType, "计划ID格式错误", idStr)
|
||||
@@ -161,7 +161,7 @@ func (c *Controller) UpdatePlan(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// 调用服务层更新计划
|
||||
resp, err := c.planService.UpdatePlan(reqCtx, uint(id), &req)
|
||||
resp, err := c.planService.UpdatePlan(reqCtx, uint32(id), &req)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层更新计划失败: %v, ID: %d", actionType, err, id)
|
||||
if errors.Is(err, plan.ErrPlanNotFound) { // 修改为 plan.ErrPlanNotFound
|
||||
@@ -191,14 +191,14 @@ func (c *Controller) DeletePlan(ctx echo.Context) error {
|
||||
const actionType = "删除计划"
|
||||
// 1. 从 URL 路径中获取 ID
|
||||
idStr := ctx.Param("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 32)
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 计划ID格式错误: %v, ID: %s", actionType, err, idStr)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的计划ID格式", actionType, "计划ID格式错误", idStr)
|
||||
}
|
||||
|
||||
// 调用服务层删除计划
|
||||
err = c.planService.DeletePlan(reqCtx, uint(id))
|
||||
err = c.planService.DeletePlan(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层删除计划失败: %v, ID: %d", actionType, err, id)
|
||||
if errors.Is(err, plan.ErrPlanNotFound) { // 修改为 plan.ErrPlanNotFound
|
||||
@@ -228,14 +228,14 @@ func (c *Controller) StartPlan(ctx echo.Context) error {
|
||||
const actionType = "启动计划"
|
||||
// 1. 从 URL 路径中获取 ID
|
||||
idStr := ctx.Param("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 32)
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 计划ID格式错误: %v, ID: %s", actionType, err, idStr)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的计划ID格式", actionType, "计划ID格式错误", idStr)
|
||||
}
|
||||
|
||||
// 调用服务层启动计划
|
||||
err = c.planService.StartPlan(reqCtx, uint(id))
|
||||
err = c.planService.StartPlan(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层启动计划失败: %v, ID: %d", actionType, err, id)
|
||||
if errors.Is(err, plan.ErrPlanNotFound) { // 修改为 plan.ErrPlanNotFound
|
||||
@@ -267,14 +267,14 @@ func (c *Controller) StopPlan(ctx echo.Context) error {
|
||||
const actionType = "停止计划"
|
||||
// 1. 从 URL 路径中获取 ID
|
||||
idStr := ctx.Param("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 32)
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 计划ID格式错误: %v, ID: %s", actionType, err, idStr)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的计划ID格式", actionType, "计划ID格式错误", idStr)
|
||||
}
|
||||
|
||||
// 调用服务层停止计划
|
||||
err = c.planService.StopPlan(reqCtx, uint(id))
|
||||
err = c.planService.StopPlan(reqCtx, uint32(id))
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层停止计划失败: %v, ID: %d", actionType, err, id)
|
||||
if errors.Is(err, plan.ErrPlanNotFound) { // 修改为 plan.ErrPlanNotFound
|
||||
|
||||
@@ -101,7 +101,7 @@ func (c *Controller) SendTestNotification(ctx echo.Context) error {
|
||||
const actionType = "发送测试通知"
|
||||
|
||||
// 1. 从 URL 中获取用户 ID
|
||||
userID, err := strconv.ParseUint(ctx.Param("id"), 10, 32)
|
||||
userID, err := strconv.ParseUint(ctx.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 无效的用户ID格式: %v", actionType, err)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的用户ID格式", actionType, "无效的用户ID格式", ctx.Param("id"))
|
||||
@@ -115,7 +115,7 @@ func (c *Controller) SendTestNotification(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// 3. 调用服务层
|
||||
err = c.userService.SendTestNotification(reqCtx, uint(userID), &req)
|
||||
err = c.userService.SendTestNotification(reqCtx, uint32(userID), &req)
|
||||
if err != nil {
|
||||
logger.Errorf("%s: 服务层调用失败: %v", actionType, err)
|
||||
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "发送测试消息失败: "+err.Error(), actionType, "服务层调用失败", map[string]interface{}{"userID": userID, "type": req.Type})
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
// SnoozeAlarmRequest 定义了忽略告警的请求体
|
||||
type SnoozeAlarmRequest struct {
|
||||
DurationMinutes uint `json:"duration_minutes" validate:"required,min=1"` // 忽略时长,单位分钟
|
||||
DurationMinutes uint32 `json:"duration_minutes" validate:"required,min=1"` // 忽略时长,单位分钟
|
||||
}
|
||||
|
||||
// ListActiveAlarmRequest 定义了获取活跃告警列表的请求参数
|
||||
@@ -16,7 +16,7 @@ type ListActiveAlarmRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
SourceType *models.AlarmSourceType `json:"source_type" query:"source_type"` // 按告警来源类型过滤
|
||||
SourceID *uint `json:"source_id" query:"source_id"` // 按告警来源ID过滤
|
||||
SourceID *uint32 `json:"source_id" query:"source_id"` // 按告警来源ID过滤
|
||||
Level *models.SeverityLevel `json:"level" query:"level"` // 按告警严重性等级过滤
|
||||
IsIgnored *bool `json:"is_ignored" query:"is_ignored"` // 按是否被忽略过滤
|
||||
TriggerTime *time.Time `json:"trigger_time" query:"trigger_time"` // 告警触发时间范围 - 开始时间
|
||||
@@ -26,11 +26,11 @@ type ListActiveAlarmRequest struct {
|
||||
|
||||
// ActiveAlarmDTO 是用于API响应的活跃告警结构
|
||||
type ActiveAlarmDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
SourceType models.AlarmSourceType `json:"source_type"`
|
||||
SourceID uint `json:"source_id"`
|
||||
SourceID uint32 `json:"source_id"`
|
||||
AlarmCode models.AlarmCode `json:"alarm_code"`
|
||||
AlarmSummary string `json:"alarm_summary"`
|
||||
Level models.SeverityLevel `json:"level"`
|
||||
@@ -52,7 +52,7 @@ type ListHistoricalAlarmRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
SourceType *models.AlarmSourceType `json:"source_type" query:"source_type"` // 按告警来源类型过滤
|
||||
SourceID *uint `json:"source_id" query:"source_id"` // 按告警来源ID过滤
|
||||
SourceID *uint32 `json:"source_id" query:"source_id"` // 按告警来源ID过滤
|
||||
Level *models.SeverityLevel `json:"level" query:"level"` // 按告警严重性等级过滤
|
||||
TriggerTimeStart *time.Time `json:"trigger_time_start" query:"trigger_time_start"` // 告警触发时间范围 - 开始时间
|
||||
TriggerTimeEnd *time.Time `json:"trigger_time_end" query:"trigger_time_end"` // 告警触发时间范围 - 结束时间
|
||||
@@ -63,9 +63,9 @@ type ListHistoricalAlarmRequest struct {
|
||||
|
||||
// HistoricalAlarmDTO 是用于API响应的历史告警结构
|
||||
type HistoricalAlarmDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
SourceType models.AlarmSourceType `json:"source_type"`
|
||||
SourceID uint `json:"source_id"`
|
||||
SourceID uint32 `json:"source_id"`
|
||||
AlarmCode models.AlarmCode `json:"alarm_code"`
|
||||
AlarmSummary string `json:"alarm_summary"`
|
||||
Level models.SeverityLevel `json:"level"`
|
||||
@@ -73,7 +73,7 @@ type HistoricalAlarmDTO struct {
|
||||
TriggerTime time.Time `json:"trigger_time"`
|
||||
ResolveTime time.Time `json:"resolve_time"`
|
||||
ResolveMethod string `json:"resolve_method"`
|
||||
ResolvedBy *uint `json:"resolved_by"`
|
||||
ResolvedBy *uint32 `json:"resolved_by"`
|
||||
}
|
||||
|
||||
// ListHistoricalAlarmResponse 是获取历史告警列表的响应结构
|
||||
@@ -84,7 +84,7 @@ type ListHistoricalAlarmResponse struct {
|
||||
|
||||
// CreateDeviceThresholdAlarmDTO 创建设备阈值告警的请求DTO
|
||||
type CreateDeviceThresholdAlarmDTO struct {
|
||||
DeviceID uint `json:"device_id" binding:"required"` // 设备ID
|
||||
DeviceID uint32 `json:"device_id" binding:"required"` // 设备ID
|
||||
SensorType models.SensorType `json:"sensor_type" binding:"required"` // 传感器类型
|
||||
Thresholds float32 `json:"thresholds" binding:"required"` // 阈值
|
||||
Operator models.Operator `json:"operator" binding:"required"` // 操作符 (使用string类型,与前端交互更通用)
|
||||
@@ -100,7 +100,7 @@ type UpdateDeviceThresholdAlarmDTO struct {
|
||||
|
||||
// CreateAreaThresholdAlarmDTO 创建区域阈值告警的请求DTO
|
||||
type CreateAreaThresholdAlarmDTO struct {
|
||||
AreaControllerID uint `json:"area_controller_id" binding:"required"` // 区域主控ID
|
||||
AreaControllerID uint32 `json:"area_controller_id" binding:"required"` // 区域主控ID
|
||||
SensorType models.SensorType `json:"sensor_type" binding:"required"` // 传感器类型
|
||||
Thresholds float32 `json:"thresholds" binding:"required"` // 阈值
|
||||
Operator models.Operator `json:"operator" binding:"required"` // 操作符
|
||||
@@ -122,7 +122,7 @@ type DeleteDeviceThresholdAlarmDTO struct {
|
||||
// AreaThresholdAlarmDTO 用于表示一个区域阈值告警任务的详细信息
|
||||
type AreaThresholdAlarmDTO struct {
|
||||
ID int `json:"id"`
|
||||
AreaControllerID uint `json:"area_controller_id"`
|
||||
AreaControllerID uint32 `json:"area_controller_id"`
|
||||
SensorType models.SensorType `json:"sensor_type"`
|
||||
Thresholds float32 `json:"thresholds"`
|
||||
Operator models.Operator `json:"operator"`
|
||||
@@ -132,7 +132,7 @@ type AreaThresholdAlarmDTO struct {
|
||||
// DeviceThresholdAlarmDTO 用于表示一个设备阈值告警任务的详细信息
|
||||
type DeviceThresholdAlarmDTO struct {
|
||||
ID int `json:"id"`
|
||||
DeviceID uint `json:"device_id"`
|
||||
DeviceID uint32 `json:"device_id"`
|
||||
SensorType models.SensorType `json:"sensor_type"`
|
||||
Thresholds float32 `json:"thresholds"`
|
||||
Operator models.Operator `json:"operator"`
|
||||
|
||||
@@ -5,8 +5,8 @@ import "git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
// CreateDeviceRequest 定义了创建设备时需要传入的参数
|
||||
type CreateDeviceRequest struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
DeviceTemplateID uint `json:"device_template_id" validate:"required"`
|
||||
AreaControllerID uint `json:"area_controller_id" validate:"required"`
|
||||
DeviceTemplateID uint32 `json:"device_template_id" validate:"required"`
|
||||
AreaControllerID uint32 `json:"area_controller_id" validate:"required"`
|
||||
Location string `json:"location,omitempty" validate:"omitempty"`
|
||||
Properties map[string]interface{} `json:"properties,omitempty" validate:"omitempty"`
|
||||
}
|
||||
@@ -14,8 +14,8 @@ type CreateDeviceRequest struct {
|
||||
// UpdateDeviceRequest 定义了更新设备时需要传入的参数
|
||||
type UpdateDeviceRequest struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
DeviceTemplateID uint `json:"device_template_id" validate:"required"`
|
||||
AreaControllerID uint `json:"area_controller_id" validate:"required"`
|
||||
DeviceTemplateID uint32 `json:"device_template_id" validate:"required"`
|
||||
AreaControllerID uint32 `json:"area_controller_id" validate:"required"`
|
||||
Location string `json:"location,omitempty" validate:"omitempty"`
|
||||
Properties map[string]interface{} `json:"properties,omitempty" validate:"omitempty"`
|
||||
}
|
||||
@@ -64,11 +64,11 @@ type UpdateDeviceTemplateRequest struct {
|
||||
|
||||
// DeviceResponse 定义了返回给客户端的单个设备信息的结构
|
||||
type DeviceResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DeviceTemplateID uint `json:"device_template_id"`
|
||||
DeviceTemplateID uint32 `json:"device_template_id"`
|
||||
DeviceTemplateName string `json:"device_template_name"`
|
||||
AreaControllerID uint `json:"area_controller_id"`
|
||||
AreaControllerID uint32 `json:"area_controller_id"`
|
||||
AreaControllerName string `json:"area_controller_name"`
|
||||
Location string `json:"location"`
|
||||
Properties map[string]interface{} `json:"properties"`
|
||||
@@ -78,7 +78,7 @@ type DeviceResponse struct {
|
||||
|
||||
// AreaControllerResponse 定义了返回给客户端的单个区域主控信息的结构
|
||||
type AreaControllerResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
NetworkID string `json:"network_id"`
|
||||
Location string `json:"location"`
|
||||
@@ -90,7 +90,7 @@ type AreaControllerResponse struct {
|
||||
|
||||
// DeviceTemplateResponse 定义了返回给客户端的单个设备模板信息的结构
|
||||
type DeviceTemplateResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Manufacturer string `json:"manufacturer"`
|
||||
Description string `json:"description"`
|
||||
|
||||
@@ -54,7 +54,7 @@ func NewListDeviceCommandLogResponse(data []models.DeviceCommandLog, total int64
|
||||
|
||||
// NewListPlanExecutionLogResponse 从模型数据创建列表响应 DTO
|
||||
func NewListPlanExecutionLogResponse(planLogs []models.PlanExecutionLog, plans []models.Plan, total int64, page, pageSize int) *ListPlanExecutionLogResponse {
|
||||
planId2Name := make(map[uint]string)
|
||||
planId2Name := make(map[uint32]string)
|
||||
for _, plan := range plans {
|
||||
planId2Name[plan.ID] = string(plan.Name)
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func NewListTaskExecutionLogResponse(data []models.TaskExecutionLog, total int64
|
||||
PlanExecutionLogID: item.PlanExecutionLogID,
|
||||
TaskID: item.TaskID,
|
||||
Task: TaskDTO{
|
||||
ID: uint(item.Task.ID),
|
||||
ID: uint32(item.Task.ID),
|
||||
Name: item.Task.Name,
|
||||
Description: item.Task.Description,
|
||||
},
|
||||
@@ -373,7 +373,7 @@ func NewListWeighingRecordResponse(data []models.WeighingRecord, total int64, pa
|
||||
func NewListPigTransferLogResponse(data []models.PigTransferLog, total int64, page, pageSize int) *ListPigTransferLogResponse {
|
||||
dtos := make([]PigTransferLogDTO, len(data))
|
||||
for i, item := range data {
|
||||
// 注意:PigTransferLog 的 ID, CreatedAt, UpdatedAt 字段是 gorm.Model 嵌入的
|
||||
// 注意:PigTransferLog 的 ID, CreatedAt, UpdatedAt 字段是 Model 嵌入的
|
||||
dtos[i] = PigTransferLogDTO{
|
||||
ID: item.ID,
|
||||
CreatedAt: item.CreatedAt,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
type ListSensorDataRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
DeviceID *uint `json:"device_id" query:"device_id"`
|
||||
DeviceID *uint32 `json:"device_id" query:"device_id"`
|
||||
SensorType *string `json:"sensor_type" query:"sensor_type"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
@@ -23,8 +23,8 @@ type ListSensorDataRequest struct {
|
||||
// SensorDataDTO 是用于API响应的传感器数据结构
|
||||
type SensorDataDTO struct {
|
||||
Time time.Time `json:"time"`
|
||||
DeviceID uint `json:"device_id"`
|
||||
AreaControllerID uint `json:"area_controller_id"`
|
||||
DeviceID uint32 `json:"device_id"`
|
||||
AreaControllerID uint32 `json:"area_controller_id"`
|
||||
SensorType models.SensorType `json:"sensor_type"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
}
|
||||
@@ -41,7 +41,7 @@ type ListSensorDataResponse struct {
|
||||
type ListDeviceCommandLogRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
DeviceID *uint `json:"device_id" query:"device_id"`
|
||||
DeviceID *uint32 `json:"device_id" query:"device_id"`
|
||||
ReceivedSuccess *bool `json:"received_success" query:"received_success"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
@@ -51,7 +51,7 @@ type ListDeviceCommandLogRequest struct {
|
||||
// DeviceCommandLogDTO 是用于API响应的设备命令日志结构
|
||||
type DeviceCommandLogDTO struct {
|
||||
MessageID string `json:"message_id"`
|
||||
DeviceID uint `json:"device_id"`
|
||||
DeviceID uint32 `json:"device_id"`
|
||||
SentAt time.Time `json:"sent_at"`
|
||||
AcknowledgedAt *time.Time `json:"acknowledged_at"`
|
||||
ReceivedSuccess bool `json:"received_success"`
|
||||
@@ -69,7 +69,7 @@ type ListDeviceCommandLogResponse struct {
|
||||
type ListPlanExecutionLogRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PlanID *uint `json:"plan_id" query:"plan_id"`
|
||||
PlanID *uint32 `json:"plan_id" query:"plan_id"`
|
||||
Status *string `json:"status" query:"status"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
@@ -78,10 +78,10 @@ type ListPlanExecutionLogRequest struct {
|
||||
|
||||
// PlanExecutionLogDTO 是用于API响应的计划执行日志结构
|
||||
type PlanExecutionLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
PlanID uint `json:"plan_id"`
|
||||
PlanID uint32 `json:"plan_id"`
|
||||
PlanName string `json:"plan_name"`
|
||||
Status models.ExecutionStatus `json:"status"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
@@ -101,7 +101,7 @@ type ListPlanExecutionLogResponse struct {
|
||||
type ListTaskExecutionLogRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PlanExecutionLogID *uint `json:"plan_execution_log_id" query:"plan_execution_log_id"`
|
||||
PlanExecutionLogID *uint32 `json:"plan_execution_log_id" query:"plan_execution_log_id"`
|
||||
TaskID *int `json:"task_id" query:"task_id"`
|
||||
Status *string `json:"status" query:"status"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
@@ -111,17 +111,17 @@ type ListTaskExecutionLogRequest struct {
|
||||
|
||||
// TaskDTO 是用于API响应的简化版任务结构
|
||||
type TaskDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// TaskExecutionLogDTO 是用于API响应的任务执行日志结构
|
||||
type TaskExecutionLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
PlanExecutionLogID uint `json:"plan_execution_log_id"`
|
||||
PlanExecutionLogID uint32 `json:"plan_execution_log_id"`
|
||||
TaskID int `json:"task_id"`
|
||||
Task TaskDTO `json:"task"` // 嵌套的任务信息
|
||||
Status models.ExecutionStatus `json:"status"`
|
||||
@@ -142,7 +142,7 @@ type ListTaskExecutionLogResponse struct {
|
||||
type ListPendingCollectionRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
DeviceID *uint `json:"device_id" query:"device_id"`
|
||||
DeviceID *uint32 `json:"device_id" query:"device_id"`
|
||||
Status *string `json:"status" query:"status"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
@@ -152,7 +152,7 @@ type ListPendingCollectionRequest struct {
|
||||
// PendingCollectionDTO 是用于API响应的待采集请求结构
|
||||
type PendingCollectionDTO struct {
|
||||
CorrelationID string `json:"correlation_id"`
|
||||
DeviceID uint `json:"device_id"`
|
||||
DeviceID uint32 `json:"device_id"`
|
||||
CommandMetadata models.UintArray `json:"command_metadata"`
|
||||
Status models.PendingCollectionStatus `json:"status"`
|
||||
FulfilledAt *time.Time `json:"fulfilled_at"`
|
||||
@@ -171,7 +171,7 @@ type ListPendingCollectionResponse struct {
|
||||
type ListUserActionLogRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
UserID *uint `json:"user_id" query:"user_id"`
|
||||
UserID *uint32 `json:"user_id" query:"user_id"`
|
||||
Username *string `json:"username" query:"username"`
|
||||
ActionType *string `json:"action_type" query:"action_type"`
|
||||
Status *string `json:"status" query:"status"`
|
||||
@@ -182,9 +182,9 @@ type ListUserActionLogRequest struct {
|
||||
|
||||
// UserActionLogDTO 是用于API响应的用户操作日志结构
|
||||
type UserActionLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Time time.Time `json:"time"`
|
||||
UserID uint `json:"user_id"`
|
||||
UserID uint32 `json:"user_id"`
|
||||
Username string `json:"username"`
|
||||
SourceIP string `json:"source_ip"`
|
||||
ActionType string `json:"action_type"`
|
||||
@@ -208,7 +208,7 @@ type ListUserActionLogResponse struct {
|
||||
type ListRawMaterialPurchaseRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
RawMaterialID *uint `json:"raw_material_id" query:"raw_material_id"`
|
||||
RawMaterialID *uint32 `json:"raw_material_id" query:"raw_material_id"`
|
||||
Supplier *string `json:"supplier" query:"supplier"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
@@ -217,14 +217,14 @@ type ListRawMaterialPurchaseRequest struct {
|
||||
|
||||
// RawMaterialDTO 是用于API响应的简化版原料结构
|
||||
type RawMaterialDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// RawMaterialPurchaseDTO 是用于API响应的原料采购结构
|
||||
type RawMaterialPurchaseDTO struct {
|
||||
ID uint `json:"id"`
|
||||
RawMaterialID uint `json:"raw_material_id"`
|
||||
ID uint32 `json:"id"`
|
||||
RawMaterialID uint32 `json:"raw_material_id"`
|
||||
RawMaterial RawMaterialDTO `json:"raw_material"`
|
||||
Supplier string `json:"supplier"`
|
||||
Amount float32 `json:"amount"`
|
||||
@@ -246,9 +246,9 @@ type ListRawMaterialPurchaseResponse struct {
|
||||
type ListRawMaterialStockLogRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
RawMaterialID *uint `json:"raw_material_id" query:"raw_material_id"`
|
||||
RawMaterialID *uint32 `json:"raw_material_id" query:"raw_material_id"`
|
||||
SourceType *string `json:"source_type" query:"source_type"`
|
||||
SourceID *uint `json:"source_id" query:"source_id"`
|
||||
SourceID *uint32 `json:"source_id" query:"source_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
OrderBy string `json:"order_by" query:"order_by"`
|
||||
@@ -256,11 +256,11 @@ type ListRawMaterialStockLogRequest struct {
|
||||
|
||||
// RawMaterialStockLogDTO 是用于API响应的原料库存日志结构
|
||||
type RawMaterialStockLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
RawMaterialID uint `json:"raw_material_id"`
|
||||
ID uint32 `json:"id"`
|
||||
RawMaterialID uint32 `json:"raw_material_id"`
|
||||
ChangeAmount float32 `json:"change_amount"`
|
||||
SourceType models.StockLogSourceType `json:"source_type"`
|
||||
SourceID uint `json:"source_id"`
|
||||
SourceID uint32 `json:"source_id"`
|
||||
HappenedAt time.Time `json:"happened_at"`
|
||||
Remarks string `json:"remarks"`
|
||||
}
|
||||
@@ -277,9 +277,9 @@ type ListRawMaterialStockLogResponse struct {
|
||||
type ListFeedUsageRecordRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PenID *uint `json:"pen_id" query:"pen_id"`
|
||||
FeedFormulaID *uint `json:"feed_formula_id" query:"feed_formula_id"`
|
||||
OperatorID *uint `json:"operator_id" query:"operator_id"`
|
||||
PenID *uint32 `json:"pen_id" query:"pen_id"`
|
||||
FeedFormulaID *uint32 `json:"feed_formula_id" query:"feed_formula_id"`
|
||||
OperatorID *uint32 `json:"operator_id" query:"operator_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
OrderBy string `json:"order_by" query:"order_by"`
|
||||
@@ -287,26 +287,26 @@ type ListFeedUsageRecordRequest struct {
|
||||
|
||||
// PenDTO 是用于API响应的简化版猪栏结构
|
||||
type PenDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// FeedFormulaDTO 是用于API响应的简化版饲料配方结构
|
||||
type FeedFormulaDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// FeedUsageRecordDTO 是用于API响应的饲料使用记录结构
|
||||
type FeedUsageRecordDTO struct {
|
||||
ID uint `json:"id"`
|
||||
PenID uint `json:"pen_id"`
|
||||
ID uint32 `json:"id"`
|
||||
PenID uint32 `json:"pen_id"`
|
||||
Pen PenDTO `json:"pen"`
|
||||
FeedFormulaID uint `json:"feed_formula_id"`
|
||||
FeedFormulaID uint32 `json:"feed_formula_id"`
|
||||
FeedFormula FeedFormulaDTO `json:"feed_formula"`
|
||||
Amount float32 `json:"amount"`
|
||||
RecordedAt time.Time `json:"recorded_at"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
OperatorID uint32 `json:"operator_id"`
|
||||
Remarks string `json:"remarks"`
|
||||
}
|
||||
|
||||
@@ -322,10 +322,10 @@ type ListFeedUsageRecordResponse struct {
|
||||
type ListMedicationLogRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PigBatchID *uint `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
MedicationID *uint `json:"medication_id" query:"medication_id"`
|
||||
PigBatchID *uint32 `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
MedicationID *uint32 `json:"medication_id" query:"medication_id"`
|
||||
Reason *string `json:"reason" query:"reason"`
|
||||
OperatorID *uint `json:"operator_id" query:"operator_id"`
|
||||
OperatorID *uint32 `json:"operator_id" query:"operator_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
OrderBy string `json:"order_by" query:"order_by"`
|
||||
@@ -333,21 +333,21 @@ type ListMedicationLogRequest struct {
|
||||
|
||||
// MedicationDTO 是用于API响应的简化版药品结构
|
||||
type MedicationDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// MedicationLogDTO 是用于API响应的用药记录结构
|
||||
type MedicationLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
PigBatchID uint `json:"pig_batch_id"`
|
||||
MedicationID uint `json:"medication_id"`
|
||||
ID uint32 `json:"id"`
|
||||
PigBatchID uint32 `json:"pig_batch_id"`
|
||||
MedicationID uint32 `json:"medication_id"`
|
||||
Medication MedicationDTO `json:"medication"`
|
||||
DosageUsed float32 `json:"dosage_used"`
|
||||
TargetCount int `json:"target_count"`
|
||||
Reason models.MedicationReasonType `json:"reason"`
|
||||
Description string `json:"description"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
OperatorID uint32 `json:"operator_id"`
|
||||
HappenedAt time.Time `json:"happened_at"`
|
||||
}
|
||||
|
||||
@@ -363,9 +363,9 @@ type ListMedicationLogResponse struct {
|
||||
type ListPigBatchLogRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PigBatchID *uint `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
PigBatchID *uint32 `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
ChangeType *string `json:"change_type" query:"change_type"`
|
||||
OperatorID *uint `json:"operator_id" query:"operator_id"`
|
||||
OperatorID *uint32 `json:"operator_id" query:"operator_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
OrderBy string `json:"order_by" query:"order_by"`
|
||||
@@ -373,16 +373,16 @@ type ListPigBatchLogRequest struct {
|
||||
|
||||
// PigBatchLogDTO 是用于API响应的猪批次日志结构
|
||||
type PigBatchLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
PigBatchID uint `json:"pig_batch_id"`
|
||||
PigBatchID uint32 `json:"pig_batch_id"`
|
||||
ChangeType models.LogChangeType `json:"change_type"`
|
||||
ChangeCount int `json:"change_count"`
|
||||
Reason string `json:"reason"`
|
||||
BeforeCount int `json:"before_count"`
|
||||
AfterCount int `json:"after_count"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
OperatorID uint32 `json:"operator_id"`
|
||||
HappenedAt time.Time `json:"happened_at"`
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ type ListPigBatchLogResponse struct {
|
||||
type ListWeighingBatchRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PigBatchID *uint `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
PigBatchID *uint32 `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
OrderBy string `json:"order_by" query:"order_by"`
|
||||
@@ -406,12 +406,12 @@ type ListWeighingBatchRequest struct {
|
||||
|
||||
// WeighingBatchDTO 是用于API响应的批次称重记录结构
|
||||
type WeighingBatchDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
WeighingTime time.Time `json:"weighing_time"`
|
||||
Description string `json:"description"`
|
||||
PigBatchID uint `json:"pig_batch_id"`
|
||||
PigBatchID uint32 `json:"pig_batch_id"`
|
||||
}
|
||||
|
||||
// ListWeighingBatchResponse 是获取批次称重记录列表的响应结构
|
||||
@@ -426,9 +426,9 @@ type ListWeighingBatchResponse struct {
|
||||
type ListWeighingRecordRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
WeighingBatchID *uint `json:"weighing_batch_id" query:"weighing_batch_id"`
|
||||
PenID *uint `json:"pen_id" query:"pen_id"`
|
||||
OperatorID *uint `json:"operator_id" query:"operator_id"`
|
||||
WeighingBatchID *uint32 `json:"weighing_batch_id" query:"weighing_batch_id"`
|
||||
PenID *uint32 `json:"pen_id" query:"pen_id"`
|
||||
OperatorID *uint32 `json:"operator_id" query:"operator_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
OrderBy string `json:"order_by" query:"order_by"`
|
||||
@@ -436,13 +436,13 @@ type ListWeighingRecordRequest struct {
|
||||
|
||||
// WeighingRecordDTO 是用于API响应的单次称重记录结构
|
||||
type WeighingRecordDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Weight float32 `json:"weight"`
|
||||
WeighingBatchID uint `json:"weighing_batch_id"`
|
||||
PenID uint `json:"pen_id"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
WeighingBatchID uint32 `json:"weighing_batch_id"`
|
||||
PenID uint32 `json:"pen_id"`
|
||||
OperatorID uint32 `json:"operator_id"`
|
||||
Remark string `json:"remark"`
|
||||
WeighingTime time.Time `json:"weighing_time"`
|
||||
}
|
||||
@@ -459,10 +459,10 @@ type ListWeighingRecordResponse struct {
|
||||
type ListPigTransferLogRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PigBatchID *uint `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
PenID *uint `json:"pen_id" query:"pen_id"`
|
||||
PigBatchID *uint32 `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
PenID *uint32 `json:"pen_id" query:"pen_id"`
|
||||
TransferType *string `json:"transfer_type" query:"transfer_type"`
|
||||
OperatorID *uint `json:"operator_id" query:"operator_id"`
|
||||
OperatorID *uint32 `json:"operator_id" query:"operator_id"`
|
||||
CorrelationID *string `json:"correlation_id" query:"correlation_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
@@ -471,16 +471,16 @@ type ListPigTransferLogRequest struct {
|
||||
|
||||
// PigTransferLogDTO 是用于API响应的猪只迁移日志结构
|
||||
type PigTransferLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
TransferTime time.Time `json:"transfer_time"`
|
||||
PigBatchID uint `json:"pig_batch_id"`
|
||||
PenID uint `json:"pen_id"`
|
||||
PigBatchID uint32 `json:"pig_batch_id"`
|
||||
PenID uint32 `json:"pen_id"`
|
||||
Quantity int `json:"quantity"`
|
||||
Type models.PigTransferType `json:"type"`
|
||||
CorrelationID string `json:"correlation_id"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
OperatorID uint32 `json:"operator_id"`
|
||||
Remarks string `json:"remarks"`
|
||||
}
|
||||
|
||||
@@ -496,11 +496,11 @@ type ListPigTransferLogResponse struct {
|
||||
type ListPigSickLogRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PigBatchID *uint `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
PenID *uint `json:"pen_id" query:"pen_id"`
|
||||
PigBatchID *uint32 `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
PenID *uint32 `json:"pen_id" query:"pen_id"`
|
||||
Reason *string `json:"reason" query:"reason"`
|
||||
TreatmentLocation *string `json:"treatment_location" query:"treatment_location"`
|
||||
OperatorID *uint `json:"operator_id" query:"operator_id"`
|
||||
OperatorID *uint32 `json:"operator_id" query:"operator_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
OrderBy string `json:"order_by" query:"order_by"`
|
||||
@@ -508,18 +508,18 @@ type ListPigSickLogRequest struct {
|
||||
|
||||
// PigSickLogDTO 是用于API响应的病猪日志结构
|
||||
type PigSickLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
PigBatchID uint `json:"pig_batch_id"`
|
||||
PenID uint `json:"pen_id"`
|
||||
PigBatchID uint32 `json:"pig_batch_id"`
|
||||
PenID uint32 `json:"pen_id"`
|
||||
ChangeCount int `json:"change_count"`
|
||||
Reason models.PigBatchSickPigReasonType `json:"reason"`
|
||||
BeforeCount int `json:"before_count"`
|
||||
AfterCount int `json:"after_count"`
|
||||
Remarks string `json:"remarks"`
|
||||
TreatmentLocation models.PigBatchSickPigTreatmentLocation `json:"treatment_location"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
OperatorID uint32 `json:"operator_id"`
|
||||
HappenedAt time.Time `json:"happened_at"`
|
||||
}
|
||||
|
||||
@@ -535,9 +535,9 @@ type ListPigSickLogResponse struct {
|
||||
type ListPigPurchaseRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PigBatchID *uint `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
PigBatchID *uint32 `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
Supplier *string `json:"supplier" query:"supplier"`
|
||||
OperatorID *uint `json:"operator_id" query:"operator_id"`
|
||||
OperatorID *uint32 `json:"operator_id" query:"operator_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
OrderBy string `json:"order_by" query:"order_by"`
|
||||
@@ -545,17 +545,17 @@ type ListPigPurchaseRequest struct {
|
||||
|
||||
// PigPurchaseDTO 是用于API响应的猪只采购记录结构
|
||||
type PigPurchaseDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
PigBatchID uint `json:"pig_batch_id"`
|
||||
PigBatchID uint32 `json:"pig_batch_id"`
|
||||
PurchaseDate time.Time `json:"purchase_date"`
|
||||
Supplier string `json:"supplier"`
|
||||
Quantity int `json:"quantity"`
|
||||
UnitPrice float32 `json:"unit_price"`
|
||||
TotalPrice float32 `json:"total_price"`
|
||||
Remarks string `json:"remarks"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
OperatorID uint32 `json:"operator_id"`
|
||||
}
|
||||
|
||||
// ListPigPurchaseResponse 是获取猪只采购记录列表的响应结构
|
||||
@@ -570,9 +570,9 @@ type ListPigPurchaseResponse struct {
|
||||
type ListPigSaleRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
PigBatchID *uint `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
PigBatchID *uint32 `json:"pig_batch_id" query:"pig_batch_id"`
|
||||
Buyer *string `json:"buyer" query:"buyer"`
|
||||
OperatorID *uint `json:"operator_id" query:"operator_id"`
|
||||
OperatorID *uint32 `json:"operator_id" query:"operator_id"`
|
||||
StartTime *time.Time `json:"start_time" query:"start_time"`
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"`
|
||||
OrderBy string `json:"order_by" query:"order_by"`
|
||||
@@ -580,17 +580,17 @@ type ListPigSaleRequest struct {
|
||||
|
||||
// PigSaleDTO 是用于API响应的猪只销售记录结构
|
||||
type PigSaleDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
PigBatchID uint `json:"pig_batch_id"`
|
||||
PigBatchID uint32 `json:"pig_batch_id"`
|
||||
SaleDate time.Time `json:"sale_date"`
|
||||
Buyer string `json:"buyer"`
|
||||
Quantity int `json:"quantity"`
|
||||
UnitPrice float32 `json:"unit_price"`
|
||||
TotalPrice float32 `json:"total_price"`
|
||||
Remarks string `json:"remarks"`
|
||||
OperatorID uint `json:"operator_id"`
|
||||
OperatorID uint32 `json:"operator_id"`
|
||||
}
|
||||
|
||||
// ListPigSaleResponse 是获取猪只销售记录列表的响应结构
|
||||
|
||||
@@ -18,7 +18,7 @@ type SendTestNotificationRequest struct {
|
||||
type ListNotificationRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
UserID *uint `json:"user_id" query:"user_id"`
|
||||
UserID *uint32 `json:"user_id" query:"user_id"`
|
||||
NotifierType *models.NotifierType `json:"notifier_type" query:"notifier_type"`
|
||||
Status *models.NotificationStatus `json:"status" query:"status"`
|
||||
Level *zapcore.Level `json:"level" query:"level"`
|
||||
@@ -29,11 +29,11 @@ type ListNotificationRequest struct {
|
||||
|
||||
// NotificationDTO 是用于API响应的通知结构
|
||||
type NotificationDTO struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
NotifierType models.NotifierType `json:"notifier_type"`
|
||||
UserID uint `json:"user_id"`
|
||||
UserID uint32 `json:"user_id"`
|
||||
Title string `json:"title"`
|
||||
Message string `json:"message"`
|
||||
Level models.SeverityLevel `json:"level"`
|
||||
|
||||
@@ -32,7 +32,7 @@ type PigBatchQueryDTO struct {
|
||||
|
||||
// PigBatchResponseDTO 定义了猪批次信息的响应结构
|
||||
type PigBatchResponseDTO struct {
|
||||
ID uint `json:"id"` // 批次ID
|
||||
ID uint32 `json:"id"` // 批次ID
|
||||
BatchNumber string `json:"batch_number"` // 批次编号
|
||||
OriginType models.PigBatchOriginType `json:"origin_type"` // 批次来源
|
||||
StartDate time.Time `json:"start_date"` // 批次开始日期
|
||||
@@ -48,31 +48,31 @@ type PigBatchResponseDTO struct {
|
||||
|
||||
// AssignEmptyPensToBatchRequest 用于为猪批次分配空栏的请求体
|
||||
type AssignEmptyPensToBatchRequest struct {
|
||||
PenIDs []uint `json:"pen_ids" validate:"required,min=1,dive" example:"1,2,3"` // 待分配的猪栏ID列表
|
||||
PenIDs []uint32 `json:"pen_ids" validate:"required,min=1,dive" example:"1,2,3"` // 待分配的猪栏ID列表
|
||||
}
|
||||
|
||||
// ReclassifyPenToNewBatchRequest 用于将猪栏划拨到新批次的请求体
|
||||
type ReclassifyPenToNewBatchRequest struct {
|
||||
ToBatchID uint `json:"to_batch_id" validate:"required"` // 目标猪批次ID
|
||||
PenID uint `json:"pen_id" validate:"required"` // 待划拨的猪栏ID
|
||||
ToBatchID uint32 `json:"to_batch_id" validate:"required"` // 目标猪批次ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 待划拨的猪栏ID
|
||||
Remarks string `json:"remarks"` // 备注
|
||||
}
|
||||
|
||||
// RemoveEmptyPenFromBatchRequest 用于从猪批次移除空栏的请求体
|
||||
type RemoveEmptyPenFromBatchRequest struct {
|
||||
PenID uint `json:"pen_id" validate:"required"` // 待移除的猪栏ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 待移除的猪栏ID
|
||||
}
|
||||
|
||||
// MovePigsIntoPenRequest 用于将猪只从“虚拟库存”移入指定猪栏的请求体
|
||||
type MovePigsIntoPenRequest struct {
|
||||
ToPenID uint `json:"to_pen_id" validate:"required"` // 目标猪栏ID
|
||||
ToPenID uint32 `json:"to_pen_id" validate:"required"` // 目标猪栏ID
|
||||
Quantity int `json:"quantity" validate:"required,min=1"` // 移入猪只数量
|
||||
Remarks string `json:"remarks"` // 备注
|
||||
}
|
||||
|
||||
// SellPigsRequest 用于处理卖猪的请求体
|
||||
type SellPigsRequest struct {
|
||||
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
Quantity int `json:"quantity" validate:"required,min=1"` // 卖出猪只数量
|
||||
UnitPrice float32 `json:"unit_price" validate:"required,min=0"` // 单价
|
||||
TotalPrice float32 `json:"total_price" validate:"required,min=0"` // 总价
|
||||
@@ -83,7 +83,7 @@ type SellPigsRequest struct {
|
||||
|
||||
// BuyPigsRequest 用于处理买猪的请求体
|
||||
type BuyPigsRequest struct {
|
||||
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
Quantity int `json:"quantity" validate:"required,min=1"` // 买入猪只数量
|
||||
UnitPrice float32 `json:"unit_price" validate:"required,min=0"` // 单价
|
||||
TotalPrice float32 `json:"total_price" validate:"required,min=0"` // 总价
|
||||
@@ -94,24 +94,24 @@ type BuyPigsRequest struct {
|
||||
|
||||
// TransferPigsAcrossBatchesRequest 用于跨猪群调栏的请求体
|
||||
type TransferPigsAcrossBatchesRequest struct {
|
||||
DestBatchID uint `json:"dest_batch_id" validate:"required"` // 目标猪批次ID
|
||||
FromPenID uint `json:"from_pen_id" validate:"required"` // 源猪栏ID
|
||||
ToPenID uint `json:"to_pen_id" validate:"required"` // 目标猪栏ID
|
||||
Quantity uint `json:"quantity" validate:"required,min=1"` // 调栏猪只数量
|
||||
DestBatchID uint32 `json:"dest_batch_id" validate:"required"` // 目标猪批次ID
|
||||
FromPenID uint32 `json:"from_pen_id" validate:"required"` // 源猪栏ID
|
||||
ToPenID uint32 `json:"to_pen_id" validate:"required"` // 目标猪栏ID
|
||||
Quantity uint32 `json:"quantity" validate:"required,min=1"` // 调栏猪只数量
|
||||
Remarks string `json:"remarks"` // 备注
|
||||
}
|
||||
|
||||
// TransferPigsWithinBatchRequest 用于群内调栏的请求体
|
||||
type TransferPigsWithinBatchRequest struct {
|
||||
FromPenID uint `json:"from_pen_id" validate:"required"` // 源猪栏ID
|
||||
ToPenID uint `json:"to_pen_id" validate:"required"` // 目标猪栏ID
|
||||
Quantity uint `json:"quantity" validate:"required,min=1"` // 调栏猪只数量
|
||||
FromPenID uint32 `json:"from_pen_id" validate:"required"` // 源猪栏ID
|
||||
ToPenID uint32 `json:"to_pen_id" validate:"required"` // 目标猪栏ID
|
||||
Quantity uint32 `json:"quantity" validate:"required,min=1"` // 调栏猪只数量
|
||||
Remarks string `json:"remarks"` // 备注
|
||||
}
|
||||
|
||||
// RecordSickPigsRequest 用于记录新增病猪事件的请求体
|
||||
type RecordSickPigsRequest struct {
|
||||
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
Quantity int `json:"quantity" validate:"required,min=1"` // 病猪数量
|
||||
TreatmentLocation models.PigBatchSickPigTreatmentLocation `json:"treatment_location" validate:"required"` // 治疗地点
|
||||
HappenedAt time.Time `json:"happened_at" validate:"required"` // 发生时间
|
||||
@@ -120,7 +120,7 @@ type RecordSickPigsRequest struct {
|
||||
|
||||
// RecordSickPigRecoveryRequest 用于记录病猪康复事件的请求体
|
||||
type RecordSickPigRecoveryRequest struct {
|
||||
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
Quantity int `json:"quantity" validate:"required,min=1"` // 康复猪数量
|
||||
TreatmentLocation models.PigBatchSickPigTreatmentLocation `json:"treatment_location" validate:"required"` // 治疗地点
|
||||
HappenedAt time.Time `json:"happened_at" validate:"required"` // 发生时间
|
||||
@@ -129,7 +129,7 @@ type RecordSickPigRecoveryRequest struct {
|
||||
|
||||
// RecordSickPigDeathRequest 用于记录病猪死亡事件的请求体
|
||||
type RecordSickPigDeathRequest struct {
|
||||
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
Quantity int `json:"quantity" validate:"required,min=1"` // 死亡猪数量
|
||||
TreatmentLocation models.PigBatchSickPigTreatmentLocation `json:"treatment_location" validate:"required"` // 治疗地点
|
||||
HappenedAt time.Time `json:"happened_at" validate:"required"` // 发生时间
|
||||
@@ -138,7 +138,7 @@ type RecordSickPigDeathRequest struct {
|
||||
|
||||
// RecordSickPigCullRequest 用于记录病猪淘汰事件的请求体
|
||||
type RecordSickPigCullRequest struct {
|
||||
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
Quantity int `json:"quantity" validate:"required,min=1"` // 淘汰猪数量
|
||||
TreatmentLocation models.PigBatchSickPigTreatmentLocation `json:"treatment_location" validate:"required"` // 治疗地点
|
||||
HappenedAt time.Time `json:"happened_at" validate:"required"` // 发生时间
|
||||
@@ -147,7 +147,7 @@ type RecordSickPigCullRequest struct {
|
||||
|
||||
// RecordDeathRequest 用于记录正常猪只死亡事件的请求体
|
||||
type RecordDeathRequest struct {
|
||||
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
Quantity int `json:"quantity" validate:"required,min=1"` // 死亡猪数量
|
||||
HappenedAt time.Time `json:"happened_at" validate:"required"` // 发生时间
|
||||
Remarks string `json:"remarks"` // 备注
|
||||
@@ -155,7 +155,7 @@ type RecordDeathRequest struct {
|
||||
|
||||
// RecordCullRequest 用于记录正常猪只淘汰事件的请求体
|
||||
type RecordCullRequest struct {
|
||||
PenID uint `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
PenID uint32 `json:"pen_id" validate:"required"` // 猪栏ID
|
||||
Quantity int `json:"quantity" validate:"required,min=1"` // 淘汰猪数量
|
||||
HappenedAt time.Time `json:"happened_at" validate:"required"` // 发生时间
|
||||
Remarks string `json:"remarks"` // 备注
|
||||
|
||||
@@ -4,19 +4,19 @@ import "git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
|
||||
// PigHouseResponse 定义了猪舍信息的响应结构
|
||||
type PigHouseResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// PenResponse 定义了猪栏信息的响应结构
|
||||
type PenResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ID uint32 `json:"id"`
|
||||
PenNumber string `json:"pen_number"`
|
||||
HouseID uint `json:"house_id"`
|
||||
HouseID uint32 `json:"house_id"`
|
||||
Capacity int `json:"capacity"`
|
||||
Status models.PenStatus `json:"status"`
|
||||
PigBatchID *uint `json:"pig_batch_id,omitempty"`
|
||||
PigBatchID *uint32 `json:"pig_batch_id,omitempty"`
|
||||
CurrentPigCount int `json:"current_pig_count"`
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ type UpdatePigHouseRequest struct {
|
||||
// CreatePenRequest 定义了创建猪栏的请求结构
|
||||
type CreatePenRequest struct {
|
||||
PenNumber string `json:"pen_number" validate:"required"`
|
||||
HouseID uint `json:"house_id" validate:"required"`
|
||||
HouseID uint32 `json:"house_id" validate:"required"`
|
||||
Capacity int `json:"capacity" validate:"required"`
|
||||
}
|
||||
|
||||
// UpdatePenRequest 定义了更新猪栏的请求结构
|
||||
type UpdatePenRequest struct {
|
||||
PenNumber string `json:"pen_number" validate:"required"`
|
||||
HouseID uint `json:"house_id" validate:"required"`
|
||||
HouseID uint32 `json:"house_id" validate:"required"`
|
||||
Capacity int `json:"capacity" validate:"required"`
|
||||
Status models.PenStatus `json:"status" validate:"required,oneof=空闲 使用中 病猪栏 康复栏 清洗消毒 维修中"` // 添加oneof校验
|
||||
}
|
||||
|
||||
@@ -17,22 +17,22 @@ type CreatePlanRequest struct {
|
||||
Name string `json:"name" validate:"required" example:"猪舍温度控制计划"`
|
||||
Description string `json:"description" example:"根据温度自动调节风扇和加热器"`
|
||||
ExecutionType models.PlanExecutionType `json:"execution_type" validate:"required" example:"自动"`
|
||||
ExecuteNum uint `json:"execute_num,omitempty" validate:"omitempty,min=0" example:"10"`
|
||||
ExecuteNum uint32 `json:"execute_num,omitempty" validate:"omitempty,min=0" example:"10"`
|
||||
CronExpression string `json:"cron_expression" validate:"omitempty,cron" example:"0 0 6 * * *"`
|
||||
SubPlanIDs []uint `json:"sub_plan_ids,omitempty" validate:"omitempty,dive"`
|
||||
SubPlanIDs []uint32 `json:"sub_plan_ids,omitempty" validate:"omitempty,dive"`
|
||||
Tasks []TaskRequest `json:"tasks,omitempty" validate:"omitempty,dive"`
|
||||
}
|
||||
|
||||
// PlanResponse 定义计划详情响应的结构体
|
||||
type PlanResponse struct {
|
||||
ID uint `json:"id" example:"1"`
|
||||
ID uint32 `json:"id" example:"1"`
|
||||
Name string `json:"name" example:"猪舍温度控制计划"`
|
||||
Description string `json:"description" example:"根据温度自动调节风扇和加热器"`
|
||||
PlanType models.PlanType `json:"plan_type" example:"自定义任务"`
|
||||
ExecutionType models.PlanExecutionType `json:"execution_type" example:"自动"`
|
||||
Status models.PlanStatus `json:"status" example:"已启用"`
|
||||
ExecuteNum uint `json:"execute_num" example:"10"`
|
||||
ExecuteCount uint `json:"execute_count" example:"0"`
|
||||
ExecuteNum uint32 `json:"execute_num" example:"10"`
|
||||
ExecuteCount uint32 `json:"execute_count" example:"0"`
|
||||
CronExpression string `json:"cron_expression" example:"0 0 6 * * *"`
|
||||
ContentType models.PlanContentType `json:"content_type" example:"任务"`
|
||||
SubPlans []SubPlanResponse `json:"sub_plans,omitempty"`
|
||||
@@ -50,17 +50,17 @@ type UpdatePlanRequest struct {
|
||||
Name string `json:"name" example:"猪舍温度控制计划V2"`
|
||||
Description string `json:"description" example:"更新后的描述"`
|
||||
ExecutionType models.PlanExecutionType `json:"execution_type" validate:"required" example:"自动"`
|
||||
ExecuteNum uint `json:"execute_num,omitempty" validate:"omitempty,min=0" example:"10"`
|
||||
ExecuteNum uint32 `json:"execute_num,omitempty" validate:"omitempty,min=0" example:"10"`
|
||||
CronExpression string `json:"cron_expression" validate:"omitempty,cron" example:"0 0 6 * * *"`
|
||||
SubPlanIDs []uint `json:"sub_plan_ids,omitempty" validate:"omitempty,dive"`
|
||||
SubPlanIDs []uint32 `json:"sub_plan_ids,omitempty" validate:"omitempty,dive"`
|
||||
Tasks []TaskRequest `json:"tasks,omitempty" validate:"omitempty,dive"`
|
||||
}
|
||||
|
||||
// SubPlanResponse 定义子计划响应结构体
|
||||
type SubPlanResponse struct {
|
||||
ID uint `json:"id" example:"1"`
|
||||
ParentPlanID uint `json:"parent_plan_id" example:"1"`
|
||||
ChildPlanID uint `json:"child_plan_id" example:"2"`
|
||||
ID uint32 `json:"id" example:"1"`
|
||||
ParentPlanID uint32 `json:"parent_plan_id" example:"1"`
|
||||
ChildPlanID uint32 `json:"child_plan_id" example:"2"`
|
||||
ExecutionOrder int `json:"execution_order" example:"1"`
|
||||
ChildPlan *PlanResponse `json:"child_plan,omitempty"`
|
||||
}
|
||||
@@ -77,7 +77,7 @@ type TaskRequest struct {
|
||||
// TaskResponse 定义任务响应结构体
|
||||
type TaskResponse struct {
|
||||
ID int `json:"id" example:"1"`
|
||||
PlanID uint `json:"plan_id" example:"1"`
|
||||
PlanID uint32 `json:"plan_id" example:"1"`
|
||||
Name string `json:"name" example:"打开风扇"`
|
||||
Description string `json:"description" example:"打开1号风扇"`
|
||||
ExecutionOrder int `json:"execution_order" example:"1"`
|
||||
|
||||
@@ -16,19 +16,19 @@ type LoginRequest struct {
|
||||
// CreateUserResponse 定义创建用户成功响应的结构体
|
||||
type CreateUserResponse struct {
|
||||
Username string `json:"username" example:"newuser"`
|
||||
ID uint `json:"id" example:"1"`
|
||||
ID uint32 `json:"id" example:"1"`
|
||||
}
|
||||
|
||||
// LoginResponse 定义登录成功响应的结构体
|
||||
type LoginResponse struct {
|
||||
Username string `json:"username" example:"testuser"`
|
||||
ID uint `json:"id" example:"1"`
|
||||
ID uint32 `json:"id" example:"1"`
|
||||
Token string `json:"token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."`
|
||||
}
|
||||
|
||||
// HistoryResponse 定义单条操作历史的响应结构体
|
||||
type HistoryResponse struct {
|
||||
UserID uint `json:"user_id" example:"101"`
|
||||
UserID uint32 `json:"user_id" example:"101"`
|
||||
Username string `json:"username" example:"testuser"`
|
||||
ActionType string `json:"action_type" example:"更新设备"`
|
||||
Description string `json:"description" example:"设备更新成功"`
|
||||
|
||||
@@ -28,23 +28,23 @@ var (
|
||||
// DeviceService 定义了应用层的设备服务接口,用于协调设备相关的业务逻辑。
|
||||
type DeviceService interface {
|
||||
CreateDevice(ctx context.Context, req *dto.CreateDeviceRequest) (*dto.DeviceResponse, error)
|
||||
GetDevice(ctx context.Context, id uint) (*dto.DeviceResponse, error)
|
||||
GetDevice(ctx context.Context, id uint32) (*dto.DeviceResponse, error)
|
||||
ListDevices(ctx context.Context) ([]*dto.DeviceResponse, error)
|
||||
UpdateDevice(ctx context.Context, id uint, req *dto.UpdateDeviceRequest) (*dto.DeviceResponse, error)
|
||||
DeleteDevice(ctx context.Context, id uint) error
|
||||
ManualControl(ctx context.Context, id uint, req *dto.ManualControlDeviceRequest) error
|
||||
UpdateDevice(ctx context.Context, id uint32, req *dto.UpdateDeviceRequest) (*dto.DeviceResponse, error)
|
||||
DeleteDevice(ctx context.Context, id uint32) error
|
||||
ManualControl(ctx context.Context, id uint32, req *dto.ManualControlDeviceRequest) error
|
||||
|
||||
CreateAreaController(ctx context.Context, req *dto.CreateAreaControllerRequest) (*dto.AreaControllerResponse, error)
|
||||
GetAreaController(ctx context.Context, id uint) (*dto.AreaControllerResponse, error)
|
||||
GetAreaController(ctx context.Context, id uint32) (*dto.AreaControllerResponse, error)
|
||||
ListAreaControllers(ctx context.Context) ([]*dto.AreaControllerResponse, error)
|
||||
UpdateAreaController(ctx context.Context, id uint, req *dto.UpdateAreaControllerRequest) (*dto.AreaControllerResponse, error)
|
||||
DeleteAreaController(ctx context.Context, id uint) error
|
||||
UpdateAreaController(ctx context.Context, id uint32, req *dto.UpdateAreaControllerRequest) (*dto.AreaControllerResponse, error)
|
||||
DeleteAreaController(ctx context.Context, id uint32) error
|
||||
|
||||
CreateDeviceTemplate(ctx context.Context, req *dto.CreateDeviceTemplateRequest) (*dto.DeviceTemplateResponse, error)
|
||||
GetDeviceTemplate(ctx context.Context, id uint) (*dto.DeviceTemplateResponse, error)
|
||||
GetDeviceTemplate(ctx context.Context, id uint32) (*dto.DeviceTemplateResponse, error)
|
||||
ListDeviceTemplates(ctx context.Context) ([]*dto.DeviceTemplateResponse, error)
|
||||
UpdateDeviceTemplate(ctx context.Context, id uint, req *dto.UpdateDeviceTemplateRequest) (*dto.DeviceTemplateResponse, error)
|
||||
DeleteDeviceTemplate(ctx context.Context, id uint) error
|
||||
UpdateDeviceTemplate(ctx context.Context, id uint32, req *dto.UpdateDeviceTemplateRequest) (*dto.DeviceTemplateResponse, error)
|
||||
DeleteDeviceTemplate(ctx context.Context, id uint32) error
|
||||
}
|
||||
|
||||
// deviceService 是 DeviceService 接口的具体实现。
|
||||
@@ -109,7 +109,7 @@ func (s *deviceService) CreateDevice(ctx context.Context, req *dto.CreateDeviceR
|
||||
return dto.NewDeviceResponse(createdDevice)
|
||||
}
|
||||
|
||||
func (s *deviceService) GetDevice(ctx context.Context, id uint) (*dto.DeviceResponse, error) {
|
||||
func (s *deviceService) GetDevice(ctx context.Context, id uint32) (*dto.DeviceResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "GetDevice")
|
||||
device, err := s.deviceRepo.FindByID(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -127,7 +127,7 @@ func (s *deviceService) ListDevices(ctx context.Context) ([]*dto.DeviceResponse,
|
||||
return dto.NewListDeviceResponse(devices)
|
||||
}
|
||||
|
||||
func (s *deviceService) UpdateDevice(ctx context.Context, id uint, req *dto.UpdateDeviceRequest) (*dto.DeviceResponse, error) {
|
||||
func (s *deviceService) UpdateDevice(ctx context.Context, id uint32, req *dto.UpdateDeviceRequest) (*dto.DeviceResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "UpdateDevice")
|
||||
existingDevice, err := s.deviceRepo.FindByID(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -161,7 +161,7 @@ func (s *deviceService) UpdateDevice(ctx context.Context, id uint, req *dto.Upda
|
||||
return dto.NewDeviceResponse(updatedDevice)
|
||||
}
|
||||
|
||||
func (s *deviceService) DeleteDevice(ctx context.Context, id uint) error {
|
||||
func (s *deviceService) DeleteDevice(ctx context.Context, id uint32) error {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "DeleteDevice")
|
||||
|
||||
// 检查设备是否存在
|
||||
@@ -191,7 +191,7 @@ func (s *deviceService) DeleteDevice(ctx context.Context, id uint) error {
|
||||
return s.deviceRepo.Delete(serviceCtx, id)
|
||||
}
|
||||
|
||||
func (s *deviceService) ManualControl(ctx context.Context, id uint, req *dto.ManualControlDeviceRequest) error {
|
||||
func (s *deviceService) ManualControl(ctx context.Context, id uint32, req *dto.ManualControlDeviceRequest) error {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ManualControl")
|
||||
dev, err := s.deviceRepo.FindByID(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -241,7 +241,7 @@ func (s *deviceService) CreateAreaController(ctx context.Context, req *dto.Creat
|
||||
return dto.NewAreaControllerResponse(ac)
|
||||
}
|
||||
|
||||
func (s *deviceService) GetAreaController(ctx context.Context, id uint) (*dto.AreaControllerResponse, error) {
|
||||
func (s *deviceService) GetAreaController(ctx context.Context, id uint32) (*dto.AreaControllerResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "GetAreaController")
|
||||
ac, err := s.areaControllerRepo.FindByID(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -259,7 +259,7 @@ func (s *deviceService) ListAreaControllers(ctx context.Context) ([]*dto.AreaCon
|
||||
return dto.NewListAreaControllerResponse(acs)
|
||||
}
|
||||
|
||||
func (s *deviceService) UpdateAreaController(ctx context.Context, id uint, req *dto.UpdateAreaControllerRequest) (*dto.AreaControllerResponse, error) {
|
||||
func (s *deviceService) UpdateAreaController(ctx context.Context, id uint32, req *dto.UpdateAreaControllerRequest) (*dto.AreaControllerResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "UpdateAreaController")
|
||||
existingAC, err := s.areaControllerRepo.FindByID(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -287,7 +287,7 @@ func (s *deviceService) UpdateAreaController(ctx context.Context, id uint, req *
|
||||
return dto.NewAreaControllerResponse(existingAC)
|
||||
}
|
||||
|
||||
func (s *deviceService) DeleteAreaController(ctx context.Context, id uint) error {
|
||||
func (s *deviceService) DeleteAreaController(ctx context.Context, id uint32) error {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "DeleteAreaController")
|
||||
|
||||
// 1. 检查是否存在
|
||||
@@ -349,7 +349,7 @@ func (s *deviceService) CreateDeviceTemplate(ctx context.Context, req *dto.Creat
|
||||
return dto.NewDeviceTemplateResponse(deviceTemplate)
|
||||
}
|
||||
|
||||
func (s *deviceService) GetDeviceTemplate(ctx context.Context, id uint) (*dto.DeviceTemplateResponse, error) {
|
||||
func (s *deviceService) GetDeviceTemplate(ctx context.Context, id uint32) (*dto.DeviceTemplateResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "GetDeviceTemplate")
|
||||
deviceTemplate, err := s.deviceTemplateRepo.FindByID(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -367,7 +367,7 @@ func (s *deviceService) ListDeviceTemplates(ctx context.Context) ([]*dto.DeviceT
|
||||
return dto.NewListDeviceTemplateResponse(deviceTemplates)
|
||||
}
|
||||
|
||||
func (s *deviceService) UpdateDeviceTemplate(ctx context.Context, id uint, req *dto.UpdateDeviceTemplateRequest) (*dto.DeviceTemplateResponse, error) {
|
||||
func (s *deviceService) UpdateDeviceTemplate(ctx context.Context, id uint32, req *dto.UpdateDeviceTemplateRequest) (*dto.DeviceTemplateResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "UpdateDeviceTemplate")
|
||||
existingDeviceTemplate, err := s.deviceTemplateRepo.FindByID(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -402,7 +402,7 @@ func (s *deviceService) UpdateDeviceTemplate(ctx context.Context, id uint, req *
|
||||
return dto.NewDeviceTemplateResponse(existingDeviceTemplate)
|
||||
}
|
||||
|
||||
func (s *deviceService) DeleteDeviceTemplate(ctx context.Context, id uint) error {
|
||||
func (s *deviceService) DeleteDeviceTemplate(ctx context.Context, id uint32) error {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "DeleteDeviceTemplate")
|
||||
|
||||
// 1. 检查是否存在
|
||||
|
||||
@@ -147,7 +147,7 @@ func (s *monitorService) ListPlanExecutionLogs(ctx context.Context, req *dto.Lis
|
||||
return nil, err
|
||||
}
|
||||
|
||||
planIds := make([]uint, 0, len(planLogs))
|
||||
planIds := make([]uint32, 0, len(planLogs))
|
||||
for _, datum := range planLogs {
|
||||
has := false
|
||||
for _, id := range planIds {
|
||||
|
||||
@@ -12,35 +12,35 @@ import (
|
||||
|
||||
// PigBatchService 接口定义保持不变,继续作为应用层对外的契约。
|
||||
type PigBatchService interface {
|
||||
CreatePigBatch(ctx context.Context, operatorID uint, dto *dto.PigBatchCreateDTO) (*dto.PigBatchResponseDTO, error)
|
||||
GetPigBatch(ctx context.Context, id uint) (*dto.PigBatchResponseDTO, error)
|
||||
UpdatePigBatch(ctx context.Context, id uint, dto *dto.PigBatchUpdateDTO) (*dto.PigBatchResponseDTO, error)
|
||||
DeletePigBatch(ctx context.Context, id uint) error
|
||||
CreatePigBatch(ctx context.Context, operatorID uint32, dto *dto.PigBatchCreateDTO) (*dto.PigBatchResponseDTO, error)
|
||||
GetPigBatch(ctx context.Context, id uint32) (*dto.PigBatchResponseDTO, error)
|
||||
UpdatePigBatch(ctx context.Context, id uint32, dto *dto.PigBatchUpdateDTO) (*dto.PigBatchResponseDTO, error)
|
||||
DeletePigBatch(ctx context.Context, id uint32) error
|
||||
ListPigBatches(ctx context.Context, isActive *bool) ([]*dto.PigBatchResponseDTO, error)
|
||||
|
||||
// Pig Pen Management
|
||||
AssignEmptyPensToBatch(ctx context.Context, batchID uint, penIDs []uint, operatorID uint) error
|
||||
ReclassifyPenToNewBatch(ctx context.Context, fromBatchID uint, toBatchID uint, penID uint, operatorID uint, remarks string) error
|
||||
RemoveEmptyPenFromBatch(ctx context.Context, batchID uint, penID uint) error
|
||||
MovePigsIntoPen(ctx context.Context, batchID uint, toPenID uint, quantity int, operatorID uint, remarks string) error
|
||||
AssignEmptyPensToBatch(ctx context.Context, batchID uint32, penIDs []uint32, operatorID uint32) error
|
||||
ReclassifyPenToNewBatch(ctx context.Context, fromBatchID uint32, toBatchID uint32, penID uint32, operatorID uint32, remarks string) error
|
||||
RemoveEmptyPenFromBatch(ctx context.Context, batchID uint32, penID uint32) error
|
||||
MovePigsIntoPen(ctx context.Context, batchID uint32, toPenID uint32, quantity int, operatorID uint32, remarks string) error
|
||||
|
||||
// Trade Sub-service
|
||||
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
|
||||
SellPigs(ctx context.Context, batchID uint32, penID uint32, quantity int, unitPrice float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint32) error
|
||||
BuyPigs(ctx context.Context, batchID uint32, penID uint32, quantity int, unitPrice float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint32) error
|
||||
|
||||
// Transfer Sub-service
|
||||
TransferPigsAcrossBatches(ctx context.Context, sourceBatchID uint, destBatchID uint, fromPenID uint, toPenID uint, quantity uint, operatorID uint, remarks string) error
|
||||
TransferPigsWithinBatch(ctx context.Context, batchID uint, fromPenID uint, toPenID uint, quantity uint, operatorID uint, remarks string) error
|
||||
TransferPigsAcrossBatches(ctx context.Context, sourceBatchID uint32, destBatchID uint32, fromPenID uint32, toPenID uint32, quantity uint32, operatorID uint32, remarks string) error
|
||||
TransferPigsWithinBatch(ctx context.Context, batchID uint32, fromPenID uint32, toPenID uint32, quantity uint32, operatorID uint32, remarks string) error
|
||||
|
||||
// Sick Pig Management
|
||||
RecordSickPigs(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigRecovery(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigDeath(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigCull(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigs(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigRecovery(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigDeath(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigCull(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
|
||||
// Normal Pig Management
|
||||
RecordDeath(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, happenedAt time.Time, remarks string) error
|
||||
RecordCull(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, happenedAt time.Time, remarks string) error
|
||||
RecordDeath(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, happenedAt time.Time, remarks string) error
|
||||
RecordCull(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, happenedAt time.Time, remarks string) error
|
||||
}
|
||||
|
||||
// pigBatchService 的实现现在依赖于领域服务接口。
|
||||
@@ -79,7 +79,7 @@ func (s *pigBatchService) toPigBatchResponseDTO(batch *models.PigBatch, currentT
|
||||
}
|
||||
|
||||
// CreatePigBatch 现在将请求委托给领域服务处理。
|
||||
func (s *pigBatchService) CreatePigBatch(ctx context.Context, operatorID uint, dto *dto.PigBatchCreateDTO) (*dto.PigBatchResponseDTO, error) {
|
||||
func (s *pigBatchService) CreatePigBatch(ctx context.Context, operatorID uint32, dto *dto.PigBatchCreateDTO) (*dto.PigBatchResponseDTO, error) {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "CreatePigBatch")
|
||||
// 1. DTO -> 领域模型
|
||||
batch := &models.PigBatch{
|
||||
@@ -102,7 +102,7 @@ func (s *pigBatchService) CreatePigBatch(ctx context.Context, operatorID uint, d
|
||||
}
|
||||
|
||||
// GetPigBatch 从领域服务获取数据并转换为DTO,同时处理错误转换。
|
||||
func (s *pigBatchService) GetPigBatch(ctx context.Context, id uint) (*dto.PigBatchResponseDTO, error) {
|
||||
func (s *pigBatchService) GetPigBatch(ctx context.Context, id uint32) (*dto.PigBatchResponseDTO, error) {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "GetPigBatch")
|
||||
batch, err := s.domainService.GetPigBatch(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -123,7 +123,7 @@ func (s *pigBatchService) GetPigBatch(ctx context.Context, id uint) (*dto.PigBat
|
||||
}
|
||||
|
||||
// UpdatePigBatch 协调获取、更新和保存的流程,并处理错误转换。
|
||||
func (s *pigBatchService) UpdatePigBatch(ctx context.Context, id uint, dto *dto.PigBatchUpdateDTO) (*dto.PigBatchResponseDTO, error) {
|
||||
func (s *pigBatchService) UpdatePigBatch(ctx context.Context, id uint32, dto *dto.PigBatchUpdateDTO) (*dto.PigBatchResponseDTO, error) {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "UpdatePigBatch")
|
||||
// 1. 先获取最新的领域模型
|
||||
existingBatch, err := s.domainService.GetPigBatch(serviceCtx, id)
|
||||
@@ -176,7 +176,7 @@ func (s *pigBatchService) UpdatePigBatch(ctx context.Context, id uint, dto *dto.
|
||||
}
|
||||
|
||||
// DeletePigBatch 将删除操作委托给领域服务,并转换领域错误为应用层错误。
|
||||
func (s *pigBatchService) DeletePigBatch(ctx context.Context, id uint) error {
|
||||
func (s *pigBatchService) DeletePigBatch(ctx context.Context, id uint32) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "DeletePigBatch")
|
||||
err := s.domainService.DeletePigBatch(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -214,7 +214,7 @@ func (s *pigBatchService) ListPigBatches(ctx context.Context, isActive *bool) ([
|
||||
}
|
||||
|
||||
// AssignEmptyPensToBatch 委托给领域服务
|
||||
func (s *pigBatchService) AssignEmptyPensToBatch(ctx context.Context, batchID uint, penIDs []uint, operatorID uint) error {
|
||||
func (s *pigBatchService) AssignEmptyPensToBatch(ctx context.Context, batchID uint32, penIDs []uint32, operatorID uint32) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "AssignEmptyPensToBatch")
|
||||
err := s.domainService.AssignEmptyPensToBatch(serviceCtx, batchID, penIDs, operatorID)
|
||||
if err != nil {
|
||||
@@ -225,7 +225,7 @@ func (s *pigBatchService) AssignEmptyPensToBatch(ctx context.Context, batchID ui
|
||||
}
|
||||
|
||||
// ReclassifyPenToNewBatch 委托给领域服务
|
||||
func (s *pigBatchService) ReclassifyPenToNewBatch(ctx context.Context, fromBatchID uint, toBatchID uint, penID uint, operatorID uint, remarks string) error {
|
||||
func (s *pigBatchService) ReclassifyPenToNewBatch(ctx context.Context, fromBatchID uint32, toBatchID uint32, penID uint32, operatorID uint32, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "ReclassifyPenToNewBatch")
|
||||
err := s.domainService.ReclassifyPenToNewBatch(serviceCtx, fromBatchID, toBatchID, penID, operatorID, remarks)
|
||||
if err != nil {
|
||||
@@ -236,7 +236,7 @@ func (s *pigBatchService) ReclassifyPenToNewBatch(ctx context.Context, fromBatch
|
||||
}
|
||||
|
||||
// RemoveEmptyPenFromBatch 委托给领域服务
|
||||
func (s *pigBatchService) RemoveEmptyPenFromBatch(ctx context.Context, batchID uint, penID uint) error {
|
||||
func (s *pigBatchService) RemoveEmptyPenFromBatch(ctx context.Context, batchID uint32, penID uint32) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "RemoveEmptyPenFromBatch")
|
||||
err := s.domainService.RemoveEmptyPenFromBatch(serviceCtx, batchID, penID)
|
||||
if err != nil {
|
||||
@@ -247,7 +247,7 @@ func (s *pigBatchService) RemoveEmptyPenFromBatch(ctx context.Context, batchID u
|
||||
}
|
||||
|
||||
// MovePigsIntoPen 委托给领域服务
|
||||
func (s *pigBatchService) MovePigsIntoPen(ctx context.Context, batchID uint, toPenID uint, quantity int, operatorID uint, remarks string) error {
|
||||
func (s *pigBatchService) MovePigsIntoPen(ctx context.Context, batchID uint32, toPenID uint32, quantity int, operatorID uint32, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "MovePigsIntoPen")
|
||||
err := s.domainService.MovePigsIntoPen(serviceCtx, batchID, toPenID, quantity, operatorID, remarks)
|
||||
if err != nil {
|
||||
@@ -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 float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint) error {
|
||||
func (s *pigBatchService) SellPigs(ctx context.Context, batchID uint32, penID uint32, quantity int, unitPrice float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint32) 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 float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint) error {
|
||||
func (s *pigBatchService) BuyPigs(ctx context.Context, batchID uint32, penID uint32, quantity int, unitPrice float32, tatalPrice float32, traderName string, tradeDate time.Time, remarks string, operatorID uint32) 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 {
|
||||
@@ -280,7 +280,7 @@ func (s *pigBatchService) BuyPigs(ctx context.Context, batchID uint, penID uint,
|
||||
}
|
||||
|
||||
// TransferPigsAcrossBatches 委托给领域服务
|
||||
func (s *pigBatchService) TransferPigsAcrossBatches(ctx context.Context, sourceBatchID uint, destBatchID uint, fromPenID uint, toPenID uint, quantity uint, operatorID uint, remarks string) error {
|
||||
func (s *pigBatchService) TransferPigsAcrossBatches(ctx context.Context, sourceBatchID uint32, destBatchID uint32, fromPenID uint32, toPenID uint32, quantity uint32, operatorID uint32, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "TransferPigsAcrossBatches")
|
||||
err := s.domainService.TransferPigsAcrossBatches(serviceCtx, sourceBatchID, destBatchID, fromPenID, toPenID, quantity, operatorID, remarks)
|
||||
if err != nil {
|
||||
@@ -291,7 +291,7 @@ func (s *pigBatchService) TransferPigsAcrossBatches(ctx context.Context, sourceB
|
||||
}
|
||||
|
||||
// TransferPigsWithinBatch 委托给领域服务
|
||||
func (s *pigBatchService) TransferPigsWithinBatch(ctx context.Context, batchID uint, fromPenID uint, toPenID uint, quantity uint, operatorID uint, remarks string) error {
|
||||
func (s *pigBatchService) TransferPigsWithinBatch(ctx context.Context, batchID uint32, fromPenID uint32, toPenID uint32, quantity uint32, operatorID uint32, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "TransferPigsWithinBatch")
|
||||
err := s.domainService.TransferPigsWithinBatch(serviceCtx, batchID, fromPenID, toPenID, quantity, operatorID, remarks)
|
||||
if err != nil {
|
||||
@@ -302,7 +302,7 @@ func (s *pigBatchService) TransferPigsWithinBatch(ctx context.Context, batchID u
|
||||
}
|
||||
|
||||
// RecordSickPigs 委托给领域服务
|
||||
func (s *pigBatchService) RecordSickPigs(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
func (s *pigBatchService) RecordSickPigs(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "RecordSickPigs")
|
||||
err := s.domainService.RecordSickPigs(serviceCtx, operatorID, batchID, penID, quantity, treatmentLocation, happenedAt, remarks)
|
||||
if err != nil {
|
||||
@@ -313,7 +313,7 @@ func (s *pigBatchService) RecordSickPigs(ctx context.Context, operatorID uint, b
|
||||
}
|
||||
|
||||
// RecordSickPigRecovery 委托给领域服务
|
||||
func (s *pigBatchService) RecordSickPigRecovery(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
func (s *pigBatchService) RecordSickPigRecovery(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "RecordSickPigRecovery")
|
||||
err := s.domainService.RecordSickPigRecovery(serviceCtx, operatorID, batchID, penID, quantity, treatmentLocation, happenedAt, remarks)
|
||||
if err != nil {
|
||||
@@ -324,7 +324,7 @@ func (s *pigBatchService) RecordSickPigRecovery(ctx context.Context, operatorID
|
||||
}
|
||||
|
||||
// RecordSickPigDeath 委托给领域服务
|
||||
func (s *pigBatchService) RecordSickPigDeath(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
func (s *pigBatchService) RecordSickPigDeath(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "RecordSickPigDeath")
|
||||
err := s.domainService.RecordSickPigDeath(serviceCtx, operatorID, batchID, penID, quantity, treatmentLocation, happenedAt, remarks)
|
||||
if err != nil {
|
||||
@@ -335,7 +335,7 @@ func (s *pigBatchService) RecordSickPigDeath(ctx context.Context, operatorID uin
|
||||
}
|
||||
|
||||
// RecordSickPigCull 委托给领域服务
|
||||
func (s *pigBatchService) RecordSickPigCull(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
func (s *pigBatchService) RecordSickPigCull(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "RecordSickPigCull")
|
||||
err := s.domainService.RecordSickPigCull(serviceCtx, operatorID, batchID, penID, quantity, treatmentLocation, happenedAt, remarks)
|
||||
if err != nil {
|
||||
@@ -346,7 +346,7 @@ func (s *pigBatchService) RecordSickPigCull(ctx context.Context, operatorID uint
|
||||
}
|
||||
|
||||
// RecordDeath 委托给领域服务
|
||||
func (s *pigBatchService) RecordDeath(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, happenedAt time.Time, remarks string) error {
|
||||
func (s *pigBatchService) RecordDeath(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, happenedAt time.Time, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "RecordDeath")
|
||||
err := s.domainService.RecordDeath(serviceCtx, operatorID, batchID, penID, quantity, happenedAt, remarks)
|
||||
if err != nil {
|
||||
@@ -357,7 +357,7 @@ func (s *pigBatchService) RecordDeath(ctx context.Context, operatorID uint, batc
|
||||
}
|
||||
|
||||
// RecordCull 委托给领域服务
|
||||
func (s *pigBatchService) RecordCull(ctx context.Context, operatorID uint, batchID uint, penID uint, quantity int, happenedAt time.Time, remarks string) error {
|
||||
func (s *pigBatchService) RecordCull(ctx context.Context, operatorID uint32, batchID uint32, penID uint32, quantity int, happenedAt time.Time, remarks string) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "RecordCull")
|
||||
err := s.domainService.RecordCull(serviceCtx, operatorID, batchID, penID, quantity, happenedAt, remarks)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,19 +18,19 @@ import (
|
||||
type PigFarmService interface {
|
||||
// PigHouse methods
|
||||
CreatePigHouse(ctx context.Context, name, description string) (*dto.PigHouseResponse, error)
|
||||
GetPigHouseByID(ctx context.Context, id uint) (*dto.PigHouseResponse, error)
|
||||
GetPigHouseByID(ctx context.Context, id uint32) (*dto.PigHouseResponse, error)
|
||||
ListPigHouses(ctx context.Context) ([]dto.PigHouseResponse, error)
|
||||
UpdatePigHouse(ctx context.Context, id uint, name, description string) (*dto.PigHouseResponse, error)
|
||||
DeletePigHouse(ctx context.Context, id uint) error
|
||||
UpdatePigHouse(ctx context.Context, id uint32, name, description string) (*dto.PigHouseResponse, error)
|
||||
DeletePigHouse(ctx context.Context, id uint32) error
|
||||
|
||||
// Pen methods
|
||||
CreatePen(ctx context.Context, penNumber string, houseID uint, capacity int) (*dto.PenResponse, error)
|
||||
GetPenByID(ctx context.Context, id uint) (*dto.PenResponse, error)
|
||||
CreatePen(ctx context.Context, penNumber string, houseID uint32, capacity int) (*dto.PenResponse, error)
|
||||
GetPenByID(ctx context.Context, id uint32) (*dto.PenResponse, error)
|
||||
ListPens(ctx context.Context) ([]*dto.PenResponse, error)
|
||||
UpdatePen(ctx context.Context, id uint, penNumber string, houseID uint, capacity int, status models.PenStatus) (*dto.PenResponse, error)
|
||||
DeletePen(ctx context.Context, id uint) error
|
||||
UpdatePen(ctx context.Context, id uint32, penNumber string, houseID uint32, capacity int, status models.PenStatus) (*dto.PenResponse, error)
|
||||
DeletePen(ctx context.Context, id uint32) error
|
||||
// UpdatePenStatus 更新猪栏状态
|
||||
UpdatePenStatus(ctx context.Context, id uint, newStatus models.PenStatus) (*dto.PenResponse, error)
|
||||
UpdatePenStatus(ctx context.Context, id uint32, newStatus models.PenStatus) (*dto.PenResponse, error)
|
||||
}
|
||||
|
||||
type pigFarmService struct {
|
||||
@@ -79,7 +79,7 @@ func (s *pigFarmService) CreatePigHouse(ctx context.Context, name, description s
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *pigFarmService) GetPigHouseByID(ctx context.Context, id uint) (*dto.PigHouseResponse, error) {
|
||||
func (s *pigFarmService) GetPigHouseByID(ctx context.Context, id uint32) (*dto.PigHouseResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "GetPigHouseByID")
|
||||
house, err := s.farmRepository.GetPigHouseByID(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -109,10 +109,10 @@ func (s *pigFarmService) ListPigHouses(ctx context.Context) ([]dto.PigHouseRespo
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *pigFarmService) UpdatePigHouse(ctx context.Context, id uint, name, description string) (*dto.PigHouseResponse, error) {
|
||||
func (s *pigFarmService) UpdatePigHouse(ctx context.Context, id uint32, name, description string) (*dto.PigHouseResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "UpdatePigHouse")
|
||||
house := &models.PigHouse{
|
||||
Model: gorm.Model{ID: id},
|
||||
Model: models.Model{ID: id},
|
||||
Name: name,
|
||||
Description: description,
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func (s *pigFarmService) UpdatePigHouse(ctx context.Context, id uint, name, desc
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *pigFarmService) DeletePigHouse(ctx context.Context, id uint) error {
|
||||
func (s *pigFarmService) DeletePigHouse(ctx context.Context, id uint32) error {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "DeletePigHouse")
|
||||
// 业务逻辑:检查猪舍是否包含猪栏
|
||||
penCount, err := s.farmRepository.CountPensInHouse(serviceCtx, id)
|
||||
@@ -159,7 +159,7 @@ func (s *pigFarmService) DeletePigHouse(ctx context.Context, id uint) error {
|
||||
|
||||
// --- Pen Implementation ---
|
||||
|
||||
func (s *pigFarmService) CreatePen(ctx context.Context, penNumber string, houseID uint, capacity int) (*dto.PenResponse, error) {
|
||||
func (s *pigFarmService) CreatePen(ctx context.Context, penNumber string, houseID uint32, capacity int) (*dto.PenResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "CreatePen")
|
||||
// 业务逻辑:验证所属猪舍是否存在
|
||||
_, err := s.farmRepository.GetPigHouseByID(serviceCtx, houseID)
|
||||
@@ -189,7 +189,7 @@ func (s *pigFarmService) CreatePen(ctx context.Context, penNumber string, houseI
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *pigFarmService) GetPenByID(ctx context.Context, id uint) (*dto.PenResponse, error) {
|
||||
func (s *pigFarmService) GetPenByID(ctx context.Context, id uint32) (*dto.PenResponse, error) {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "GetPenByID")
|
||||
pen, err := s.penRepository.GetPenByID(serviceCtx, id)
|
||||
if err != nil {
|
||||
@@ -251,7 +251,7 @@ func (s *pigFarmService) ListPens(ctx context.Context) ([]*dto.PenResponse, erro
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *pigFarmService) UpdatePen(ctx context.Context, id uint, penNumber string, houseID uint, capacity int, status models.PenStatus) (*dto.PenResponse, error) {
|
||||
func (s *pigFarmService) UpdatePen(ctx context.Context, id uint32, penNumber string, houseID uint32, capacity int, status models.PenStatus) (*dto.PenResponse, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "UpdatePen")
|
||||
// 业务逻辑:验证所属猪舍是否存在
|
||||
_, err := s.farmRepository.GetPigHouseByID(serviceCtx, houseID)
|
||||
@@ -263,7 +263,7 @@ func (s *pigFarmService) UpdatePen(ctx context.Context, id uint, penNumber strin
|
||||
}
|
||||
|
||||
pen := &models.Pen{
|
||||
Model: gorm.Model{ID: id},
|
||||
Model: models.Model{ID: id},
|
||||
PenNumber: penNumber,
|
||||
HouseID: houseID,
|
||||
Capacity: capacity,
|
||||
@@ -291,7 +291,7 @@ func (s *pigFarmService) UpdatePen(ctx context.Context, id uint, penNumber strin
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *pigFarmService) DeletePen(ctx context.Context, id uint) error {
|
||||
func (s *pigFarmService) DeletePen(ctx context.Context, id uint32) error {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "DeletePen")
|
||||
// 业务逻辑:检查猪栏是否被活跃批次使用
|
||||
pen, err := s.penRepository.GetPenByID(serviceCtx, id)
|
||||
@@ -327,7 +327,7 @@ func (s *pigFarmService) DeletePen(ctx context.Context, id uint) error {
|
||||
}
|
||||
|
||||
// UpdatePenStatus 更新猪栏状态
|
||||
func (s *pigFarmService) UpdatePenStatus(ctx context.Context, id uint, newStatus models.PenStatus) (*dto.PenResponse, error) {
|
||||
func (s *pigFarmService) UpdatePenStatus(ctx context.Context, id uint32, newStatus models.PenStatus) (*dto.PenResponse, error) {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "UpdatePenStatus")
|
||||
var updatedPen *models.Pen
|
||||
err := s.uow.ExecuteInTransaction(serviceCtx, func(tx *gorm.DB) error {
|
||||
|
||||
@@ -16,17 +16,17 @@ type PlanService interface {
|
||||
// CreatePlan 创建一个新的计划
|
||||
CreatePlan(ctx context.Context, req *dto.CreatePlanRequest) (*dto.PlanResponse, error)
|
||||
// GetPlanByID 根据ID获取计划详情
|
||||
GetPlanByID(ctx context.Context, id uint) (*dto.PlanResponse, error)
|
||||
GetPlanByID(ctx context.Context, id uint32) (*dto.PlanResponse, error)
|
||||
// ListPlans 获取计划列表,支持过滤和分页
|
||||
ListPlans(ctx context.Context, query *dto.ListPlansQuery) (*dto.ListPlansResponse, error)
|
||||
// UpdatePlan 更新计划
|
||||
UpdatePlan(ctx context.Context, id uint, req *dto.UpdatePlanRequest) (*dto.PlanResponse, error)
|
||||
UpdatePlan(ctx context.Context, id uint32, req *dto.UpdatePlanRequest) (*dto.PlanResponse, error)
|
||||
// DeletePlan 删除计划(软删除)
|
||||
DeletePlan(ctx context.Context, id uint) error
|
||||
DeletePlan(ctx context.Context, id uint32) error
|
||||
// StartPlan 启动计划
|
||||
StartPlan(ctx context.Context, id uint) error
|
||||
StartPlan(ctx context.Context, id uint32) error
|
||||
// StopPlan 停止计划
|
||||
StopPlan(ctx context.Context, id uint) error
|
||||
StopPlan(ctx context.Context, id uint32) error
|
||||
}
|
||||
|
||||
// planService 是 PlanService 接口的实现
|
||||
@@ -77,7 +77,7 @@ func (s *planService) CreatePlan(ctx context.Context, req *dto.CreatePlanRequest
|
||||
}
|
||||
|
||||
// GetPlanByID 根据ID获取计划详情
|
||||
func (s *planService) GetPlanByID(ctx context.Context, id uint) (*dto.PlanResponse, error) {
|
||||
func (s *planService) GetPlanByID(ctx context.Context, id uint32) (*dto.PlanResponse, error) {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "GetPlanByID")
|
||||
const actionType = "应用服务层:获取计划详情"
|
||||
|
||||
@@ -135,7 +135,7 @@ func (s *planService) ListPlans(ctx context.Context, query *dto.ListPlansQuery)
|
||||
}
|
||||
|
||||
// UpdatePlan 更新计划
|
||||
func (s *planService) UpdatePlan(ctx context.Context, id uint, req *dto.UpdatePlanRequest) (*dto.PlanResponse, error) {
|
||||
func (s *planService) UpdatePlan(ctx context.Context, id uint32, req *dto.UpdatePlanRequest) (*dto.PlanResponse, error) {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "UpdatePlan")
|
||||
const actionType = "应用服务层:更新计划"
|
||||
|
||||
@@ -166,7 +166,7 @@ func (s *planService) UpdatePlan(ctx context.Context, id uint, req *dto.UpdatePl
|
||||
}
|
||||
|
||||
// DeletePlan 删除计划(软删除)
|
||||
func (s *planService) DeletePlan(ctx context.Context, id uint) error {
|
||||
func (s *planService) DeletePlan(ctx context.Context, id uint32) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "DeletePlan")
|
||||
const actionType = "应用服务层:删除计划"
|
||||
|
||||
@@ -182,7 +182,7 @@ func (s *planService) DeletePlan(ctx context.Context, id uint) error {
|
||||
}
|
||||
|
||||
// StartPlan 启动计划
|
||||
func (s *planService) StartPlan(ctx context.Context, id uint) error {
|
||||
func (s *planService) StartPlan(ctx context.Context, id uint32) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "StartPlan")
|
||||
const actionType = "应用服务层:启动计划"
|
||||
|
||||
@@ -198,7 +198,7 @@ func (s *planService) StartPlan(ctx context.Context, id uint) error {
|
||||
}
|
||||
|
||||
// StopPlan 停止计划
|
||||
func (s *planService) StopPlan(ctx context.Context, id uint) error {
|
||||
func (s *planService) StopPlan(ctx context.Context, id uint32) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "StopPlan")
|
||||
const actionType = "应用服务层:停止计划"
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ import (
|
||||
// 该服务负责管理阈值告警任务的配置,并将其与计划进行联动。
|
||||
type ThresholdAlarmService interface {
|
||||
// SnoozeThresholdAlarm 忽略一个阈值告警,或更新其忽略时间。
|
||||
SnoozeThresholdAlarm(ctx context.Context, alarmID uint, durationMinutes uint) error
|
||||
SnoozeThresholdAlarm(ctx context.Context, alarmID uint32, durationMinutes uint32) error
|
||||
// CancelSnoozeThresholdAlarm 取消对一个阈值告警的忽略状态。
|
||||
CancelSnoozeThresholdAlarm(ctx context.Context, alarmID uint) error
|
||||
CancelSnoozeThresholdAlarm(ctx context.Context, alarmID uint32) error
|
||||
// ListActiveAlarms 批量查询活跃告警。
|
||||
ListActiveAlarms(ctx context.Context, req *dto.ListActiveAlarmRequest) (*dto.ListActiveAlarmResponse, error)
|
||||
// ListHistoricalAlarms 批量查询历史告警。
|
||||
@@ -35,7 +35,7 @@ type ThresholdAlarmService interface {
|
||||
// DeleteDeviceThresholdAlarm 删除一个设备阈值告警。
|
||||
DeleteDeviceThresholdAlarm(ctx context.Context, taskID int, req *dto.DeleteDeviceThresholdAlarmDTO) error
|
||||
// DeleteDeviceThresholdAlarmByDeviceID 实现了根据设备ID删除一个设备下所有设备阈值告警的逻辑。
|
||||
DeleteDeviceThresholdAlarmByDeviceID(ctx context.Context, deviceID uint) error
|
||||
DeleteDeviceThresholdAlarmByDeviceID(ctx context.Context, deviceID uint32) error
|
||||
|
||||
// CreateAreaThresholdAlarm 创建一个区域阈值告警。
|
||||
CreateAreaThresholdAlarm(ctx context.Context, req *dto.CreateAreaThresholdAlarmDTO) error
|
||||
@@ -46,7 +46,7 @@ type ThresholdAlarmService interface {
|
||||
// DeleteAreaThresholdAlarm 实现了删除一个区域阈值告警的逻辑。
|
||||
DeleteAreaThresholdAlarm(ctx context.Context, taskID int) error
|
||||
// DeleteAreaThresholdAlarmByAreaControllerID 实现了根据区域ID删除一个区域下所有区域阈值告警的逻辑。
|
||||
DeleteAreaThresholdAlarmByAreaControllerID(ctx context.Context, areaControllerID uint) error
|
||||
DeleteAreaThresholdAlarmByAreaControllerID(ctx context.Context, areaControllerID uint32) error
|
||||
}
|
||||
|
||||
// thresholdAlarmService 是 ThresholdAlarmService 接口的具体实现。
|
||||
@@ -82,13 +82,13 @@ func NewThresholdAlarmService(ctx context.Context,
|
||||
}
|
||||
|
||||
// SnoozeThresholdAlarm 实现了忽略阈值告警的逻辑。
|
||||
func (s *thresholdAlarmService) SnoozeThresholdAlarm(ctx context.Context, alarmID uint, durationMinutes uint) error {
|
||||
func (s *thresholdAlarmService) SnoozeThresholdAlarm(ctx context.Context, alarmID uint32, durationMinutes uint32) error {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "SnoozeThresholdAlarm")
|
||||
return s.alarmService.SnoozeAlarm(serviceCtx, alarmID, time.Duration(durationMinutes)*time.Minute)
|
||||
}
|
||||
|
||||
// CancelSnoozeThresholdAlarm 实现了取消忽略阈值告警的逻辑。
|
||||
func (s *thresholdAlarmService) CancelSnoozeThresholdAlarm(ctx context.Context, alarmID uint) error {
|
||||
func (s *thresholdAlarmService) CancelSnoozeThresholdAlarm(ctx context.Context, alarmID uint32) error {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "CancelSnoozeThresholdAlarm")
|
||||
return s.alarmService.CancelAlarmSnooze(serviceCtx, alarmID)
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func (s *thresholdAlarmService) CreateDeviceThresholdAlarm(ctx context.Context,
|
||||
}
|
||||
case models.TaskTypeAreaCollectorThresholdCheck: // 向区域阈值检查任务过滤列表中添加该设备
|
||||
params := task.AreaThresholdCheckParams{
|
||||
ExcludeDeviceIDs: []uint{},
|
||||
ExcludeDeviceIDs: []uint32{},
|
||||
}
|
||||
err = t.ParseParameters(¶ms)
|
||||
if err != nil {
|
||||
@@ -375,7 +375,7 @@ func (s *thresholdAlarmService) DeleteDeviceThresholdAlarm(ctx context.Context,
|
||||
}
|
||||
|
||||
// DeleteDeviceThresholdAlarmByDeviceID 实现了根据设备ID删除一个设备下所有设备阈值告警的逻辑。
|
||||
func (s *thresholdAlarmService) DeleteDeviceThresholdAlarmByDeviceID(ctx context.Context, deviceID uint) error {
|
||||
func (s *thresholdAlarmService) DeleteDeviceThresholdAlarmByDeviceID(ctx context.Context, deviceID uint32) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "DeleteDeviceThresholdAlarmByDeviceID")
|
||||
tasks, err := s.planRepo.ListTasksByDeviceID(serviceCtx, deviceID)
|
||||
if err != nil {
|
||||
@@ -462,13 +462,13 @@ func (s *thresholdAlarmService) CreateAreaThresholdAlarm(ctx context.Context, re
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取区域 %d 下的设备列表失败: %w", req.AreaControllerID, err)
|
||||
}
|
||||
devicesInAreaMap := make(map[uint]struct{}, len(devicesInArea))
|
||||
devicesInAreaMap := make(map[uint32]struct{}, len(devicesInArea))
|
||||
for _, device := range devicesInArea {
|
||||
devicesInAreaMap[device.ID] = struct{}{}
|
||||
}
|
||||
|
||||
// 3. 遍历计划,检查存在性并收集需要排除的设备ID
|
||||
var excludeDeviceIDs []uint
|
||||
var excludeDeviceIDs []uint32
|
||||
for _, t := range plan.Tasks {
|
||||
switch t.Type {
|
||||
case models.TaskTypeAreaCollectorThresholdCheck:
|
||||
@@ -631,7 +631,7 @@ func (s *thresholdAlarmService) DeleteAreaThresholdAlarm(ctx context.Context, ta
|
||||
}
|
||||
|
||||
// DeleteAreaThresholdAlarmByAreaControllerID 实现了根据区域ID删除一个区域下所有区域阈值告警的逻辑。
|
||||
func (s *thresholdAlarmService) DeleteAreaThresholdAlarmByAreaControllerID(ctx context.Context, areaControllerID uint) error {
|
||||
func (s *thresholdAlarmService) DeleteAreaThresholdAlarmByAreaControllerID(ctx context.Context, areaControllerID uint32) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "DeleteAreaThresholdAlarmByAreaControllerID")
|
||||
|
||||
// 1. 获取系统健康检查计划
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
type UserService interface {
|
||||
CreateUser(ctx context.Context, req *dto.CreateUserRequest) (*dto.CreateUserResponse, error)
|
||||
Login(ctx context.Context, req *dto.LoginRequest) (*dto.LoginResponse, error)
|
||||
SendTestNotification(ctx context.Context, userID uint, req *dto.SendTestNotificationRequest) error
|
||||
SendTestNotification(ctx context.Context, userID uint32, req *dto.SendTestNotificationRequest) error
|
||||
}
|
||||
|
||||
// userService 实现了 UserService 接口
|
||||
@@ -103,7 +103,7 @@ func (s *userService) Login(ctx context.Context, req *dto.LoginRequest) (*dto.Lo
|
||||
}
|
||||
|
||||
// SendTestNotification 发送测试通知
|
||||
func (s *userService) SendTestNotification(ctx context.Context, userID uint, req *dto.SendTestNotificationRequest) error {
|
||||
func (s *userService) SendTestNotification(ctx context.Context, userID uint32, req *dto.SendTestNotificationRequest) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "SendTestNotification")
|
||||
err := s.notifyService.SendTestMessage(serviceCtx, userID, req.Type)
|
||||
if err != nil {
|
||||
|
||||
@@ -429,7 +429,7 @@ func (c *ChirpStackListener) handleIntegrationEvent(ctx context.Context, event *
|
||||
// sensorDeviceID: 实际产生传感器数据的普通设备的ID
|
||||
// sensorType: 传感器值的类型 (例如 models.SensorTypeTemperature)
|
||||
// data: 具体的传感器数据结构体实例 (例如 models.TemperatureData)
|
||||
func (c *ChirpStackListener) recordSensorData(ctx context.Context, areaControllerID uint, sensorDeviceID uint, eventTime time.Time, sensorType models.SensorType, data interface{}) {
|
||||
func (c *ChirpStackListener) recordSensorData(ctx context.Context, areaControllerID uint32, sensorDeviceID uint32, eventTime time.Time, sensorType models.SensorType, data interface{}) {
|
||||
reqCtx, logger := logs.Trace(ctx, c.ctx, "recordSensorData")
|
||||
// 1. 将传入的结构体序列化为 JSON
|
||||
jsonData, err := json.Marshal(data)
|
||||
|
||||
Reference in New Issue
Block a user