mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 23:05:44 +00:00
add master data config checklist
This commit is contained in:
@@ -951,6 +951,12 @@ func (s dailyChecklistService) GetReport(c *fiber.Ctx, params *validation.Report
|
||||
PhaseID uint
|
||||
}
|
||||
|
||||
type dailyActivityStat struct {
|
||||
Completed int
|
||||
Total int
|
||||
Date time.Time
|
||||
}
|
||||
|
||||
employeeIDs := make([]uint, 0)
|
||||
kandangIDs := make([]uint, 0)
|
||||
phaseIDs := make([]uint, 0)
|
||||
@@ -976,7 +982,7 @@ func (s dailyChecklistService) GetReport(c *fiber.Ctx, params *validation.Report
|
||||
}
|
||||
}
|
||||
|
||||
dailyActivityMap := make(map[comboKey]map[string]int)
|
||||
dailyActivityMap := make(map[comboKey]map[string]dailyActivityStat)
|
||||
if len(employeeIDs) > 0 {
|
||||
var dailyRows []struct {
|
||||
EmployeeID uint
|
||||
@@ -984,6 +990,7 @@ func (s dailyChecklistService) GetReport(c *fiber.Ctx, params *validation.Report
|
||||
PhaseID uint
|
||||
Date time.Time
|
||||
Completed int64
|
||||
Total int64
|
||||
}
|
||||
|
||||
dailyQuery := buildBase().
|
||||
@@ -995,7 +1002,8 @@ func (s dailyChecklistService) GetReport(c *fiber.Ctx, params *validation.Report
|
||||
dc.kandang_id,
|
||||
dcat.phase_id,
|
||||
dc.date,
|
||||
SUM(CASE WHEN dca.checked THEN 1 ELSE 0 END) AS completed`).
|
||||
SUM(CASE WHEN dca.checked THEN 1 ELSE 0 END) AS completed,
|
||||
COUNT(*) AS total`).
|
||||
Group("dca.employee_id, dc.kandang_id, dcat.phase_id, dc.date")
|
||||
|
||||
if err := dailyQuery.Scan(&dailyRows).Error; err != nil {
|
||||
@@ -1009,10 +1017,14 @@ func (s dailyChecklistService) GetReport(c *fiber.Ctx, params *validation.Report
|
||||
continue
|
||||
}
|
||||
if _, ok := dailyActivityMap[key]; !ok {
|
||||
dailyActivityMap[key] = make(map[string]int)
|
||||
dailyActivityMap[key] = make(map[string]dailyActivityStat)
|
||||
}
|
||||
day := strconv.Itoa(row.Date.Day())
|
||||
dailyActivityMap[key][day] = int(row.Completed)
|
||||
dailyActivityMap[key][day] = dailyActivityStat{
|
||||
Completed: int(row.Completed),
|
||||
Total: int(row.Total),
|
||||
Date: row.Date,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1068,18 +1080,66 @@ func (s dailyChecklistService) GetReport(c *fiber.Ctx, params *validation.Report
|
||||
}{Completed: row.Completed, Total: row.Total}
|
||||
}
|
||||
|
||||
var configs []entity.ConfigChecklist
|
||||
if err := s.Repository.DB().WithContext(c.Context()).
|
||||
Order("date ASC").
|
||||
Find(&configs).Error; err != nil {
|
||||
s.Log.Errorf("Failed to load config checklists: %+v", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
getConfigForDate := func(date time.Time) *entity.ConfigChecklist {
|
||||
var selected *entity.ConfigChecklist
|
||||
for i := range configs {
|
||||
if !configs[i].Date.After(date) {
|
||||
selected = &configs[i]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if selected == nil {
|
||||
return &entity.ConfigChecklist{
|
||||
PercentageThresholdBad: 50,
|
||||
PercentageThresholdEnough: 75,
|
||||
}
|
||||
}
|
||||
return selected
|
||||
}
|
||||
|
||||
items := make([]DailyChecklistReportItem, len(rows))
|
||||
for i, row := range rows {
|
||||
key := comboKey{EmployeeID: row.EmployeeID, KandangID: row.KandangID, PhaseID: row.PhaseID}
|
||||
|
||||
activities := dailyActivityMap[key]
|
||||
if activities == nil {
|
||||
activities = map[string]int{}
|
||||
activities = map[string]dailyActivityStat{}
|
||||
}
|
||||
|
||||
totalChecklist := 0
|
||||
for _, count := range activities {
|
||||
totalChecklist += count
|
||||
categoryCounts := DailyChecklistReportCategory{}
|
||||
activityOutput := make(map[string]int, len(activities))
|
||||
|
||||
for day, stat := range activities {
|
||||
activityOutput[day] = stat.Completed
|
||||
totalChecklist += stat.Completed
|
||||
|
||||
if stat.Total == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
cfg := getConfigForDate(stat.Date)
|
||||
if cfg == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
progress := int(math.Ceil(float64(stat.Completed) / float64(stat.Total) * 100))
|
||||
if progress <= cfg.PercentageThresholdBad {
|
||||
categoryCounts.Kurang++
|
||||
} else if progress <= cfg.PercentageThresholdEnough {
|
||||
categoryCounts.Cukup++
|
||||
} else {
|
||||
categoryCounts.Baik++
|
||||
}
|
||||
}
|
||||
|
||||
employeeStat := employeeStats[row.EmployeeID]
|
||||
@@ -1104,17 +1164,13 @@ func (s dailyChecklistService) GetReport(c *fiber.Ctx, params *validation.Report
|
||||
EmployeeID: row.EmployeeID,
|
||||
EmployeeName: row.EmployeeName,
|
||||
PhaseName: row.PhaseName,
|
||||
DailyActivities: activities,
|
||||
DailyActivities: activityOutput,
|
||||
Summary: DailyChecklistReportSummary{
|
||||
TotalChecklist: totalChecklist,
|
||||
JumlahHariEfektif: len(activities),
|
||||
AbkPercentage: abkPercentage,
|
||||
KandangPercentage: kandangPercentage,
|
||||
Category: DailyChecklistReportCategory{
|
||||
Kurang: 0,
|
||||
Cukup: 0,
|
||||
Baik: 0,
|
||||
},
|
||||
Category: categoryCounts,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user