2023-03-31 11:49:03 +02:00
|
|
|
package xml_loader
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"gitea.urkob.com/urko/ess-etl-go/internal/request"
|
|
|
|
"gitea.urkob.com/urko/ess-etl-go/pkg/domain"
|
2023-04-10 11:43:13 +02:00
|
|
|
"github.com/docker/go-units"
|
2023-03-31 11:49:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type EmployeeWILoader struct {
|
|
|
|
r request.RequestService
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewEmployeeWILoader(r request.RequestService) EmployeeWILoader {
|
|
|
|
return EmployeeWILoader{r: r}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e EmployeeWILoader) LoadEmployeeList(employeeIDList []string, from, to string) ([]domain.EmployeeWorkInformation, error) {
|
2023-04-10 11:43:13 +02:00
|
|
|
xmlBts := make([]byte, 0, units.MiB*5)
|
|
|
|
err := e.r.EmployeeWorkInformation(&xmlBts, employeeIDList, from, to)
|
2023-03-31 11:49:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("r.EmployeeWorkInformation: %s", err)
|
|
|
|
}
|
2023-04-10 11:43:13 +02:00
|
|
|
if len(xmlBts) <= 0 {
|
|
|
|
return nil, fmt.Errorf("couldn't load xml ")
|
|
|
|
}
|
2023-03-31 11:49:03 +02:00
|
|
|
|
2023-04-10 11:43:13 +02:00
|
|
|
return loadFromXML(xmlBts)
|
2023-03-31 11:49:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e EmployeeWILoader) LoadEmployee(employeeID, from, to string) ([]domain.EmployeeWorkInformation, error) {
|
|
|
|
employeeIDList := []string{employeeID}
|
2023-04-10 11:43:13 +02:00
|
|
|
xmlBts := make([]byte, 0, units.MiB*5)
|
|
|
|
err := e.r.EmployeeWorkInformation(&xmlBts, employeeIDList, from, to)
|
2023-03-31 11:49:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("r.EmployeeWorkInformation: %s", err)
|
|
|
|
}
|
2023-04-10 11:43:13 +02:00
|
|
|
if len(xmlBts) <= 0 {
|
|
|
|
return nil, fmt.Errorf("couldn't load xml ")
|
|
|
|
}
|
|
|
|
return loadFromXML(xmlBts)
|
2023-03-31 11:49:03 +02:00
|
|
|
}
|
|
|
|
|
2023-04-10 11:43:13 +02:00
|
|
|
func loadFromXML(xmlFile []byte) ([]domain.EmployeeWorkInformation, error) {
|
2023-03-31 11:49:03 +02:00
|
|
|
var awi domain.ArrayOfEmployeeWorkInformation
|
2023-04-10 11:43:13 +02:00
|
|
|
if err := xml.Unmarshal(xmlFile, &awi); err != nil {
|
|
|
|
return nil, fmt.Errorf("xml.Unmarshal: %s", err)
|
2023-03-31 11:49:03 +02:00
|
|
|
}
|
|
|
|
return awi.EmployeeWorkInfos, nil
|
|
|
|
}
|