Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.3 kB
18
Indexable
Never
func MapperKafkaMessageEmployees(rows []*models.EmployeesRow, d models.Driver, val *validator.Validate) ([][]models.Json, int64, int64) {
	var updated, failed int64
	count := d.Updated
	var messageArray *models.Json
	var json []models.Json
	for _, r := range rows {
		var inicioRela, terminoRela string
		if err := val.Struct(r); err == nil {
			r = validBools(r)
			if r.InicioRela == nil {
				inicioRela = "nil"
			} else {
				inicioRela = r.InicioRela.Format("2006-01-02")
			}
			if r.TerminoRela == nil {
				terminoRela = "nil"
			} else {
				terminoRela = r.TerminoRela.Format("2006-01-02")
			}
			if r.CodEmpresa == 173 {
				messageArray = &models.Json{
					"employeeKey":       count,
					"codeCountry":       r.EmployeeCode,
					"code":              r.NumDocu,
					"internalId":        r.NumUser,
					"name":              r.Nombres,
					"lastName":          r.ApePaterno,
					"secondLastName":    r.ApeMaterno,
					"email":             r.Email,
					"internalCodeType":  r.CodOrigen,
					"employeeType":      r.Origen,
					"makeMarks":         r.MakeMarksBool,
					"hired":             r.ContratadoBool,
					"expertLevel":       r.NivelExperto,
					"contractStartDate": inicioRela,
					"contractEndDate":   terminoRela,
					"workContractCode":  r.CodTipoJornada,
					"workContractName":  r.NomJornada,

					"facility": map[string]interface{}{
						"code":         r.CodEmpresa,
						"name":         r.NomEmpresa,
						"commerceCode": CommerceCode,
						"commerceName": NombreI,
					},
					"workUnit": map[string]interface{}{
						"positionName":   r.NomCargo,
						"posLocalCode":   r.PosLocal,
						"cecoName":       r.NomCosto,
						"cecoCode":       r.CodCosto,
						"departmentName": r.NomDepto,
						"departmentCode": r.CodDepto,
						"workShiftMode":  r.ExepHoraria,
						"positionCode":   r.CodCargo,
					},

					"location": map[string]interface{}{
						"country":    r.CodPais,
						"countyCode": r.CoComuna,
						"countyName": r.NomComuna,
					},
					"extractDate": d.ExtractDate,
					"extractDay":  d.ExtractDay,
				}
			}
			json = append(json, *messageArray)
			updated += 1
			count += 1
		} else {
			failed += 1
		}
	}
	return createEvents(d.NumberExtractor, json), updated, failed
}