2025-10-18 15:31:05 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
2025-11-05 19:57:30 +08:00
|
|
|
"context"
|
|
|
|
|
|
2025-10-31 15:10:09 +08:00
|
|
|
"git.huangwc.com/pig/pig-farm-controller/internal/app/dto"
|
2025-11-05 19:57:30 +08:00
|
|
|
"git.huangwc.com/pig/pig-farm-controller/internal/infra/logs"
|
2025-10-18 15:31:05 +08:00
|
|
|
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
|
|
|
|
"git.huangwc.com/pig/pig-farm-controller/internal/infra/repository"
|
|
|
|
|
)
|
|
|
|
|
|
2025-10-19 20:24:01 +08:00
|
|
|
// MonitorService 定义了监控相关的业务逻辑服务接口
|
|
|
|
|
type MonitorService interface {
|
2025-11-05 19:57:30 +08:00
|
|
|
ListSensorData(ctx context.Context, req *dto.ListSensorDataRequest) (*dto.ListSensorDataResponse, error)
|
|
|
|
|
ListDeviceCommandLogs(ctx context.Context, req *dto.ListDeviceCommandLogRequest) (*dto.ListDeviceCommandLogResponse, error)
|
|
|
|
|
ListPlanExecutionLogs(ctx context.Context, req *dto.ListPlanExecutionLogRequest) (*dto.ListPlanExecutionLogResponse, error)
|
|
|
|
|
ListTaskExecutionLogs(ctx context.Context, req *dto.ListTaskExecutionLogRequest) (*dto.ListTaskExecutionLogResponse, error)
|
|
|
|
|
ListPendingCollections(ctx context.Context, req *dto.ListPendingCollectionRequest) (*dto.ListPendingCollectionResponse, error)
|
|
|
|
|
ListUserActionLogs(ctx context.Context, req *dto.ListUserActionLogRequest) (*dto.ListUserActionLogResponse, error)
|
|
|
|
|
ListMedicationLogs(ctx context.Context, req *dto.ListMedicationLogRequest) (*dto.ListMedicationLogResponse, error)
|
|
|
|
|
ListPigBatchLogs(ctx context.Context, req *dto.ListPigBatchLogRequest) (*dto.ListPigBatchLogResponse, error)
|
|
|
|
|
ListWeighingBatches(ctx context.Context, req *dto.ListWeighingBatchRequest) (*dto.ListWeighingBatchResponse, error)
|
|
|
|
|
ListWeighingRecords(ctx context.Context, req *dto.ListWeighingRecordRequest) (*dto.ListWeighingRecordResponse, error)
|
|
|
|
|
ListPigTransferLogs(ctx context.Context, req *dto.ListPigTransferLogRequest) (*dto.ListPigTransferLogResponse, error)
|
|
|
|
|
ListPigSickLogs(ctx context.Context, req *dto.ListPigSickLogRequest) (*dto.ListPigSickLogResponse, error)
|
|
|
|
|
ListPigPurchases(ctx context.Context, req *dto.ListPigPurchaseRequest) (*dto.ListPigPurchaseResponse, error)
|
|
|
|
|
ListPigSales(ctx context.Context, req *dto.ListPigSaleRequest) (*dto.ListPigSaleResponse, error)
|
|
|
|
|
ListNotifications(ctx context.Context, req *dto.ListNotificationRequest) (*dto.ListNotificationResponse, error)
|
2025-10-19 20:24:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// monitorService 是 MonitorService 接口的具体实现
|
|
|
|
|
type monitorService struct {
|
2025-11-05 19:57:30 +08:00
|
|
|
ctx context.Context
|
2025-10-18 15:43:27 +08:00
|
|
|
sensorDataRepo repository.SensorDataRepository
|
|
|
|
|
deviceCommandLogRepo repository.DeviceCommandLogRepository
|
|
|
|
|
executionLogRepo repository.ExecutionLogRepository
|
2025-10-29 17:52:07 +08:00
|
|
|
planRepository repository.PlanRepository
|
2025-10-18 15:43:27 +08:00
|
|
|
pendingCollectionRepo repository.PendingCollectionRepository
|
2025-10-18 15:47:13 +08:00
|
|
|
userActionLogRepo repository.UserActionLogRepository
|
2025-10-19 13:47:37 +08:00
|
|
|
medicationRepo repository.MedicationLogRepository
|
2025-10-19 13:41:29 +08:00
|
|
|
pigBatchRepo repository.PigBatchRepository
|
2025-10-19 12:41:13 +08:00
|
|
|
pigBatchLogRepo repository.PigBatchLogRepository
|
2025-10-19 14:11:18 +08:00
|
|
|
pigTransferLogRepo repository.PigTransferLogRepository
|
2025-10-19 14:34:22 +08:00
|
|
|
pigSickLogRepo repository.PigSickLogRepository
|
2025-10-19 14:54:13 +08:00
|
|
|
pigTradeRepo repository.PigTradeRepository
|
2025-10-25 14:36:24 +08:00
|
|
|
notificationRepo repository.NotificationRepository
|
2025-10-18 15:31:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewMonitorService 创建一个新的 MonitorService 实例
|
2025-10-18 15:33:39 +08:00
|
|
|
func NewMonitorService(
|
2025-11-05 19:57:30 +08:00
|
|
|
ctx context.Context,
|
2025-10-18 15:33:39 +08:00
|
|
|
sensorDataRepo repository.SensorDataRepository,
|
|
|
|
|
deviceCommandLogRepo repository.DeviceCommandLogRepository,
|
2025-10-18 15:36:32 +08:00
|
|
|
executionLogRepo repository.ExecutionLogRepository,
|
2025-10-29 17:52:07 +08:00
|
|
|
planRepository repository.PlanRepository,
|
2025-10-18 15:43:27 +08:00
|
|
|
pendingCollectionRepo repository.PendingCollectionRepository,
|
2025-10-18 15:47:13 +08:00
|
|
|
userActionLogRepo repository.UserActionLogRepository,
|
2025-10-19 13:47:37 +08:00
|
|
|
medicationRepo repository.MedicationLogRepository,
|
2025-10-19 13:41:29 +08:00
|
|
|
pigBatchRepo repository.PigBatchRepository,
|
2025-10-19 12:41:13 +08:00
|
|
|
pigBatchLogRepo repository.PigBatchLogRepository,
|
2025-10-19 14:11:18 +08:00
|
|
|
pigTransferLogRepo repository.PigTransferLogRepository,
|
2025-10-19 14:34:22 +08:00
|
|
|
pigSickLogRepo repository.PigSickLogRepository,
|
2025-10-19 14:54:13 +08:00
|
|
|
pigTradeRepo repository.PigTradeRepository,
|
2025-10-25 14:36:24 +08:00
|
|
|
notificationRepo repository.NotificationRepository,
|
2025-10-19 20:24:01 +08:00
|
|
|
) MonitorService {
|
|
|
|
|
return &monitorService{
|
2025-11-05 19:57:30 +08:00
|
|
|
ctx: ctx,
|
2025-10-18 15:43:27 +08:00
|
|
|
sensorDataRepo: sensorDataRepo,
|
|
|
|
|
deviceCommandLogRepo: deviceCommandLogRepo,
|
|
|
|
|
executionLogRepo: executionLogRepo,
|
2025-10-29 17:52:07 +08:00
|
|
|
planRepository: planRepository,
|
2025-10-18 15:43:27 +08:00
|
|
|
pendingCollectionRepo: pendingCollectionRepo,
|
2025-10-18 15:47:13 +08:00
|
|
|
userActionLogRepo: userActionLogRepo,
|
2025-10-18 16:22:59 +08:00
|
|
|
medicationRepo: medicationRepo,
|
2025-10-19 13:41:29 +08:00
|
|
|
pigBatchRepo: pigBatchRepo,
|
2025-10-19 12:41:13 +08:00
|
|
|
pigBatchLogRepo: pigBatchLogRepo,
|
2025-10-19 14:11:18 +08:00
|
|
|
pigTransferLogRepo: pigTransferLogRepo,
|
2025-10-19 14:34:22 +08:00
|
|
|
pigSickLogRepo: pigSickLogRepo,
|
2025-10-19 14:54:13 +08:00
|
|
|
pigTradeRepo: pigTradeRepo,
|
2025-10-25 14:36:24 +08:00
|
|
|
notificationRepo: notificationRepo,
|
2025-10-18 15:31:05 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListSensorData 负责处理查询传感器数据列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListSensorData(ctx context.Context, req *dto.ListSensorDataRequest) (*dto.ListSensorDataResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListSensorData")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.SensorDataListOptions{
|
|
|
|
|
DeviceID: req.DeviceID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
if req.SensorType != nil {
|
|
|
|
|
sensorType := models.SensorType(*req.SensorType)
|
|
|
|
|
opts.SensorType = &sensorType
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.sensorDataRepo.List(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListSensorDataResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-18 15:31:05 +08:00
|
|
|
}
|
2025-10-18 15:33:39 +08:00
|
|
|
|
|
|
|
|
// ListDeviceCommandLogs 负责处理查询设备命令日志列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListDeviceCommandLogs(ctx context.Context, req *dto.ListDeviceCommandLogRequest) (*dto.ListDeviceCommandLogResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListDeviceCommandLogs")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.DeviceCommandLogListOptions{
|
|
|
|
|
DeviceID: req.DeviceID,
|
|
|
|
|
ReceivedSuccess: req.ReceivedSuccess,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.deviceCommandLogRepo.List(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListDeviceCommandLogResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-18 15:33:39 +08:00
|
|
|
}
|
2025-10-18 15:36:32 +08:00
|
|
|
|
|
|
|
|
// ListPlanExecutionLogs 负责处理查询计划执行日志列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListPlanExecutionLogs(ctx context.Context, req *dto.ListPlanExecutionLogRequest) (*dto.ListPlanExecutionLogResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListPlanExecutionLogs")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.PlanExecutionLogListOptions{
|
|
|
|
|
PlanID: req.PlanID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
if req.Status != nil {
|
|
|
|
|
status := models.ExecutionStatus(*req.Status)
|
|
|
|
|
opts.Status = &status
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
planLogs, total, err := s.executionLogRepo.ListPlanExecutionLogs(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-29 17:52:07 +08:00
|
|
|
if err != nil {
|
2025-10-31 15:10:09 +08:00
|
|
|
return nil, err
|
2025-10-29 17:52:07 +08:00
|
|
|
}
|
2025-10-31 15:10:09 +08:00
|
|
|
|
2025-11-10 22:23:31 +08:00
|
|
|
planIds := make([]uint32, 0, len(planLogs))
|
2025-10-29 17:52:07 +08:00
|
|
|
for _, datum := range planLogs {
|
2025-10-29 19:07:00 +08:00
|
|
|
has := false
|
2025-10-29 17:52:07 +08:00
|
|
|
for _, id := range planIds {
|
|
|
|
|
if id == datum.PlanID {
|
2025-10-29 19:07:00 +08:00
|
|
|
has = true
|
2025-10-29 17:52:07 +08:00
|
|
|
break
|
|
|
|
|
}
|
2025-10-29 19:07:00 +08:00
|
|
|
}
|
|
|
|
|
if !has {
|
2025-10-29 17:52:07 +08:00
|
|
|
planIds = append(planIds, datum.PlanID)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-05 19:57:30 +08:00
|
|
|
plans, err := s.planRepository.GetPlansByIDs(serviceCtx, planIds)
|
2025-10-29 17:52:07 +08:00
|
|
|
if err != nil {
|
2025-10-31 15:10:09 +08:00
|
|
|
return nil, err
|
2025-10-29 17:52:07 +08:00
|
|
|
}
|
2025-10-31 15:10:09 +08:00
|
|
|
return dto.NewListPlanExecutionLogResponse(planLogs, plans, total, req.Page, req.PageSize), nil
|
2025-10-18 15:36:32 +08:00
|
|
|
}
|
2025-10-18 15:39:47 +08:00
|
|
|
|
|
|
|
|
// ListTaskExecutionLogs 负责处理查询任务执行日志列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListTaskExecutionLogs(ctx context.Context, req *dto.ListTaskExecutionLogRequest) (*dto.ListTaskExecutionLogResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListTaskExecutionLogs")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.TaskExecutionLogListOptions{
|
|
|
|
|
PlanExecutionLogID: req.PlanExecutionLogID,
|
|
|
|
|
TaskID: req.TaskID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
if req.Status != nil {
|
|
|
|
|
status := models.ExecutionStatus(*req.Status)
|
|
|
|
|
opts.Status = &status
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.executionLogRepo.ListTaskExecutionLogs(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListTaskExecutionLogResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-18 15:39:47 +08:00
|
|
|
}
|
2025-10-18 15:43:27 +08:00
|
|
|
|
|
|
|
|
// ListPendingCollections 负责处理查询待采集请求列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListPendingCollections(ctx context.Context, req *dto.ListPendingCollectionRequest) (*dto.ListPendingCollectionResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListPendingCollections")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.PendingCollectionListOptions{
|
|
|
|
|
DeviceID: req.DeviceID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
if req.Status != nil {
|
|
|
|
|
status := models.PendingCollectionStatus(*req.Status)
|
|
|
|
|
opts.Status = &status
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.pendingCollectionRepo.List(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListPendingCollectionResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-18 15:43:27 +08:00
|
|
|
}
|
2025-10-18 15:47:13 +08:00
|
|
|
|
|
|
|
|
// ListUserActionLogs 负责处理查询用户操作日志列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListUserActionLogs(ctx context.Context, req *dto.ListUserActionLogRequest) (*dto.ListUserActionLogResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListUserActionLogs")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.UserActionLogListOptions{
|
|
|
|
|
UserID: req.UserID,
|
|
|
|
|
Username: req.Username,
|
|
|
|
|
ActionType: req.ActionType,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
if req.Status != nil {
|
|
|
|
|
status := models.AuditStatus(*req.Status)
|
|
|
|
|
opts.Status = &status
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.userActionLogRepo.List(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListUserActionLogResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-18 16:08:46 +08:00
|
|
|
}
|
2025-10-18 16:22:59 +08:00
|
|
|
|
|
|
|
|
// ListMedicationLogs 负责处理查询用药记录列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListMedicationLogs(ctx context.Context, req *dto.ListMedicationLogRequest) (*dto.ListMedicationLogResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListMedicationLogs")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.MedicationLogListOptions{
|
|
|
|
|
PigBatchID: req.PigBatchID,
|
|
|
|
|
MedicationID: req.MedicationID,
|
|
|
|
|
OperatorID: req.OperatorID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
if req.Reason != nil {
|
|
|
|
|
reason := models.MedicationReasonType(*req.Reason)
|
|
|
|
|
opts.Reason = &reason
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.medicationRepo.ListMedicationLogs(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListMedicationLogResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-18 16:22:59 +08:00
|
|
|
}
|
2025-10-19 12:41:13 +08:00
|
|
|
|
|
|
|
|
// ListPigBatchLogs 负责处理查询猪批次日志列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListPigBatchLogs(ctx context.Context, req *dto.ListPigBatchLogRequest) (*dto.ListPigBatchLogResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListPigBatchLogs")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.PigBatchLogListOptions{
|
|
|
|
|
PigBatchID: req.PigBatchID,
|
|
|
|
|
OperatorID: req.OperatorID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
if req.ChangeType != nil {
|
|
|
|
|
changeType := models.LogChangeType(*req.ChangeType)
|
|
|
|
|
opts.ChangeType = &changeType
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.pigBatchLogRepo.List(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListPigBatchLogResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-19 12:41:13 +08:00
|
|
|
}
|
2025-10-19 13:41:29 +08:00
|
|
|
|
|
|
|
|
// ListWeighingBatches 负责处理查询批次称重记录列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListWeighingBatches(ctx context.Context, req *dto.ListWeighingBatchRequest) (*dto.ListWeighingBatchResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListWeighingBatches")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.WeighingBatchListOptions{
|
|
|
|
|
PigBatchID: req.PigBatchID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.pigBatchRepo.ListWeighingBatches(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListWeighingBatchResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-19 13:41:29 +08:00
|
|
|
}
|
2025-10-19 13:59:11 +08:00
|
|
|
|
|
|
|
|
// ListWeighingRecords 负责处理查询单次称重记录列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListWeighingRecords(ctx context.Context, req *dto.ListWeighingRecordRequest) (*dto.ListWeighingRecordResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListWeighingRecords")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.WeighingRecordListOptions{
|
|
|
|
|
WeighingBatchID: req.WeighingBatchID,
|
|
|
|
|
PenID: req.PenID,
|
|
|
|
|
OperatorID: req.OperatorID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.pigBatchRepo.ListWeighingRecords(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListWeighingRecordResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-19 13:59:11 +08:00
|
|
|
}
|
2025-10-19 14:11:18 +08:00
|
|
|
|
|
|
|
|
// ListPigTransferLogs 负责处理查询猪只迁移日志列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListPigTransferLogs(ctx context.Context, req *dto.ListPigTransferLogRequest) (*dto.ListPigTransferLogResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListPigTransferLogs")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.PigTransferLogListOptions{
|
|
|
|
|
PigBatchID: req.PigBatchID,
|
|
|
|
|
PenID: req.PenID,
|
|
|
|
|
OperatorID: req.OperatorID,
|
|
|
|
|
CorrelationID: req.CorrelationID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
if req.TransferType != nil {
|
|
|
|
|
transferType := models.PigTransferType(*req.TransferType)
|
|
|
|
|
opts.TransferType = &transferType
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.pigTransferLogRepo.ListPigTransferLogs(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListPigTransferLogResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-19 14:11:18 +08:00
|
|
|
}
|
2025-10-19 14:34:22 +08:00
|
|
|
|
|
|
|
|
// ListPigSickLogs 负责处理查询病猪日志列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListPigSickLogs(ctx context.Context, req *dto.ListPigSickLogRequest) (*dto.ListPigSickLogResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListPigSickLogs")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.PigSickLogListOptions{
|
|
|
|
|
PigBatchID: req.PigBatchID,
|
|
|
|
|
PenID: req.PenID,
|
|
|
|
|
OperatorID: req.OperatorID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
if req.Reason != nil {
|
|
|
|
|
reason := models.PigBatchSickPigReasonType(*req.Reason)
|
|
|
|
|
opts.Reason = &reason
|
|
|
|
|
}
|
|
|
|
|
if req.TreatmentLocation != nil {
|
|
|
|
|
treatmentLocation := models.PigBatchSickPigTreatmentLocation(*req.TreatmentLocation)
|
|
|
|
|
opts.TreatmentLocation = &treatmentLocation
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.pigSickLogRepo.ListPigSickLogs(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListPigSickLogResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-19 14:34:22 +08:00
|
|
|
}
|
2025-10-19 14:54:13 +08:00
|
|
|
|
|
|
|
|
// ListPigPurchases 负责处理查询猪只采购记录列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListPigPurchases(ctx context.Context, req *dto.ListPigPurchaseRequest) (*dto.ListPigPurchaseResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListPigPurchases")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.PigPurchaseListOptions{
|
|
|
|
|
PigBatchID: req.PigBatchID,
|
|
|
|
|
Supplier: req.Supplier,
|
|
|
|
|
OperatorID: req.OperatorID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.pigTradeRepo.ListPigPurchases(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListPigPurchaseResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-19 14:54:13 +08:00
|
|
|
}
|
2025-10-19 15:53:19 +08:00
|
|
|
|
|
|
|
|
// ListPigSales 负责处理查询猪只销售记录列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListPigSales(ctx context.Context, req *dto.ListPigSaleRequest) (*dto.ListPigSaleResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListPigSales")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.PigSaleListOptions{
|
|
|
|
|
PigBatchID: req.PigBatchID,
|
|
|
|
|
Buyer: req.Buyer,
|
|
|
|
|
OperatorID: req.OperatorID,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.pigTradeRepo.ListPigSales(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListPigSaleResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-19 15:53:19 +08:00
|
|
|
}
|
2025-10-25 14:36:24 +08:00
|
|
|
|
|
|
|
|
// ListNotifications 负责处理查询通知列表的业务逻辑
|
2025-11-05 19:57:30 +08:00
|
|
|
func (s *monitorService) ListNotifications(ctx context.Context, req *dto.ListNotificationRequest) (*dto.ListNotificationResponse, error) {
|
|
|
|
|
serviceCtx := logs.AddFuncName(ctx, s.ctx, "ListNotifications")
|
2025-10-31 15:10:09 +08:00
|
|
|
opts := repository.NotificationListOptions{
|
|
|
|
|
UserID: req.UserID,
|
|
|
|
|
NotifierType: req.NotifierType,
|
|
|
|
|
Level: req.Level,
|
|
|
|
|
StartTime: req.StartTime,
|
|
|
|
|
EndTime: req.EndTime,
|
|
|
|
|
OrderBy: req.OrderBy,
|
|
|
|
|
Status: req.Status,
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:57:30 +08:00
|
|
|
data, total, err := s.notificationRepo.List(serviceCtx, opts, req.Page, req.PageSize)
|
2025-10-31 15:10:09 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto.NewListNotificationResponse(data, total, req.Page, req.PageSize), nil
|
2025-10-25 14:36:24 +08:00
|
|
|
}
|