Files
nCovTrack-Backend/service/management/faker.go
fallen-angle 9e3638885d finish
2022-05-16 19:55:59 +08:00

112 lines
3.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package management
import (
"encoding/json"
"fmt"
"nCovTrack-Backend/global"
"nCovTrack-Backend/models"
"nCovTrack-Backend/utils"
"strings"
"time"
)
//fakerGetRequest Get data from faker
func fakerGetRequest(uri string) string {
resStr := utils.GetWhioutHeader(global.FACKER_HOST + uri)
var res utils.GinResponse
_ = json.Unmarshal([]byte(resStr), &res)
dataStr, _ := json.Marshal(res.Data)
return string(dataStr)
}
//queryHotelContacts Hotel contacts
func queryHotelContacts(identification string) []models.HotelContactRequest {
dataStr := fakerGetRequest("query/contacts/hotel/" + identification)
var data []models.HotelContactRequest
err := json.Unmarshal([]byte(dataStr), &data)
if err != nil {
panic(err)
}
return data
}
//queryRailwayContacts Railway contacts
func queryRailwayContacts(identification string) []models.RailwayContactRequest {
dataStr := fakerGetRequest("query/contacts/railway/" + identification)
var data []models.RailwayContactRequest
err := json.Unmarshal([]byte(dataStr), &data)
if err != nil {
panic(err)
}
return data
}
//queryPatients Patients
func QueryPatients(identification string) []models.PatientRequest {
dataStr := fakerGetRequest("query/contacts/railway/" + identification)
var data []models.PatientRequest
err := json.Unmarshal([]byte(dataStr), &data)
if err != nil {
panic(err)
}
return data
}
//queryContacts Resolve the diffrent of hotel and railway request
func queryContacts(identification string) []models.BackObservation {
hotelContacts := queryHotelContacts(identification)
railwayContacts := queryRailwayContacts(identification)
observations := append(fakerContacts2Observations(hotelContacts), fakerContacts2Observations(railwayContacts)...)
return observations
}
//splitFakerAddress Extract the region
func splitFakerAddress(fakerAddress string) string {
addresses := strings.Split(fakerAddress, " ")
return addresses[1] + " " + addresses[2]
}
//fakerContacts2Observations Convvert structs
func fakerContacts2Observations(contacts any) []models.BackObservation {
var observations []models.BackObservation
switch contacts.(type) {
case []models.HotelContactRequest:
for _, contact := range contacts.([]models.HotelContactRequest) {
tranjectory := fmt.Sprintf("在%s-%s期间与患者同期留宿%s", contact.InData.String(), contact.OutData.String(), contact.HotelName)
observation := &models.BackObservation{
Name: contact.Name,
Age: contact.Age,
Sex: contact.Sex,
Phone: contact.Phone,
Identification: contact.Identification,
Region: splitFakerAddress(contact.Address),
Address: "",
HealthSituation: global.HEALTH_SITUATION_ID_MAP["CONTACT"],
HealthChangeTime: time.Now(),
MeasureSituation: global.MEASURE_SITUATION_ID_MAP["NOMEASURE"],
Trajectory: tranjectory,
}
observations = append(observations, *observation)
}
case []models.RailwayContactRequest:
for _, contact := range contacts.([]models.RailwayContactRequest) {
tranjectory := fmt.Sprintf("在%s与患者同期乘坐%s", contact.Launch.String(), contact.Train)
observation := &models.BackObservation{
Name: contact.Name,
Age: contact.Age,
Sex: contact.Sex,
Phone: contact.Phone,
Identification: contact.Identification,
Region: splitFakerAddress(contact.Address),
Address: "",
HealthSituation: global.HEALTH_SITUATION_ID_MAP["CONTACT"],
HealthChangeTime: time.Now(),
MeasureSituation: global.MEASURE_SITUATION_ID_MAP["NOMEASURE"],
Trajectory: tranjectory,
}
observations = append(observations, *observation)
}
}
return observations
}