mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'fix/BE/UUIT-Recording-closing-report-uniformity-dashboard' into 'development'
Fix/be/uuit recording closing report uniformity dashboard See merge request mbugroup/lti-api!240
This commit is contained in:
@@ -287,6 +287,11 @@ func (u *ProjectflockController) LookupProjectFlockKandang(c *fiber.Ctx) error {
|
||||
} else {
|
||||
dtoResult.AvailableQuantity = population
|
||||
}
|
||||
if chickinDate, err := u.ProjectflockService.GetProjectFlockKandangChickinDate(c, result.Id); err != nil {
|
||||
return err
|
||||
} else if chickinDate != nil {
|
||||
dtoResult.ChickInDate = chickinDate
|
||||
}
|
||||
if warehouse, werr := u.ProjectflockService.GetWarehouseByKandangID(c, result.KandangId); werr != nil {
|
||||
return werr
|
||||
} else if warehouse != nil {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
|
||||
fcrDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/fcrs/dto"
|
||||
@@ -38,6 +40,7 @@ type ProjectFlockKandangDTO struct {
|
||||
ProjectFlock *ProjectFlockWithPivotDTO `json:"project_flock,omitempty"`
|
||||
AvailableQuantity float64 `json:"available_quantity"`
|
||||
Population *float64 `json:"population,omitempty"`
|
||||
ChickInDate *time.Time `json:"chick_in_date,omitempty"`
|
||||
}
|
||||
|
||||
func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangDTO {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
@@ -42,6 +43,7 @@ type ProjectflockService interface {
|
||||
DeleteOne(ctx *fiber.Ctx, id uint) error
|
||||
GetProjectFlockKandangByProjectAndKandang(ctx *fiber.Ctx, projectFlockID uint, kandangID uint) (*entity.ProjectFlockKandang, float64, error)
|
||||
GetProjectFlockKandangPopulation(ctx *fiber.Ctx, projectFlockKandangID uint) (float64, error)
|
||||
GetProjectFlockKandangChickinDate(ctx *fiber.Ctx, projectFlockKandangID uint) (*time.Time, error)
|
||||
GetPeriodSummary(ctx *fiber.Ctx, locationID uint) ([]KandangPeriodSummary, error)
|
||||
GetProjectPeriods(ctx *fiber.Ctx, projectIDs []uint) (map[uint]int, error)
|
||||
Approval(ctx *fiber.Ctx, req *validation.Approve) ([]entity.ProjectFlock, error)
|
||||
@@ -459,6 +461,35 @@ func (s projectflockService) GetProjectFlockKandangPopulation(ctx *fiber.Ctx, pr
|
||||
return total, nil
|
||||
}
|
||||
|
||||
func (s projectflockService) GetProjectFlockKandangChickinDate(ctx *fiber.Ctx, projectFlockKandangID uint) (*time.Time, error) {
|
||||
if s.PopulationRepo == nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Project flock population repository is not configured")
|
||||
}
|
||||
if projectFlockKandangID == 0 {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "project_flock_kandang_id is required")
|
||||
}
|
||||
|
||||
populations, err := s.PopulationRepo.GetByProjectFlockKandangID(ctx.Context(), projectFlockKandangID)
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to fetch populations for project flock kandang %d: %+v", projectFlockKandangID, err)
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch project flock kandang chick in date")
|
||||
}
|
||||
|
||||
var earliest *time.Time
|
||||
for _, pop := range populations {
|
||||
if pop.ProjectChickin == nil || pop.ProjectChickin.ChickInDate.IsZero() {
|
||||
continue
|
||||
}
|
||||
chickinDate := pop.ProjectChickin.ChickInDate
|
||||
if earliest == nil || chickinDate.Before(*earliest) {
|
||||
copy := chickinDate
|
||||
earliest = ©
|
||||
}
|
||||
}
|
||||
|
||||
return earliest, nil
|
||||
}
|
||||
|
||||
func (s projectflockService) GetProjectFlockKandangByParams(ctx *fiber.Ctx, idStr string, projectFlockIdStr string, kandangIdStr string) (*entity.ProjectFlockKandang, float64, error) {
|
||||
idStr = strings.TrimSpace(idStr)
|
||||
projectFlockIdStr = strings.TrimSpace(projectFlockIdStr)
|
||||
|
||||
@@ -3,6 +3,8 @@ package controller
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/dto"
|
||||
service "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/services"
|
||||
@@ -82,7 +84,16 @@ func (u *RecordingController) GetNextDay(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "project_flock_kandang_id is required")
|
||||
}
|
||||
|
||||
nextDay, err := u.RecordingService.GetNextDay(c, uint(projectFlockID))
|
||||
recordTime := time.Now().UTC()
|
||||
if recordDate := strings.TrimSpace(c.Query("record_date")); recordDate != "" {
|
||||
parsed, err := time.Parse("2006-01-02", recordDate)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "record_date must be in YYYY-MM-DD format")
|
||||
}
|
||||
recordTime = parsed.UTC()
|
||||
}
|
||||
|
||||
nextDay, err := u.RecordingService.GetNextDay(c, uint(projectFlockID), recordTime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
sProductionStandard "gitlab.com/mbugroup/lti-api.git/internal/modules/master/production-standards/services"
|
||||
rProjectFlock "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
|
||||
repository "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/repositories"
|
||||
rStockLogs "gitlab.com/mbugroup/lti-api.git/internal/modules/shared/repositories"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/validations"
|
||||
rStockLogs "gitlab.com/mbugroup/lti-api.git/internal/modules/shared/repositories"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
approvalutils "gitlab.com/mbugroup/lti-api.git/internal/utils/approvals"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils/fifo"
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
type RecordingService interface {
|
||||
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.Recording, int64, error)
|
||||
GetOne(ctx *fiber.Ctx, id uint) (*entity.Recording, error)
|
||||
GetNextDay(ctx *fiber.Ctx, projectFlockKandangId uint) (int, error)
|
||||
GetNextDay(ctx *fiber.Ctx, projectFlockKandangId uint, recordTime time.Time) (int, error)
|
||||
CreateOne(ctx *fiber.Ctx, req *validation.Create) (*entity.Recording, error)
|
||||
UpdateOne(ctx *fiber.Ctx, req *validation.Update, id uint) (*entity.Recording, error)
|
||||
DeleteOne(ctx *fiber.Ctx, id uint) error
|
||||
@@ -160,12 +160,15 @@ func (s recordingService) GetOne(c *fiber.Ctx, id uint) (*entity.Recording, erro
|
||||
return recording, nil
|
||||
}
|
||||
|
||||
func (s recordingService) GetNextDay(c *fiber.Ctx, projectFlockKandangId uint) (int, error) {
|
||||
func (s recordingService) GetNextDay(c *fiber.Ctx, projectFlockKandangId uint, recordTime time.Time) (int, error) {
|
||||
if projectFlockKandangId == 0 {
|
||||
return 0, fiber.NewError(fiber.StatusBadRequest, "project_flock_kandang_id is required")
|
||||
}
|
||||
|
||||
day, err := s.computeRecordingDay(c.Context(), projectFlockKandangId, time.Now().UTC())
|
||||
if recordTime.IsZero() {
|
||||
recordTime = time.Now().UTC()
|
||||
}
|
||||
day, err := s.computeRecordingDay(c.Context(), projectFlockKandangId, recordTime)
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to compute recording day for project_flock_kandang_id=%d: %+v", projectFlockKandangId, err)
|
||||
return 0, err
|
||||
|
||||
@@ -375,7 +375,7 @@ func (s *uniformityService) CreateOne(c *fiber.Ctx, req *validation.Create, file
|
||||
var latestWeek int
|
||||
if err := s.Repository.DB().WithContext(c.Context()).
|
||||
Model(&entity.ProjectFlockKandangUniformity{}).
|
||||
Where("project_flock_kandang_id = ? AND deleted_at IS NULL", req.ProjectFlockKandangId).
|
||||
Where("project_flock_kandang_id = ?", req.ProjectFlockKandangId).
|
||||
Select("COALESCE(MAX(week), 0)").
|
||||
Scan(&latestWeek).Error; err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate uniformity week sequence")
|
||||
|
||||
Reference in New Issue
Block a user