70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package dashboard
|
|
|
|
import "time"
|
|
|
|
type ListPerbandinganStatusAntrean []PerbandinganStatusAntreanQueryResult
|
|
type ListAntrianPerHari []AntrianPerHari
|
|
|
|
func (list ListPerbandinganStatusAntrean) findJumlahById(id int) int {
|
|
for _, item := range list {
|
|
if item.IdStatus == id {
|
|
return item.Jumlah
|
|
}
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
func (list ListPerbandinganStatusAntrean) MapToResponse() []PerbandinganStatusAntreanResponse {
|
|
return []PerbandinganStatusAntreanResponse{
|
|
{IdStatus: 1, Status: "Belum", Jumlah: list.findJumlahById(1)},
|
|
{IdStatus: 2, Status: "Selesai", Jumlah: list.findJumlahById(2)},
|
|
{IdStatus: 3, Status: "Tunda", Jumlah: list.findJumlahById(3)},
|
|
{IdStatus: 4, Status: "Batal", Jumlah: list.findJumlahById(4)},
|
|
}
|
|
}
|
|
|
|
func getMonthRange(year int, month time.Month) (time.Time, time.Time) {
|
|
start := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
|
|
end := start.AddDate(0, 1, 0)
|
|
|
|
return start, end
|
|
}
|
|
|
|
func (list ListAntrianPerHari) ParseToResponse(year int, month time.Month) []AntrianPerHariResponse {
|
|
dataMap := make(map[string]AntrianPerHari)
|
|
|
|
for _, item := range list {
|
|
key := item.TanggalDaftar.Format("2006-01-02")
|
|
dataMap[key] = item
|
|
}
|
|
|
|
start, end := getMonthRange(year, month)
|
|
|
|
var result []AntrianPerHariResponse
|
|
|
|
for d := start; d.Before(end); d = d.AddDate(0, 0, 1) {
|
|
key := d.Format("2006-01-02")
|
|
|
|
if val, ok := dataMap[key]; ok {
|
|
result = append(result, AntrianPerHariResponse{
|
|
TanggalDaftar: d.Format("2006-01-02"),
|
|
Belum: val.Belum,
|
|
Selesai: val.Selesai,
|
|
Tunda: val.Tunda,
|
|
Batal: val.Batal,
|
|
})
|
|
} else {
|
|
result = append(result, AntrianPerHariResponse{
|
|
TanggalDaftar: d.Format("2006-01-02"),
|
|
Belum: 0,
|
|
Selesai: 0,
|
|
Tunda: 0,
|
|
Batal: 0,
|
|
})
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|